summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/mkconstants.rb52
-rw-r--r--ext/socket/socket.c25
2 files changed, 74 insertions, 3 deletions
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb
index a4f7569f887..318ffde6782 100644
--- a/ext/socket/mkconstants.rb
+++ b/ext/socket/mkconstants.rb
@@ -157,6 +157,36 @@ level_to_int(char *str, int len, int *valp)
<%= gen_name_to_int("str", "len", "valp", /\A(SOL_SOCKET\z|IPPROTO_)/) %>
}
+static int
+so_optname_to_int(char *str, int len, int *valp)
+{
+<%= gen_name_to_int("str", "len", "valp", /\ASO_/) %>
+}
+
+static int
+ip_optname_to_int(char *str, int len, int *valp)
+{
+<%= gen_name_to_int("str", "len", "valp", /\AIP_/) %>
+}
+
+static int
+ipv6_optname_to_int(char *str, int len, int *valp)
+{
+<%= gen_name_to_int("str", "len", "valp", /\AIPV6_/) %>
+}
+
+static int
+tcp_optname_to_int(char *str, int len, int *valp)
+{
+<%= gen_name_to_int("str", "len", "valp", /\ATCP_/) %>
+}
+
+static int
+udp_optname_to_int(char *str, int len, int *valp)
+{
+<%= gen_name_to_int("str", "len", "valp", /\AUDP_/) %>
+}
+
static char *
family_to_str(int val)
{
@@ -335,6 +365,13 @@ IP_RECVOPTS
IP_RECVRETOPTS
IP_RECVDSTADDR
IP_RETOPTS
+IP_MINTTL
+IP_DONTFRAG
+IP_SENDSRCADDR
+IP_ONESBCAST
+IP_RECVTTL
+IP_RECVIF
+IP_PORTRANGE
IP_MULTICAST_IF
IP_MULTICAST_TTL
IP_MULTICAST_LOOP
@@ -390,6 +427,21 @@ IPX_TYPE
TCP_NODELAY
TCP_MAXSEG
+TCP_CORK
+TCP_DEFER_ACCEPT
+TCP_INFO
+TCP_KEEPCNT
+TCP_KEEPIDLE
+TCP_KEEPINTVL
+TCP_LINGER2
+TCP_MD5SIG
+TCP_NOOPT
+TCP_NOPUSH
+TCP_QUICKACK
+TCP_SYNCNT
+TCP_WINDOW_CLAMP
+
+UDP_CORK
EAI_ADDRFAMILY
EAI_AGAIN
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 7f4564d410e..b50747a5e1b 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -258,7 +258,7 @@ constant_arg(VALUE arg, int (*str_to_int)(char*, int, int*), char *errmsg)
rb_check_safe_obj(arg);
ptr = RSTRING_PTR(arg);
if (str_to_int(ptr, RSTRING_LEN(arg), &ret) == -1)
- rb_raise(rb_eSocket, "%s %s", errmsg, ptr);
+ rb_raise(rb_eSocket, "%s: %s", errmsg, ptr);
}
else {
ret = NUM2INT(arg);
@@ -287,6 +287,25 @@ level_arg(VALUE level)
return constant_arg(level, level_to_int, "unknown protocol level");
}
+static int
+optname_arg(int level, VALUE optname)
+{
+ switch (level) {
+ case SOL_SOCKET:
+ return constant_arg(optname, so_optname_to_int, "unknown socket level option name");
+ case IPPROTO_IP:
+ return constant_arg(optname, ip_optname_to_int, "unknown IP level option name");
+ case IPPROTO_IPV6:
+ return constant_arg(optname, ipv6_optname_to_int, "unknown IPv6 level option name");
+ case IPPROTO_TCP:
+ return constant_arg(optname, tcp_optname_to_int, "unknown TCP level option name");
+ case IPPROTO_UDP:
+ return constant_arg(optname, udp_optname_to_int, "unknown UDP level option name");
+ default:
+ return NUM2INT(optname);
+ }
+}
+
static VALUE
init_sock(VALUE sock, int fd)
{
@@ -433,7 +452,7 @@ bsock_setsockopt(VALUE sock, VALUE lev, VALUE optname, VALUE val)
rb_secure(2);
level = level_arg(lev);
- option = NUM2INT(optname);
+ option = optname_arg(level, optname);
switch (TYPE(val)) {
case T_FIXNUM:
@@ -513,7 +532,7 @@ bsock_getsockopt(VALUE sock, VALUE lev, VALUE optname)
rb_io_t *fptr;
level = level_arg(lev);
- option = NUM2INT(optname);
+ option = optname_arg(level, optname);
len = 256;
buf = ALLOCA_N(char,len);