Skip to content

How to get the correct destination port-number? #668

Closed Answered by Tech56
Tech56 asked this question in Q&A
Discussion options

You must be logged in to vote

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();

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Tech56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant