Each structure in the list contains data that can be directly fed as arguments to the socket() function: ai_family (its value is either PF_INET or PF_INET6 in our case), ai_socktype (usually SOCK_STREAM or SOCK_DGRAM) and ai_protocol (usually IPPROTO_TCP or IPPROTO_UDP). The socket address is found in ai_addr, with ai_addrlen specifying its length.
The nodename argument to getaddrinfo() should contain the domain name we want to look up or, alternatively, an IPv4 or IPv6 address in the usual textual notation. Optionally, we can also fill in the servname argument, either with a service name as defined in /etc/services or a string representing a decimal port number.
Through the hints argument we can specify the data we are interested in. Its type is again addrinfo, although only the following members may be filled in: ai_flags, ai_family, ai_socktype and ai_protocol. Other members must contain NULL. In the case you are prepared to accept everything in a certain category, set the values in the hints argument according to the following table:

If we have no preferences at all, we can pass the NULL as the hints argument.
Even more detailed requirements can be specified in the ai_flags member of the hints argument. As usual, we can combine individual flags using the bitwise OR operation (|). The following flags are available:
AI_PASSIVE
This flag is significant only if NULL has been passed as the nodename argument. By setting
this flag we indicate our intention to use the result of getaddrinfo() directly as an argument to
the bind() function, i.e., on the local side of the socket. The socket address is then filled with
INADDR_ANY for IPv4 and IN6ADDR_ANY_INIT for IPv6. Hence, if we want to use the
result of getaddrinfo() for the remote end of the socket, e.g., in the connect() or sendto()
functions, this flag should be cleared. In the returned result, the IP address part of the socket
address (i.e., sin_addr in sockaddr_in or sin6_addr in sockaddr_in6) will be set to
INADDR_LOOPBACK or IN6ADDR_LOOPBACK_INIT, respectively.
AI_CANONNAME
If this flag is set and argument nodename non-NULL, getaddrinfo() will attempt to look up the canonical domain name as well. This may come handy, for example, if you only know the DNS alias and want to learn the “official” name.
AI_NUMERICHOST
If this flag is set, getaddrinfo() will not use DNS at all. In this case, the nodename argument must be a string representing an IPv4 or IPv6 address.
AI_NUMERICSERV
Setting this flag indicates that the servname parameter is to be interpreted as a decimal port number.
