gethostbyaddr()

get a network host entry, given an Internet address

Synopsis:

#include <netdb.h>

struct hostent *gethostbyaddr( const char *addr,
                               int len,
                               int type );

Description:

The gethostbyaddr() function searches the host database for an Internet host. The arguments are:

addr
The address of the host.
len
The length, in bytes, of addr.
type
The type of address. Currently, this must be AF_INET.

This function returns a pointer to a structure of type hostent that describes an Internet host. This structure contains either the information obtained from the name server, named, or broken-out fields from a line in /etc/hosts.

You can use sethostent() to request the use of a connected TCP socket for queries. If the stayopen flag is nonzero, all queries to the name server will use TCP and the connection will be retained after each call to gethostbyname() or gethostbyaddr(). If the stayopen flag is zero, queries use UDP datagrams.

Returns:

A pointer to a valid hostent structure, or NULL if an error occurs (h_errno is set).

Errors:

See herror().

Files:

/etc/hosts
Host database file.

Classification:

POSIX 1003.1g (draft)

Safety:
Interrupt handler No
Signal handler No
Thread No

Caveats:

This function uses static data storage; if the data is needed for future use, it should be copied before any subsequent calls overwrite it. Currently, only the Internet address format is understood.

See also:

endhostent(), gethostbyname(), gethostent(), herror(), hostent, sethostent()

/etc/hosts, named, /etc/resolv.conf in the TCP/IP User's Guide