diff --git a/ChangeLog b/ChangeLog index 8551aa2f00..3065786261 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu Jan 1 20:47:09 2009 Tanaka Akira + + * ext/socket/socket.c (sock_s_getaddrinfo): use family_to_int. + Thu Jan 1 20:17:47 2009 Tanaka Akira * ext/socket/socket.c: include constants.h at top. diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 6561c89b98..623a5a79fe 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -3252,14 +3252,10 @@ sock_s_getaddrinfo(int argc, VALUE *argv) hints.ai_family = FIX2INT(family); } else if ((ap = StringValuePtr(family)) != 0) { - if (strcmp(ap, "AF_INET") == 0) { - hints.ai_family = PF_INET; - } -#ifdef INET6 - else if (strcmp(ap, "AF_INET6") == 0) { - hints.ai_family = PF_INET6; - } -#endif + int af; + if (family_to_int(ap, RSTRING_LEN(family), &af) == -1) + rb_raise(rb_eSocket, "unknown socket domain %s", ap); + hints.ai_family = af; } if (!NIL_P(socktype)) { diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb index 3133590ab1..15267c2623 100644 --- a/test/socket/test_socket.rb +++ b/test/socket/test_socket.rb @@ -110,4 +110,9 @@ class TestSocket < Test::Unit::TestCase assert_raise(ArgumentError) { Socket.unpack_sockaddr_un(addr) } } end + + def test_getaddrinfo + # This should not send a DNS query because AF_UNIX. + assert_raise(SocketError) { Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX") } + end end if defined?(Socket)