Re: Newbie to programming, Net::Divert, Linux-Debian, autoflush error
- From: vivek.m1234@xxxxxxxxx
- Date: Sat, 26 Apr 2008 03:35:55 -0700 (PDT)
Identified and solved part of the problem. When the divert was
compiled as part of the Linux kernel, it did not create an entry in /
etc/protocols. When IO::Socket::INET does:
if(defined $proto && $proto =~ /\D/) {
my $num = _get_proto_number($proto);
unless (defined $num) {
$@ = "Bad protocol '$proto'";
return;
it is not able to get a proper protocol number and b0rks.
Can i use any value for 'divert' in /etc/protocols? For testing
purposes i added divert 200 Blah. Now i get no error :) Instead the
darn program just sits around doing nothing! Whereas the C code works
great regardless! "alterpacket" isn't receiving and pkts to
process?????
----------------------------------------------------
# IPTABLES line to redirect all tcp pkts to port 9999
iptables -A INPUT -p TCP -j DIVERT --div-port 9999
# Perl script to listen on port 9999
#!/usr/bin/perl -w
use Net::Divert;
use NetPacket::IP;
use NetPacket::TCP;
my $divobj = Net::Divert->new('localhost',9999);
$divobj->getPackets(\&alterPacket);
sub alterPacket {
my($packet,$fwtag) = @_;
print STDOUT "hi\n";
exit;
#decode the IP header
my $ip_obj = NetPacket::IP->decode($packet);
#check if this is a TCP packet
if($ip_obj->{proto} == IP_PROTO_TCP) {
# decode the TCP header
my $tcp_obj = NetPacket::TCP->decode($ip_obj->{data});
# set the ece and cwr flags
$tcp_obj->{flags} |= ECE | CWR;
# construct the new ip packet
$ip_obj->{data} = $tcp_obj->encode($ip_obj);
$packet = $ip_obj->encode;
}
# write it back out
# $divobj->putPacket($packet,$fwtag);
}
.
- References:
- Newbie to programming, Net::Divert, Linux-Debian, autoflush error
- From: vivek . m1234
- Re: Newbie to programming, Net::Divert, Linux-Debian, autoflush error
- From: grocery_stocker
- Re: Newbie to programming, Net::Divert, Linux-Debian, autoflush error
- From: vivek . m1234
- Newbie to programming, Net::Divert, Linux-Debian, autoflush error
- Prev by Date: Re: Newbie to programming, Net::Divert, Linux-Debian, autoflush error
- Next by Date: Re: Newbie to programming, Net::Divert, Linux-Debian, autoflush error
- Previous by thread: Re: Newbie to programming, Net::Divert, Linux-Debian, autoflush error
- Next by thread: Re: Newbie to programming, Net::Divert, Linux-Debian, autoflush error
- Index(es):
Relevant Pages
|
|