LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-19-2005, 04:10 AM   #1
Prakhardeep
LQ Newbie
 
Registered: May 2004
Distribution: RH9
Posts: 11

Rep: Reputation: 0
Angry Error while compiling packet capturing code on FC2


Hi,
I wrote a packet sniffer on RH 9 using pcap library a year ago. Now i installed FC2 and tried to run the code there and i get this error:

Warning: Kernel filter failed: Invalid argument

when i run the program.

The program is as follows:

int main(int count, char *cmdln[])
{

pcap_t *devdes;
struct bpf_program fp;
bpf_u_int32 mask,netip;
char errbuf[PCAP_ERRBUF_SIZE];
int buffer;
int n;
int packet_captured;

if(count==1)
{
printf("Arguments Required!!");
printf("\nUsage: ./filtercapn [expression] [n]\n");
exit(0);
}


if(count==2)
n=-1; //This will put the capturing into infinite loop
else
n=atoi(cmdln[2]);

//Open device for reading
devdes=pcap_open_live("eth0",buffer,1,-1,errbuf);

if(devdes==NULL)
{
printf("\npcap_open_live(): %s\n",errbuf);
exit(0);
}

//Get the network IP address and the network mask.
pcap_lookupnet("eth0",&netip,&mask,errbuf);

//Compile the packet condition into filter program
pcap_compile(devdes,&fp,cmdln[1],0,netip);

//Set the filter program
pcap_setfilter(devdes,&fp);

//Send each packet captured according to the filter to the packet_analyser()
pcap_loop(devdes,n,(pcap_handler)packet_analyser,NULL);

return 0;
}

The error is comming in the pcap_filter() function as the kernel is not able to set the filter and gives the invalid filter error but the same filter string works fine with tcpdump.

Please help me out,

Rest is fine,

Thanks!!

Last edited by Prakhardeep; 02-01-2005 at 03:54 AM.
 
Old 08-02-2011, 07:00 AM   #2
arunns
LQ Newbie
 
Registered: May 2009
Posts: 4

Rep: Reputation: 0
Have you got any fix for this
 
Old 08-02-2011, 10:32 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Do you really have to wake up a 6 year old thread
 
Old 08-10-2011, 04:55 AM   #4
arunns
LQ Newbie
 
Registered: May 2009
Posts: 4

Rep: Reputation: 0
I have similar issue with a Redhat system kernel, was wondering whether i should have a custom kernel to fix it
 
  


Reply


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
Packet Filter to redirect a packet to a user level process akawale Linux - Networking 3 09-01-2006 12:06 PM
Problem in transferring packet capturing code fron RH9 to FC2 Prakhardeep Linux - Networking 0 02-01-2005 03:57 AM
lot of problem in capturing packet in promisc mode masood_gandhi Linux - Networking 2 11-26-2004 09:53 AM
capturing internet packet blackzone Linux - Security 3 09-15-2004 10:57 AM
Wierd error with ping WARNING: failed to install socket filter: Protocol not availabl abefroman Linux - Networking 4 03-25-2004 05:48 PM


All times are GMT -5. The time now is 09:27 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