I've put together a perl script that reads packets into userspace via Linux::TunTap, and it all seems to work fine:
#!/usr/bin/perl
use warnings;
use strict;
use Linux::TunTap;
$tun = new Linux::TunTap(NAME => 'localtun')
or die "Couldn't connect to IF\n";
while (my $packet = $tun->get_raw()) {
print Dumper($packet);
}
Now the question is: How do I turn the string representing the raw IP packet as read from the tuntap device into a proper datastructure for processing? In particular I'm after the source, destination, and sequence number.
Obviously, the raw IP packet isn't very human readable in its original format. Here's the output after sending a ping through the tuntap interface:
{{{�}/��8V�| !"#$%&'()*+,-./0123456ET��@@4
How do I proceed from here to be able to process this data programatically?
$packet
, the remainder could be parsed withNetPacket::IP
. Too bad one can't accept a comment as answer. – Irrefragable