* 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
This commit is contained in:
akr 2009-01-01 11:47:55 +00:00
Родитель 6e4149f04a
Коммит e485a566ed
3 изменённых файлов: 13 добавлений и 8 удалений

Просмотреть файл

@ -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> Thu Jan 1 20:17:47 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/socket.c: include constants.h at top. * ext/socket/socket.c: include constants.h at top.

Просмотреть файл

@ -3252,14 +3252,10 @@ sock_s_getaddrinfo(int argc, VALUE *argv)
hints.ai_family = FIX2INT(family); hints.ai_family = FIX2INT(family);
} }
else if ((ap = StringValuePtr(family)) != 0) { else if ((ap = StringValuePtr(family)) != 0) {
if (strcmp(ap, "AF_INET") == 0) { int af;
hints.ai_family = PF_INET; if (family_to_int(ap, RSTRING_LEN(family), &af) == -1)
} rb_raise(rb_eSocket, "unknown socket domain %s", ap);
#ifdef INET6 hints.ai_family = af;
else if (strcmp(ap, "AF_INET6") == 0) {
hints.ai_family = PF_INET6;
}
#endif
} }
if (!NIL_P(socktype)) { if (!NIL_P(socktype)) {

Просмотреть файл

@ -110,4 +110,9 @@ class TestSocket < Test::Unit::TestCase
assert_raise(ArgumentError) { Socket.unpack_sockaddr_un(addr) } assert_raise(ArgumentError) { Socket.unpack_sockaddr_un(addr) }
} }
end 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) end if defined?(Socket)