title: Altering packets using Scapy - automatically update properties (length, checksum etc.) after editing packet's payload
body: <p>I am currently modifying a <code>pcap</code> file (on a Linux system) using <code>scapy</code> in Python. I do this for two reasons:</p>
  
  <ul>
  <li>I need to alter specific parts of the load of some of the packets and then replay those so that a software I'm testing receives the changed data allowing me to observe its behaviour</li>
  <li>With some packets (with the original load) I'm getting the "message too long" when I try to use <code>tcpreplay</code> or <code>scapy</code>'s own <code>sendp(...)</code>. Trimming down the load should (if I'm not mistaken) allow me to go around this problem.</li>
  </ul>
  
  <p>Here is a small example of what I do (I use <code>ipython</code>):</p>
  
  <pre><code>from scapy.all import rdpcap, wrpcap
  from scapy.utils import sendp
  import re
  
  # Load PCAP file. In my case I have 24 packets
  pkts = rdpcap('dump.pcap')
  
  # Change the load of packet 16 by removing some of the data inside
  pkts[16].load = re.sub(r'&lt;Stop[0-9]+&gt;[0-9]+&lt;/Stop[0-9]+&gt;', '', pkts[16].load)
  
  # Write the changes to a new file
  wrpcap('dump_edited.pcap', pkts)
  
  # and send those (the operation requires admin privileges!)
  sendp(pkts) # or use tcpreplay in the terminal
  </code></pre>
  
  <p>Now the problem is that editing the load in this way means that other properties related to it will not get updated. For example if the length was previously <strong>2982</strong> (using <code>pkts[16].show()</code> you can get a detailed overview of the packet's properties) after editing its load the length is still the same. Checksum doesn't change also. This is of course expected since all I'm doing is directly edit the string, which clearly doesn't trigger any updates of the packets properties.</p>
  
  <p>I've just discovered <code>scapy</code> so the question is probably too obvious but is there a way to alter the load in such a way that its properties also get updated automatically?</p>