MirOS Manual: endhostent(3), gethostbyaddr(3), gethostbyname(3), gethostbyname2(3), gethostent(3), herror(3), hstrerror(3), sethostent(3)

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

NAME

     gethostbyname, gethostbyname2, gethostbyaddr, gethostent, sethostent,
     endhostent, hstrerror, herror - get network host entry

SYNOPSIS

     #include <netdb.h>

     extern int h_errno;

     struct hostent *
     gethostbyname(const char *name);

     struct hostent *
     gethostbyname2(const char *name, int af);

     struct hostent *
     gethostbyaddr(const void *addr, socklen_t len, int af);

     struct hostent *
     gethostent(void);

     void
     sethostent(int stayopen);

     void
     endhostent(void);

     void
     herror(const char *string);

     const char *
     hstrerror(int err);

DESCRIPTION

     The gethostbyname(), gethostbyname2(), and gethostbyaddr() functions each
     return a pointer to an object with the following structure describing an
     Internet host referenced by name or by address, respectively. This struc-
     ture contains either information obtained from the name server (i.e.,
     resolver(3) and named(8)), broken-out fields from a line in /etc/hosts,
     or database entries supplied by the yp(8) system. resolv.conf(5)
     describes how the particular database is chosen.

           struct  hostent {
                   char    *h_name;        /* official name of host */
                   char    **h_aliases;    /* alias list */
                   int     h_addrtype;     /* host address type */
                   int     h_length;       /* length of address */
                   char    **h_addr_list;  /* list of returned addresses */
           };
           #define h_addr  h_addr_list[0]  /* address, for backward compat */

     The members of this structure are:

     h_name       Official name of the host.

     h_aliases    A null-terminated array of alternate names for the host.

     h_addrtype   The type of address being returned.

     h_length     The length, in bytes, of the address.

     h_addr_list  A null-terminated array of network addresses for the host.
                  Host addresses are returned in network byte order.

     h_addr       The first address in h_addr_list; this is for backward com-
                  patibility.

     The function gethostbyname() will search for the named host in the
     current domain and its parents using the search lookup semantics detailed
     in resolv.conf(5) and hostname(7).

     gethostbyname2() is an advanced form of gethostbyname() which allows
     lookups in address families other than AF_INET. Currently, the only sup-
     ported address family besides AF_INET is AF_INET6.

     The gethostbyaddr() function will search for the specified address of
     length len in the address family af. The only address family currently
     supported is AF_INET.

     The sethostent() function may be used to request the use of a connected
     TCP socket for queries. If the stayopen flag is non-zero, this sets the
     option to send all queries to the name server using TCP and to retain the
     connection after each call to gethostbyname() or gethostbyaddr(). Other-
     wise, queries are performed using UDP datagrams.

     The endhostent() function closes the TCP connection.

     The herror() function prints an error message describing the failure. If
     its argument string is non-null, it is prepended to the message string
     and separated from it by a colon (':') and a space. The error message is
     printed with a trailing newline. The contents of the error message is the
     same as that returned by hstrerror() with argument h_errno.

ENVIRONMENT

     HOSTALIASES  A file containing local host aliases. See hostname(7) for
                  more information.

     RES_OPTIONS  A list of options to override the resolver's internal de-
                  faults. See resolver(3) for more information.

FILES

     /etc/hosts
     /etc/resolv.conf

DIAGNOSTICS

     Error return status from gethostbyname(), gethostbyname2(), and gethost-
     byaddr() is indicated by return of a null pointer. The external integer
     h_errno may then be checked to see whether this is a temporary failure or
     an invalid or unknown host.

     The variable h_errno can have the following values:

     HOST_NOT_FOUND  No such host is known.

     TRY_AGAIN       This is usually a temporary error and means that the lo-
                     cal server did not receive a response from an authorita-
                     tive server. A retry at some later time may succeed.

     NO_RECOVERY     Some unexpected server failure was encountered. This is a
                     non-recoverable error.

     NO_DATA         The requested name is valid but does not have an IP ad-
                     dress; this is not a temporary error. This means that the
                     name is known to the name server but there is no address
                     associated with this name. Another type of request to the
                     name server using this domain name will result in an
                     answer; for example, a mail-forwarder may be registered
                     for this domain.

     NETDB_INTERNAL  An internal error occurred. This may occur when an ad-
                     dress family other than AF_INET or AF_INET6 is specified
                     or when a resource is unable to be allocated.

     NETDB_SUCCESS   The function completed successfully.

SEE ALSO

     getaddrinfo(3), getnameinfo(3), resolver(3), hosts(5), resolv.conf(5),
     hostname(7), named(8)

HISTORY

     The herror() function appeared in 4.3BSD. The endhostent(), gethost-
     byaddr(), gethostbyname(), gethostent(), and sethostent() functions ap-
     peared in 4.2BSD.

CAVEATS

     If the search routines in resolv.conf(5) decide to read the /etc/hosts
     file, gethostent() and other functions will read the next line of the
     file, re-opening the file if necessary.

     The sethostent() function opens and/or rewinds the file /etc/hosts. If
     the stayopen argument is non-zero, the file will not be closed after each
     call to gethostbyname(), gethostbyname2(), or gethostbyaddr().

     The endhostent() function closes the file.

BUGS

     These functions use static data storage; if the data is needed for future
     use, it should be copied before any subsequent calls overwrite it.

     Only the Internet address formats are currently understood.

MirOS BSD #10-current           March 13, 1997                               2

Generated on 2014-07-04 21:17:45 by $MirOS: src/scripts/roff2htm,v 1.79 2014/02/10 00:36:11 tg Exp $

These manual pages and other documentation are copyrighted by their respective writers; their source is available at our CVSweb, AnonCVS, and other mirrors. The rest is Copyright © 2002‒2014 The MirOS Project, Germany.
This product includes material provided by Thorsten Glaser.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report – diffs preferred.