summaryrefslogtreecommitdiff
path: root/ext/socket/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/socket/init.c')
-rw-r--r--ext/socket/init.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/ext/socket/init.c b/ext/socket/init.c
index 484d27e..f0e34d1 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -505,6 +505,18 @@ s_accept(VALUE klass, int fd, struct sockaddr *sockaddr, socklen_t *len)
return init_sock(rb_obj_alloc(klass), fd2);
}
+int rb_sock_getfamily(int sockfd)
+{
+ struct sockaddr_storage ss;
+ socklen_t sslen = sizeof(ss);
+
+ ss.ss_family = AF_UNSPEC;
+ if (getsockname(sockfd, (struct sockaddr*)&ss, &sslen) < 0)
+ rb_sys_fail("getsockname(2)");
+
+ return ss.ss_family;
+}
+
/*
* SocketError is the error class for socket.
*/