1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
____________________________________________________________________________________________________________
// Function: GetIPInterfaceList
//
// Description:
// This function returns an array of SOCKADDR_IN structures,
// one for every local IP interface on the machine.
//_____________________________________________________________________________________________________________
SOCKADDR_IN *GetIPInterfaceList(SOCKET s, int *count)
{
static SOCKADDR_IN sa_in[MAX_NUM_CSADDRS];
INTERFACE_INFO iflist[MAX_INTERFACE_LIST];
DWORD dwBytes;
int ret, i;
*count = 0;
ret = WSAIoctl(s, SIO_GET_INTERFACE_LIST, NULL, 0, &iflist,
sizeof(iflist), &dwBytes, NULL, NULL);
if (ret == SOCKET_ERROR){
return NULL;
}
// Loop through the interfaces and copy them into the SOCKADDR_IN
// array.
//
*count = dwBytes / sizeof(INTERFACE_INFO);
for(i=0; i < *count ;i++)
{
memcpy(&sa_in[i], &iflist[i].iiAddress.AddressIn, sizeof(SOCKADDR_IN));
}
return sa_in;
} |
Partager