NAME

AnyEvent::Pcap - Net::Pcap wrapper with AnyEvent

SYNOPSIS

use AnyEvent::Pcap;

my $a_pcap;
$a_pcap = AnyEvent::Pcap->new(
    device         => "eth0",
    filter         => "tcp port 80",
    timeout        => 1000,
    packet_handler => sub {
        my $io     = pop;
        while (@_) {
            my $header = shift;
            my $packet = shift;

            # you can use utils to get an NetPacket::TCP object.
            my $tcp = $a_pcap->utils->extract_tcp_packet($packet);

            # or ...
            $tcp = AnyEvent::Pcap::Utils->extract_tcp_packet($packet); 

            # do something....
        }
    }
);

$a_pcap->run();

AnyEvent->condvar->recv;

DESCRIPTION

AnyEvent::Pcap is a Net::Pcap wrapper with AnyEvent.

Also you can use its utils to get NetPacket::IP or NetPacket::TCP object.

METHODS

new([%args]);
my %args = (

    # It will be filled up Net::Pcap::pcap_lookupdev() by default
    device => "eth0",

    # Default is NULL
    filter => "tcp port 80",

    # How much time wait befor flush pcap buffer
    # Default is 0 (unlimited)
    timeout => 1000,

    # set your coderef
    packet_handler => sub {
        my $io     = pop;

        # get first pair....
        my $header = shift;
        my $packet = shift;

        # do something....
    }
);

my $a_pcap = AnyEvent::Pcap->new(%args);

Cteate and return new AnyEvent::Pcap object .

utils()
my $a_pcap = AnyEvent::Pcap->new;
my $utils  = $a_pcap->utils;
  

You can get an utilty for packet handling. See AnyEvent::Pcap::Utils.

run()
my $a_pcap = AnyEvent::Pcap->new(%args);
$a_pcap->run;

AnyEvent->condvar->recv;

Running AnyEvent loop.

accessor methods

device([STRING])
fiilter([STRING])
packet_handler([CODEREF])
timeout([INTEGER])

AUTHOR

Takeshi Miki <miki@cpan.org>

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

AnyEvent Net::Pcap