PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/ext/socket/mkconstants.rb

http://github.com/ruby/ruby
Ruby | 814 lines | 756 code | 38 blank | 20 comment | 29 complexity | 6fb5406cad5a06cb3073c10ca2b386c1 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, AGPL-3.0
  1. # frozen_string_literal: false
  2. require 'optparse'
  3. require 'erb'
  4. opt = OptionParser.new
  5. opt.def_option('-h', 'help') {
  6. puts opt
  7. exit 0
  8. }
  9. opt_o = nil
  10. opt.def_option('-o FILE', 'specify output file') {|filename|
  11. opt_o = filename
  12. }
  13. opt_H = nil
  14. opt.def_option('-H FILE', 'specify output header file') {|filename|
  15. opt_H = filename
  16. }
  17. C_ESC = {
  18. "\\" => "\\\\",
  19. '"' => '\"',
  20. "\n" => '\n',
  21. }
  22. 0x00.upto(0x1f) {|ch| C_ESC[[ch].pack("C")] ||= "\\%03o" % ch }
  23. 0x7f.upto(0xff) {|ch| C_ESC[[ch].pack("C")] = "\\%03o" % ch }
  24. C_ESC_PAT = Regexp.union(*C_ESC.keys)
  25. def c_str(str)
  26. '"' + str.gsub(C_ESC_PAT) {|s| C_ESC[s]} + '"'
  27. end
  28. opt.parse!
  29. h = {}
  30. COMMENTS = Hash.new { |h, name| h[name] = name }
  31. DATA.each_line {|s|
  32. name, default_value, comment = s.chomp.split(/\s+/, 3)
  33. next unless name && name[0] != ?#
  34. default_value = nil if default_value == 'nil'
  35. if h.has_key? name
  36. warn "#{$.}: warning: duplicate name: #{name}"
  37. next
  38. end
  39. h[name] = default_value
  40. COMMENTS[name] = comment
  41. }
  42. DEFS = h.to_a
  43. def each_const
  44. DEFS.each {|name, default_value|
  45. guard = nil
  46. if /\A(AF_INET6|PF_INET6|IPV6_.*)\z/ =~ name
  47. # IPv6 is not supported although AF_INET6 is defined on mingw
  48. guard = "defined(INET6)"
  49. end
  50. yield guard, name, default_value
  51. }
  52. end
  53. def each_name(pat)
  54. DEFS.each {|name, default_value|
  55. next if pat !~ name
  56. yield name
  57. }
  58. end
  59. erb_new = lambda do |src, safe, trim|
  60. if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
  61. ERB.new(src, trim_mode: trim)
  62. else
  63. ERB.new(src, safe, trim)
  64. end
  65. end
  66. erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_const_decls")
  67. % each_const {|guard, name, default_value|
  68. #if !defined(<%=name%>)
  69. # if defined(HAVE_CONST_<%=name.upcase%>)
  70. # define <%=name%> <%=name%>
  71. %if default_value
  72. # else
  73. # define <%=name%> <%=default_value%>
  74. %end
  75. # endif
  76. #endif
  77. % }
  78. EOS
  79. erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_const_defs_in_guard(name, default_value)")
  80. #if defined(<%=name%>)
  81. /* <%= COMMENTS[name] %> */
  82. rb_define_const(rb_cSocket, <%=c_str name%>, INTEGER2NUM(<%=name%>));
  83. /* <%= COMMENTS[name] %> */
  84. rb_define_const(rb_mSockConst, <%=c_str name%>, INTEGER2NUM(<%=name%>));
  85. #endif
  86. EOS
  87. erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_const_defs")
  88. % each_const {|guard, name, default_value|
  89. % if guard
  90. #if <%=guard%>
  91. <%= gen_const_defs_in_guard(name, default_value).chomp %>
  92. #endif
  93. % else
  94. <%= gen_const_defs_in_guard(name, default_value).chomp %>
  95. % end
  96. % }
  97. EOS
  98. def reverse_each_name(pat)
  99. DEFS.reverse_each {|name, default_value|
  100. next if pat !~ name
  101. yield name
  102. }
  103. end
  104. def each_names_with_len(pat, prefix_optional=nil)
  105. h = {}
  106. DEFS.each {|name, default_value|
  107. next if pat !~ name
  108. (h[name.length] ||= []) << [name, name]
  109. }
  110. if prefix_optional
  111. if Regexp === prefix_optional
  112. prefix_pat = prefix_optional
  113. else
  114. prefix_pat = /\A#{Regexp.escape prefix_optional}/
  115. end
  116. DEFS.each {|const, default_value|
  117. next if pat !~ const
  118. next if prefix_pat !~ const
  119. name = $'
  120. (h[name.length] ||= []) << [name, const]
  121. }
  122. end
  123. hh = {}
  124. h.each {|len, pairs|
  125. pairs.each {|name, const|
  126. raise "name crash: #{name}" if hh[name]
  127. hh[name] = true
  128. }
  129. }
  130. h.keys.sort.each {|len|
  131. yield h[len], len
  132. }
  133. end
  134. erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_decl(funcname, pat, prefix_optional, guard=nil)")
  135. %if guard
  136. #ifdef <%=guard%>
  137. int <%=funcname%>(const char *str, long len, int *valp);
  138. #endif
  139. %else
  140. int <%=funcname%>(const char *str, long len, int *valp);
  141. %end
  142. EOS
  143. erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_func_in_guard(funcname, pat, prefix_optional, guard=nil)")
  144. int
  145. <%=funcname%>(const char *str, long len, int *valp)
  146. {
  147. switch (len) {
  148. % each_names_with_len(pat, prefix_optional) {|pairs, len|
  149. case <%=len%>:
  150. % pairs.each {|name, const|
  151. #ifdef <%=const%>
  152. if (memcmp(str, <%=c_str name%>, <%=len%>) == 0) { *valp = <%=const%>; return 0; }
  153. #endif
  154. % }
  155. return -1;
  156. % }
  157. default:
  158. if (!str || !valp) {/* wrong argument */}
  159. return -1;
  160. }
  161. }
  162. EOS
  163. erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_func(funcname, pat, prefix_optional, guard=nil)")
  164. %if guard
  165. #ifdef <%=guard%>
  166. <%=gen_name_to_int_func_in_guard(funcname, pat, prefix_optional, guard)%>
  167. #endif
  168. %else
  169. <%=gen_name_to_int_func_in_guard(funcname, pat, prefix_optional, guard)%>
  170. %end
  171. EOS
  172. NAME_TO_INT_DEFS = []
  173. def def_name_to_int(funcname, pat, prefix_optional, guard=nil)
  174. decl = gen_name_to_int_decl(funcname, pat, prefix_optional, guard)
  175. func = gen_name_to_int_func(funcname, pat, prefix_optional, guard)
  176. NAME_TO_INT_DEFS << [decl, func]
  177. end
  178. def reverse_each_name_with_prefix_optional(pat, prefix_pat)
  179. reverse_each_name(pat) {|n|
  180. yield n, n
  181. }
  182. if prefix_pat
  183. reverse_each_name(pat) {|n|
  184. next if prefix_pat !~ n
  185. yield n, $'
  186. }
  187. end
  188. end
  189. erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_int_to_name_hash(hash_var, pat, prefix_pat)")
  190. <%=hash_var%> = st_init_numtable();
  191. % reverse_each_name_with_prefix_optional(pat, prefix_pat) {|n,s|
  192. #ifdef <%=n%>
  193. st_insert(<%=hash_var%>, (st_data_t)<%=n%>, (st_data_t)rb_intern2(<%=c_str s%>, <%=s.length%>));
  194. #endif
  195. % }
  196. EOS
  197. erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_int_to_name_func(func_name, hash_var)")
  198. ID
  199. <%=func_name%>(int val)
  200. {
  201. st_data_t name;
  202. if (st_lookup(<%=hash_var%>, (st_data_t)val, &name))
  203. return (ID)name;
  204. return 0;
  205. }
  206. EOS
  207. erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_int_to_name_decl(func_name, hash_var)")
  208. ID <%=func_name%>(int val);
  209. EOS
  210. INTERN_DEFS = []
  211. def def_intern(func_name, pat, prefix_optional=nil)
  212. prefix_pat = nil
  213. if prefix_optional
  214. if Regexp === prefix_optional
  215. prefix_pat = prefix_optional
  216. else
  217. prefix_pat = /\A#{Regexp.escape prefix_optional}/
  218. end
  219. end
  220. hash_var = "#{func_name}_hash"
  221. vardef = "static st_table *#{hash_var};"
  222. gen_hash = gen_int_to_name_hash(hash_var, pat, prefix_pat)
  223. decl = gen_int_to_name_decl(func_name, hash_var)
  224. func = gen_int_to_name_func(func_name, hash_var)
  225. INTERN_DEFS << [vardef, gen_hash, decl, func]
  226. end
  227. def_name_to_int("rsock_family_to_int", /\A(AF_|PF_)/, "AF_")
  228. def_name_to_int("rsock_socktype_to_int", /\ASOCK_/, "SOCK_")
  229. def_name_to_int("rsock_ipproto_to_int", /\AIPPROTO_/, "IPPROTO_")
  230. def_name_to_int("rsock_unknown_level_to_int", /\ASOL_SOCKET\z/, "SOL_")
  231. def_name_to_int("rsock_ip_level_to_int", /\A(SOL_SOCKET\z|IPPROTO_)/, /\A(SOL_|IPPROTO_)/)
  232. def_name_to_int("rsock_so_optname_to_int", /\ASO_/, "SO_")
  233. def_name_to_int("rsock_ip_optname_to_int", /\AIP_/, "IP_")
  234. def_name_to_int("rsock_ipv6_optname_to_int", /\AIPV6_/, "IPV6_", "IPPROTO_IPV6")
  235. def_name_to_int("rsock_tcp_optname_to_int", /\ATCP_/, "TCP_")
  236. def_name_to_int("rsock_udp_optname_to_int", /\AUDP_/, "UDP_")
  237. def_name_to_int("rsock_shutdown_how_to_int", /\ASHUT_/, "SHUT_")
  238. def_name_to_int("rsock_scm_optname_to_int", /\ASCM_/, "SCM_")
  239. def_intern('rsock_intern_family', /\AAF_/)
  240. def_intern('rsock_intern_family_noprefix', /\AAF_/, "AF_")
  241. def_intern('rsock_intern_protocol_family', /\APF_/)
  242. def_intern('rsock_intern_socktype', /\ASOCK_/)
  243. def_intern('rsock_intern_ipproto', /\AIPPROTO_/)
  244. def_intern('rsock_intern_iplevel', /\A(SOL_SOCKET\z|IPPROTO_)/, /\A(SOL_|IPPROTO_)/)
  245. def_intern('rsock_intern_so_optname', /\ASO_/, "SO_")
  246. def_intern('rsock_intern_ip_optname', /\AIP_/, "IP_")
  247. def_intern('rsock_intern_ipv6_optname', /\AIPV6_/, "IPV6_")
  248. def_intern('rsock_intern_tcp_optname', /\ATCP_/, "TCP_")
  249. def_intern('rsock_intern_udp_optname', /\AUDP_/, "UDP_")
  250. def_intern('rsock_intern_scm_optname', /\ASCM_/, "SCM_")
  251. def_intern('rsock_intern_local_optname', /\ALOCAL_/, "LOCAL_")
  252. result = erb_new.call(<<'EOS', nil, '%').result(binding)
  253. /* autogenerated file */
  254. <%= INTERN_DEFS.map {|vardef, gen_hash, decl, func| vardef }.join("\n") %>
  255. #ifdef HAVE_LONG_LONG
  256. #define INTEGER2NUM(n) \
  257. (FIXNUM_MAX < (n) ? ULL2NUM(n) : \
  258. FIXNUM_MIN > (LONG_LONG)(n) ? LL2NUM(n) : \
  259. LONG2FIX(n))
  260. #else
  261. #define INTEGER2NUM(n) \
  262. (FIXNUM_MAX < (n) ? ULONG2NUM(n) : \
  263. FIXNUM_MIN > (long)(n) ? LONG2NUM(n) : \
  264. LONG2FIX(n))
  265. #endif
  266. static void
  267. init_constants(void)
  268. {
  269. /*
  270. * Document-module: Socket::Constants
  271. *
  272. * Socket::Constants provides socket-related constants. All possible
  273. * socket constants are listed in the documentation but they may not all
  274. * be present on your platform.
  275. *
  276. * If the underlying platform doesn't define a constant the corresponding
  277. * Ruby constant is not defined.
  278. *
  279. */
  280. rb_mSockConst = rb_define_module_under(rb_cSocket, "Constants");
  281. <%= gen_const_defs %>
  282. <%= INTERN_DEFS.map {|vardef, gen_hash, decl, func| gen_hash }.join("\n") %>
  283. }
  284. <%= NAME_TO_INT_DEFS.map {|decl, func| func }.join("\n") %>
  285. <%= INTERN_DEFS.map {|vardef, gen_hash, decl, func| func }.join("\n") %>
  286. EOS
  287. header_result = erb_new.call(<<'EOS', nil, '%').result(binding)
  288. /* autogenerated file */
  289. <%= gen_const_decls %>
  290. <%= NAME_TO_INT_DEFS.map {|decl, func| decl }.join("\n") %>
  291. <%= INTERN_DEFS.map {|vardef, gen_hash, decl, func| decl }.join("\n") %>
  292. EOS
  293. if opt_H
  294. File.open(opt_H, 'w') {|f|
  295. f << header_result
  296. }
  297. else
  298. result = header_result + result
  299. end
  300. if opt_o
  301. File.open(opt_o, 'w') {|f|
  302. f << result
  303. }
  304. else
  305. $stdout << result
  306. end
  307. __END__
  308. SOCK_STREAM nil A stream socket provides a sequenced, reliable two-way connection for a byte stream
  309. SOCK_DGRAM nil A datagram socket provides connectionless, unreliable messaging
  310. SOCK_RAW nil A raw socket provides low-level access for direct access or implementing network protocols
  311. SOCK_RDM nil A reliable datagram socket provides reliable delivery of messages
  312. SOCK_SEQPACKET nil A sequential packet socket provides sequenced, reliable two-way connection for datagrams
  313. SOCK_PACKET nil Device-level packet access
  314. AF_UNSPEC nil Unspecified protocol, any supported address family
  315. PF_UNSPEC nil Unspecified protocol, any supported address family
  316. AF_INET nil IPv4 protocol
  317. PF_INET nil IPv4 protocol
  318. AF_INET6 nil IPv6 protocol
  319. PF_INET6 nil IPv6 protocol
  320. AF_UNIX nil UNIX sockets
  321. PF_UNIX nil UNIX sockets
  322. AF_AX25 nil AX.25 protocol
  323. PF_AX25 nil AX.25 protocol
  324. AF_IPX nil IPX protocol
  325. PF_IPX nil IPX protocol
  326. AF_APPLETALK nil AppleTalk protocol
  327. PF_APPLETALK nil AppleTalk protocol
  328. AF_LOCAL nil Host-internal protocols
  329. PF_LOCAL nil Host-internal protocols
  330. AF_IMPLINK nil ARPANET IMP protocol
  331. PF_IMPLINK nil ARPANET IMP protocol
  332. AF_PUP nil PARC Universal Packet protocol
  333. PF_PUP nil PARC Universal Packet protocol
  334. AF_CHAOS nil MIT CHAOS protocols
  335. PF_CHAOS nil MIT CHAOS protocols
  336. AF_NS nil XEROX NS protocols
  337. PF_NS nil XEROX NS protocols
  338. AF_ISO nil ISO Open Systems Interconnection protocols
  339. PF_ISO nil ISO Open Systems Interconnection protocols
  340. AF_OSI nil ISO Open Systems Interconnection protocols
  341. PF_OSI nil ISO Open Systems Interconnection protocols
  342. AF_ECMA nil European Computer Manufacturers protocols
  343. PF_ECMA nil European Computer Manufacturers protocols
  344. AF_DATAKIT nil Datakit protocol
  345. PF_DATAKIT nil Datakit protocol
  346. AF_CCITT nil CCITT (now ITU-T) protocols
  347. PF_CCITT nil CCITT (now ITU-T) protocols
  348. AF_SNA nil IBM SNA protocol
  349. PF_SNA nil IBM SNA protocol
  350. AF_DEC nil DECnet protocol
  351. PF_DEC nil DECnet protocol
  352. AF_DLI nil DEC Direct Data Link Interface protocol
  353. PF_DLI nil DEC Direct Data Link Interface protocol
  354. AF_LAT nil Local Area Transport protocol
  355. PF_LAT nil Local Area Transport protocol
  356. AF_HYLINK nil NSC Hyperchannel protocol
  357. PF_HYLINK nil NSC Hyperchannel protocol
  358. AF_ROUTE nil Internal routing protocol
  359. PF_ROUTE nil Internal routing protocol
  360. AF_LINK nil Link layer interface
  361. PF_LINK nil Link layer interface
  362. AF_COIP nil Connection-oriented IP
  363. PF_COIP nil Connection-oriented IP
  364. AF_CNT nil Computer Network Technology
  365. PF_CNT nil Computer Network Technology
  366. AF_SIP nil Simple Internet Protocol
  367. PF_SIP nil Simple Internet Protocol
  368. AF_NDRV nil Network driver raw access
  369. PF_NDRV nil Network driver raw access
  370. AF_ISDN nil Integrated Services Digital Network
  371. PF_ISDN nil Integrated Services Digital Network
  372. AF_NATM nil Native ATM access
  373. PF_NATM nil Native ATM access
  374. AF_SYSTEM
  375. PF_SYSTEM
  376. AF_NETBIOS nil NetBIOS
  377. PF_NETBIOS nil NetBIOS
  378. AF_PPP nil Point-to-Point Protocol
  379. PF_PPP nil Point-to-Point Protocol
  380. AF_ATM nil Asynchronous Transfer Mode
  381. PF_ATM nil Asynchronous Transfer Mode
  382. AF_NETGRAPH nil Netgraph sockets
  383. PF_NETGRAPH nil Netgraph sockets
  384. AF_MAX nil Maximum address family for this platform
  385. PF_MAX nil Maximum address family for this platform
  386. AF_PACKET nil Direct link-layer access
  387. PF_PACKET nil Direct link-layer access
  388. AF_E164 nil CCITT (ITU-T) E.164 recommendation
  389. PF_XTP nil eXpress Transfer Protocol
  390. PF_RTIP
  391. PF_PIP
  392. PF_KEY
  393. MSG_OOB nil Process out-of-band data
  394. MSG_PEEK nil Peek at incoming message
  395. MSG_DONTROUTE nil Send without using the routing tables
  396. MSG_EOR nil Data completes record
  397. MSG_TRUNC nil Data discarded before delivery
  398. MSG_CTRUNC nil Control data lost before delivery
  399. MSG_WAITALL nil Wait for full request or error
  400. MSG_DONTWAIT nil This message should be non-blocking
  401. MSG_EOF nil Data completes connection
  402. MSG_FLUSH nil Start of a hold sequence. Dumps to so_temp
  403. MSG_HOLD nil Hold fragment in so_temp
  404. MSG_SEND nil Send the packet in so_temp
  405. MSG_HAVEMORE nil Data ready to be read
  406. MSG_RCVMORE nil Data remains in the current packet
  407. MSG_COMPAT nil End of record
  408. MSG_PROXY nil Wait for full request
  409. MSG_FIN
  410. MSG_SYN
  411. MSG_CONFIRM nil Confirm path validity
  412. MSG_RST
  413. MSG_ERRQUEUE nil Fetch message from error queue
  414. MSG_NOSIGNAL nil Do not generate SIGPIPE
  415. MSG_MORE nil Sender will send more
  416. MSG_FASTOPEN nil Reduce step of the handshake process
  417. SOL_SOCKET nil Socket-level options
  418. SOL_IP nil IP socket options
  419. SOL_IPX nil IPX socket options
  420. SOL_AX25 nil AX.25 socket options
  421. SOL_ATALK nil AppleTalk socket options
  422. SOL_TCP nil TCP socket options
  423. SOL_UDP nil UDP socket options
  424. IPPROTO_IP 0 Dummy protocol for IP
  425. IPPROTO_ICMP 1 Control message protocol
  426. IPPROTO_IGMP nil Group Management Protocol
  427. IPPROTO_GGP nil Gateway to Gateway Protocol
  428. IPPROTO_TCP 6 TCP
  429. IPPROTO_EGP nil Exterior Gateway Protocol
  430. IPPROTO_PUP nil PARC Universal Packet protocol
  431. IPPROTO_UDP 17 UDP
  432. IPPROTO_IDP nil XNS IDP
  433. IPPROTO_HELLO nil "hello" routing protocol
  434. IPPROTO_ND nil Sun net disk protocol
  435. IPPROTO_TP nil ISO transport protocol class 4
  436. IPPROTO_XTP nil Xpress Transport Protocol
  437. IPPROTO_EON nil ISO cnlp
  438. IPPROTO_BIP
  439. IPPROTO_AH nil IP6 auth header
  440. IPPROTO_DSTOPTS nil IP6 destination option
  441. IPPROTO_ESP nil IP6 Encapsulated Security Payload
  442. IPPROTO_FRAGMENT nil IP6 fragmentation header
  443. IPPROTO_HOPOPTS nil IP6 hop-by-hop options
  444. IPPROTO_ICMPV6 nil ICMP6
  445. IPPROTO_IPV6 nil IP6 header
  446. IPPROTO_NONE nil IP6 no next header
  447. IPPROTO_ROUTING nil IP6 routing header
  448. IPPROTO_RAW 255 Raw IP packet
  449. IPPROTO_MAX nil Maximum IPPROTO constant
  450. # Some port configuration
  451. IPPORT_RESERVED 1024 Default minimum address for bind or connect
  452. IPPORT_USERRESERVED 5000 Default maximum address for bind or connect
  453. # Some reserved IP v.4 addresses
  454. INADDR_ANY 0x00000000 A socket bound to INADDR_ANY receives packets from all interfaces and sends from the default IP address
  455. INADDR_BROADCAST 0xffffffff The network broadcast address
  456. INADDR_LOOPBACK 0x7F000001 The loopback address
  457. INADDR_UNSPEC_GROUP 0xe0000000 The reserved multicast group
  458. INADDR_ALLHOSTS_GROUP 0xe0000001 Multicast group for all systems on this subset
  459. INADDR_MAX_LOCAL_GROUP 0xe00000ff The last local network multicast group
  460. INADDR_NONE 0xffffffff A bitmask for matching no valid IP address
  461. # IP [gs]etsockopt options
  462. IP_OPTIONS nil IP options to be included in packets
  463. IP_HDRINCL nil Header is included with data
  464. IP_TOS nil IP type-of-service
  465. IP_TTL nil IP time-to-live
  466. IP_RECVOPTS nil Receive all IP options with datagram
  467. IP_RECVRETOPTS nil Receive all IP options for response
  468. IP_RECVDSTADDR nil Receive IP destination address with datagram
  469. IP_RETOPTS nil IP options to be included in datagrams
  470. IP_MINTTL nil Minimum TTL allowed for received packets
  471. IP_DONTFRAG nil Don't fragment packets
  472. IP_SENDSRCADDR nil Source address for outgoing UDP datagrams
  473. IP_ONESBCAST nil Force outgoing broadcast datagrams to have the undirected broadcast address
  474. IP_RECVTTL nil Receive IP TTL with datagrams
  475. IP_RECVIF nil Receive interface information with datagrams
  476. IP_RECVSLLA nil Receive link-layer address with datagrams
  477. IP_PORTRANGE nil Set the port range for sockets with unspecified port numbers
  478. IP_MULTICAST_IF nil IP multicast interface
  479. IP_MULTICAST_TTL nil IP multicast TTL
  480. IP_MULTICAST_LOOP nil IP multicast loopback
  481. IP_ADD_MEMBERSHIP nil Add a multicast group membership
  482. IP_DROP_MEMBERSHIP nil Drop a multicast group membership
  483. IP_DEFAULT_MULTICAST_TTL nil Default multicast TTL
  484. IP_DEFAULT_MULTICAST_LOOP nil Default multicast loopback
  485. IP_MAX_MEMBERSHIPS nil Maximum number multicast groups a socket can join
  486. IP_ROUTER_ALERT nil Notify transit routers to more closely examine the contents of an IP packet
  487. IP_PKTINFO nil Receive packet information with datagrams
  488. IP_PKTOPTIONS nil Receive packet options with datagrams
  489. IP_MTU_DISCOVER nil Path MTU discovery
  490. IP_RECVERR nil Enable extended reliable error message passing
  491. IP_RECVTOS nil Receive TOS with incoming packets
  492. IP_MTU nil The Maximum Transmission Unit of the socket
  493. IP_FREEBIND nil Allow binding to nonexistent IP addresses
  494. IP_IPSEC_POLICY nil IPsec security policy
  495. IP_XFRM_POLICY
  496. IP_PASSSEC nil Retrieve security context with datagram
  497. IP_TRANSPARENT nil Transparent proxy
  498. IP_PMTUDISC_DONT nil Never send DF frames
  499. IP_PMTUDISC_WANT nil Use per-route hints
  500. IP_PMTUDISC_DO nil Always send DF frames
  501. IP_UNBLOCK_SOURCE nil Unblock IPv4 multicast packets with a give source address
  502. IP_BLOCK_SOURCE nil Block IPv4 multicast packets with a give source address
  503. IP_ADD_SOURCE_MEMBERSHIP nil Add a multicast group membership
  504. IP_DROP_SOURCE_MEMBERSHIP nil Drop a multicast group membership
  505. IP_MSFILTER nil Multicast source filtering
  506. MCAST_JOIN_GROUP nil Join a multicast group
  507. MCAST_BLOCK_SOURCE nil Block multicast packets from this source
  508. MCAST_UNBLOCK_SOURCE nil Unblock multicast packets from this source
  509. MCAST_LEAVE_GROUP nil Leave a multicast group
  510. MCAST_JOIN_SOURCE_GROUP nil Join a multicast source group
  511. MCAST_LEAVE_SOURCE_GROUP nil Leave a multicast source group
  512. MCAST_MSFILTER nil Multicast source filtering
  513. MCAST_EXCLUDE nil Exclusive multicast source filter
  514. MCAST_INCLUDE nil Inclusive multicast source filter
  515. SO_DEBUG nil Debug info recording
  516. SO_REUSEADDR nil Allow local address reuse
  517. SO_REUSEPORT nil Allow local address and port reuse
  518. SO_TYPE nil Get the socket type
  519. SO_ERROR nil Get and clear the error status
  520. SO_DONTROUTE nil Use interface addresses
  521. SO_BROADCAST nil Permit sending of broadcast messages
  522. SO_SNDBUF nil Send buffer size
  523. SO_RCVBUF nil Receive buffer size
  524. SO_SNDBUFFORCE nil Send buffer size without wmem_max limit (Linux 2.6.14)
  525. SO_RCVBUFFORCE nil Receive buffer size without rmem_max limit (Linux 2.6.14)
  526. SO_KEEPALIVE nil Keep connections alive
  527. SO_OOBINLINE nil Leave received out-of-band data in-line
  528. SO_NO_CHECK nil Disable checksums
  529. SO_PRIORITY nil The protocol-defined priority for all packets on this socket
  530. SO_LINGER nil Linger on close if data is present
  531. SO_PASSCRED nil Receive SCM_CREDENTIALS messages
  532. SO_PEERCRED nil The credentials of the foreign process connected to this socket
  533. SO_RCVLOWAT nil Receive low-water mark
  534. SO_SNDLOWAT nil Send low-water mark
  535. SO_RCVTIMEO nil Receive timeout
  536. SO_SNDTIMEO nil Send timeout
  537. SO_ACCEPTCONN nil Socket has had listen() called on it
  538. SO_USELOOPBACK nil Bypass hardware when possible
  539. SO_ACCEPTFILTER nil There is an accept filter
  540. SO_DONTTRUNC nil Retain unread data
  541. SO_WANTMORE nil Give a hint when more data is ready
  542. SO_WANTOOBFLAG nil OOB data is wanted in MSG_FLAG on receive
  543. SO_NREAD nil Get first packet byte count
  544. SO_NKE nil Install socket-level Network Kernel Extension
  545. SO_NOSIGPIPE nil Don't SIGPIPE on EPIPE
  546. SO_SECURITY_AUTHENTICATION
  547. SO_SECURITY_ENCRYPTION_TRANSPORT
  548. SO_SECURITY_ENCRYPTION_NETWORK
  549. SO_BINDTODEVICE nil Only send packets from the given interface
  550. SO_ATTACH_FILTER nil Attach an accept filter
  551. SO_DETACH_FILTER nil Detach an accept filter
  552. SO_GET_FILTER nil Obtain filter set by SO_ATTACH_FILTER (Linux 3.8)
  553. SO_PEERNAME nil Name of the connecting user
  554. SO_TIMESTAMP nil Receive timestamp with datagrams (timeval)
  555. SO_TIMESTAMPNS nil Receive nanosecond timestamp with datagrams (timespec)
  556. SO_BINTIME nil Receive timestamp with datagrams (bintime)
  557. SO_RECVUCRED nil Receive user credentials with datagram
  558. SO_MAC_EXEMPT nil Mandatory Access Control exemption for unlabeled peers
  559. SO_ALLZONES nil Bypass zone boundaries
  560. SO_PEERSEC nil Obtain the security credentials (Linux 2.6.2)
  561. SO_PASSSEC nil Toggle security context passing (Linux 2.6.18)
  562. SO_MARK nil Set the mark for mark-based routing (Linux 2.6.25)
  563. SO_TIMESTAMPING nil Time stamping of incoming and outgoing packets (Linux 2.6.30)
  564. SO_PROTOCOL nil Protocol given for socket() (Linux 2.6.32)
  565. SO_DOMAIN nil Domain given for socket() (Linux 2.6.32)
  566. SO_RXQ_OVFL nil Toggle cmsg for number of packets dropped (Linux 2.6.33)
  567. SO_WIFI_STATUS nil Toggle cmsg for wifi status (Linux 3.3)
  568. SO_PEEK_OFF nil Set the peek offset (Linux 3.4)
  569. SO_NOFCS nil Set netns of a socket (Linux 3.4)
  570. SO_LOCK_FILTER nil Lock the filter attached to a socket (Linux 3.9)
  571. SO_SELECT_ERR_QUEUE nil Make select() detect socket error queue with errorfds (Linux 3.10)
  572. SO_BUSY_POLL nil Set the threshold in microseconds for low latency polling (Linux 3.11)
  573. SO_MAX_PACING_RATE nil Cap the rate computed by transport layer. [bytes per second] (Linux 3.13)
  574. SO_BPF_EXTENSIONS nil Query supported BPF extensions (Linux 3.14)
  575. SOPRI_INTERACTIVE nil Interactive socket priority
  576. SOPRI_NORMAL nil Normal socket priority
  577. SOPRI_BACKGROUND nil Background socket priority
  578. IPX_TYPE
  579. TCP_NODELAY nil Don't delay sending to coalesce packets
  580. TCP_MAXSEG nil Set maximum segment size
  581. TCP_CORK nil Don't send partial frames (Linux 2.2, glibc 2.2)
  582. TCP_DEFER_ACCEPT nil Don't notify a listening socket until data is ready (Linux 2.4, glibc 2.2)
  583. TCP_INFO nil Retrieve information about this socket (Linux 2.4, glibc 2.2)
  584. TCP_KEEPCNT nil Maximum number of keepalive probes allowed before dropping a connection (Linux 2.4, glibc 2.2)
  585. TCP_KEEPIDLE nil Idle time before keepalive probes are sent (Linux 2.4, glibc 2.2)
  586. TCP_KEEPINTVL nil Time between keepalive probes (Linux 2.4, glibc 2.2)
  587. TCP_LINGER2 nil Lifetime of orphaned FIN_WAIT2 sockets (Linux 2.4, glibc 2.2)
  588. TCP_MD5SIG nil Use MD5 digests (RFC2385, Linux 2.6.20, glibc 2.7)
  589. TCP_NOOPT nil Don't use TCP options
  590. TCP_NOPUSH nil Don't push the last block of write
  591. TCP_QUICKACK nil Enable quickack mode (Linux 2.4.4, glibc 2.3)
  592. TCP_SYNCNT nil Number of SYN retransmits before a connection is dropped (Linux 2.4, glibc 2.2)
  593. TCP_WINDOW_CLAMP nil Clamp the size of the advertised window (Linux 2.4, glibc 2.2)
  594. TCP_FASTOPEN nil Reduce step of the handshake process (Linux 3.7, glibc 2.18)
  595. TCP_CONGESTION nil TCP congestion control algorithm (Linux 2.6.13, glibc 2.6)
  596. TCP_COOKIE_TRANSACTIONS nil TCP Cookie Transactions (Linux 2.6.33, glibc 2.18)
  597. TCP_QUEUE_SEQ nil Sequence of a queue for repair mode (Linux 3.5, glibc 2.18)
  598. TCP_REPAIR nil Repair mode (Linux 3.5, glibc 2.18)
  599. TCP_REPAIR_OPTIONS nil Options for repair mode (Linux 3.5, glibc 2.18)
  600. TCP_REPAIR_QUEUE nil Queue for repair mode (Linux 3.5, glibc 2.18)
  601. TCP_THIN_DUPACK nil Duplicated acknowledgments handling for thin-streams (Linux 2.6.34, glibc 2.18)
  602. TCP_THIN_LINEAR_TIMEOUTS nil Linear timeouts for thin-streams (Linux 2.6.34, glibc 2.18)
  603. TCP_TIMESTAMP nil TCP timestamp (Linux 3.9, glibc 2.18)
  604. TCP_USER_TIMEOUT nil Max timeout before a TCP connection is aborted (Linux 2.6.37, glibc 2.18)
  605. UDP_CORK nil Don't send partial frames (Linux 2.5.44, glibc 2.11)
  606. EAI_ADDRFAMILY nil Address family for hostname not supported
  607. EAI_AGAIN nil Temporary failure in name resolution
  608. EAI_BADFLAGS nil Invalid flags
  609. EAI_FAIL nil Non-recoverable failure in name resolution
  610. EAI_FAMILY nil Address family not supported
  611. EAI_MEMORY nil Memory allocation failure
  612. EAI_NODATA nil No address associated with hostname
  613. EAI_NONAME nil Hostname nor servname, or not known
  614. EAI_OVERFLOW nil Argument buffer overflow
  615. EAI_SERVICE nil Servname not supported for socket type
  616. EAI_SOCKTYPE nil Socket type not supported
  617. EAI_SYSTEM nil System error returned in errno
  618. EAI_BADHINTS nil Invalid value for hints
  619. EAI_PROTOCOL nil Resolved protocol is unknown
  620. EAI_MAX nil Maximum error code from getaddrinfo
  621. AI_PASSIVE nil Get address to use with bind()
  622. AI_CANONNAME nil Fill in the canonical name
  623. AI_NUMERICHOST nil Prevent host name resolution
  624. AI_NUMERICSERV nil Prevent service name resolution
  625. AI_MASK nil Valid flag mask for getaddrinfo (not for application use)
  626. AI_ALL nil Allow all addresses
  627. AI_V4MAPPED_CFG nil Accept IPv4 mapped addresses if the kernel supports it
  628. AI_ADDRCONFIG nil Accept only if any address is assigned
  629. AI_V4MAPPED nil Accept IPv4-mapped IPv6 addresses
  630. AI_DEFAULT nil Default flags for getaddrinfo
  631. NI_MAXHOST nil Maximum length of a hostname
  632. NI_MAXSERV nil Maximum length of a service name
  633. NI_NOFQDN nil An FQDN is not required for local hosts, return only the local part
  634. NI_NUMERICHOST nil Return a numeric address
  635. NI_NAMEREQD nil A name is required
  636. NI_NUMERICSERV nil Return the service name as a digit string
  637. NI_DGRAM nil The service specified is a datagram service (looks up UDP ports)
  638. SHUT_RD 0 Shut down the reading side of the socket
  639. SHUT_WR 1 Shut down the writing side of the socket
  640. SHUT_RDWR 2 Shut down the both sides of the socket
  641. IPV6_JOIN_GROUP nil Join a group membership
  642. IPV6_LEAVE_GROUP nil Leave a group membership
  643. IPV6_MULTICAST_HOPS nil IP6 multicast hops
  644. IPV6_MULTICAST_IF nil IP6 multicast interface
  645. IPV6_MULTICAST_LOOP nil IP6 multicast loopback
  646. IPV6_UNICAST_HOPS nil IP6 unicast hops
  647. IPV6_V6ONLY nil Only bind IPv6 with a wildcard bind
  648. IPV6_CHECKSUM nil Checksum offset for raw sockets
  649. IPV6_DONTFRAG nil Don't fragment packets
  650. IPV6_DSTOPTS nil Destination option
  651. IPV6_HOPLIMIT nil Hop limit
  652. IPV6_HOPOPTS nil Hop-by-hop option
  653. IPV6_NEXTHOP nil Next hop address
  654. IPV6_PATHMTU nil Retrieve current path MTU
  655. IPV6_PKTINFO nil Receive packet information with datagram
  656. IPV6_RECVDSTOPTS nil Receive all IP6 options for response
  657. IPV6_RECVHOPLIMIT nil Receive hop limit with datagram
  658. IPV6_RECVHOPOPTS nil Receive hop-by-hop options
  659. IPV6_RECVPKTINFO nil Receive destination IP address and incoming interface
  660. IPV6_RECVRTHDR nil Receive routing header
  661. IPV6_RECVTCLASS nil Receive traffic class
  662. IPV6_RTHDR nil Allows removal of sticky routing headers
  663. IPV6_RTHDRDSTOPTS nil Allows removal of sticky destination options header
  664. IPV6_RTHDR_TYPE_0 nil Routing header type 0
  665. IPV6_RECVPATHMTU nil Receive current path MTU with datagram
  666. IPV6_TCLASS nil Specify the traffic class
  667. IPV6_USE_MIN_MTU nil Use the minimum MTU size
  668. INET_ADDRSTRLEN 16 Maximum length of an IPv4 address string
  669. INET6_ADDRSTRLEN 46 Maximum length of an IPv6 address string
  670. IFNAMSIZ nil Maximum interface name size
  671. IF_NAMESIZE nil Maximum interface name size
  672. SOMAXCONN 5 Maximum connection requests that may be queued for a socket
  673. SCM_RIGHTS nil Access rights
  674. SCM_TIMESTAMP nil Timestamp (timeval)
  675. SCM_TIMESTAMPNS nil Timespec (timespec)
  676. SCM_TIMESTAMPING nil Timestamp (timespec list) (Linux 2.6.30)
  677. SCM_BINTIME nil Timestamp (bintime)
  678. SCM_CREDENTIALS nil The sender's credentials
  679. SCM_CREDS nil Process credentials
  680. SCM_UCRED nil User credentials
  681. SCM_WIFI_STATUS nil Wifi status (Linux 3.3)
  682. LOCAL_PEERCRED nil Retrieve peer credentials
  683. LOCAL_CREDS nil Pass credentials to receiver
  684. LOCAL_CONNWAIT nil Connect blocks until accepted
  685. IFF_802_1Q_VLAN nil 802.1Q VLAN device
  686. IFF_ALLMULTI nil receive all multicast packets
  687. IFF_ALTPHYS nil use alternate physical connection
  688. IFF_AUTOMEDIA nil auto media select active
  689. IFF_BONDING nil bonding master or slave
  690. IFF_BRIDGE_PORT nil device used as bridge port
  691. IFF_BROADCAST nil broadcast address valid
  692. IFF_CANTCONFIG nil unconfigurable using ioctl(2)
  693. IFF_DEBUG nil turn on debugging
  694. IFF_DISABLE_NETPOLL nil disable netpoll at run-time
  695. IFF_DONT_BRIDGE nil disallow bridging this ether dev
  696. IFF_DORMANT nil driver signals dormant
  697. IFF_DRV_OACTIVE nil tx hardware queue is full
  698. IFF_DRV_RUNNING nil resources allocated
  699. IFF_DYING nil interface is winding down
  700. IFF_DYNAMIC nil dialup device with changing addresses
  701. IFF_EBRIDGE nil ethernet bridging device
  702. IFF_ECHO nil echo sent packets
  703. IFF_ISATAP nil ISATAP interface (RFC4214)
  704. IFF_LINK0 nil per link layer defined bit 0
  705. IFF_LINK1 nil per link layer defined bit 1
  706. IFF_LINK2 nil per link layer defined bit 2
  707. IFF_LIVE_ADDR_CHANGE nil hardware address change when it's running
  708. IFF_LOOPBACK nil loopback net
  709. IFF_LOWER_UP nil driver signals L1 up
  710. IFF_MACVLAN_PORT nil device used as macvlan port
  711. IFF_MASTER nil master of a load balancer
  712. IFF_MASTER_8023AD nil bonding master, 802.3ad.
  713. IFF_MASTER_ALB nil bonding master, balance-alb.
  714. IFF_MASTER_ARPMON nil bonding master, ARP mon in use
  715. IFF_MONITOR nil user-requested monitor mode
  716. IFF_MULTICAST nil supports multicast
  717. IFF_NOARP nil no address resolution protocol
  718. IFF_NOTRAILERS nil avoid use of trailers
  719. IFF_OACTIVE nil transmission in progress
  720. IFF_OVS_DATAPATH nil device used as Open vSwitch datapath port
  721. IFF_POINTOPOINT nil point-to-point link
  722. IFF_PORTSEL nil can set media type
  723. IFF_PPROMISC nil user-requested promisc mode
  724. IFF_PROMISC nil receive all packets
  725. IFF_RENAMING nil interface is being renamed
  726. IFF_ROUTE nil routing entry installed
  727. IFF_RUNNING nil resources allocated
  728. IFF_SIMPLEX nil can't hear own transmissions
  729. IFF_SLAVE nil slave of a load balancer
  730. IFF_SLAVE_INACTIVE nil bonding slave not the curr. active
  731. IFF_SLAVE_NEEDARP nil need ARPs for validation
  732. IFF_SMART nil interface manages own routes
  733. IFF_STATICARP nil static ARP
  734. IFF_SUPP_NOFCS nil sending custom FCS
  735. IFF_TEAM_PORT nil used as team port
  736. IFF_TX_SKB_SHARING nil sharing skbs on transmit
  737. IFF_UNICAST_FLT nil unicast filtering
  738. IFF_UP nil interface is up
  739. IFF_WAN_HDLC nil WAN HDLC device
  740. IFF_XMIT_DST_RELEASE nil dev_hard_start_xmit() is allowed to release skb->dst
  741. IFF_VOLATILE nil volatile flags
  742. IFF_CANTCHANGE nil flags not changeable