From: djfiander Date: Fri, 25 Aug 2006 01:21:37 +0000 (+0000) Subject: Replace idiomatic perl checksum code, which seems to fail on X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=80e317cf98d424f3b517da58ca5e619ec7b41238;p=working%2FSIPServer.git Replace idiomatic perl checksum code, which seems to fail on strings with diacriticals in them, with an explicit sum of the ordinal values of the characters in the string, which seems to cope. --- diff --git a/Sip/Checksum.pm b/Sip/Checksum.pm index dd5776b..07bcd9f 100644 --- a/Sip/Checksum.pm +++ b/Sip/Checksum.pm @@ -1,4 +1,3 @@ - package Sip::Checksum; use Exporter; @@ -10,8 +9,15 @@ our @EXPORT_OK = qw(checksum verify_cksum); sub checksum { my $pkt = shift; + my $cksum; - return (-unpack("%16C*", $pkt)) & 0xFFFF; + $cksum = 0; + foreach my $chr (map(ord, split(//, $pkt))) { + $cksum += $chr; + } + $cksum = (-$cksum) & 0xFFFF; + + return $cksum; } sub verify_cksum { @@ -52,3 +58,5 @@ while (<>) { chomp; test($_); } + +1;