new(p1, p2 = v2, p3 = v3, p4 = v4) public

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_in(80, “www.ruby-lang.org”)

  • 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 Addrinfo#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.

Show source
Register or log in to add new notes.