Count network interfaces with WSAIoctl function (API WIN32)

I am trying to list the available interfaces using the WSAIoctl function. I have to go to the clipboard to save the complete list. I want to get the number of interfaces before I allocated memory to store the interface details, but if I pass in a NULL pointer, the call just fails (I don't get the correct counter). Any way to get this account up to what I have to allocate memory?

I am assuming I am running loading processes / threads on a windows machine that all connect to the same server. I want the server to see these individual connections as coming from different IPs, and I have added a load of aliases to the test machine to allow this (lots). WSAIoct finds all the ones I added correctly.

Greeting...

0


a source to share


1 answer


From the msdn documentation for WSAIoctl:

Note . If the output buffer is not large enough to contain the address of the list, SOCKET_ERROR is returned as the result of this IOCTL and WSAGetLastError returns WSAEFAULT. the required size, in bytes, for the output buffer is returned in the lpcbBytesReturned parameter in this case. Note that the WSAEFAULT error code is also returned if the lpvInBuffer, lpvOutBuffer, or lpcbBytesReturned parameter is not completely in the valid user address space.



Thus, you must call the WSAIoctl function twice. First time with an arbitrary buffer and then check the error codes mentioned in the documentation. Then use the size returned by lpcbBytesReturned to allocate the buffer and call the WSAIoctl function a second time.

+1


a source







All Articles