Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Addrinfo#getnameinfo

addrinfo.getnameinfo => [nodename, service]
addrinfo.getnameinfo(flags) => [nodename, service]

returns nodename and service as a pair of strings. This converts struct sockaddr in addrinfo to textual representation.

flags should be bitwise OR of Socket::NI_??? constants.

Example
Addrinfo.tcp("127.0.0.1", 80).getnameinfo #=> ["localhost", "www"]

Addrinfo.tcp("127.0.0.1", 80).getnameinfo(Socket::NI_NUMERICSERV)
#=> ["localhost", "80"]