I believe your bug is here :
while(addr_str != NULL)
{
if(selected_ip_adr == addr_str->IpAddress.String)
{
found = true;
break;
}
}
Change the while
to if (addr_str != NULL)
then
it should look like
if (add_str != NULL)
{
if (selected_ip_adr == addr_str->IpAddress.String)
{
PrintMACaddress(pAdapterInfo->Address);
}
}
pAdapterInfo = pAdapterInfo->Next;
This should handle if pAdapterInfo is null by using the do/while on the subsequent next
calls.
See IP_ADAPTER_INFO structure at MSDN.