HP-UX Reference (11i v2 07/12) - 3 Library Functions A-M (vol 6)

g
getaddrinfo(3N) getaddrinfo(3N)
If the flag bit NI_NAMEREQD is
set, an error is returned if the host’s name cannot be located in the
DNS.
If the flag bit
NI_NUMERICSERV
is set, the numeric form of the service address is returned (e.g., its
port number) instead of its name. The two
NI_NUMERIC xxx flags are required to support the -n flag that
many commands provide.
A fifth flag bit,
NI_DGRAM
, specifies that the service is a datagram service, and causes get-
servbyport()
to be called with a second argument of "udp" instead of its default of "tcp". This is
required for the few ports (512-514) that have different services for UDP and TCP.
These NI_xxx flags are defined in
<netdb.h> along with the AI_xxx flags already defined for getad-
drinfo()
.
Name Service Switch-Based Operation
The getnameinfo()
and getaddrinfo()
library routines internally call the name service switch to
access the
ipnodes database lookup policy configured in the
/etc/nsswitch.conf
file (see
nsswitch.conf(4)) for the name/address resolution, and
services database lookup policy for the
service/port resolution. The lookup policy defines the order and criteria of the supported name services
that can be used for resolution. If addresses are not gathered after contacting all the
ipnodes directives,
and if the caller has set the
ai_family to AF_INET or set ai_flags to AI_V4MAPPED with an
ai_family of AF_INET6, getaddrinfo()
/getnameinfo() uses the hosts directive in the
/etc/nsswitch.conf
file to resolve the hostname/address. In this case, when the hosts directive
hostname/address resolution fails, the error number returned will be that of the error returned by the
hosts directive lookup. The operations of these name services, Domain Name Server and Nonserver
Modes, are described below:
Domain Name Server Operation
If the local system is configured to use the BIND name server, named (see named(1M) and resolver(4)) for
name/address resolution, the function
getnameinfo()
/getaddrinfo() retrieves the host informa-
tion from the name server. The host names are matched irrespective of upper or lower case alphatets. For
example, the domain names
berkeley.edu , Berkeley.EDU , and BERKELEY.EDU match the same
entry berkeley.edu in the name server database. When hosts directive is used for hostname/address
resolution, a delay may be observed due to an additional lookup using the sources specified for
hosts
directive.
Nonserver Operation
During a name/address resolution, if the database is configured for files resolution,
getnameinfo() and
getaddrinfo() use the /etc/hosts
file for resolution. Similarly, if the services database is
configured for files resolution, the
/etc/services
file is used for resolution. If the /etc/hosts file is
used for name/address resolution, the method used by the functions
getnameinfo() and getad-
drinfo()
to search an address is listed below:
getnameinfo() Sequentially searches the /etc/hosts file until an address matching the src
parameter is found or till the end of file is encountered.
getaddrinfo() Sequentially searches the /etc/hosts file until a host name (official name or
an alias name) matching the name parameter is found or until the end of file is
encountered. The host names are matched irrespective of upper or lower case
alphabets.
WARNINGS
Obsolescent Interfaces
The following interfaces are included to support existing applications and may be removed in future
releases.
struct hostent *getipnodebyname(const char *name, int af, int flags, int
*error_num);
int getipnodebyaddr(const void *src, size_t len, int af, int
*error_num);
New applications must use the APIs getaddrinfo() and getnameinfo() for name/address resolu-
tion.
466 Hewlett-Packard Company 4 HP-UX 11i Version 2: December 2007 Update