From 0a6cbadea08d824e26838a18bb75745c78f27461 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 25 Jul 2013 18:30:51 +0100 Subject: [PATCH] site: use unaligned.h's functions, not pointer cast and ntohl Switch site.c to using unaligned.h's functions for accessing multi-byte values inside messages. There were a few places where this construction was used: something = ntohl(*(uint32_t*)(buf->start + offset)); It is much clearer to use this equivalent construction: something = get_uint32(buf->start + offset); Also the packet's message type was extracted from the message using get_uint32 and then put through ntohl. This is, of course, wrong. Currently all the message type codes are palindromes, so it doesn't matter in practice. Fix it anyway. Signed-off-by: Ian Jackson --- site.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/site.c b/site.c index 98bd6b6..5b071b2 100644 --- a/site.c +++ b/site.c @@ -859,9 +859,9 @@ static bool_t process_msg0(struct site *st, struct buffer_if *msg0, static void dump_packet(struct site *st, struct buffer_if *buf, const struct comm_addr *addr, bool_t incoming) { - uint32_t dest=ntohl(*(uint32_t *)buf->start); - uint32_t source=ntohl(*(uint32_t *)(buf->start+4)); - uint32_t msgtype=ntohl(*(uint32_t *)(buf->start+8)); + uint32_t dest=get_uint32(buf->start); + uint32_t source=get_uint32(buf->start+4); + uint32_t msgtype=get_uint32(buf->start+8); if (st->log_events & LOG_DUMP) slilog(st->log,M_DEBUG,"%s: %s: %08x<-%08x: %08x:", @@ -1268,8 +1268,8 @@ static bool_t site_incoming(void *sst, struct buffer_if *buf, if (buf->size < 12) return False; - uint32_t msgtype=ntohl(get_uint32(buf->start+8)); - uint32_t dest=ntohl(*(uint32_t *)buf->start); + uint32_t dest=get_uint32(buf->start); + uint32_t msgtype=get_uint32(buf->start+8); struct msg named_msg; if (msgtype==LABEL_MSG1) { -- 2.30.2