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 --- llmnr-query.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'llmnr-query.c') diff --git a/llmnr-query.c b/llmnr-query.c index 5de2c6b..996723d 100644 --- a/llmnr-query.c +++ b/llmnr-query.c @@ -297,7 +297,6 @@ int main(int argc, char **argv) FD_ZERO(&rfds); FD_SET(sock, &rfds); - /* wait up to one second for a response */ tv.tv_sec = timeout_ms / 1000; tv.tv_usec = (timeout_ms % 1000) * 1000; @@ -347,10 +346,14 @@ int main(int argc, char **argv) name = (char *)pkt_put(p, nl + 1); } - type = htons(*(uint16_t *)pkt_put(p, sizeof(type))); - clss = htons(*(uint16_t *)pkt_put(p, sizeof(clss))); - ttl = htonl(*(uint32_t *)pkt_put(p, sizeof(ttl))); - addr_size = htons(*(uint16_t *)pkt_put(p, sizeof(addr_size))); + type = htons(pkt_put_extract_u16(p)); + clss = htons(pkt_put_extract_u16(p)); + + if (clss != LLMNR_CLASS_IN) + log_warn("Unexpected response class received: %d\n", clss); + + ttl = htonl(pkt_put_extract_u32(p)); + addr_size = htons(pkt_put_extract_u16(p)); if (addr_size == sizeof(struct in_addr)) { af = AF_INET; @@ -361,7 +364,8 @@ int main(int argc, char **argv) break; } - if (!inet_ntop(af, pkt_put(p, addr_size), addr, ARRAY_SIZE(addr))) + memcpy(&sst, pkt_put(p, addr_size), addr_size); + if (!inet_ntop(af, &sst, addr, ARRAY_SIZE(addr))) strncpy(addr, "", sizeof(addr)); addr[INET6_ADDRSTRLEN] = '\0'; -- cgit v1.2.3-54-g00ecf