-
I captured a packet with nfqueue-rs (Debian 11) and in Vec it looks like:
The destination port number should be 10001, but I'm getting 44. I've tried to convert to big and little endian, but only get wrong values with the following code: struct PacketVkr<'a> {
raw_data: &'a nfqueue::Message,
}
impl<'a> PacketVkr<'a> {
pub fn new(raw_packet: &nfqueue::Message) -> PacketVkr {
PacketVkr {raw_data: &raw_packet}
}
pub fn show_info(&self) {
let packet_data = &self.raw_data.get_payload();
println!("packet payload: {:?}\n", packet_data);
if let Some(tcp_packet) = pnet::packet::tcp::TcpPacket::new(&packet_data) {
println!("Destination port: {:?}, Origin port: {:?}", tcp_packet.get_destination(), tcp_packet.get_source());
}
}
} Am I doing something wrong or is it a bug? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I figured it out. I had to first create an IP packet from the data. Then use the payload from that to turn into a TCP packet to extract the port numbers: let ip4_packet = pnet::packet::ipv4::Ipv4Packet::new(packet).unwrap();
let tcp_packet = pnet::packet::tcp::TcpPacket::new(ip4_packet.payload()).unwrap();
let port_number = tcp_packet.get_destination(); |
Beta Was this translation helpful? Give feedback.
I figured it out. I had to first create an IP packet from the data. Then use the payload from that to turn into a TCP packet to extract the port numbers: