summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 12:26:57 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 12:26:57 +0000
commite924cabede82193e86e505f735b2d91954d07b2b (patch)
treecfdcb1030cc1914399377992c40fc0d34e74a843
parent85d13f6165ece405b66f6c4d6771043375830c1e (diff)
* ext/socket/socket.c (sock_s_getnameinfo): use family_to_int.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--ext/socket/socket.c12
-rw-r--r--test/socket/test_socket.rb4
3 files changed, 12 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 7d03094923..e2585b84d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 623a5a79fe..04b79ff3c3 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 15267c2623..4c88177c9e 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)