How is an ICMP packet constructed in python
<p>For the sake of learning I am currently trying to create a simple python porgram to send a ICMP ping packet to some device. To get started I looked through the source code of the python module Pyping: <a href="https://github.com/Akhavi/pyping/blob/master/pyping/core.py" rel="noreferrer">https://github.com/Akhavi/pyping/blob/master/pyping/core.py</a></p>

<p>I am trying to understand all that is going on when sending and constructing the packet however i have managed to get stuck on one part of the code and can't seem to figure out exactly what its fucntion and use is. I have been looking into ICMP packets and i understand that they contain <strong>Type code checksum and data</strong>  now the piece of code that puzzles me is:</p>

<pre><code>    self.own_id = os.getpid() &amp; 0xFFFF

    header = struct.pack(
        "!BBHHH", ICMP_ECHO, 0, checksum, self.own_id, self.seq_number
    )

    padBytes = []
    startVal = 0x42
    for i in range(startVal, startVal + (self.packet_size)):
        padBytes += [(i &amp; 0xff)]  # Keep chars in the 0-255 range
    data = bytes(padBytes)
</code></pre>

<p>My questions would be:</p>

<ol>
<li>What is the use of adding the self.own_id and self.seq_number to the header?</li>
<li>What is being calculated in the for-loop, and why does it have a specific start value of 0x42?</li>
</ol>

<p>I am new to networking and any help would be really appreciated.</p>