【问题标题】:How are these values calculated in Python Scapy?在 Python Scapy 中这些值是如何计算的?
【发布时间】:2022-10-07 23:51:42
【问题描述】:

我很好奇chksum 的值以及它是如何计算的。

###[ IP ]### 
     chksum    = 0x95d3

###[ UDP ]### 
     chksum    = 0x1a77

chksum=0x1a77chksum=0x95d3 是什么,它们在 python Scapy 中是如何计算的?我需要对这些值进行一些解释。

【问题讨论】:

    标签: networking python ip


    【解决方案1】:

    IPTCPUDP checksums 的机制类似。

    来自RFC 791 page 14(IP):

    Header Checksum:  16 bits
    
    A checksum on the header only.  Since some header fields change
    (e.g., time to live), this is recomputed and verified at each point
    that the internet header is processed.
    
    The checksum algorithm is:
    
      The checksum field is the 16 bit one's complement of the one's
      complement sum of all 16 bit words in the header.  For purposes of
      computing the checksum, the value of the checksum field is zero.
    
    This is a simple to compute checksum and experimental evidence
    indicates it is adequate, but it is provisional and may be replaced
    by a CRC procedure, depending on further experience.
    

    来自RFC 768 page 2 (UDP):

    Checksum is the 16-bit one's complement of the one's complement sum of
    a pseudo header of information from the IP header, the UDP header, and
    the data,  padded  with zero octets  at the end (if  necessary)  to 
    make  a multiple of two octets.
    

    来自RFC 793 page 16 (TCP):

    Checksum:  16 bits
    
    The checksum field is the 16 bit one's complement of the one's
    complement sum of all 16 bit words in the header and text.  If a
    segment contains an odd number of header and text octets to be
    checksummed, the last octet is padded on the right with zeros to
    form a 16 bit word for checksum purposes.  The pad is not
    transmitted as part of the segment.  While computing the checksum,
    the checksum field itself is replaced with zeros.
    

    校验和的有效计算在RFC 1071“计算互联网校验和”中讨论。它有些涉及,但其中包含理论背后的数学和一些代码实现。

    【讨论】:

    • 我必须知道这一切吗?还是没有必要?
    猜你喜欢
    • 2016-04-29
    • 2011-03-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-14
    • 2021-11-09
    • 2016-04-08
    • 2019-11-08
    • 2013-12-18
    相关资源
    最近更新 更多