Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ boot/Makefile.common	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -112,5 +112,5 @@
 	$(USPACE_PATH)/srv/hid/remcons/remcons \
 	$(USPACE_PATH)/srv/hid/isdv4_tablet/isdv4_tablet \
-	$(USPACE_PATH)/srv/net/dnsres/dnsres \
+	$(USPACE_PATH)/srv/net/dnsrsrv/dnsrsrv \
 	$(USPACE_PATH)/srv/net/ethip/ethip \
 	$(USPACE_PATH)/srv/net/inetsrv/inetsrv \
@@ -166,4 +166,5 @@
 	$(USPACE_PATH)/app/dltest2/dltest2 \
 	$(USPACE_PATH)/app/dload/dload \
+	$(USPACE_PATH)/app/dnsres/dnsres \
 	$(USPACE_PATH)/app/edit/edit \
 	$(USPACE_PATH)/app/inet/inet \
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ uspace/Makefile	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -39,4 +39,5 @@
 	app/bnchmark \
 	app/devctl \
+	app/dnsres \
 	app/edit \
 	app/getterm \
@@ -82,5 +83,5 @@
 	srv/devman \
 	srv/loader \
-	srv/net/dnsres \
+	srv/net/dnsrsrv \
 	srv/net/ethip \
 	srv/net/inetsrv \
