* ext/socket/ipsocket.c (init_inetsock_internal): Don't use local
addresses which address family is different to remote address. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
db50aa78fb
commit
a5fcce2820
@ -1,3 +1,8 @@
|
|||||||
|
Fri Jun 28 12:14:04 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* ext/socket/ipsocket.c (init_inetsock_internal): Don't use local
|
||||||
|
addresses which address family is different to remote address.
|
||||||
|
|
||||||
Fri Jun 28 08:06:22 2013 Tanaka Akira <akr@fsij.org>
|
Fri Jun 28 08:06:22 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* bignum.c (bigand_int): Add arguments, xn and hibitsx.
|
* bignum.c (bigand_int): Add arguments, xn and hibitsx.
|
||||||
|
@ -42,7 +42,7 @@ static VALUE
|
|||||||
init_inetsock_internal(struct inetsock_arg *arg)
|
init_inetsock_internal(struct inetsock_arg *arg)
|
||||||
{
|
{
|
||||||
int type = arg->type;
|
int type = arg->type;
|
||||||
struct addrinfo *res;
|
struct addrinfo *res, *lres;
|
||||||
int fd, status = 0, local = 0;
|
int fd, status = 0, local = 0;
|
||||||
const char *syscall = 0;
|
const char *syscall = 0;
|
||||||
|
|
||||||
@ -62,6 +62,15 @@ init_inetsock_internal(struct inetsock_arg *arg)
|
|||||||
if (res->ai_family == AF_INET6)
|
if (res->ai_family == AF_INET6)
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
|
lres = NULL;
|
||||||
|
if (arg->local.res) {
|
||||||
|
for (lres = arg->local.res; lres; lres = lres->ai_next) {
|
||||||
|
if (lres->ai_family == res->ai_family)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!lres)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
status = rsock_socket(res->ai_family,res->ai_socktype,res->ai_protocol);
|
status = rsock_socket(res->ai_family,res->ai_socktype,res->ai_protocol);
|
||||||
syscall = "socket(2)";
|
syscall = "socket(2)";
|
||||||
fd = status;
|
fd = status;
|
||||||
@ -79,8 +88,8 @@ init_inetsock_internal(struct inetsock_arg *arg)
|
|||||||
syscall = "bind(2)";
|
syscall = "bind(2)";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (arg->local.res) {
|
if (lres) {
|
||||||
status = bind(fd, arg->local.res->ai_addr, arg->local.res->ai_addrlen);
|
status = bind(fd, lres->ai_addr, lres->ai_addrlen);
|
||||||
local = status;
|
local = status;
|
||||||
syscall = "bind(2)";
|
syscall = "bind(2)";
|
||||||
}
|
}
|
||||||
|
@ -7,19 +7,21 @@ end
|
|||||||
|
|
||||||
class TestSocket_TCPSocket < Test::Unit::TestCase
|
class TestSocket_TCPSocket < Test::Unit::TestCase
|
||||||
def test_initialize_failure
|
def test_initialize_failure
|
||||||
s = TCPServer.new("localhost", nil)
|
addr = '127.0.0.1'
|
||||||
|
|
||||||
|
s = TCPServer.new(addr, nil)
|
||||||
server_port = s.addr[1]
|
server_port = s.addr[1]
|
||||||
|
|
||||||
c = TCPSocket.new("localhost", server_port)
|
c = TCPSocket.new(addr, server_port)
|
||||||
client_port = c.addr[1]
|
client_port = c.addr[1]
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# TCPServer.new uses SO_REUSEADDR so we must create a failure on the
|
# TCPServer.new uses SO_REUSEADDR so we must create a failure on the
|
||||||
# local address.
|
# local address.
|
||||||
TCPSocket.new("localhost", server_port, "localhost", client_port)
|
TCPSocket.new(addr, server_port, addr, client_port)
|
||||||
flunk "expected SystemCallError"
|
flunk "expected SystemCallError"
|
||||||
rescue SystemCallError => e
|
rescue SystemCallError => e
|
||||||
assert_match "for \"localhost\" port #{client_port}", e.message
|
assert_match "for \"#{addr}\" port #{client_port}", e.message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user