LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 09-20-2005, 07:13 PM   #1
jinxcat
LQ Newbie
 
Registered: Sep 2005
Posts: 9

Rep: Reputation: 0
netfilter hook function error


my hook function code, called at PRE_ROUTING

Code:
unsigned int in_hook(unsigned int hooknum,
struct sk_buff **skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
  print_string("Packet reached IN_HOOK.");

  struct iphdr *my_ipheader;
  //u32 this_address;

  if (out)
    {
      if(out->name)
	{
	  print_string("out is: ");
	  print_string(out->name);


	  // compare the out device with the list of rules
	  // TODO: replace by matches_rule()
	  if (strcmp(out->name, "eth1") == 0) 
	    {

	      print_string("packet matches rule");


	      if(skb == NULL)
		{
		  return -1;
		}
	      
	      my_ipheader = skb->nh->iph;
	      print_string("printk-ing saddr...");
	      //this_address = *my_ipheader->saddr;
	      //printk("the ip is : %d.%d.%d.%d\n",NIPQUAD(*my_ipheader->saddr));

	    }
	}
      else
	{
	  print_string("out is null");
	}
    }


  return NF_QUEUE;           /* Drop ALL packets */
}
line 150 is: my_ipheader = skb->nh->iph;

on compile, I get this error:

[root@whatever spider]# make -C /usr/src/kernels/`uname -r`-i686 SUBDIRS=$PWD modules
make: Entering directory `/usr/src/kernels/2.6.12-1.1447_FC4-i686'
CC [M] /home/jc/code/spider/spider.o
/home/jc/code/spider/spider.c: In function ‘in_hook’:
/home/jc/code/spider/spider.c:126: warning: ISO C90 forbids mixed declarations and code
/home/jc/code/spider/spider.c:134: warning: passing argument 1 of ‘print_string’ discards qualifiers from pointer target type
/home/jc/code/spider/spider.c:150: error: request for member ‘nh’ in something not a structure or union


I've seen that statement being made more than a number of times, so what am I doing wrong??

I need to change the saddr (source address) in that if to another one (basicly, NATing it). How will I commit that change to the skb and then send it back into the stack?

thanx in advance...

J
 
Old 09-23-2005, 04:24 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
I guess you want to change content of the struct of type sk_buff, right? You have a pointer to pointer, so you should write:
my_ipheader = (*skb)->nh->iph;
Of course, if I understand what you want to do correctly.
 
  


Reply



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
sizeof() function error ??? Quest101 Programming 9 03-10-2005 09:35 PM
error function in c code shams Programming 3 08-06-2004 04:00 AM
error recursive function in c shams Programming 3 07-28-2004 08:44 PM
error coding a function in c shams Mandriva 1 07-28-2004 12:09 AM
open function returns error sudheernair Programming 2 05-07-2004 11:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration