diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2017-02-08 14:40:04 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2017-02-08 14:40:04 +0100 |
commit | 7f719d2f9f39dc541da85ff3cfc709058952d837 (patch) | |
tree | 420c0c40b4daa90781c672ae5ca9dac968c70129 /pkt.h | |
parent | 4a1e982b7733ac84936ff4f7d992dbea18dd0076 (diff) |
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 <tklauser@distanz.ch>
Diffstat (limited to 'pkt.h')
-rw-r--r-- | pkt.h | 15 |
1 files changed, 14 insertions, 1 deletions
@@ -1,7 +1,7 @@ /* * Packet buffer structure and utilities. * - * Copyright (C) 2015 Tobias Klauser <tklauser@distanz.ch> + * Copyright (C) 2015-2017 Tobias Klauser <tklauser@distanz.ch> * * 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 */ |