Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ fn ping_with_socktype(
let reply = if dest.is_ipv4() {
// DGRAM socket on Linux may return pure ICMP packet without IP header.
if n == ECHO_REQUEST_BUFFER_SIZE {
match EchoReply::decode::<IcmpV4>(&buffer) {
match EchoReply::decode::<IcmpV4>(&buffer[..n]) {
Ok(reply) => reply,
Err(_) => continue,
}
} else {
// Skip undecodable IP packets (malformed, truncated, or
// unrelated ICMP traffic from other hosts on a RAW socket)
// instead of failing the whole ping; keep waiting for our reply.
let ipv4_packet = match IpV4Packet::decode(&buffer) {
let ipv4_packet = match IpV4Packet::decode(&buffer[..n]) {
Ok(packet) => packet,
Err(_) => continue,
};
Expand All @@ -151,7 +151,7 @@ fn ping_with_socktype(
}
}
} else {
match EchoReply::decode::<IcmpV6>(&buffer) {
match EchoReply::decode::<IcmpV6>(&buffer[..n]) {
Ok(reply) => reply,
Err(_) => continue,
}
Expand Down
Loading