libpcap bindings for Perl6
Branch: master
Clone or download
Latest commit 102fb43 Jun 11, 2015
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 NativeCall is now in "CORE" Mar 2, 2015 Install with panda Nov 21, 2014 Add not yet implemented libpcap functions. Nov 24, 2014

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.


Using panda:

$ panda update
$ panda install Net::Pcap

Using ufo:

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


Starting a capture:

use Net::Pcap;

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

# 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 $ ~~ IPv4 {
        say sprintf 'IPv4:';
        say sprintf '  Source:      %s', $;
        say sprintf '  Destination: %s', $;