Skip to content

Instantly share code, notes, and snippets.

@majek
Created July 15, 2019 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save majek/c22b94f55cc429b2c6e3e2c4a0a82b62 to your computer and use it in GitHub Desktop.
Save majek/c22b94f55cc429b2c6e3e2c4a0a82b62 to your computer and use it in GitHub Desktop.
available setsockopts
[SETSOCKOPT(SOL_ICMPV6, 1)]: {.bytes = 32}
[SETSOCKOPT(SOL_IP, IP_BIND_ADDRESS_NO_PORT)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_CHECKSUM)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_FREEBIND)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_HDRINCL)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_MINTTL)]: {.min = 0, .max = 255}
[SETSOCKOPT(SOL_IP, IP_MTU_DISCOVER)]: {.min = 0, .max = 6}
[SETSOCKOPT(SOL_IP, IP_MULTICAST_ALL)]: {.min = 0, .max = 1}
// [SETSOCKOPT(SOL_IP, IP_MULTICAST_IF)]: # not settable ??
// [SETSOCKOPT(SOL_IP, IP_MULTICAST_IF)]: # only single value 0
[SETSOCKOPT(SOL_IP, IP_MULTICAST_LOOP)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_MULTICAST_TTL)]: {.min = 0, .max = 255}
// [SETSOCKOPT(SOL_IP, IP_MULTICAST_TTL)]: # not settable ??
[SETSOCKOPT(SOL_IP, IP_NODEFRAG)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_OPTIONS)]: {}, # variable bytes?
[SETSOCKOPT(SOL_IP, IP_ORIGDSTADDR)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_PASSSEC)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_PKTINFO)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_RECVERR)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_RECVFRAGSIZE)]: {.min = 0, .max = 1}
// [SETSOCKOPT(SOL_IP, IP_RECVFRAGSIZE)]: # not settable ??
[SETSOCKOPT(SOL_IP, IP_RECVOPTS)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_RECVTOS)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_RECVTTL)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_RETOPTS)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_TOS)]: {.bytes = 4}
[SETSOCKOPT(SOL_IP, IP_TRANSPARENT)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, IP_TTL)]: {.bytes = 4}
// [SETSOCKOPT(SOL_IP, IP_UNICAST_IF)]: # only single value 0
[SETSOCKOPT(SOL_IP, MRT6_ASSERT)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IP, MRT6_PIM)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_2292DSTOPTS)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_2292HOPLIMIT)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_2292HOPOPTS)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_2292PKTINFO)]: {.min = 0, .max = 1}
// [SETSOCKOPT(SOL_IPV6, IPV6_2292PKTOPTIONS)]: # errno ENODEV
[SETSOCKOPT(SOL_IPV6, IPV6_2292RTHDR)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_ADDR_PREFERENCES)]: {.bytes = 4}
[SETSOCKOPT(SOL_IPV6, IPV6_AUTOFLOWLABEL)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_CHECKSUM)]: {.bytes = 4}
// [SETSOCKOPT(SOL_IPV6, IPV6_CHECKSUM)]: # not settable ??
[SETSOCKOPT(SOL_IPV6, IPV6_DONTFRAG)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_DSTOPTS)]: {}, # variable bytes?
[SETSOCKOPT(SOL_IPV6, IPV6_FLOWINFO)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_FLOWINFO_SEND)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_FLOWLABEL_MGR)]: {.bytes = 32}
[SETSOCKOPT(SOL_IPV6, IPV6_FREEBIND)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_HDRINCL)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_HOPOPTS)]: {}, # variable bytes?
[SETSOCKOPT(SOL_IPV6, IPV6_MINHOPCOUNT)]: {.min = 0, .max = 255}
[SETSOCKOPT(SOL_IPV6, IPV6_MTU_DISCOVER)]: {.min = 0, .max = 6}
[SETSOCKOPT(SOL_IPV6, IPV6_MULTICAST_ALL)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_MULTICAST_HOPS)]: {.min = 0, .max = 255}
// [SETSOCKOPT(SOL_IPV6, IPV6_MULTICAST_IF)]: # only single value 0
[SETSOCKOPT(SOL_IPV6, IPV6_MULTICAST_LOOP)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_ORIGDSTADDR)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_RECVDSTOPTS)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_RECVERR)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_RECVFRAGSIZE)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_RECVHOPLIMIT)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_RECVHOPOPTS)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_RECVPATHMTU)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_RECVPKTINFO)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_RECVRTHDR)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_RECVTCLASS)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_ROUTER_ALERT_ISOLATE)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_RTHDRDSTOPTS)]: {}, # variable bytes?
[SETSOCKOPT(SOL_IPV6, IPV6_RTHDR)]: {}, # variable bytes?
[SETSOCKOPT(SOL_IPV6, IPV6_TCLASS)]: {.min = 0, .max = 255}
[SETSOCKOPT(SOL_IPV6, IPV6_TRANSPARENT)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, IPV6_UNICAST_HOPS)]: {.bytes = 4}
// [SETSOCKOPT(SOL_IPV6, IPV6_UNICAST_IF)]: # only single value 0
[SETSOCKOPT(SOL_IPV6, IPV6_V6ONLY)]: {.min = 0, .max = 1}
// [SETSOCKOPT(SOL_IPV6, IPV6_V6ONLY)]: # not settable ??
[SETSOCKOPT(SOL_IPV6, MRT6_ASSERT)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_IPV6, MRT6_PIM)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SCTP, SCTP_ADAPTATION_LAYER)]: {.min = 0, .max = 0xffffffffUL}
[SETSOCKOPT(SOL_SCTP, SCTP_ASSOCINFO)]: {.bytes = 20}
// [SETSOCKOPT(SOL_SCTP, SCTP_AUTO_ASCONF)]: # only single value 0
[SETSOCKOPT(SOL_SCTP, SCTP_AUTOCLOSE)]: {.bytes = 4}
[SETSOCKOPT(SOL_SCTP, SCTP_CONTEXT)]: {.bytes = 8}
[SETSOCKOPT(SOL_SCTP, SCTP_DEFAULT_PRINFO)]: {.bytes = 12}
[SETSOCKOPT(SOL_SCTP, SCTP_DEFAULT_SEND_PARAM)]: {.bytes = 32}
[SETSOCKOPT(SOL_SCTP, SCTP_DEFAULT_SNDINFO)]: {.bytes = 16}
[SETSOCKOPT(SOL_SCTP, SCTP_DELAYED_ACK_TIME)]: {.bytes = 12}
[SETSOCKOPT(SOL_SCTP, SCTP_DISABLE_FRAGMENTS)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SCTP, SCTP_ENABLE_STREAM_RESET)]: {.bytes = 8}
[SETSOCKOPT(SOL_SCTP, SCTP_EVENTS)]: {.bytes = 13}
[SETSOCKOPT(SOL_SCTP, SCTP_FRAGMENT_INTERLEAVE)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SCTP, SCTP_GET_LOCAL_ADDRS)]: {}, # variable bytes?
[SETSOCKOPT(SOL_SCTP, SCTP_INITMSG)]: {.bytes = 8}
// [SETSOCKOPT(SOL_SCTP, SCTP_INTERLEAVING_SUPPORTED)]: # not settable
[SETSOCKOPT(SOL_SCTP, SCTP_I_WANT_MAPPED_V4_ADDR)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SCTP, SCTP_MAX_BURST)]: {.bytes = 1024}
[SETSOCKOPT(SOL_SCTP, SCTP_MAXSEG)]: {.bytes = 8}
[SETSOCKOPT(SOL_SCTP, SCTP_NODELAY)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SCTP, SCTP_PARTIAL_DELIVERY_POINT)]: {.bytes = 4}
[SETSOCKOPT(SOL_SCTP, SCTP_PEER_ADDR_PARAMS)]: {.bytes = 156}
[SETSOCKOPT(SOL_SCTP, SCTP_PEER_ADDR_THLDS)]: {.bytes = 144}
[SETSOCKOPT(SOL_SCTP, SCTP_PR_SUPPORTED)]: {.bytes = 8}
[SETSOCKOPT(SOL_SCTP, SCTP_RECONFIG_SUPPORTED)]: {.bytes = 8}
[SETSOCKOPT(SOL_SCTP, SCTP_RECVNXTINFO)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SCTP, SCTP_RECVRCVINFO)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SCTP, SCTP_REUSE_PORT)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SCTP, SCTP_RTOINFO)]: {.bytes = 16}
[SETSOCKOPT(SOL_SCTP, SCTP_STREAM_SCHEDULER)]: {.bytes = 8}
[SETSOCKOPT(SOL_SOCKET, SO_ATTACH_FILTER)]: {}, # variable bytes?
[SETSOCKOPT(SOL_SOCKET, SO_BINDTODEVICE)]: {}, # variable bytes?
[SETSOCKOPT(SOL_SOCKET, SO_BINDTOIFINDEX)]: {.bytes = 4}
[SETSOCKOPT(SOL_SOCKET, SO_BROADCAST)]: {.min = 0, .max = 1}
// [SETSOCKOPT(SOL_SOCKET, SO_BSDCOMPAT)]: # only single value 0
[SETSOCKOPT(SOL_SOCKET, SO_BUSY_POLL)]: {.bytes = 4}
[SETSOCKOPT(SOL_SOCKET, SO_DEBUG)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_DONTROUTE)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_INCOMING_CPU)]: {.min = 0, .max = 0xffffffffUL}
[SETSOCKOPT(SOL_SOCKET, SO_KEEPALIVE)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_LINGER)]: {.bytes = 8}
[SETSOCKOPT(SOL_SOCKET, SO_LOCK_FILTER)]: {.min = 0, .max = 1}
// [SETSOCKOPT(SOL_SOCKET, SO_LOCK_FILTER)]: # only single value 1
[SETSOCKOPT(SOL_SOCKET, SO_MARK)]: {.min = 0, .max = 0xffffffffUL}
[SETSOCKOPT(SOL_SOCKET, SO_MAX_PACING_RATE)]: {.bytes = 8}
[SETSOCKOPT(SOL_SOCKET, SO_NO_CHECK)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_NOFCS)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_OOBINLINE)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_PASSCRED)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_PASSSEC)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_PEEK_OFF)]: {.min = 0, .max = 0xffffffffUL}
[SETSOCKOPT(SOL_SOCKET, SO_PRIORITY)]: {.min = 0, .max = 0xffffffffUL}
[SETSOCKOPT(SOL_SOCKET, SO_RCVBUF)]: {.bytes = 4}
[SETSOCKOPT(SOL_SOCKET, SO_RCVLOWAT)]: {.bytes = 4}
[SETSOCKOPT(SOL_SOCKET, SO_RCVTIMEO)]: {.bytes = 16}
[SETSOCKOPT(SOL_SOCKET, SO_RCVTIMEO_NEW)]: {.bytes = 16}
[SETSOCKOPT(SOL_SOCKET, SO_REUSEADDR)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_REUSEPORT)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_RXQ_OVFL)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_SELECT_ERR_QUEUE)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_SNDBUF)]: {.bytes = 4}
[SETSOCKOPT(SOL_SOCKET, SO_SNDTIMEO)]: {.bytes = 16}
[SETSOCKOPT(SOL_SOCKET, SO_SNDTIMEO_NEW)]: {.bytes = 16}
[SETSOCKOPT(SOL_SOCKET, SO_TIMESTAMPING_OLD)]: {.bytes = 4}
[SETSOCKOPT(SOL_SOCKET, SO_TIMESTAMP_NEW)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_TIMESTAMPNS_NEW)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_TIMESTAMPNS_OLD)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_TIMESTAMP_OLD)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_TXTIME)]: {.bytes = 8}
[SETSOCKOPT(SOL_SOCKET, SO_WIFI_STATUS)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_SOCKET, SO_ZEROCOPY)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_TCP, TCP_CC_INFO)]: {}, # variable bytes?
[SETSOCKOPT(SOL_TCP, TCP_CONGESTION)]: {.bytes = 16}
[SETSOCKOPT(SOL_TCP, TCP_CORK)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_TCP, TCP_DEFER_ACCEPT)]: {.bytes = 4}
[SETSOCKOPT(SOL_TCP, TCP_FASTOPEN)]: {.bytes = 4}
[SETSOCKOPT(SOL_TCP, TCP_FASTOPEN_CONNECT)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_TCP, TCP_FASTOPEN_KEY)]: {}, # variable bytes?
[SETSOCKOPT(SOL_TCP, TCP_FASTOPEN_NO_COOKIE)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_TCP, TCP_INQ)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_TCP, TCP_KEEPCNT)]: {.bytes = 4}
[SETSOCKOPT(SOL_TCP, TCP_KEEPIDLE)]: {.bytes = 4}
[SETSOCKOPT(SOL_TCP, TCP_KEEPINTVL)]: {.bytes = 4}
[SETSOCKOPT(SOL_TCP, TCP_LINGER2)]: {.bytes = 4}
// [SETSOCKOPT(SOL_TCP, TCP_MAXSEG)]: # only single value 536
[SETSOCKOPT(SOL_TCP, TCP_NODELAY)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_TCP, TCP_NOTSENT_LOWAT)]: {.min = 0, .max = 0xffffffffUL}
[SETSOCKOPT(SOL_TCP, TCP_QUEUE_SEQ)]: {.min = 0, .max = 0xffffffffUL}
[SETSOCKOPT(SOL_TCP, TCP_QUICKACK)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_TCP, TCP_REPAIR)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_TCP, TCP_REPAIR_QUEUE)]: {.min = 0, .max = 3}
[SETSOCKOPT(SOL_TCP, TCP_SAVED_SYN)]: {}, # variable bytes?
[SETSOCKOPT(SOL_TCP, TCP_SAVE_SYN)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_TCP, TCP_SYNCNT)]: {.bytes = 4}
// [SETSOCKOPT(SOL_TCP, TCP_THIN_DUPACK)]: # only single value 0
[SETSOCKOPT(SOL_TCP, TCP_THIN_LINEAR_TIMEOUTS)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_TCP, TCP_TIMESTAMP)]: {.min = 0, .max = 0xffffffffUL}
[SETSOCKOPT(SOL_TCP, TCP_ULP)]: {}, # variable bytes?
[SETSOCKOPT(SOL_TCP, TCP_USER_TIMEOUT)]: {.bytes = 4}
[SETSOCKOPT(SOL_TCP, TCP_WINDOW_CLAMP)]: {.bytes = 4}
[SETSOCKOPT(SOL_UDPLITE, UDP_CORK)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_UDPLITE, UDP_ENCAP)]: {.min = 0, .max = 4}
[SETSOCKOPT(SOL_UDPLITE, UDPLITE_RECV_CSCOV)]: {.bytes = 4}
[SETSOCKOPT(SOL_UDPLITE, UDPLITE_SEND_CSCOV)]: {.bytes = 4}
[SETSOCKOPT(SOL_UDPLITE, UDP_NO_CHECK6_RX)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_UDPLITE, UDP_NO_CHECK6_TX)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_UDPLITE, UDP_SEGMENT)]: {.min = 0, .max = 0xffffUL}
[SETSOCKOPT(SOL_UDP, UDP_CORK)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_UDP, UDP_ENCAP)]: {.min = 0, .max = 4}
[SETSOCKOPT(SOL_UDP, UDP_NO_CHECK6_RX)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_UDP, UDP_NO_CHECK6_TX)]: {.min = 0, .max = 1}
[SETSOCKOPT(SOL_UDP, UDP_SEGMENT)]: {.min = 0, .max = 0xffffUL}
import errno
import socket
import socket as s
af_to_name = '''
SOL_IP 0
SOL_SOCKET 1
SOL_TCP 6
SOL_UDP 17
SOL_IPV6 41
SOL_ICMPV6 58
SOL_CAN_BASE 100
SOL_CAN_RAW 101
SOL_SCTP 132
SOL_UDPLITE 136
SOL_RAW 255
SOL_IPX 256
SOL_AX25 257
SOL_ATALK 258
SOL_NETROM 259
SOL_ROSE 260
SOL_DECNET 261
SOL_X25 262
SOL_PACKET 263
SOL_ATM 264
SOL_AAL 265
SOL_IRDA 266
SOL_NETBEUI 267
SOL_LLC 268
SOL_DCCP 269
SOL_NETLINK 270
SOL_TIPC 271
SOL_RXRPC 272
SOL_PPPOL2TP 273
SOL_BLUETOOTH 274
SOL_PNPIPE 275
SOL_RDS 276
SOL_IUCV 277
SOL_CAIF 278
SOL_ALG 279
SOL_NFC 280
SOL_KCM 281
SOL_TLS 282
SOL_XDP 283
'''
af_to_name = dict((int(v), n) for line in af_to_name.strip().split('\n') for n, v in [line.split()] )
ip_ss_to_name = '''
#define IP_TOS 1
#define IP_TTL 2
#define IP_HDRINCL 3
#define IP_OPTIONS 4
#define IP_ROUTER_ALERT 5
#define IP_RECVOPTS 6
#define IP_RETOPTS 7
#define IP_PKTINFO 8
#define IP_PKTOPTIONS 9
#define IP_MTU_DISCOVER 10
#define IP_RECVERR 11
#define IP_RECVTTL 12
#define IP_RECVTOS 13
#define IP_MTU 14
#define IP_FREEBIND 15
#define IP_IPSEC_POLICY 16
#define IP_XFRM_POLICY 17
#define IP_PASSSEC 18
#define IP_TRANSPARENT 19
#define IP_ORIGDSTADDR 20
#define IP_MINTTL 21
#define IP_NODEFRAG 22
#define IP_CHECKSUM 23
#define IP_BIND_ADDRESS_NO_PORT 24
#define IP_RECVFRAGSIZE 25
#define IP_MULTICAST_IF 32
#define IP_MULTICAST_TTL 33
#define IP_MULTICAST_LOOP 34
#define IP_ADD_MEMBERSHIP 35
#define IP_DROP_MEMBERSHIP 36
#define IP_UNBLOCK_SOURCE 37
#define IP_BLOCK_SOURCE 38
#define IP_ADD_SOURCE_MEMBERSHIP 39
#define IP_DROP_SOURCE_MEMBERSHIP 40
#define IP_MSFILTER 41
#define MCAST_JOIN_GROUP 42
#define MCAST_BLOCK_SOURCE 43
#define MCAST_UNBLOCK_SOURCE 44
#define MCAST_LEAVE_GROUP 45
#define MCAST_JOIN_SOURCE_GROUP 46
#define MCAST_LEAVE_SOURCE_GROUP 47
#define MCAST_MSFILTER 48
#define IP_MULTICAST_ALL 49
#define IP_UNICAST_IF 50
#define MRT6_INIT 200 /* Activate the kernel mroute code */
#define MRT6_DONE 201 /* Shutdown the kernel mroute */
#define MRT6_ADD_MIF 202 /* Add a virtual interface */
#define MRT6_DEL_MIF 203 /* Delete a virtual interface */
#define MRT6_ADD_MFC 204 /* Add a multicast forwarding entry */
#define MRT6_DEL_MFC 205 /* Delete a multicast forwarding entry */
#define MRT6_VERSION 206 /* Get the kernel multicast version */
#define MRT6_ASSERT 207 /* Activate PIM assert mode */
#define MRT6_PIM 208 /* enable PIM code */
#define MRT6_TABLE 209 /* Specify mroute table ID */
#define MRT6_ADD_MFC_PROXY 210 /* Add a (*,*|G) mfc entry */
#define MRT6_DEL_MFC_PROXY 211 /* Del a (*,*|G) mfc entry */
#define MRT6_FLUSH 212 /* Flush all mfc entries and/or vifs */
'''
ipv6_ss_to_name = '''
#define IPV6_ADDRFORM 1
#define IPV6_2292PKTINFO 2
#define IPV6_2292HOPOPTS 3
#define IPV6_2292DSTOPTS 4
#define IPV6_2292RTHDR 5
#define IPV6_2292PKTOPTIONS 6
#define IPV6_CHECKSUM 7
#define IPV6_2292HOPLIMIT 8
#define IPV6_NEXTHOP 9
#define IPV6_AUTHHDR 10
#define IPV6_FLOWINFO 11
#define IPV6_UNICAST_HOPS 16
#define IPV6_MULTICAST_IF 17
#define IPV6_MULTICAST_HOPS 18
#define IPV6_MULTICAST_LOOP 19
#define IPV6_JOIN_GROUP 20
#define IPV6_LEAVE_GROUP 21
#define IPV6_ROUTER_ALERT 22
#define IPV6_MTU_DISCOVER 23
#define IPV6_MTU 24
#define IPV6_RECVERR 25
#define IPV6_V6ONLY 26
#define IPV6_JOIN_ANYCAST 27
#define IPV6_LEAVE_ANYCAST 28
#define IPV6_MULTICAST_ALL 29
#define IPV6_ROUTER_ALERT_ISOLATE 30
#define IPV6_FLOWLABEL_MGR 32
#define IPV6_FLOWINFO_SEND 33
#define IPV6_IPSEC_POLICY 34
#define IPV6_XFRM_POLICY 35
#define IPV6_HDRINCL 36
#define IPV6_RECVPKTINFO 49
#define IPV6_PKTINFO 50
#define IPV6_RECVHOPLIMIT 51
#define IPV6_HOPLIMIT 52
#define IPV6_RECVHOPOPTS 53
#define IPV6_HOPOPTS 54
#define IPV6_RTHDRDSTOPTS 55
#define IPV6_RECVRTHDR 56
#define IPV6_RTHDR 57
#define IPV6_RECVDSTOPTS 58
#define IPV6_DSTOPTS 59
#define IPV6_RECVPATHMTU 60
#define IPV6_PATHMTU 61
#define IPV6_DONTFRAG 62
#define IPV6_RECVTCLASS 66
#define IPV6_TCLASS 67
#define IPV6_AUTOFLOWLABEL 70
#define IPV6_ADDR_PREFERENCES 72
#define IPV6_MINHOPCOUNT 73
#define IPV6_ORIGDSTADDR 74
#define IPV6_TRANSPARENT 75
#define IPV6_UNICAST_IF 76
#define IPV6_RECVFRAGSIZE 77
#define IPV6_FREEBIND 78
#define MRT6_INIT 200 /* Activate the kernel mroute code */
#define MRT6_DONE 201 /* Shutdown the kernel mroute */
#define MRT6_ADD_MIF 202 /* Add a virtual interface */
#define MRT6_DEL_MIF 203 /* Delete a virtual interface */
#define MRT6_ADD_MFC 204 /* Add a multicast forwarding entry */
#define MRT6_DEL_MFC 205 /* Delete a multicast forwarding entry */
#define MRT6_VERSION 206 /* Get the kernel multicast version */
#define MRT6_ASSERT 207 /* Activate PIM assert mode */
#define MRT6_PIM 208 /* enable PIM code */
#define MRT6_TABLE 209 /* Specify mroute table ID */
#define MRT6_ADD_MFC_PROXY 210 /* Add a (*,*|G) mfc entry */
#define MRT6_DEL_MFC_PROXY 211 /* Del a (*,*|G) mfc entry */
#define MRT6_FLUSH 212 /* Flush all mfc entries and/or vifs */
'''
sock_ss_to_name = '''
#define SO_DEBUG 1
#define SO_REUSEADDR 2
#define SO_TYPE 3
#define SO_ERROR 4
#define SO_DONTROUTE 5
#define SO_BROADCAST 6
#define SO_SNDBUF 7
#define SO_RCVBUF 8
#define SO_SNDBUFFORCE 32
#define SO_RCVBUFFORCE 33
#define SO_KEEPALIVE 9
#define SO_OOBINLINE 10
#define SO_NO_CHECK 11
#define SO_PRIORITY 12
#define SO_LINGER 13
#define SO_BSDCOMPAT 14
#define SO_REUSEPORT 15
#define SO_PASSCRED 16
#define SO_PEERCRED 17
#define SO_RCVLOWAT 18
#define SO_SNDLOWAT 19
#define SO_RCVTIMEO 20
#define SO_SNDTIMEO 21
#define SO_SECURITY_AUTHENTICATION 22
#define SO_SECURITY_ENCRYPTION_TRANSPORT 23
#define SO_SECURITY_ENCRYPTION_NETWORK 24
#define SO_BINDTODEVICE 25
#define SO_ATTACH_FILTER 26
#define SO_DETACH_FILTER 27
#define SO_PEERNAME 28
#define SO_TIMESTAMP 29
#define SO_ACCEPTCONN 30
#define SO_PEERSEC 31
#define SO_PASSSEC 34
#define SO_TIMESTAMPNS 35
#define SO_MARK 36
#define SO_TIMESTAMPING 37
#define SO_PROTOCOL 38
#define SO_DOMAIN 39
#define SO_RXQ_OVFL 40
#define SO_WIFI_STATUS 41
#define SO_PEEK_OFF 42
#define SO_NOFCS 43
#define SO_LOCK_FILTER 44
#define SO_SELECT_ERR_QUEUE 45
#define SO_BUSY_POLL 46
#define SO_MAX_PACING_RATE 47
#define SO_BPF_EXTENSIONS 48
#define SO_INCOMING_CPU 49
#define SO_ATTACH_BPF 50
#define SO_ATTACH_REUSEPORT_CBPF 51
#define SO_ATTACH_REUSEPORT_EBPF 52
#define SO_CNX_ADVICE 53
#define SCM_TIMESTAMPING_OPT_STATS 54
#define SO_MEMINFO 55
#define SO_INCOMING_NAPI_ID 56
#define SO_COOKIE 57
#define SCM_TIMESTAMPING_PKTINFO 58
#define SO_PEERGROUPS 59
#define SO_ZEROCOPY 60
#define SO_TXTIME 61
#define SO_BINDTOIFINDEX 62
#define SO_TIMESTAMP_OLD 29
#define SO_TIMESTAMPNS_OLD 35
#define SO_TIMESTAMPING_OLD 37
#define SO_TIMESTAMP_NEW 63
#define SO_TIMESTAMPNS_NEW 64
#define SO_TIMESTAMPING_NEW 65
#define SO_RCVTIMEO_NEW 66
#define SO_SNDTIMEO_NEW 67
'''
sctp_ss_to_name = '''
#define SCTP_RTOINFO 0
#define SCTP_ASSOCINFO 1
#define SCTP_INITMSG 2
#define SCTP_NODELAY 3 /* Get/set nodelay option. */
#define SCTP_AUTOCLOSE 4
#define SCTP_SET_PEER_PRIMARY_ADDR 5
#define SCTP_PRIMARY_ADDR 6
#define SCTP_ADAPTATION_LAYER 7
#define SCTP_DISABLE_FRAGMENTS 8
#define SCTP_PEER_ADDR_PARAMS 9
#define SCTP_DEFAULT_SEND_PARAM 10
#define SCTP_EVENTS 11
#define SCTP_I_WANT_MAPPED_V4_ADDR 12 /* Turn on/off mapped v4 addresses */
#define SCTP_MAXSEG 13 /* Get/set maximum fragment. */
#define SCTP_STATUS 14
#define SCTP_GET_PEER_ADDR_INFO 15
#define SCTP_DELAYED_ACK_TIME 16
#define SCTP_CONTEXT 17
#define SCTP_FRAGMENT_INTERLEAVE 18
#define SCTP_PARTIAL_DELIVERY_POINT 19 /* Set/Get partial delivery point */
#define SCTP_MAX_BURST 20 /* Set/Get max burst */
#define SCTP_AUTH_CHUNK 21 /* Set only: add a chunk type to authenticate */
#define SCTP_HMAC_IDENT 22
#define SCTP_AUTH_KEY 23
#define SCTP_AUTH_ACTIVE_KEY 24
#define SCTP_AUTH_DELETE_KEY 25
#define SCTP_PEER_AUTH_CHUNKS 26 /* Read only */
#define SCTP_LOCAL_AUTH_CHUNKS 27 /* Read only */
#define SCTP_GET_ASSOC_NUMBER 28 /* Read only */
#define SCTP_GET_ASSOC_ID_LIST 29 /* Read only */
#define SCTP_AUTO_ASCONF 30
#define SCTP_PEER_ADDR_THLDS 31
#define SCTP_RECVRCVINFO 32
#define SCTP_RECVNXTINFO 33
#define SCTP_DEFAULT_SNDINFO 34
#define SCTP_AUTH_DEACTIVATE_KEY 35
#define SCTP_REUSE_PORT 36
#define SCTP_SOCKOPT_BINDX_ADD 100 /* BINDX requests for adding addrs */
#define SCTP_SOCKOPT_BINDX_REM 101 /* BINDX requests for removing addrs. */
#define SCTP_SOCKOPT_PEELOFF 102 /* peel off association. */
#define SCTP_SOCKOPT_CONNECTX_OLD 107 /* CONNECTX old requests. */
#define SCTP_GET_PEER_ADDRS 108 /* Get all peer address. */
#define SCTP_GET_LOCAL_ADDRS 109 /* Get all local address. */
#define SCTP_SOCKOPT_CONNECTX 110 /* CONNECTX requests. */
#define SCTP_SOCKOPT_CONNECTX3 111 /* CONNECTX requests (updated) */
#define SCTP_GET_ASSOC_STATS 112 /* Read only */
#define SCTP_PR_SUPPORTED 113
#define SCTP_DEFAULT_PRINFO 114
#define SCTP_PR_ASSOC_STATUS 115
#define SCTP_PR_STREAM_STATUS 116
#define SCTP_RECONFIG_SUPPORTED 117
#define SCTP_ENABLE_STREAM_RESET 118
#define SCTP_RESET_STREAMS 119
#define SCTP_RESET_ASSOC 120
#define SCTP_ADD_STREAMS 121
#define SCTP_SOCKOPT_PEELOFF_FLAGS 122
#define SCTP_STREAM_SCHEDULER 123
#define SCTP_STREAM_SCHEDULER_VALUE 124
#define SCTP_INTERLEAVING_SUPPORTED 125
#define SCTP_SENDMSG_CONNECT 126
#define SCTP_EVENT 127
'''
tcp_ss_to_name = '''
#define TCP_NODELAY 1 /* Turn off Nagle's algorithm. */
#define TCP_MAXSEG 2 /* Limit MSS */
#define TCP_CORK 3 /* Never send partially complete segments */
#define TCP_KEEPIDLE 4 /* Start keeplives after this period */
#define TCP_KEEPINTVL 5 /* Interval between keepalives */
#define TCP_KEEPCNT 6 /* Number of keepalives before death */
#define TCP_SYNCNT 7 /* Number of SYN retransmits */
#define TCP_LINGER2 8 /* Life time of orphaned FIN-WAIT-2 state */
#define TCP_DEFER_ACCEPT 9 /* Wake up listener only when data arrive */
#define TCP_WINDOW_CLAMP 10 /* Bound advertised window */
#define TCP_INFO 11 /* Information about this connection. */
#define TCP_QUICKACK 12 /* Block/reenable quick acks */
#define TCP_CONGESTION 13 /* Congestion control algorithm */
#define TCP_MD5SIG 14 /* TCP MD5 Signature (RFC2385) */
#define TCP_THIN_LINEAR_TIMEOUTS 16 /* Use linear timeouts for thin streams*/
#define TCP_THIN_DUPACK 17 /* Fast retrans. after 1 dupack */
#define TCP_USER_TIMEOUT 18 /* How long for loss retry before timeout */
#define TCP_REPAIR 19 /* TCP sock is under repair right now */
#define TCP_REPAIR_QUEUE 20
#define TCP_QUEUE_SEQ 21
#define TCP_REPAIR_OPTIONS 22
#define TCP_FASTOPEN 23 /* Enable FastOpen on listeners */
#define TCP_TIMESTAMP 24
#define TCP_NOTSENT_LOWAT 25 /* limit number of unsent bytes in write queue */
#define TCP_CC_INFO 26 /* Get Congestion Control (optional) info */
#define TCP_SAVE_SYN 27 /* Record SYN headers for new connections */
#define TCP_SAVED_SYN 28 /* Get SYN headers recorded for connection */
#define TCP_REPAIR_WINDOW 29 /* Get/set window parameters */
#define TCP_FASTOPEN_CONNECT 30 /* Attempt FastOpen with connect */
#define TCP_ULP 31 /* Attach a ULP to a TCP connection */
#define TCP_MD5SIG_EXT 32 /* TCP MD5 Signature with extensions */
#define TCP_FASTOPEN_KEY 33 /* Set the key for Fast Open (cookie) */
#define TCP_FASTOPEN_NO_COOKIE 34 /* Enable TFO without a TFO cookie */
#define TCP_ZEROCOPY_RECEIVE 35
#define TCP_INQ 36 /* Notify bytes available to read as a cmsg on read */
'''
udp_ss_to_name = '''
#define UDP_CORK 1 /* Never send partially complete segments */
#define UDP_ENCAP 100 /* Set the socket to accept encapsulated packets */
#define UDP_NO_CHECK6_TX 101 /* Disable sending checksum for UDP6X */
#define UDP_NO_CHECK6_RX 102 /* Disable accpeting checksum for UDP6 */
#define UDP_SEGMENT 103 /* Set GSO segmentation size */
#define UDP_GRO 104 /* This socket can receive UDP GRO packets */
#define UDPLITE_SEND_CSCOV 10 /* sender partial coverage (as sent) */
#define UDPLITE_RECV_CSCOV 11 /* receiver partial coverage (threshold ) */
'''
IPPROTO_UDPLITE = 136
SOL_IPV6 = 41
SOL_SCTP = s.IPPROTO_SCTP
ss_to_name = {
s.SOL_SOCKET: dict((int(v), n) for line in sock_ss_to_name.strip().split('\n') for _, n, v in [line.split()] ),
s.SOL_IP: dict((int(v), n) for line in ip_ss_to_name.strip().split('\n') for _, n, v in [line.split()[:3]] ),
SOL_IPV6 :dict((int(v), n) for line in ipv6_ss_to_name.strip().split('\n') for _, n, v in [line.split()[:3]] ),
SOL_SCTP :dict((int(v), n) for line in sctp_ss_to_name.strip().split('\n') for _, n, v in [line.split()[:3]] ),
s.IPPROTO_TCP :dict((int(v), n) for line in tcp_ss_to_name.strip().split('\n') for _, n, v in [line.split()[:3]] ),
s.IPPROTO_UDP :dict((int(v), n) for line in udp_ss_to_name.strip().split('\n') for _, n, v in [line.split()[:3]] ),
IPPROTO_UDPLITE :dict((int(v), n) for line in udp_ss_to_name.strip().split('\n') for _, n, v in [line.split()[:3]] ),
}
for address_family in (s.AF_UNIX, s.AF_INET, s.AF_INET6, s.AF_NETLINK):
for socket_type in (s.SOCK_STREAM, s.SOCK_DGRAM, s.SOCK_SEQPACKET, s.SOCK_RAW):
for protocol in range(255): #(0, s.IPPROTO_SCTP, IPPROTO_UDPLITE, s.IPPROTO_TCP, s.IPPROTO_UDP):
try:
sd = socket.socket(address_family, socket_type, protocol)
except OSError:
continue
# print("socket(%d, %d, %d)" % (address_family, socket_type, protocol))
for level in (s.SOL_SOCKET, s.SOL_IP, SOL_IPV6, protocol):
for optname in range(255):
comment = ''
v_min, v_max = 0, 0
try:
x = sd.getsockopt(level, optname, 1024)
except OSError:
continue
if len(x) > 0:
try:
sd.setsockopt(level, optname, x)
except PermissionError:
comment = '# not settable'
except OSError as e:
if e.errno in (errno.ENOPROTOOPT, errno.ENOTSUP, 524): # ENOTSUPP
continue
if e.errno == errno.EINVAL:
pass
else:
comment = "# errno %s" % errno.errorcode.get(e.errno, e.errno)
if not comment and len(x) == 4:
r = []
ose = 0
# start with 0 for SO_LOCKFILTER
values = (0,-129,-128,-127,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,127,128,255,256, 16384,16385,65535,65536,131072,212992,1073741824,1073741825,2147483647)
for i in values:
try:
sd.setsockopt(level, optname, i)
except PermissionError:
continue
except OSError:
ose += 1
continue
a = sd.getsockopt(level, optname)
r.append(a)
# if optname == s.SO_RCVLOWAT:
# print ('xxxx', r)
r = set(r)
if len(r) == 0 and ose == len(values):
comment = '# not settable ??'
# setsockopt aint good
pass
elif r == set((0,1)):
v_max = 1
elif r == set(filter(lambda a:a >=0 and a<= 255, values)):
v_max = 255
elif r == set(filter(lambda a:a >0 and a<= 255, values)):
v_min, v_max = 1, 255
elif len(r) == 1:
comment = '# only single value %d' % (list(r)[0],)
elif r == set(values):
v_max = '0xffffffffUL'
elif r == set(filter(lambda a:a >=0 and a<= 65535, values)):
v_max = '0xffffUL'
else:
for top in range(18):
if r == set(range(top)):
v_max = top
s_level = af_to_name.get(level, level)
s_optname = optname
if level in ss_to_name:
s_optname = ss_to_name[level].get(optname, optname)
if comment:
print(" // [SETSOCKOPT(%s, %s)]: %s" % (
s_level,
s_optname,
comment
))
elif v_min or v_max:
print(" [SETSOCKOPT(%s, %s)]: {.min = %s, .max = %s}" % (
s_level,
s_optname,
v_min,
v_max,
))
elif len(x) == 0:
print(" [SETSOCKOPT(%s, %s)]: {}, # variable bytes? " % (
s_level,
s_optname,
))
else:
print(" [SETSOCKOPT(%s, %s)]: {.bytes = %d}" % (
s_level,
s_optname,
len(x)
))
sd.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment