Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 615781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:15:24+00:00 2026-05-13T18:15:24+00:00

I have a small function that tries to print the fragment offset of an

  • 0

I have a small function that tries to print the fragment offset of an IP header.

ParseIpHeader(unsigned char *packet, int len)
{
    struct ethhdr *ethernet_header;
    struct iphdr *ip_header;

    /* First Check if the packet contains an IP header using
       the Ethernet header                                */

    ethernet_header = (struct ethhdr *)packet;

    if(ntohs(ethernet_header->h_proto) == ETH_P_IP)
    {
            /* The IP header is after the Ethernet header  */

            if(len >= (sizeof(struct ethhdr) + sizeof(struct iphdr)))
            {
                    ip_header = (struct iphdr*)(packet + sizeof(struct ethhdr));

                    /* print the Source and Destination IP address */

                    //printf("Dest IP address: %s\n", inet_ntoa(ip_header->daddr));
                    //printf("Source IP address: %s\n", inet_ntoa(ip_header->saddr));
                    printf("protocol %d\n", ip_header->protocol);
                    printf("Fragment off is %d\n", ntohs(ip_header->frag_off));

            }

}

My packets are TCP (the ip_header->protocol is always 6. the problem is that the frag_off
is always 16384. I am sending a lot of data, why the frag_off is always constant?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:15:25+00:00Added an answer on May 13, 2026 at 6:15 pm

    Fragment offset is shared with flags. You have the “DF” (don’t fragment) bit set.

    Which gives you 16384 for the entire 16-bit field, given the fragment offset of 0.

    Take a look at the http://www.ietf.org/rfc/rfc791.txt, starting from page 10.

    EDIT:

    The DF bit in the TCP segments that you are receiving is set by the remote side, to perform the Path MTU discovery – in a nutshell, to try to avoid the fragmentation.
    In this case the sending side learns the biggest MTU that the overall path can handle, and chops the TCP segments such that they did not exceed it after the encapsulation into IP.

    EDIT2:

    regarding the use of recvfrom() and TCP: TCP is a connection-oriented protocol, and all of the segmentation/fragmentation details are already handled by it (fragmentation is obviously handled by the lower layer, IP) – so you do not need to deal with it. Anything you write() on the sending side will be eventually read() on the other side – possibly not in the same chunks though – i.e. two 4K writes may result in a single 8K read sometimes, and sometimes in two 4K reads – depending on the behaviour of the media inbetween concerning reordering/losses.

    IP Fragmentation and reassembly is handled transparently by the operating system, so you do not need to worry about it, same as about packets out of order, etc. (you will just see the decreased performance as the effect on the application).

    One good read I could recommend is this one: UNIX network programming. Given Steven’s involvement with the TCP, it’s a good book no matter which OS you use.

    EDIT3:

    And if you are doing something to be a “man in the middle” (assuming you have good and legitimate reasons for doing so 🙂 – then you can assess the upcoming work by looking at the prior art: chaosreader (one-script approach that works on pcap files, but adaptable to something else), or LibNIDS – that does emulate the IP defragmentation and the TCP stream reassembly; and maybe just reuse them for your purposes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small sample function: #define VALUE 0 int test(unsigned char x) {
i have small function that running on condintion, if text box value is not
In an access database I have a small function that is called on startup
I have a small C# function that takes any generic SQLDataReader and converts it
I have a strongly recursive function, that creates a (very small) std::multimap locally for
I have a small JavaScript function that (among other things) retrieves the ID of
I have functions that contribute to small parts of a figure generation. I'm trying
I have a small javascript function which opens an url in a new tab:
i have build a small function whose work to get value in alert box
I have written a small function, which uses ElementTree to parse xml file,but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.