<div class="gmail_quote">2011/9/7 Greg Bowyer <span dir="ltr">&lt;<a href="mailto:gbowyer@fastmail.co.uk">gbowyer@fastmail.co.uk</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi all, I have a rather interesting in house networking tool that uses pcap to sniff packets, take them into twisted and replay them against a target.<br>
<br>
Internally the tight loop for packet reassembly is currently run via twisted and some custom parsing and packet reconstruction code, I have been investigating if I can make this code faster _without_ reimplementing the capture part in C, as such I think I have two options:<br>

<br>
* Pypy (which I would prefer as it means that I hopefully will gain performance improvements over time, as well as JIT acceleration throughout the code)<br>
* Cython (which will let me change the main loop to be mostly C without having to write a lot of C)<br>
<br>
The tool currently uses an old style cPython c extension to bind python to pcap, since this will be slow in pypy I found the first semi implemented ctype pcap binding from google code here (<a href="http://code.google.com/p/pcap/" target="_blank">http://code.google.com/p/<u></u>pcap/</a>) (I didnt write it so it may be broken)<br>

<br>
The following test code works fine on cPython2.7<br>
</blockquote><div><br></div><div>The pcap module has an important issue; pcap_open_live() contains this code:</div><div>    error=c_char_p()</div><div><div>    handle=pcap_c_funcs.pcap_open_live(source,snaplen,promisc,to_ms,error)</div>
</div><div>Which is wrong: according to the man page, the &quot;error&quot; parameter</div><div>&quot;is assumed to be able to hold at least PCAP_ERRBUF_SIZE chars&quot;</div><div>which is not the case here, NULL is passed instead and bad things will happen at runtime.</div>
<div><br></div><div><span class="Apple-style-span">pcap should be modified, probably with something like &quot;error = create_string_buffer(</span><span class="Apple-style-span" style="font-family: Monaco, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Lucida Console&#39;, monospace; font-size: 12px; white-space: pre-wrap; background-color: rgb(255, 255, 255); ">256</span><span class="Apple-style-span">)&quot;</span></div>
<div><br></div></div>-- <br>Amaury Forgeot d&#39;Arc<br>