Skip to content

Latest commit

 

History

History
228 lines (147 loc) · 8.3 KB

nf-winsock2-wsastringtoaddressw.md

File metadata and controls

228 lines (147 loc) · 8.3 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:winsock2.WSAStringToAddressW
WSAStringToAddressW function (winsock2.h)
The WSAStringToAddress function converts a network address in its standard text presentation form into its numeric binary form in a sockaddr structure, suitable for passing to Windows Sockets routines that take such a structure. (Unicode)
WSAStringToAddress
WSAStringToAddress function [Winsock]
WSAStringToAddressW
_win32_wsastringtoaddress_2
winsock.wsastringtoaddress_2
winsock2/WSAStringToAddress
winsock2/WSAStringToAddressW
winsock\wsastringtoaddress_2.htm
WinSock
7b9946c3-c8b3-45ae-9bde-03faaf604bba
12/05/2018
WSAStringToAddress, WSAStringToAddress function [Winsock], WSAStringToAddressA, WSAStringToAddressW, _win32_wsastringtoaddress_2, winsock.wsastringtoaddress_2, winsock2/WSAStringToAddress, winsock2/WSAStringToAddressA, winsock2/WSAStringToAddressW
winsock2.h
Windows
Windows XP, Windows 8.1 [desktop apps \| UWP apps]
Windows Server 2003 [desktop apps \| UWP apps]
WSAStringToAddressW (Unicode) and WSAStringToAddressA (ANSI)
Ws2_32.lib
Ws2_32.dll
Windows
19H1
WSAStringToAddressW
winsock2/WSAStringToAddressW
c++
APIRef
kbSyntax
DllExport
Ws2_32.dll
WSAStringToAddress
WSAStringToAddressA
WSAStringToAddressW

WSAStringToAddressW function

-description

The WSAStringToAddress function converts a network address in its standard text presentation form into its numeric binary form in a sockaddr structure, suitable for passing to Windows Sockets routines that take such a structure.

-parameters

-param AddressString [in]

A pointer to the zero-terminated string that contains the network address in standard text form to convert.

-param AddressFamily [in]

The address family of the network address pointed to by the AddressString parameter.

-param lpProtocolInfo [in, optional]

The WSAPROTOCOL_INFO structure associated 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.

-param lpAddress [out]

A pointer to a buffer that is filled with a sockaddr structure for the address string if the function succeeds.

-param lpAddressLength [in, out]

A pointer to the length, in bytes, of the buffer pointed to by the lpAddress parameter. If the function call is successful, this parameter returns a pointer to the size of the sockaddr structure returned in the lpAddress parameter. If the specified 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.

-returns

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 code Meaning
WSAEFAULT
The buffer pointed to by the lpAddress parameter is too small. Pass in a larger buffer.
WSAEINVAL
The functions was unable to translate the string into a sockaddr. See the following Remarks section for more information.
WSANOTINITIALISED
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.

-remarks

The WSAStringToAddress function converts a network address in standard text form into its numeric binary form in a sockaddr structure.

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.

The WSAStringToAddress function fails (and returns WSAEINVAL) if the sin_family member of the SOCKADDR_IN structure, which is passed in the lpAddress parameter in the form of a sockaddr structure, is not set to AF_INET or AF_INET6.

Support for IPv6 addresses using the WSAStringToAddress function was added on Windows XP with Service Pack 1 (SP1) and later. IPv6 must also be installed on the local computer for the WSAStringToAddress function to support IPv6 addresses.

Windows Phone 8: This function is supported for Windows Phone Store apps on Windows Phone 8 and later.

Windows 8.1 and Windows Server 2012 R2: This function is supported for Windows Store apps on Windows 8.1, Windows Server 2012 R2, and later.

Note

The winsock2.h header defines WSAStringToAddress as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

-see-also

InetNtop

InetPton

RtlIpv4AddressToString

RtlIpv4AddressToStringEx

RtlIpv4StringToAddress

RtlIpv4StringToAddressEx

RtlIpv6AddressToString

RtlIpv6AddressToStringEx

RtlIpv6StringToAddress

RtlIpv6StringToAddressEx

WSAAddressToString

WSAPROTOCOL_INFO

WSAStartup

inet_addr

inet_ntoa

sockaddr