<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 9pt;
font-family:±¼¸²
}
--></style>
</head>
<body class='hmmessage'>
<span class="Apple-style-span" style="font-family: AppleGothic, Tahoma, sans-serif; line-height: 19px; "><div><div>Hi, tips for WinPcap users.</div><div>Whenever you use WinPcap, you are forced to select a specific network adapter to capture packets.</div><div>This sample shows you how to select the best network adapter automatically by using "GetBestInteface" win32 API.</div><div>I wish I could help you.</div><div>Thank you.</div><div><br></div><div>pcap_if_t* findBestAdapter(PIP_ADAPTER_INFO allIPAdaptersInfo, pcap_if_t* alldevs)</div><div>{</div><div> DWORD bestIfIndex;</div><div> IPAddr ipAddr = htonl(0x08080808); // "8.8.8.8" is well-knowon Google DNS Server IP.</div><div> DWORD res = GetBestInterface(ipAddr, &bestIfIndex);</div><div> if (res != NO_ERROR)</div><div> {</div><div> printf("GetBestInterface return %d", res);</div><div> return NULL;</div><div> }</div><div> </div><div> PIP_ADAPTER_INFO p = allIPAdaptersInfo;</div><div> while (p != NULL)</div><div> {</div><div> if (bestIfIndex == p->Index) break;</div><div> p = p->Next;</div><div> }</div><div> if (p == NULL)</div><div> {</div><div> printf("Can not find appropriate system adapter\n");</div><div> return NULL;</div><div> }</div><div> </div><div> pcap_if_t *d = alldevs;</div><div> while (d != NULL)</div><div> {</div><div> if (strstr(d->name, p->AdapterName) != NULL)</div><div> break;</div><div> }</div><div> if (d == NULL)</div><div> {</div><div> printf("Can not find appropriate winpcap adapter\n");</div><div> return NULL;</div><div> }</div><div> return d;</div><div>}</div><div><br></div><div>You can download samples at <a href="http://www.gilgil.net/3550">http://www.gilgil.net/3550</a> .</div></div></span>                                            </body>
</html>