title: checksum icmp python with wireshark
body: <p>Over the last few days, I am passionate about the ICMP protocol and I found a python function that calculates its checksum:</p>
  
  <pre><code>def carry_around_add(a, b):
      c = a + b
      return (c &amp; 0xffff) + (c &gt;&gt; 16)
  
  def checksum(msg):
     s = 0
     for i in range(0, len(msg), 2):
         w = ord(msg[i]) + (ord(msg[i+1]) &lt;&lt; 8)
         s = carry_around_add(s, w)
     return ~s &amp; 0xffff
  
  print checksum("abcdefghijklmnopqrst")
  </code></pre>
  
  <p>In this picture of a wireshark capture: <img src="https://i.stack.imgur.com/OPEIL.png" alt="http://memory00stack.files.wordpress.com/2013/12/resultat.png"></p>
  
  <p>The checksum is "<code>0xcfcb</code>" but the function in my test returns "<code>55 245</code> -> <code>0xd7cd</code>". Why ? </p>
  
  <p>Thanks so much =)</p>