HP-UX Reference (11i v1 05/09) - 3 Library Functions A-M (vol 6)

g
getipnodebyname(3N) getipnodebyname(3N)
Domain Name Server Operation
If the local system is configured to use the
named name server (see named(1M) and resolver(4)) for name
or address resolution, then the functions:
getipnodebyname()
getipnodebyaddr()
Both retrieve host information from the name server. Names are matched
without respect to uppercase or lowercase. For example,
berkeley.edu , Berkeley.EDU , and BERKELEY.EDU all match the
entry for berkeley.edu . 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
If the
/etc/hosts file is used for name or address resolution, then the function:
getipnodebyaddr()
Sequentially searches from the beginning of the file for Internet addresses
matching its src parameter till EOF is encountered.
getipnodebyname()
Sequentially searches from the beginning of the file for host names (among
either the official names or the aliases) matching its name parameter till
EOF is encountered. Names are matched without respect to uppercase or
lowercase, as described above in the name server case.
The return value,
struct hostent, must be saved before a subsequent call to the functions
gethost*() , getipnodeby*(),
getaddrinfo() and getnameinfo().
In a multithreaded application,
getipnodebyname()
and getipnodebyaddr()
use thread-specific
storage that is re-used in each call. The return value,
struct hostent, should be unique for each
thread and should be saved, if desired, before the thread makes the next getipnode*() , gethost*()
,
getaddrinfo() or getnameinfo()
call. The return value must be saved before a subsequent call to
the function
getipnodebyname()
or getipnodebyaddr(), is made because these functions may
internally call the
gethost*() function which may overwrite the return value, struct hostent.
For enumeration in multithreaded applications, the position within the enumeration is a process-wide pro-
perty shared by all threads.
NOTES: Currently, only the Internet address format is understood. Hence AF_INET and AF_INET6
alone are valid address families.
Arguments
name The name argument to the function, getipnodebyname()
can be either a node name or a
literal address string (i.e., a dotted-decimal IPv4 address or an IPv6 hexadecimal address). This
saves applications from having to call
inet_pton() to handle literal address strings.
af The af argument specifies the address family. Currently address families AF_INET and
AF_INET6, alone, are supported.
flags The flags argument specifies the types of addresses that are to be searched for, and the types
of addresses that are returned. The flags argument can be a bitwise OR of the following
values :
AI_V4MAPPED Return IPv4-Mapped IPv6 addresses only.
AI_ADDRCONFIG Return addresses only if the node has at least one of the interfaces
configured for that particular address family.
AI_ALL Return both IPv6 and IPv4 addresses.
AI_DEFAULT This is defined as AI_V4MAPPED | AI_ADDRCONFIG.
error_num
getipnodebyname()
and getipnodebyaddr()
return errors to the caller via the
error_num pointer passed to these functions. The error value is returned to the caller with
appropriate error code, to support thread safe error code returns. The value of error_num can
be one of those explained under the heading ERRORS below.
In calls to getipnodebyaddr(), the parameter src must be a pointer to an in_addr or in6_addr
structure, an Internet address in network order (see byteorder(3N)) and the header file
<netinet/in.h>). The parameter len must be the number of bytes in an Internet address; that is,
sizeof (struct in_addr) or sizeof (struct in6_addr).
HP-UX 11i Version 1: September 2005 2 Hewlett-Packard Company Section 3335