diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-28 03:16:07 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-28 03:16:07 +0000 |
commit | a5fcce2820bd008b690ce39be86d82cb959f62f8 (patch) | |
tree | eaae7f340614a7380529c888b706f8b8c7e43c9f /ext/socket | |
parent | db50aa78fbfaf626f0c7d61a7bc209589cddcea4 (diff) | |
download | ruby-a5fcce2820bd008b690ce39be86d82cb959f62f8.tar.gz |
* 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
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/ipsocket.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/ext/socket/ipsocket.c b/ext/socket/ipsocket.c index c3b989730d..01290cbb8f 100644 --- a/ext/socket/ipsocket.c +++ b/ext/socket/ipsocket.c @@ -42,7 +42,7 @@ static VALUE init_inetsock_internal(struct inetsock_arg *arg) { int type = arg->type; - struct addrinfo *res; + struct addrinfo *res, *lres; int fd, status = 0, local = 0; const char *syscall = 0; @@ -62,6 +62,15 @@ init_inetsock_internal(struct inetsock_arg *arg) if (res->ai_family == AF_INET6) continue; #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); syscall = "socket(2)"; fd = status; @@ -79,8 +88,8 @@ init_inetsock_internal(struct inetsock_arg *arg) syscall = "bind(2)"; } else { - if (arg->local.res) { - status = bind(fd, arg->local.res->ai_addr, arg->local.res->ai_addrlen); + if (lres) { + status = bind(fd, lres->ai_addr, lres->ai_addrlen); local = status; syscall = "bind(2)"; } |