scapy icon indicating copy to clipboard operation
scapy copied to clipboard

The padding and CRC of Ethernet II frames are included in the TCP length

Open yafeng-Soong opened this issue 3 years ago • 0 comments

Brief description

The padding and CRC of Ethernet II frames are included in the TCP length, when I tried to get the length of TCP payload with the following code.

with PcapNgReader(pcap_path) as preader:
        for p in preader:
            ip = p.payload
            if not isinstance(ip, scapy.layers.inet.IP):
                continue
            tcp = ip.payload
            p_len = len(tcp.payload) # There is a problem with the value of p_len

Ethernet II specifies that the minimum amount of data is 46 bytes. If it does not meet the requirements, 0 bytes will be filled. Therefore, when the TCP payload is length 0, there will be 6 bytes of padding, and 4 bytes of CRC check code.Here, the value of p_len is 10 instead of the 0.

Scapy version

2.4.5

Python version

3.10

Operating system

Windows 11

Additional environment information

No response

How to reproduce

Useing following code to parse the report.pcapng file in related resources

with PcapNgReader(pcap_path) as preader:
    for p in preader:
        ip = p.payload
        if not isinstance(ip, scapy.layers.inet.IP):
            continue
        tcp = ip.payload
        p_len = len(tcp.payload)
        print(p_len)

Actual result

10

Expected result

0

Related resources

report.zip

yafeng-Soong avatar Sep 09 '22 08:09 yafeng-Soong