summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2015-02-17 17:42:33 +0100
committerTobias Klauser <tklauser@distanz.ch>2015-02-17 17:42:33 +0100
commitdca3fbc189503465d5720b487533c6a5a8e6996e (patch)
treee90ddd8669ce7c0514df4ed79eb609acfab8b1d9
parentd0905f3cfb7831fcd823dd55675b1ba50e147a1e (diff)
llmnrd: Implement message compression for name
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--llmnr.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/llmnr.c b/llmnr.c
index a28a51e..92eb562 100644
--- a/llmnr.c
+++ b/llmnr.c
@@ -142,13 +142,14 @@ static void llmnr_respond(unsigned int ifindex, const struct llmnr_hdr *hdr,
} else
continue;
- /*
- * NAME
- *
- * TODO: Implement message compression (RFC 1035,
- * section 4.1.3)
- */
- memcpy(pkt_put(p, llmnr_hostname[0] + 2), llmnr_hostname, llmnr_hostname[0] + 2);
+ /* NAME */
+ if (i == 0)
+ memcpy(pkt_put(p, llmnr_hostname[0] + 2), llmnr_hostname, llmnr_hostname[0] + 2);
+ else {
+ /* message compression (RFC 1035, section 4.1.3) */
+ uint16_t ptr = 0xC000 | (sizeof(*hdr) + query_len);
+ pkt_put_u16(p, ntohs(ptr));
+ }
/* TYPE */
pkt_put_u16(p, htons(type));
/* CLASS */