LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   pointer dereference problem (https://www.linuxquestions.org/questions/programming-9/pointer-dereference-problem-319235/)

cranium2004 05-02-2005 12:30 AM

pointer dereference problem
 
Hello,
I have written a kernel module that accesses skbuff and depending on whether packet is icmp or not it prints IP checksum and ICMP checksum. But I am getting
sum.c: In function `hook_func1':
sum.c:24: dereferencing pointer to incomplete type
sum.c: In function `hook_func2':
sum.c:40: dereferencing pointer to incomplete type
Whats wrong?
regards,
cranium.

*************************************************

#define __KERNEL__
#define MODULE

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>

static struct nf_hook_ops nfho1,nfho2;

unsigned int hook_func1(unsigned int hooknum,struct sk_buff **skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct sk_buff *sb = *skb;

if(sb->nh.iph->protocol==1)
{
printk(KERN_DEBUG"ICMP packet\n");
printk(KERN_DEBUG "ICMP cksum=%d,& IP cksum=%d\n",sb->h.icmph->checksum,sb->nh.iph->check);
}

return NF_ACCEPT;
}


unsigned int hook_func2(unsigned int hooknum,struct sk_buff **skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct sk_buff *sb = *skb;
if(sb->nh.iph->protocol==1)
{
printk(KERN_DEBUG"ICMP packet\n");
printk(KERN_DEBUG "ICMP cksum=%d,& IP cksum=%d\n",sb->h.icmph->checksum,sb->nh.iph->check);
}
return NF_ACCEPT;
}

static int __init init(void)
{
nfho1.hook = hook_func1;
nfho1.hooknum = NF_IP_POST_ROUTING;
nfho1.pf = PF_INET;
nfho1.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho1);

nfho2.hook = hook_func2;
nfho2.hooknum = NF_IP_PRE_ROUTING;
nfho2.pf = PF_INET;
nfho2.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho2);
return 0;
}

static void __exit fini(void)
{
nf_unregister_hook(&nfho1);
nf_unregister_hook(&nfho2);
}
module_init(init);
module_exit(fini);
MODULE_LICENSE("GPL");

*************************************************************

coolguy_iiit 05-02-2005 02:19 AM

Hi,

<code>
nfho1.hook = hook_func1;
nfho1.hooknum = NF_IP_POST_ROUTING;
nfho1.pf = PF_INET;
nfho1.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho1);

nfho2.hook = hook_func2;
nfho2.hooknum = NF_IP_PRE_ROUTING;
nfho2.pf = PF_INET;
nfho2.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho2);
return 0;
</code>

In the above code hook_fun1,2 are functions and u are calling them without "()"brackets for them so plz check them once....

hoping correct...
C000000000000L

ahwkong 05-02-2005 03:07 AM

coolguy_iiit,

They are function pointers and not supposed to have the "()" to follow them there.

ahwkong 05-02-2005 03:49 AM

cranium2004,

Seems like you need to add this line:

Code:

#include <linux/icmp.h>
at the beginning of the file...

BTW, I am using gcc 3.4.2 on Fedora Core 3

cranium2004 05-03-2005 09:34 AM

header inclusion problem
 
I am just wondering about how header files are added to other header files and source files.
Say if i added following statement in dev.c
printk(KERN_DEBUG "TCP cksum=%d",skb->h.th->check);
This works without pointer dereference.
But same is not true with
printk(KERN_DEBUG "UCP cksum=%d",skb->h.uh->check);
This gives pointer dereference error.
That mean some header file may be already added tcp.h
Now if we see skbuff.h there are no network protocol headers are defined why?
Isn't that a very important socket buffer structure? In compilation it does not give error for including tcp.h,ip.h,icmp.h...
then how those network headers are added to skbuff.h?


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