gethostbyname

Searches the host database sequentially from the beginning of the database for a host record with a given name or alias.

Format

#include  <netdb.h>

struct hostent *gethostbyname  (char *name);
Routine Variants This socket routine has a variant named __bsd44_gethostbyname. Enabled by defining _SOCKADDR_LEN, this variant implements 4.4BSD-compatible semantics. See Section A.7 for more information.

Argument

name
A pointer to a null-terminated character string containing the name or an alias of the host sought.

Description

This routine finds the first host in the host database with the given name or alias.

The gethostbyname routine uses a common static area for its return values. This means that subsequent calls to this routine will overwrite any existing host entry. You must make a copy of the host entry if you wish to save it.

Return Values
NULL  Indicates an error. 
A pointer to an object having the hostent structure. See <netdb.h> for a description of the hostent structure.

Depending on the error condition and the socket implementation selected, errno or h_errno might be set to further indicate the error. (See sections A.5 and A.6.)  


Previous Page | Next Page | Table of Contents | Index