[Winpcap-users] How to get best adapter in winpcap automatically

LeeGilbert gilgil1973 at hotmail.com
Wed Mar 24 02:37:53 PDT 2010


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 . 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20100324/09555359/attachment.htm 


More information about the Winpcap-users mailing list