summaryrefslogtreecommitdiff
path: root/ext/socket/basicsocket.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-08 15:12:27 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-08 15:12:27 +0000
commitc02ce88762eeda44002b82f4176e9fdbc0dd7e3c (patch)
tree84ee65ed2aaf50af5b1f9ad4adb59c3f561aa95b /ext/socket/basicsocket.c
parent3e11901f1c03f7d3a88349644223f6c920f5f9e2 (diff)
* ext/socket/rubysocket.h (sockopt_new): add family argument.
* ext/socket/option.c (sockopt_initialize): add vfamily argument. (sockopt_new): add family argument and record it in the object. (sockopt_family): new method. (sockopt_s_int): add vfamily argument. (sockopt_inspect): show family. * ext/socket/basicsocket.c (bsock_getsockopt): check address family using getsockname. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/basicsocket.c')
-rw-r--r--ext/socket/basicsocket.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c
index da8ab10..65c19d0 100644
--- a/ext/socket/basicsocket.c
+++ b/ext/socket/basicsocket.c
@@ -290,6 +290,8 @@ 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);
level = level_arg(lev);
option = optname_arg(level, optname);
@@ -297,10 +299,16 @@ bsock_getsockopt(VALUE sock, VALUE lev, VALUE optname)
buf = ALLOCA_N(char,len);
GetOpenFile(sock, fptr);
+
+ if (getsockname(fptr->fd, (struct sockaddr*)&ss, &sslen) < 0)
+ rb_sys_fail("getsockname(2)");
+
if (getsockopt(fptr->fd, level, option, buf, &len) < 0)
rb_sys_fail_path(fptr->pathv);
- return sockopt_new(level, option, rb_str_new(buf, len));
+ if (sslen < (char*)&ss.ss_family + sizeof(ss.ss_family) - (char*)&ss)
+ ss.ss_family = AF_UNSPEC;
+ return sockopt_new(ss.ss_family, level, option, rb_str_new(buf, len));
#else
rb_notimplement();
#endif