LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
LinkBack Search this Thread
Old 06-24-2008, 11:16 PM   #1
tanmoy_tiger
LQ Newbie
 
Registered: Jun 2008
Posts: 6

Rep: Reputation: 0
Red face 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?
 
Old 06-24-2008, 11:20 PM   #2
tanmoy_tiger
LQ Newbie
 
Registered: Jun 2008
Posts: 6

Original Poster
Rep: Reputation: 0
Red face

Quote:
Originally Posted by tanmoy_tiger View Post
i want to make a program using libpcap.But it doesn't work properly.
My code is as followProgram 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
 
  


Reply

Tags
libpcap, programing


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
libpcap thealphajustin Linux - Newbie 2 09-22-2006 04:52 PM
problem with libpcap ARCIS_house Linux - Newbie 9 06-05-2006 12:41 AM
Two questions about libpcap. smn Programming 2 11-19-2003 06:02 PM
libpcap trojan baduba Linux - Security 3 11-20-2002 06:00 AM
libpcap oulevon Linux - General 1 09-25-2001 09:06 AM


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

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