Closed mjmjelde closed 6 years ago
You need to convert the port value from network to host order using ntohs()
:
printf("Source port is '%d'; Dest Port is '%d'\n", ntohs(udpLayer->getUdpHeader()->portSrc), ntohs(udpLayer->getUdpHeader()->portDst));
ntohs(31753)
=> 2428
ntohs(30729)
=> 2424
You can also take a look at the following tutorial to understand more: http://seladb.github.io/PcapPlusPlus-Doc/tutorial_packet_parsing.html
Did it solve the issue?
Hey sorry I meant to respond yesterday and forgot. Yes this resolved my issue. Thanks! I will go ahead and close this ticket
Howdy,
I am currently trying to get the source and destination ports of some UDP packets, however it seems like they are not being read correctly.
A sample file that I am testing on is the tpncp_udp.pcap file from the wireshark samples page, found here: https://wiki.wireshark.org/SampleCaptures?action=AttachFile&do=get&target=tpncp_udp.pcap
The first packet in this file is from 10.4.2.44:2428 and is going to destination 10.4.96.100:2424 according to wireshark. However, when I use the following code, the source port shows up as 31753 and the destination port is 30729. Is there something I am doing wrong?