1
0
mirror of https://github.com/corundum/corundum.git synced 2025-01-16 08:12:53 +08:00

Add checksum verification methods

This commit is contained in:
Alex Forencich 2019-07-29 18:54:37 -07:00
parent bfef06ca0e
commit cdfa01e2aa
2 changed files with 12 additions and 0 deletions

View File

@ -135,6 +135,9 @@ class IPFrame(object):
def update_checksum(self):
self.ip_header_checksum = self.calc_checksum()
def verify_checksum(self):
return self.ip_header_checksum == self.calc_checksum()
def build(self):
if self.ip_length is None:
self.update_length()

View File

@ -159,6 +159,9 @@ class UDPFrame(object):
def update_ip_checksum(self):
self.ip_header_checksum = self.calc_ip_checksum()
def verify_ip_checksum(self):
return self.ip_header_checksum == self.calc_ip_checksum()
def calc_udp_pseudo_header_checksum(self):
cksum = self.ip_source_ip & 0xffff
cksum += (self.ip_source_ip >> 16) & 0xffff
@ -196,10 +199,16 @@ class UDPFrame(object):
self.update_udp_length()
self.udp_checksum = self.calc_udp_checksum()
def verify_udp_checksum(self):
return self.udp_checksum == self.calc_udp_checksum()
def update_checksum(self):
self.update_udp_checksum()
self.update_ip_checksum()
def verify_checksums(self):
return self.verify_ip_checksum() and self.verify_udp_checksum()
def build(self):
if self.udp_length is None:
self.update_udp_length()