diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-13 03:14:13 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-10-13 03:14:13 +0000 |
commit | 030a334125e5752f516475058630e0bd16c00bc0 (patch) | |
tree | c76ca9b10f1bed48dabc7f2e0eae875a0206519c /ext/socket/raddrinfo.c | |
parent | 20acd44f8a15893d4c88a38e8827facf777b05a6 (diff) | |
download | ruby-030a334125e5752f516475058630e0bd16c00bc0.tar.gz |
rsock_addrinfo: specify address family
* ext/socket/rsock_addrinfo (rsock_addrinfo): specify address
family. [Fix GH-1052]
* ext/socket/udpsocket.c (udp_connect, udp_bind, udp_send):
address family by the receiver.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/raddrinfo.c')
-rw-r--r-- | ext/socket/raddrinfo.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c index 7aaa83128e..b42707454a 100644 --- a/ext/socket/raddrinfo.c +++ b/ext/socket/raddrinfo.c @@ -518,13 +518,25 @@ rsock_getaddrinfo(VALUE host, VALUE port, struct addrinfo *hints, int socktype_h return res; } +int +rsock_fd_family(int fd) +{ + struct sockaddr sa = { 0 }; + socklen_t sa_len = sizeof(sa); + + if (fd < 0 || getsockname(fd, &sa, &sa_len) != 0) { + return AF_UNSPEC; + } + return sa.sa_family; +} + struct rb_addrinfo* -rsock_addrinfo(VALUE host, VALUE port, int socktype, int flags) +rsock_addrinfo(VALUE host, VALUE port, int family, int socktype, int flags) { struct addrinfo hints; MEMZERO(&hints, struct addrinfo, 1); - hints.ai_family = AF_UNSPEC; + hints.ai_family = family; hints.ai_socktype = socktype; hints.ai_flags = flags; return rsock_getaddrinfo(host, port, &hints, 1); |