Index: uspace/app/dnsres/Makefile
===================================================================
--- uspace/app/dnsres/Makefile	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/app/dnsres/Makefile	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,35 @@
+#
+# Copyright (c) 2013 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../..
+BINARY = dnsres
+
+SOURCES = \
+	dnsres.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/dnsres/dnsres.c
===================================================================
--- uspace/app/dnsres/dnsres.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/app/dnsres/dnsres.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2013 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup dnsres
+ * @{
+ */
+/** @file DNS query utility.
+ */
+
+#include <errno.h>
+#include <inet/dnsr.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define NAME "dnsres"
+
+static void print_syntax(void)
+{
+	printf("syntax: " NAME " <host-name>\n");
+}
+
+static int addr_format(inet_addr_t *addr, char **bufp)
+{
+	int rc;
+
+	rc = asprintf(bufp, "%d.%d.%d.%d", addr->ipv4 >> 24,
+	    (addr->ipv4 >> 16) & 0xff, (addr->ipv4 >> 8) & 0xff,
+	    addr->ipv4 & 0xff);
+
+	if (rc < 0)
+		return ENOMEM;
+
+	return EOK;
+}
+
+int main(int argc, char *argv[])
+{
+	int rc;
+	dnsr_hostinfo_t *hinfo;
+	char *saddr;
+
+	rc = dnsr_init();
+	if (rc != EOK) {
+		printf(NAME ": Failed connecting to DNS resolution service "
+		    "(%d).\n", rc);
+		return 1;
+	}
+
+	if (argc != 2) {
+		print_syntax();
+		return 1;
+	}
+
+	rc = dnsr_name2host(argv[1], &hinfo);
+	if (rc != EOK) {
+		printf(NAME ": Error resolving '%s'.\n", argv[1]);
+		return 1;
+	}
+
+	rc = addr_format(&hinfo->addr, &saddr);
+	if (rc != EOK) {
+		dnsr_hostinfo_destroy(hinfo);
+		printf(NAME ": Out of memory.\n");
+		return 1;
+	}
+
+	printf("Host name: %s address: %s\n", hinfo->name, saddr);
+	dnsr_hostinfo_destroy(hinfo);
+	free(saddr);
+
+	return 0;
+}
+
+/** @}
+ */
Index: uspace/app/init/init.c
===================================================================
--- uspace/app/init/init.c	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ uspace/app/init/init.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -359,4 +359,5 @@
 	srv_start("/srv/tcp");
 	srv_start("/srv/udp");
+	srv_start("/srv/dnsrsrv");
 	
 	srv_start("/srv/clipboard");
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ uspace/lib/c/Makefile	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -74,4 +74,5 @@
 	generic/device/pci.c \
 	generic/device/ahci.c \
+	generic/dnsr.c \
 	generic/dlfcn.c \
 	generic/elf/elf_load.c \
Index: uspace/lib/c/generic/dnsr.c
===================================================================
--- uspace/lib/c/generic/dnsr.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/lib/c/generic/dnsr.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2013 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <async.h>
+#include <assert.h>
+#include <errno.h>
+#include <inet/dnsr.h>
+#include <ipc/dnsr.h>
+#include <ipc/services.h>
+#include <loc.h>
+#include <stdlib.h>
+#include <str.h>
+
+static async_sess_t *dnsr_sess = NULL;
+
+int dnsr_init(void)
+{
+	service_id_t dnsr_svc;
+	int rc;
+
+	assert(dnsr_sess == NULL);
+
+	rc = loc_service_get_id(SERVICE_NAME_DNSR, &dnsr_svc,
+	    IPC_FLAG_BLOCKING);
+	if (rc != EOK)
+		return ENOENT;
+
+	dnsr_sess = loc_service_connect(EXCHANGE_SERIALIZE, dnsr_svc,
+	    IPC_FLAG_BLOCKING);
+	if (dnsr_sess == NULL)
+		return ENOENT;
+
+	return EOK;
+}
+
+int dnsr_name2host(char *name, dnsr_hostinfo_t **rinfo)
+{
+	async_exch_t *exch = async_exchange_begin(dnsr_sess);
+	dnsr_hostinfo_t *info;
+
+	ipc_call_t answer;
+	aid_t req = async_send_0(exch, DNSR_NAME2HOST, &answer);
+	sysarg_t retval = async_data_write_start(exch, name, str_size(name));
+
+	async_exchange_end(exch);
+
+	if (retval != EOK) {
+		async_forget(req);
+		return retval;
+	}
+
+	async_wait_for(req, &retval);
+	if (retval != EOK)
+		return EIO;
+
+	info = calloc(1, sizeof(dnsr_hostinfo_t));
+	if (info == NULL)
+		return ENOMEM;
+
+	info->name = str_dup(name);
+	info->addr.ipv4 = IPC_GET_ARG1(answer);
+
+	*rinfo = info;
+	return EOK;
+}
+
+void dnsr_hostinfo_destroy(dnsr_hostinfo_t *info)
+{
+	free(info->name);
+	free(info);
+}
+
+int dnsr_get_srvaddr(inet_addr_t *srvaddr)
+{
+	sysarg_t addr;
+	async_exch_t *exch = async_exchange_begin(dnsr_sess);
+
+	int rc = async_req_0_1(exch, DNSR_GET_SRVADDR, &addr);
+	async_exchange_end(exch);
+
+	if (rc != EOK)
+		return rc;
+
+	srvaddr->ipv4 = addr;
+	return EOK;
+}
+
+int dnsr_set_srvaddr(inet_addr_t *srvaddr)
+{
+	async_exch_t *exch = async_exchange_begin(dnsr_sess);
+
+	int rc = async_req_1_0(exch, DNSR_SET_SRVADDR, srvaddr->ipv4);
+	async_exchange_end(exch);
+
+	if (rc != EOK)
+		return rc;
+
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/c/include/inet/dnsr.h
===================================================================
--- uspace/lib/c/include/inet/dnsr.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/lib/c/include/inet/dnsr.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2013 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_INET_DNSRES_H_
+#define LIBC_INET_DNSRES_H_
+
+#include <inet/inet.h>
+
+typedef struct {
+	/** Host name */
+	char *name;
+	/** Host address */
+	inet_addr_t addr;
+} dnsr_hostinfo_t;
+
+extern int dnsr_init(void);
+extern int dnsr_name2host(char *, dnsr_hostinfo_t **);
+extern void dnsr_hostinfo_destroy(dnsr_hostinfo_t *);
+extern int dnsr_get_srvaddr(inet_addr_t *);
+extern int dnsr_set_srvaddr(inet_addr_t *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/ipc/dnsr.h
===================================================================
--- uspace/lib/c/include/ipc/dnsr.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/lib/c/include/ipc/dnsr.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcipc
+ * @{
+ */
+
+#ifndef LIBC_IPC_DNSR_H_
+#define LIBC_IPC_DNSR_H_
+
+#include <ipc/common.h>
+
+typedef enum {
+	DNSR_NAME2HOST = IPC_FIRST_USER_METHOD,
+	DNSR_GET_SRVADDR,
+	DNSR_SET_SRVADDR
+} dnsr_request_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/ipc/services.h
===================================================================
--- uspace/lib/c/include/ipc/services.h	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ uspace/lib/c/include/ipc/services.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -53,4 +53,5 @@
 } services_t;
 
+#define SERVICE_NAME_DNSR     "net/dnsr"
 #define SERVICE_NAME_INET     "net/inet"
 #define SERVICE_NAME_INETCFG  "net/inetcfg"
Index: pace/srv/net/dnsres/Makefile
===================================================================
--- uspace/srv/net/dnsres/Makefile	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ 	(revision )
@@ -1,38 +1,0 @@
-#
-# Copyright (c) 2012 Jiri Svoboda
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-USPACE_PREFIX = ../../..
-BINARY = dnsres
-
-SOURCES = \
-	dns_msg.c \
-	dnsres.c \
-	query.c \
-	transport.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: pace/srv/net/dnsres/dns_msg.c
===================================================================
--- uspace/srv/net/dnsres/dns_msg.c	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ 	(revision )
@@ -1,639 +1,0 @@
-/*
- * Copyright (c) 2013 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup dnsres
- * @{
- */
-/**
- * @file
- */
-
-#include <bitops.h>
-#include <byteorder.h>
-#include <errno.h>
-#include <macros.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <str.h>
-
-#include "dns_msg.h"
-#include "dns_std.h"
-
-#define NAME  "dnsres"
-
-static uint16_t dns_uint16_t_decode(uint8_t *, size_t);
-
-static int dns_dstr_ext(char **dstr, const char *suff)
-{
-	size_t s1, s2;
-	size_t nsize;
-	char *nstr;
-
-	if (*dstr == NULL) {
-		*dstr = str_dup(suff);
-		if (*dstr == NULL)
-			return ENOMEM;
-		return EOK;
-	}
-
-	s1 = str_size(*dstr);
-	s2 = str_size(suff);
-	nsize = s1 + s2 + 1;
-
-	nstr = realloc(*dstr, nsize);
-	if (nstr == NULL)
-		return ENOMEM;
-
-	str_cpy((*dstr) + s1, nsize - s1, suff);
-
-	*dstr = nstr;
-	return EOK;
-}
-
-#include <stdio.h>
-static int dns_name_encode(char *name, uint8_t *buf, size_t buf_size,
-    size_t *act_size)
-{
-	size_t off;
-	wchar_t c;
-	size_t lsize;
-	size_t pi, di;
-
-	pi = 0;
-	di = 1;
-	off = 0;
-
-	printf("dns_name_encode(name='%s', buf=%p, buf_size=%zu, act_size=%p\n",
-	    name, buf, buf_size, act_size);
-	lsize = 0;
-	while (true) {
-		printf("off=%zu\n", off);
-		c = str_decode(name, &off, STR_NO_LIMIT);
-		printf("c=%d\n", (int)c);
-		if (c >= 127) {
-			/* Non-ASCII character */
-			printf("non-ascii character\n");
-			return EINVAL;
-		}
-
-		if (c == '.' || c == '\0') {
-			/* Empty string, starting with period or two consecutive periods. */
-			if (lsize == 0) {
-				printf("empty token\n");
-				return EINVAL;
-			}
-
-			if (lsize > DNS_LABEL_MAX_SIZE) {
-				/* Label too long */
-				printf("label too long\n");
-				return EINVAL;
-			}
-
-			if (buf != NULL && pi < buf_size)
-				buf[pi] = (uint8_t)lsize;
-
-			lsize = 0;
-			pi = di;
-			++di;
-
-			if (c == '\0')
-				break;
-		} else {
-			if (buf != NULL && di < buf_size)
-				buf[di] = c;
-			++di;
-			++lsize;
-		}
-	}
-
-	if (buf != NULL && pi < buf_size)
-		buf[pi] = 0;
-
-	*act_size = di;
-	return EOK;
-}
-
-static int dns_name_decode(uint8_t *buf, size_t size, size_t boff, char **rname,
-    size_t *eoff)
-{
-	uint8_t *bp;
-	size_t bsize;
-	size_t lsize;
-	size_t i;
-	size_t ptr;
-	size_t eptr;
-	char *name;
-	char dbuf[2];
-	int rc;
-	bool first;
-
-	name = NULL;
-
-	if (boff > size)
-		return EINVAL;
-
-	bp = buf + boff;
-	bsize = min(size - boff, DNS_NAME_MAX_SIZE);
-	first = true;
-	*eoff = 0;
-
-	while (true) {
-		if (bsize == 0) {
-			rc = EINVAL;
-			goto error;
-		}
-
-		lsize = *bp;
-		++bp;
-		--bsize;
-
-		if (lsize == 0)
-			break;
-
-		if (!first) {
-			printf(".");
-			rc = dns_dstr_ext(&name, ".");
-			if (rc != EOK) {
-				rc = ENOMEM;
-				goto error;
-			}
-		}
-
-		if ((lsize & 0xc0) == 0xc0) {
-			printf("Pointer\n");
-			/* Pointer */
-			if (bsize < 1) {
-				printf("Pointer- bsize < 1\n");
-				rc = EINVAL;
-				goto error;
-			}
-
-			ptr = dns_uint16_t_decode(bp - 1, bsize) & 0x3fff;
-			++bp;
-			--bsize;
-
-			if (ptr >= (size_t)(bp - buf)) {
-				printf("Pointer- forward ref %u, pos=%u\n",
-				    ptr, bp - buf);
-				/* Forward reference */
-				rc = EINVAL;
-				goto error;
-			}
-
-			/*
-			 * Make sure we will not decode any byte twice.
-			 * XXX Is assumption correct?
-			 */
-			eptr = bp - buf;
-			/*
-			 * This is where encoded name ends in terms where
-			 * the message continues
-			 */
-			*eoff = eptr;
-
-			printf("ptr=%u, eptr=%u\n", ptr, eptr);
-			bp = buf + ptr;
-			bsize = eptr - ptr;
-			continue;
-		}
-
-		if (lsize > bsize) {
-			rc = EINVAL;
-			goto error;
-		}
-
-		for (i = 0; i < lsize; i++) {
-			printf("%c", *bp);
-
-			if (*bp < 32 || *bp >= 127) {
-				rc = EINVAL;
-				goto error;
-			}
-
-			dbuf[0] = *bp;
-			dbuf[1] = '\0';
-
-			rc = dns_dstr_ext(&name, dbuf);
-			if (rc != EOK) {
-				rc = ENOMEM;
-				goto error;
-			}
-			++bp;
-			--bsize;
-		}
-
-		first = false;
-	}
-
-	printf("\n");
-
-	*rname = name;
-	if (*eoff == 0)
-		*eoff = bp - buf;
-	return EOK;
-error:
-	free(name);
-	return rc;
-}
-
-/** Decode unaligned big-endian 16-bit integer */
-static uint16_t dns_uint16_t_decode(uint8_t *buf, size_t buf_size)
-{
-	assert(buf_size >= 2);
-
-	return ((uint16_t)buf[0] << 8) + buf[1];
-}
-
-/** Encode unaligned big-endian 16-bit integer */
-static void dns_uint16_t_encode(uint16_t w, uint8_t *buf, size_t buf_size)
-{
-	if (buf != NULL && buf_size >= 1)
-		buf[0] = w >> 8;
-
-	if (buf != NULL && buf_size >= 2)
-		buf[1] = w & 0xff;
-}
-
-/** Decode unaligned big-endian 32-bit integer */
-uint32_t dns_uint32_t_decode(uint8_t *buf, size_t buf_size)
-{
-	uint32_t w;
-	assert(buf_size >= 4);
-
-	w = ((uint32_t)buf[0] << 24) +
-	    ((uint32_t)buf[1] << 16) +
-	    ((uint32_t)buf[2] << 8) +
-	    buf[3];
-
-	printf("dns_uint32_t_decode: %x, %x, %x, %x -> %x\n",
-	    buf[0], buf[1], buf[2], buf[3], w);
-	return w;
-}
-
-static int dns_question_encode(dns_question_t *question, uint8_t *buf,
-    size_t buf_size, size_t *act_size)
-{
-	size_t name_size;
-	size_t di;
-	int rc;
-
-	rc = dns_name_encode(question->qname, buf, buf_size, &name_size);
-	if (rc != EOK)
-		return rc;
-
-	printf("name_size=%zu\n", name_size);
-
-	*act_size = name_size + sizeof(uint16_t) + sizeof(uint16_t);
-	printf("act_size=%zu\n", *act_size);
-	if (buf == NULL)
-		return EOK;
-
-	di = name_size;
-
-	dns_uint16_t_encode(question->qtype, buf + di, buf_size - di);
-	di += sizeof(uint16_t);
-
-	dns_uint16_t_encode(question->qclass, buf + di, buf_size - di);
-	di += sizeof(uint16_t);
-
-	return EOK;
-}
-
-static int dns_question_decode(uint8_t *buf, size_t buf_size, size_t boff,
-    dns_question_t **rquestion, size_t *eoff)
-{
-	dns_question_t *question;
-	size_t name_eoff;
-	int rc;
-
-	question = calloc(1, sizeof (dns_question_t));
-	if (question == NULL)
-		return ENOMEM;
-
-	printf("decode name..\n");
-	rc = dns_name_decode(buf, buf_size, boff, &question->qname, &name_eoff);
-	if (rc != EOK) {
-		printf("error decoding name..\n");
-		free(question);
-		return ENOMEM;
-	}
-
-	printf("ok decoding name..\n");
-	if (name_eoff + 2 * sizeof(uint16_t) > buf_size) {
-		printf("name_eoff + 2 * 2 = %d >  buf_size = %d\n",
-		    name_eoff + 2 * sizeof(uint16_t), buf_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);
-	*eoff = name_eoff + 2 * sizeof(uint16_t);
-
-	*rquestion = question;
-	return EOK;
-}
-
-static int dns_rr_decode(uint8_t *buf, size_t buf_size, size_t boff,
-    dns_rr_t **retrr, size_t *eoff)
-{
-	dns_rr_t *rr;
-	size_t name_eoff;
-	uint8_t *bp;
-	size_t bsz;
-	size_t rdlength;
-	int rc;
-
-	rr = calloc(1, sizeof (dns_rr_t));
-	if (rr == NULL)
-		return ENOMEM;
-
-	printf("decode name..\n");
-	rc = dns_name_decode(buf, buf_size, boff, &rr->name, &name_eoff);
-	if (rc != EOK) {
-		printf("error decoding name..\n");
-		free(rr);
-		return ENOMEM;
-	}
-
-	printf("ok decoding name.. '%s'\n", rr->name);
-	if (name_eoff + 2 * sizeof(uint16_t) > buf_size) {
-		printf("name_eoff + 2 * 2 = %d >  buf_size = %d\n",
-		    name_eoff + 2 * sizeof(uint16_t), buf_size);
-		free(rr->name);
-		free(rr);
-		return EINVAL;
-	}
-
-	bp = buf + name_eoff;
-	bsz = buf_size - name_eoff;
-
-	if (bsz < 3 * sizeof(uint16_t) + sizeof(uint32_t)) {
-		free(rr->name);
-		free(rr);
-		return EINVAL;
-	}
-
-	rr->rtype = dns_uint16_t_decode(bp, bsz);
-	bp += sizeof(uint16_t); bsz -= sizeof(uint16_t);
-	printf("rtype=%u\n", rr->rtype);
-
-	rr->rclass = dns_uint16_t_decode(bp, bsz);
-	bp += sizeof(uint16_t); bsz -= sizeof(uint16_t);
-	printf("rclass=%u\n", rr->rclass);
-
-	rr->ttl = dns_uint32_t_decode(bp, bsz);
-	bp += sizeof(uint32_t); bsz -= sizeof(uint32_t);
-	printf("ttl=%u\n", rr->ttl);
-
-	rdlength = dns_uint16_t_decode(bp, bsz);
-	bp += sizeof(uint16_t); bsz -= sizeof(uint16_t);
-	printf("rdlength=%u\n", rdlength);
-
-	if (rdlength > bsz) {
-		free(rr->name);
-		free(rr);
-		return EINVAL;
-	}
-
-	rr->rdata_size = rdlength;
-	rr->rdata = calloc(1, sizeof(rdlength));
-	if (rr->rdata == NULL) {
-		free(rr->name);
-		free(rr);
-		return ENOMEM;
-	}
-
-	memcpy(rr->rdata, bp, rdlength);
-	bp += rdlength;
-	bsz -= rdlength;
-
-	*eoff = bp - buf;
-	*retrr = rr;
-	return EOK;
-}
-
-int dns_message_encode(dns_message_t *msg, void **rdata, size_t *rsize)
-{
-	uint8_t *data;
-	size_t size;
-	dns_header_t hdr;
-	size_t q_size;
-	size_t di;
-	int rc;
-
-	hdr.id = host2uint16_t_be(msg->id);
-
-	hdr.opbits = host2uint16_t_be(
-	    (msg->qr << OPB_QR) |
-	    (msg->opcode << OPB_OPCODE_l) |
-	    (msg->aa ? BIT_V(uint16_t, OPB_AA) : 0) |
-	    (msg->tc ? BIT_V(uint16_t, OPB_TC) : 0) |
-	    (msg->rd ? BIT_V(uint16_t, OPB_RD) : 0) |
-	    (msg->ra ? BIT_V(uint16_t, OPB_RA) : 0) |
-	    msg->rcode
-	);
-
-	hdr.qd_count = host2uint16_t_be(list_count(&msg->question));
-	hdr.an_count = 0;
-	hdr.ns_count = 0;
-	hdr.ar_count = 0;
-
-	size = sizeof(dns_header_t);
-	printf("dns header size=%zu\n", size);
-
-	list_foreach(msg->question, link) {
-		dns_question_t *q = list_get_instance(link, dns_question_t, msg);
-		rc = dns_question_encode(q, NULL, 0, &q_size);
-		if (rc != EOK)
-			return rc;
-
-		printf("q_size=%zu\n", q_size);
-		size += q_size;
-	}
-
-	data = calloc(1, size);
-	if (data == NULL)
-		return ENOMEM;
-
-	memcpy(data, &hdr, sizeof(dns_header_t));
-	di = sizeof(dns_header_t);
-
-	list_foreach(msg->question, link) {
-		dns_question_t *q = list_get_instance(link, dns_question_t, msg);
-		rc = dns_question_encode(q, data + di, size - di, &q_size);
-		if (rc != EOK) {
-			assert(rc == ENOMEM || rc == EINVAL);
-			free(data);
-			return rc;
-		}
-
-		di += q_size;
-	}
-
-	printf("-> size=%zu, di=%zu\n", size, di);
-	*rdata = data;
-	*rsize = size;
-	return EOK;
-}
-
-int dns_message_decode(void *data, size_t size, dns_message_t **rmsg)
-{
-	dns_message_t *msg;
-	dns_header_t *hdr;
-	size_t doff;
-	size_t field_eoff;
-	dns_question_t *question;
-	dns_rr_t *rr;
-	size_t qd_count;
-	size_t an_count;
-	size_t i;
-	int rc;
-
-	msg = calloc(1, sizeof(dns_message_t));
-	if (msg == NULL)
-		return ENOMEM;
-
-	if (size < sizeof(dns_header_t))
-		return EINVAL;
-
-	hdr = data;
-
-	msg->id = uint16_t_be2host(hdr->id);
-	msg->qr = BIT_RANGE_EXTRACT(uint16_t, OPB_QR, OPB_QR, hdr->opbits);
-	msg->opcode = BIT_RANGE_EXTRACT(uint16_t, OPB_OPCODE_h, OPB_OPCODE_l,
-	    hdr->opbits);
-	msg->aa = BIT_RANGE_EXTRACT(uint16_t, OPB_AA, OPB_AA, hdr->opbits);
-	msg->tc = BIT_RANGE_EXTRACT(uint16_t, OPB_TC, OPB_TC, hdr->opbits);
-	msg->rd = BIT_RANGE_EXTRACT(uint16_t, OPB_RD, OPB_RD, hdr->opbits);
-	msg->ra = BIT_RANGE_EXTRACT(uint16_t, OPB_RA, OPB_RA, hdr->opbits);
-	msg->rcode = BIT_RANGE_EXTRACT(uint16_t, OPB_RCODE_h, OPB_RCODE_l,
-	    hdr->opbits);
-
-	list_initialize(&msg->question);
-	list_initialize(&msg->answer);
-	list_initialize(&msg->authority);
-	list_initialize(&msg->additional);
-
-	doff = sizeof(dns_header_t);
-
-	qd_count = uint16_t_be2host(hdr->qd_count);
-	printf("qd_count = %d\n", (int)qd_count);
-
-	for (i = 0; i < qd_count; i++) {
-		printf("decode question..\n");
-		rc = dns_question_decode(data, size, doff, &question, &field_eoff);
-		if (rc != EOK) {
-			printf("error decoding question\n");
-			goto error;
-		}
-		printf("ok decoding question\n");
-
-		list_append(&question->msg, &msg->question);
-		doff = field_eoff;
-	}
-
-	an_count = uint16_t_be2host(hdr->an_count);
-	printf("an_count = %d\n", an_count);
-
-	for (i = 0; i < an_count; i++) {
-		printf("decode answer..\n");
-		rc = dns_rr_decode(data, size, doff, &rr, &field_eoff);
-		if (rc != EOK) {
-			printf("error decoding answer\n");
-			goto error;
-		}
-		printf("ok decoding answer\n");
-
-		list_append(&rr->msg, &msg->answer);
-		doff = field_eoff;
-	}
-
-	printf("ns_count = %d\n", uint16_t_be2host(hdr->ns_count));
-	printf("ar_count = %d\n", uint16_t_be2host(hdr->ar_count));
-
-	*rmsg = msg;
-	return EOK;
-error:
-	dns_message_destroy(msg);
-	return rc;
-}
-
-static void dns_question_destroy(dns_question_t *question)
-{
-	free(question->qname);
-	free(question);
-}
-
-static void dns_rr_destroy(dns_rr_t *rr)
-{
-	free(rr->name);
-	free(rr->rdata);
-	free(rr);
-}
-
-void dns_message_destroy(dns_message_t *msg)
-{
-	link_t *link;
-	dns_question_t *question;
-	dns_rr_t *rr;
-
-	while (!list_empty(&msg->question)) {
-		link = list_first(&msg->question);
-		question = list_get_instance(link, dns_question_t, msg);
-		list_remove(&question->msg);
-		dns_question_destroy(question);
-	}
-
-	while (!list_empty(&msg->answer)) {
-		link = list_first(&msg->answer);
-		rr = list_get_instance(link, dns_rr_t, msg);
-		list_remove(&rr->msg);
-		dns_rr_destroy(rr);
-	}
-
-	while (!list_empty(&msg->authority)) {
-		link = list_first(&msg->authority);
-		rr = list_get_instance(link, dns_rr_t, msg);
-		list_remove(&rr->msg);
-		dns_rr_destroy(rr);
-	}
-
-	while (!list_empty(&msg->additional)) {
-		link = list_first(&msg->additional);
-		rr = list_get_instance(link, dns_rr_t, msg);
-		list_remove(&rr->msg);
-		dns_rr_destroy(rr);
-	}
-
-	free(msg);
-}
-
-/** @}
- */
Index: pace/srv/net/dnsres/dns_msg.h
===================================================================
--- uspace/srv/net/dnsres/dns_msg.h	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ 	(revision )
@@ -1,53 +1,0 @@
-/*
- * Copyright (c) 2013 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup dnsres
- * @{
- */
-/**
- * @file
- */
-
-#ifndef DNS_MSG_H
-#define DNS_MSG_H
-
-#include <adt/list.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include "dns_std.h"
-#include "dns_type.h"
-
-extern int dns_message_encode(dns_message_t *, void **, size_t *);
-extern int dns_message_decode(void *, size_t, dns_message_t **);
-extern void dns_message_destroy(dns_message_t *);
-extern uint32_t dns_uint32_t_decode(uint8_t *, size_t);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/dnsres/dns_std.h
===================================================================
--- uspace/srv/net/dnsres/dns_std.h	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ 	(revision )
@@ -1,143 +1,0 @@
-/*
- * Copyright (c) 2012 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup dnsres
- * @{
- */
-/**
- * @file DNS Standard definitions.
- *
- * From RFC 1035 Domain Names - Implementation and Specification
- */
-
-#ifndef DNS_STD_H
-#define DNS_STD_H
-
-#include <stdint.h>
-
-/** From 2.3.4. Size Limits */
-enum dns_limits {
-	DNS_LABEL_MAX_SIZE	= 63,
-	DNS_NAME_MAX_SIZE	= 255,
-	DNS_UDP_MSG_MAX_SIZE	= 512
-};
-
-typedef enum dns_qtype {
-	DTYPE_A		= 1,
-	DTYPE_NS	= 2,
-	DTYPE_MD	= 3,
-	DTYPE_MF	= 4,
-	DTYPE_CNAME	= 5,
-	DTYPE_SOA	= 6,
-	DTYPE_MB	= 7,
-	DTYPE_MG	= 8,
-	DTYPE_MR	= 9,
-	DTYPE_NULL	= 10,
-	DTYPE_WKS	= 11,
-	DTYPE_PTR	= 12,
-	DTYPE_HINFO	= 13,
-	DTYPE_MINFO	= 14,
-	DTYPE_MX	= 15,
-	DTYPE_TXT	= 16,
-	DQTYPE_AXFR	= 252,
-	DQTYPE_MAILB	= 253,
-	DQTYPE_MAILA	= 254,
-	DQTYPE_ALL	= 255
-} dns_type_t, dns_qtype_t;
-
-typedef enum dns_qclass {
-	/** Internet */
-	DC_IN		= 1,
-	/** CSNET */
-	DC_CS		= 2,
-	/** CHAOS */
-	DC_CH		= 3,
-	/** Hesiod */
-	DC_HS		= 4,
-	/** Any class */
-	DQC_ANY		= 255
-} dns_class_t, dns_qclass_t;
-
-typedef struct {
-	/** Identifier assigned by the query originator */
-	uint16_t id;
-	/** QR, Opcode, AA, TC,RD, RA, Z, Rcode */
-	uint16_t opbits;
-	/** Number of entries in query section */
-	uint16_t qd_count;
-	/** Number of RRs in the answer section */
-	uint16_t an_count;
-	/** Number of name server RRs in the authority records section */
-	uint16_t ns_count;
-	/** Number of RRs in the additional records section */
-	uint16_t ar_count;
-} dns_header_t;
-
-/** Bits in dns_header_t.opbits.
- *
- * Note that bit numbers in RFC 1035 are reversed (0 is the most significant)
- * but we use the standard notation (0 is the least significant).
- */
-enum dns_opbits {
-	OPB_QR 		= 15,
-	OPB_OPCODE_h	= 14,
-	OPB_OPCODE_l	= 11,
-	OPB_AA		= 10,
-	OPB_TC		= 9,
-	OPB_RD		= 8,
-	OPB_RA		= 7,
-	OPB_Z_h		= 6,
-	OPB_Z_l		= 4,
-	OPB_RCODE_h	= 3,
-	OPB_RCODE_l	= 0
-};
-
-typedef enum dns_query_response {
-	QR_QUERY	= 0,
-	QR_RESPONSE	= 1
-} dns_query_response_t;
-
-typedef enum dns_opcode {
-	OPC_QUERY	= 0,
-	OPC_IQUERY	= 1,
-	OPC_STATUS	= 2
-} dns_opcode_t;
-
-typedef enum dns_rcode {
-	RC_OK		= 0,
-	RC_FMT_ERR	= 1,
-	RC_SRV_FAIL	= 2,
-	RC_NAME_ERR	= 3,
-	RC_NOT_IMPL	= 4,
-	RC_REFUSED	= 5
-} dns_rcode_t;
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/dnsres/dns_type.h
===================================================================
--- uspace/srv/net/dnsres/dns_type.h	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ 	(revision )
@@ -1,110 +1,0 @@
-/*
- * Copyright (c) 2012 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup dnsres
- * @{
- */
-/**
- * @file
- */
-
-#ifndef DNS_TYPE_H
-#define DNS_TYPE_H
-
-#include <adt/list.h>
-#include <inet/inet.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include "dns_std.h"
-
-/** Unencoded DNS message */
-typedef struct {
-	/** Identifier */
-	uint16_t id;
-	/** Query or Response */
-	dns_query_response_t qr;
-	/** Opcode */
-	dns_opcode_t opcode;
-	/** Authoritative Answer */
-	bool aa;
-	/** TrunCation */
-	bool tc;
-	/** Recursion Desired */
-	bool rd;
-	/** Recursion Available */
-	bool ra;
-	/** Response Code */
-	dns_rcode_t rcode;
-
-	list_t question; /* of dns_question_t */
-	list_t answer; /* of dns_rr_t */
-	list_t authority; /* of dns_rr_t */
-	list_t additional; /* of dns_rr_t */
-} dns_message_t;
-
-/** Unencoded DNS message question section */
-typedef struct {
-	link_t msg;
-	/** Domain name in text format (dot notation) */
-	char *qname;
-	/** Query type */
-	dns_qtype_t qtype;
-	/** Query class */
-	dns_qclass_t qclass;
-} dns_question_t;
-
-/** Unencoded DNS resource record */
-typedef struct {
-	link_t msg;
-	/** Domain name */
-	char *name;
-	/** RR type */
-	dns_type_t rtype;
-	/** Class of data */
-	dns_class_t rclass;
-	/** Time to live */
-	uint32_t ttl;
-
-	/** Resource data */
-	void *rdata;
-	/** Number of bytes in @c *rdata */
-	size_t rdata_size;
-} dns_rr_t;
-
-/** Host information */
-typedef struct {
-	/** Host name */
-	char *name;
-	/** Host address */
-	inet_addr_t addr;
-} dns_host_info_t;
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/dnsres/dnsres.c
===================================================================
--- uspace/srv/net/dnsres/dnsres.c	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ 	(revision )
@@ -1,88 +1,0 @@
-/*
- * Copyright (c) 2012 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup dnsres
- * @{
- */
-/**
- * @file
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include "dns_msg.h"
-#include "dns_std.h"
-#include "query.h"
-
-#define NAME  "dnsres"
-
-static int addr_format(inet_addr_t *addr, char **bufp)
-{
-	int rc;
-
-	rc = asprintf(bufp, "%d.%d.%d.%d", addr->ipv4 >> 24,
-	    (addr->ipv4 >> 16) & 0xff, (addr->ipv4 >> 8) & 0xff,
-	    addr->ipv4 & 0xff);
-
-	if (rc < 0)
-		return ENOMEM;
-
-	return EOK;
-}
-
-int main(int argc, char *argv[])
-{
-	dns_host_info_t *hinfo;
-	char *astr;
-	int rc;
-
-	printf("%s: DNS Resolution Service\n", NAME);
-	rc = dns_name2host(argc < 2 ? "helenos.org" : argv[1], &hinfo);
-	printf("dns_name2host() -> rc = %d\n", rc);
-
-	if (rc == EOK) {
-		rc = addr_format(&hinfo->addr, &astr);
-		if (rc != EOK) {
-			dns_hostinfo_destroy(hinfo);
-			printf("Out of memory\n");
-			return ENOMEM;
-		}
-
-		printf("hostname: %s\n", hinfo->name);
-		printf("IPv4 address: %s\n", astr);
-		free(astr);
-		dns_hostinfo_destroy(hinfo);
-	}
-
-	return 0;
-}
-
-/** @}
- */
Index: pace/srv/net/dnsres/query.c
===================================================================
--- uspace/srv/net/dnsres/query.c	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ 	(revision )
@@ -1,117 +1,0 @@
-/*
- * Copyright (c) 2013 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup dnsres
- * @{
- */
-/**
- * @file
- */
-
-#include <errno.h>
-#include <mem.h>
-#include <stdlib.h>
-#include <str.h>
-
-#include "dns_msg.h"
-#include "dns_std.h"
-#include "dns_type.h"
-#include "query.h"
-#include "transport.h"
-
-static uint16_t msg_id;
-
-#include <stdio.h>
-int dns_name2host(const char *name, dns_host_info_t **rinfo)
-{
-	dns_message_t msg;
-	dns_message_t *amsg;
-	dns_question_t question;
-	dns_host_info_t *info;
-	int rc;
-
-	question.qname = (char *)name;
-	question.qtype = DTYPE_A;
-	question.qclass = DC_IN;
-
-	memset(&msg, 0, sizeof(msg));
-
-	list_initialize(&msg.question);
-	list_append(&question.msg, &msg.question);
-
-	msg.id = msg_id++;
-	msg.qr = QR_QUERY;
-	msg.opcode = OPC_QUERY;
-	msg.aa = false;
-	msg.tc = false;
-	msg.rd = true;
-	msg.ra = false;
-
-	rc = dns_request(&msg, &amsg);
-	if (rc != EOK)
-		return rc;
-
-	list_foreach(amsg->answer, link) {
-		dns_rr_t *rr = list_get_instance(link, dns_rr_t, msg);
-
-		printf(" - '%s' %u/%u, dsize %u\n",
-			rr->name, rr->rtype, rr->rclass, rr->rdata_size);
-
-		if (rr->rtype == DTYPE_A && rr->rclass == DC_IN &&
-			rr->rdata_size == sizeof(uint32_t)) {
-
-			info = calloc(1, sizeof(dns_host_info_t));
-			if (info == NULL) {
-				dns_message_destroy(amsg);
-				return ENOMEM;
-			}
-
-			info->name = str_dup(rr->name);
-			info->addr.ipv4 = dns_uint32_t_decode(rr->rdata, rr->rdata_size);
-			printf("info->addr = %x\n", info->addr.ipv4);
-
-			dns_message_destroy(amsg);
-			*rinfo = info;
-			return EOK;
-		}
-	}
-
-	dns_message_destroy(amsg);
-	printf("no A/IN found, fail\n");
-
-	return EIO;
-}
-
-void dns_hostinfo_destroy(dns_host_info_t *info)
-{
-	free(info->name);
-	free(info);
-}
-
-/** @}
- */
Index: pace/srv/net/dnsres/query.h
===================================================================
--- uspace/srv/net/dnsres/query.h	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ 	(revision )
@@ -1,47 +1,0 @@
-/*
- * Copyright (c) 2013 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup dnsres
- * @{
- */
-/**
- * @file
- */
-
-#ifndef QUERY_H
-#define QUERY_H
-
-#include "dns_type.h"
-
-extern int dns_name2host(const char *, dns_host_info_t **);
-extern void dns_hostinfo_destroy(dns_host_info_t *);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/dnsres/transport.c
===================================================================
--- uspace/srv/net/dnsres/transport.c	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ 	(revision )
@@ -1,139 +1,0 @@
-/*
- * Copyright (c) 2013 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup dnsres
- * @{
- */
-/**
- * @file
- */
-
-#include <errno.h>
-#include <net/in.h>
-#include <net/inet.h>
-#include <net/socket.h>
-#include <stdlib.h>
-
-#include "dns_msg.h"
-#include "dns_type.h"
-#include "transport.h"
-
-#include <stdio.h>
-
-#define RECV_BUF_SIZE 4096
-
-static uint8_t recv_buf[RECV_BUF_SIZE];
-
-int dns_request(dns_message_t *req, dns_message_t **rresp)
-{
-	dns_message_t *resp;
-	int rc;
-	void *req_data;
-	size_t req_size;
-	struct sockaddr_in addr;
-	struct sockaddr_in laddr;
-	struct sockaddr_in src_addr;
-	socklen_t src_addr_size;
-	size_t recv_size;
-	int fd;
-	int i;
-
-	addr.sin_family = AF_INET;
-	addr.sin_port = htons(53);
-	addr.sin_addr.s_addr = htonl((10 << 24) | (0 << 16) | (0 << 8) | 138);
-
-	laddr.sin_family = AF_INET;
-	laddr.sin_port = htons(12345);
-	laddr.sin_addr.s_addr = INADDR_ANY;
-
-	req_data = NULL;
-	fd = -1;
-
-	rc = dns_message_encode(req, &req_data, &req_size);
-	if (rc != EOK)
-		goto error;
-
-	fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
-	if (fd < 0) {
-		rc = EIO;
-		goto error;
-	}
-
-	rc = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr));
-	if (rc != EOK)
-		goto error;
-
-	printf("fd=%d req_data=%p, req_size=%zu\n", fd, req_data, req_size);
-	rc = sendto(fd, req_data, req_size, 0, (struct sockaddr *)&addr,
-	    sizeof(addr));
-	if (rc != EOK)
-		goto error;
-
-	src_addr_size = sizeof(src_addr);
-	rc = recvfrom(fd, recv_buf, RECV_BUF_SIZE, 0,
-	    (struct sockaddr *)&src_addr, &src_addr_size);
-	if (rc < 0) {
-		printf("recvfrom returns error - %d\n", rc);
-		goto error;
-	}
-
-	recv_size = (size_t)rc;
-
-	printf("received %d bytes\n", (int)recv_size);
-	for (i = 0; i < (int)recv_size; i++) {
-		if (recv_buf[i] >= 32 && recv_buf[i] < 127)
-			printf("%c", recv_buf[i]);
-		else
-			printf("?");
-	}
-	printf("\n");
-
-	printf("close socket\n");
-	closesocket(fd);
-	printf("free req_data\n");
-	free(req_data);
-
-	rc = dns_message_decode(recv_buf, recv_size, &resp);
-	if (rc != EOK) {
-		rc = EIO;
-		goto error;
-	}
-
-	*rresp = resp;
-	return EOK;
-
-error:
-	if (req_data != NULL)
-		free(req_data);
-	if (fd >= 0)
-		closesocket(fd);
-	return rc;
-}
-
-/** @}
- */
Index: pace/srv/net/dnsres/transport.h
===================================================================
--- uspace/srv/net/dnsres/transport.h	(revision dc95342d483b757291ef4b2e55e39d02aef56862)
+++ 	(revision )
@@ -1,46 +1,0 @@
-/*
- * Copyright (c) 2012 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup dnsres
- * @{
- */
-/**
- * @file
- */
-
-#ifndef TRANSPORT_H
-#define TRANSPORT_H
-
-#include "dns_type.h"
-
-extern int dns_request(dns_message_t *, dns_message_t **);
-
-#endif
-
-/** @}
- */
Index: uspace/srv/net/dnsrsrv/Makefile
===================================================================
--- uspace/srv/net/dnsrsrv/Makefile	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/srv/net/dnsrsrv/Makefile	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2012 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../../..
+BINARY = dnsrsrv
+
+SOURCES = \
+	dns_msg.c \
+	dnsrsrv.c \
+	query.c \
+	transport.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/dnsrsrv/dns_msg.c
===================================================================
--- uspace/srv/net/dnsrsrv/dns_msg.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/srv/net/dnsrsrv/dns_msg.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,639 @@
+/*
+ * Copyright (c) 2013 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup dnsres
+ * @{
+ */
+/**
+ * @file
+ */
+
+#include <bitops.h>
+#include <byteorder.h>
+#include <errno.h>
+#include <macros.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <str.h>
+
+#include "dns_msg.h"
+#include "dns_std.h"
+
+#define NAME  "dnsres"
+
+static uint16_t dns_uint16_t_decode(uint8_t *, size_t);
+
+static int dns_dstr_ext(char **dstr, const char *suff)
+{
+	size_t s1, s2;
+	size_t nsize;
+	char *nstr;
+
+	if (*dstr == NULL) {
+		*dstr = str_dup(suff);
+		if (*dstr == NULL)
+			return ENOMEM;
+		return EOK;
+	}
+
+	s1 = str_size(*dstr);
+	s2 = str_size(suff);
+	nsize = s1 + s2 + 1;
+
+	nstr = realloc(*dstr, nsize);
+	if (nstr == NULL)
+		return ENOMEM;
+
+	str_cpy((*dstr) + s1, nsize - s1, suff);
+
+	*dstr = nstr;
+	return EOK;
+}
+
+#include <stdio.h>
+static int dns_name_encode(char *name, uint8_t *buf, size_t buf_size,
+    size_t *act_size)
+{
+	size_t off;
+	wchar_t c;
+	size_t lsize;
+	size_t pi, di;
+
+	pi = 0;
+	di = 1;
+	off = 0;
+
+	printf("dns_name_encode(name='%s', buf=%p, buf_size=%zu, act_size=%p\n",
+	    name, buf, buf_size, act_size);
+	lsize = 0;
+	while (true) {
+		printf("off=%zu\n", off);
+		c = str_decode(name, &off, STR_NO_LIMIT);
+		printf("c=%d\n", (int)c);
+		if (c >= 127) {
+			/* Non-ASCII character */
+			printf("non-ascii character\n");
+			return EINVAL;
+		}
+
+		if (c == '.' || c == '\0') {
+			/* Empty string, starting with period or two consecutive periods. */
+			if (lsize == 0) {
+				printf("empty token\n");
+				return EINVAL;
+			}
+
+			if (lsize > DNS_LABEL_MAX_SIZE) {
+				/* Label too long */
+				printf("label too long\n");
+				return EINVAL;
+			}
+
+			if (buf != NULL && pi < buf_size)
+				buf[pi] = (uint8_t)lsize;
+
+			lsize = 0;
+			pi = di;
+			++di;
+
+			if (c == '\0')
+				break;
+		} else {
+			if (buf != NULL && di < buf_size)
+				buf[di] = c;
+			++di;
+			++lsize;
+		}
+	}
+
+	if (buf != NULL && pi < buf_size)
+		buf[pi] = 0;
+
+	*act_size = di;
+	return EOK;
+}
+
+static int dns_name_decode(uint8_t *buf, size_t size, size_t boff, char **rname,
+    size_t *eoff)
+{
+	uint8_t *bp;
+	size_t bsize;
+	size_t lsize;
+	size_t i;
+	size_t ptr;
+	size_t eptr;
+	char *name;
+	char dbuf[2];
+	int rc;
+	bool first;
+
+	name = NULL;
+
+	if (boff > size)
+		return EINVAL;
+
+	bp = buf + boff;
+	bsize = min(size - boff, DNS_NAME_MAX_SIZE);
+	first = true;
+	*eoff = 0;
+
+	while (true) {
+		if (bsize == 0) {
+			rc = EINVAL;
+			goto error;
+		}
+
+		lsize = *bp;
+		++bp;
+		--bsize;
+
+		if (lsize == 0)
+			break;
+
+		if (!first) {
+			printf(".");
+			rc = dns_dstr_ext(&name, ".");
+			if (rc != EOK) {
+				rc = ENOMEM;
+				goto error;
+			}
+		}
+
+		if ((lsize & 0xc0) == 0xc0) {
+			printf("Pointer\n");
+			/* Pointer */
+			if (bsize < 1) {
+				printf("Pointer- bsize < 1\n");
+				rc = EINVAL;
+				goto error;
+			}
+
+			ptr = dns_uint16_t_decode(bp - 1, bsize) & 0x3fff;
+			++bp;
+			--bsize;
+
+			if (ptr >= (size_t)(bp - buf)) {
+				printf("Pointer- forward ref %u, pos=%u\n",
+				    ptr, bp - buf);
+				/* Forward reference */
+				rc = EINVAL;
+				goto error;
+			}
+
+			/*
+			 * Make sure we will not decode any byte twice.
+			 * XXX Is assumption correct?
+			 */
+			eptr = bp - buf;
+			/*
+			 * This is where encoded name ends in terms where
+			 * the message continues
+			 */
+			*eoff = eptr;
+
+			printf("ptr=%u, eptr=%u\n", ptr, eptr);
+			bp = buf + ptr;
+			bsize = eptr - ptr;
+			continue;
+		}
+
+		if (lsize > bsize) {
+			rc = EINVAL;
+			goto error;
+		}
+
+		for (i = 0; i < lsize; i++) {
+			printf("%c", *bp);
+
+			if (*bp < 32 || *bp >= 127) {
+				rc = EINVAL;
+				goto error;
+			}
+
+			dbuf[0] = *bp;
+			dbuf[1] = '\0';
+
+			rc = dns_dstr_ext(&name, dbuf);
+			if (rc != EOK) {
+				rc = ENOMEM;
+				goto error;
+			}
+			++bp;
+			--bsize;
+		}
+
+		first = false;
+	}
+
+	printf("\n");
+
+	*rname = name;
+	if (*eoff == 0)
+		*eoff = bp - buf;
+	return EOK;
+error:
+	free(name);
+	return rc;
+}
+
+/** Decode unaligned big-endian 16-bit integer */
+static uint16_t dns_uint16_t_decode(uint8_t *buf, size_t buf_size)
+{
+	assert(buf_size >= 2);
+
+	return ((uint16_t)buf[0] << 8) + buf[1];
+}
+
+/** Encode unaligned big-endian 16-bit integer */
+static void dns_uint16_t_encode(uint16_t w, uint8_t *buf, size_t buf_size)
+{
+	if (buf != NULL && buf_size >= 1)
+		buf[0] = w >> 8;
+
+	if (buf != NULL && buf_size >= 2)
+		buf[1] = w & 0xff;
+}
+
+/** Decode unaligned big-endian 32-bit integer */
+uint32_t dns_uint32_t_decode(uint8_t *buf, size_t buf_size)
+{
+	uint32_t w;
+	assert(buf_size >= 4);
+
+	w = ((uint32_t)buf[0] << 24) +
+	    ((uint32_t)buf[1] << 16) +
+	    ((uint32_t)buf[2] << 8) +
+	    buf[3];
+
+	printf("dns_uint32_t_decode: %x, %x, %x, %x -> %x\n",
+	    buf[0], buf[1], buf[2], buf[3], w);
+	return w;
+}
+
+static int dns_question_encode(dns_question_t *question, uint8_t *buf,
+    size_t buf_size, size_t *act_size)
+{
+	size_t name_size;
+	size_t di;
+	int rc;
+
+	rc = dns_name_encode(question->qname, buf, buf_size, &name_size);
+	if (rc != EOK)
+		return rc;
+
+	printf("name_size=%zu\n", name_size);
+
+	*act_size = name_size + sizeof(uint16_t) + sizeof(uint16_t);
+	printf("act_size=%zu\n", *act_size);
+	if (buf == NULL)
+		return EOK;
+
+	di = name_size;
+
+	dns_uint16_t_encode(question->qtype, buf + di, buf_size - di);
+	di += sizeof(uint16_t);
+
+	dns_uint16_t_encode(question->qclass, buf + di, buf_size - di);
+	di += sizeof(uint16_t);
+
+	return EOK;
+}
+
+static int dns_question_decode(uint8_t *buf, size_t buf_size, size_t boff,
+    dns_question_t **rquestion, size_t *eoff)
+{
+	dns_question_t *question;
+	size_t name_eoff;
+	int rc;
+
+	question = calloc(1, sizeof (dns_question_t));
+	if (question == NULL)
+		return ENOMEM;
+
+	printf("decode name..\n");
+	rc = dns_name_decode(buf, buf_size, boff, &question->qname, &name_eoff);
+	if (rc != EOK) {
+		printf("error decoding name..\n");
+		free(question);
+		return ENOMEM;
+	}
+
+	printf("ok decoding name..\n");
+	if (name_eoff + 2 * sizeof(uint16_t) > buf_size) {
+		printf("name_eoff + 2 * 2 = %d >  buf_size = %d\n",
+		    name_eoff + 2 * sizeof(uint16_t), buf_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);
+	*eoff = name_eoff + 2 * sizeof(uint16_t);
+
+	*rquestion = question;
+	return EOK;
+}
+
+static int dns_rr_decode(uint8_t *buf, size_t buf_size, size_t boff,
+    dns_rr_t **retrr, size_t *eoff)
+{
+	dns_rr_t *rr;
+	size_t name_eoff;
+	uint8_t *bp;
+	size_t bsz;
+	size_t rdlength;
+	int rc;
+
+	rr = calloc(1, sizeof (dns_rr_t));
+	if (rr == NULL)
+		return ENOMEM;
+
+	printf("decode name..\n");
+	rc = dns_name_decode(buf, buf_size, boff, &rr->name, &name_eoff);
+	if (rc != EOK) {
+		printf("error decoding name..\n");
+		free(rr);
+		return ENOMEM;
+	}
+
+	printf("ok decoding name.. '%s'\n", rr->name);
+	if (name_eoff + 2 * sizeof(uint16_t) > buf_size) {
+		printf("name_eoff + 2 * 2 = %d >  buf_size = %d\n",
+		    name_eoff + 2 * sizeof(uint16_t), buf_size);
+		free(rr->name);
+		free(rr);
+		return EINVAL;
+	}
+
+	bp = buf + name_eoff;
+	bsz = buf_size - name_eoff;
+
+	if (bsz < 3 * sizeof(uint16_t) + sizeof(uint32_t)) {
+		free(rr->name);
+		free(rr);
+		return EINVAL;
+	}
+
+	rr->rtype = dns_uint16_t_decode(bp, bsz);
+	bp += sizeof(uint16_t); bsz -= sizeof(uint16_t);
+	printf("rtype=%u\n", rr->rtype);
+
+	rr->rclass = dns_uint16_t_decode(bp, bsz);
+	bp += sizeof(uint16_t); bsz -= sizeof(uint16_t);
+	printf("rclass=%u\n", rr->rclass);
+
+	rr->ttl = dns_uint32_t_decode(bp, bsz);
+	bp += sizeof(uint32_t); bsz -= sizeof(uint32_t);
+	printf("ttl=%u\n", rr->ttl);
+
+	rdlength = dns_uint16_t_decode(bp, bsz);
+	bp += sizeof(uint16_t); bsz -= sizeof(uint16_t);
+	printf("rdlength=%u\n", rdlength);
+
+	if (rdlength > bsz) {
+		free(rr->name);
+		free(rr);
+		return EINVAL;
+	}
+
+	rr->rdata_size = rdlength;
+	rr->rdata = calloc(1, sizeof(rdlength));
+	if (rr->rdata == NULL) {
+		free(rr->name);
+		free(rr);
+		return ENOMEM;
+	}
+
+	memcpy(rr->rdata, bp, rdlength);
+	bp += rdlength;
+	bsz -= rdlength;
+
+	*eoff = bp - buf;
+	*retrr = rr;
+	return EOK;
+}
+
+int dns_message_encode(dns_message_t *msg, void **rdata, size_t *rsize)
+{
+	uint8_t *data;
+	size_t size;
+	dns_header_t hdr;
+	size_t q_size;
+	size_t di;
+	int rc;
+
+	hdr.id = host2uint16_t_be(msg->id);
+
+	hdr.opbits = host2uint16_t_be(
+	    (msg->qr << OPB_QR) |
+	    (msg->opcode << OPB_OPCODE_l) |
+	    (msg->aa ? BIT_V(uint16_t, OPB_AA) : 0) |
+	    (msg->tc ? BIT_V(uint16_t, OPB_TC) : 0) |
+	    (msg->rd ? BIT_V(uint16_t, OPB_RD) : 0) |
+	    (msg->ra ? BIT_V(uint16_t, OPB_RA) : 0) |
+	    msg->rcode
+	);
+
+	hdr.qd_count = host2uint16_t_be(list_count(&msg->question));
+	hdr.an_count = 0;
+	hdr.ns_count = 0;
+	hdr.ar_count = 0;
+
+	size = sizeof(dns_header_t);
+	printf("dns header size=%zu\n", size);
+
+	list_foreach(msg->question, link) {
+		dns_question_t *q = list_get_instance(link, dns_question_t, msg);
+		rc = dns_question_encode(q, NULL, 0, &q_size);
+		if (rc != EOK)
+			return rc;
+
+		printf("q_size=%zu\n", q_size);
+		size += q_size;
+	}
+
+	data = calloc(1, size);
+	if (data == NULL)
+		return ENOMEM;
+
+	memcpy(data, &hdr, sizeof(dns_header_t));
+	di = sizeof(dns_header_t);
+
+	list_foreach(msg->question, link) {
+		dns_question_t *q = list_get_instance(link, dns_question_t, msg);
+		rc = dns_question_encode(q, data + di, size - di, &q_size);
+		if (rc != EOK) {
+			assert(rc == ENOMEM || rc == EINVAL);
+			free(data);
+			return rc;
+		}
+
+		di += q_size;
+	}
+
+	printf("-> size=%zu, di=%zu\n", size, di);
+	*rdata = data;
+	*rsize = size;
+	return EOK;
+}
+
+int dns_message_decode(void *data, size_t size, dns_message_t **rmsg)
+{
+	dns_message_t *msg;
+	dns_header_t *hdr;
+	size_t doff;
+	size_t field_eoff;
+	dns_question_t *question;
+	dns_rr_t *rr;
+	size_t qd_count;
+	size_t an_count;
+	size_t i;
+	int rc;
+
+	msg = calloc(1, sizeof(dns_message_t));
+	if (msg == NULL)
+		return ENOMEM;
+
+	if (size < sizeof(dns_header_t))
+		return EINVAL;
+
+	hdr = data;
+
+	msg->id = uint16_t_be2host(hdr->id);
+	msg->qr = BIT_RANGE_EXTRACT(uint16_t, OPB_QR, OPB_QR, hdr->opbits);
+	msg->opcode = BIT_RANGE_EXTRACT(uint16_t, OPB_OPCODE_h, OPB_OPCODE_l,
+	    hdr->opbits);
+	msg->aa = BIT_RANGE_EXTRACT(uint16_t, OPB_AA, OPB_AA, hdr->opbits);
+	msg->tc = BIT_RANGE_EXTRACT(uint16_t, OPB_TC, OPB_TC, hdr->opbits);
+	msg->rd = BIT_RANGE_EXTRACT(uint16_t, OPB_RD, OPB_RD, hdr->opbits);
+	msg->ra = BIT_RANGE_EXTRACT(uint16_t, OPB_RA, OPB_RA, hdr->opbits);
+	msg->rcode = BIT_RANGE_EXTRACT(uint16_t, OPB_RCODE_h, OPB_RCODE_l,
+	    hdr->opbits);
+
+	list_initialize(&msg->question);
+	list_initialize(&msg->answer);
+	list_initialize(&msg->authority);
+	list_initialize(&msg->additional);
+
+	doff = sizeof(dns_header_t);
+
+	qd_count = uint16_t_be2host(hdr->qd_count);
+	printf("qd_count = %d\n", (int)qd_count);
+
+	for (i = 0; i < qd_count; i++) {
+		printf("decode question..\n");
+		rc = dns_question_decode(data, size, doff, &question, &field_eoff);
+		if (rc != EOK) {
+			printf("error decoding question\n");
+			goto error;
+		}
+		printf("ok decoding question\n");
+
+		list_append(&question->msg, &msg->question);
+		doff = field_eoff;
+	}
+
+	an_count = uint16_t_be2host(hdr->an_count);
+	printf("an_count = %d\n", an_count);
+
+	for (i = 0; i < an_count; i++) {
+		printf("decode answer..\n");
+		rc = dns_rr_decode(data, size, doff, &rr, &field_eoff);
+		if (rc != EOK) {
+			printf("error decoding answer\n");
+			goto error;
+		}
+		printf("ok decoding answer\n");
+
+		list_append(&rr->msg, &msg->answer);
+		doff = field_eoff;
+	}
+
+	printf("ns_count = %d\n", uint16_t_be2host(hdr->ns_count));
+	printf("ar_count = %d\n", uint16_t_be2host(hdr->ar_count));
+
+	*rmsg = msg;
+	return EOK;
+error:
+	dns_message_destroy(msg);
+	return rc;
+}
+
+static void dns_question_destroy(dns_question_t *question)
+{
+	free(question->qname);
+	free(question);
+}
+
+static void dns_rr_destroy(dns_rr_t *rr)
+{
+	free(rr->name);
+	free(rr->rdata);
+	free(rr);
+}
+
+void dns_message_destroy(dns_message_t *msg)
+{
+	link_t *link;
+	dns_question_t *question;
+	dns_rr_t *rr;
+
+	while (!list_empty(&msg->question)) {
+		link = list_first(&msg->question);
+		question = list_get_instance(link, dns_question_t, msg);
+		list_remove(&question->msg);
+		dns_question_destroy(question);
+	}
+
+	while (!list_empty(&msg->answer)) {
+		link = list_first(&msg->answer);
+		rr = list_get_instance(link, dns_rr_t, msg);
+		list_remove(&rr->msg);
+		dns_rr_destroy(rr);
+	}
+
+	while (!list_empty(&msg->authority)) {
+		link = list_first(&msg->authority);
+		rr = list_get_instance(link, dns_rr_t, msg);
+		list_remove(&rr->msg);
+		dns_rr_destroy(rr);
+	}
+
+	while (!list_empty(&msg->additional)) {
+		link = list_first(&msg->additional);
+		rr = list_get_instance(link, dns_rr_t, msg);
+		list_remove(&rr->msg);
+		dns_rr_destroy(rr);
+	}
+
+	free(msg);
+}
+
+/** @}
+ */
Index: uspace/srv/net/dnsrsrv/dns_msg.h
===================================================================
--- uspace/srv/net/dnsrsrv/dns_msg.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/srv/net/dnsrsrv/dns_msg.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2013 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup dnsres
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef DNS_MSG_H
+#define DNS_MSG_H
+
+#include <adt/list.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include "dns_std.h"
+#include "dns_type.h"
+
+extern int dns_message_encode(dns_message_t *, void **, size_t *);
+extern int dns_message_decode(void *, size_t, dns_message_t **);
+extern void dns_message_destroy(dns_message_t *);
+extern uint32_t dns_uint32_t_decode(uint8_t *, size_t);
+
+#endif
+
+/** @}
+ */
Index: uspace/srv/net/dnsrsrv/dns_std.h
===================================================================
--- uspace/srv/net/dnsrsrv/dns_std.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/srv/net/dnsrsrv/dns_std.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2012 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup dnsres
+ * @{
+ */
+/**
+ * @file DNS Standard definitions.
+ *
+ * From RFC 1035 Domain Names - Implementation and Specification
+ */
+
+#ifndef DNS_STD_H
+#define DNS_STD_H
+
+#include <stdint.h>
+
+/** From 2.3.4. Size Limits */
+enum dns_limits {
+	DNS_LABEL_MAX_SIZE	= 63,
+	DNS_NAME_MAX_SIZE	= 255,
+	DNS_UDP_MSG_MAX_SIZE	= 512
+};
+
+typedef enum dns_qtype {
+	DTYPE_A		= 1,
+	DTYPE_NS	= 2,
+	DTYPE_MD	= 3,
+	DTYPE_MF	= 4,
+	DTYPE_CNAME	= 5,
+	DTYPE_SOA	= 6,
+	DTYPE_MB	= 7,
+	DTYPE_MG	= 8,
+	DTYPE_MR	= 9,
+	DTYPE_NULL	= 10,
+	DTYPE_WKS	= 11,
+	DTYPE_PTR	= 12,
+	DTYPE_HINFO	= 13,
+	DTYPE_MINFO	= 14,
+	DTYPE_MX	= 15,
+	DTYPE_TXT	= 16,
+	DQTYPE_AXFR	= 252,
+	DQTYPE_MAILB	= 253,
+	DQTYPE_MAILA	= 254,
+	DQTYPE_ALL	= 255
+} dns_type_t, dns_qtype_t;
+
+typedef enum dns_qclass {
+	/** Internet */
+	DC_IN		= 1,
+	/** CSNET */
+	DC_CS		= 2,
+	/** CHAOS */
+	DC_CH		= 3,
+	/** Hesiod */
+	DC_HS		= 4,
+	/** Any class */
+	DQC_ANY		= 255
+} dns_class_t, dns_qclass_t;
+
+typedef struct {
+	/** Identifier assigned by the query originator */
+	uint16_t id;
+	/** QR, Opcode, AA, TC,RD, RA, Z, Rcode */
+	uint16_t opbits;
+	/** Number of entries in query section */
+	uint16_t qd_count;
+	/** Number of RRs in the answer section */
+	uint16_t an_count;
+	/** Number of name server RRs in the authority records section */
+	uint16_t ns_count;
+	/** Number of RRs in the additional records section */
+	uint16_t ar_count;
+} dns_header_t;
+
+/** Bits in dns_header_t.opbits.
+ *
+ * Note that bit numbers in RFC 1035 are reversed (0 is the most significant)
+ * but we use the standard notation (0 is the least significant).
+ */
+enum dns_opbits {
+	OPB_QR 		= 15,
+	OPB_OPCODE_h	= 14,
+	OPB_OPCODE_l	= 11,
+	OPB_AA		= 10,
+	OPB_TC		= 9,
+	OPB_RD		= 8,
+	OPB_RA		= 7,
+	OPB_Z_h		= 6,
+	OPB_Z_l		= 4,
+	OPB_RCODE_h	= 3,
+	OPB_RCODE_l	= 0
+};
+
+typedef enum dns_query_response {
+	QR_QUERY	= 0,
+	QR_RESPONSE	= 1
+} dns_query_response_t;
+
+typedef enum dns_opcode {
+	OPC_QUERY	= 0,
+	OPC_IQUERY	= 1,
+	OPC_STATUS	= 2
+} dns_opcode_t;
+
+typedef enum dns_rcode {
+	RC_OK		= 0,
+	RC_FMT_ERR	= 1,
+	RC_SRV_FAIL	= 2,
+	RC_NAME_ERR	= 3,
+	RC_NOT_IMPL	= 4,
+	RC_REFUSED	= 5
+} dns_rcode_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/srv/net/dnsrsrv/dns_type.h
===================================================================
--- uspace/srv/net/dnsrsrv/dns_type.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/srv/net/dnsrsrv/dns_type.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2012 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup dnsres
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef DNS_TYPE_H
+#define DNS_TYPE_H
+
+#include <adt/list.h>
+#include <inet/inet.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include "dns_std.h"
+
+/** Unencoded DNS message */
+typedef struct {
+	/** Identifier */
+	uint16_t id;
+	/** Query or Response */
+	dns_query_response_t qr;
+	/** Opcode */
+	dns_opcode_t opcode;
+	/** Authoritative Answer */
+	bool aa;
+	/** TrunCation */
+	bool tc;
+	/** Recursion Desired */
+	bool rd;
+	/** Recursion Available */
+	bool ra;
+	/** Response Code */
+	dns_rcode_t rcode;
+
+	list_t question; /* of dns_question_t */
+	list_t answer; /* of dns_rr_t */
+	list_t authority; /* of dns_rr_t */
+	list_t additional; /* of dns_rr_t */
+} dns_message_t;
+
+/** Unencoded DNS message question section */
+typedef struct {
+	link_t msg;
+	/** Domain name in text format (dot notation) */
+	char *qname;
+	/** Query type */
+	dns_qtype_t qtype;
+	/** Query class */
+	dns_qclass_t qclass;
+} dns_question_t;
+
+/** Unencoded DNS resource record */
+typedef struct {
+	link_t msg;
+	/** Domain name */
+	char *name;
+	/** RR type */
+	dns_type_t rtype;
+	/** Class of data */
+	dns_class_t rclass;
+	/** Time to live */
+	uint32_t ttl;
+
+	/** Resource data */
+	void *rdata;
+	/** Number of bytes in @c *rdata */
+	size_t rdata_size;
+} dns_rr_t;
+
+/** Host information */
+typedef struct {
+	/** Host name */
+	char *name;
+	/** Host address */
+	inet_addr_t addr;
+} dns_host_info_t;
+
+typedef struct {
+} dnsr_client_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/srv/net/dnsrsrv/dnsrsrv.c
===================================================================
--- uspace/srv/net/dnsrsrv/dnsrsrv.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/srv/net/dnsrsrv/dnsrsrv.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,198 @@
+/*
+ * Copyright (c) 2013 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup dnsres
+ * @{
+ */
+/**
+ * @file
+ */
+
+#include <async.h>
+#include <errno.h>
+#include <io/log.h>
+#include <ipc/dnsr.h>
+#include <ipc/services.h>
+#include <loc.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <task.h>
+
+#include "dns_msg.h"
+#include "dns_std.h"
+#include "query.h"
+
+#define NAME  "dnsres"
+
+static void dnsr_client_conn(ipc_callid_t, ipc_call_t *, void *);
+
+static int dnsr_init(void)
+{
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "dnsr_init()");
+
+	async_set_client_connection(dnsr_client_conn);
+
+	int rc = loc_server_register(NAME);
+	if (rc != EOK) {
+		log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering server (%d).", rc);
+		return EEXIST;
+	}
+
+	service_id_t sid;
+	rc = loc_service_register(SERVICE_NAME_DNSR, &sid);
+	if (rc != EOK) {
+		log_msg(LOG_DEFAULT, LVL_ERROR, "Failed registering service (%d).", rc);
+		return EEXIST;
+	}
+
+	return EOK;
+}
+
+static void dnsr_name2host_srv(dnsr_client_t *client, ipc_callid_t callid,
+    ipc_call_t *call)
+{
+	char *name;
+	dns_host_info_t *hinfo;
+	int rc;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srvaddr_srv()");
+
+	rc = async_data_write_accept((void **) &name, true, 0,
+	    DNS_NAME_MAX_SIZE, 0, NULL);
+	if (rc != EOK) {
+		async_answer_0(callid, rc);
+		return;
+	}
+
+	rc = dns_name2host(name, &hinfo);
+	if (rc != EOK) {
+		async_answer_0(callid, rc);
+		return;
+	}
+
+	async_answer_1(callid, EOK, hinfo->addr.ipv4);
+
+	dns_hostinfo_destroy(hinfo);
+}
+
+static void dnsr_get_srvaddr_srv(dnsr_client_t *client, ipc_callid_t callid,
+    ipc_call_t *call)
+{
+//	inet_addr_t remote;
+//	uint8_t tos;
+//	inet_addr_t local;
+//	int rc;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "inet_get_srvaddr_srv()");
+
+/*	remote.ipv4 = IPC_GET_ARG1(*call);
+	tos = IPC_GET_ARG2(*call);
+	local.ipv4 = 0;
+
+	rc = inet_get_srcaddr(&remote, tos, &local);*/
+	async_answer_1(callid, EOK, 0x01020304);
+}
+
+static void dnsr_set_srvaddr_srv(dnsr_client_t *client, ipc_callid_t callid,
+    ipc_call_t *call)
+{
+//	inet_addr_t naddr;
+//	int rc;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "dnsr_set_srvaddr_srv()");
+
+//	naddr.ipv4 = IPC_GET_ARG1(*call);
+
+	/*rc = inet_get_srcaddr(&remote, tos, &local);*/
+	async_answer_0(callid, EOK);
+}
+
+static void dnsr_client_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
+{
+	dnsr_client_t client;
+
+	log_msg(LOG_DEFAULT, LVL_DEBUG, "dnsr_conn()");
+
+	/* Accept the connection */
+	async_answer_0(iid, EOK);
+
+//	inet_client_init(&client);
+
+	while (true) {
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		sysarg_t method = IPC_GET_IMETHOD(call);
+
+		if (!method) {
+			/* The other side has hung up */
+			async_answer_0(callid, EOK);
+			return;
+		}
+
+		switch (method) {
+		case DNSR_NAME2HOST:
+			dnsr_name2host_srv(&client, callid, &call);
+			break;
+		case DNSR_GET_SRVADDR:
+			dnsr_get_srvaddr_srv(&client, callid, &call);
+			break;
+		case DNSR_SET_SRVADDR:
+			dnsr_set_srvaddr_srv(&client, callid, &call);
+			break;
+		default:
+			async_answer_0(callid, EINVAL);
+		}
+	}
+
+//	inet_client_fini(&client);
+}
+
+int main(int argc, char *argv[])
+{
+	int rc;
+
+	printf("%s: DNS Resolution Service\n", NAME);
+
+	if (log_init(NAME) != EOK) {
+		printf(NAME ": Failed to initialize logging.\n");
+		return 1;
+	}
+
+	rc = dnsr_init();
+	if (rc != EOK)
+		return 1;
+
+	printf(NAME ": Accepting connections.\n");
+	task_retval(0);
+	async_manager();
+
+	return 0;
+}
+
+/** @}
+ */
Index: uspace/srv/net/dnsrsrv/query.c
===================================================================
--- uspace/srv/net/dnsrsrv/query.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/srv/net/dnsrsrv/query.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2013 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup dnsres
+ * @{
+ */
+/**
+ * @file
+ */
+
+#include <errno.h>
+#include <mem.h>
+#include <stdlib.h>
+#include <str.h>
+
+#include "dns_msg.h"
+#include "dns_std.h"
+#include "dns_type.h"
+#include "query.h"
+#include "transport.h"
+
+static uint16_t msg_id;
+
+#include <stdio.h>
+int dns_name2host(const char *name, dns_host_info_t **rinfo)
+{
+	dns_message_t msg;
+	dns_message_t *amsg;
+	dns_question_t question;
+	dns_host_info_t *info;
+	int rc;
+
+	question.qname = (char *)name;
+	question.qtype = DTYPE_A;
+	question.qclass = DC_IN;
+
+	memset(&msg, 0, sizeof(msg));
+
+	list_initialize(&msg.question);
+	list_append(&question.msg, &msg.question);
+
+	msg.id = msg_id++;
+	msg.qr = QR_QUERY;
+	msg.opcode = OPC_QUERY;
+	msg.aa = false;
+	msg.tc = false;
+	msg.rd = true;
+	msg.ra = false;
+
+	rc = dns_request(&msg, &amsg);
+	if (rc != EOK)
+		return rc;
+
+	list_foreach(amsg->answer, link) {
+		dns_rr_t *rr = list_get_instance(link, dns_rr_t, msg);
+
+		printf(" - '%s' %u/%u, dsize %u\n",
+			rr->name, rr->rtype, rr->rclass, rr->rdata_size);
+
+		if (rr->rtype == DTYPE_A && rr->rclass == DC_IN &&
+			rr->rdata_size == sizeof(uint32_t)) {
+
+			info = calloc(1, sizeof(dns_host_info_t));
+			if (info == NULL) {
+				dns_message_destroy(amsg);
+				return ENOMEM;
+			}
+
+			info->name = str_dup(rr->name);
+			info->addr.ipv4 = dns_uint32_t_decode(rr->rdata, rr->rdata_size);
+			printf("info->addr = %x\n", info->addr.ipv4);
+
+			dns_message_destroy(amsg);
+			*rinfo = info;
+			return EOK;
+		}
+	}
+
+	dns_message_destroy(amsg);
+	printf("no A/IN found, fail\n");
+
+	return EIO;
+}
+
+void dns_hostinfo_destroy(dns_host_info_t *info)
+{
+	free(info->name);
+	free(info);
+}
+
+/** @}
+ */
Index: uspace/srv/net/dnsrsrv/query.h
===================================================================
--- uspace/srv/net/dnsrsrv/query.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/srv/net/dnsrsrv/query.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2013 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup dnsres
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef QUERY_H
+#define QUERY_H
+
+#include "dns_type.h"
+
+extern int dns_name2host(const char *, dns_host_info_t **);
+extern void dns_hostinfo_destroy(dns_host_info_t *);
+
+#endif
+
+/** @}
+ */
Index: uspace/srv/net/dnsrsrv/transport.c
===================================================================
--- uspace/srv/net/dnsrsrv/transport.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/srv/net/dnsrsrv/transport.c	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2013 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup dnsres
+ * @{
+ */
+/**
+ * @file
+ */
+
+#include <errno.h>
+#include <net/in.h>
+#include <net/inet.h>
+#include <net/socket.h>
+#include <stdlib.h>
+
+#include "dns_msg.h"
+#include "dns_type.h"
+#include "transport.h"
+
+#include <stdio.h>
+
+#define RECV_BUF_SIZE 4096
+
+static uint8_t recv_buf[RECV_BUF_SIZE];
+
+int dns_request(dns_message_t *req, dns_message_t **rresp)
+{
+	dns_message_t *resp;
+	int rc;
+	void *req_data;
+	size_t req_size;
+	struct sockaddr_in addr;
+	struct sockaddr_in laddr;
+	struct sockaddr_in src_addr;
+	socklen_t src_addr_size;
+	size_t recv_size;
+	int fd;
+	int i;
+
+	addr.sin_family = AF_INET;
+	addr.sin_port = htons(53);
+	addr.sin_addr.s_addr = htonl((10 << 24) | (0 << 16) | (0 << 8) | 138);
+
+	laddr.sin_family = AF_INET;
+	laddr.sin_port = htons(12345);
+	laddr.sin_addr.s_addr = INADDR_ANY;
+
+	req_data = NULL;
+	fd = -1;
+
+	rc = dns_message_encode(req, &req_data, &req_size);
+	if (rc != EOK)
+		goto error;
+
+	fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
+	if (fd < 0) {
+		rc = EIO;
+		goto error;
+	}
+
+	rc = bind(fd, (struct sockaddr *)&laddr, sizeof(laddr));
+	if (rc != EOK)
+		goto error;
+
+	printf("fd=%d req_data=%p, req_size=%zu\n", fd, req_data, req_size);
+	rc = sendto(fd, req_data, req_size, 0, (struct sockaddr *)&addr,
+	    sizeof(addr));
+	if (rc != EOK)
+		goto error;
+
+	src_addr_size = sizeof(src_addr);
+	rc = recvfrom(fd, recv_buf, RECV_BUF_SIZE, 0,
+	    (struct sockaddr *)&src_addr, &src_addr_size);
+	if (rc < 0) {
+		printf("recvfrom returns error - %d\n", rc);
+		goto error;
+	}
+
+	recv_size = (size_t)rc;
+
+	printf("received %d bytes\n", (int)recv_size);
+	for (i = 0; i < (int)recv_size; i++) {
+		if (recv_buf[i] >= 32 && recv_buf[i] < 127)
+			printf("%c", recv_buf[i]);
+		else
+			printf("?");
+	}
+	printf("\n");
+
+	printf("close socket\n");
+	closesocket(fd);
+	printf("free req_data\n");
+	free(req_data);
+
+	rc = dns_message_decode(recv_buf, recv_size, &resp);
+	if (rc != EOK) {
+		rc = EIO;
+		goto error;
+	}
+
+	*rresp = resp;
+	return EOK;
+
+error:
+	if (req_data != NULL)
+		free(req_data);
+	if (fd >= 0)
+		closesocket(fd);
+	return rc;
+}
+
+/** @}
+ */
Index: uspace/srv/net/dnsrsrv/transport.h
===================================================================
--- uspace/srv/net/dnsrsrv/transport.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
+++ uspace/srv/net/dnsrsrv/transport.h	(revision 31e9fe0439e18929e4471ead9784560a4706b8a1)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup dnsres
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef TRANSPORT_H
+#define TRANSPORT_H
+
+#include "dns_type.h"
+
+extern int dns_request(dns_message_t *, dns_message_t **);
+
+#endif
+
+/** @}
+ */
