Index: uspace/app/netspeed/netspeed.c
===================================================================
--- uspace/app/netspeed/netspeed.c	(revision e2839d70628a0e488109c7397a080ea3921f6d08)
+++ uspace/app/netspeed/netspeed.c	(revision 26de91ad6075a30c55e624bbca95373c9209119e)
@@ -36,4 +36,9 @@
  */
 
+#include <assert.h>
+#include <inet/dnsr.h>
+#include <net/in.h>
+#include <net/inet.h>
+#include <net/socket.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -41,8 +46,4 @@
 #include <str_error.h>
 #include <task.h>
-
-#include <net/in.h>
-#include <net/inet.h>
-#include <net/socket.h>
 
 #define NAME "netspeed"
@@ -114,19 +115,31 @@
 }
 
-static int client(sock_type_t sock_type, const char *address, unsigned port,
+static int client(sock_type_t sock_type, const char *host, unsigned port,
     unsigned long count, char *buf, size_t bufsize)
 {
-	struct sockaddr_in addr;
-	
-	addr.sin_family = AF_INET;
-	addr.sin_port = htons(port);
-	
-	int rc = inet_pton(AF_INET, address, (void *) &addr.sin_addr.s_addr);
-	if (rc != EOK) {
-		fprintf(stderr, "inet_pton failed: %s\n", str_error(rc));
-		return rc;
-	}
-	
-	int conn_sd = socket(PF_INET, sock_type, 0);
+	inet_addr_t iaddr;
+	struct sockaddr *saddr;
+	socklen_t saddrlen;
+	
+	int rc = inet_addr_parse(host, &iaddr);
+	if (rc != EOK) {
+		dnsr_hostinfo_t *hinfo = NULL;
+		rc = dnsr_name2host(host, &hinfo, ip_any);
+		if (rc != EOK) {
+			fprintf(stderr, "Error resolving host '%s'.\n", host);
+			return ENOENT;
+		}
+		
+		iaddr = hinfo->addr;
+	}
+	
+	rc = inet_addr_sockaddr(&iaddr, port, &saddr, &saddrlen);
+	if (rc != EOK) {
+		assert(rc == ENOMEM);
+		fprintf(stderr, "Out of memory.\n");
+		return ENOMEM;
+	}
+	
+	int conn_sd = socket(saddr->sa_family, sock_type, 0);
 	if (conn_sd < 0) {
 		fprintf(stderr, "socket failed: %s\n", str_error(rc));
@@ -135,5 +148,5 @@
 	
 	if (sock_type == SOCK_STREAM) {
-		rc = connect(conn_sd, (struct sockaddr *) &addr, sizeof(addr));
+		rc = connect(conn_sd, saddr, saddrlen);
 		if (rc != EOK) {
 			fprintf(stderr, "connect failed: %s\n", str_error(rc));
@@ -151,6 +164,5 @@
 			rc = send(conn_sd, buf, bufsize, 0);
 		} else {
-			rc = sendto(conn_sd, buf, bufsize, 0,
-			    (struct sockaddr *) &addr, sizeof(addr));
+			rc = sendto(conn_sd, buf, bufsize, 0, saddr, saddrlen);
 		}
 		if (rc != EOK) {
@@ -161,4 +173,5 @@
 	
 	closesocket(conn_sd);
+	free(saddr);
 	return rc;
 }
@@ -167,5 +180,5 @@
 {
 	fprintf(stderr, "Usage: netspeed <tcp|udp> server [port] <buffer size>\n");
-	fprintf(stderr, "       netspeed <tcp|udp> client <ip> <port> <count> <buffer size>\n");
+	fprintf(stderr, "       netspeed <tcp|udp> client <host> <port> <count> <buffer size>\n");
 }
 
Index: uspace/app/nettest1/nettest1.c
===================================================================
--- uspace/app/nettest1/nettest1.c	(revision e2839d70628a0e488109c7397a080ea3921f6d08)
+++ uspace/app/nettest1/nettest1.c	(revision 26de91ad6075a30c55e624bbca95373c9209119e)
@@ -38,4 +38,5 @@
 #include "print_error.h"
 
+#include <assert.h>
 #include <malloc.h>
 #include <stdio.h>
@@ -326,51 +327,36 @@
 	}
 	
-	char *addr_s = argv[argc - 1];
+	char *host = argv[argc - 1];
 	
 	/* Interpret as address */
-	inet_addr_t addr_addr;
-	rc = inet_addr_parse(addr_s, &addr_addr);
+	inet_addr_t iaddr;
+	rc = inet_addr_parse(host, &iaddr);
 	
 	if (rc != EOK) {
 		/* Interpret as a host name */
 		dnsr_hostinfo_t *hinfo = NULL;
-		rc = dnsr_name2host(addr_s, &hinfo, ipver_from_af(family));
+		rc = dnsr_name2host(host, &hinfo, ipver_from_af(family));
 		
 		if (rc != EOK) {
-			printf("Error resolving host '%s'.\n", addr_s);
+			printf("Error resolving host '%s'.\n", host);
 			return EINVAL;
 		}
 		
-		addr_addr = hinfo->addr;
-	}
-	
-	struct sockaddr_in addr;
-	struct sockaddr_in6 addr6;
-	uint16_t af = inet_addr_sockaddr_in(&addr_addr, &addr, &addr6);
+		iaddr = hinfo->addr;
+	}
+	
+	rc = inet_addr_sockaddr(&iaddr, port, &address, &addrlen);
+	if (rc != EOK) {
+		assert(rc == ENOMEM);
+		printf("Out of memory.\n");
+		return ENOMEM;
+	}
 	
 	if (family == AF_NONE)
-		family = af;
-	
-	if (af != family) {
+		family = address->sa_family;
+	
+	if (address->sa_family != family) {
 		printf("Address family does not match explicitly set family.\n");
 		return EINVAL;
-	}
-	
-	/* Prepare the address buffer */
-	
-	switch (af) {
-	case AF_INET:
-		addr.sin_port = htons(port);
-		address = (struct sockaddr *) &addr;
-		addrlen = sizeof(addr);
-		break;
-	case AF_INET6:
-		addr6.sin6_port = htons(port);
-		address = (struct sockaddr *) &addr6;
-		addrlen = sizeof(addr6);
-		break;
-	default:
-		fprintf(stderr, "Address family is not supported\n");
-		return EAFNOSUPPORT;
 	}
 	
@@ -437,4 +423,6 @@
 	    &time_before));
 	
+	free(address);
+	
 	if (verbose)
 		printf("Exiting\n");
Index: uspace/app/nettest2/nettest2.c
===================================================================
--- uspace/app/nettest2/nettest2.c	(revision e2839d70628a0e488109c7397a080ea3921f6d08)
+++ uspace/app/nettest2/nettest2.c	(revision 26de91ad6075a30c55e624bbca95373c9209119e)
@@ -38,4 +38,5 @@
 #include "print_error.h"
 
+#include <assert.h>
 #include <malloc.h>
 #include <stdio.h>
@@ -281,35 +282,19 @@
 	}
 	
