Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_in_checksum(self):
print_header("Internet checksum")
# see packets_dns.py, packet 2
udp = b"\x00\x35\xa5\xc0\x00\x62\x00\x00\x48\x5b\x81\x80\x00\x01\x00\x03\x00\x00\x00\x01" +\
b"\x03\x77\x77\x77\x06\x67\x6f\x6f\x67\x6c\x65\x02\x64\x65\x00\x00\x01\x00\x01\xc0" +\
b"\x0c\x00\x01\x00\x01\x00\x00\x00\x55\x00\x04\xad\xc2\x23\x97\xc0\x0c\x00\x01\x00" +\
b"\x01\x00\x00\x00\x55\x00\x04\xad\xc2\x23\x98\xc0\x0c\x00\x01\x00\x01\x00\x00\x00" +\
b"\x55\x00\x04\xad\xc2\x23\x9f\x00\x00\x29\x05\xb4\x00\x00\x00\x00\x00\x00"
pseudoheader = b"\xc0\xa8\xb2\x01\xc0\xa8\xb2\x16\x00\x11" + struct.pack(">H", len(udp))
print(len(udp))
csum = checksum.in_cksum(pseudoheader + udp)
self.assertEqual(csum, 0x32bf)
def _update_fields(self):
if self.sum_au_active and self._changed():
self.sum = 0
self.sum = checksum.in_cksum(pypacker.Packet.bin(self))
def _update_fields(self):
# logger.debug("sum is: %d" % self.sum)
if self.sum_au_active and self._changed():
# logger.debug("sum is: %d" % self.sum)
# logger.debug("header: %r", self.header_bytes)
# logger.debug("body: %r", self.body_bytes)
self.sum = 0
self.sum = checksum.in_cksum(self.header_bytes + self.body_bytes)
# logger.debug("sum is: %d" % self.sum)
def _update_fields(self):
if self.sum_au_active and self._changed():
self.sum = 0
self.sum = checksum.in_cksum(pypacker.Packet.bin(self))
def __str__(self):
data = "".join(map(str, self.data))
if not self.sum:
self.sum = checksum.in_cksum(self.pack_hdr() + data)
return self.pack_hdr() + data
# we need src/dst for checksum-calculation
src, dst = self._lower_layer.src, self._lower_layer.dst
except Exception:
# not an IP packet as lower layer (src, dst not present) or invalid src/dst
# logger.debug("could not calculate checksum: %r" % e)
return
# pseudoheader
# packet length = length of upper layers
self.sum = 0
# logger.debug("TCP sum recalc: IP6= len(src)=%d\n%s\n%s\nhdr=%s\nbody=%s" %
# (len(src), src, dst, self.header_bytes, self.body_bytes))
pkt = self.header_bytes + self.body_bytes
hdr = pack_ipv6_icmp6(src, dst, len(pkt), 58)
# this will set the header status to changes, should be reset by calling bin()
self.sum = checksum.in_cksum(hdr + pkt)
#logger.debug(">>> new checksum: %0X" % self.sum)
def _update_fields(self):
if self.sum_au_active and self._changed():
self.sum = 0
self.sum = checksum.in_cksum(pypacker.Packet.bin(self))