diff options
Diffstat (limited to 'ext/socket/mkconstants.rb')
| -rw-r--r-- | ext/socket/mkconstants.rb | 143 |
1 files changed, 112 insertions, 31 deletions
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb index d12b2a24e3..4271e40cd8 100644 --- a/ext/socket/mkconstants.rb +++ b/ext/socket/mkconstants.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require 'optparse' require 'erb' @@ -50,7 +51,10 @@ DATA.each_line {|s| next end h[name] = default_value - COMMENTS[name] = comment + if comment + # Stop unintentional references + COMMENTS[name] = comment.gsub(/\b(Data|Kernel|Process|Set|Socket|Time)\b/, '\\\\\\&') + end } DEFS = h.to_a @@ -72,7 +76,11 @@ def each_name(pat) } end -ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_const_decls") +erb_new = lambda do |src, trim| + ERB.new(src, trim_mode: trim) +end + +erb_new.call(<<'EOS', '%').def_method(Object, "gen_const_decls") % each_const {|guard, name, default_value| #if !defined(<%=name%>) # if defined(HAVE_CONST_<%=name.upcase%>) @@ -86,7 +94,7 @@ ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_const_decls") % } EOS -ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_const_defs_in_guard(name, default_value)") +erb_new.call(<<'EOS', '%').def_method(Object, "gen_const_defs_in_guard(name, default_value)") #if defined(<%=name%>) /* <%= COMMENTS[name] %> */ rb_define_const(rb_cSocket, <%=c_str name%>, INTEGER2NUM(<%=name%>)); @@ -95,7 +103,7 @@ ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_const_defs_in_guard(name, def #endif EOS -ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_const_defs") +erb_new.call(<<'EOS', '%').def_method(Object, "gen_const_defs") % each_const {|guard, name, default_value| % if guard #if <%=guard%> @@ -145,7 +153,7 @@ def each_names_with_len(pat, prefix_optional=nil) } end -ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_decl(funcname, pat, prefix_optional, guard=nil)") +erb_new.call(<<'EOS', '%').def_method(Object, "gen_name_to_int_decl(funcname, pat, prefix_optional, guard=nil)") %if guard #ifdef <%=guard%> int <%=funcname%>(const char *str, long len, int *valp); @@ -155,7 +163,7 @@ int <%=funcname%>(const char *str, long len, int *valp); %end EOS -ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_func_in_guard(funcname, pat, prefix_optional, guard=nil)") +erb_new.call(<<'EOS', '%').def_method(Object, "gen_name_to_int_func_in_guard(funcname, pat, prefix_optional, guard=nil)") int <%=funcname%>(const char *str, long len, int *valp) { @@ -171,12 +179,13 @@ int % } default: + if (!str || !valp) {/* wrong argument */} return -1; } } EOS -ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_func(funcname, pat, prefix_optional, guard=nil)") +erb_new.call(<<'EOS', '%').def_method(Object, "gen_name_to_int_func(funcname, pat, prefix_optional, guard=nil)") %if guard #ifdef <%=guard%> <%=gen_name_to_int_func_in_guard(funcname, pat, prefix_optional, guard)%> @@ -205,7 +214,7 @@ def reverse_each_name_with_prefix_optional(pat, prefix_pat) end end -ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_int_to_name_hash(hash_var, pat, prefix_pat)") +erb_new.call(<<'EOS', '%').def_method(Object, "gen_int_to_name_hash(hash_var, pat, prefix_pat)") <%=hash_var%> = st_init_numtable(); % reverse_each_name_with_prefix_optional(pat, prefix_pat) {|n,s| #ifdef <%=n%> @@ -214,7 +223,7 @@ ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_int_to_name_hash(hash_var, pa % } EOS -ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_int_to_name_func(func_name, hash_var)") +erb_new.call(<<'EOS', '%').def_method(Object, "gen_int_to_name_func(func_name, hash_var)") ID <%=func_name%>(int val) { @@ -225,7 +234,7 @@ ID } EOS -ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_int_to_name_decl(func_name, hash_var)") +erb_new.call(<<'EOS', '%').def_method(Object, "gen_int_to_name_decl(func_name, hash_var)") ID <%=func_name%>(int val); EOS @@ -274,7 +283,7 @@ def_intern('rsock_intern_udp_optname', /\AUDP_/, "UDP_") def_intern('rsock_intern_scm_optname', /\ASCM_/, "SCM_") def_intern('rsock_intern_local_optname', /\ALOCAL_/, "LOCAL_") -result = ERB.new(<<'EOS', nil, '%').result(binding) +result = erb_new.call(<<'EOS', '%').result(binding) /* autogenerated file */ <%= INTERN_DEFS.map {|vardef, gen_hash, decl, func| vardef }.join("\n") %> @@ -317,7 +326,7 @@ init_constants(void) EOS -header_result = ERB.new(<<'EOS', nil, '%').result(binding) +header_result = erb_new.call(<<'EOS', '%').result(binding) /* autogenerated file */ <%= gen_const_decls %> <%= NAME_TO_INT_DEFS.map {|decl, func| decl }.join("\n") %> @@ -348,6 +357,8 @@ SOCK_RAW nil A raw socket provides low-level access for direct access or impleme SOCK_RDM nil A reliable datagram socket provides reliable delivery of messages SOCK_SEQPACKET nil A sequential packet socket provides sequenced, reliable two-way connection for datagrams SOCK_PACKET nil Device-level packet access +SOCK_NONBLOCK nil Set the O_NONBLOCK file status flag on the open file description (see open(2)) referred to by the new file descriptor. +SOCK_CLOEXEC nil Set the close-on-exec (FD_CLOEXEC) flag on the new file descriptor. AF_UNSPEC nil Unspecified protocol, any supported address family PF_UNSPEC nil Unspecified protocol, any supported address family @@ -387,6 +398,8 @@ AF_SNA nil IBM SNA protocol PF_SNA nil IBM SNA protocol AF_DEC nil DECnet protocol PF_DEC nil DECnet protocol +AF_DECnet nil DECnet protocol +PF_DECnet nil DECnet protocol AF_DLI nil DEC Direct Data Link Interface protocol PF_DLI nil DEC Direct Data Link Interface protocol AF_LAT nil Local Area Transport protocol @@ -409,8 +422,8 @@ AF_ISDN nil Integrated Services Digital Network PF_ISDN nil Integrated Services Digital Network AF_NATM nil Native ATM access PF_NATM nil Native ATM access -AF_SYSTEM -PF_SYSTEM +AF_SYSTEM nil Kernel event messages +PF_SYSTEM nil Kernel event messages AF_NETBIOS nil NetBIOS PF_NETBIOS nil NetBIOS AF_PPP nil Point-to-Point Protocol @@ -426,9 +439,36 @@ PF_PACKET nil Direct link-layer access AF_E164 nil CCITT (ITU-T) E.164 recommendation PF_XTP nil eXpress Transfer Protocol -PF_RTIP -PF_PIP -PF_KEY +PF_RTIP nil Help Identify RTIP packets +PF_PIP nil Help Identify PIP packets +AF_KEY nil Key management protocol, originally developed for usage with IPsec +PF_KEY nil Key management protocol, originally developed for usage with IPsec +AF_NETLINK nil Kernel user interface device +PF_NETLINK nil Kernel user interface device +AF_RDS nil Reliable Datagram Sockets (RDS) protocol +PF_RDS nil Reliable Datagram Sockets (RDS) protocol +AF_PPPOX nil Generic PPP transport layer, for setting up L2 tunnels (L2TP and PPPoE) +PF_PPPOX nil Generic PPP transport layer, for setting up L2 tunnels (L2TP and PPPoE) +AF_LLC nil Logical link control (IEEE 802.2 LLC) protocol +PF_LLC nil Logical link control (IEEE 802.2 LLC) protocol +AF_IB nil InfiniBand native addressing +PF_IB nil InfiniBand native addressing +AF_MPLS nil Multiprotocol Label Switching +PF_MPLS nil Multiprotocol Label Switching +AF_CAN nil Controller Area Network automotive bus protocol +PF_CAN nil Controller Area Network automotive bus protocol +AF_TIPC nil TIPC, "cluster domain sockets" protocol +PF_TIPC nil TIPC, "cluster domain sockets" protocol +AF_BLUETOOTH nil Bluetooth low-level socket protocol +PF_BLUETOOTH nil Bluetooth low-level socket protocol +AF_ALG nil Interface to kernel crypto API +PF_ALG nil Interface to kernel crypto API +AF_VSOCK nil VSOCK (originally "VMWare VSockets") protocol for hypervisor-guest communication +PF_VSOCK nil VSOCK (originally "VMWare VSockets") protocol for hypervisor-guest communication +AF_KCM nil KCM (kernel connection multiplexor) interface +PF_KCM nil KCM (kernel connection multiplexor) interface +AF_XDP nil XDP (express data path) interface +PF_XDP nil XDP (express data path) interface MSG_OOB nil Process out-of-band data MSG_PEEK nil Peek at incoming message @@ -540,6 +580,7 @@ IP_FREEBIND nil Allow binding to nonexistent IP addresses IP_IPSEC_POLICY nil IPsec security policy IP_XFRM_POLICY IP_PASSSEC nil Retrieve security context with datagram +IP_TRANSPARENT nil Transparent proxy IP_PMTUDISC_DONT nil Never send DF frames IP_PMTUDISC_WANT nil Use per-route hints IP_PMTUDISC_DO nil Always send DF frames @@ -568,6 +609,8 @@ SO_DONTROUTE nil Use interface addresses SO_BROADCAST nil Permit sending of broadcast messages SO_SNDBUF nil Send buffer size SO_RCVBUF nil Receive buffer size +SO_SNDBUFFORCE nil Send buffer size without wmem_max limit (Linux 2.6.14) +SO_RCVBUFFORCE nil Receive buffer size without rmem_max limit (Linux 2.6.14) SO_KEEPALIVE nil Keep connections alive SO_OOBINLINE nil Leave received out-of-band data in-line SO_NO_CHECK nil Disable checksums @@ -582,6 +625,7 @@ SO_SNDTIMEO nil Send timeout SO_ACCEPTCONN nil Socket has had listen() called on it SO_USELOOPBACK nil Bypass hardware when possible SO_ACCEPTFILTER nil There is an accept filter +SO_USER_COOKIE nil Setting an identifier for ipfw purpose mainly SO_DONTTRUNC nil Retain unread data SO_WANTMORE nil Give a hint when more data is ready SO_WANTOOBFLAG nil OOB data is wanted in MSG_FLAG on receive @@ -594,6 +638,7 @@ SO_SECURITY_ENCRYPTION_NETWORK SO_BINDTODEVICE nil Only send packets from the given interface SO_ATTACH_FILTER nil Attach an accept filter SO_DETACH_FILTER nil Detach an accept filter +SO_GET_FILTER nil Obtain filter set by SO_ATTACH_FILTER (Linux 3.8) SO_PEERNAME nil Name of the connecting user SO_TIMESTAMP nil Receive timestamp with datagrams (timeval) SO_TIMESTAMPNS nil Receive nanosecond timestamp with datagrams (timespec) @@ -601,6 +646,26 @@ SO_BINTIME nil Receive timestamp with datagrams (bintime) SO_RECVUCRED nil Receive user credentials with datagram SO_MAC_EXEMPT nil Mandatory Access Control exemption for unlabeled peers SO_ALLZONES nil Bypass zone boundaries +SO_PEERSEC nil Obtain the security credentials (Linux 2.6.2) +SO_PASSSEC nil Toggle security context passing (Linux 2.6.18) +SO_MARK nil Set the mark for mark-based routing (Linux 2.6.25) +SO_TIMESTAMPING nil Time stamping of incoming and outgoing packets (Linux 2.6.30) +SO_PROTOCOL nil Protocol given for socket() (Linux 2.6.32) +SO_DOMAIN nil Domain given for socket() (Linux 2.6.32) +SO_RXQ_OVFL nil Toggle cmsg for number of packets dropped (Linux 2.6.33) +SO_WIFI_STATUS nil Toggle cmsg for wifi status (Linux 3.3) +SO_PEEK_OFF nil Set the peek offset (Linux 3.4) +SO_NOFCS nil Set netns of a socket (Linux 3.4) +SO_LOCK_FILTER nil Lock the filter attached to a socket (Linux 3.9) +SO_SELECT_ERR_QUEUE nil Make select() detect socket error queue with errorfds (Linux 3.10) +SO_BUSY_POLL nil Set the threshold in microseconds for low latency polling (Linux 3.11) +SO_MAX_PACING_RATE nil Cap the rate computed by transport layer. [bytes per second] (Linux 3.13) +SO_BPF_EXTENSIONS nil Query supported BPF extensions (Linux 3.14) +SO_SETFIB nil Set the associated routing table for the socket (FreeBSD) +SO_RTABLE nil Set the routing table for this socket (OpenBSD) +SO_INCOMING_CPU nil Receive the cpu attached to the socket (Linux 3.19) +SO_INCOMING_NAPI_ID nil Receive the napi ID attached to a RX queue (Linux 4.12) +SO_CONNECT_TIME nil Returns the number of seconds a socket has been connected. This option is only valid for connection-oriented protocols (Windows) SOPRI_INTERACTIVE nil Interactive socket priority SOPRI_NORMAL nil Normal socket priority @@ -610,22 +675,34 @@ IPX_TYPE TCP_NODELAY nil Don't delay sending to coalesce packets TCP_MAXSEG nil Set maximum segment size -TCP_CORK nil Don't send partial frames -TCP_DEFER_ACCEPT nil Don't notify a listening socket until data is ready -TCP_INFO nil Retrieve information about this socket -TCP_KEEPCNT nil Maximum number of keepalive probes allowed before dropping a connection -TCP_KEEPIDLE nil Idle time before keepalive probes are sent -TCP_KEEPINTVL nil Time between keepalive probes -TCP_LINGER2 nil Lifetime of orphaned FIN_WAIT2 sockets -TCP_MD5SIG nil Use MD5 digests (RFC2385) +TCP_CONNECTION_INFO nil Retrieve information about this socket (macOS) +TCP_CORK nil Don't send partial frames (Linux 2.2, glibc 2.2) +TCP_DEFER_ACCEPT nil Don't notify a listening socket until data is ready (Linux 2.4, glibc 2.2) +TCP_INFO nil Retrieve information about this socket (Linux 2.4, glibc 2.2) +TCP_KEEPALIVE nil Idle time before keepalive probes are sent (macOS) +TCP_KEEPCNT nil Maximum number of keepalive probes allowed before dropping a connection (Linux 2.4, glibc 2.2) +TCP_KEEPIDLE nil Idle time before keepalive probes are sent (Linux 2.4, glibc 2.2) +TCP_KEEPINTVL nil Time between keepalive probes (Linux 2.4, glibc 2.2) +TCP_LINGER2 nil Lifetime of orphaned FIN_WAIT2 sockets (Linux 2.4, glibc 2.2) +TCP_MD5SIG nil Use MD5 digests (RFC2385, Linux 2.6.20, glibc 2.7) TCP_NOOPT nil Don't use TCP options TCP_NOPUSH nil Don't push the last block of write -TCP_QUICKACK nil Enable quickack mode -TCP_SYNCNT nil Number of SYN retransmits before a connection is dropped -TCP_WINDOW_CLAMP nil Clamp the size of the advertised window -TCP_FASTOPEN nil Reduce step of the handshake process - -UDP_CORK nil Don't send partial frames +TCP_QUICKACK nil Enable quickack mode (Linux 2.4.4, glibc 2.3) +TCP_SYNCNT nil Number of SYN retransmits before a connection is dropped (Linux 2.4, glibc 2.2) +TCP_WINDOW_CLAMP nil Clamp the size of the advertised window (Linux 2.4, glibc 2.2) +TCP_FASTOPEN nil Reduce step of the handshake process (Linux 3.7, glibc 2.18) +TCP_CONGESTION nil TCP congestion control algorithm (Linux 2.6.13, glibc 2.6) +TCP_COOKIE_TRANSACTIONS nil TCP Cookie Transactions (Linux 2.6.33, glibc 2.18) +TCP_QUEUE_SEQ nil Sequence of a queue for repair mode (Linux 3.5, glibc 2.18) +TCP_REPAIR nil Repair mode (Linux 3.5, glibc 2.18) +TCP_REPAIR_OPTIONS nil Options for repair mode (Linux 3.5, glibc 2.18) +TCP_REPAIR_QUEUE nil Queue for repair mode (Linux 3.5, glibc 2.18) +TCP_THIN_DUPACK nil Duplicated acknowledgments handling for thin-streams (Linux 2.6.34, glibc 2.18) +TCP_THIN_LINEAR_TIMEOUTS nil Linear timeouts for thin-streams (Linux 2.6.34, glibc 2.18) +TCP_TIMESTAMP nil TCP timestamp (Linux 3.9, glibc 2.18) +TCP_USER_TIMEOUT nil Max timeout before a TCP connection is aborted (Linux 2.6.37, glibc 2.18) + +UDP_CORK nil Don't send partial frames (Linux 2.5.44, glibc 2.11) EAI_ADDRFAMILY nil Address family for hostname not supported EAI_AGAIN nil Temporary failure in name resolution @@ -668,6 +745,7 @@ SHUT_RDWR 2 Shut down the both sides of the socket IPV6_JOIN_GROUP nil Join a group membership IPV6_LEAVE_GROUP nil Leave a group membership +IPV6_MTU_DISCOVER nil Path MTU discovery IPV6_MULTICAST_HOPS nil IP6 multicast hops IPV6_MULTICAST_IF nil IP6 multicast interface IPV6_MULTICAST_LOOP nil IP6 multicast loopback @@ -682,6 +760,7 @@ IPV6_NEXTHOP nil Next hop address IPV6_PATHMTU nil Retrieve current path MTU IPV6_PKTINFO nil Receive packet information with datagram IPV6_RECVDSTOPTS nil Receive all IP6 options for response +IPV6_RECVERR nil Enable extended reliable error message passing IPV6_RECVHOPLIMIT nil Receive hop limit with datagram IPV6_RECVHOPOPTS nil Receive hop-by-hop options IPV6_RECVPKTINFO nil Receive destination IP address and incoming interface @@ -704,10 +783,12 @@ SOMAXCONN 5 Maximum connection requests that may be queued for a socket SCM_RIGHTS nil Access rights SCM_TIMESTAMP nil Timestamp (timeval) SCM_TIMESTAMPNS nil Timespec (timespec) +SCM_TIMESTAMPING nil Timestamp (timespec list) (Linux 2.6.30) SCM_BINTIME nil Timestamp (bintime) SCM_CREDENTIALS nil The sender's credentials SCM_CREDS nil Process credentials SCM_UCRED nil User credentials +SCM_WIFI_STATUS nil Wifi status (Linux 3.3) LOCAL_PEERCRED nil Retrieve peer credentials LOCAL_CREDS nil Pass credentials to receiver |
