tags:

views:

354

answers:

1

I'm trying to list available interfaces using the WSAIoctl function. I have to pass in a buffer to hold the complete list. I want to get a count of the interfaces before I allocate memory to hold the interface details but if I pass in a NULL pointer the call just fails (I dont get a valid count returned). Any way to get this count befor I have to allocate memory?

Background is that I am starting a load of processes/threads on on Windows machine which all connect to a single server. I want the server to see these individual connections as coming from different IP addresses and I have added a load of aliases to the test machine to allow for this (lots). The WSAIoct does correctly find all the ones I added.

Cheers...

+1  A: 

From the msdn documentation for WSAIoctl:

Note: If the output buffer is not large enough to contain the address 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 the WSAEFAULT error code is also returned if the lpvInBuffer, lpvOutBuffer, or lpcbBytesReturned parameter is not completely contained in a valid part of the user address space.

So you have to call the WSAIoctl function twice. The first time with an arbitrary buffer and then check for the error codes mentioned in the documentation. Then use the the size returned in lpcbBytesReturned to allocate the buffer and call the WSAIoctl function a second time.

Dani van der Meer
Hmmn, this works for SIO_ADDRESS_LIST_QUERY, I get a different answer for SIO_GET_INTERFACE list. Looking to see what the differences are....
Tim Ring
You are right, I assumed you used SIO_ADDRESS_LIST_QUERY. I have never used SIO_GET_INTERFACE, so I'm afraid I can't help you further. Please let us know if you find a solution.
Dani van der Meer