summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--ext/socket/socket.c27
-rw-r--r--test/socket/test_socket.rb8
3 files changed, 41 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index c50b4deb81..d6f18d0edc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Fri Jun 25 11:37:34 2010 Akinori MUSHA <knu@iDaemons.org>
+
+ * ext/socket/raddrinfo.c (ruby_getaddrinfo__darwin): new workaround for
+ getaddrinfo problem on Mac OS X Snow Leopard. [ruby-core:29427]
+ patch by Wataru Kimura. [ruby-core:30842] [Backport #3474]
+
Wed Jun 23 21:36:45 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in: avoid getcontext() overhead if possible.
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 0d675bc66b..fb0160375b 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -234,6 +234,33 @@ ruby_getnameinfo__aix(sa, salen, host, hostlen, serv, servlen, flags)
#endif
#endif
+static int str_isnumber __P((const char *));
+
+#if defined(__APPLE__)
+/* fix [ruby-core:29427] */
+static int
+ruby_getaddrinfo__darwin(const char *nodename, const char *servname,
+ struct addrinfo *hints, struct addrinfo **res)
+{
+ const char *tmp_servname;
+ struct addrinfo tmp_hints;
+ tmp_servname = servname;
+ MEMCPY(&tmp_hints, hints, struct addrinfo, 1);
+ if (nodename && servname) {
+ if (str_isnumber(tmp_servname) && atoi(servname) == 0) {
+ tmp_servname = NULL;
+#ifdef AI_NUMERICSERV
+ if (tmp_hints.ai_flags) tmp_hints.ai_flags &= ~AI_NUMERICSERV;
+#endif
+ }
+ }
+ int error = getaddrinfo(nodename, tmp_servname, &tmp_hints, res);
+ return error;
+}
+#undef getaddrinfo
+#define getaddrinfo(node,serv,hints,res) ruby_getaddrinfo__darwin((node),(serv),(hints),(res))
+#endif
+
#ifdef HAVE_CLOSESOCKET
#undef close
#define close closesocket
diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb
index c5428b0b58..6385e9212d 100644
--- a/test/socket/test_socket.rb
+++ b/test/socket/test_socket.rb
@@ -71,6 +71,14 @@ class TestBasicSocket < Test::Unit::TestCase
}
end
end
+
+ def test_getaddrinfo_raises_no_errors_on_port_argument_of_0 # [ruby-core:29427]
+ assert_nothing_raised('[ruby-core:29427]'){ Socket.getaddrinfo('localhost', 0, Socket::AF_INET, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME) }
+ assert_nothing_raised('[ruby-core:29427]'){ Socket.getaddrinfo('localhost', '0', Socket::AF_INET, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME) }
+ assert_nothing_raised('[ruby-core:29427]'){ Socket.getaddrinfo('localhost', '00', Socket::AF_INET, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME) }
+ assert_raise(SocketError, '[ruby-core:29427]'){ Socket.getaddrinfo(nil, nil, Socket::AF_INET, Socket::SOCK_STREAM, nil, Socket::AI_CANONNAME) }
+ assert_nothing_raised('[ruby-core:29427]'){ TCPServer.open('localhost', 0) {} }
+ end
end if defined?(Socket)
class TestSocket < Test::Unit::TestCase