From 62d30ceae14ddf3d468dd4a7216794d52fb217b0 Mon Sep 17 00:00:00 2001 From: Dan Scott Date: Mon, 20 Jun 2011 22:11:38 -0400 Subject: [PATCH] Convert checksum to hex value inside checksum() function 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 --- Sip.pm | 5 +---- Sip/Checksum.pm | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Sip.pm b/Sip.pm index 42c6e02..0922e84 100644 --- 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); } diff --git a/Sip/Checksum.pm b/Sip/Checksum.pm index 35abb3a..6d6a66b 100644 --- a/Sip/Checksum.pm +++ b/Sip/Checksum.pm @@ -77,7 +77,7 @@ sub checksum { printf STDERR "# %39s\n", $check; } - return $check; + return sprintf("%4.4X", $check); } sub verify_cksum { -- 2.11.0