WSAStringToAddress (ws2_32)
Last changed: -77.124.220.248

.
Summary
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.

C# Signature:

    [DllImport("ws2_32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
    public static extern int WSAStringToAddress(
        string addressString,
        System.Net.Sockets.AddressFamily addressfamily,
        IntPtr lpProtocolInfo,
        ref SockAddr socketAddress,
        ref int socketAddressSize);

VB Signature:

Declare Function WSAStringToAddress Lib "ws2_32.dll" (TODO) As TODO

Parameters:

Notes:

The application must first call WSAStartup before calling WSAStringToAddress.

Sample Code:

    WSADATA data = new WSADATA();
    SockAddr sockAddr = new SockAddr();
    IntPtr pSockAddr = IntPtr.Zero;

    if (WSAStartup(0x201, ref data) == ERROR_SUCCESS)
    {
        int sockAddrSize = Marshal.SizeOf(sockAddr);

        int result = WSAStringToAddress(
        "1.2.3.4",
        System.Net.Sockets.AddressFamily.InterNetwork,
        IntPtr.Zero,
        ref sockAddr,
        ref sockAddrSize);

        WSACleanup();
    }

    if (result != ERROR_SUCCESS)
    {
         throw new Win32Exception(result);
    }

    pSockAddr = Marshal.AllocHGlobal(Marshal.SizeOf(sockAddr));
    Marshal.StructureToPtr(sockAddr, pSockAddr, true);

Documentation