How do I access the IP layer and TCP layer header information from the datagram received at the link layer?

Source: Internet
Author: User
The first line of SKB-> NH. iph in ip_rcp () is assigned a value before!

When the network adapter starts to receive data packets and starts to track the receiving process of a data packet to the ip_rcp () function, his first sentence is the first line in struct iphdr * IPH = SKB-> NH. IPH

However, the source code I read does not provide SKB-> NH. IPH value assignment. Some values only include SKB-> Dev, so here this SKB-> NH. IPH is useless, I think.

I don't know where he assigned a value. Let's take a look at it :)

Re: the first line of SKB-> NH. iph in ip_rcp () is assigned a value before![Re: linuxask]

2.6.9 Dev. c

Netif_receive_skb ()
SKB-> H. Raw = SKB-> NH. Raw = SKB-> data;

========================================================== =

Comments:

After the NIC receives the data, it allocates a SKB space in the receiving Letter to copy the data from the buffer on the NIC chip to the memory where SKB-> data is the starting address, in this case, SKB-> data is the MAC frame starting from the source MAC address. In this case, the other variables in the SKB structure are 0. However, the value assignment statement above sets the pointer position in H and NH to be the same as SKB-> data, that is

In this case, (Link Layer) SKB-> data points to the MAC header, IP layer header, and TCP layer header.

This means that if you want to access the variable in the H (TCP Header) at this time, you must:

Struct tcphdr * temp;

Temp = (struct tcphdr *) (char *) SKB-> Data + sizeof (struct iphdr ));

At this time, the temp Pointer Points to the TCP Header structure in the datagram-struct tcphdr.

If you want to access the IP address header information, struct iphdr * IPH = SKB-> NH. iph

In this case, IPH points to the IP header structure-struct iphdr.

After removing the MAC header from eth_trans_type, upload it to the IP layer. The function that the IP layer receives is

Ip_rcv ().

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.