Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function retrieves the host information corresponding to a network address.

Note:
The gethostbyaddr function has been deprecated by the introduction of the getnameinfofunction. Developers who create Windows Sockets 2 applications are urged to use the getnameinfo function instead of the gethostbyaddr function. See Remarks.

Syntax

struct hostent FAR* gethostbyaddr(
  const char FAR* 
addr,
  int 
len,
  int 
type
);

Parameters

addr

[in] Pointer to an address in network byte order.

len

[in] Length of the address.

type

[in] Type of the address, such as the AF_INETaddress family type (defined as TCP, UDP, and other associated Internet protocols). Address family types and their corresponding values are defined in the winsock2.h header file.

Return Value

If no error occurs, this function returns a pointer to the hostentstructure that contains the name and address corresponding to the given network address. If an error occurs, it returns a NULL pointer, and a specific error code can be retrieved by calling WSAGetLastError.

The following table shows a list of possible error codes.

Error code Description

WSANOTINITIALISED

A successful WSAStartupcall must occur before using this function.

WSAENETDOWN

The network subsystem has failed.

WSAHOST_NOT_FOUND

An authoritative answer host was not found.

WSATRY_AGAIN

A nonauthoritative host was not found, or the server failed.

WSANO_RECOVERY

A nonrecoverable error occurred.

WSANO_DATA

A valid name exists, but no data record of the requested type exists.

WSAEINPROGRESS

A blocking Winsock call is in progress, or the service provider is still processing a callback function.

WSAEAFNOSUPPORT

The type specified is not supported by the Windows Sockets implementation.

WSAEFAULT

The addrparameter is not a valid part of the user address space, or the lenparameter is too small.

WSAEINTR

The socket was closed.

Remarks

Although gethostbyaddris deprecated by the getnameinfofunction, gethostbyaddris capable of returning a NetBIOS name; getnameinfois not. Developers who require NetBIOS name resolution may need to use gethostbyaddr until their applications are completely independent of NetBIOS names.

Note:
The capability to perform reverse lookups by using the gethostbyaddrfunction is convenient, but such lookups are considered inherently unreliable, and should be used only as a hint.

Requirements

Header winsock2.h
Library Ws2.lib
Windows Embedded CE Windows CE 1.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also