-#\r
-# Copyright (C) 2006-2008 Georgia Public Library Service\r
-# \r
-# Author: David J. Fiander\r
-# \r
-# This program is free software; you can redistribute it and/or\r
-# modify it under the terms of version 2 of the GNU General Public\r
-# License as published by the Free Software Foundation.\r
-# \r
-# This program is distributed in the hope that it will be useful,\r
-# but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-# GNU General Public License for more details.\r
-# \r
-# You should have received a copy of the GNU General Public\r
-# License along with this program; if not, write to the Free\r
-# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,\r
-# MA 02111-1307 USA\r
-\r
-package Sip::Checksum;\r
-\r
-use Exporter;\r
-use strict;\r
-use warnings;\r
-\r
-our @ISA = qw(Exporter);\r
-our @EXPORT_OK = qw(checksum verify_cksum);\r
-\r
-sub checksum {\r
- my $pkt = shift;\r
-\r
- return (-unpack('%16C*', $pkt) & 0xFFFF);\r
-}\r
-\r
-sub verify_cksum {\r
- my $pkt = shift;\r
- my $cksum;\r
- my $shortsum;\r
-\r
- return 0 if (substr($pkt, -6, 2) ne "AZ"); # No checksum at end\r
-\r
- # Convert the checksum back to hex and calculate the sum of the\r
- # pack without the checksum.\r
- $cksum = hex(substr($pkt, -4));\r
- $shortsum = unpack("%16U*", substr($pkt, 0, -4));\r
-\r
- # The checksum is valid if the hex sum, plus the checksum of the \r
- # base packet short when truncated to 16 bits.\r
- return (($cksum + $shortsum) & 0xFFFF) == 0;\r
-}\r
-\r
-{\r
- no warnings qw(once);\r
- eval join('',<main::DATA>) || die $@ unless caller();\r
-}\r
-__END__\r
-\r
-#\r
-# Some simple test data\r
-#\r
-sub test {\r
- my $testpkt = shift;\r
- my $cksum = checksum($testpkt);\r
- my $fullpkt = sprintf("%s%4X", $testpkt, $cksum);\r
-\r
- print $fullpkt, "\n";\r
-}\r
-\r
-while (<>) {\r
- chomp;\r
- test($_);\r
-}\r
-\r
-1;\r
+#
+# Copyright (C) 2006-2008 Georgia Public Library Service
+#
+# Author: David J. Fiander
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of version 2 of the GNU General Public
+# License as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free
+# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+
+package Sip::Checksum;
+
+use Exporter;
+use strict;
+use warnings;
+
+our @ISA = qw(Exporter);
+our @EXPORT_OK = qw(checksum verify_cksum);
+
+sub checksum {
+ my $pkt = shift;
+
+ return (-unpack('%16C*', $pkt) & 0xFFFF);
+}
+
+sub verify_cksum {
+ my $pkt = shift;
+ my $cksum;
+ my $shortsum;
+
+ return 0 if (substr($pkt, -6, 2) ne "AZ"); # No checksum at end
+
+ # 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));
+
+ # The checksum is valid if the hex sum, plus the checksum of the
+ # base packet short when truncated to 16 bits.
+ return (($cksum + $shortsum) & 0xFFFF) == 0;
+}
+
+{
+ no warnings qw(once);
+ eval join('',<main::DATA>) || die $@ unless caller();
+}
+__END__
+
+#
+# Some simple test data
+#
+sub test {
+ my $testpkt = shift;
+ my $cksum = checksum($testpkt);
+ my $fullpkt = sprintf("%s%4X", $testpkt, $cksum);
+
+ print $fullpkt, "\n";
+}
+
+while (<>) {
+ chomp;
+ test($_);
+}
+
+1;