LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   libpcap programming (https://www.linuxquestions.org/questions/linux-newbie-8/libpcap-programming-651442/)

tanmoy_tiger 06-24-2008 11:16 PM

libpcap programming
 
i want to make a program using libpcap.But it doesn't work properly.
My code is as follow:
#include<stdio.h>
#include<pcap.h>
#include<stdlib.h>
void process_packet(u_char *arg,struct pcap_pkthdr *header,u_char *packet)
{
printf("\npacket is captured");
}
int main()
{
char *dev;
char errbuf[PCAP_ERRBUF_SIZE];
bpf_u_int32 mask,net;
struct bpf_program fp;
char filter[]="ip";
pcap_t *p;
printf("1");
dev=pcap_lookupdev(errbuf);
printf("dev:%s",dev);
printf("\n2");
if(dev==NULL)
{
printf("\nError:%s",errbuf);
exit(0);
}
else
printf("\nDEVICE:%s",dev);
if(pcap_lookupnet(dev,&net,&mask,errbuf)==-1)
printf("\nError:%s",errbuf);
printf("\n3");
p=pcap_open_live(dev,200,1,2000,errbuf);
if(p==NULL)
printf("\nError:%s",errbuf);
if(pcap_compile(p,&fp,filter,0,net)==-1)
printf("\nError:%s",pcap_geterr(p));
if(pcap_setfilter(p,&fp)==-1)
printf("\nError:%s",pcap_geterr(p));
pcap_loop(p,2,process_packet,NULL);
printf("\nLibrary version:%s \n",pcap_lib_version());
pcap_freecode(&fp);
pcap_close(p);
return 1;
}
and in console i get this:
tanmoy:/home/tanmoy/Desktop/tdas # gcc appdev.c -lpcap
appdev.c: In function ‘main’:
appdev.c:37: warning: passing argument 3 of ‘pcap_loop’ from incompatible pointer type
tanmoy:/home/tanmoy/Desktop/tdas # ./a.out
1dev:eth0
2
DEVICE:eth0



and nothing else.What should i do???????????What is the problem?

tanmoy_tiger 06-24-2008 11:20 PM

Quote:

Originally Posted by tanmoy_tiger (Post 3194241)
i want to make a program using libpcap.But it doesn't work properly.
My code is as follow:(Program name is appdev.c)
#include<stdio.h>
#include<pcap.h>
#include<stdlib.h>
void process_packet(u_char *arg,struct pcap_pkthdr *header,u_char *packet)
{
printf("\npacket is captured");
}
int main()
{
char *dev;
char errbuf[PCAP_ERRBUF_SIZE];
bpf_u_int32 mask,net;
struct bpf_program fp;
char filter[]="ip";
pcap_t *p;
printf("1");
dev=pcap_lookupdev(errbuf);
printf("dev:%s",dev);
printf("\n2");
if(dev==NULL)
{
printf("\nError:%s",errbuf);
exit(0);
}
else
printf("\nDEVICE:%s",dev);
if(pcap_lookupnet(dev,&net,&mask,errbuf)==-1)
printf("\nError:%s",errbuf);
printf("\n3");
p=pcap_open_live(dev,200,1,2000,errbuf);
if(p==NULL)
printf("\nError:%s",errbuf);
if(pcap_compile(p,&fp,filter,0,net)==-1)
printf("\nError:%s",pcap_geterr(p));
if(pcap_setfilter(p,&fp)==-1)
printf("\nError:%s",pcap_geterr(p));
pcap_loop(p,2,process_packet,NULL);
printf("\nLibrary version:%s \n",pcap_lib_version());
pcap_freecode(&fp);
pcap_close(p);
return 1;
}
and in console i get this:
tanmoy:/home/tanmoy/Desktop/tdas # gcc appdev.c -lpcap
appdev.c: In function ‘main’:
appdev.c:37: warning: passing argument 3 of ‘pcap_loop’ from incompatible pointer type
tanmoy:/home/tanmoy/Desktop/tdas # ./a.out
1dev:eth0
2
DEVICE:eth0



and nothing else.What should i do???????????What is the problem?

please mail me at tanmoy.justu@gmail.com


All times are GMT -5. The time now is 07:16 PM.