https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112011-11-01T04:57:48ZRuby Issue Tracking SystemRuby master - Bug #5525: UDPSocket#bind(ip, port) fails under IPv6 => Errno::EAFNOSUPPORThttps://redmine.ruby-lang.org/issues/5525?journal_id=217252011-11-01T04:57:48Zdrbrain (Eric Hodel)drbrain@segment7.net
<ul><li><strong>Category</strong> set to <i>lib</i></li><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>=begin<br>
You need to create an AF_INET6 UDP socket to bind to a UDP address:</p>
<p>$ ruby -vr 'socket' -e 'u = UDPSocket.new Socket::AF_INET6; u.bind "::1", 9999'<br>
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]</p>
<p>=end</p> Ruby master - Bug #5525: UDPSocket#bind(ip, port) fails under IPv6 => Errno::EAFNOSUPPORThttps://redmine.ruby-lang.org/issues/5525?journal_id=217502011-11-01T12:36:06Zibc (Iñaki Baz Castillo)ibc@aliax.net
<ul></ul><p>Thanks a lot. But why is it required just for UDP? In TCP I can use "TCPServer.new some_ipv6, port" with no problem. Why UDPSocket requires special handling for IPv6?</p> Ruby master - Bug #5525: UDPSocket#bind(ip, port) fails under IPv6 => Errno::EAFNOSUPPORThttps://redmine.ruby-lang.org/issues/5525?journal_id=217742011-11-01T20:53:09Zakr (Akira Tanaka)akr@fsij.org
<ul><li><strong>ruby -v</strong> changed from <i>ruby 1.9.3dev (2011-07-31 revision 32789) [x86_64-linux]</i> to <i>-</i></li></ul><p>2011/11/1 Iñaki Baz Castillo <a href="mailto:ibc@aliax.net" class="email">ibc@aliax.net</a>:</p>
<blockquote>
<p>Thanks a lot. But why is it required just for UDP? In TCP I can use "TCPServer.new some_ipv6, port" with no problem. Why UDPSocket requires special handling for IPv6?</p>
</blockquote>
<p>The protocol (IPv4/IPv6) is determined at socket creation.</p>
<p>The argument of TCPServer.new(ipv6_address) makes Ruby to find that<br>
the protocol is IPv6.<br>
So TCPServer.new creates a socket for IPv6.</p>
<h2>But Ruby cannot find the protocol for UDPSocket.new without arguments.<br>
In that case, UDPScoket.new creates a socket for IPv4.<br>
You meet an error when you use it for IPv6.</h2>
<p>Tanaka Akira</p> Ruby master - Bug #5525: UDPSocket#bind(ip, port) fails under IPv6 => Errno::EAFNOSUPPORThttps://redmine.ruby-lang.org/issues/5525?journal_id=218032011-11-02T05:04:01Zdrbrain (Eric Hodel)drbrain@segment7.net
<ul></ul><p>Iñaki, perhaps you should open a feature request for new methods, perhaps UDPSocket::bind and UDPSocket::connect which will determine the address family from the address given.</p>
<p>The existing Socket::udp_server_sockets may also help you, but I don't know if it uses bind or connect.</p> Ruby master - Bug #5525: UDPSocket#bind(ip, port) fails under IPv6 => Errno::EAFNOSUPPORThttps://redmine.ruby-lang.org/issues/5525?journal_id=218072011-11-02T06:29:13Zakr (Akira Tanaka)akr@fsij.org
<ul></ul><p>2011/11/2 Eric Hodel <a href="mailto:drbrain@segment7.net" class="email">drbrain@segment7.net</a>:</p>
<blockquote>
<p>Iñaki, perhaps you should open a feature request for new methods, perhaps UDPSocket::bind and UDPSocket::connect which will determine the address family from the address given.</p>
</blockquote>
<p>It is possible as follows since Ruby 1.9.2.</p>
<h2>Addrinfo.udp("::1", 2000).bind<br>
Addrinfo.udp("127.0.0.1", 2001).bind</h2>
<p>Tanaka Akira</p>