-	struct sockaddr_in addr;
-	struct sockaddr_in6 addr6;
-	uint16_t af = inet_addr_sockaddr_in(&addr_addr, &addr, &addr6);
+	struct sockaddr *address;
+	socklen_t addrlen;
+	rc = inet_addr_sockaddr(&addr_addr, port, &address, &addrlen);
+	if (rc != EOK) {
+		assert(rc == ENOMEM);
+		printf("Out of memory.\n");
+		return ENOMEM;
+	}
 	
 	if (family == AF_NONE)
-		family = af;
-	
-	if (af != family) {
+		family = address->sa_family;
+	
+	if (address->sa_family != family) {
 		printf("Address family does not match explicitly set family.\n");
 		return EINVAL;
-	}
-	
-	/* Prepare the address buffer */
-	
-	struct sockaddr *address;
-	socklen_t addrlen;
-	
-	switch (af) {
-	case AF_INET:
-		addr.sin_port = htons(port);
-		address = (struct sockaddr *) &addr;
-		addrlen = sizeof(addr);
-		break;
-	case AF_INET6:
-		addr6.sin6_port = htons(port);
-		address = (struct sockaddr *) &addr6;
-		addrlen = sizeof(addr6);
-		break;
-	default:
-		fprintf(stderr, "Address family is not supported\n");
-		return EAFNOSUPPORT;
 	}
 	
@@ -427,4 +412,6 @@
 		return rc;
 	
+	free(address);
+	
 	if (verbose)
 		printf("\nExiting\n");
Index: uspace/app/nettest3/nettest3.c
===================================================================
--- uspace/app/nettest3/nettest3.c	(revision e2839d70628a0e488109c7397a080ea3921f6d08)
+++ uspace/app/nettest3/nettest3.c	(revision 26de91ad6075a30c55e624bbca95373c9209119e)
@@ -37,4 +37,5 @@
 #include <async.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <str.h>
 
@@ -52,5 +53,6 @@
 static char buf[BUF_SIZE];
 
-static struct sockaddr_in addr;
+static struct sockaddr *address;
+static socklen_t addrlen;
 
 static uint16_t port;
@@ -62,4 +64,6 @@
 	char *endptr;
 	dnsr_hostinfo_t *hinfo;
+	inet_addr_t addr;
+	char *addr_s;
 
 	port = 7;
@@ -69,11 +73,9 @@
 
 	/* Connect to local IP address by default */
-	addr.sin_family = AF_INET;
-	addr.sin_port = htons(port);
-	addr.sin_addr.s_addr = htonl(0x7f000001);
+	inet_addr(&addr, 127, 0, 0, 1);
 
 	if (argc >= 2) {
 		printf("parsing address '%s'\n", argv[1]);
-		rc = inet_pton(AF_INET, argv[1], (uint8_t *)&addr.sin_addr.s_addr);
+		rc = inet_addr_parse(argv[1], &addr);
 		if (rc != EOK) {
 			/* Try interpreting as a host name */
@@ -84,17 +86,20 @@
 			}
 
-			uint16_t af = inet_addr_sockaddr_in(&hinfo->addr, &addr, NULL);
-			if (af != AF_INET) {
-				printf("Host '%s' not resolved as IPv4 address.\n", argv[1]);
-				return rc;
-			}
+			addr = hinfo->addr;
 		}
-		printf("result: rc=%d, family=%d, addr=%x\n", rc,
-		    addr.sin_family, addr.sin_addr.s_addr);
+		rc = inet_addr_format(&addr, &addr_s);
+		if (rc != EOK) {
+			assert(rc == ENOMEM);
+			printf("Out of memory.\n");
+			return rc;
+		}
+		printf("result: rc=%d, ver=%d, addr=%s\n", rc,
+		    addr.version, addr_s);
+		free(addr_s);
 	}
 
 	if (argc >= 3) {
 		printf("parsing port '%s'\n", argv[2]);
-		addr.sin_port = htons(strtoul(argv[2], &endptr, 10));
+		port = htons(strtoul(argv[2], &endptr, 10));
 		if (*endptr != '\0') {
 			fprintf(stderr, "Error parsing port\n");
@@ -103,6 +108,12 @@
 	}
 
+	rc = inet_addr_sockaddr(&hinfo->addr, port, &address, &addrlen);
+	if (rc != EOK) {
+		printf("Out of memory.\n");
+		return rc;
+	}
+
 	printf("socket()\n");
-	fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+	fd = socket(address->sa_family, SOCK_STREAM, IPPROTO_TCP);
 	printf(" -> %d\n", fd);
 	if (fd < 0)
@@ -110,5 +121,5 @@
 
 	printf("connect()\n");
-	rc = connect(fd, (struct sockaddr *) &addr, sizeof(addr));
+	rc = connect(fd, address, addrlen);
 	printf(" -> %d\n", rc);
 	if (rc != 0)
@@ -133,4 +144,6 @@
 	printf(" -> %d\n", rc);
 
+	free(address);
+
 	return 0;
 }
