Manual Pages for Linux CentOS command on man gethostbyname
MyWebUniversity

Manual Pages for Linux CentOS command on man gethostbyname

GETHOSTBYNAME(3) Linux Programmer's Manual GETHOSTBYNAME(3)

NAME gethostbyname, gethostbyaddr, sethostent, gethostent, endhostent, herrno, herror, hstrerror, gethostbyaddrr, gethostbyname2, gethostby‐

name2r, gethostbynamer, gethostentr - get network host entry SYNOPSIS

#include extern int herrno; struct hostent *gethostbyname(const char *name);

#include /* for AFINET */ struct hostent *gethostbyaddr(const void *addr, socklent len, int type); void sethostent(int stayopen); void endhostent(void); void herror(const char *s); const char *hstrerror(int err); /* System V/POSIX extension */ struct hostent *gethostent(void); /* GNU extensions */ struct hostent *gethostbyname2(const char *name, int af); int gethostentr( struct hostent *ret, char *buf, sizet buflen, struct hostent **result, int *herrnop); int gethostbyaddrr(const void *addr, socklent len, int type, struct hostent *ret, char *buf, sizet buflen, struct hostent **result, int *herrnop); int gethostbynamer(const char *name, struct hostent *ret, char *buf, sizet buflen, struct hostent **result, int *herrnop); int gethostbyname2r(const char *name, int af, struct hostent *ret, char *buf, sizet buflen, struct hostent **result, int *herrnop); Feature Test Macro Requirements for glibc (see featuretestmacros(7)): gethostbyname2(), gethostentr(), gethostbyaddrr(), gethostbynamer(), gethostbyname2r(): BSDSOURCE || SVIDSOURCE herror(), hstrerror(): Since glibc 2.8: BSDSOURCE || SVIDSOURCE || GNUSOURCE Before glibc 2.8: none DESCRIPTION The gethostbyname*() and gethostbyaddr*() functions are obsolete. Applications should use getaddrinfo(3) and getnameinfo(3) instead. The gethostbyname() function returns a structure of type hostent for the given host name. Here name is either a hostname, or an IPv4 address in standard dot notation (as for inetaddr(3)), 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 hname field and its struct inaddr equivalent into the haddrlist[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 hostname(7) 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. Valid address types are AFINET and AFINET6. The host address argument is a pointer to a struct of a type depending on the address type, for exam‐ ple a struct inaddr * (probably obtained via a call to inetaddr(3)) for address type AFINET. 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. Oth‐ erwise, 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 herrno on stderr. The (obsolete) hstrerror() function takes an error number (typically herrno) and returns the corresponding message string. The domain name queries carried out by gethostbyname() and gethost‐ byaddr() use a combination of any or all of the name server named(8), a broken out line from /etc/hosts, and the Network Information Service (NIS or YP), depending upon the contents of the order line in /etc/host.conf. The default action is to query named(8), followed by /etc/hosts. The hostent structure is defined in as follows: struct hostent { char *hname; /* official name of host */ char **haliases; /* alias list */ int haddrtype; /* host address type */ int hlength; /* length of address */ char **haddrlist; /* list of addresses */ }

#define haddr haddrlist[0] /* for backward compatibility */ The members of the hostent structure are: hname The official name of the host. haliases An array of alternative names for the host, terminated by a NULL pointer. haddrtype The type of address; always AFINET or AFINET6 at present. hlength The length of the address in bytes. haddrlist An array of pointers to network addresses for the host (in net‐ work byte order), terminated by a NULL pointer. haddr The first address in haddrlist for backward compatibility. RETURN VALUE The gethostbyname() and gethostbyaddr() functions return the hostent structure or a NULL pointer if an error occurs. On error, the herrno

variable holds an error number. When non-NULL, the return value may point at static data, see the notes below. ERRORS The variable herrno can have the following values: HOSTNOTFOUND The specified host is unknown. NOADDRESS or NODATA The requested name is valid but does not have an IP address. NORECOVERY A nonrecoverable name server error occurred. TRYAGAIN A temporary error occurred on an authoritative name server. Try again later. FILES /etc/host.conf resolver configuration file /etc/hosts host database file /etc/nsswitch.conf name service switch configuration CONFORMING TO

POSIX.1-2001 specifies gethostbyname(), gethostbyaddr(), sethostent(), endhostent(), gethostent(), and herrno; gethostbyname(), gethost‐ byaddr(), and herrno are marked obsolescent in that standard.

POSIX.1-2008 removes the specifications of gethostbyname(), gethost‐ byaddr(), and herrno, recommending the use of getaddrinfo(3) and get‐ nameinfo(3) instead. NOTES The functions gethostbyname() and gethostbyaddr() may return pointers to static data, which may be overwritten by later calls. Copying the struct hostent does not suffice, since it contains pointers; a deep copy is required. In the original BSD implementation the len argument of gethostbyname() was an int. The SUSv2 standard is buggy and declares the len argument of gethostbyaddr() to be of type sizet. (That is wrong, because it

has to be int, and sizet is not. POSIX.1-2001 makes it socklent, which is OK.) See also accept(2). The BSD prototype for gethostbyaddr() uses const char * for the first argument. System V/POSIX extension POSIX requires the gethostent() call, that should return the next entry in the host data base. When using DNS/BIND this does not make much sense, but it may be reasonable if the host data base is a file that can be read line by line. On many systems a routine of this name reads from the file /etc/hosts. It may be available only when the library was built without DNS support. The glibc version will ignore ipv6 entries. This function is not reentrant, and glibc adds a reentrant version gethostentr(). GNU extensions Glibc2 also has a gethostbyname2() that works like gethostbyname(), but permits to specify the address family to which the address must belong. Glibc2 also has reentrant versions gethostentr(), gethostbyaddrr(), gethostbynamer() and gethostbyname2r(). The caller supplies a hos‐ tent structure ret which will be filled in on success, and a temporary work buffer buf of size buflen. After the call, result will point to the result on success. In case of an error or if no entry is found result will be NULL. The functions return 0 on success and a nonzero error number on failure. In addition to the errors returned by the nonreentrant versions of these functions, if buf is too small, the functions will return ERANGE, and the call should be retried with a larger buffer. The global variable herrno is not modified, but the address of a variable in which to store error numbers is passed in herrnop. BUGS gethostbyname() does not recognize components of a dotted IPv4 address string that are expressed in hexadecimal. SEE ALSO getaddrinfo(3), getnameinfo(3), inet(3), inetntop(3), inetpton(3), resolver(3), hosts(5), nsswitch.conf(5), hostname(7), named(8) COLOPHON

This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can

be found at http://www.kernel.org/doc/man-pages/.

2010-10-04 GETHOSTBYNAME(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™