Guest User

Untitled

a guest
May 19th, 2026
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.21 KB | Cybersecurity | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <sys/socket.h>
  4. #include <errno.h>
  5.  
  6.  
  7. /* Supported address families: (https://github.com/torvalds/linux/blob/master/include/linux/socket.h) */
  8. char *af[47] = {
  9.     [ 0] = "AF_UNSPEC",
  10.     [ 1] = "AF_UNIX",       /* Unix domain sockets */
  11.     [ 2] = "AF_INET",       /* Internet IP Protocol */
  12.     [ 3] = "AF_AX25",       /* Amateur Radio AX.25 */
  13.     [ 4] = "AF_IPX",        /* Novell IPX */
  14.     [ 5] = "AF_APPLETALK",  /* AppleTalk DDP */
  15.     [ 6] = "AF_NETROM",     /* Amateur Radio NET/ROM */
  16.     [ 7] = "AF_BRIDGE",     /* Multiprotocol bridge */
  17.     [ 8] = "AF_ATMPVC",     /* ATM PVCs */
  18.     [ 9] = "AF_X25",        /* Reserved for X.25 project */
  19.     [10] = "AF_INET6",      /* IP version 6 */
  20.     [11] = "AF_ROSE",       /* Amateur Radio X.25 PLP */
  21.     [12] = "AF_DECnet",     /* Reserved for DECnet project */
  22.     [13] = "AF_NETBEUI",    /* Reserved for 802.2LLC project*/
  23.     [14] = "AF_SECURITY",   /* Security callback pseudo AF */
  24.     [15] = "AF_KEY",        /* PF_KEY key management API */
  25.     [16] = "AF_NETLINK",
  26.     [17] = "AF_PACKET",     /* Packet family */
  27.     [18] = "AF_ASH",        /* Ash */
  28.     [19] = "AF_ECONET",     /* Acorn Econet */
  29.     [20] = "AF_ATMSVC",     /* ATM SVCs */
  30.     [21] = "AF_RDS",        /* RDS sockets */
  31.     [22] = "AF_SNA",        /* Linux SNA Project (nutters!) */
  32.     [23] = "AF_IRDA",       /* IRDA sockets */
  33.     [24] = "AF_PPPOX",      /* PPPoX sockets */
  34.     [25] = "AF_WANPIPE",    /* Wanpipe API Sockets */
  35.     [26] = "AF_LLC",        /* Linux LLC */
  36.     [27] = "AF_IB",         /* Native InfiniBand address */
  37.     [28] = "AF_MPLS",       /* MPLS */
  38.     [29] = "AF_CAN",        /* Controller Area Network */
  39.     [30] = "AF_TIPC",       /* TIPC sockets */
  40.     [31] = "AF_BLUETOOTH",  /* Bluetooth sockets */
  41.     [32] = "AF_IUCV",       /* IUCV sockets */
  42.     [33] = "AF_RXRPC",      /* RxRPC sockets */
  43.     [34] = "AF_ISDN",       /* mISDN sockets */
  44.     [35] = "AF_PHONET",     /* Phonet sockets */
  45.     [36] = "AF_IEEE802154", /* IEEE802154 sockets */
  46.     [37] = "AF_CAIF",       /* CAIF sockets */
  47.     [38] = "AF_ALG",        /* Algorithm sockets */
  48.     [39] = "AF_NFC",        /* NFC sockets */
  49.     [40] = "AF_VSOCK",      /* vSockets */
  50.     [41] = "AF_KCM",        /* Kernel Connection Multiplexor*/
  51.     [42] = "AF_QIPCRTR",    /* Qualcomm IPC Router */
  52.     [43] = "AF_SMC",        /* smc sockets: reserve number for PF_SMC protocol family that reuses AF_INET address family */
  53.     [44] = "AF_XDP",        /* XDP sockets */
  54.     [45] = "AF_MCTP",       /* Management component transport protocol */
  55.     [46] = "AF_MAX",        /* For now.. */
  56. };
  57.  
  58. #define af_name(X)          ( (X < ( sizeof(af) / sizeof(af[1] )) ) ? af[X] : "err: AF_MAX exceeded" )
  59.  
  60. #define FG_RED      "\x1b[31m"
  61. #define FG_GREEN    "\x1b[32m"
  62. #define FG_DEF      "\x1b[39m"
  63.  
  64. char no_acc[] =  FG_GREEN "This user does not have access to this socket." FG_DEF;
  65. char has_acc[] = FG_RED   "This user has access to this socket." FG_DEF;
  66.  
  67. char msg[] = "socket(%02i) [%-13s] -> %03i: %s\n";
  68.  
  69. int main()
  70. {
  71.     for (unsigned int i = 0; i <= 256; i++) {
  72.         errno = 0;
  73.         int s = socket(i, 0, 0);
  74.         if (s == -1) {
  75.             if (errno == 97) {
  76.                 continue;
  77.             }
  78.             if (errno ==  1) {
  79.                 printf(msg, i, af_name(i), errno, no_acc);
  80.                 continue;
  81.             }
  82.         }
  83.         printf(msg, i, af_name(i), errno, has_acc);
  84.     }
  85. }
  86.  
Advertisement
Add Comment
Please, Sign In to add comment