Hi, tips for WinPcap users.Whenever you use WinPcap, you are forced to select a 
specific network adapter to capture packets.This sample shows you how to select 
the best network adapter automatically by using "GetBestInteface" win32 API.I 
wish I could help you.Thank you.
pcap_if_t* findBestAdapter(PIP_ADAPTER_INFO allIPAdaptersInfo, pcap_if_t* 
alldevs){  DWORD  bestIfIndex;  IPAddr ipAddr = htonl(0x08080808); // "8.8.8.8" 
is well-knowon Google DNS Server IP.  DWORD res = GetBestInterface(ipAddr, 
&bestIfIndex);  if (res != NO_ERROR)  {    printf("GetBestInterface return %d", 
res);    return NULL;  }   PIP_ADAPTER_INFO p = allIPAdaptersInfo;  while (p != 
NULL)  {    if (bestIfIndex == p->Index) break;    p = p->Next;  }  if (p == 
NULL)  {    printf("Can not find appropriate system adapter\n");    return 
NULL;  }   pcap_if_t *d = alldevs;  while (d != NULL)  {    if (strstr(d->name, 
p->AdapterName) != NULL)      break;  }  if (d == NULL)  {    printf("Can not 
find appropriate winpcap adapter\n");    return NULL;  }  return d;}
You can download samples at http://www.gilgil.net/3550 .                        
                  
_______________________________________________
Winpcap-users mailing list
[email protected]
https://www.winpcap.org/mailman/listinfo/winpcap-users

Reply via email to