summaryrefslogtreecommitdiff
path: root/llmnr-query.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2017-02-08 14:40:04 +0100
committerTobias Klauser <tklauser@distanz.ch>2017-02-08 14:40:04 +0100
commit7f719d2f9f39dc541da85ff3cfc709058952d837 (patch)
tree420c0c40b4daa90781c672ae5ca9dac968c70129 /llmnr-query.c
parent4a1e982b7733ac84936ff4f7d992dbea18dd0076 (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 'llmnr-query.c')
-rw-r--r--llmnr-query.c16
1 files changed, 10 insertions, 6 deletions
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, "<invalid>", sizeof(addr));
addr[INET6_ADDRSTRLEN] = '\0';