<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.3790.2577" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hello Matt,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Depending on what StartRoutine does, it might not
be a good idea to spawn a thread for each interface. In my case, all interfaces
use a single list, so each having a thread would make the program more complex
because of so many tasks acessing the list (I'd need mutexes and locks and
such).</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>My current implementation (working steadily and
fast for a while now) is to create a single </FONT><FONT face=Arial
size=2>thread for all the interfaces, and loop through the devices.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Bye,</FONT></DIV>
<DIV><FONT face=Arial size=2>Ramiro Polla</FONT></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=mjaffa@gmail.com href="mailto:mjaffa@gmail.com">matt jaffa</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=winpcap-users@winpcap.org
href="mailto:winpcap-users@winpcap.org">winpcap-users@winpcap.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Tuesday, March 28, 2006 6:00
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [Winpcap-users] Correct
Initialization for winpcap</DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV>
<DIV>Hi,</DIV>
<DIV><FONT face=Arial size=2></FONT> </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><FONT face=Arial size=2></FONT> </DIV>
<DIV>Thanks,</DIV>
<DIV>Matt</DIV>
<DIV><FONT face=Arial size=2></FONT> </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><FONT face=Arial></FONT> </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>
<P></P><FONT size=2></FONT>
<HR>
<P></P>_______________________________________________<BR>Winpcap-users
mailing
list<BR>Winpcap-users@winpcap.org<BR>https://www.winpcap.org/mailman/listinfo/winpcap-users<BR></BLOCKQUOTE></BODY></HTML>