From 26934901c8db591739ebf5d459489c26d4e569cd Mon Sep 17 00:00:00 2001 From: FujiApple Date: Tue, 3 Oct 2023 23:55:15 +0800 Subject: [PATCH] feat: truncate Ipv4 and Ipv6 packets to the number of bytes read from the socket --- src/tracing/net/ipv4.rs | 4 ++-- src/tracing/net/ipv6.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tracing/net/ipv4.rs b/src/tracing/net/ipv4.rs index 23206c1ec..c20cc9649 100644 --- a/src/tracing/net/ipv4.rs +++ b/src/tracing/net/ipv4.rs @@ -189,8 +189,8 @@ pub fn recv_icmp_probe( ) -> TraceResult> { let mut buf = [0_u8; MAX_PACKET_SIZE]; match recv_socket.read(&mut buf) { - Ok(_bytes_read) => { - let ipv4 = Ipv4Packet::new_view(&buf).req()?; + Ok(bytes_read) => { + let ipv4 = Ipv4Packet::new_view(&buf[..bytes_read]).req()?; Ok(extract_probe_resp(protocol, &ipv4)?) } Err(err) => match err.kind() { diff --git a/src/tracing/net/ipv6.rs b/src/tracing/net/ipv6.rs index 5e8a49927..8b7f128a5 100644 --- a/src/tracing/net/ipv6.rs +++ b/src/tracing/net/ipv6.rs @@ -141,8 +141,8 @@ pub fn recv_icmp_probe( ) -> TraceResult> { let mut buf = [0_u8; MAX_PACKET_SIZE]; match recv_socket.recv_from(&mut buf) { - Ok((_bytes_read, addr)) => { - let icmp_v6 = IcmpPacket::new_view(&buf).req()?; + Ok((bytes_read, addr)) => { + let icmp_v6 = IcmpPacket::new_view(&buf[..bytes_read]).req()?; let src_addr = match addr.as_ref().req()? { SocketAddr::V6(addr) => addr.ip(), SocketAddr::V4(_) => panic!(),