<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri","sans-serif";}
h1
        {mso-style-priority:9;
        mso-style-link:"Heading 1 Char";
        margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:0cm;
        page-break-after:avoid;
        font-size:16.0pt;
        font-family:"Cambria","serif";}
h2
        {mso-style-priority:9;
        mso-style-link:"Heading 2 Char";
        margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:0cm;
        page-break-after:avoid;
        font-size:14.0pt;
        font-family:"Cambria","serif";
        font-style:italic;}
h3
        {mso-style-priority:9;
        mso-style-link:"Heading 3 Char";
        margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:0cm;
        page-break-after:avoid;
        font-size:13.0pt;
        font-family:"Cambria","serif";}
h4
        {mso-style-priority:9;
        mso-style-link:"Heading 4 Char";
        margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:0cm;
        page-break-after:avoid;
        font-size:14.0pt;
        font-family:"Calibri","sans-serif";}
h5
        {mso-style-priority:9;
        mso-style-link:"Heading 5 Char";
        margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:0cm;
        font-size:13.0pt;
        font-family:"Calibri","sans-serif";
        font-style:italic;}
h6
        {mso-style-priority:9;
        mso-style-link:"Heading 6 Char";
        margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:0cm;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
p.MsoHeading7, li.MsoHeading7, div.MsoHeading7
        {mso-style-priority:9;
        mso-style-link:"Heading 7 Char";
        margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Calibri","sans-serif";}
p.MsoHeading8, li.MsoHeading8, div.MsoHeading8
        {mso-style-priority:9;
        mso-style-link:"Heading 8 Char";
        margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Calibri","sans-serif";
        font-style:italic;}
p.MsoHeading9, li.MsoHeading9, div.MsoHeading9
        {mso-style-priority:9;
        mso-style-link:"Heading 9 Char";
        margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:0cm;
        font-size:11.0pt;
        font-family:"Cambria","serif";}
p.MsoCaption, li.MsoCaption, div.MsoCaption
        {mso-style-priority:35;
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:9.0pt;
        font-family:"Calibri","sans-serif";
        color:#4F81BD;
        font-weight:bold;}
p.MsoTitle, li.MsoTitle, div.MsoTitle
        {mso-style-priority:10;
        mso-style-link:"Title Char";
        margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:0cm;
        text-align:center;
        font-size:16.0pt;
        font-family:"Cambria","serif";
        font-weight:bold;}
p.MsoSubtitle, li.MsoSubtitle, div.MsoSubtitle
        {mso-style-priority:11;
        mso-style-link:"Subtitle Char";
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:0cm;
        text-align:center;
        font-size:12.0pt;
        font-family:"Cambria","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
em
        {mso-style-priority:20;
        font-family:"Calibri","sans-serif";
        font-weight:bold;}
p.MsoNoSpacing, li.MsoNoSpacing, div.MsoNoSpacing
        {mso-style-priority:1;
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri","sans-serif";}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst
        {mso-style-priority:34;
        mso-style-type:export-only;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle
        {mso-style-priority:34;
        mso-style-type:export-only;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri","sans-serif";}
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast
        {mso-style-priority:34;
        mso-style-type:export-only;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri","sans-serif";}
p.MsoQuote, li.MsoQuote, div.MsoQuote
        {mso-style-priority:29;
        mso-style-link:"Quote Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri","sans-serif";
        font-style:italic;}
p.MsoIntenseQuote, li.MsoIntenseQuote, div.MsoIntenseQuote
        {mso-style-priority:30;
        mso-style-link:"Intense Quote Char";
        margin-top:0cm;
        margin-right:36.0pt;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri","sans-serif";
        font-weight:bold;
        font-style:italic;}
span.MsoSubtleEmphasis
        {mso-style-priority:19;
        color:#5A5A5A;
        font-style:italic;}
span.MsoIntenseEmphasis
        {mso-style-priority:21;
        font-weight:bold;
        font-style:italic;
        text-decoration:underline;}
span.MsoSubtleReference
        {mso-style-priority:31;
        text-decoration:underline;}
span.MsoIntenseReference
        {mso-style-priority:32;
        font-weight:bold;
        text-decoration:underline;}
span.MsoBookTitle
        {mso-style-priority:33;
        font-family:"Cambria","serif";
        font-weight:bold;
        font-style:italic;}
p.MsoTocHeading, li.MsoTocHeading, div.MsoTocHeading
        {mso-style-priority:39;
        margin-top:12.0pt;
        margin-right:0cm;
        margin-bottom:3.0pt;
        margin-left:0cm;
        page-break-after:avoid;
        font-size:16.0pt;
        font-family:"Cambria","serif";
        font-weight:bold;}
span.Heading1Char
        {mso-style-name:"Heading 1 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 1";
        font-family:"Cambria","serif";
        font-weight:bold;}
span.Heading2Char
        {mso-style-name:"Heading 2 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 2";
        font-family:"Cambria","serif";
        font-weight:bold;
        font-style:italic;}
span.Heading3Char
        {mso-style-name:"Heading 3 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 3";
        font-family:"Cambria","serif";
        font-weight:bold;}
span.Heading4Char
        {mso-style-name:"Heading 4 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 4";
        font-family:"Times New Roman","serif";
        font-weight:bold;}
span.Heading5Char
        {mso-style-name:"Heading 5 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 5";
        font-family:"Times New Roman","serif";
        font-weight:bold;
        font-style:italic;}
span.Heading6Char
        {mso-style-name:"Heading 6 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 6";
        font-family:"Times New Roman","serif";
        font-weight:bold;}
span.Heading7Char
        {mso-style-name:"Heading 7 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 7";
        font-family:"Times New Roman","serif";}
span.Heading8Char
        {mso-style-name:"Heading 8 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 8";
        font-family:"Times New Roman","serif";
        font-style:italic;}
span.Heading9Char
        {mso-style-name:"Heading 9 Char";
        mso-style-priority:9;
        mso-style-link:"Heading 9";
        font-family:"Cambria","serif";}
span.TitleChar
        {mso-style-name:"Title Char";
        mso-style-priority:10;
        mso-style-link:Title;
        font-family:"Cambria","serif";
        font-weight:bold;}
span.SubtitleChar
        {mso-style-name:"Subtitle Char";
        mso-style-priority:11;
        mso-style-link:Subtitle;
        font-family:"Cambria","serif";}
span.QuoteChar
        {mso-style-name:"Quote Char";
        mso-style-priority:29;
        mso-style-link:Quote;
        font-style:italic;}
span.IntenseQuoteChar
        {mso-style-name:"Intense Quote Char";
        mso-style-priority:30;
        mso-style-link:"Intense Quote";
        font-weight:bold;
        font-style:italic;}
span.EmailStyle45
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-GB link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'>Hi,<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'>I am trying to
receive packets using pcap_next_ex(), but for some reason I keep getting a
timeout. I know that packets are coming into the machine because I can
see them via WinDump. The odd part is that when I run WinDump
concurrently with my test application, I start to see packets in the test app
(as well as in WinDump). But without WinDump, I get no packets on the
test app at all.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'>I am guessing that
there is something I need to do to “start” the packet driver
capturing, although I thought that’s what pcap_open_live does, so I’m
not quite sure on that.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'>My code so far is
a fairly liberal sampling of the pktdump_ex example:<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:green'>/* Open the adapter */<o:p></o:p></span></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:blue'>if</span> ((m_pSessionHandle =
pcap_open_live(m_pReceiveDevice->name, <span
style='color:green'>// name of the device<o:p></o:p></span></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> 65536, <span
style='color:green'>// 65536 means the whole packet will be captured.<o:p></o:p></span></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> 0, <span
style='color:green'>// non promiscuous mode (nonzero means promiscuous)<o:p></o:p></span></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> 1000, <span
style='color:green'>// read timeout<o:p></o:p></span></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> errbuf <span
style='color:green'>// error buffer</span>)) == NULL)<span style='color:green'><o:p></o:p></span></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> {<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> //
Error code<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> }<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> std::cout << <span
style='color:#A31515'>"Filter: "</span> << m_strFilter <<
std::endl;<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:blue'>if</span> ( !m_strFilter.empty() )<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> {<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> bpf_u_int32
NetMask = 0;<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:blue'>struct</span> bpf_program fcode;<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:green'>//compile the filter<o:p></o:p></span></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:blue'>if</span>(pcap_compile(m_pSessionHandle, &fcode, <span
style='color:blue'>const_cast</span><<span style='color:blue'>char</span>*>(m_strFilter.c_str()),
1, NetMask) < 0)<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> {<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> //
Error code<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> }<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:green'>//set the filter<o:p></o:p></span></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:blue'>if</span>(pcap_setfilter(m_pSessionHandle, &fcode)<0)<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> {<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> //
Error code<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> }<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> }<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:green'>/* At this point, we don't need the device list any more.
Free it */<o:p></o:p></span></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> pcap_freealldevs(alldevs);<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'>And later on:<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'><o:p> </o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:blue'>while</span>((res = pcap_next_ex( m_pSessionHandle,
&header, &pkt_data)) >= 0)<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> {<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:blue'>if</span>(res == 0)<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> {<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:green'>/* Timeout elapsed */<o:p></o:p></span></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> OutputDebugString(L<span
style='color:#A31515'>"No packets!\n"</span>);<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> <span
style='color:blue'>continue</span>;<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> }<o:p></o:p></span></p>
<p class=MsoNormal style='margin-left:36.0pt;text-indent:36.0pt;text-autospace:
none'><span style='font-size:10.0pt;font-family:"Courier New"'>//…<o:p></o:p></span></p>
<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'> }<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:11.0pt'><o:p> </o:p></span></p>
<div>
<div style='border:none;border-top:dotted silver 1.0pt;padding:4.0pt 0cm 0cm 0cm'>
<p class=MsoNormal><b><span style='font-size:9.0pt;font-family:"Arial","sans-serif";
color:#666666'>Ryan Fowler</span></b><span style='font-size:10.0pt;font-family:
"Arial","sans-serif";color:#666666'><br>
</span><span style='font-size:9.0pt;font-family:"Arial","sans-serif";
color:#666666'>Software Engineer</span><span style='font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:9.0pt;margin-right:0cm;margin-bottom:
9.0pt;margin-left:0cm'><b><span style='font-size:9.0pt;font-family:"Arial","sans-serif";
color:#F57F20'>Thomson Reuters</span></b><span style='font-family:"Times New Roman","serif"'>
<o:p></o:p></span></p>
</div>
</div>
</div>
</body>
</html>