gethostent()--Get Next Entry from Local Host Table


  Syntax
 #include <netdb.h>

 struct hostent *gethostent()

  Service Program Name: QSOSRV2

  Default Public Authority: *USE

  Threadsafe: No; see Usage Notes.

The gethostent() function is used to retrieve information from the local host table. When gethostent() is first called, the table is opened, and the first entry is returned. Each subsequent call to gethostent() results in the next entry in the table being returned. To close the table, use endhostent().


Authorities

No authorization is required.


Return Value

gethostent() returns a pointer. Possible values are:

The structure struct hostent is defined in <netdb.h>.

      struct hostent {
        char   *h_name;
        char   **h_aliases;
        int    h_addrtype;
        int    h_length;
        char   **h_addr_list;
      };

      #define h_addr  h_addr_list[0]

h_name points to the character string that contains the name of the host.
h_aliases is a pointer to a NULL-terminated list of pointers, each of which points to a character string that represents an alternative name for the host.
h_addrtype contains the address type of the host (for example, AF_INET or AF_INET6).
h_length contains the size of an address in octets (for example, the size of an Internet address is 4 octets).
h_addr_list is a pointer to a NULL-terminated list of pointers, each of which points to a network address (in network byte order) for the host. Note that the array of address pointers points to structures of type in_addr or in6_addr defined in <netinet/in.h>.


Usage Notes

  1. System i® Navigator or the following CL commands can be used to access the local host table:

  2. There are limits to both the number of entries and the size of those entries returned in the hostent structure. The limits are defined in <netdb.h> and entries may be truncated. The string and pointer arrays should be traversed by looking for null terminators rather than relying on hardcoded limits.

    An exception to these limits is made for gethostent() and gethostent_r(). If there are more than NETDB_MAX_ARRAY_SIZE aliases in an entry, then the first NETDB_MAX_ARRAY_SIZE aliases will be returned in the struct hostent structure. The next call to gethostent() will then return the same address with the next NETDB_MAX_ARRAY_SIZE aliases. Each subsequent call to gethostent() will return additional aliases until all the aliases in the entry have been returned.

  3. The pointer returned by gethostent() points to static storage that is overwritten on subsequent calls to the gethostent(), gethostbyaddr(), or gethostbyname() functions.

  4. A coded character set identifier (CCSID) of 65535 requests that no translation be performed. For translation to occur for the host names in the hostent structure, the job CCSID must be something other than 65535.

  5. Do not use the gethostent() function in a multithreaded environment. See the multithread alternative gethostent_r() function.

  6. When you develop in C-based languages and an application is compiled with the _XOPEN_SOURCE macro defined to the value 520 or greater, the gethostent() API is mapped to qso_gethostent98().

Related Information



API introduced: V3R1

[ Back to top | UNIX-Type APIs | APIs by category ]