[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Question about skbuff
> what exactly is the problem here ?
The problem is I cannot correctly point to the data content
(payload) in the tcp header. And what I've pointed is the end
of skbuff.
> data addr : c7ca3d50
> tail : c7ca3d50
> end : c7ca3d50
The address is the same, so I think I should make something
wrong while I'm trying to point to the data content (payload) of
the tcp header. Could you tell me how can I calculate the
address of the data content (payload in tcp header) in skbuff.
Thanks for your reply,
your sincerely,
marco.
"Hilik Stein" <hilik@netvision.net.il> wrote:
>
> what exactly is the problem here ?
>
> -----Original Message-----
> From: owner-kernelnewbies@nl.linux.org
> [mailto:owner-kernelnewbies@nl.linux.org]On Behalf Of lam wai
wm
> Sent: Saturday, August 11, 2001 10:10 PM
> To: kernelnewbies@nl.linux.org
> Subject: Re:Question about skbuff
>
>
> Hi all,
>
> I have a problem while I try to retrieve the pointer of the
> data content (payload) in skbuff (TCP protocol)
>
> And the code is the following.
>
> #define MODULE
> #include <linux/module.h>
>
> #include <linux/init.h>
> #include <linux/config.h>
> #include <linux/kernel.h>
>
> #include <asm/types.h>
> #include <linux/string.h>//memset
> #include <linux/config.h>
> #include <linux/module.h>
> #include <linux/netfilter_ipv4.h>
> #include <linux/ip.h>
> #include <net/ip.h> //IPPROTO_TCP, IPPROTO_UDP
> #include <linux/malloc.h>
> #include <asm-i386/types.h>
>
>
> static unsigned int hkpt(unsigned int hook, struct sk_buff
> **pskb, const struct net_device *indev, const struct
net_device
> *outdev, int(*okfn)(struct sk_buff *))
> {
> struct iphdr *ip = (*pskb)->nh.iph;
> unsigned char *data = NULL;
> int src_port = 0;
> int dst_port = 0;
>
>
> if (ip->protocol == IPPROTO_TCP || ip->protocol ==
> IPPROTO_TCP) {
> struct tcphdr * tcph = (void *) ip + ip->ihl *4;
> int tcplen = (*pskb)->len - ip->ihl *4;
> data = (unsigned char *)tcph + (tcph->doff*4);
> src_port = ntohs(tcph->source);
> dst_port = ntohs(tcph->dest);
>
> if (tcplen != tcph->doff * 4)
> printk("TCP length not match\n");
> else
> printk("TCP length match..\n");
>
>
> printk("Source addr : %u.%u.%u.%u:%hu\n",
> NIPQUAD(ip->saddr), src_port);
> printk("Dest addr : %u.%u.%u.%u:%hu\n", NIPQUAD(ip-
>daddr),
> dst_port);
> printk("Length : %hu\n", ntohs(ip->tot_len));
> printk("Skb Data addr : %p\n", (*pskb)->data);
> printk("IP addr : %p\n", (*pskb)->nh.iph);
> printk("IP->ihl : %d\n", ip->ihl);
> printk("TCP addr : %p\n", tcph);
> printk("Data : %s\n", data);
> printk("data addr : %p\n", data);
> printk("tail : %p\n", (*pskb)->tail);
> printk("end : %p\n", (*pskb)->end);
> }
>
> return NF_ACCEPT;
> }
>
> static struct nf_hook_ops nf_ops = { {NULL, NULL}, hkpt,
> PF_INET, NF_IP_LOCAL_OUT, NF_IP_PRI_FILTER-1};
> static struct nf_hook_ops nf_ops2 = { {NULL, NULL}, hkpt,
> PF_INET, NF_IP_LOCAL_IN, NF_IP_PRI_FILTER-1};
>
> static int __init init(void) {
>
> nf_register_hook(&nf_ops);
> nf_register_hook(&nf_ops2);
>
> return 0;
> }
>
> static void __exit fini(void) {
> nf_unregister_hook(&nf_ops);
> nf_unregister_hook(&nf_ops2);
>
> }
>
> module_init(init);
> module_exit(fini);
>
>
>
> The result is :
> Source addr : 161.40.211.86:6190
> Dest addr : 161.40.211.86:1037
> Length : 52
> Skb Data addr : c7ca3d1c
> IP addr : c7ca3d1c
> IP->ihl : 5
> TCP addr : c7ca3d30
> Data :
> data addr : c7ca3d50
> tail : c7ca3d50
> end : c7ca3d50
>
>
> Could you correct me please.
>
> Honestly, I'm a newbie in kernel programming. And if I made
> any stupid mistakes in the above. Please point me out or give
> some advices to me that I can look for reference. Thanks
> Thanks a lot.
>
> your sincerely,
> marco.
>
>
>
>
> -
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive: http://mail.nl.linux.org/kernelnewbies/
> IRC Channel: irc.openprojects.net / #kernelnewbies
> Web Page: http://www.kernelnewbies.org/
>
>
-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
IRC Channel: irc.openprojects.net / #kernelnewbies
Web Page: http://www.kernelnewbies.org/