LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   error in ip_hdrlen in netfilter module (https://www.linuxquestions.org/questions/linux-newbie-8/error-in-ip_hdrlen-in-netfilter-module-924364/)

divdelleah 01-18-2012 01:27 AM

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

divdelleah 02-09-2012 11:21 PM

how to read data from the skbuff structure
 
1 Attachment(s)
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...

divdelleah 03-08-2012 05:07 AM

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


All times are GMT -5. The time now is 10:25 PM.