LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 05-02-2005, 12:30 AM   #1
cranium2004
Member
 
Registered: Feb 2004
Distribution: FC4,RHEL4
Posts: 223

Rep: Reputation: 30
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");

*************************************************************
 
Old 05-02-2005, 02:19 AM   #2
coolguy_iiit
Member
 
Registered: Aug 2004
Posts: 51

Rep: Reputation: 15
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
 
Old 05-02-2005, 03:07 AM   #3
ahwkong
Member
 
Registered: Aug 2004
Location: Australia
Distribution: Fedora
Posts: 282

Rep: Reputation: 30
coolguy_iiit,

They are function pointers and not supposed to have the "()" to follow them there.
 
Old 05-02-2005, 03:49 AM   #4
ahwkong
Member
 
Registered: Aug 2004
Location: Australia
Distribution: Fedora
Posts: 282

Rep: Reputation: 30
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
 
Old 05-03-2005, 09:34 AM   #5
cranium2004
Member
 
Registered: Feb 2004
Distribution: FC4,RHEL4
Posts: 223

Original Poster
Rep: Reputation: 30
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?
 
  


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
Kernel Null Pointer Dereference Error Another Round of Issues Smillie Slackware 6 08-04-2005 04:55 PM
Kernel Null Pointer Dereference Error Smillie Slackware 3 04-27-2005 05:21 PM
NULL pointer dereference error Mercman2000 Linux - General 1 03-21-2005 09:36 PM
NIC, unable to handle kernel NULL pointer dereference blo1005 Linux - Networking 1 06-30-2004 03:23 AM
Unable to handle kernel NULL pointer dereference.... kadaver Slackware 2 12-19-2003 07:46 AM


All times are GMT -5. The time now is 07:32 PM.

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