packet capture library

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi 
     I have written a simple packet capture code as
below.
I am getting blocked for ever in pcap_next though i
have given a timeout in pcap_open_live.
I am not getting the printf statement before pcap_next
too,looks strange.

pcap_next waits indefinitely,though i am pinging the
machine,pcap should also be capturing ICMP packets.

But if i comment pcap_next i get all the printf
statements.

I tried even with pcap_loop,doesnt seem to work.
I have read almost all the documents in tcpdump.org
can anyone tell me whether this code will work,or any
clues,as i am trying to write a sniffer code.


#include <stdio.h>
#include <netinet/in.h>
#include <pcap/pcap.h>

int main()
{
        char* dev=NULL;
        char err[256];
        pcap_t* descr=NULL;
        char* packet;
        struct pcap_pkthdr hdr;
                
        dev = pcap_lookupdev(err);
        if(dev == NULL){
                printf("Unable to find the network
device");
                exit(1);
        }
   
        descr = pcap_open_live(dev,1500,0,1000,err);  

   
        if(descr == NULL)
        {                 
                printf("\nUnable to open the %s for
capture",dev);
                exit(1);
        }
        
        printf("\nopened the %s for capture",dev);
     
        for(;packet=(char*)pcap_next(descr,&hdr);)
        {
                printf("\nPKT:%s",packet);
        }
        printf("\nEND");
        return 0;
}


Thanks
Vidhya




http://my.yahoo.com.au - My Yahoo!
- It's My Yahoo! Get your own!
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux