计算校验和 校验和算法描述:为保证网络上传输的数据的可靠性,在许多协议中都设置了校验和项,例如:IPv4、ICMPv4、IGMPV4、ICMPv6、UDP和TCP 等等。计算这些校验和的算法称为网际校验和算法,简单来说就是:把被校验的数据16位进行累加,然后取反码,若数据字节长度为奇数,则数据尾部补一个字节的0以凑成偶数。 由于从输入文件读入的数据不能直接满足计算校验和的条件,所以首先对从文件读入缓冲区的数据进行预处理,即读入缓冲区时忽略空格。由于累加是按16位进行的,所以每次从缓冲区中读出4个字符,并将字符转换成对应的16进制数字,如此依次累加,直至数据全部读完。 还有一种情况,即如果数据长度为奇数个字节,则需要判断,并补0累加。程序中利用的是缓冲区长度计数器i和当前读取到计数器j判断数据长度是否为奇数。即如果数据长度为偶数,则读完数据时当前读取到计数器j的值应与缓冲区长度i相等,而如果数据长度为奇数,则读完数据时,当前读取到计数器j>缓冲区长度i,此时需将缓冲区中剩余的两个字符读出,并补0,转换成相应16进制数以后参与累加。 当累加结束后,将累加和的16位以上数据位移下再进行一次累加,并对最后累加和取反即得所求校验和。 -calculated checksum checksum algorithm Description : To ensure the network transmission of data reliability, in many of the agreements are set up and calibration, for example : IPv4, ICMPv4, IGMPV4, ICMPv6. UDP and TCP so on. Calculating checksum algorithm called the Internet checksum algorithm, the simple answer is : as has been the calibration data for 16 cumulative, and then take the anti-code, if the data byte length of the odd, data will make up the tail of a 0 byte to make up even. As the input file is read into the data can not be directly calculated checksum meet the conditions, So, the first right from the document read into the buffer data preprocessing, read into the buffer zone that is overlooked spaces. As the cumulative basis for the 16, so every time from the buffer read out 下载
p2p源程序 apr6008 c mpeg-2 解码器源码 神经网络 图像 matlab c 编写蒙特卡洛 opnet aodv 协议 socket5 网上考试系统java jsp 锁相环matlab仿真 tab控件下载 vb编写的pid控制程序 vc遗传算法解决tsp问题 matlab 形态学边缘检测函数 主成分分析法计算 vc源代码,连续画线 linux arp程序 源代码 网页发送邮件代码 vc http断点续传 vc 记事本 vc 鼠标 源码 skype 源码 pb 自动升级 matlab 源代码 神经网络 socket5代理 电动车控制器 pic源程序 基于java的ftp 存储过程process 流水灯c程序设计 涡轮特性 短信群发代码 声卡 声音大小 vc turbo c串口通信编程实践 源代码 下载 vb编写打印程序 linux spi 驱动 vc 工业自动化 数据结构大作业源程序 javascript 播放器 delphi病毒源代码 mapinfo地图 文件大小 深圳大学dsp 线性调频 源码 元胞自动机程序代码 注册表内显示隐藏 主元分析法的matlab代码 lr文法 caj view ace 多线程 文件 上传 最小二乘法 c uctcpip c socket 服务器 代码