Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Socket.unpack_sockaddr_in

Socket.unpack_sockaddr_in(sockaddr) => [port, ip_address]

Unpacks sockaddr into port and ip_address.

sockaddr should be a string or an addrinfo for AF_INET/AF_INET6.

Example
sockaddr = Socket.sockaddr_in(80, "127.0.0.1")
p sockaddr #=> "\x02\x00\x00P\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
p Socket.unpack_sockaddr_in(sockaddr) #=> [80, "127.0.0.1"]