WSAStringToAddress

The Windows Sockets WSAStringToAddress function converts a numeric string to a SOCKADDR structure, suitable for passing to Windows Sockets routines that take such a structure.

INT WSAStringToAddress(
  LPTSTR AddressString,               
  INT AddressFamily,                  
  LPWSAPROTOCOL_INFO lpProtocolInfo,  
  LPSOCKADDR lpAddress,               
  LPINT lpAddressLength               
);
 

Parameters

AddressString
[in] Points to the zero-terminated human-readable numeric string to convert.
AddressFamily
[in] The address family to which the string belongs.
lpProtocolInfo
[in] (optional) the WSAPROTOCOL_INFO structureassociated with the provider to be used. If this is NULL, the call is routed to the provider of the first protocol supporting the indicated AddressFamily.
Address
[out] A buffer that is filled with a single SOCKADDR.
lpAddressLength
[in/out] The length of the Address buffer. Returns the size of the resultant SOCKADDR structure. 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.

Remarks

The WSAStringToAddress function converts alpha-numeric address to SOCKADDR structures. WSAStringToAddress is the protocol independent equivalent of the BSD inet_ntoa function.

Any missing components of the address will be defaulted to a reasonable value, if possible. For example, a missing port number will default to zero. 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.

Return Values

The return value for WSAStringToAddress is zero if the operation was successful. Otherwise, the value SOCKET_ERROR is returned, and a specific error number can be retrieved by calling WSAGetLastError.

Error Codes

WSAEFAULT The specified Address buffer is too small. Pass in a larger buffer.
WSAEINVAL Unable to translate the string into a SOCKADDR.
WSANOTINITIALIZED The WS2_32.DLL has not been initialized. The application must first call WSAStartup before calling any Windows Socket 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.