Minimum size of the data part of TCP segment

119

Solution 1

The minimum frame size for Ethernet is dictated at 64 bytes (as also described in your references).

DMAC + SMAC + EtherType + Payload + CRC  
 6   +  6   +     2     +    46   +  4  = 64

At layer 4 (TCP or UDP) the 'length' covers the layer 4 header and it is tracked in the IP header.
This means, for UDP the minimum expected is 8 bytes (for its header). And, for TCP it is 20 bytes (the minimum TCP header).

The part you seem to be missing starts now.
While the Ethernet data length is required to be a minimum of 46 bytes, the IP length does not have to be 46-20 bytes. It can be much lesser than that.

So, if we had a 8 byte UDP packet with no data at all, its IP length would be 20+8 but the Ethernet payload length will still be 46 bytes. What happens to the 18 byte hole? It is padded to make the Ethernet frame on wire 64 bytes (for reasons you already know).

[Eth: DMAC + SMAC + EtherType + [IP: Hdr + [UDP: Hdr + 0data ]] + PAD + CRC ]

Bottomline: What you refer as the application data size has no minimum expectations based on this 64 byte Ethernet requirement. The PAD will compensate for any differences.

Solution 2

Short Answer:
The minimum length of the data part of a TCP segment is zero. The minimum length of the data part of a UDP datagram is zero.

If an IP stack needs to pass a less-than-46-byte datagram to Ethernet, Ethernet pads it out to 46 bytes by adding padding bytes. The IP header has its own length field (as do the TCP and UDP headers), so those protocols never get confused and try to interpret the link-layer padding as part of their own payloads.

Additional Information:
Ethernet is just one of many, many data link layer protocols IP can run on. Ethernet has a 64 byte minimum packet length for legacy technical reasons (so that "collisions" could be reliably detected on max-diameter Ethernet networks, back when Ethernet networks were CSMA/CD and could have collisions — modern Ethernet networks use switches everywhere and are full-duplex on all segments, so CSMA/CD and collisions are pretty much a thing of the past).

Because we so often use IP over Ethernet, it's easy to forget that Ethernet and IP are two separate network technologies created by two separate institutions. Ethernet, standardized by the IEEE (Institute of Electrical and Electronics Engineers) was designed to handle an unknown number of Network (layer 3) protocols besides IP, and IP, created by the IETF (Internet Engineering Task Force) was designed to work on an unknown number of Data Link (layer 2) protocols besides Ethernet. IP does not change its minimum or its maximum datagram size just because of one popular link-layer protocol. If the link layer protocol doesn't like a tiny datagram it gets, it has to pad it. And in the opposite case, if IP doesn't like the MTU the current data link offers, it has to fragment.

Share:
119

Related videos on Youtube

user2303321
Author by

user2303321

Updated on September 18, 2022

Comments

  • user2303321
    user2303321 over 1 year

    I'm trying to have PHP run a python script that runs matlab code. I want the matlab output (the value 7.5) to come back to PHP and output to the browser.

    When I run my python script from the terminal, it successfully runs the matlab code.

    When I run the python script from PHP, it does not output the matlab result to the browser. I should have "7.5" appear in the browser.

    If I change the python code to just print something, then I get the correct output in the browser.

    I suspect that I'm having an issue with permission, but I've given all of the files RWX permission to all.

    HTML code

    <form action='ts.php' method='POST' enctype='multipart/form-data'>
    <input type='submit' name='matlab_plot' value='Plot in Matlab'>
    </form>
    

    PHP code

    <?php 
    $command = escapeshellcmd('/Applications/XAMPP/xamppfiles/htdocs/CS85_Project/troubleshoot/ts.py 2>&1');
    $output = shell_exec($command);
    echo $output;
    ?>
    

    Python code

    #!/usr/bin/python
    import matlab.engine
    eng = matlab.engine.start_matlab()
    eng.triarea(nargout=0)
    a = eng.workspace['a']
    print a
    

    Matlab code

    b = 5;
    h = 3;
    a = 0.5*(b.* h);
    

    EDIT: I have found that the python script stops running at eng = matlab.engine.start_matlab() when called from PHP. I still don't have a solution to this problem, but my question is: why can't PHP run this python function?

  • Adrian
    Adrian about 12 years
    So, to make a minimum 64 bytes Ethernet Frame -(18 bytes Ethernet header/trailer + 20 bytes IP header + 20 (or 8) bytes Transport layer header + xxxx bytes of padding is used. I was confused with the statement "IP packet should be minimum of 64 bytes" made by many people, which is not true. Actually "an Ethernet frame should be minimum of 64 bytes" is correct. Am I right?