<div>Hi,</div>
<div> </div>
<div>I was wondering if how I was first initially using winpcap is the correct way of doing it.</div>
<div>So I am looking up all the devices then creating a thread for each device to listen for packets on.</div>
<div>Does this code look right? (Code is below).</div>
<div> </div>
<div>Thanks,</div>
<div>Matt</div>
<div> </div>
<div><font size="2">
<p>pcap_if_t *alldevs;</p>
<p>pcap_if_t *d;</p>
<p></p></font><font color="#0000ff" size="2">int</font><font size="2"> i=0;
<p></p></font><font color="#0000ff" size="2">char</font><font size="2"> errbuf[PCAP_ERRBUF_SIZE];
<p></p>
<p> </p>
<p></p></font><font color="#0000ff" size="2">if</font><font size="2">(pcap_findalldevs(&alldevs, errbuf) == -1) // This is where it hangs when are program is a service
<p>{</p>
<p>fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);</p>
<p></p></font><font color="#0000ff" size="2">return</font><font size="2">;
<p>}</p>
<p></p></font><font color="#0000ff" size="2">for</font><font size="2">(d=alldevs; d; d=d->next)
<p>{ </p>
<p></p></font><font color="#0000ff" size="2">char</font><font size="2"> *deviceName = </font><font color="#0000ff" size="2">new</font><font size="2"> </font><font color="#0000ff" size="2">char</font><font size="2">[256];
<p>sprintf(deviceName, "%s", d->name);</p>
<p>CreateThread(NULL, 0, &StartRoutine, deviceName, 0, NULL); // Each of these threads listen for packets on each device</p>
<p>}</p>
<p>pcap_freealldevs(alldevs);</p></font></div>