<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    Humm interesting, I wonder why it works in Cpython, when I get the
    chance I will try making those changes and see if pypy works.<br>
    On 06/09/11 23:57, Amaury Forgeot d'Arc wrote:
    <blockquote
cite="mid:CAGmFidbdzUO5ETm0ihU6n3g=w7wtpvft4yNEHptrSAKuWaHp3g@mail.gmail.com"
      type="cite">
      <div class="gmail_quote">2011/9/7 Greg Bowyer <span dir="ltr">&lt;<a
            moz-do-not-send="true" href="mailto:gbowyer@fastmail.co.uk">gbowyer@fastmail.co.uk</a>&gt;</span><br>
        <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
          0.8ex; border-left: 1px solid rgb(204, 204, 204);
          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 moz-do-not-send="true"
            href="http://code.google.com/p/pcap/" target="_blank">http://code.google.com/p/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;&nbsp;pcap_open_live()
          contains this code:</div>
        <div>&nbsp; &nbsp; error=c_char_p()</div>
        <div>
          <div>&nbsp; &nbsp;
            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 "error"
          parameter</div>
        <div>"is&nbsp;assumed to be able to hold at least PCAP_ERRBUF_SIZE
          chars"</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 "error = create_string_buffer(</span><span
            class="Apple-style-span" style="font-family: Monaco,'DejaVu
            Sans Mono','Bitstream Vera Sans Mono','Lucida
            Console',monospace; font-size: 12px; white-space: pre-wrap;
            background-color: rgb(255, 255, 255);">256</span><span
            class="Apple-style-span">)"</span></div>
        <div><br>
        </div>
      </div>
      -- <br>
      Amaury Forgeot d'Arc<br>
    </blockquote>
    <br>
  </body>
</html>