INtime SDK Help
gethostent (legacy networking)
INtime Help

The gethostbyaddr(), gethostbyname(), sethostent(), endhostent(), _gethtbyaddr(), _gethtbyname(), _sethtent(), _gethtent(), and _endhtent() functions set and return entries that identify the network host.

You can access the HOSTSFILE database file via the INtime Configuration utility:

  1. Start>Programs>INtime>INtime Configuration
  2. Select your node in Node Management.
  3. Click the Advanced tab.
  4. Ensure you are in the CLIB section. The database file displays in the listbox.

Syntax

#include <netdb.h>
struct hostent *gethostbyaddr(addr, len, type)
    char *addr;   
    int len, type;  
struct hostent *gethostbyname(name)
    char *name;
void sethostent(stayopen)
    int stayopen;
void endhostent( )
struct hostent *_gethtbyaddr(addr, len, type) 
    char *addr;
   int len, type; 
struct hostent *_gethtbyname(name)
   char *name;
void _sethtent(stayopen)
   int stayopen;  
struct hostent * _gethtent( )  
void _endhtent( )

Remarks

Network host information can be obtained from either of two places, the hosts database or the Domain Name Service (DNS). The INtime TCP/IP software does not include the named DNS name server. However, it does include a DNS client. The client contacts any DNS name servers running on other hosts on the network and uses their name translation services.

The DNS tunable parameters determine how the two sources are accessed for requested information:

A set of provided functions explicitly retrieves information from the host's database. All information obtained from the host database is contained in a static area so, to save, it must be copied. Only Internet addresses are understood.

The gethostbyname( ) and _gethtbyname( ) functions retrieve a specific entry by host name. Gethostbyname( ) uses the NONAMESERVER environment variable to determine the source; _gethtbyname( ) always searches from the hosts database.

The gethostbyaddr( ) and _gethtbyaddr( ) functions retrieve a specific entry by Internet address. Gethostbyaddr( ) uses the NONAMESERVER environment variable to determine the source; _gethtbyaddr( ) always searches from the hosts database. The Internet address used in both calls should be in host order. The network type should be AF_INET, as defined in the system include file sys/socket.h. The len argument is the length, in bytes, of the address.

To retrieve a sequential series of host entries from the hosts database, it is more efficient to use the _sethtent( ), _gethtent( ), and _endhtent( ) functions. However, the sethostent( ), gethostent( ), and endhostent( ) functions have the same basic behavior described below.

You must pair the calls to _sethtent( ) and _endhtent( ). The _sethtent( ) function opens or rewinds (sets the file pointer to 0) the hosts database.

If passed a 0 value for the argument stayopen, _sethtent( ) opens the :config:hosts file. Subsequent calls to the _gethtent( ) function return the next entry in the hosts database until end of file, opening it if necessary. The _endhtent( ) function closes the database.

If passed a non-zero value for the argument stayopen, _sethtent( ) rewinds the :config:hosts file or opens it, if it is not already open. Subsequent calls to the _gethtent( ) function return the next entry in the hosts database until end of file, opening it if necessary. The host's database remains open until the application executes exit( ). Calling _endhtent( ) does not close the database.

The host entry has this structure:

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] 
};

Where:

h_name
The host's official name.
h_aliases
A list of alternate names for the host. The list is terminated by a null string.
h_addrtype
The type of host address; AF_INET is the only type supported.
h_length
The length, in bytes, of the host address.
h_addr_list
A list of addresses for the host. The first entry in the list can be retrieved by the defined name h_addr as well as by its position in the list. The list is terminated by a 0 address. All host addresses are returned in network byte order.

Return Values

Errors A null pointer is returned by gethostbyaddr( ), gethostbyname( ), _gethtbyaddr( ), _gethtbyname( ), and _gethtent( ) on an EOF or on an error.

Requirements

Versions Defined in Include Link to
INtime 3.1 intime/rt/include/netdb.h net.db.h netiff3m.lib
   
See Also