I have spent a couple of days casting about, looking at examples and
perldoc. I don't seem to be able to get the data from 'tcpdump' (or
POE::Component::PCAP) to the wheel that will process the data. For my last
attempt, I removed Filter::Referece and tried with just the wheel. Still
no luck. Any suggestions?
#!/usr/bin/perl
use warnings;
use strict;
use POE qw( Wheel::Run ); #Filter::Reference );
use Data::Dumper;
our $offset = 0;
our $linechars = '';
POE::Session->create
( inline_states =>
{
_start => sub {
my ($heap) = $_[HEAP];
my $gp = POE::Wheel::Run->new
( Program => '/usr/sbin/tcpdump -i eth0 -w - '
# , Conduit => "pipe"
# , StdoutFilter => POE::Filter::Reference->new()
# , StdinEvent => 'process_packet'
, StdinEvent => 'stdin'
# , StdoutEvent => 'print'
# , InputEvent => 'process_packet'
);
print "gp compleate\n";
$heap->{gp} = $gp;
# my $pp = POE::Wheel::Run->new
# ( Program => &process_packet
# , StdoutEvent => 'stdout'
# );
}
}
);
sub process_packet {
print "process_packet called\n";
# my ($heap) = $_[HEAP];
# my $filter = POE::Filter::Reference->new();
# my $pdump = $filter->get( [ $heap->{gp} ] );
my $pdump = $_[ARG0];
foreach my $char (split(//, $pdump)) {
if($char !~ /\n/) {
dump_char($char) ;
} else {
print "\n\n";
$offset = 0;
$linechars = '';
}
1;
}
dump_char( ' ', 1 ) while length($linechars) != 0;
}
sub dump_char {
my ( $char ) = shift;
if ( length( $linechars ) == 0 ) {
printf( "%06X ", $offset );
}
$linechars .= ( $char =~ m#[!-~ ]# ) ? $char : '.';
printf( "%02X ", ord($char) );
if ( length( $linechars ) == 16 ) {
print( "\n" );
$linechars = '';
$offset += 16;
}
}
$poe_kernel->run();
exit 0;