| Red Hat Documentation: man pages: man3: Linux Programmer's Manual (3) |
GETHOSTBYNAMESection: Linux Programmer's Manual (3)Updated: April 19, 2025 Index NAMEgethostbyname, gethostbyaddr, sethostent, endhostent, herror, hstrerror - get network host entrySYNOPSIS#include <netdb.h> extern int h_errno; struct hostent *gethostbyname(const char *name); #include <sys/socket.h> /* for AF_INET */ struct hostent *gethostbyaddr(const char *addr, int len, int type); void sethostent(int stayopen); void endhostent(void); void herror(const char *s); const char * hstrerror(int err); DESCRIPTIONThe gethostbyname() function returns a structure of type hostent for the given host name. Here name is either a host name, or an IPv4 address in standard dot notation, or an IPv6 address in colon (and possibly dot) notation. (See RFC 1884 for the description of IPv6 addresses.) If name is an IPv4 or IPv6 address, no lookup is performed and gethostbyname() simply copies name into the h_name field and its struct in_addr equivalent into the h_addr_list[0] field of the returned hostent structure. If name doesn't end in a dot and the environment variable HOSTALIASES is set, the alias file pointed to by HOSTALIASES will first be searched for name. (See for the file format.) The current domain and its parents are searched unless name ends in a dot.The gethostbyaddr() function returns a structure of type hostent for the given host address addr of length len and address type type. The only valid address type is currently AF_INET. The sethostent() function specifies, if stayopen is true (1), that a connected TCP socket should be used for the name server queries and that the connection should remain open during successive queries. Otherwise, name server queries will use UDP datagrams. The endhostent() function ends the use of a TCP connection for name server queries. The (obsolete) herror() function prints the error message associated with the current value of h_errno on stderr. The (obsolete) hstrerror() function takes an error number (typically h_errno) and returns the corresponding message string. The domain name queries carried out by gethostbyname() and gethostbyaddr() use a combination of any or all of the name server Information Service (NIS or YP), depending upon the contents of the order line in /etc/host.conf. (See resolv+(8)). /etc/hosts. The hostent structure is defined in <netdb.h> as follows:
The members of the hostent structure are:
RETURN VALUEThe gethostbyname() and gethostbyaddr() functions return the hostent structure or a NULL pointer if an error occurs. On error, the h_errno variable holds an error number.ERRORSThe variable h_errno can have the following values:
FILES
CONFORMING TOBSD 4.3SEE ALSOresolv+(8),
IndexThis document was created by using the manual pages. Time: 11:58:05 GMT, March 24, 2025 |
|
© 2001 Red Hat, Inc. All rights reserved. About Red Hat : Legal statement : Privacy statement : Y2K statement : Contact Red Hat |