[Nottingham] Perl - NetPacket modules
Graeme Fowler
graeme at graemef.net
Thu Dec 28 12:34:56 GMT 2006
On Thu, 2006-12-28 at 11:46 +0000, Michael Erskine (at home!) wrote:
> OK, how are you calling the encode method? From the docs on cpan
> (http://search.cpan.org/~atrak/NetPacket-0.04/NetPacket/IP.pm) I see
> that encode expects a scalar containing an object ref but you seem to be
> passing something else (perhaps by mistake). Post a bit of code that
> gives you the problem.
Slightly edited to remove the surrounding and contained cruft, we have:
print "entering loop...\n" if ($debug > 0);
while (1) {
if (!defined($packet = $queue->get_message($timeout))) {
if (IPTables::IPv4::IPQueue->errstr=~/Timeout/) {
print "Timeout...\n" if ($debug > 1);
} else {
die "ERROR: ". IPTables::IPv4::IPQueue->errstr . "\n";
}
} else {
print "packet!\n" if ($debug > 1);
if(defined($ip = NetPacket::IP->decode($packet->payload()))) {
# at this point, $ip is a scalar hashref
#...various tests to determine where the packet came from, what
# it's doing, etc etc and set various flags
$src_ip_addr = $ip->{src_ip};
$dst_ip_addr = $ip->{dst_ip};
if ($ip->{proto}==6) {
$tcp = NetPacket::TCP->decode($ip->{data});
$dst_port = $tcp{dest_port};
$proto="TCP";
}
} else {
# something isn't right
die "Exiting: decode failed\n";
}
$retpack = NetPacket::IP->encode($ip)
print "Passing packet back to kernel...\n" if ($debug > 1);
$queue->set_verdict($packet->packet_id(), NF_ACCEPT);
}
}
The line defining $retpack is where it throws the error, every time. I
can call it with the scalar hashref or try to create an empty
constructor, the error is the same.
Graeme
More information about the Nottingham
mailing list