diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | ext/socket/socket.c | 12 | ||||
-rw-r--r-- | test/socket/test_socket.rb | 4 |
3 files changed, 12 insertions, 8 deletions
@@ -1,3 +1,7 @@ +Thu Jan 1 21:26:05 2009 Tanaka Akira <akr@fsij.org> + + * ext/socket/socket.c (sock_s_getnameinfo): use family_to_int. + Thu Jan 1 21:08:34 2009 Tanaka Akira <akr@fsij.org> * ext/socket/mkconstants.rb: check all alias possibility. diff --git a/ext/socket/socket.c b/ext/socket/socket.c index 623a5a79f..04b79ff3c 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -3369,14 +3369,10 @@ sock_s_getnameinfo(int argc, VALUE *argv) hints.ai_family = FIX2INT(af); } else if ((ap = StringValuePtr(af)) != 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 family; + if (family_to_int(ap, RSTRING_LEN(af), &family) == -1) + rb_raise(rb_eSocket, "unknown socket domain %s", ap); + hints.ai_family = family; } error = getaddrinfo(hptr, pptr, &hints, &res); if (error) goto error_exit_addr; diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb index 15267c262..4c88177c9 100644 --- a/test/socket/test_socket.rb +++ b/test/socket/test_socket.rb @@ -115,4 +115,8 @@ class TestSocket < Test::Unit::TestCase # This should not send a DNS query because AF_UNIX. assert_raise(SocketError) { Socket.getaddrinfo("www.kame.net", 80, "AF_UNIX") } end + + def test_getnameinfo + assert_raise(SocketError) { Socket.getnameinfo(["AF_UNIX", 80, "0.0.0.0"]) } + end end if defined?(Socket) |