WSAAddressToString

The Windows Sockets WSAAddressToString function converts all components of a SOCKADDR structure into a human-readable string representation of the address.

This is intended to be used mainly for display purposes. If the caller wants the translation to be done by a particular provider, it should supply the corresponding WSAPROTOCOL_INFO structure in the lpProtocolInfo parameter.

INT WSAAddressToString(
  LPSOCKADDR lpsaAddress,             
  DWORD dwAddressLength,              
  LPWSAPROTOCOL_INFO lpProtocolInfo,  
  OUT LPTSTR lpszAddressString,       
  IN OUT LPDWORD lpdwAddressStringLength  
);
 

Parameters

lpsaAddress
[in] A pointer to the SOCKADDR structure to translate into a string.
dwAddressLength
[in] The length of the address in SOCKADDR,which may vary in size with different protocols.
lpProtocolInfo
[in] (Optional) The WSAPROTOCOL_INFO structure for a particular provider. If this is NULL, the call is routed to the provider of the first protocol supporting the address family indicated in lpsaAddress.
lpszAddressString
[in] A buffer that receives the human-readable address string.
lpdwAddressStringLength
[in/out] On input, the length of the AddressString buffer. On output, returns the length of the string actually copied into the buffer. If the supplied buffer is not large enough, the function fails with a specific error of WSAEFAULT and this parameter is updated with the required size in bytes.

Return Values

If no error occurs, WSAAddressToString returns a value of zero. Otherwise, the value SOCKET_ERROR is returned, and a specific error number can be retrieved by calling WSAGetLastError.

Error Codes

WSAEFAULT The specified lpcsAddress, lpProtocolInfo, lpszAddressString are not all in the address space of the process, or the lpszAddressString buffer is too small. Pass in a larger buffer.
WSAEINVAL The specified address is not a valid socket address, or there was no transport provider supporting its indicated address family.
WSANOTINITIALIZED The Winsock 2 DLL has not been initialized. The application must first call WSAStartup before calling any Windows Sockets functions.
WSA NOT ENOUGH MEMORY There was insufficient memory to perform the operation.

QuickInfo

  Windows NT: Yes
  Windows: Yes
  Windows CE: Unsupported.
  Header: Declared in winsock2.h.
  Import Library: Link with ws2_32.lib.