Addrinfo.new(sockaddr, family) => addrinfo
Addrinfo.new(sockaddr, family, socktype) => addrinfo
Addrinfo.new(sockaddr, family, socktype, protocol) => addrinfo
returns a new instance of Addrinfo. The instance contains sockaddr, family, socktype, protocol. sockaddr means struct sockaddr which can be used for connect(2), etc. family, socktype and protocol are integers which is used for arguments of socket(2).
sockaddr is specified as an array or a string. The array should be compatible to the value of IPSocket#addr or UNIXSocket#addr. The string should be struct sockaddr as generated by Socket.sockaddr_in or Socket.unpack_sockaddr_un.
sockaddr examples:
- âAF_INETâ, 46102, âlocalhost.localdomainâ, â127.0.0.1â
- âAF_INET6â, 42304, âip6-localhostâ, â::1â
- âAF_UNIXâ, â/tmp/sockâ
-
Socket.sockaddr_in(âsmtpâ, â2001:DB8::1â)
-
Socket.sockaddr_in(80, â172.18.22.42â)
-
Socket.sockaddr_un(â/tmp/sockâ)
In an AF_INET/AF_INET6 sockaddr array, the 4th element, numeric IP address, is used to construct socket address in the Addrinfo instance. If the 3rd element, textual host name, is non-nil, it is also recorded but used only for #inspect.
family is specified as an integer to specify the protocol family such as Socket::PF_INET. It can be a symbol or a string which is the constant name with or without PF_ prefix such as :INET, :INET6, :UNIX, âPF_INETâ, etc. If omitted, PF_UNSPEC is assumed.
socktype is specified as an integer to specify the socket type such as Socket::SOCK_STREAM. It can be a symbol or a string which is the constant name with or without SOCK_ prefix such as :STREAM, :DGRAM, :RAW, âSOCK_STREAMâ, etc. If omitted, 0 is assumed.
protocol is specified as an integer to specify the protocol such as Socket::IPPROTO_TCP. It must be an integer, unlike family and socktype. If omitted, 0 is assumed. Note that 0 is reasonable value for most protocols, except raw socket.
Please login to continue.