Get a network host entry by name
struct hostent *gethostbyname_r(
const char * name,
struct hostent * result,
char * buffer,
int * h_errnop );
- The name of the Internet host whose entry you want to find.
- A pointer to a struct hostent where the function can
store the host entry.
- A pointer to a buffer that the function can use during the operation
to store host database entries; buffer should be large enough to
hold all of the data associated with the host entry.
A 2 KB buffer is usually more than enough; a 256-byte buffer is safe in most
- The length of the area pointed to by buffer.
- A pointer to a location where the function can store an
value if an error occurs.
Use the -l socket option to
to link against this library.
The gethostbyname_r() function is a thread-safe version of
This function gets the network host entry for the host specified by
name, and stores the entry in the struct hostent
pointed to by result.
A pointer to result, or NULL if an error occurs.
If an error occurs, the int pointed to by h_errnop
is set to:
- The supplied buffer isn't large enough to store the result.
- Authoritative answer: Unknown host.
- No address associated with name; look for an MX record.
- Valid name, but no data record of the requested type.
The name is known to the name server, but has no IP
address associated with it—this isn't a temporary
error. Another type of request to the name server using this
domain name will result in an answer (e.g. a
mail-forwarder may be registered for this domain).
- Unknown server error. An unexpected server failure was encountered.
This is a nonrecoverable network error.
- Nonauthoritative answer: Host name lookup failure.
This is usually a temporary error and means that the
local server didn't receive a response from an authoritative
server. A retry at some later time may succeed.
- Local host database file.
- Name-service switch configuration file.
For information about these files, see the Utilities Reference.
in the Utilities Reference