WSALookupServiceNext (ws2_32)
Last changed: -192.31.21.182

.
Summary
Iterate through available network connections

C# Signature:

[DllImport("ws2_32.dll", CharSet = CharSet.Auto, SetLastError=true)]
static extern Int32 WSALookupServiceNext(Int32 hLookup, Int32 dwControlFlags,ref Int32 lpdwBufferLength, IntPtr pqsResults);

VB Signature:

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

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

        WSAData data = new WSAData();
        int result = 0;

        result = WSAStartup(2, out data);
        if (result == WSAError.Success)
        {
        WSAQUERYSET lpRestrictions = new WSAQUERYSET();
        lpRestrictions.dwSize = Marshal.SizeOf(lpRestrictions);
        int hLookup = 0;
        if (WSALookupServiceBegin(ref lpRestrictions, 4080, ref hLookup) != (int)SocketError.SocketError)
        {
            int nextresult = 0;

            while (nextresult != WSAError.WSAENOMORE && nextresult != WSAError.WSA_E_NO_MORE && nextresult != WSAError.Error)
            {
            int dwLength = 5000;
            WSAQUERYSET qs = new WSAQUERYSET();
            IntPtr pqs = Marshal.AllocHGlobal(dwLength);
            nextresult = WSALookupServiceNext(hLookup, 4080, ref dwLength, pqs);
            if (nextresult == 0)
            {
                qs = Marshal.PtrToStructure<WSAQUERYSET>(pqs);
                System.Diagnostics.Debug.WriteLine(qs.szServiceInstanceName);
            }
            else
            {
                nextresult = Marshal.GetLastWin32Error();
            }
            Marshal.FreeHGlobal(pqs);
            }

            WSALookupServiceEnd(hLookup);
        }

        WSACleanup();
        }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation