#include "uip.h" #include "uip_arch.h" #define BUF ((uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) #define IP_PROTO_TCP 6 /*-----------------------------------------------------------------------------------*/ void uip_add32(u8_t *op32, u16_t op16) { uip_acc32[3] = op32[3] + (op16 & 0xff); uip_acc32[2] = op32[2] + (op16 >> 8); uip_acc32[1] = op32[1]; uip_acc32[0] = op32[0]; if(uip_acc32[2] < (op16 >> 8)) { ++uip_acc32[1]; if(uip_acc32[1] == 0) { ++uip_acc32[0]; } } if(uip_acc32[3] < (op16 & 0xff)) { ++uip_acc32[2]; if(uip_acc32[2] == 0) { ++uip_acc32[1]; if(uip_acc32[1] == 0) { ++uip_acc32[0]; } } } } /*-----------------------------------------------------------------------------------*/ u16_t uip_chksum(u16_t *sdata, u16_t len) { u16_t acc; for(acc = 0; len > 1; len -= 2) { acc += *sdata; if(acc < *sdata) { /* Overflow, so we add the carry to acc (i.e., increase by one). */ ++acc; } ++sdata; } /* add up any odd byte */ if(len == 1) { acc += htons(((u16_t)(*(u8_t *)sdata)) << 8); if(acc < htons(((u16_t)(*(u8_t *)sdata)) << 8)) { ++acc; } } return acc; } /*-----------------------------------------------------------------------------------*/ u16_t uip_ipchksum(void) { return uip_chksum((u16_t *)&uip_buf[UIP_LLH_LEN], 20); } /*-----------------------------------------------------------------------------------*/ u16_t uip_tcpchksum(void) { u16_t hsum, sum; /* Compute the checksum of the TCP header. */ hsum = uip_chksum((u16_t *)&uip_buf[20 + UIP_LLH_LEN], 20); /* Compute the checksum of the data in the TCP packet and add it to the TCP header checksum. */ sum = uip_chksum((u16_t *)uip_appdata, (u16_t)(((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 40))); if((sum += hsum) < hsum) { ++sum; } if((sum += BUF->srcipaddr[0]) < BUF->srcipaddr[0]) { ++sum; } if((sum += BUF->srcipaddr[1]) < BUF->srcipaddr[1]) { ++sum; } if((sum += BUF->destipaddr[0]) < BUF->destipaddr[0]) { ++sum; } if((sum += BUF->destipaddr[1]) < BUF->destipaddr[1]) { ++sum; } if((sum += (u16_t)htons((u16_t)IP_PROTO_TCP)) < (u16_t)htons((u16_t)IP_PROTO_TCP)) { ++sum; } hsum = (u16_t)htons((((u16_t)(BUF->len[0]) << 8) + BUF->len[1]) - 20); if((sum += hsum) < hsum) { ++sum; } return sum; } /*-----------------------------------------------------------------------------------*/我看里面的uip_chksum(u16_t *sdata, u16_t len)为什么那个len是 -2 呢?不是一个一个的?
收藏0 举报
查看全部评分
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
人才类勋章
时间类勋章
发帖类勋章
23
344
3
扫码关注 21ic 官方微信
扫码关注嵌入式微处理器
扫码关注电源系统设计
扫码关注21ic项目外包
扫码浏览21ic手机版
本站介绍 | 申请友情链接 | 欢迎投稿 | 隐私声明 | 广告业务 | 网站地图 | 联系我们 | 诚聘英才
京公网安备 11010802024343号