Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

OSS Library Calls (g - h) gethostbyname2(3)
NAME
gethostbyname2 - Gets an Internet host entry by name and IPv4 or IPv6 address family
LIBRARY
G-series native OSS processes: /G/system/sysnn/zinetsrl
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zinetdll |
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/yinetdll |
SYNOPSIS
#include <netdb.h>
extern h_errno;
struct hostent *gethostbyname2 (
const char *name,
int af);
PARAMETERS
name Points to either the official name or an alias of the host whose Internet address is
to be found.
af Specifies the address family searched for and returned by the function. Valid
values are AF_INET (IPv4) or AF_INET6 (IPv6).
DESCRIPTION
The gethostbyname2( ) function searches host entries sequentially until a match with the value
pointed to by the name parameter occurs.
The gethostbyname2( ) function returns a pointer to a structure of type hostent whose members
specify data obtained from a name server specified in the /etc/resolv.conf file or from fields of a
record line in the /etc/hosts network hostname database file. (When the name server is not run-
ning and /etc/resolv.conf cannot be searched, this function searches the /etc/hosts name file.)
The <netdb.h> header file defines the hostent structure.
EXAMPLE
This example makes a call to gethostbyname2( ) by passing the host name and address family as
arguments. If an answer is found, a pointer to the hostent structure is returned and stored in hp.
NULL is returned if no answer is found.
int af;
char *name;
struct hostent *hp;
hp = gethostbyname2(name, af);
NOTES
The name value passed to the gethostbyname2( ) function is case-sensitive.
The hostent structure is statically declared. Subsequent calls to gethostbyname2( ) replace the
existing data in the hostent structure.
RETURN VALUES
Upon successful completion, gethostbyname2( ) returns a pointer to a structure (based on the
hostent structure) in which information on the specified host is returned. The information
includes the ofcial name, aliases, and addresses for the host.
If the call to gethostbyname2( ) fails, a null pointer is returned.
527187-017 Hewlett-Packard Company 357