LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-18-2012, 02:27 AM   #1
divdelleah
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Rep: Reputation: Disabled
error in ip_hdrlen in netfilter module


hi all i'm a newbie and have joined LQ for some guidance.... i'm creating a network module and trying to capture a tcpip packet and read its header but i'm getting error can someone help me resolve this...


code:
unsigned int hook_func(unsigned int hooknum, struct sk_buff **skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *))
{

struct iphdr *iph = NULL;
struct tcphdr *tcph = NULL;

if ((skb != NULL) && ((*skb)->pkt_type == PACKET_HOST) && ((*skb)->protocol == htons(ETH_P_IP))){
iph = ip_hdr((*skb)); // access ip header.


if ((iph->protocol == IPPROTO_TCP) ){
tcph = (struct tcphdr *)(skb_network_header(*skb) + ip_hdrlen(*skb));

printk(KERN_ALERT "INFO: Source IP Address: %u.\n",iph->saddr);
printk(KERN_ALERT "INFO: Destination IP Address: %u.\n",iph->daddr);
printk(KERN_ALERT "INFO: Source Port: %u.\n",tcph->source);
printk(KERN_ALERT "INFO: Destination Port: %u.\n",tcph->dest);

}
}
return NF_ACCEPT; // Tells the system to accept the packet, and process the next one.

}


error:

make -C /lib/modules/2.6.35-22-generic-pae/build M=/home/divdelleah modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.35-22-generic-pae'
CC [M] /home/divdelleah/trial3.o
/home/divdelleah/trial3.c: In function ‘hook_func’:
/home/divdelleah/trial3.c:27: error: implicit declaration of function ‘ip_hdrlen’
/home/divdelleah/trial3.c: In function ‘init_module’:
/home/divdelleah/trial3.c:49: warning: assignment from incompatible pointer type
make[2]: *** [/home/divdelleah/trial3.o] Error 1
make[1]: *** [_module_/home/divdelleah] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.35-22-generic-pae'
make: *** [all] Error 2
 
Old 02-10-2012, 12:21 AM   #2
divdelleah
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Question how to read data from the skbuff structure

i have changed the module into several subtasks to reach the final goal... i have captured the packet but i'm not able to read the data... i captured using simply using this.....

unsigned int hook_func(unsigned int hooknum, struct sk_buff *skb, const struct net_device *in, const struct net_device *out, int (*okfn)(struct sk_buff *))
{
printk(KERN_INFO "packet ACCEPTED is %s\n"); //log to var/log/messages
return NF_ACCEPT;

}



i tried to read the data from skbuff->data since the structure skbuff is which consists of the data head, tail etc.. can someone tell what is to be done...
Attached Thumbnails
Click image for larger version

Name:	skbuff.png
Views:	6
Size:	36.0 KB
ID:	9054  
 
Old 03-08-2012, 06:07 AM   #3
divdelleah
LQ Newbie
 
Registered: Jan 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
i have used sk_buff->data to start reading from the top of the data and then using skb_put(skb_buff,8)
to access next character in the buffer..... but i'm not able to set a loop to mark the ending data character....i know sk_buff->tail marks the ending of the character data.... but loop doesnt wrk with this condition instead it hangs with error....

thanks in advance
 
  


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
[SOLVED] error in ip_hdrlen in netfilter module oracle89divi22 Linux - Newbie 1 01-18-2012 04:58 AM
Netfilter module help ttthdl Programming 1 07-12-2008 06:10 PM
questions about register myself module onto netfilter linwenyuan Linux - Kernel 1 03-12-2007 07:29 PM
howto load netfilter module..? minike Slackware 2 08-13-2006 09:14 PM
Help installing custom netfilter module TySoft Linux - Networking 3 08-04-2003 05:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:15 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration