/usr/share/doc/libnflog-perl/examples/example.pl is in libnflog-perl 0.2-3.1+b3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | #!/usr/bin/perl -w
#
# see http://search.cpan.org/~atrak/NetPacket-0.04/
use strict;
BEGIN {
push @INC,"perl";
push @INC,"build/perl";
push @INC,"NetPacket-0.04";
};
use nflog;
use NetPacket::IP qw(IP_PROTO_TCP);
use NetPacket::TCP;
use Socket qw(AF_INET AF_INET6);
my $l;
sub cleanup()
{
print "unbind\n";
$l->unbind(AF_INET);
print "close\n";
$l->close();
}
sub cb()
{
my ($payload) = @_;
print "Perl callback called!\n";
if ($payload) {
print "len: " . $payload->get_length() . "\n";
my $ip_obj = NetPacket::IP->decode($payload->get_data());
print $ip_obj, "\n";
print("$ip_obj->{src_ip} => $ip_obj->{dest_ip} $ip_obj->{proto}\n");
print "Id: " . $payload->swig_id_get() . "\n";
if($ip_obj->{proto} == IP_PROTO_TCP) {
# decode the TCP header
my $tcp_obj = NetPacket::TCP->decode($ip_obj->{data});
print "TCP src_port: $tcp_obj->{src_port}\n";
print "TCP dst_port: $tcp_obj->{dest_port}\n";
}
return 0;
}
}
$l = new nflog::log();
$SIG{INT} = "cleanup";
print "setting callback\n";
$l->set_callback(\&cb);
print "open\n";
$l->fast_open(1, AF_INET);
print "trying to run\n";
$l->try_run();
|