From 288e436728d4c70a01b411b8a0e3a1fd6f92d8af Mon Sep 17 00:00:00 2001 From: djfiander Date: Sat, 26 Aug 2006 18:50:42 +0000 Subject: [PATCH] Go back to using unpack to generate the checksums, except that I'm using the 'U'TF encoding instead of the 'C'har encoding. This seems to work, at least in my test environment. --- Sip/Checksum.pm | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Sip/Checksum.pm b/Sip/Checksum.pm index 07bcd9f..093dfb4 100644 --- a/Sip/Checksum.pm +++ b/Sip/Checksum.pm @@ -9,15 +9,8 @@ our @EXPORT_OK = qw(checksum verify_cksum); sub checksum { my $pkt = shift; - my $cksum; - - $cksum = 0; - foreach my $chr (map(ord, split(//, $pkt))) { - $cksum += $chr; - } - $cksum = (-$cksum) & 0xFFFF; - return $cksum; + return (-unpack('%16U*', $pkt) & 0xFFFF); } sub verify_cksum { @@ -30,7 +23,7 @@ sub verify_cksum { # Convert the checksum back to hex and calculate the sum of the # pack without the checksum. $cksum = hex(substr($pkt, -4)); - $shortsum = unpack("%16C*", substr($pkt, 0, -4)); + $shortsum = unpack("%16U*", substr($pkt, 0, -4)); # The checksum is valid if the hex sum, plus the checksum of the # base packet short when truncated to 16 bits. -- 2.11.0