From cdfa01e2aad4224c7849dc39c01296a3102a8426 Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Mon, 29 Jul 2019 18:54:37 -0700 Subject: [PATCH] Add checksum verification methods --- tb/ip_ep.py | 3 +++ tb/udp_ep.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/tb/ip_ep.py b/tb/ip_ep.py index 252f4aa3f..f1991d010 100644 --- a/tb/ip_ep.py +++ b/tb/ip_ep.py @@ -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() diff --git a/tb/udp_ep.py b/tb/udp_ep.py index afd0c3dae..e9ac019db 100644 --- a/tb/udp_ep.py +++ b/tb/udp_ep.py @@ -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()