I have the following the functions:
This function will get every IP Addresses from the local machine
void GetIP()
{
WORD wVersionRequested;
WSADATA wsaData;
char name[ 255 ];
PHOSTENT hostinfo;
wVersionRequested = MAKEWORD( 1, 1 );
char *ip;
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
{
if( gethostname ( name, sizeof( name ) ) == 0 )
{
if ( ( hostinfo = gethostbyname( name ) ) != NULL )
{
int nCount = 0;
while ( hostinfo->h_addr_list[ nCount ] )
{
ip = inet_ntoa( *(struct in_addr *)hostinfo->h_addr_list[ nCount ] );
//printf( "IP #%d: %s\n", ++nCount, ip );
printf( "IP : %s\n", ip );
++nCount;
}
}
}
}
}//GetIP
And here is my second function, which will get every MAC Address from the local machine:
void GetMACaddress()
{
IP_ADAPTER_INFO AdapterInfo[ 16 ]; // Allocate information for up to 16 NICs
DWORD dwBufLen = sizeof( AdapterInfo ); // Save the memory size of buffer
DWORD dwStatus = GetAdaptersInfo( // Call GetAdapterInfo
AdapterInfo,// [out] buffer to receive data
&dwBufLen // [in] size of receive data buffer
);
assert( dwStatus == ERROR_SUCCESS ); // Verify return value is valid, no buffer overflow
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to current adapter info
do
{
printf( "MAC : %02X:%02X:%02X:%02X:%02X:%02X\n", pAdapterInfo->Address[ 0 ],
pAdapterInfo->Address[ 1 ],
pAdapterInfo->Address[ 2 ],
pAdapterInfo->Address[ 3 ],
pAdapterInfo->Address[ 4 ],
pAdapterInfo->Address[ 5 ] );
pAdapterInfo = pAdapterInfo->Next; // Progress through linked list
}while( pAdapterInfo ); // Terminate if last adapter
}//GetMACaddress
So my question is:
How do i know if the queried MAC Address and the queried IP Address belongs to a WiFi?
Thanks!
That code you have for querying MAC addresses, also fetches the interface type.
Starting with Vista, for a WiFi interface, the
Typefield will beIF_TYPE_IEEE80211You can also identify dial-up (MIB_IF_TYPE_PPP) connections and loopback (MIB_IF_TYPE_LOOPBACK) virtual interfaces.As Remy says, you should pull the IP addresses out of that same data structure (there’s an
IpAddressListfield).