Flowdock
method

getaddrinfo

Importance_2
Ruby latest stable (v2_5_5) - 0 notes - Class: Addrinfo
getaddrinfo(p1, p2, p3 = v3, p4 = v4, p5 = v5, p6 = v6) public

returns a list of addrinfo objects as an array.

This method converts nodename (hostname) and service (port) to addrinfo. Since the conversion is not unique, the result is a list of addrinfo objects.

nodename or service can be nil if no conversion intended.

family, socktype and protocol are hint for preferred protocol. If the result will be used for a socket with SOCK_STREAM, SOCK_STREAM should be specified as socktype. If so, Addrinfo.getaddrinfo returns addrinfo list appropriate for SOCK_STREAM. If they are omitted or nil is given, the result is not restricted.

Similarly, PF_INET6 as family restricts for IPv6.

flags should be bitwise OR of Socket::AI_??? constants such as follows. Note that the exact list of the constants depends on OS.

AI_PASSIVE      Get address to use with bind()
AI_CANONNAME    Fill in the canonical name
AI_NUMERICHOST  Prevent host name resolution
AI_NUMERICSERV  Prevent service name resolution
AI_V4MAPPED     Accept IPv4-mapped IPv6 addresses
AI_ALL          Allow all addresses
AI_ADDRCONFIG   Accept only if any address is assigned

Note that socktype should be specified whenever application knows the usage of the address. Some platform causes an error when socktype is omitted and servname is specified as an integer because some port numbers, 512 for example, are ambiguous without socktype.

Addrinfo.getaddrinfo("www.kame.net", 80, nil, :STREAM)
#=> [#<Addrinfo: 203.178.141.194:80 TCP (www.kame.net)>,
#    #<Addrinfo: [2001:200:dff:fff1:216:3eff:feb1:44d7]:80 TCP (www.kame.net)>]
Show source
Register or log in to add new notes.