Index: uspace/srv/net/dnsrsrv/dns_msg.c
===================================================================
--- uspace/srv/net/dnsrsrv/dns_msg.c	(revision d531bd6e25df500e048bf1e978ed6684fd0d65d0)
+++ uspace/srv/net/dnsrsrv/dns_msg.c	(revision 9f029aad6714344fd5426157c5a25c4c68bf1b98)
@@ -50,4 +50,10 @@
 static uint16_t dns_uint16_t_decode(uint8_t *, size_t);
 
+/** Extend dynamically allocated string with suffix.
+ *
+ * @a *dstr points to a dynamically alocated buffer containing a string.
+ * Reallocate this buffer so that concatenation of @a *dstr and @a suff can
+ * fit in and append @a suff.
+ */
 static int dns_dstr_ext(char **dstr, const char *suff)
 {
@@ -77,4 +83,14 @@
 }
 
+/** Encode DNS name.
+ *
+ * Encode DNS name or measure the size of encoded name (with @a buf NULL,
+ * and @a buf_size 0).
+ *
+ * @param name		String to encode
+ * @param buf		Buffer or NULL
+ * @param buf_size      Buffer size or 0 if @a buf is NULL
+ * @param act_size	Place to store actual encoded size
+ */
 static int dns_name_encode(char *name, uint8_t *buf, size_t buf_size,
     size_t *act_size)
@@ -135,5 +151,12 @@
 }
 
