C<Net::PcapUtils> - Utility routines for Net::Pcap module |
Net::PcapUtils
- Utility routines for Net::Pcap module
require Net::Pcap 0.03; use Net::PcapUtils;
# Call function for all packets received
Net::PcapUtils::loop(\&callbackfn, [optional args]);
# Return the next packet available on the interface
($pkt, %hdr) = Net::PcapUtils::next($pcap_t);
# Open a network device for processing
$pcap_t = Net::PcapUtils::open([optional args]);
Net::PcapUtils is a module to sit in front of Net::Pcap in order to
hide some of the pcap(3)
initialisation by providing sensible
defaults. This enables a programmer to easily write small, specific
scripts for a particular purpose without having to worry about too
many details.
The functions implemented in Net::PcapUtils are named after those in Net::Pcap. The loop function sits in a loop and executes a callback for each packet received, while next retrieves the next packet from the network device, and open returns an opened packet descriptor suitable for use with other Net::Pcap routines.
The optional arguments are those which are normally passed to the
pcap_open_live()
function from the pcap(3)
library. Their defaults
are given below.
my %args = ( SNAPLEN => 100, # Num bytes to capture from packet PROMISC => 1, # Operate in promiscuous mode? TIMEOUT => 1000, # Read timeout (ms) NUMPACKETS => -1, # Pkts to read (-1 = loop forever) FILTER => '', # Filter string USERDATA => '', # Passed as first arg to callback fn SAVEFILE => '', # Default save file DEV => '', # Network interface to open );
Consult the documentation for the pcap(3)
library for more details on
the nature of these parameters.
On error, this function returns an error string describing the error. An empty string is returned upon success.
If the open()
command was successful, it returns a reference to a
packet capture descriptor, else a string containing an error message.
The following script prints a message for each IP packet received.
#!/usr/bin/perl -w
use strict; use Net::PcapUtils;
sub process_pkt { print("packet\n"); }
Net::PcapUtils::loop(\&process_pkt, FILTER => 'ip');
The Net::Pcap
module for XS bindings to the pcap(3)
library.
The pcap library is available from ftp://ftp.ee.lbl.gov/libpcap.tar.Z
Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the participants in the CRC for Advanced Computational Systems ('ACSys').
ACSys makes this software and all associated data and documentation ('Software') available free of charge. You may make copies of the Software but you must include all of this notice on any copy.
The Software was developed for research purposes and ACSys does not warrant that it is error free or fit for any purpose. ACSys disclaims any liability for all claims, expenses, losses, damages and costs any user may incur as a result of using, copying or modifying the Software.
Tim Potter <tpot@acsys.anu.edu.au>
C<Net::PcapUtils> - Utility routines for Net::Pcap module |