<html>
<head>
<style>
P
{
margin:0px;
padding:0px
}
body
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body>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></body>
</html>