From 80e317cf98d424f3b517da58ca5e619ec7b41238 Mon Sep 17 00:00:00 2001 From: djfiander Date: Fri, 25 Aug 2006 01:21:37 +0000 Subject: [PATCH] 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. --- Sip/Checksum.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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; -- 2.11.0