This function looks up an IP address and port number in a
sockaddr structure specified by sa and returns node name and
service name text strings in the buffers pointed to by the node
and service arguments, respectively.
If the node name is not found, getnameinfo() returns the numeric
form of the node address, regardless of the value of the flags
argument. If the service name is not found, getnameinfo() returns
the numeric form of the service address (port number) regardless
of the value of the flags argument.
The application must provide buffers large enough to hold the
fully-qualified domain name and the service name, including the
terminating null characters.
Flags describes the flag bits and, if set, their meanings. The
flags are defined in the NETDB.H header file.
Table 4-2 getnameinfo() Flags
Flag Value Description
NI_DGRAM Specifies that the service is a datagram
service (SOCK_DGRAM). The default assumes
a stream service (SOCK_STREAM). This is
required for the few ports (512-514) that
have different services for UDP and TCP.
NI_NAMEREQD Returns an error if the host name cannot be
located in the hosts database.
NI_NOFQDN Searches the hosts database and returns the
node name portion of the fully-qualified
domain name for local hosts.
NI_NUMERICHOST Returns the numeric form of the host's address
instead of its name. Resolution of the host
name is not performed.
NI_NUMERICSERV Returns the numeric form (port number) of the
service address instead of its name. The host
name is not resolved.