The Windows Sockets gethostbyname function retrieves host information corresponding to a host name from a host database.
struct hostent FAR * gethostbyname (
const char FAR * name
);
The gethostbyname function returns a pointer to a HOSTENT structure — a structure allocated by Windows Sockets. The HOSTENT structure contains the results of a successful search for the host specified in the name parameter.
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, so the application should copy any information it needs before issuing any other Windows Sockets function calls.
The gethostbyname function cannot resolve IP address strings passed to it. Such a request is treated exactly as if an unknown host name were passed. Use inet_addr to convert an IP address string the string to an actual IP address, then use another function, gethostbyaddr, to obtain the contents of the HOSTENT structure.
The gethostbyname function resolves the string returned by a successful call to gethostname.
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.
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 parameter is not a valid part of the user address space. |
WSAEINTR | A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall. |
Windows NT: Yes
Windows: Yes
Windows CE: Use version 1.0 and later.
Header: Declared in winsock2.h.
Import Library: Link with ws2_32.lib.
gethostbyaddr, WSAAsyncGetHostByName