netfilter hook function error...

Patrick Schaaf bof at bof.de
Wed Sep 21 07:51:21 CEST 2005


Hi JC,

welcome to "introduction to C". This is NOT a usual service of
this mailing list. Anyway...

> /home/jc/code/spider/spider.c:126: warning: ISO C90 forbids mixed
> declarations and code
>   print_string("Packet reached IN_HOOK.");
>   struct iphdr *my_ipheader;

In traditional C, a variable declaration (like your my_ipheader)
MUST COME BEFORE ANY OTHER CODE IN A FUNCTION (like your print_string
call)

> /home/jc/code/spider/spider.c:134: warning: passing argument 1 of
> 'print_string' discards qualifiers from pointer target type
> 	  print_string(out->name);

Not that I really know, because you have not shown your print_string()
function prototype, but I bet that you made its first argument be
a 'const char *', and out->name is a 'char *' without the 'const'.

> /home/jc/code/spider/spider.c:150: error: request for member 'nh' in
> something not a structure or union
> 	      my_ipheader = skb->nh->iph;

The compiler complains that the skb thing is not pointer to a structure.
Which is correct. It is a pointer to a pointer to a structure. So you
need to dereference it once, like '(*skb)->nh->iph'. However, I'm
not sure that nh->iph is valid in all cases. Look at other hook
functions which need the IP header.

best regards
  Patrick



More information about the netfilter-devel mailing list