I packed a struct using this line
# type(8) code(8) checksum(16) process id(16) sequence(16)
packet = struct.pack("bbHHh", ICMP_ECHO_REQUEST, 0, packet_checksum, pid, sequence)
And now im using a checksum calculation function which unpacks the packet in a way that the 16 bits of where the checksum should be (packet_checksum) is removed. But i don't know how it does that, and what does the sum function actually do? add up the different elements?:
n = len(pkt)
two_bytes = struct.unpack("%sH" % (n/2), pkt)
chksum = sum(two_bytes)
the code works well i'm just wondering how it works.