MCPcopy Create free account
hub / github.com/F-Stack/f-stack / TcpChecksum

Function TcpChecksum

freebsd/netinet/libalias/alias_util.c:107–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105}
106
107u_short
108TcpChecksum(struct ip *pip)
109{
110 u_short *ptr;
111 struct tcphdr *tc;
112 int nhdr, ntcp, nbytes;
113 int sum, oddbyte;
114
115 nhdr = pip->ip_hl << 2;
116 ntcp = ntohs(pip->ip_len) - nhdr;
117
118 tc = (struct tcphdr *)ip_next(pip);
119 ptr = (u_short *) tc;
120
121/* Add up TCP header and data */
122 nbytes = ntcp;
123 sum = 0;
124 while (nbytes > 1) {
125 sum += *ptr++;
126 nbytes -= 2;
127 }
128 if (nbytes == 1) {
129 oddbyte = 0;
130 ((u_char *) & oddbyte)[0] = *(u_char *) ptr;
131 ((u_char *) & oddbyte)[1] = 0;
132 sum += oddbyte;
133 }
134/* "Pseudo-header" data */
135 ptr = (void *)&pip->ip_dst;
136 sum += *ptr++;
137 sum += *ptr;
138 ptr = (void *)&pip->ip_src;
139 sum += *ptr++;
140 sum += *ptr;
141 sum += htons((u_short) ntcp);
142 sum += htons((u_short) pip->ip_p);
143
144/* Roll over carry bits */
145 sum = (sum >> 16) + (sum & 0xffff);
146 sum += (sum >> 16);
147
148/* Return checksum */
149 return ((u_short) ~ sum);
150}
151#endif /* not _KERNEL */
152
153void

Callers 9

NewFtpMessageFunction · 0.85
AliasHandleIrcOutFunction · 0.85
alias_rtsp_outFunction · 0.85
alias_pna_outFunction · 0.85
ProxyEncodeTcpStreamFunction · 0.85
ProxyEncodeIpHeaderFunction · 0.85
alias_skinny_reg_msgFunction · 0.85
alias_skinny_port_msgFunction · 0.85

Calls 1

ip_nextFunction · 0.85

Tested by

no test coverage detected