Pegasus InfoCorp: Web site design and web software development company

GETHOSTBYNAME (3)

get network

host entry

SYNOPSIS

    #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 );  
    

DESCRIPTION

    The 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 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. 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 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. (See resolv+ (8)). The default action is to query named(8), followed by /etc/hosts.

    The hostent structure is defined in <netdb.h> as follows:

      7
      8n 16n 32n
      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 addresses */
      }
      #define h_addr  h_addr_list[0]          /* for backward compatibility */
      
      

    The members of the hostent structure are:

    h_name

      The official name of the host.

    h_aliases

      A zero-terminated array of alternative names for the host.

    h_addrtype

      The type of address; always AF_INET at present.

    h_length

      The length of the address in bytes.

    h_addr_list

      A zero-terminated array of network addresses for the host in network byte order.

    h_addr

      The first address in h_addr_list 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 h_errno variable holds an error number.

ERRORS

    The variable h_errno can have the following values:

    HOST_NOT_FOUND

      The specified host is unknown.

    NO_ADDRESS or NO_DATA

      The requested name is valid but does not have an IP address.

    NO_RECOVERY

      A non-recoverable name server error occurred.

    TRY_AGAIN

      A temporary error occurred on an authoritative name server. Try again later.

FILES

    /etc/host.conf

      resolver configuration file

    /etc/hosts

      host database file

CONFORMING TO

    BSD 4.3. The SUS-v2 declares the len parameter to be of type size_t .

RUMOURS

    The future glibc2.2 will follow SUS-v2.

SEE ALSO

    - resolver (3) - hosts(5) - hostname (7) - resolv+(8) - named (8) - ' " ' " Copyright(c) 1994 The Regents of the University of California ' " Copyright(c) 1994-1996 Sun Microsystems Inc ' " ' " See the file "license terms" for information on usage and redistribution ' " of this file and for a DISCLAIMER OF ALL WARRANTIES ' " ' " RCS: @(#) $Id: GetImage 3 v 1 2 1998/09/14 18:22:49 stanton Exp $ ' " ' " The definitions below are for supplemental macros used in Tcl/Tk ' " manual entries ' " ' " AP type name in/out ?indent? ' " Start paragraph describing an argument to a library procedure ' " type is type of argument(int etc ) in/out is either "in" "out" ' " or "in/out" to describe whether procedure reads or modifies arg ' " and indent is equivalent to second arg of IP(shouldn't ever be ' " needed; use AS below instead) ' " ' " AS ?type? ?name? ' " Give maximum sizes of arguments for setting tab stops Type and ' " name are examples of largest possible arguments that will be passed ' " to AP later If args are omitted default tab stops are used ' " ' " BS ' " Start box enclosure From here until next BE everything will be ' " enclosed in one large box ' " ' " BE ' " End of box enclosure ' " ' " CS ' " Begin code excerpt ' " ' " CE ' " End code excerpt ' " ' " VS ?version? ?br? ' " Begin vertical sidebar for use in marking newly-changed parts ' " of man pages The first argument is ignored and used for recording ' " the version when the VS was added so that the sidebars can be ' " found and removed when they reach a certain age If another argument ' " is present then a line break is forced before starting the sidebar ' " ' " VE ' " End of vertical sidebar ' " ' " DS ' " Begin an indented unfilled display ' " ' " DE ' " End of indented unfilled display ' " ' " SO ' " Start of list of standard options for a Tk widget The ' " options follow on successive lines in four columns separated ' " by tabs ' " ' " SE ' " End of list of standard options for a Tk widget ' " ' " OP cmdName dbName dbClass ' " Start of description of a specific option cmdName gives the ' " option's name as specified in the class command dbName gives ' " the option's name in the option database and dbClass gives ' " the option's class in the option database ' " ' " UL arg1 arg2 ' " Print arg1 underlined then print arg2 normally ' " ' " RCS: @(#) $Id: man macros v 1 2 1998/09/14 18:39:54 stanton Exp $ ' " ' " # Set up traps and other miscellaneous stuff for Tcl/Tk man pages t wh -1 3i ^B ^l n( l b ' " # Start an argument description AP !" $4"" TP $4 { !" $2"" TP n()Cu 15