I'm currently doing a class project using raw sockets to send out packets. The structure of the packet follows Ethernet/802.1Q/IP/UDP/Payload. On the receiver, I'm using libtins to sniff them to examine the packet to make sure I'm receiving them correctly. I'm having trouble extracting the UDP pdu from the packet. I can get up to the IP PDU, but when trying to get the UDP (and later payload size from raw PDU after), it throws PDU not found exception.
I have this snippet of code here:
bool processRawPacket(Tins::PDU &packet){
...
Tins::IP &ip = packet.rfind_pdu<Tins::IP>();
Tins::UDP &udp = packet.rfind_pdu<Tins::UDP>();
...
}
Is this the correct way to get the UDP PDU? I also tried
Tins::UDP &udp = ip.rfind_pdu<Tins::UDP>();
in case the UDP was the inner PDU, but I still get the not found exception.
The IP header info is mostly filled out with legitimate information. I can extract the src address/protocol/ID fields correctly from it. Does the IP header need a correct checksum for the UDP to be found? It is currently set to 0 to ignore.
Thanks,
Philip