关于校验算法的学习(学习以太网时遇到的)

本文探讨了以太网和ICMP协议中使用的校验算法,包括ICMP的校验和计算以及以太网帧的CRC校验。通过分析RFC1071文档,了解到ICMP校验和的生成过程,以及它与TCP/IP中其他协议的校验和差异。同时,介绍了CRC32校验在以太网帧中的应用,确保数据传输的准确性。
摘要由CSDN通过智能技术生成

关于校验算法的学习(学习以太网时遇到的)以太网的包头还是数据都会有校验,在FPGA上实现IP核时,用的是CRC校验,然后学习ICMP协议时,也看到一种校验算法,以此学习分析一下背后原理。

一、先看看ICMP的包格式,主要是写ping命令是用到(会有一篇专门将ping的c语言实现),所以只是展示与ping命令背后的ICMP规则。
这里写图片描述
(来自维基)
对于校验的研究暂时不需要理解其他数据的意思,维基对checksum的解释为
Checksum
Error checking data, calculated from the ICMP header and data, with value 0 substituted for this field. The Internet Checksum is used, specified in RFC 1071.
首先校验的是header+data,然后如果忽略补0,规则看RFC 1071,来看看这个文档。
二、在看这个文档之前先了解几个概念:2’s complement 和 1’s complement
其实这就是两种数值的表示方法,
先看2’s complement :这就是我们日常使用的,称为2补码系统。
看看维基大神的解释:
【This system is the most common method of representing signed integers on computers.[2] An N-bit two’s-complement numeral system can represent every integer in the range −(2N − 1) to +(2N − 1 − 1) 】
那怎么编码数据呢,看看:
For example, to find the 4-bit representation of −5 (subscripts denote the base of the representation):
x = 510 therefore x = 01012
Hence, with N = 4:
x* = 2N − x = 24 − 510 = 100002 − 01012 = 10112
The calculation can be done entirely in base 10, converting to base 2 at the end:
x* = 2N − x = 24 − 510 = 1110 = 10112
就是正数是其本身,如5为0101;负数最高位置一,然后将其他低位取反,再加一。
这就是常见的计算机编码方式。
这是编码图
这里写图片描述
再看看1’s complement
Positive numbers are the same simple, binary system used by two’s complement and sign-magnitude. Negative values are the bit complement of the corresponding positive value. The largest positive value is characterized by the sign (high-order) bit being off (0) and all other bits being on (1). The smallest negat

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值