https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-04-07T06:08:30ZRuby Issue Tracking SystemRuby master - Bug #13409: UDPSocket#send breaks when using sockaddrhttps://bugs.ruby-lang.org/issues/13409?journal_id=641122017-04-07T06:08:30Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p><a href="mailto:samuel@oriontransfer.org" class="email">samuel@oriontransfer.org</a> wrote:</p>
<blockquote>
<p>Here is one that fails with EINVAL:</p>
</blockquote>
<p>Thanks for the example. This failure appears OS-specific,<br>
no problems under Linux.</p> Ruby master - Bug #13409: UDPSocket#send breaks when using sockaddrhttps://bugs.ruby-lang.org/issues/13409?journal_id=641132017-04-07T06:26:14Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><p>On linux I get the following output for the 2nd example:</p>
<pre><code>Server waiting for packet...
Sending data to #<Addrinfo: [::1]:6778 UDP (localhost)>
-:25:in `send': Address family not supported by protocol - send(2) (Errno::EAFNOSUPPORT)
from -:25:in `block in <main>'
</code></pre> Ruby master - Bug #13409: UDPSocket#send breaks when using sockaddrhttps://bugs.ruby-lang.org/issues/13409?journal_id=641192017-04-08T03:27:12Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p><code>rsock_bsock_send</code> calls <code>sendto(2)</code> if the third argument is present and not nil.<br>
Fixed the message now.</p> Ruby master - Bug #13409: UDPSocket#send breaks when using sockaddrhttps://bugs.ruby-lang.org/issues/13409?journal_id=641202017-04-08T04:07:07Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/64120/diff?detail_id=44661">diff</a>)</li></ul><p>On 2017/04/07 15:44, Eric Wong wrote:</p>
<blockquote>
<p>It looks like your system does not have full IPv6 support.</p>
</blockquote>
<p>What version is your kernel?</p> Ruby master - Bug #13409: UDPSocket#send breaks when using sockaddrhttps://bugs.ruby-lang.org/issues/13409?journal_id=641412017-04-10T01:10:41Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><pre><code>% uname -a
Linux koyoko.local 4.10.4-1-ARCH #1 SMP PREEMPT Sat Mar 18 19:39:18 CET 2017 x86_64 GNU/Linux
</code></pre>
<pre><code>% ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 74:d0:2b:7b:dd:77 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.23/24 brd 192.168.1.255 scope global dynamic eno1
valid_lft 383sec preferred_lft 383sec
inet6 2406:e007:aed:0:76d0:2bff:fe7b:dd77/64 scope global noprefixroute dynamic
valid_lft 2591868sec preferred_lft 604668sec
inet6 fe80::76d0:2bff:fe7b:dd77/64 scope link
valid_lft forever preferred_lft forever
</code></pre>
<p>I use IPv6 all the time and it works fine.</p> Ruby master - Bug #13409: UDPSocket#send breaks when using sockaddrhttps://bugs.ruby-lang.org/issues/13409?journal_id=641442017-04-10T06:34:27Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><blockquote>
<p>server = UDPSocket.new.tap{|socket| socket.bind("localhost", port)}<br>
client = UDPSocket.new</p>
</blockquote>
<p><code>UDPSocket.new</code> receives an optional argument address family, whose default is AF_INET.<br>
If you use IPv6, you need to specify AF_INET6 like <code>UDPSocket.new(Socket::AF_INET6)</code>.</p> Ruby master - Bug #13409: UDPSocket#send breaks when using sockaddrhttps://bugs.ruby-lang.org/issues/13409?journal_id=641732017-04-11T06:13:33Znaruse (Yui NARUSE)naruse@airemix.jp
<ul></ul><p>naruse (Yui NARUSE) wrote:</p>
<blockquote>
<p><code>UDPSocket.new</code> receives an optional argument address family, whose default is AF_INET.<br>
If you use IPv6, you need to specify AF_INET6 like <code>UDPSocket.new(Socket::AF_INET6)</code>.</p>
</blockquote>
<p>FYI, <a href="https://ruby-doc.org/stdlib-2.4.1/libdoc/socket/rdoc/Socket.html#method-c-udp_server_loop" class="external">Socket#udp_server_loop</a> is useful to implement UDP server which supports both IPv4 and IPv6.</p>