From d94dbed46deaa325a43b92c5005585b3fbb20766 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 6 Aug 2001 06:10:10 +0000 Subject: [PATCH] * socket.c: wrap UNIX code by ifdef HAVE_SYS_UN_H. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/socket/socket.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/ext/socket/socket.c b/ext/socket/socket.c index d3e3fd53f0..da30898e0d 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -2078,6 +2078,17 @@ sock_s_pack_sockaddr_in(self, port, host) return addr; } +static VALUE +sock_s_unpack_sockaddr_in(self, addr) + VALUE self, addr; +{ + struct sockaddr_in * sockaddr; + + sockaddr = (struct sockaddr_in*)StringValuePtr(addr); + return rb_assoc_new(INT2NUM(ntohs(sockaddr->sin_port)), mkipaddr(sockaddr)); +} + +#ifdef HAVE_SYS_UN_H static VALUE sock_s_pack_sockaddr_un(self, path) VALUE self, path; @@ -2094,16 +2105,6 @@ sock_s_pack_sockaddr_un(self, path) return addr; } -static VALUE -sock_s_unpack_sockaddr_in(self, addr) - VALUE self, addr; -{ - struct sockaddr_in * sockaddr; - - sockaddr = (struct sockaddr_in*)StringValuePtr(addr); - return rb_assoc_new(INT2NUM(ntohs(sockaddr->sin_port)), mkipaddr(sockaddr)); -} - static VALUE sock_s_unpack_sockaddr_un(self, addr) VALUE self, addr; @@ -2114,6 +2115,7 @@ sock_s_unpack_sockaddr_un(self, addr) /* xxx: should I check against sun_path size? */ return rb_tainted_str_new2(sockaddr->sun_path); } +#endif static VALUE mConst; @@ -2225,11 +2227,13 @@ Init_socket() rb_define_singleton_method(rb_cSocket, "getaddrinfo", sock_s_getaddrinfo, -1); rb_define_singleton_method(rb_cSocket, "getnameinfo", sock_s_getnameinfo, -1); rb_define_singleton_method(rb_cSocket, "sockaddr_in", sock_s_pack_sockaddr_in, 2); - rb_define_singleton_method(rb_cSocket, "sockaddr_un", sock_s_pack_sockaddr_un, 1); rb_define_singleton_method(rb_cSocket, "pack_sockaddr_in", sock_s_pack_sockaddr_in, 2); - rb_define_singleton_method(rb_cSocket, "pack_sockaddr_un", sock_s_pack_sockaddr_un, 1); rb_define_singleton_method(rb_cSocket, "unpack_sockaddr_in", sock_s_unpack_sockaddr_in, 1); +#ifdef HAVE_SYS_UN_H + rb_define_singleton_method(rb_cSocket, "sockaddr_un", sock_s_pack_sockaddr_un, 1); + rb_define_singleton_method(rb_cSocket, "pack_sockaddr_un", sock_s_pack_sockaddr_un, 1); rb_define_singleton_method(rb_cSocket, "unpack_sockaddr_un", sock_s_unpack_sockaddr_un, 1); +#endif /* constants */ mConst = rb_define_module_under(rb_cSocket, "Constants");