port: net: replace useless checksum with slightly more useful crc16

This commit is contained in:
fgsfds committed 2024-01-14 20:36:03 +01:00
1 parent 562e763fbd
commit 4cb99506cb
2 files changed
+12 -6

No files matched your search

+6 -3
View File
@@ -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]