Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ gethostbyaddr_r(3) — OSF/1 3.0 αXP

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

gethostbyname(3)

endhostent(3)

sethostent(3)

resolv.conf(4)

gethostbyaddr(3)  —  Subroutines

NAME

gethostbyaddr, gethostbyaddr_r − Gets a network host entry by address

LIBRARY

Standard C Library (libc.a)

SYNOPSIS

#include <netdb.h>

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

int ∗gethostbyaddr_r(
const char ∗addr,
int len,
int type,
struct hostent ∗hptr,
struct hostent_data ∗hdptr);

PARAMETERS

addrSpecifies an Internet address in network order. 

lenSpecifies the number of bytes in an Internet address. 

typeSpecifies the Internet domain address format. The value AF_INET must be used. 

hdptrIs data for the host database. 

hptrPoints to the hostent structure. 

DESCRIPTION

The gethostbyaddr() function searches the /etc/hosts network hostname file sequentially until a match with the addr and type parameters occurs. The len parameter must specify the number of bytes in an Internet address. The address parameter must specify the address in network order. The type parameter must be the constant AF_INET, which specifies the Internet address format. When EOF (End-of-File) is reached without a match, an error value is returned. 

The gethostbyaddr() function returns a pointer to a structure of type hostent. Its members specify data obtained from a name server specified in the /etc/resolv.conf file or from fields of a record line in the /etc/hosts network hostname database file.  When the name server is not running, the gethostbyaddr() function searches the hosts name file. The hostent structure is defined in the netdb.h header file. 

Use the endhostent() function to close the /etc/hosts file. 

The system searches either the local /etc/hosts file or one of the files distributed by BIND or NIS for the requested information.  To determine which file or files to search, and in which order, the system uses the switches in the /etc/svc.conf file. 

The gethostbyaddr_r() function is the reentrant version of gethostbyaddr().  Upon successful completion, the returned structure is stored in hptr.  The netdb.h header file defines the hostent and hostent_data structures. 

NOTES

For gethostbyaddr(), a return value points to static data, which is overwritten by any subsequently called functions using the same structure. 

You must zero-fill the hdptr structure before its first access by the gethostbyaddr_r() function. 

RETURN VALUES

Upon successful completion of gethostbyaddr(), a pointer to a hostent structure is returned.  A NULL pointer is returned whenever the end of the hosts network hostname file is reached. 

Upon successful completion of gethostbyaddr_r(), a value of 0 (zero) is returned.  Upon error, a value of -1 is returned. 

ERRORS

If any of the following conditions occurs, the gethostbyaddr_r() function sets errno to the corresponding value:

[EINVAL]The name, hptr, or hdptr is invalid, or type is not AF_INET. 

FILES

/etc/hostsThis file is the DARPA Internet network hostname database. Each record in the file occupies a single line and has three fields consisting of the host address, official hostname, and aliases. 

RELATED INFORMATION

Functions: gethostbyname(3), endhostent(3), sethostent(3). 

Files: resolv.conf(4)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026