summaryrefslogtreecommitdiff
path: root/ext/socket/basicsocket.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-09 13:56:43 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-09 13:56:43 +0000
commitf5da7031b91426f362e8ec2101bf794976ecc590 (patch)
tree4d360cb11fc6daa19f831c1a30baecad4351515a /ext/socket/basicsocket.c
parent2092fbcc3ad4437f066dc79a64a80236afcbdf50 (diff)
* ext/socket/rubysocket.h (level_arg): add family argument.
(optname_arg): ditto. (cmsg_type_arg): ditto. (rb_sock_getfamily): declared. * ext/socket/constants.c (level_arg): add family argument. (optname_arg): ditto. (cmsg_type_arg): ditto. * ext/socket/init.c (rb_sock_getfamily): defined. * ext/socket/option.c (sockopt_initialize): give family for level_arg and optname_arg. (sockopt_s_int): ditto. * ext/socket/basicsocket.c (bsock_setsockopt): ditto. (bsock_getsockopt): ditto. * ext/socket/ancdata.c (ancillary_initialize): ditto. (ancillary_s_int): ditto. (ancillary_cmsg_is_p): ditto. (bsock_sendmsg_internal): ditto. (bsock_recvmsg_internal): use rb_sock_getfamily. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/basicsocket.c')
-rw-r--r--ext/socket/basicsocket.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c
index f6fb9f2..7690fb6 100644
--- a/ext/socket/basicsocket.c
+++ b/ext/socket/basicsocket.c
@@ -195,7 +195,7 @@ static VALUE
bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
{
VALUE lev, optname, val;
- int level, option;
+ int family, level, option;
rb_io_t *fptr;
int i;
char *v;
@@ -211,8 +211,10 @@ bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
}
rb_secure(2);
- level = level_arg(lev);
- option = optname_arg(level, optname);
+ GetOpenFile(sock, fptr);
+ family = rb_sock_getfamily(fptr->fd);
+ level = level_arg(family, lev);
+ option = optname_arg(family, level, optname);
switch (TYPE(val)) {
case T_FIXNUM:
@@ -235,7 +237,7 @@ bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
#define rb_sys_fail_path(path) rb_sys_fail(NIL_P(path) ? 0 : RSTRING_PTR(path))
- GetOpenFile(sock, fptr);
+ rb_io_check_closed(fptr);
if (setsockopt(fptr->fd, level, option, v, vlen) < 0)
rb_sys_fail_path(fptr->pathv);
@@ -290,24 +292,21 @@ bsock_getsockopt(VALUE sock, VALUE lev, VALUE optname)
socklen_t len;
char *buf;
rb_io_t *fptr;
- struct sockaddr_storage ss;
- socklen_t sslen = sizeof(ss);
+ int family;
- level = level_arg(lev);
- option = optname_arg(level, optname);
+ GetOpenFile(sock, fptr);
+ family = rb_sock_getfamily(fptr->fd);
+ level = level_arg(family, lev);
+ option = optname_arg(family, level, optname);
len = 256;
buf = ALLOCA_N(char,len);
- GetOpenFile(sock, fptr);
-
- ss.ss_family = AF_UNSPEC;
- if (getsockname(fptr->fd, (struct sockaddr*)&ss, &sslen) < 0)
- rb_sys_fail("getsockname(2)");
+ rb_io_check_closed(fptr);
if (getsockopt(fptr->fd, level, option, buf, &len) < 0)
rb_sys_fail_path(fptr->pathv);
- return sockopt_new(ss.ss_family, level, option, rb_str_new(buf, len));
+ return sockopt_new(family, level, option, rb_str_new(buf, len));
#else
rb_notimplement();
#endif