Index: uspace/app/nterm/conn.c
===================================================================
--- uspace/app/nterm/conn.c	(revision e2839d70628a0e488109c7397a080ea3921f6d08)
+++ uspace/app/nterm/conn.c	(revision 26de91ad6075a30c55e624bbca95373c9209119e)
@@ -38,6 +38,8 @@
 #include <fibril.h>
 #include <inet/dnsr.h>
+#include <net/inet.h>
 #include <net/socket.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <str_error.h>
 #include <sys/types.h>
@@ -73,28 +75,26 @@
 }
 
-int conn_open(const char *addr_s, const char *port_s)
+int conn_open(const char *host, const char *port_s)
 {
 	int conn_fd = -1;
+	struct sockaddr *saddr = NULL;
+	socklen_t saddrlen;
 	
 	/* Interpret as address */
-	inet_addr_t addr_addr;
-	int rc = inet_addr_parse(addr_s, &addr_addr);
+	inet_addr_t iaddr;
+	int rc = inet_addr_parse(host, &iaddr);
 	
 	if (rc != EOK) {
 		/* Interpret as a host name */
 		dnsr_hostinfo_t *hinfo = NULL;
-		rc = dnsr_name2host(addr_s, &hinfo, ip_any);
+		rc = dnsr_name2host(host, &hinfo, ip_any);
 		
 		if (rc != EOK) {
-			printf("Error resolving host '%s'.\n", addr_s);
+			printf("Error resolving host '%s'.\n", host);
 			goto error;
 		}
 		
-		addr_addr = hinfo->addr;
+		iaddr = hinfo->addr;
 	}
-	
-	struct sockaddr_in addr;
-	struct sockaddr_in6 addr6;
-	uint16_t af = inet_addr_sockaddr_in(&addr_addr, &addr, &addr6);
 	
 	char *endptr;
@@ -105,24 +105,18 @@
 	}
 	
