PCAP library in Perl in UBUNTU ????

Discussion of programming on Linux, including shell scripting, perl, python, c/c++, mono, java. Whatever tickles your fancy.

PCAP library in Perl in UBUNTU ????

Postby talalshah » Mon Apr 10, 2006 2:39 pm

Hi, I have to access NET::PCAP lbrary from Perl using BUNTU 5.04 version. I found libpcap libraries at www.tcpdump.com.
but when i try to access the library it never worked. can you tell me how do access these libraries. also there is a PCAP library in /usr folder, but i dont exactly know is it installed or not.
can anyone help me please.
I need some help as soon as possible because it is related to my project.
Hope i get reply from anyone.

Thanks in advance

do tell me at this id

Talal Shah Bukhari
Posts: 5
Joined: Mon Apr 10, 2006 2:33 pm


Postby LinuxFreaK » Wed Apr 12, 2006 10:26 am

Dear talalshah,

Use below command.

# perl -MCPAN -e shell
CPAN> install Net::Pcap
CPAN> exit

Best Regards.
Farrukh Ahmed
Site Admin
Posts: 5132
Joined: Fri May 02, 2003 10:24 am
ICQ: 82075802
Website: http://www.linuxpakistan.net/wiki/index.php?pagename=LinuxFreak
WLM: f4fahmed@hotmail.com
Yahoo Messenger: f4fahmed@yahoo.com
AOL: linuxpakistan@aol.com
Location: Karachi

Postby Kdaemon » Wed Apr 12, 2006 10:35 am

After installing the perl pcap modules, here is the sample code you can go through.

Net::Pcap - Interface to pcap LBL packet capture library

Code: Select all

use strict;
use Net::Pcap;

# Switch this to 1 for enabling debugging code
my $debug = 1;

# Do no buffering - flushing output directly
#declaration of functions
sub f_probe_pcapinit;
sub f_probe_read80211b_func;
sub f_probe_ctrl_c;

# Declarations of global variables
my $g_pcap_err = '';
my $g_sniff_device='eth0';
my $g_cap_descrip;

# Trapping Signal "INT" like ctrl+c for cleanup first.
$SIG{INT} = \&f_probe_ctrl_c;

# Main program
#initializing the sniffer

# End of the main-program

sub f_probe_pcapinit{
if ($g_cap_descrip = Net::Pcap::open_live($g_sniff_device,2000,0,1000,\$g_pcap_err))
# Initiate endless packet gathering.
Net::Pcap::loop($g_cap_descrip, -1, \&f_probe_read80211b_func , '' );
print "\nCould not initiating the open_live command on $g_sniff_device from the pcap.\nThe following error where reported: $g_pcap_err\n";

sub f_probe_read80211b_func {
my($data, $header,$packet) = @_;
print "\n Got a packet: ";
print "\n" . unpack ('H*',$packet);

sub f_probe_ctrl_c {
# Checks if there is a open pcap handle and closes it first.
if ($g_cap_descrip)
Net::Pcap::close ($g_cap_descrip);
print "\nClosed the pcap allready, the program exits now.\n";
# End of file
reg linux user #298274
Naib Subedar
Posts: 346
Joined: Sat Nov 30, 2002 12:22 pm
Location: Islamabad. GPS: LHR

Re: PCAP library in Perl in UBUNTU ????

Postby lambda » Wed Apr 12, 2006 11:25 am

install the libpcap-devel package. ubuntu might also have the perl module as a package, i can't tell right now.

always check your distribution for packages related to libraries or other software you want to install. don't go out and download random crap from other sites.
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Website: http://www.hungry.com/~fn/
Location: Lahore

Postby talalshah » Sat Apr 22, 2006 7:29 pm

thank you all for help.
Posts: 5
Joined: Mon Apr 10, 2006 2:33 pm

Return to “%s” Programming

Who is online

Users browsing this forum: No registered users and 1 guest