Project

General

Profile

Actions

Feature #19064

open

UDPSocket#bind does not take AddrInfo, despite documentation saying it should

Added by mcr (Michael Richardson) about 2 years ago. Updated about 2 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:110325]

Description

https://docs.ruby-lang.org/en/master/Socket.html#method-i-bind says that this code should work:

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:

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:

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

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

Actions

Also available in: Atom PDF

Like0
Like0Like0