Skip to content

Commit

Permalink
fix parsing of ICMP responses when using raw socket
Browse files Browse the repository at this point in the history
also when falling back from ping socket to raw

the data received from a raw socket also contains the IP header so it needs to
be parsed differently
  • Loading branch information
abraxxa committed Jan 17, 2018
1 parent ddcaf5b commit 6f93535
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- fix parsing of ICMP responses when using raw socket
also when falling back from ping socket to raw

0.003002 2018-01-17 14:01:58+01:00 Europe/Vienna
- fix processing of unrelated ICMP and ICMPv6 error packets
Expand Down
24 changes: 19 additions & 5 deletions lib/Net/Async/Ping/ICMP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,25 @@ sub ping {
my $from_pid = -1;
my $from_seq = -1;

my $frame = Net::Frame::Simple->new(
raw => $recv_msg,
firstLayer => 'ICMPv4',
);
my @layers = $frame->layers;
my @layers;
# ping sockets only return the ICMP packet
if ($ping_socket) {
my $frame = Net::Frame::Simple->new(
raw => $recv_msg,
firstLayer => 'ICMPv4',
);
@layers = $frame->layers;
}
# raw sockets return the IPv4 packet containing the ICMP payload
else {
my $frame = Net::Frame::Simple->new(
raw => $recv_msg,
firstLayer => 'IPv4',
);
@layers = $frame->layers;
# discard the IPv4 layer
shift @layers;
}
my $icmpv4 = $layers[0];
my $icmpv4_payload = $layers[1];

Expand Down

0 comments on commit 6f93535

Please sign in to comment.