diff options
author | Ian Moffett <ian@osmora.org> | 2025-09-25 14:57:59 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-09-25 14:59:19 -0400 |
commit | c9dc332811b0f98799411de6cbed66957c184188 (patch) | |
tree | 63438a387b5d80299cf2347ed4ba49c2e75402c4 /src | |
parent | afcdcf6ae6d95eb828733994c7de30f8ab095dcc (diff) |
dgram: Put CRC32 at the end of the datagram hdr
This makes it easier to compute the checksum as we can simply subtract
from the length of the header
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/dgram/dgram_subr.c | 2 | ||||
-rw-r--r-- | src/include/dgram.h | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/dgram/dgram_subr.c b/src/dgram/dgram_subr.c index d79386f..fda8178 100644 --- a/src/dgram/dgram_subr.c +++ b/src/dgram/dgram_subr.c @@ -44,6 +44,6 @@ dgram_load(uint16_t length, uint8_t port, struct onet_dgram *res) res->length = (length >> 8) & 0xFF; res->length |= (length & 0xFF) << 8; res->port = port; - res->crc32 = crc32(res, sizeof(*res)); + res->crc32 = crc32(res, sizeof(*res) - sizeof(res->crc32)); return 0; } diff --git a/src/include/dgram.h b/src/include/dgram.h index 0f798ee..31f7c03 100644 --- a/src/include/dgram.h +++ b/src/include/dgram.h @@ -40,18 +40,18 @@ typedef tx_len_t rx_len_t; /* * Represents an ONET datagram * - * @crc32: CRC32 checksum of data + header * @length: Packet length in bytes * @reserved: Reserved for future use * @reserved1: Reserved for future use * @port: Datagram port number to send on + * @crc32: CRC32 checksum of data + header */ struct onet_dgram { - uint32_t crc32; uint16_t length; uint16_t reserved; uint16_t reserved1; uint8_t port; + uint32_t crc32; } __attribute__((packed)); /* |