libpcap bindings for Perl6
Branch: master
Clone or download
Latest commit 102fb43 Jun 11, 2015
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Update documentation. Jun 11, 2015
lib/Net C_Buf.pm6: Fixed positional implementation. Jun 1, 2015
t Initial commit. Nov 16, 2014
LICENSE
META.info NativeCall is now in "CORE" Mar 2, 2015
README.md README.md: Install with panda Nov 21, 2014
TODO.md TODO.md: Add not yet implemented libpcap functions. Nov 24, 2014

README.md

Net::Pcap (Perl6)

Libpcap bindings for Perl6.

The modules are annotated with Pod. These Pods are rendered to docs/.

perl6-net-packet is useful for decoding frames.

Installation

Using panda:

$ panda update
$ panda install Net::Pcap

Using ufo:

$ ufo           # Generates Makefile
$ make
$ make test
$ make install

Usage

Starting a capture:

use Net::Pcap;

# Live capturing
my $pcap = Net::Pcap.create("eth0");
$pcap.filter('portrange 1-1024');
$pcap.activate;

# Read from file
my $pcap = Net::Pcap.offline_open('./capture.pcap');

Looping through frames:

use Net::Packet :short;

loop $pcap.next_ex -> ($hdr, $frame) {
    my $eth = Ethernet.decode($frame);

    say sprintf 'Time:   %.3f', $hdr.seconds;
    say sprintf 'Length: %d (%d captured)', $hdr.len, $hdr.caplen;
    say sprintf 'Ethernet:';
    say sprintf '  Source:      %s', $eth.src;
    say sprintf '  Destination: %s', $eth.dst;

    if $eth.pl ~~ IPv4 {
        say sprintf 'IPv4:';
        say sprintf '  Source:      %s', $eth.pl.src;
        say sprintf '  Destination: %s', $eth.pl.dst;
    }
}