📄 tcpcksum.c
字号:
/* tcpcksum.c - tcpcksum */#include <conf.h>#include <kernel.h>#include <network.h>/*------------------------------------------------------------------------ * tcpcksum - compute a TCP pseudo-header checksum *------------------------------------------------------------------------ */unsigned shorttcpcksum(struct ep *pep, unsigned len){ struct ip *pip = (struct ip *)pep->ep_data; struct tcp *ptcp = (struct tcp *)pip->ip_data; unsigned short *sptr; unsigned long tcksum; unsigned i; tcksum = 0; sptr = (unsigned short *) &pip->ip_src; /* 2*IP_ALEN octets = IP_ALEN shorts... */ /* they are in net order. */ for (i=0; i<IP_ALEN; ++i) tcksum += *sptr++; sptr = (unsigned short *)ptcp; tcksum += hs2net(IPT_TCP + len); if (len % 2) { ((char *)ptcp)[len] = 0; /* pad */ len += 1; /* for the following division */ } len >>= 1; /* convert to length in shorts */ for (i=0; i<len; ++i) tcksum += *sptr++; tcksum = (tcksum >> 16) + (tcksum & 0xffff); tcksum += (tcksum >> 16); return (short)(~tcksum & 0xffff);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -