Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

gethostent(), gethostbyname(), gethostbyaddr(), sethostent(), endhostent() - get information about host names and addresses

&pagelevel(4)&pagelevel

#include <sys/socket.h>
#include <netdb.h>

struct hostent *gethostent(void);
struct hostent *gethostbyname(const char *name);
struct hostent *gethostbyaddr(const void *addr, size_t len, int type);
void sethostent(int stayopen);
void endhostent(void);

Description

The gethostbyname() and gethostbyaddr() functions return current information about the host reachable in the network by calling a BCAM information interface. The DNS concept (Domain Name Service) is supported if the DNS Resolver from the product interNet Services (formerly TCP-IP-SV) is installed in POSIX or the subsystem SOCKETS (BS2000) has been started.

In contrast to this, the gethostent() function accesses the file /etc/inet/hosts which normally only contains an entry for the local host.

The gethostbyname(), gethostbyaddr() and gethostent() functions return a pointer to an object with the hostent structure described below.

The hostent structure corresponds to the fields in a line of the host database and is declared as follows:

struct hostent {
   char *h_name;           /* Official host name */
   char **h_aliases;       /* Alias list */
   int h_addrtype;         /* Address type */
   int h_length;           /* Length of the address in bytes */
   char **h_addr_list;     /* List of addresses for the host, */
                           /* terminated by the null pointer */ 
};

hostent components:

h_name

Name of the host.

h_aliases

A list of alternative (alias) names for the host, terminated with null. Alias names are currently not supported.

h_addrtype

Type of the returned address (always AF_INET).

length

Length of the address in bytes.

**h_addr_list

A pointer to a list of network addresses for the host. The addresses are returned in network byte order.

In the case of gethostbyaddr(), addr is a pointer to the address in binary format with the length len (not a character string).

gethostent() reads the next line of the file. If necessary, gethostent() opens the file first.

sethostent() opens the file and resets it to the start. If the stayopen flag is not equal to zero, the database is not closed after any gethostent() call (neither directly nor indirectly via one of the other gethost...() calls).

Return value

The null pointer is returned if errors occur or the end of the file is reached.

Note

All information is in a static area and therefore has to be copied if it is to be saved.
Only the IPv4 address format is supported.