X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=metacube2.cpp;h=666355d16867524422b72de72853723725554e88;hp=9473dced414b62fd5d93548d7d81b43745b81143;hb=HEAD;hpb=bfc1a54cf84bb1784c14bd4f5acbb500460e35b5 diff --git a/metacube2.cpp b/metacube2.cpp index 9473dce..666355d 100644 --- a/metacube2.cpp +++ b/metacube2.cpp @@ -7,6 +7,8 @@ #include "metacube2.h" +#include + /* * https://www.ece.cmu.edu/~koopman/pubs/KoopmanCRCWebinar9May2012.pdf * recommends this for messages as short as ours (see table at page 34). @@ -24,7 +26,7 @@ uint16_t metacube2_compute_crc(const struct metacube2_block_header *hdr) uint16_t crc = METACUBE2_CRC_START; int i, j; - for (i = 0; i < data_len; ++i) { + for (i = 0; i < data_len; ++i) { uint8_t c = data[i]; for (j = 0; j < 8; j++) { int bit = crc & 0x8000; @@ -44,5 +46,14 @@ uint16_t metacube2_compute_crc(const struct metacube2_block_header *hdr) } } + /* + * Invert the checksum for metadata packets, so that clients that + * don't understand metadata will ignore it as broken. There will + * probably be logging, but apart from that, it's harmless. + */ + if (ntohs(hdr->flags) & METACUBE_FLAGS_METADATA) { + crc ^= 0xffff; + } + return crc; }