version 1.7.4.1, 2024/10/12 16:07:17
|
version 1.9, 2024/10/28 09:58:51
|
Line 281 crc16_ccitt(u_char * __restrict buf, int bufLen)
|
Line 281 crc16_ccitt(u_char * __restrict buf, int bufLen)
|
* crcIP() - Checksum in IP communication |
* crcIP() - Checksum in IP communication |
* |
* |
* @buf = Data for calculation |
* @buf = Data for calculation |
* @bufLen = Length of data | * @len = Length of data in bytes |
* return: Checksum |
* return: Checksum |
*/ |
*/ |
u_short |
u_short |
crcIP(u_char * __restrict buf, int bufLen) | crcIP(u_short* __restrict buf, int len) |
{ |
{ |
register u_int sum; | register u_long sum = 0; |
u_short last = 0, *nBuf = (u_short*) buf; | |
|
|
assert(buf); |
assert(buf); |
|
|
for (sum = 0; bufLen > 1; bufLen -= 2) | for (sum = 0; len > 1; len -= 2) |
sum += *nBuf++; | sum += *buf++; |
if (bufLen == 1) { | if (len > 0) |
*(u_char*)(&last) += *(u_char*) nBuf; | sum += ((*buf) & htons(0xFF00)); |
sum += last; | |
} | |
|
|
sum = (sum >> 16) + (sum & 0xFFFF); |
sum = (sum >> 16) + (sum & 0xFFFF); |
sum += sum >> 16; |
sum += sum >> 16; |
|
|
return (u_short) ~sum; | return (u_short) (~sum); |
} |
} |
|
|
/* |
/* |
Line 332 crcTCP(struct in_addr src, struct in_addr dst, u_char
|
Line 329 crcTCP(struct in_addr src, struct in_addr dst, u_char
|
buf.tcp_len = htons(sizeof buf.tcp); |
buf.tcp_len = htons(sizeof buf.tcp); |
memcpy(&buf.tcp, th, sizeof buf.tcp); |
memcpy(&buf.tcp, th, sizeof buf.tcp); |
|
|
return crcIP((u_char*) &buf, sizeof buf); | return crcIP((u_short*) &buf, sizeof buf); |
} |
} |
|
|
/* |
/* |
Line 362 crcUDP(struct in_addr src, struct in_addr dst, u_char
|
Line 359 crcUDP(struct in_addr src, struct in_addr dst, u_char
|
buf.udp_len = htons(sizeof buf.udp); |
buf.udp_len = htons(sizeof buf.udp); |
memcpy(&buf.udp, uh, sizeof buf.udp); |
memcpy(&buf.udp, uh, sizeof buf.udp); |
|
|
return crcIP((u_char*) &buf, sizeof buf); | return crcIP((u_short*) &buf, sizeof buf); |
} |
} |
|
|
|
|