<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)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-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;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
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 bgcolor=white lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><span style='color:#1F497D'>Hi,<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>Yeah. I understand that. But I
doubt if that effects the speed much.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>I am doing some processing on
the array later. But the processing is not the bottleneck. It is the packet
capture (packet_handler) that is the bottleneck. Even if I remove<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>All the code inside the
packet_handler the packet capture still does not meet expectations. We have
nearly 20,000 packets. And as I mentioned before we are looking to achieve a
frame rate<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>Of 30-60 Mbytes/s.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>Any ideas ?<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>Thanks<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>Charu<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<div>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
winpcap-users-bounces@winpcap.org [mailto:winpcap-users-bounces@winpcap.org] <b>On
Behalf Of </b>Gianluca Varenni<br>
<b>Sent:</b> Tuesday, April 21, 2009 3:33 PM<br>
<b>To:</b> winpcap-users@winpcap.org<br>
<b>Subject:</b> Re: [Winpcap-users] Better Performance<o:p></o:p></span></p>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<div>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Times New Roman","serif"'>First
of all, allocating some memory at every received packet is a bad idea. You
should preallocate memory at the very beginning. </span><span style='font-size:
12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Times New Roman","serif"'>Then,
how many packets do you want to capture? What are you doing with all those
packets in these arrays? </span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'> <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Times New Roman","serif"'>Have
a nice day</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Times New Roman","serif"'>GV</span><span
style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'> <o:p></o:p></span></p>
</div>
<blockquote style='border:none;border-left:solid black 1.5pt;padding:0in 0in 0in 4.0pt;
margin-left:3.75pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt'>
<div>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>-----
Original Message ----- <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal style='background:#E4E4E4'><b><span style='font-size:10.0pt;
font-family:"Arial","sans-serif"'>From:</span></b><span style='font-size:10.0pt;
font-family:"Arial","sans-serif"'> <a href="mailto:cagrawal@altasens.com"
title="cagrawal@altasens.com">Charu Agrawal</a> <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>To:</span></b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'> <a
href="mailto:winpcap-users@winpcap.org" title="winpcap-users@winpcap.org">winpcap-users@winpcap.org</a>
<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Sent:</span></b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'> Tuesday, April 21,
2009 2:20 PM<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Subject:</span></b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'> Re: [Winpcap-users]
Better Performance<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p> </o:p></span></p>
</div>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>Hi,<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>This is what the code looks like
– <o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>This is all initialization code
– <o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
if ((adhandle=
pcap_open_live(d->name,
// name of the device<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
65536,
// portion of the packet to capture. <o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
// 65536 grants that the whole packet will be captured on all the MACs.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
1,
// promiscuous mode (nonzero means promiscuous)<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
1,
// read timeout<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
errbuf
// error buffer<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
)) == NULL)<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
{<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
printf("\nUnable to open the adapter. %s is not supported by WinPcap\n",
d->name);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
return RETCODE_ERR;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
}<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
//Set the filter string to the source ip address<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
//Only packets from this source address will be captured.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
//This does slow down the capture a bit.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> NetMask=0xffffff;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> filter = "src
192.168.1.10";<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
if(pcap_compile(adhandle, &fcode, filter, 1, NetMask) < 0)<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
{<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
printf("\nError compiling filter: wrong syntax.\n");<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
pcap_close(adhandle);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
return RETCODE_ERR;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
}<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
if(pcap_setfilter(adhandle, &fcode)<0)<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
{<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
printf("\nError setting the filter\n");<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
pcap_close(adhandle);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
return RETCODE_ERR;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
}
<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
//Set the kernel buffer<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
if (pcap_setbuff(adhandle,41943040) < 0)<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
{<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
printf("\n unable to set buffer");<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
return RETCODE_ERR;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
}<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>Then I start the pcap_loop on a
separate thread – This function is called for each packet capture.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>I copy the data for all packets in
a global array – image_buf <o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>void packet_handler(u_char
*dumpfileHandler, const struct pcap_pkthdr *header, const u_char *pkt_data)<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>{<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> //copy the packet data to
image_buf and also store the packet length<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> image_buf[packetCounter] =
(unsigned char*)(malloc(header->caplen*sizeof(unsigned char)));<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> if(image_buf[packetCounter]
== NULL)<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> {
<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
printf("\n unable to allocate buffer");<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>
return;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> }<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> memcpy(image_buf[packetCounter],pkt_data,header->caplen);<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> pkt_length[packetCounter]=header->caplen;<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> <o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'> packetCounter += 1; <o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>}<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>Please let me know if you need
more details. I can zip and send the code file if needed.<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>Thanks<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'>Charu<o:p></o:p></span></p>
<p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p>
<div>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> winpcap-users-bounces@winpcap.org
[mailto:winpcap-users-bounces@winpcap.org] <b>On Behalf Of </b>Gianluca Varenni<br>
<b>Sent:</b> Tuesday, April 21, 2009 1:51 PM<br>
<b>To:</b> winpcap-users@winpcap.org<br>
<b>Subject:</b> Re: [Winpcap-users] Better Performance<o:p></o:p></span></p>
</div>
</div>
<p class=MsoNormal><o:p> </o:p></p>
<div>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Times New Roman","serif"'>Before
trying to modify the WinPcap source code, I would try to understand what the
bottlenecks are. What are you doing with the received packets?</span><span
style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'> <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Times New Roman","serif"'>Can
you show us the packet processing loop that you have in your code (even in form
of pseudocode)?</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'> <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Times New Roman","serif"'>Have
a nice day</span><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Times New Roman","serif"'>GV</span><span
style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p></o:p></span></p>
</div>
<blockquote style='border:none;border-left:solid black 1.5pt;padding:0in 0in 0in 4.0pt;
margin-left:3.75pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt'>
<div>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>-----
Original Message ----- <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal style='background:#E4E4E4'><b><span style='font-size:10.0pt;
font-family:"Arial","sans-serif"'>From:</span></b><span style='font-size:10.0pt;
font-family:"Arial","sans-serif"'> <a href="mailto:cagrawal@altasens.com"
title="cagrawal@altasens.com">Charu Agrawal</a> <o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>To:</span></b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'> <a
href="mailto:winpcap-users@winpcap.org" title="winpcap-users@winpcap.org">winpcap-users@winpcap.org</a>
<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Sent:</span></b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'> Monday, April 20,
2009 10:58 AM<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>Subject:</span></b><span
style='font-size:10.0pt;font-family:"Arial","sans-serif"'> [Winpcap-users]
Better Performance<o:p></o:p></span></p>
</div>
<div>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p> </o:p></span></p>
</div>
<p class=MsoNormal>Hi,<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>I am trying to figure out how to capture image frames most
efficiently. Each frame is approximately 20Mbytes.<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>I am trying to achieve frame rate of 1-2 frames per second.
The packets are being received over a Gig eth dedicated link. ( Packets
are sent over that link using only one source).<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>I am unable to achieve this frame rate using winpcap. Would
it be helpful to modify the Winpcap source code for better performance ? Has
anyone here have any experience in modifying the winpcap source to achieve
higher frame rate capture ?<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
<p class=MsoNormal>Thanks for your help in advance<o:p></o:p></p>
<p class=MsoNormal>Regards<o:p></o:p></p>
<p class=MsoNormal>Charu Agrawal<o:p></o:p></p>
<div class=MsoNormal align=center style='text-align:center'><span
style='font-size:12.0pt;font-family:"Times New Roman","serif"'>
<hr size=2 width="100%" align=center>
</span></div>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'>_______________________________________________<br>
Winpcap-users mailing list<br>
Winpcap-users@winpcap.org<br>
https://www.winpcap.org/mailman/listinfo/winpcap-users<o:p></o:p></span></p>
</blockquote>
<div class=MsoNormal align=center style='text-align:center'><span
style='font-size:12.0pt;font-family:"Times New Roman","serif"'>
<hr size=2 width="100%" align=center>
</span></div>
<p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'>_______________________________________________<br>
Winpcap-users mailing list<br>
Winpcap-users@winpcap.org<br>
https://www.winpcap.org/mailman/listinfo/winpcap-users<o:p></o:p></span></p>
</blockquote>
</div>
</body>
</html>