ruby-changes:10468
From: akr <ko1@a...>
Date: Tue, 3 Feb 2009 23:50:56 +0900 (JST)
Subject: [ruby-changes:10468] Ruby:r22018 (trunk): don't connect to unspecified address.
akr 2009-02-03 23:50:50 +0900 (Tue, 03 Feb 2009) New Revision: 22018 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=22018 Log: don't connect to unspecified address. Modified files: trunk/test/socket/test_socket.rb Index: test/socket/test_socket.rb =================================================================== --- test/socket/test_socket.rb (revision 22017) +++ test/socket/test_socket.rb (revision 22018) @@ -73,10 +73,20 @@ } end + def tcp_unspecified_to_loopback(addrinfo) + if addrinfo.ipv4? && addrinfo.ip_address == "0.0.0.0" + AddrInfo.tcp("127.0.0.1", addrinfo.ip_port) + elsif addrinfo.ipv6? && addrinfo.ipv6_unspecified? + AddrInfo.tcp("::1", addrinfo.ip_port) + else + addrinfo + end + end + def test_tcp TCPServer.open(0) {|serv| - port, addr = Socket.unpack_sockaddr_in(serv.getsockname) - Socket.tcp(addr, port) {|s1| + addr = tcp_unspecified_to_loopback(serv.local_address) + addr.connect {|s1| s2 = serv.accept begin assert_equal(s2.remote_address.ip_unpack, s1.local_address.ip_unpack) @@ -168,7 +178,8 @@ tcp_servers = Socket.tcp_server_sockets(0) unix_server = Socket.unix_server_socket("#{tmpdir}/sock") tcp_servers.each {|s| - clients << s.local_address.connect + addr = tcp_unspecified_to_loopback(s.local_address) + clients << addr.connect } clients << unix_server.local_address.connect Socket.accept_loop(tcp_servers, unix_server) {|s| -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/