From 7f719d2f9f39dc541da85ff3cfc709058952d837 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 8 Feb 2017 14:40:04 +0100 Subject: llmnr-query: Extract LLMNR packet data in an alignment-safe way Follow commit 9bec6fb9 ("Fix misaligned memory access") for llmnr-query and extract values from the response packets in a way that doesn't cause unaligned memory access on architectures that don't support it. Signed-off-by: Tobias Klauser --- pkt.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'pkt.h') diff --git a/pkt.h b/pkt.h index bb2b717..70591b5 100644 --- a/pkt.h +++ b/pkt.h @@ -1,7 +1,7 @@ /* * Packet buffer structure and utilities. * - * Copyright (C) 2015 Tobias Klauser + * Copyright (C) 2015-2017 Tobias Klauser * * Based on pkt_buff.h from the netsniff-ng toolkit which is: * @@ -108,4 +108,17 @@ DEFINE_PKT_PUT(8) DEFINE_PKT_PUT(16) DEFINE_PKT_PUT(32) +/* extract values from struct pkt in an alignment-safe way */ +#define DEFINE_PKT_PUT_EXTRACT(__bitwidth) \ +static inline uint##__bitwidth##_t pkt_put_extract_u##__bitwidth(struct pkt *p) \ +{ \ + uint##__bitwidth##_t val; \ + memcpy(&val, pkt_put(p, sizeof(val)), sizeof(val)); \ + return val; \ +} + +DEFINE_PKT_PUT_EXTRACT(8) +DEFINE_PKT_PUT_EXTRACT(16) +DEFINE_PKT_PUT_EXTRACT(32) + #endif /* PKT_H */ -- cgit v1.2.3-54-g00ecf