计算机网络计算UDP校验和
by Randall · 14 Jan 2026·c-hrqwmbbi / ji-suan-ji-wang-luo / study
← /u/randall/blog
by Randall · 14 Jan 2026·c-hrqwmbbi / ji-suan-ji-wang-luo / study

源IP地址:123.151.78.47(0x7b97, 0x4e2f)
目的IP地址:10.66.149.117(0xa42, 0x9575)
源端口:8000(0x1f40)
目的端口:4006(0xfa6)
UDP长度:39(0x27)
数据:0x023a, 0x2700, 0xcd27, 0x6784, 0xc57e, 0xf400, 0x0000, 0x5ad0, 0xc585, 0xf70f, 0xf03a, 0x71fa, 0x294d, 0xe354, 0x2bdf, 0x0300 校验和:0x9ab9
// C语言计算校验和
#include<stdio.h>
unsigned short checksum(unsigned short *buf,int nword){
unsigned long sum;
for(sum=0;nword>0;nword--){
sum += *buf++;
sum = (sum>>16) +