-	printf("Connecting to host %s port %u\n", addr_s, port);
+	rc = inet_addr_sockaddr(&iaddr, port, &saddr, &saddrlen);
+	if (rc != EOK) {
+		assert(rc == ENOMEM);
+		printf("Out of memory.\n");
+		return ENOMEM;
+	}
 	
-	conn_fd = socket(PF_INET, SOCK_STREAM, 0);
+	printf("Connecting to host %s port %u\n", host, port);
+	
+	conn_fd = socket(saddr->sa_family, SOCK_STREAM, 0);
 	if (conn_fd < 0)
 		goto error;
 	
-	switch (af) {
-	case AF_INET:
-		addr.sin_port = htons(port);
-		rc = connect(conn_fd, (struct sockaddr *) &addr, sizeof(addr));
-		break;
-	case AF_INET6:
-		addr6.sin6_port = htons(port);
-		rc = connect(conn_fd, (struct sockaddr *) &addr6, sizeof(addr6));
-		break;
-	default:
-		printf("Unknown address family.\n");
-		goto error;
-	}
-	
+	rc = connect(conn_fd, saddr, saddrlen);
 	if (rc != EOK)
 		goto error;
@@ -134,6 +128,6 @@
 	fibril_add_ready(rcv_fid);
 	
+	free(saddr);
 	return EOK;
-	
 error:
 	if (conn_fd >= 0) {
@@ -141,4 +135,5 @@
 		conn_fd = -1;
 	}
+	free(saddr);
 	
 	return EIO;
Index: uspace/lib/c/generic/inet/addr.c
===================================================================
--- uspace/lib/c/generic/inet/addr.c	(revision e2839d70628a0e488109c7397a080ea3921f6d08)
+++ uspace/lib/c/generic/inet/addr.c	(revision 26de91ad6075a30c55e624bbca95373c9209119e)
@@ -636,4 +636,45 @@
 }
 
+int inet_addr_sockaddr(const inet_addr_t *addr, uint16_t port,
+    sockaddr_t **nsockaddr, socklen_t *naddrlen)
+{
+	sockaddr_in_t *sa4;
+	sockaddr_in6_t *sa6;
+
+	switch (addr->version) {
+	case ip_v4:
+		sa4 = calloc(1, sizeof(sockaddr_in_t));
+		if (sa4 == NULL)
+			return ENOMEM;
+
+		sa4->sin_family = AF_INET;
+		sa4->sin_port = host2uint16_t_be(port);
+		sa4->sin_addr.s_addr = host2uint32_t_be(addr->addr);
+		if (nsockaddr != NULL)
+			*nsockaddr = (sockaddr_t *)sa4;
+		if (naddrlen != NULL)
+			*naddrlen = sizeof(*sa4);
+		break;
+	case ip_v6:
+		sa6 = calloc(1, sizeof(sockaddr_in6_t));
+		if (sa6 == NULL)
+			return ENOMEM;
+
+		sa6->sin6_family = AF_INET6;
+		sa6->sin6_port = host2uint16_t_be(port);
+		host2addr128_t_be(addr->addr6, sa6->sin6_addr.s6_addr);
+		if (nsockaddr != NULL)
+			*nsockaddr = (sockaddr_t *)sa6;
+		if (naddrlen != NULL)
+			*naddrlen = sizeof(*sa6);
+		break;
+	default:
+		assert(false);
+		break;
+	}
+
+	return EOK;
+}
+
 /** @}
  */
