Pointers to both ip header & tcp header of skbuff ???

Foo Chun Choong (ccfoo@mip.ee.nus.sg)
Thu, 19 Sep 1996 19:24:01 +0800 (SGT)


Hi, what's the best way to point to the start of the ip header of an
skbuff? And also the best way to point to the start of the tcp header of
an skbuff? Both must be available at the same time.
Let's just say initially, either skb->head or skb->data is
initially pointing to the the start of the ip header of the packet. And I
want to have a pointer to the start of the ip header, and also a pointer to
the start of the tcp header of the packet.

skb->h.th or skb->h.iph is not suitable here as I don't want a copy of
the ip or tcp headers only, I want to be able to modify certain fields of the
two headers also. Furthermore, skb->h is a union, implying that you can have
only one or the other, but I need both.

What do you think of the method below:
Let's say you have a struct sk_buff * skb;, and that skb->head (or
skb->data) is pointing to the start of the ip header. Then, to get the
pointers to the ip headers and the tcp headers, all you have to do is:

(struct iphdr *) myiphdr = (struct iphdr *) skb->head;
__u32 iphdrlen = GETVALUE(myiphdr->ihl);
(struct tcphdr *) mytcphdr = (struct tcphdr *) (skb->head + iphdrlen);

Thanks in advance.
Foo Chun Choong