Skip to content

Commit

Permalink
Fix parse UDP and TCP packets correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Mar 27, 2024
1 parent 18ac9a4 commit e7fbf6c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test/test-manager/src/network_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ impl Codec {

let mut source = SocketAddr::new(IpAddr::V4(packet.get_source()), 0);
let mut destination = SocketAddr::new(IpAddr::V4(packet.get_destination()), 0);
let mut payload = vec![];

let protocol = packet.get_next_level_protocol();

match protocol {
IpHeaderProtocols::Tcp => {
let seg = TcpPacket::new(packet.payload()).or_else(|| {
Expand All @@ -87,6 +87,7 @@ impl Codec {
})?;
source.set_port(seg.get_source());
destination.set_port(seg.get_destination());
payload = seg.payload().to_vec();
}
IpHeaderProtocols::Udp => {
let seg = UdpPacket::new(packet.payload()).or_else(|| {
Expand All @@ -95,13 +96,12 @@ impl Codec {
})?;
source.set_port(seg.get_source());
destination.set_port(seg.get_destination());
payload = seg.payload().to_vec();
}
IpHeaderProtocols::Icmp => {}
proto => log::debug!("ignoring v4 packet, transport/protocol type {proto}"),
}

let payload = packet.payload().to_vec();

Some(ParsedPacket {
source,
destination,
Expand Down

0 comments on commit e7fbf6c

Please sign in to comment.