Convert checksum to hex value inside checksum() function
authorDan Scott <dan@coffeecode.net>
Tue, 21 Jun 2011 02:11:38 +0000 (22:11 -0400)
committerDan Scott <dan@coffeecode.net>
Tue, 21 Jun 2011 02:11:38 +0000 (22:11 -0400)
Rather than returning the integer value of the checksum and converting
that to a hex value only when it is appended to the returned message,
return the hex value from checksum() itself. This enables the unit tests
for Sip::Checksum to be run meaningfully.

Signed-off-by: Dan Scott <dan@coffeecode.net>
Sip.pm
Sip/Checksum.pm

diff --git a/Sip.pm b/Sip.pm
index 42c6e02..0922e84 100644 (file)
--- a/Sip.pm
+++ b/Sip.pm
@@ -225,15 +225,12 @@ sub read_SIP_packet {
 
 sub write_msg {
     my ($self, $msg, $file) = @_;
-    my $cksum;
 
     if ($error_detection) {
         if (defined($self->{seqno})) {
             $msg .= 'AY' . $self->{seqno};
         }
-        $msg .= 'AZ';
-        $cksum = checksum($msg);
-        $msg .= sprintf('%04.4X', $cksum);
+        $msg .= 'AZ' . checksum($msg);
     }
 
 
index 35abb3a..6d6a66b 100644 (file)
@@ -77,7 +77,7 @@ sub checksum {
         printf STDERR "# %39s\n", $check;
     }
 
-    return $check;
+    return sprintf("%4.4X", $check);
 }
 
 sub verify_cksum {