Index: uspace/lib/c/include/inet/addr.h
===================================================================
--- uspace/lib/c/include/inet/addr.h	(revision e2839d70628a0e488109c7397a080ea3921f6d08)
+++ uspace/lib/c/include/inet/addr.h	(revision 26de91ad6075a30c55e624bbca95373c9209119e)
@@ -39,4 +39,5 @@
 #include <net/in.h>
 #include <net/in6.h>
+#include <net/socket.h>
 
 typedef uint32_t addr32_t;
@@ -135,4 +136,6 @@
 
 extern ip_ver_t ipver_from_af(int af);
+extern int inet_addr_sockaddr(const inet_addr_t *, uint16_t, sockaddr_t **,
+    socklen_t *);
 
 #endif
Index: uspace/lib/http/http.c
===================================================================
--- uspace/lib/http/http.c	(revision e2839d70628a0e488109c7397a080ea3921f6d08)
+++ uspace/lib/http/http.c	(revision 26de91ad6075a30c55e624bbca95373c9209119e)
@@ -174,24 +174,19 @@
 	}
 	
-	struct sockaddr_in addr;
-	struct sockaddr_in6 addr6;
-	uint16_t af = inet_addr_sockaddr_in(&http->addr, &addr, &addr6);
-	
-	http->conn_sd = socket(PF_INET, SOCK_STREAM, 0);
+	struct sockaddr *saddr;
+	socklen_t saddrlen;
+	
+	rc = inet_addr_sockaddr(&http->addr, http->port, &saddr, &saddrlen);
+	if (rc != EOK) {
+		assert(rc == ENOMEM);
+		return ENOMEM;
+	}
+	
+	http->conn_sd = socket(saddr->sa_family, SOCK_STREAM, 0);
 	if (http->conn_sd < 0)
 		return http->conn_sd;
 	
-	switch (af) {
-	case AF_INET:
-		addr.sin_port = htons(http->port);
-		rc = connect(http->conn_sd, (struct sockaddr *) &addr, sizeof(addr));
-		break;
-	case AF_INET6:
-		addr6.sin6_port = htons(http->port);
-		rc = connect(http->conn_sd, (struct sockaddr *) &addr6, sizeof(addr6));
-		break;
-	default:
-		return ENOTSUP;
-	}
+	rc = connect(http->conn_sd, saddr, saddrlen);
+	free(saddr);
 	
 	return rc;
Index: uspace/srv/net/dnsrsrv/transport.c
===================================================================
--- uspace/srv/net/dnsrsrv/transport.c	(revision e2839d70628a0e488109c7397a080ea3921f6d08)
+++ uspace/srv/net/dnsrsrv/transport.c	(revision 26de91ad6075a30c55e624bbca95373c9209119e)
@@ -182,4 +182,6 @@
 {
 	trans_req_t *treq = NULL;
+	struct sockaddr *saddr = NULL;
+	socklen_t saddrlen;
 	
 	void *req_data;
@@ -189,25 +191,8 @@
 		goto error;
 	
-	struct sockaddr_in addr;
-	struct sockaddr_in6 addr6;
-	uint16_t af =
-	    inet_addr_sockaddr_in(&dns_server_addr, &addr, &addr6);
-	
-	struct sockaddr *address;
-	socklen_t addrlen;
-	
-	switch (af) {
-	case AF_INET:
-		addr.sin_port = htons(DNS_SERVER_PORT);
-		address = (struct sockaddr *) &addr;
-		addrlen = sizeof(addr);
-		break;
-	case AF_INET6:
-		addr6.sin6_port = htons(DNS_SERVER_PORT);
-		address = (struct sockaddr *) &addr6;
-		addrlen = sizeof(addr6);
-		break;
-	default:
-		rc = EAFNOSUPPORT;
+	rc = inet_addr_sockaddr(&dns_server_addr, DNS_SERVER_PORT,
+	    &saddr, &saddrlen);
+	if (rc != EOK) {
+		assert(rc == ENOMEM);
 		goto error;
 	}
@@ -217,5 +202,5 @@
 	while (ntry < REQ_RETRY_MAX) {
 		rc = sendto(transport_fd, req_data, req_size, 0,
-		    (struct sockaddr *) address, addrlen);
+		    saddr, saddrlen);
 		if (rc != EOK)
 			goto error;
@@ -256,4 +241,5 @@
 	treq_destroy(treq);
 	free(req_data);
+	free(saddr);
 	return EOK;
 	
@@ -263,4 +249,5 @@
 	
 	free(req_data);
+	free(saddr);
 	return rc;
 }
