gethostbyname

The Windows Sockets gethostbyname function gets host information corresponding to a hostname.

struct hostent FAR * gethostbyname (

const char FAR * name

);

Parameters

name

[out] A pointer to the null terminated name of the host.

Remarks

gethostbyname
returns a pointer to a hostent structure. The contents of this structure correspond to the hostname name.

The pointer which is returned points to a structure which is allocated by Windows Sockets. The application must never attempt to modify this structure or to free any of its components. Furthermore, only one copy of this structure is allocated per thread, and so the application should copy any information which it needs before issuing any other Windows Sockets function calls.

gethostbyname does not resolve IP address strings passed to it. Such a request is treated exactly as if an unknown host name were passed. An application with an IP address string to resolve should use inet_addr to convert the string to an IP address, then gethostbyaddr to obtain the hostent structure.

gethostbyname will resolve the string returned by a successful call to gethostname.

Return Values

If no error occurs, gethostbyname returns a pointer to the hostent structure described above. Otherwise, it returns a NULL pointer and a specific error number can be retrieved by calling WSAGetLastError.

Error Codes

WSANOTINITIALISED
A successful WSAStartup must occur before using this function.
WSAENETDOWN
The network subsystem has failed.
WSAHOST_NOT_FOUND
Authoritative Answer Host not found.
WSATRY_AGAIN
Non-Authoritative Host not found, or server failure.
WSANO_RECOVERY
Nonrecoverable error occurred.
WSANO_DATA
Valid name, no data record of requested type.
WSAEINPROGRESS
A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
WSAEFAULT
The name argument is not a valid part of the user address space.
WSAEINTR
The (blocking) call was canceled through WSACancelBlockingCall.

See Also

gethostbyaddr
, WSAAsyncGetHostByName

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database