Index: uspace/app/nettest1/nettest1.c
===================================================================
--- uspace/app/nettest1/nettest1.c	(revision b5cf742a59181f253244bd8f695f588d137834ed)
+++ uspace/app/nettest1/nettest1.c	(revision f3386d746b4f2e3d741eb9009428dbd331e2b6b1)
@@ -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) {
