dantheman1210 has asked for the wisdom of the Perl Monks concerning the following question:

Forgive me if this is a simple question, but I have been looking for hours and can't seem to find it.

I have two simple scripts, one that creats and sends UDP packets and another that listens and processes those packets both using IO::Socket::INET.

What I would like to be able to do is verify the checksum of the packet in the receiving script. Sadly I can't find a way to get the UDP checksum of the packet and once I have it to compare with the actual packet data. Am I missing something this obvious or is it more difficult than I think it should be?

  • Comment on How to check the UDP checksum of an IO::Socket::INET packet

Replies are listed 'Best First'.
Re: How to check the UDP checksum of an IO::Socket::INET packet
by BrowserUk (Patriarch) on Mar 14, 2012 at 03:48 UTC

    IP packet checksums are check at the transmission layer. If the checksum fails to verify, your receiver will never be notified that anything arrived.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

Re: How to check the UDP checksum of an IO::Socket::INET packet
by VinsWorldcom (Prior) on Mar 14, 2012 at 12:32 UTC

    I won't say it's impossible, but I don't *think* it can be done with IO::Socket::INET. The methods available will return peer address and port, but not specific fields in the IP or 'transport' (TCP / UDP) layer protocol.

    It is certainly possible with something like Net::Pcap. But of course with that functionality comes complexity - you'll need to understand the structure of the entire frame / packet to get the right field and parse it into a meaningful number representing the checksum.

    If you want to go that way for the receiver, you're looking at creating a simple packet capture ('sniffer') and there is an incredibly useful suite of Perl modules for crafting and dissecting frames / packets:

    Net::Frame

    Net::Frame::Simple

    Net::Frame::Dump

    As BrowserUK says above, packets with incorrect checksums aren't even sent. There is of course the possibility it gets mangled en-route - perhaps that's what you're trying to check for? Although even then, as the receiver passes this up the stack and the checksum fails to verify, I think the packet is discarded before being sent to the 'application' layer.

      Well at least I wasn't totally missing something in IO::Socket::INET. :)

      I will look into the Net::Pcap and Net::Frame stuff to see what I can do with them.

      Thank you both for the assistance! I have no doubt that I will be back with some more painfully obvious questions.