forked from Ports/perfect_dark
port: net: replace useless checksum with slightly more useful crc16
This commit is contained in:
1 parent
562e763fbd
commit
4cb99506cb
2 files changed
+12
-6
No files matched your search
+6
-3
@@ -368,11 +368,14 @@ static void netServerQueryResponse(ENetAddress *address)
|
||||
|
||||
// calculate and rewrite checksum
|
||||
buf.wp = ebuf.dataLength - sizeof(u16);
|
||||
u32 chk = 1;
|
||||
u16 crc = 0xFFFF;
|
||||
u16 x;
|
||||
for (u32 i = 0; i < buf.wp; ++i) {
|
||||
chk = (chk + buf.data[i]) % 65521;
|
||||
x = crc >> 8 ^ buf.data[i];
|
||||
x ^= x >> 4;
|
||||
crc += (crc << 8) ^ (x << 12) ^ (x << 5) ^ x;
|
||||
}
|
||||
netbufWriteU16(&buf, chk);
|
||||
netbufWriteU16(&buf, crc);
|
||||
|
||||
enet_socket_send(g_NetHost->socket, address, &ebuf, 1);
|
||||
}
|
||||
|
||||
+6
-3
@@ -9,10 +9,13 @@ QUERY_MAGIC = b"PDQM\x01"
|
||||
MAX_WAIT = 5.0
|
||||
|
||||
def checksum(data):
|
||||
chk = 1
|
||||
crc = 0xFFFF
|
||||
for b in data[:-2]:
|
||||
chk = (chk + b) % 65521
|
||||
return chk
|
||||
x = crc >> 8 ^ b
|
||||
x ^= x >> 4
|
||||
crc += (crc << 8) ^ (x << 12) ^ (x << 5) ^ x
|
||||
crc &= 0xFFFF
|
||||
return crc
|
||||
|
||||
def eat_string(data):
|
||||
strlen = struct.unpack_from("<H", data)[0]
|
||||
|
||||
Reference in new issue
Block a user