ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:110325] [Ruby master Bug#19064] UDPSocket#bind does not take AddrInfo, despite documentation saying it should
@ 2022-10-17  0:50 mcr (Michael Richardson)
  2022-11-01  4:06 ` [ruby-core:110563] " tomgilligan (Tom Gilligan)
  2022-11-07 17:15 ` [ruby-core:110642] [Ruby master Feature#19064] " jeremyevans0 (Jeremy Evans)
  0 siblings, 2 replies; 3+ messages in thread
From: mcr (Michael Richardson) @ 2022-10-17  0:50 UTC (permalink / raw
  To: ruby-core

Issue #19064 has been reported by mcr (Michael Richardson).

----------------------------------------
Bug #19064: UDPSocket#bind does not take AddrInfo, despite documentation saying it should
https://bugs.ruby-lang.org/issues/19064

* Author: mcr (Michael Richardson)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-10-16T09:31:08Z master ba9c0d0b9f) [x86_64-linux
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
https://docs.ruby-lang.org/en/master/Socket.html#method-i-bind says that this code should work:

``` ruby
require 'socket'

# use Addrinfo
socket = Socket.new(:INET, :STREAM, 0)
socket.bind(Addrinfo.tcp("127.0.0.1", 2222))
p socket.local_address #=> #<Addrinfo: 127.0.0.1:2222 TCP>
```

and it does, but UDPSocket does *not* like Addrinfo:

``` ruby
socket = UDPSocket.new(Socket::AF_INET6)
ai=Addrinfo.udp("127.0.0.1", 2224)
socket.bind(ai, 0)
````

A reason to use an Addrinfo rather than a string is because it came from, for instance, Socket.getifaddrs, and might have scope and other information attached, like:

``` ruby
#<Addrinfo: fe80::f58e:d5ea:41e0:2555%eth0>
```

Seen on versions back to 2.6.6, but tested with ruby-head to be sure.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:110563] [Ruby master Bug#19064] UDPSocket#bind does not take AddrInfo, despite documentation saying it should
  2022-10-17  0:50 [ruby-core:110325] [Ruby master Bug#19064] UDPSocket#bind does not take AddrInfo, despite documentation saying it should mcr (Michael Richardson)
@ 2022-11-01  4:06 ` tomgilligan (Tom Gilligan)
  2022-11-07 17:15 ` [ruby-core:110642] [Ruby master Feature#19064] " jeremyevans0 (Jeremy Evans)
  1 sibling, 0 replies; 3+ messages in thread
From: tomgilligan (Tom Gilligan) @ 2022-11-01  4:06 UTC (permalink / raw
  To: ruby-core

Issue #19064 has been updated by tomgilligan (Tom Gilligan).


The linked documentation is for Socket, not UDPSocket.  The documentation for UDPSocket does not suggest that it accepts an Addrinfo. https://docs.ruby-lang.org/en/master/UDPSocket.html
The difference between Socket/UDPSocket is confusing and could be clarified.  To be honest I'm not sure if UDPSocket/TCPSocket classes are very helpful at all (especially in light of potential confusion with Socket).

If you would like to create a UDP socket using Socket and give it an Addrinfo, you can do so with

``` ruby
require 'socket'

socket = Socket.new(:AF_INET6, :DGRAM, 0)
ai=Addrinfo.udp("::1", 2224)
socket.bind(ai)
p socket.local_address #=> #<Addrinfo: [::1]:2224 UDP>
```

Or if you want to use IPv4:

``` ruby
require 'socket'

socket = Socket.new(:AF_INET, :DGRAM, 0)
ai=Addrinfo.udp("127.0.0.1", 2224)
socket.bind(ai)
p socket.local_address #=> #<Addrinfo: 127.0.0.1:2224 UDP>
```




----------------------------------------
Bug #19064: UDPSocket#bind does not take AddrInfo, despite documentation saying it should
https://bugs.ruby-lang.org/issues/19064#change-99893

* Author: mcr (Michael Richardson)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0dev (2022-10-16T09:31:08Z master ba9c0d0b9f) [x86_64-linux
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
https://docs.ruby-lang.org/en/master/Socket.html#method-i-bind says that this code should work:

``` ruby
require 'socket'

# use Addrinfo
socket = Socket.new(:INET, :STREAM, 0)
socket.bind(Addrinfo.tcp("127.0.0.1", 2222))
p socket.local_address #=> #<Addrinfo: 127.0.0.1:2222 TCP>
```

and it does, but UDPSocket does *not* like Addrinfo:

``` ruby
socket = UDPSocket.new(Socket::AF_INET6)
ai=Addrinfo.udp("127.0.0.1", 2224)
socket.bind(ai, 0)
````

A reason to use an Addrinfo rather than a string is because it came from, for instance, Socket.getifaddrs, and might have scope and other information attached, like:

``` ruby
#<Addrinfo: fe80::f58e:d5ea:41e0:2555%eth0>
```

Seen on versions back to 2.6.6, but tested with ruby-head to be sure.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:110642] [Ruby master Feature#19064] UDPSocket#bind does not take AddrInfo, despite documentation saying it should
  2022-10-17  0:50 [ruby-core:110325] [Ruby master Bug#19064] UDPSocket#bind does not take AddrInfo, despite documentation saying it should mcr (Michael Richardson)
  2022-11-01  4:06 ` [ruby-core:110563] " tomgilligan (Tom Gilligan)
@ 2022-11-07 17:15 ` jeremyevans0 (Jeremy Evans)
  1 sibling, 0 replies; 3+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2022-11-07 17:15 UTC (permalink / raw
  To: ruby-core

Issue #19064 has been updated by jeremyevans0 (Jeremy Evans).

Tracker changed from Bug to Feature
ruby -v deleted (ruby 3.2.0dev (2022-10-16T09:31:08Z master ba9c0d0b9f) [x86_64-linux)
Backport deleted (2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN)

`UDPSocket` is not a subclass of `Socket`, so the fact that `Addrinfo` instances work for `Socket` (as documented), but do not work for `UDPSocket` is not a bug.  I agree that having `UDPSocket` support `Addrinfo` would be useful, switching to feature request.

----------------------------------------
Feature #19064: UDPSocket#bind does not take AddrInfo, despite documentation saying it should
https://bugs.ruby-lang.org/issues/19064#change-99982

* Author: mcr (Michael Richardson)
* Status: Open
* Priority: Normal
----------------------------------------
https://docs.ruby-lang.org/en/master/Socket.html#method-i-bind says that this code should work:

``` ruby
require 'socket'

# use Addrinfo
socket = Socket.new(:INET, :STREAM, 0)
socket.bind(Addrinfo.tcp("127.0.0.1", 2222))
p socket.local_address #=> #<Addrinfo: 127.0.0.1:2222 TCP>
```

and it does, but UDPSocket does *not* like Addrinfo:

``` ruby
socket = UDPSocket.new(Socket::AF_INET6)
ai=Addrinfo.udp("127.0.0.1", 2224)
socket.bind(ai, 0)
````

A reason to use an Addrinfo rather than a string is because it came from, for instance, Socket.getifaddrs, and might have scope and other information attached, like:

``` ruby
#<Addrinfo: fe80::f58e:d5ea:41e0:2555%eth0>
```

Seen on versions back to 2.6.6, but tested with ruby-head to be sure.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-07 17:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-17  0:50 [ruby-core:110325] [Ruby master Bug#19064] UDPSocket#bind does not take AddrInfo, despite documentation saying it should mcr (Michael Richardson)
2022-11-01  4:06 ` [ruby-core:110563] " tomgilligan (Tom Gilligan)
2022-11-07 17:15 ` [ruby-core:110642] [Ruby master Feature#19064] " jeremyevans0 (Jeremy Evans)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).