Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

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

&pagelevel(3)&pagelevel

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

Kernighan-Ritchie-C:
struct hostent *gethostbyaddr(addr, len, type);

char *addr;
int len;
int type;

struct hostent *gethostbyname(name);

char *name;

ANSI-C:
struct hostent* gethostbyaddr(char* addr, int len, int type);
struct hostent* gethostbyname(char* name);


Description

Use of the gethostbyaddr() and gethostbyname() functions only makes sense in the AF_INET address family.

The gethostbyaddr() and gethostbyname() functions return current information on all known hosts on the network by obtaining the required information (host name and host address) from a DNS server. Otherwise, i.e. only in cases where this is not successful, the information taken from the BCAM processor table (see the “BCAM Volume 1/2” manual for details).

For gethostbyaddr(), addr is a pointer to the host address. This host address must be available in binary format with the length len. The only valid entry for type is AF_INET.For gethostbyname(), the host name must be specified for name.

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

The hostent structure is declared as follows:

struct hostent {
   char *h_name;           /* socket 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 */ 
};
#define h_addr h_addr_list[0]; /* first address, network byte order */

Description of hostent components:

h_name

Name of the host

h_aliases

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

h_addrtype

Type of the returned address (always AF_INET)

h_length

Length of the address in bytes

**h_addr_list

A pointer to a null-terminated list of network addresses for the host. These addresses of length h_length are returned in network byte order.

Return value

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

Note

The data returned in the hostent object is supplied in a static area that is overwritten with each new gethostby...() call. It must therefore be copied if it needs to be saved.

As of version V2.2, the LWRESD resolver which is common to SOCKETS(BS2000), BCAM und POSIX sockets is used to access the DNS in the case of gethostbyname() and gethostbyaddr(). For more details, see the manual “BCAM Volume 1/2”.
The POSIX resolver daemon dnsd is no longer used.