<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<STYLE>P {
        PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px
}
BODY {
        FONT-SIZE: 10pt; FONT-FAMILY: Tahoma
}
</STYLE>
<META content="MSHTML 6.00.6000.16414" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face="Courier New">I don't think it would make any difference, in any
case the thread function you are using has the wrong prototype (hence the need
for the explicit cast in CreateThread).</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">The right prototype for the thread fcn passed to
CreateThread is</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">DWORD WINAPI GetINetDevice(LPVOID
lpParam);</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">Also, have you changed the C-runtime library from
single threaded (the default one for VC6, I don't remember for more recent
versions of VS/VC) to multithreaded?</FONT></DIV>
<DIV><FONT face="Courier New"></FONT> </DIV>
<DIV><FONT face="Courier New">Have a nice day</FONT></DIV>
<DIV><FONT face="Courier New">GV</FONT></DIV>
<DIV><FONT face="Courier New"></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=martins_ajc@msn.com href="mailto:martins_ajc@msn.com">Avelino
Martins</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> Thursday, April 19, 2007 2:18
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [Winpcap-users] Problem with
threading</DIV>
<DIV><FONT face="Courier New"></FONT><BR></DIV>Hello all, <BR>despite all the
threads i readed about issues on threading problems, i couldn't get to a
conclusion at the specific issue of the function <FONT color=#010001
size=2><BR>pcap_findalldevs() hanging when called from a child thread, take
the simple example:<BR> <BR><FONT color=#010001 size=2><FONT
color=#0000ff size=2>#include</FONT><FONT color=#000000 size=2> </FONT><FONT
color=#a31515 size=2><pcap.h><BR></FONT><FONT color=#0000ff
size=2>#pragma</FONT><FONT color=#000000 size=2> </FONT><FONT color=#0000ff
size=2>comment</FONT><FONT color=#000000 size=2>(</FONT><FONT color=#0000ff
size=2>lib</FONT><FONT color=#000000 size=2>, </FONT><FONT color=#a31515
size=2>"Wpcap.lib"</FONT><FONT size=2><FONT
color=#000000>)</FONT></FONT><BR><FONT size=2><FONT
color=#000000></FONT> <BR></FONT><FONT color=#0000ff
size=2>void</FONT><FONT color=#000000 size=2> </FONT><FONT
size=2>GetINetDevice</FONT><FONT size=2>()<BR>{<BR></FONT><FONT
size=2> pcap_if_t</FONT><FONT size=2>* </FONT><FONT
size=2>alldevs</FONT><FONT size=2>;<BR></FONT><FONT color=#0000ff size=2><FONT
color=#010001> </FONT>char</FONT><FONT size=2>
</FONT><FONT size=2>errbuf</FONT><FONT size=2>[</FONT><FONT
size=2>PCAP_ERRBUF_SIZE</FONT><FONT size=2>+1];<BR> <BR></FONT><FONT
color=#008000 size=2><FONT color=#010001> </FONT>/*
Retrieve the device list */<BR></FONT><FONT size=2></FONT><FONT color=#0000ff
size=2><FONT color=#010001> </FONT>if</FONT><FONT
size=2>(</FONT><FONT color=#010001 size=2>pcap_findalldevs</FONT><FONT
size=2>(&</FONT><FONT color=#010001 size=2>alldevs</FONT><FONT size=2>,
</FONT><FONT color=#010001 size=2>errbuf</FONT><FONT size=2>) ==
-1)<BR> {<BR></FONT><FONT color=#010001
size=2>
printf</FONT><FONT size=2>(</FONT><FONT color=#a31515 size=2>"Error in
pcap_findalldevs: %s\n"</FONT><FONT size=2>, </FONT><FONT
size=2>errbuf</FONT><FONT size=2>);<BR></FONT><FONT
size=2> exit</FONT><FONT
size=2>(1);<BR> }<BR></FONT><FONT color=#008000
size=2><FONT color=#010001> </FONT>// Could not create
thread<BR></FONT><FONT size=2></FONT><FONT color=#010001
size=2> MessageBox</FONT><FONT size=2>(</FONT><FONT
color=#010001 size=2>NULL</FONT><FONT size=2>, </FONT><FONT color=#a31515
size=2>"Sucess"</FONT><FONT size=2>,</FONT><FONT color=#a31515
size=2>""</FONT><FONT size=2>,</FONT><FONT size=2>MB_OK</FONT><FONT
size=2>);<BR> <BR></FONT><FONT color=#008000 size=2><FONT
color=#010001> </FONT>// Free the device list
<BR></FONT><FONT size=2></FONT><FONT color=#010001
size=2> pcap_freealldevs</FONT><FONT
size=2>(</FONT><FONT color=#010001 size=2>alldevs</FONT><FONT
size=2>);<BR>}<BR> <BR> <BR></FONT><FONT color=#0000ff
size=2>int</FONT><FONT color=#000000 size=2> </FONT><FONT
size=2>main</FONT><FONT size=2>()<BR>{ <BR></FONT><FONT
size=2> DWORD</FONT><FONT size=2> </FONT><FONT
size=2>m_dwThreadID</FONT><FONT size=2>;<BR></FONT><FONT
size=2> HANDLE</FONT><FONT size=2> </FONT><FONT
size=2>m_hThread</FONT><FONT size=2>;<BR></FONT><FONT
size=2> m_hThread</FONT><FONT size=2> = </FONT><FONT
size=2>CreateThread</FONT><FONT
size=2>(0,<BR>
0,<BR>
(</FONT><FONT size=2>LPTHREAD_START_ROUTINE</FONT><FONT size=2>)</FONT><FONT
size=2>GetINetDevice</FONT><FONT size=2>,<BR></FONT><FONT
size=2>
NULL</FONT><FONT
size=2>,<BR>
0,<BR>
&</FONT><FONT size=2>m_dwThreadID</FONT><FONT size=2>);<BR></FONT><FONT
color=#0000ff size=2><FONT color=#010001>
</FONT>if</FONT><FONT size=2>(!</FONT><FONT size=2>m_hThread</FONT><FONT
size=2>)<BR> {<BR></FONT><FONT color=#008000
size=2><FONT
color=#010001> </FONT>//
Could not create thread<BR></FONT><FONT size=2></FONT><FONT color=#010001
size=2>
MessageBox</FONT><FONT size=2>(</FONT><FONT color=#010001
size=2>NULL</FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2>"Thread
error"</FONT><FONT size=2>,</FONT><FONT color=#a31515 size=2>""</FONT><FONT
size=2>,</FONT><FONT size=2>MB_OK</FONT><FONT
size=2>);<BR> }<BR></FONT><FONT color=#0000ff
size=2><FONT color=#010001> </FONT>return</FONT><FONT
size=2> 0;<BR>}<BR> <BR>Is anyone able to tell me if the fact of the app
hangs/exits on pcap_findalldevs(), is a known issue at winpcap, and if there
is any workaround?<BR> <BR>Best Regards<BR></FONT></FONT></FONT><BR>
<HR>
Uma nova forma de utilizar mensagens: <A
href="http://ideas.live.com/programpage.aspx?versionId=0eccd94b-eb48-497c-8e60-c6313f7ebb73"
target=_new>Windows Live Messenger beta</A>
<P>
<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>