From efbf6968fae93835bfa8f031abc5e95d62179a6a Mon Sep 17 00:00:00 2001 From: An Long Date: Thu, 25 Jun 2026 00:16:48 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Decode=20replies=20using=20actua?= =?UTF-8?q?l=20received=20length?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ping.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ping.rs b/src/ping.rs index 599fc96..2900df3 100644 --- a/src/ping.rs +++ b/src/ping.rs @@ -132,7 +132,7 @@ 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::(&buffer) { + match EchoReply::decode::(&buffer[..n]) { Ok(reply) => reply, Err(_) => continue, } @@ -140,7 +140,7 @@ fn ping_with_socktype( // 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, }; @@ -151,7 +151,7 @@ fn ping_with_socktype( } } } else { - match EchoReply::decode::(&buffer) { + match EchoReply::decode::(&buffer[..n]) { Ok(reply) => reply, Err(_) => continue, }