Index: uspace/app/nettest1/nettest1.c
===================================================================
--- uspace/app/nettest1/nettest1.c	(revision edf0d273d18a4466ab749a9c51b5b32133fb2693)
+++ uspace/app/nettest1/nettest1.c	(revision b2010e2b0367c842795ba5cd97043f8a6ae6912b)
@@ -59,16 +59,16 @@
 #define NETTEST1_TEXT  "Networking test 1 - sockets"
 
-static int family = PF_INET;
+static uint16_t family = AF_INET;
 static sock_type_t type = SOCK_DGRAM;
-static char *data;
 static size_t size = 27;
-static int verbose = 0;
+static bool verbose = false;
+static int sockets = 10;
+static int messages = 10;
+static uint16_t port = 7;
 
 static struct sockaddr *address;
 static socklen_t addrlen;
 
-static int sockets;
-static int messages;
-static uint16_t port;
+static char *data;
 
 static void nettest1_print_help(void)
@@ -299,25 +299,13 @@
 int main(int argc, char *argv[])
 {
-	struct sockaddr_in address_in;
-	struct sockaddr_in6 address_in6;
-	dnsr_hostinfo_t *hinfo;
-	uint8_t *address_start;
-
-	int *socket_ids;
-	int index;
-	struct timeval time_before;
-	struct timeval time_after;
-
-	int rc;
-
-	sockets = 10;
-	messages = 10;
-	port = 7;
-
 	/*
 	 * Parse the command line arguments. Stop before the last argument
 	 * if it does not start with dash ('-')
 	 */
-	for (index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); index++) {
+	int index;
+	int rc;
+	
+	for (index = 1; (index < argc - 1) || ((index == argc - 1) &&
+	    (argv[index][0] == '-')); index++) {
 		/* Options should start with dash ('-') */
 		if (argv[index][0] == '-') {
@@ -331,48 +319,55 @@
 	}
 	
-	/* If not before the last argument containing the host */
+	/* The last argument containing the host */
 	if (index >= argc) {
-		printf("Command line error: missing host name\n");
+		printf("Host name missing.\n");
 		nettest1_print_help();
 		return EINVAL;
 	}
-
+	
+	char *addr_s = argv[argc - 1];
+	
+	/* Interpret as address */
+	inet_addr_t addr_addr;
+	rc = inet_addr_parse(addr_s, &addr_addr);
+	
+	if (rc != EOK) {
+		/* Interpret as a host name */
+		dnsr_hostinfo_t *hinfo = NULL;
+		rc = dnsr_name2host(addr_s, &hinfo);
+		
+		if (rc != EOK) {
+			printf("Error resolving host '%s'.\n", addr_s);
+			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);
+	
+	if (af != family) {
+		printf("Address family does not match explicitly set family.\n");
+		return EINVAL;
+	}
+	
 	/* Prepare the address buffer */
-
-	switch (family) {
-	case PF_INET:
-		address_in.sin_family = AF_INET;
-		address_in.sin_port = htons(port);
-		address = (struct sockaddr *) &address_in;
-		addrlen = sizeof(address_in);
-		address_start = (uint8_t *) &address_in.sin_addr.s_addr;
-		break;
-	case PF_INET6:
-		address_in6.sin6_family = AF_INET6;
-		address_in6.sin6_port = htons(port);
-		address = (struct sockaddr *) &address_in6;
-		addrlen = sizeof(address_in6);
-		address_start = (uint8_t *) &address_in6.sin6_addr.s6_addr;
+	
+	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;
-	}
-
-	/* Parse the last argument which should contain the host/address */
-	rc = inet_pton(family, argv[argc - 1], address_start);
-	if (rc != EOK) {
-		/* Try interpreting as a host name */
-		rc = dnsr_name2host(argv[argc - 1], &hinfo);
-		if (rc != EOK) {
-			printf("Error resolving host '%s'.\n", argv[argc - 1]);
-			return rc;
-		}
-		
-		rc = inet_addr_sockaddr_in(&hinfo->addr, &address_in);
-		if (rc != EOK) {
-			printf("Host '%s' not resolved as IPv4 address.\n", argv[argc - 1]);
-			return rc;
-		}
 	}
 	
@@ -406,5 +401,5 @@
 	 * null (\0).
 	 */
-	socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
+	int *socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
 	if (!socket_ids) {
 		fprintf(stderr, "Failed to allocate receive buffer.\n");
@@ -417,4 +412,5 @@
 		printf("Starting tests\n");
 	
+	struct timeval time_before;
 	rc = gettimeofday(&time_before, NULL);
 	if (rc != EOK) {
@@ -428,4 +424,5 @@
 	nettest1_test(socket_ids, sockets, messages);
 	
+	struct timeval time_after;
 	rc = gettimeofday(&time_after, NULL);
 	if (rc != EOK) {
Index: uspace/app/nettest2/nettest2.c
===================================================================
--- uspace/app/nettest2/nettest2.c	(revision edf0d273d18a4466ab749a9c51b5b32133fb2693)
+++ uspace/app/nettest2/nettest2.c	(revision b2010e2b0367c842795ba5cd97043f8a6ae6912b)
@@ -60,11 +60,11 @@
 #define NETTEST2_TEXT  "Networking test 2 - transfer"
 
-static size_t size;
-static bool verbose;
-static sock_type_t type;
-static int sockets;
-static int messages;
-static int family;
-static uint16_t port;
+static uint16_t family = PF_INET;
+static size_t size = 28;
+static bool verbose = false;
+static sock_type_t type = SOCK_DGRAM;
+static int sockets = 10;
+static int messages = 10;
+static uint16_t port = 7;
 
 static void nettest2_print_help(void)
@@ -234,27 +234,7 @@
 int main(int argc, char *argv[])
 {
-	struct sockaddr *address;
-	struct sockaddr_in address_in;
-	struct sockaddr_in6 address_in6;
-	dnsr_hostinfo_t *hinfo;
-	socklen_t addrlen;
-	uint8_t *address_start;
-
-	int *socket_ids;
-	char *data;
 	int index;
-	struct timeval time_before;
-	struct timeval time_after;
-
 	int rc;
-
-	size = 28;
-	verbose = false;
-	type = SOCK_DGRAM;
-	sockets = 10;
-	messages = 10;
-	family = PF_INET;
-	port = 7;
-
+	
 	/*
 	 * Parse the command line arguments.
@@ -264,5 +244,4 @@
 	for (index = 1; (index < argc - 1) || ((index == argc - 1) &&
 	    (argv[index][0] == '-')); ++index) {
-
 		/* Options should start with dash ('-') */
 		if (argv[index][0] == '-') {
@@ -276,48 +255,58 @@
 	}
 	
-	/* If not before the last argument containing the host */
+	/* The last argument containing the host */
 	if (index >= argc) {
-		printf("Command line error: missing host name\n");
+		printf("Host name missing.\n");
 		nettest2_print_help();
 		return EINVAL;
 	}
-
+	
+	char *addr_s = argv[argc - 1];
+	
+	/* Interpret as address */
+	inet_addr_t addr_addr;
+	rc = inet_addr_parse(addr_s, &addr_addr);
+	
+	if (rc != EOK) {
+		/* Interpret as a host name */
+		dnsr_hostinfo_t *hinfo = NULL;
+		rc = dnsr_name2host(addr_s, &hinfo);
+		
+		if (rc != EOK) {
+			printf("Error resolving host '%s'.\n", addr_s);
+			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);
+	
+	if (af != family) {
+		printf("Address family does not match explicitly set family.\n");
+		return EINVAL;
+	}
+	
 	/* Prepare the address buffer */
-
-	switch (family) {
-	case PF_INET:
-		address_in.sin_family = AF_INET;
-		address_in.sin_port = htons(port);
-		address = (struct sockaddr *) &address_in;
-		addrlen = sizeof(address_in);
-		address_start = (uint8_t *) &address_in.sin_addr.s_addr;
-		break;
-	case PF_INET6:
-		address_in6.sin6_family = AF_INET6;
-		address_in6.sin6_port = htons(port);
-		address = (struct sockaddr *) &address_in6;
-		addrlen = sizeof(address_in6);
-		address_start = (uint8_t *) &address_in6.sin6_addr.s6_addr;
+	
+	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;
-	}
-
-	/* Parse the last argument which should contain the host/address */
-	rc = inet_pton(family, argv[argc - 1], address_start);
-	if (rc != EOK) {
-		/* Try interpreting as a host name */
-		rc = dnsr_name2host(argv[argc - 1], &hinfo);
-		if (rc != EOK) {
-			printf("Error resolving host '%s'.\n", argv[argc - 1]);
-			return rc;
-		}
-		
-		rc = inet_addr_sockaddr_in(&hinfo->addr, &address_in);
-		if (rc != EOK) {
-			printf("Host '%s' not resolved as IPv4 address.\n", argv[argc - 1]);
-			return rc;
-		}
 	}
 	
@@ -333,5 +322,5 @@
 	 * null character.
 	 */
-	data = (char *) malloc(size + 1);
+	char *data = (char *) malloc(size + 1);
 	if (!data) {
 		fprintf(stderr, "Failed to allocate data buffer.\n");
@@ -353,9 +342,10 @@
 	 * Allocate count entries plus the terminating null (\0)
 	 */
-	socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
+	int *socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
 	if (!socket_ids) {
 		fprintf(stderr, "Failed to allocate receive buffer.\n");
 		return ENOMEM;
 	}
+	
 	socket_ids[sockets] = 0;
 	
@@ -377,4 +367,5 @@
 		printf("\n");
 	
+	struct timeval time_before;
 	rc = gettimeofday(&time_before, NULL);
 	if (rc != EOK) {
@@ -388,4 +379,5 @@
 		return rc;
 	
+	struct timeval time_after;
 	rc = gettimeofday(&time_after, NULL);
 	if (rc != EOK) {
Index: uspace/app/nettest3/nettest3.c
===================================================================
--- uspace/app/nettest3/nettest3.c	(revision edf0d273d18a4466ab749a9c51b5b32133fb2693)
+++ uspace/app/nettest3/nettest3.c	(revision b2010e2b0367c842795ba5cd97043f8a6ae6912b)
@@ -84,6 +84,6 @@
 			}
 			
-			rc = inet_addr_sockaddr_in(&hinfo->addr, &addr);
-			if (rc != EOK) {
+			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;
Index: uspace/app/nterm/conn.c
===================================================================
--- uspace/app/nterm/conn.c	(revision edf0d273d18a4466ab749a9c51b5b32133fb2693)
+++ uspace/app/nterm/conn.c	(revision b2010e2b0367c842795ba5cd97043f8a6ae6912b)
@@ -75,15 +75,15 @@
 int conn_open(const char *addr_s, const char *port_s)
 {
-	struct sockaddr_in addr;
-	dnsr_hostinfo_t *hinfo = NULL;
-	int rc;
-	char *endptr;
-
-	addr.sin_family = AF_INET;
-
-	rc = inet_pton(addr.sin_family, addr_s, (uint8_t *)&addr.sin_addr);
+	int conn_fd = -1;
+	
+	/* Interpret as address */
+	inet_addr_t addr_addr;
+	int rc = inet_addr_parse(addr_s, &addr_addr);
+	
 	if (rc != EOK) {
-		/* Try interpreting as a host name */
+		/* Interpret as a host name */
+		dnsr_hostinfo_t *hinfo = NULL;
 		rc = dnsr_name2host(addr_s, &hinfo);
+		
 		if (rc != EOK) {
 			printf("Error resolving host '%s'.\n", addr_s);
@@ -91,12 +91,13 @@
 		}
 		
-		rc = inet_addr_sockaddr_in(&hinfo->addr, &addr);
-		if (rc != EOK) {
-			printf("Host '%s' not resolved as IPv4 address.\n", addr_s);
-			return rc;
-		}
+		addr_addr = hinfo->addr;
 	}
-
-	addr.sin_port = htons(strtol(port_s, &endptr, 10));
+	
+	struct sockaddr_in addr;
+	struct sockaddr_in6 addr6;
+	uint16_t af = inet_addr_sockaddr_in(&addr_addr, &addr, &addr6);
+	
+	char *endptr;
+	uint16_t port = strtol(port_s, &endptr, 10);
 	if (*endptr != '\0') {
 		printf("Invalid port number %s\n", port_s);
@@ -104,11 +105,24 @@
 	}
 	
+	printf("Connecting to host %s port %u\n", addr_s, port);
+	
 	conn_fd = socket(PF_INET, SOCK_STREAM, 0);
 	if (conn_fd < 0)
 		goto error;
 	
-	printf("Connecting to host %s port %u\n", addr_s, ntohs(addr.sin_port));
+	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, (struct sockaddr *)&addr, sizeof(addr));
 	if (rc != EOK)
 		goto error;
Index: uspace/app/ping/ping.c
===================================================================
--- uspace/app/ping/ping.c	(revision edf0d273d18a4466ab749a9c51b5b32133fb2693)
+++ uspace/app/ping/ping.c	(revision b2010e2b0367c842795ba5cd97043f8a6ae6912b)
@@ -37,4 +37,5 @@
 #include <errno.h>
 #include <fibril_synch.h>
+#include <net/socket_codes.h>
 #include <inet/dnsr.h>
 #include <inet/addr.h>
@@ -63,6 +64,6 @@
 };
 
-static uint32_t src;
-static uint32_t dest;
+static addr32_t src;
+static addr32_t dest;
 
 static bool ping_repeat = false;
@@ -84,8 +85,8 @@
 {
 	inet_addr_t src_addr;
-	inet_addr_unpack(sdu->src, &src_addr);
+	inet_addr_set(sdu->src, &src_addr);
 	
 	inet_addr_t dest_addr;
-	inet_addr_unpack(sdu->dest, &dest_addr);
+	inet_addr_set(sdu->dest, &dest_addr);
 	
 	char *asrc;
@@ -220,6 +221,6 @@
 	}
 	
-	rc = inet_addr_pack(&dest_addr, &dest);
-	if (rc != EOK) {
+	uint16_t af = inet_addr_get(&dest_addr, &dest, NULL);
+	if (af != AF_INET) {
 		printf(NAME ": Destination '%s' is not an IPv4 address.\n",
 		    argv[argi]);
@@ -235,5 +236,5 @@
 	
 	inet_addr_t src_addr;
-	inet_addr_unpack(src, &src_addr);
+	inet_addr_set(src, &src_addr);
 	
 	rc = inet_addr_format(&src_addr, &asrc);
