WSPAddressToString

The WSPAddressToString function converts all components of a SOCKADDR structure into a human-readable numeric string representation of the address. This is used mainly for display purposes.

int WSPAddressToString (
  LPSOCKADDR lpsaAddress,            
  DWORD dwAddressLength,             
  LPWSAPROTOCOL_INFOW lpProtocolInfo,   
  LPWSTR lpszAddressString,          
  LPDWORD lpdwAddressStringLength,   
  LPINT lpErrno                      
);
 

Parameters

lpsaAddress
[in] Points to a SOCKADDR structure to translate into a string.
dwAddressLength
[in] The length of the Address SOCKADDR.
lpProtocolInfo
[in] (required) The WSAPROTOCOL_INFO structure associated with the provider that will do the translation.
lpszAddressString
[out] A buffer which receives the human-readable address string.
lpdwAddressStringLength
[in/out] The length of the AddressString buffer. 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.
lpErrno
[out] A pointer to the error code.

Layered Service Provider Considerations

A layered service provider supplies an implementation of this function, but it is also a client of this function if and when it calls WSPAddressToString of the next layer in the protocol chain. Some special considerations apply to this function's lpProtocolInfo parameter as it is propagated down through the layers of the protocol chain.

If the next layer in the protocol chain is another layer then when the next layer's WSPAddressToString is called, this layer must pass to the next layer a lpProtocolInfo that references the same unmodified WSAPROTOCOL_INFO structure with the same unmodified chain information. However, if the next layer is the base protocol (i.e., the last element in the chain), this layer performs a substitution when calling the base provider's WSPAddressToString. In this case, the base provider's WSAPROTOCOL_INFO structure should be referenced by the lpProtocolInfo parameter.

One vital benefit of this policy is that base service providers do not have to be aware of protocol chains.

This same propagation policy applies when propagating a WSAPROTOCOL_INFO structure through a layered sequence of other functions such as WSPDuplicateSocket, WSPStartup, WSPSocket, or WSPStringToAddress.

Return Values

If no error occurs, WSPAddressToString returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error code is available in lpErrno.

Error Codes

WSAEFAULT The specified AddressString buffer is too small. Pass in a larger buffer.
WSA_EINVAL The specified Address is not a valid socket address, or its address family is not supported by the provider, or the specified lpProtocolInfo did not refer to a WSAPROTOCOL_INFO structure supported by the provider.

QuickInfo

  Windows NT: Yes
  Windows: Yes
  Windows CE: Unsupported.
  Header: Declared in ws2spi.h.