Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Apply Andrew Feren's patch to make ICMP packet parsing more correct.

Resolves rt.cpan.org ticket 33968.
  • Loading branch information...
commit 5efb3836b26cebf6099435135a097031ea3ba9c8 1 parent 080153c
Rocco Caputo authored March 24, 2008

Showing 1 changed file with 5 additions and 6 deletions. Show diff stats Hide diff stats

  1. 11  Ping.pm
11  Ping.pm
@@ -24,7 +24,7 @@ use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS);
24 24
 );
25 25
 
26 26
 use vars qw($VERSION $PKTSIZE);
27  
-$VERSION = '1.13';
  27
+$VERSION = '1.14';
28 28
 $PKTSIZE = $^O eq 'linux' ? 3_000 : 100;
29 29
 
30 30
 use Carp qw(croak);
@@ -527,16 +527,15 @@ sub poco_ping_pong {
527 527
   my ($from_port, $from_ip) = unpack_sockaddr_in($from_saddr);
528 528
 
529 529
   # Get the response packet's time to live.
530  
-  my ($from_ttl) = unpack('C', substr($recv_message, 8, 1));
  530
+  my ($ihl, $from_ttl) = unpack('C1@7C1', $recv_message);
  531
+  $ihl &= 0x0F;
531 532
 
532 533
   # Unpack the packet itself.
533 534
   my (
534 535
     $from_type, $from_subcode,
535 536
     $from_checksum, $from_pid, $from_seq, $from_message
536  
-  )  = unpack(
537  
-    ICMP_STRUCT . $heap->{data_size},
538  
-    substr($recv_message, -$heap->{message_length})
539  
-  );
  537
+  )  = unpack( '@'.$ihl*4 . ICMP_STRUCT.$heap->{data_size},
  538
+               $recv_message );
540 539
 
541 540
   DEBUG and do {
542 541
     warn ",----- packet from ", inet_ntoa($from_ip), ", port $from_port\n";

0 notes on commit 5efb383

Please sign in to comment.
Something went wrong with that request. Please try again.