Skip to content

Commit

Permalink
feat: truncate Ipv4 and Ipv6 packets to the number of bytes read from…
Browse files Browse the repository at this point in the history
… the socket
  • Loading branch information
fujiapple852 committed Oct 6, 2023
1 parent 55eb028 commit 2693490
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/tracing/net/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ pub fn recv_icmp_probe<S: Socket>(
) -> TraceResult<Option<ProbeResponse>> {
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() {
Expand Down
4 changes: 2 additions & 2 deletions src/tracing/net/ipv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ pub fn recv_icmp_probe<S: Socket>(
) -> TraceResult<Option<ProbeResponse>> {
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!(),
Expand Down

0 comments on commit 2693490

Please sign in to comment.