Brief description of gethostbyaddr:
Returns the host information corresponding to the given address.
# Include <Winsock. h>
Struct hostent far * Pascal far gethostbyaddr (const char
Far * ADDR, int Len, int type );
ADDR: pointer to the byte sequential address of the network.
Len: the length of the address. The value is 4 in the pf_inet type.
Type: Address type, which must be pf_inet.
Note:
Gethostbyaddr () returns the hostent structure pointer corresponding to the given address that contains the Host Name and address information. The structure declaration is as follows:
Struct hostent {
Char far * h_name;
Char far * h_aliases;
Short h_addrtype;
Short h_length;
Char far * h_addr_list;
};
Structure members include:
Member Purpose
H_name: Specifies the Host Name (PC ).
H_aliases: an optional host name queue ending with a null pointer.
H_addrtype: Type of the returned address. For Windows Sockets, this field is always pf_inet.
H_legnth the length (number of bytes) of each address, which corresponds to 4 in the pf_inet domain.
H_addr_list should be a list of host addresses ending with a null pointer, and the returned addresses are in network order
To ensure the compatibility of other old software, h_addr_list [0] is defined as macro h_addr.
The returned Pointer Points to a structure allocated by Windows Sockets. The application should not try to modify this structure or release any part of it. In addition, each thread only has a copy of this structure, so the application should copy the information it needs before calling other Windows scokets APIs.
Return Value:
If no error occurs, gethostbyaddr () returns a pointer to the hostent structure described above. Otherwise, a null pointer is returned. The application can get a specific error code through wsagetlasterror.
Error code:
Wsanotintialised must successfully call wsastartup () before applying this API ().
Wsaentdown Windows Sockets implementation detected network subsystem errors.
Wsahost_not_found does not find the authorization response host.
Wsatry_again does not find an unauthorized host or serverfail.
Errors that cannot be recovered by wsano_retimp, such as formerr, refused, and noibd.
Wsano_data is a valid name, but there is no data record about the request type.
Wsaeinprogress a blocked Windows Sockets operation is in progress.
Wsacancelblockingcall () canceled the blocked wsaeintr call.