summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 11:47:55 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 11:47:55 +0000
commite485a566ed8d5d8670641909319161632f9647c9 (patch)
tree5cf62ab2720d5106aa94709fd0925ca86046c8c3
parent6e4149f04a31d3347a8adff35ef7ab4f7fe7d00a (diff)
* ext/socket/socket.c (sock_s_getaddrinfo): use family_to_int.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21247 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--ext/socket/socket.c12
-rw-r--r--test/socket/test_socket.rb5
3 files changed, 13 insertions, 8 deletions
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 <akr@fsij.org>
+
+ * ext/socket/socket.c (sock_s_getaddrinfo): use family_to_int.
+
Thu Jan 1 20:17:47 2009 Tanaka Akira <akr@fsij.org>
* 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)