mirror of
https://code.semirocket.science/wrapsix
synced 2024-11-10 08:10:59 +02:00
4bc68edce5
Written new mechanism of wrapper from scratch in C * It listens to all ICMPv6 packets (for now) and translates them to ICMPv4 ones * It can compute the checksum of the packet as well
31 lines
441 B
C
31 lines
441 B
C
unsigned short checksum(const void *_buf, int len)
|
|
{
|
|
const unsigned short *buf = _buf;
|
|
unsigned sum = 0;
|
|
|
|
while (len >= 2) {
|
|
sum += *buf ++;
|
|
|
|
if (sum & 0x80000000) {
|
|
sum = (sum & 0xffff) + (sum >> 16);
|
|
}
|
|
|
|
len -= 2;
|
|
}
|
|
|
|
if (len) {
|
|
unsigned char temp[2];
|
|
|
|
temp[0] = *(unsigned char *) buf;
|
|
temp[1] = 0;
|
|
|
|
sum += *(unsigned short *) temp;
|
|
}
|
|
|
|
while (sum >> 16) {
|
|
sum = (sum & 0xffff) + (sum >> 16);
|
|
}
|
|
|
|
return ~sum;
|
|
}
|