-int dns_name_decode(uint8_t *buf, size_t size, size_t boff, char **rname,
+/** Decode DNS name.
+ *
+ * @param pdu	PDU from which we are decoding
+ * @param boff	Starting offset within PDU
+ * @param rname	Place to return dynamically allocated string
+ * @param eoff	Place to store end offset (offset after last decoded byte)
+ */
+int dns_name_decode(dns_pdu_t *pdu, size_t boff, char **rname,
     size_t *eoff)
 {
@@ -151,9 +174,9 @@
 	name = NULL;
 
-	if (boff > size)
+	if (boff > pdu->size)
 		return EINVAL;
 
-	bp = buf + boff;
-	bsize = min(size - boff, DNS_NAME_MAX_SIZE);
+	bp = pdu->data + boff;
+	bsize = min(pdu->size - boff, DNS_NAME_MAX_SIZE);
 	first = true;
 	*eoff = 0;
@@ -192,8 +215,8 @@
 			--bsize;
 
-			if (ptr >= (size_t)(bp - buf)) {
+			if (ptr >= (size_t)(bp - pdu->data)) {
 				log_msg(LOG_DEFAULT, LVL_DEBUG,
 				    "Pointer- forward ref %zu, pos=%zu",
-				    ptr, (size_t)(bp - buf));
+				    ptr, (size_t)(bp - pdu->data));
 				/* Forward reference */
 				rc = EINVAL;
@@ -205,5 +228,5 @@
 			 * XXX Is assumption correct?
 			 */
-			eptr = bp - buf;
+			eptr = bp - pdu->data;
 			/*
 			 * This is where encoded name ends in terms where
@@ -212,5 +235,5 @@
 			*eoff = eptr;
 
-			bp = buf + ptr;
+			bp = pdu->data + ptr;
 			bsize = eptr - ptr;
 			continue;
@@ -245,5 +268,5 @@
 	*rname = name;
 	if (*eoff == 0)
-		*eoff = bp - buf;
+		*eoff = bp - pdu->data;
 	return EOK;
 error:
@@ -284,4 +307,14 @@
 }
 
+/** Encode DNS question.
+ *
+ * Encode DNS question or measure the size of encoded question (with @a buf NULL,
+ * and @a buf_size 0).
+ *
+ * @param question	Question to encode
+ * @param buf		Buffer or NULL
+ * @param buf_size      Buffer size or 0 if @a buf is NULL
+ * @param act_size	Place to store actual encoded size
+ */
 static int dns_question_encode(dns_question_t *question, uint8_t *buf,
     size_t buf_size, size_t *act_size)
@@ -310,5 +343,12 @@
 }
 
-static int dns_question_decode(uint8_t *buf, size_t buf_size, size_t boff,
+/** Decode DNS question.
+ *
+ * @param pdu		PDU from which we are decoding
+ * @param boff		Starting offset within PDU
+ * @param rquestion	Place to return dynamically allocated question
+ * @param eoff		Place to store end offset (offset after last decoded byte)
+ */
+static int dns_question_decode(dns_pdu_t *pdu, size_t boff,
     dns_question_t **rquestion, size_t *eoff)
 {
@@ -321,5 +361,5 @@
 		return ENOMEM;
 
-	rc = dns_name_decode(buf, buf_size, boff, &question->qname, &name_eoff);
+	rc = dns_name_decode(pdu, boff, &question->qname, &name_eoff);
 	if (rc != EOK) {
 		log_msg(LOG_DEFAULT, LVL_DEBUG, "Error decoding name");
@@ -328,12 +368,13 @@
 	}
 
-	if (name_eoff + 2 * sizeof(uint16_t) > buf_size) {
+	if (name_eoff + 2 * sizeof(uint16_t) > pdu->size) {
 		free(question);
 		return EINVAL;
 	}
 
-	question->qtype = dns_uint16_t_decode(buf + name_eoff, buf_size - name_eoff);
-	question->qclass = dns_uint16_t_decode(buf + sizeof(uint16_t) + name_eoff,
-	    buf_size - sizeof(uint16_t) - name_eoff);
+	question->qtype = dns_uint16_t_decode(pdu->data + name_eoff,
+	    pdu->size - name_eoff);
+	question->qclass = dns_uint16_t_decode(pdu->data + sizeof(uint16_t)
+	    + name_eoff, pdu->size - sizeof(uint16_t) - name_eoff);
 	*eoff = name_eoff + 2 * sizeof(uint16_t);
 
@@ -342,6 +383,13 @@
 }
 
-static int dns_rr_decode(uint8_t *buf, size_t buf_size, size_t boff,
-    dns_rr_t **retrr, size_t *eoff)
+/** Decode DNS resource record.
+ *
+ * @param pdu		PDU from which we are decoding
+ * @param boff		Starting offset within PDU
+ * @param retrr		Place to return dynamically allocated resource record
+ * @param eoff		Place to store end offset (offset after last decoded byte)
+ */
+static int dns_rr_decode(dns_pdu_t *pdu, size_t boff, dns_rr_t **retrr,
+    size_t *eoff)
 {
 	dns_rr_t *rr;
@@ -356,5 +404,5 @@
 		return ENOMEM;
 
-	rc = dns_name_decode(buf, buf_size, boff, &rr->name, &name_eoff);
+	rc = dns_name_decode(pdu, boff, &rr->name, &name_eoff);
 	if (rc != EOK) {
 		log_msg(LOG_DEFAULT, LVL_DEBUG, "Error decoding name");
@@ -363,5 +411,5 @@
 	}
 
-	if (name_eoff + 2 * sizeof(uint16_t) > buf_size) {
+	if (name_eoff + 2 * sizeof(uint16_t) > pdu->size) {
 		free(rr->name);
 		free(rr);
@@ -369,6 +417,6 @@
 	}
 
-	bp = buf + name_eoff;
-	bsz = buf_size - name_eoff;
+	bp = pdu->data + name_eoff;
+	bsz = pdu->size - name_eoff;
 
 	if (bsz < 3 * sizeof(uint16_t) + sizeof(uint32_t)) {
@@ -405,13 +453,22 @@
 
 	memcpy(rr->rdata, bp, rdlength);
-	rr->roff = bp - buf;
+	rr->roff = bp - pdu->data;
 	bp += rdlength;
 	bsz -= rdlength;
 
-	*eoff = bp - buf;
+	*eoff = bp - pdu->data;
 	*retrr = rr;
 	return EOK;
 }
 
+/** Encode DNS message.
+ *
+ * @param msg	Message
+ * @param rdata	Place to store encoded data pointer
+ * @param rsize	Place to store encoded data size
+ *
+ * @return 	EOK on success, EINVAL if message contains invalid data,
+ *		ENOMEM if out of memory
+ */
 int dns_message_encode(dns_message_t *msg, void **rdata, size_t *rsize)
 {
@@ -475,4 +532,13 @@
 }
 
+/** Decode DNS message.
+ *
+ * @param data	Encoded PDU data
+ * @param size	Encoded PDU size
+ * @param rmsg	Place to store pointer to decoded message
+ *
+ * @return	EOK on success, EINVAL if message contains invalid data,
+ * 		ENOMEM if out of memory
+ */
 int dns_message_decode(void *data, size_t size, dns_message_t **rmsg)
 {
@@ -499,14 +565,14 @@
 	/* Store a copy of raw message data for string decompression */
 
-	msg->raw = malloc(size);
-	if (msg->raw == NULL) {
-		rc = EINVAL;
+	msg->pdu.data = malloc(size);
+	if (msg->pdu.data == NULL) {
+		rc = ENOMEM;
 		goto error;
 	}
 
-	memcpy(msg->raw, data, size);
-	msg->raw_size = size;
-	log_msg(LOG_DEFAULT, LVL_NOTE, "dns_message_decode: msg->raw = %p, msg->raw_size=%zu",
-	    msg->raw, msg->raw_size);
+	memcpy(msg->pdu.data, data, size);
+	msg->pdu.size = size;
+	log_msg(LOG_DEFAULT, LVL_NOTE, "dns_message_decode: pdu->data = %p, "
+	    "pdu->size=%zu", msg->pdu.data, msg->pdu.size);
 
 	hdr = data;
@@ -528,5 +594,5 @@
 
 	for (i = 0; i < qd_count; i++) {
-		rc = dns_question_decode(data, size, doff, &question, &field_eoff);
+		rc = dns_question_decode(&msg->pdu, doff, &question, &field_eoff);
 		if (rc != EOK) {
 			log_msg(LOG_DEFAULT, LVL_DEBUG, "error decoding question");
@@ -541,5 +607,5 @@
 
 	for (i = 0; i < an_count; i++) {
-		rc = dns_rr_decode(data, size, doff, &rr, &field_eoff);
+		rc = dns_rr_decode(&msg->pdu, doff, &rr, &field_eoff);
 		if (rc != EOK) {
 			log_msg(LOG_DEFAULT, LVL_DEBUG, "Error decoding answer");
@@ -558,4 +624,5 @@
 }
 
+/** Destroy question. */
 static void dns_question_destroy(dns_question_t *question)
 {
@@ -564,4 +631,5 @@
 }
 
+/** Destroy resource record. */
 static void dns_rr_destroy(dns_rr_t *rr)
 {
@@ -571,4 +639,5 @@
 }
 
+/** Create new empty message. */
 dns_message_t *dns_message_new(void)
 {
@@ -587,4 +656,5 @@
 }
 
+/** Destroy message. */
 void dns_message_destroy(dns_message_t *msg)
 {
@@ -621,5 +691,5 @@
 	}
 
-	free(msg->raw);
+	free(msg->pdu.data);
 	free(msg);
 }
Index: uspace/srv/net/dnsrsrv/dns_msg.h
===================================================================
--- uspace/srv/net/dnsrsrv/dns_msg.h	(revision d531bd6e25df500e048bf1e978ed6684fd0d65d0)
+++ uspace/srv/net/dnsrsrv/dns_msg.h	(revision 9f029aad6714344fd5426157c5a25c4c68bf1b98)
@@ -47,5 +47,5 @@
 extern dns_message_t *dns_message_new(void);
 extern void dns_message_destroy(dns_message_t *);
-extern int dns_name_decode(uint8_t *, size_t, size_t, char **, size_t *);
+extern int dns_name_decode(dns_pdu_t *, size_t, char **, size_t *);
 extern uint32_t dns_uint32_t_decode(uint8_t *, size_t);
 
Index: uspace/srv/net/dnsrsrv/dns_type.h
===================================================================
--- uspace/srv/net/dnsrsrv/dns_type.h	(revision d531bd6e25df500e048bf1e978ed6684fd0d65d0)
+++ uspace/srv/net/dnsrsrv/dns_type.h	(revision 9f029aad6714344fd5426157c5a25c4c68bf1b98)
@@ -43,10 +43,16 @@
 #include "dns_std.h"
 
+/** Encoded DNS PDU */
+typedef struct {
+	/** Encoded PDU data */
+	uint8_t *data;
+	/** Encoded PDU size */
+	size_t size;
+} dns_pdu_t;
+
 /** DNS message */
 typedef struct {
-	/** Raw message data */
-	void *raw;
-	/** Raw message size */
-	size_t raw_size;
+	/* Encoded PDU */
+	dns_pdu_t pdu;
 
 	/** Identifier */
Index: uspace/srv/net/dnsrsrv/query.c
===================================================================
--- uspace/srv/net/dnsrsrv/query.c	(revision d531bd6e25df500e048bf1e978ed6684fd0d65d0)
+++ uspace/srv/net/dnsrsrv/query.c	(revision 9f029aad6714344fd5426157c5a25c4c68bf1b98)
@@ -97,7 +97,6 @@
 		    str_cmp(rr->name, sname) == 0) {
 			log_msg(LOG_DEFAULT, LVL_DEBUG, "decode cname (%p, %zu, %zu)",
-			    amsg->raw, amsg->raw_size, rr->roff);
-			rc = dns_name_decode(amsg->raw, amsg->raw_size, rr->roff,
-			    &cname, &eoff);
+			    amsg->pdu.data, amsg->pdu.size, rr->roff);
+			rc = dns_name_decode(&amsg->pdu, rr->roff, &cname, &eoff);
 			if (rc != EOK) {
 				log_msg(LOG_DEFAULT, LVL_DEBUG,
