Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 05-17-2005, 05:58 PM   #1
LQ Newbie
Registered: May 2005
Posts: 1

Rep: Reputation: 0
Can't sniff packets using libpcap

I'm trying to sniff packets on my non switched ethernet network using libpcap. The problem is that I can't sniff anything except for what is destined to the MAC address of the sniffing machine. I've set the NIC to promiscuous mode by setting the promisc flag to 1 in the pcap_open_live function.
"descr = pcap_open_live(dev,BUFSIZ,1,-1,errbuf)". That didn't help. So I tried setting it manually using ifconfig eth0 promisc. That didn't help either.

There's nothing wrong with the NIC or anything since tcpdump works like a charm. So I must be missing out on something!

Any suggestions??? Please help.

I'm using this example code I found.

* file: testpcap1.c
* Date: Thu Mar 08 17:14:36 MST 2001
* Author: Martin Casado
* Location: LAX Airport (hehe)
* Simple single packet capture program
#include <stdio.h>
#include <stdlib.h>
#include <pcap.h> /* if this gives you an error try pcap/pcap.h */
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/if_ether.h> /* includes net/ethernet.h */

int main(int argc, char **argv)
int i;
char *dev;
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t* descr;
const u_char *packet;
struct pcap_pkthdr hdr; /* pcap.h */
struct ether_header *eptr; /* net/ethernet.h */

u_char *ptr; /* printing out hardware header info */

/* grab a device to peak into... */
dev = pcap_lookupdev(errbuf);

if(dev == NULL)

printf("DEV: %s\n",dev);

descr = pcap_open_live(dev,BUFSIZ,1,-1,errbuf);

if(descr == NULL)
printf("pcap_open_live(): %s\n",errbuf);

grab a packet from descr (yay!)
u_char *pcap_next(pcap_t *p,struct pcap_pkthdr *h)
so just pass in the descriptor we got from
our call to pcap_open_live and an allocated
struct pcap_pkthdr */

packet = pcap_next(descr,&hdr);


Last edited by masterm; 05-17-2005 at 06:00 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ability to sniff, process and drop packets kidskc Linux - Networking 1 08-18-2005 01:40 AM
how can i use libpcap to capture packets for the local loopback interface (lo) ? gajaykrishnan Programming 0 02-22-2005 04:03 AM
encapsulating TCP packets in UDP packets... yoshi95 Programming 3 06-03-2004 02:53 PM
aim sniff WallMart4Life Linux - Networking 2 08-11-2003 12:42 PM
How to sniff port redirection shawnzhou888 Linux - Networking 0 07-18-2003 02:31 PM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:07 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration