Index: uspace/app/bdsh/exec.c
===================================================================
--- uspace/app/bdsh/exec.c	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ uspace/app/bdsh/exec.c	(revision b3631bc28ac6307c083b19e3b502538bf74cbae9)
@@ -40,4 +40,5 @@
 #include <str.h>
 #include <fcntl.h>
+#include <str_error.h>
 
 #include "config.h"
@@ -124,5 +125,5 @@
 
 	if (tid == 0) {
-		cli_error(CL_EEXEC, "Cannot spawn `%s'.", cmd);
+		cli_error(CL_EEXEC, "%s: Cannot spawn `%s'", progname, cmd);
 		return 1;
 	}
@@ -130,7 +131,8 @@
 	task_wait(tid, &texit, &retval);
 	if (texit != TASK_EXIT_NORMAL) {
-		printf("Command failed (unexpectedly terminated).\n");
+		printf("%s: Command failed (unexpectedly terminated)\n", progname);
 	} else if (retval != 0) {
-		printf("Command failed (return value %d).\n", retval);
+		printf("%s: Command failed (%s)\n",
+		    progname, str_error(retval));
 	}
 
Index: uspace/app/bdsh/scli.h
===================================================================
--- uspace/app/bdsh/scli.h	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ uspace/app/bdsh/scli.h	(revision b3631bc28ac6307c083b19e3b502538bf74cbae9)
@@ -13,3 +13,5 @@
 } cliuser_t;
 
+extern const char *progname;
+
 #endif
Index: uspace/app/netecho/Makefile
===================================================================
--- uspace/app/netecho/Makefile	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ uspace/app/netecho/Makefile	(revision b3631bc28ac6307c083b19e3b502538bf74cbae9)
@@ -35,5 +35,4 @@
 SOURCES = \
 	netecho.c \
-	parse.c \
 	print_error.c
 
Index: uspace/app/netecho/netecho.c
===================================================================
--- uspace/app/netecho/netecho.c	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ uspace/app/netecho/netecho.c	(revision b3631bc28ac6307c083b19e3b502538bf74cbae9)
@@ -40,4 +40,5 @@
 #include <str.h>
 #include <task.h>
+#include <arg_parse.h>
 
 #include <in.h>
@@ -46,6 +47,6 @@
 #include <socket.h>
 #include <net_err.h>
-
-#include "parse.h"
+#include <socket_parse.h>
+
 #include "print_error.h"
 
@@ -128,8 +129,4 @@
 	int value;
 
-	// print the program label
-	printf("Task %d - ", task_get_id());
-	printf("%s\n", NAME);
-
 	// parse the command line arguments
 	for(index = 1; index < argc; ++ index){
@@ -137,11 +134,11 @@
 			switch(argv[index][1]){
 				case 'b':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &backlog, "accepted sockets queue size", 0));
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 0));
 					break;
 				case 'c':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "message count", 0));
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 0));
 					break;
 				case 'f':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, parse_protocol_family));
+					ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family));
 					break;
 				case 'h':
@@ -150,16 +147,16 @@
 					break;
 				case 'p':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 0));
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
 					port = (uint16_t) value;
 					break;
 				case 'r':
-					ERROR_PROPAGATE(parse_parameter_string(argc, argv, &index, &reply, "reply string", 0));
+					ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 0));
 					break;
 				case 's':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "receive size", 0));
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
 					size = (value >= 0) ? (size_t) value : 0;
 					break;
 				case 't':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, parse_socket_type));
+					ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type));
 					type = (sock_type_t) value;
 					break;
@@ -170,27 +167,26 @@
 				case '-':
 					if(str_lcmp(argv[index] + 2, "backlog=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &backlog, "accepted sockets queue size", 8));
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 8));
 					}else if(str_lcmp(argv[index] + 2, "count=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "message count", 8));
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 8));
 					}else if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, parse_protocol_family));
+						ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family));
 					}else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
 						echo_print_help();
 						return EOK;
 					}else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 7));
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
 						port = (uint16_t) value;
 					}else if(str_lcmp(argv[index] + 2, "reply=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_string(argc, argv, &index, &reply, "reply string", 8));
+						ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 8));
 					}else if(str_lcmp(argv[index] + 2, "size=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "receive size", 7));
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
 						size = (value >= 0) ? (size_t) value : 0;
 					}else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, parse_socket_type));
+						ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type));
 						type = (sock_type_t) value;
 					}else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
 						verbose = 1;
 					}else{
-						print_unrecognized(index, argv[index] + 2);
 						echo_print_help();
 						return EINVAL;
@@ -198,10 +194,8 @@
 					break;
 				default:
-					print_unrecognized(index, argv[index] + 1);
 					echo_print_help();
 					return EINVAL;
 			}
 		}else{
-			print_unrecognized(index, argv[index]);
 			echo_print_help();
 			return EINVAL;
Index: uspace/app/netecho/parse.c
===================================================================
--- uspace/app/netecho/parse.c	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ 	(revision )
@@ -1,123 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * 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 net_app
- *  @{
- */
-
-/** @file
- *  Generic application parsing functions implementation.
- */
-
-#include <stdio.h>
-#include <str.h>
-
-#include <socket.h>
-#include <net_err.h>
-
-#include "parse.h"
-
-int parse_address_family(const char * name){
-	if(str_lcmp(name, "AF_INET", 7) == 0){
-		return AF_INET;
-	}else if(str_lcmp(name, "AF_INET6", 8) == 0){
-		return AF_INET6;
-	}
-	return EAFNOSUPPORT;
-}
-
-int parse_parameter_int(int argc, char ** argv, int * index, int * value, const char * name, int offset){
-	char * rest;
-
-	if(offset){
-		*value = strtol(argv[*index] + offset, &rest, 10);
-	}else if((*index) + 1 < argc){
-		++ (*index);
-		*value = strtol(argv[*index], &rest, 10);
-	}else{
-		fprintf(stderr, "Command line error: missing %s\n", name);
-		return EINVAL;
-	}
-	if(rest && (*rest)){
-		fprintf(stderr, "Command line error: %s unrecognized (%d: %s)\n", name, * index, argv[*index]);
-		return EINVAL;
-	}
-	return EOK;
-}
-
-int parse_parameter_name_int(int argc, char ** argv, int * index, int * value, const char * name, int offset, int (*parse_value)(const char * value)){
-	ERROR_DECLARE;
-
-	char * parameter;
-
-	ERROR_PROPAGATE(parse_parameter_string(argc, argv, index, &parameter, name, offset));
-	*value = (*parse_value)(parameter);
-	if((*value) == ENOENT){
-		fprintf(stderr, "Command line error: unrecognized %s value (%d: %s)\n", name, * index, parameter);
-		return ENOENT;
-	}
-	return EOK;
-}
-
-int parse_parameter_string(int argc, char ** argv, int * index, char ** value, const char * name, int offset){
-	if(offset){
-		*value = argv[*index] + offset;
-	}else if((*index) + 1 < argc){
-		++ (*index);
-		*value = argv[*index];
-	}else{
-		fprintf(stderr, "Command line error: missing %s\n", name);
-		return EINVAL;
-	}
-	return EOK;
-}
-
-int parse_protocol_family(const char * name){
-	if(str_lcmp(name, "PF_INET", 7) == 0){
-		return PF_INET;
-	}else if(str_lcmp(name, "PF_INET6", 8) == 0){
-		return PF_INET6;
-	}
-	return EPFNOSUPPORT;
-}
-
-int parse_socket_type(const char * name){
-	if(str_lcmp(name, "SOCK_DGRAM", 11) == 0){
-		return SOCK_DGRAM;
-	}else if(str_lcmp(name, "SOCK_STREAM", 12) == 0){
-		return SOCK_STREAM;
-	}
-	return ESOCKTNOSUPPORT;
-}
-
-void print_unrecognized(int index, const char * parameter){
-	fprintf(stderr, "Command line error: unrecognized argument (%d: %s)\n", index, parameter);
-}
-
-/** @}
- */
Index: uspace/app/netecho/parse.h
===================================================================
--- uspace/app/netecho/parse.h	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ 	(revision )
@@ -1,120 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * 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 net_app
- *  @{
- */
-
-/** @file
- *  Generic command line arguments parsing functions.
- */
-
-#ifndef __NET_APP_PARSE__
-#define __NET_APP_PARSE__
-
-#include <socket.h>
-
-/** Translates the character string to the address family number.
- *  @param[in] name The address family name.
- *  @returns The corresponding address family number.
- *  @returns EAFNOSUPPORTED if the address family is not supported.
- */
-extern int parse_address_family(const char * name);
-
-/** Parses the next parameter as an integral number.
- *  The actual parameter is pointed by the index.
- *  Parses the offseted actual parameter value if the offset is set or the next one if not.
- *  @param[in] argc The total number of the parameters.
- *  @param[in] argv The parameters.
- *  @param[in,out] index The actual parameter index. The index is incremented by the number of processed parameters.
- *  @param[out] value The parsed parameter value.
- *  @param[in] name The parameter name to be printed on errors.
- *  @param[in] offset The value offset in the actual parameter. If not set, the next parameter is parsed instead.
- *  @returns EOK on success.
- *  @returns EINVAL if the parameter is missing.
- *  @returns EINVAL if the parameter is in wrong format.
- */
-extern int parse_parameter_int(int argc, char ** argv, int * index, int * value, const char * name, int offset);
-
-/** Parses the next named parameter as an integral number.
- *  The actual parameter is pointed by the index.
- *  Uses the offseted actual parameter if the offset is set or the next one if not.
- *  Translates the parameter using the parse_value function.
- *  Increments the actual index by the number of processed parameters.
- *  @param[in] argc The total number of the parameters.
- *  @param[in] argv The parameters.
- *  @param[in,out] index The actual parameter index. The index is incremented by the number of processed parameters.
- *  @param[out] value The parsed parameter value.
- *  @param[in] name The parameter name to be printed on errors.
- *  @param[in] offset The value offset in the actual parameter. If not set, the next parameter is parsed instead.
- *  @param[in] parse_value The translation function to parse the named value.
- *  @returns EOK on success.
- *  @returns EINVAL if the parameter is missing.
- *  @returns ENOENT if the parameter name has not been found.
- */
-extern int parse_parameter_name_int(int argc, char ** argv, int * index, int * value, const char * name, int offset, int (*parse_value)(const char * value));
-
-/** Parses the next parameter as a character string.
- *  The actual parameter is pointed by the index.
- *  Uses the offseted actual parameter value if the offset is set or the next one if not.
- *  Increments the actual index by the number of processed parameters.
- *  @param[in] argc The total number of the parameters.
- *  @param[in] argv The parameters.
- *  @param[in,out] index The actual parameter index. The index is incremented by the number of processed parameters.
- *  @param[out] value The parsed parameter value.
- *  @param[in] name The parameter name to be printed on errors.
- *  @param[in] offset The value offset in the actual parameter. If not set, the next parameter is parsed instead.
- *  @returns EOK on success.
- *  @returns EINVAL if the parameter is missing.
- */
-extern int parse_parameter_string(int argc, char ** argv, int * index, char ** value, const char * name, int offset);
-
-/** Translates the character string to the protocol family number.
- *  @param[in] name The protocol family name.
- *  @returns The corresponding protocol family number.
- *  @returns EPFNOSUPPORTED if the protocol family is not supported.
- */
-extern int parse_protocol_family(const char * name);
-
-/** Translates the character string to the socket type number.
- *  @param[in] name The socket type name.
- *  @returns The corresponding socket type number.
- *  @returns ESOCKNOSUPPORTED if the socket type is not supported.
- */
-extern int parse_socket_type(const char * name);
-
-/** Prints the parameter unrecognized message and the application help.
- *  @param[in] index The index of the parameter.
- *  @param[in] parameter The parameter name.
- */
-extern void print_unrecognized(int index, const char * parameter);
-
-#endif
-
-/** @}
- */
Index: uspace/app/nettest1/Makefile
===================================================================
--- uspace/app/nettest1/Makefile	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ uspace/app/nettest1/Makefile	(revision b3631bc28ac6307c083b19e3b502538bf74cbae9)
@@ -36,5 +36,4 @@
 	nettest1.c \
 	nettest.c \
-	parse.c \
 	print_error.c
 
Index: uspace/app/nettest1/nettest1.c
===================================================================
--- uspace/app/nettest1/nettest1.c	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ uspace/app/nettest1/nettest1.c	(revision b3631bc28ac6307c083b19e3b502538bf74cbae9)
@@ -40,4 +40,5 @@
 #include <task.h>
 #include <time.h>
+#include <arg_parse.h>
 
 #include <in.h>
@@ -46,7 +47,7 @@
 #include <socket.h>
 #include <net_err.h>
+#include <socket_parse.h>
 
 #include "nettest.h"
-#include "parse.h"
 #include "print_error.h"
 
@@ -105,8 +106,4 @@
 	struct timeval time_after;
 
-	// print the program label
-	printf("Task %d - ", task_get_id());
-	printf("%s\n", NAME);
-
 	// parse the command line arguments
 	// stop before the last argument if it does not start with the minus sign ('-')
@@ -117,5 +114,5 @@
 				// short options with only one letter
 				case 'f':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, parse_protocol_family));
+					ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family));
 					break;
 				case 'h':
@@ -124,19 +121,19 @@
 					break;
 				case 'm':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 0));
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 0));
 					break;
 				case 'n':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 0));
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 0));
 					break;
 				case 'p':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 0));
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
 					port = (uint16_t) value;
 					break;
 				case 's':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 0));
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
 					size = (value >= 0) ? (size_t) value : 0;
 					break;
 				case 't':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, parse_socket_type));
+					ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type));
 					type = (sock_type_t) value;
 					break;
@@ -147,22 +144,21 @@
 				case '-':
 					if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, parse_protocol_family));
+						ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family));
 					}else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
 						nettest1_print_help();
 						return EOK;
 					}else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 8));
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 8));
 					}else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 8));
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 8));
 					}else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 7));
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
 						port = (uint16_t) value;
 					}else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, parse_socket_type));
+						ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type));
 						type = (sock_type_t) value;
 					}else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
 						verbose = 1;
 					}else{
-						print_unrecognized(index, argv[index] + 2);
 						nettest1_print_help();
 						return EINVAL;
@@ -170,10 +166,8 @@
 					break;
 				default:
-					print_unrecognized(index, argv[index] + 1);
 					nettest1_print_help();
 					return EINVAL;
 			}
 		}else{
-			print_unrecognized(index, argv[index]);
 			nettest1_print_help();
 			return EINVAL;
Index: uspace/app/nettest1/parse.c
===================================================================
--- uspace/app/nettest1/parse.c	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../netecho/parse.c
Index: uspace/app/nettest1/parse.h
===================================================================
--- uspace/app/nettest1/parse.h	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../netecho/parse.h
Index: uspace/app/nettest2/Makefile
===================================================================
--- uspace/app/nettest2/Makefile	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ uspace/app/nettest2/Makefile	(revision b3631bc28ac6307c083b19e3b502538bf74cbae9)
@@ -36,5 +36,4 @@
 	nettest2.c \
 	nettest.c \
-	parse.c \
 	print_error.c
 
Index: uspace/app/nettest2/nettest2.c
===================================================================
--- uspace/app/nettest2/nettest2.c	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ uspace/app/nettest2/nettest2.c	(revision b3631bc28ac6307c083b19e3b502538bf74cbae9)
@@ -40,4 +40,5 @@
 #include <task.h>
 #include <time.h>
+#include <arg_parse.h>
 
 #include <in.h>
@@ -46,7 +47,7 @@
 #include <socket.h>
 #include <net_err.h>
+#include <socket_parse.h>
 
 #include "nettest.h"
-#include "parse.h"
 #include "print_error.h"
 
@@ -105,7 +106,4 @@
 	struct timeval time_after;
 
-	printf("Task %d - ", task_get_id());
-	printf("%s\n", NAME);
-
 	// parse the command line arguments
 	// stop before the last argument if it does not start with the minus sign ('-')
@@ -116,5 +114,5 @@
 				// short options with only one letter
 				case 'f':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, parse_protocol_family));
+					ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family));
 					break;
 				case 'h':
@@ -123,19 +121,19 @@
 					break;
 				case 'm':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 0));
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 0));
 					break;
 				case 'n':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 0));
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 0));
 					break;
 				case 'p':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 0));
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
 					port = (uint16_t) value;
 					break;
 				case 's':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 0));
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
 					size = (value >= 0) ? (size_t) value : 0;
 					break;
 				case 't':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, parse_socket_type));
+					ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type));
 					type = (sock_type_t) value;
 					break;
@@ -146,22 +144,21 @@
 				case '-':
 					if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, parse_protocol_family));
+						ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family));
 					}else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
 						nettest2_print_help();
 						return EOK;
 					}else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 8));
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 8));
 					}else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 8));
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 8));
 					}else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 7));
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
 						port = (uint16_t) value;
 					}else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, parse_socket_type));
+						ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type));
 						type = (sock_type_t) value;
 					}else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
 						verbose = 1;
 					}else{
-						print_unrecognized(index, argv[index] + 2);
 						nettest2_print_help();
 						return EINVAL;
@@ -169,10 +166,8 @@
 					break;
 				default:
-					print_unrecognized(index, argv[index] + 1);
 					nettest2_print_help();
 					return EINVAL;
 			}
 		}else{
-			print_unrecognized(index, argv[index]);
 			nettest2_print_help();
 			return EINVAL;
Index: uspace/app/nettest2/parse.c
===================================================================
--- uspace/app/nettest2/parse.c	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../netecho/parse.c
Index: uspace/app/nettest2/parse.h
===================================================================
--- uspace/app/nettest2/parse.h	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../netecho/parse.h
Index: uspace/app/ping/Makefile
===================================================================
--- uspace/app/ping/Makefile	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ uspace/app/ping/Makefile	(revision b3631bc28ac6307c083b19e3b502538bf74cbae9)
@@ -35,5 +35,4 @@
 SOURCES = \
 	ping.c \
-	parse.c \
 	print_error.c
 
Index: uspace/app/ping/parse.c
===================================================================
--- uspace/app/ping/parse.c	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../netecho/parse.c
Index: uspace/app/ping/parse.h
===================================================================
--- uspace/app/ping/parse.h	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../netecho/parse.h
Index: uspace/app/ping/ping.c
===================================================================
--- uspace/app/ping/ping.c	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ uspace/app/ping/ping.c	(revision b3631bc28ac6307c083b19e3b502538bf74cbae9)
@@ -28,9 +28,9 @@
 
 /** @addtogroup ping
- *  @{
+ * @{
  */
 
 /** @file
- *  Ping application.
+ * Packet Internet Network Grouper.
  */
 
@@ -41,4 +41,6 @@
 #include <ipc/ipc.h>
 #include <ipc/services.h>
+#include <str_error.h>
+#include <arg_parse.h>
 
 #include <icmp_api.h>
@@ -48,252 +50,355 @@
 #include <ip_codes.h>
 #include <socket_errno.h>
-#include <net_err.h>
-
-#include "parse.h"
+#include <socket_parse.h>
+
 #include "print_error.h"
 
-/** Echo module name.
+#define NAME  "ping"
+
+#define CL_OK           0
+#define CL_USAGE        -1
+#define CL_MISSING      -2
+#define CL_INVALID      -3
+#define CL_UNSUPPORTED  -4
+#define CL_ERROR        -5
+
+/** Ping configuration
+ *
  */
-#define NAME	"Ping"
-
-/** Module entry point.
- *  Reads command line parameters and pings.
- *  @param[in] argc The number of command line parameters.
- *  @param[in] argv The command line parameters.
- *  @returns EOK on success.
- */
-int main(int argc, char * argv[]);
-
-/** Prints the application help.
- */
-void ping_print_help(void);
-
-int main(int argc, char * argv[]){
-	ERROR_DECLARE;
-
-	size_t size			= 38;
-	int verbose			= 0;
-	int dont_fragment	= 0;
-	ip_ttl_t ttl		= 0;
-	ip_tos_t tos		= 0;
-	int count			= 3;
-	suseconds_t timeout	= 3000;
-	int family			= AF_INET;
-
-	socklen_t max_length				= sizeof(struct sockaddr_in6);
-	uint8_t address_data[max_length];
-	struct sockaddr * address			= (struct sockaddr *) address_data;
-	struct sockaddr_in * address_in		= (struct sockaddr_in *) address;
-	struct sockaddr_in6 * address_in6	= (struct sockaddr_in6 *) address;
-	socklen_t addrlen;
-	char address_string[INET6_ADDRSTRLEN];
-	uint8_t * address_start;
-	int icmp_phone;
-	struct timeval time_before;
-	struct timeval time_after;
-	int result;
-	int value;
-	int index;
-
-	// print the program label
-	printf("Task %d - ", task_get_id());
-	printf("%s\n", NAME);
-
-	// parse the command line arguments
-	// stop before the last argument if it does not start with the minus sign ('-')
-	for(index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index){
-		// options should start with the minus sign ('-')
-		if(argv[index][0] == '-'){
-			switch(argv[index][1]){
-				// short options with only one letter
-				case 'c':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "count", 0));
-					break;
-				case 'f':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "address family", 0, parse_address_family));
-					break;
-				case 'h':
-					ping_print_help();
-					return EOK;
-					break;
-				case 's':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 0));
-					size = (value >= 0) ? (size_t) value : 0;
-					break;
-				case 't':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "timeout", 0));
-					timeout = (value >= 0) ? (suseconds_t) value : 0;
-					break;
-				case 'v':
-					verbose = 1;
-					break;
-				// long options with the double minus sign ('-')
-				case '-':
-					if(str_lcmp(argv[index] + 2, "count=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "received count", 8));
-					}else if(str_lcmp(argv[index] + 2, "dont_fragment", 13) == 0){
-						dont_fragment = 1;
-					}else if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "address family", 9, parse_address_family));
-					}else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
-						ping_print_help();
-						return EOK;
-					}else if(str_lcmp(argv[index] + 2, "size=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 7));
-						size = (value >= 0) ? (size_t) value : 0;
-					}else if(str_lcmp(argv[index] + 2, "timeout=", 8) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "timeout", 7));
-						timeout = (value >= 0) ? (suseconds_t) value : 0;
-					}else if(str_lcmp(argv[index] + 2, "tos=", 4) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "type of service", 7));
-						tos = (value >= 0) ? (ip_tos_t) value : 0;
-					}else if(str_lcmp(argv[index] + 2, "ttl=", 4) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "time to live", 7));
-						ttl = (value >= 0) ? (ip_ttl_t) value : 0;
-					}else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
-						verbose = 1;
-					}else{
-						print_unrecognized(index, argv[index] + 2);
-						ping_print_help();
-						return EINVAL;
-					}
-					break;
-				default:
-					print_unrecognized(index, argv[index] + 1);
-					ping_print_help();
-					return EINVAL;
-			}
-		}else{
-			print_unrecognized(index, argv[index]);
-			ping_print_help();
-			return EINVAL;
-		}
-	}
-
-	// if not before the last argument containing the address
-	if(index >= argc){
-		printf("Command line error: missing address\n");
-		ping_print_help();
-		return EINVAL;
-	}
-
-	// prepare the address buffer
-	bzero(address_data, max_length);
-	switch(family){
-		case AF_INET:
-			address_in->sin_family = AF_INET;
-			address_start = (uint8_t *) &address_in->sin_addr.s_addr;
-			addrlen = sizeof(struct sockaddr_in);
+typedef struct {
+	bool verbose;               /**< Verbose printouts. */
+	size_t size;                /**< Outgoing packet size. */
+	unsigned int count;         /**< Number of packets to send. */
+	suseconds_t timeout;        /**< Reply wait timeout. */
+	int af;                     /**< Address family. */
+	ip_tos_t tos;               /**< Type of service. */
+	ip_ttl_t ttl;               /**< Time-to-live. */
+	bool fragments;             /**< Fragmentation. */
+	
+	char *dest_addr;            /**< Destination address. */
+	struct sockaddr_in dest;    /**< IPv4 destionation. */
+	struct sockaddr_in6 dest6;  /**< IPv6 destionation. */
+	
+	struct sockaddr *dest_raw;  /**< Raw destination address. */
+	socklen_t dest_len;         /**< Raw destination address length. */
+	
+	/** Converted address string. */
+	char dest_str[INET6_ADDRSTRLEN];
+} ping_config_t;
+
+
+static void usage(void)
+{
+	printf(
+	    "Usage: ping [-c count] [-s size] [-W timeout] [-f family] [-t ttl]\n" \
+	    "            [-Q tos] [--dont_fragment] destination\n" \
+	    "\n" \
+	    "Options:\n" \
+	    "\t-c count\n" \
+	    "\t--count=count\n" \
+	    "\t\tNumber of outgoing packets (default: 4)\n" \
+	    "\n" \
+	    "\t-s size\n" \
+	    "\t--size=bytes\n" \
+	    "\t\tOutgoing packet size (default: 56 bytes)\n" \
+	    "\n" \
+	    "\t-W timeout\n" \
+	    "\t--timeout=ms\n" \
+	    "\t\tReply wait timeout (default: 3000 ms)\n" \
+	    "\n" \
+	    "\t-f family\n" \
+	    "\t--family=family\n" \
+	    "\t\tDestination address family, AF_INET or AF_INET6 (default: AF_INET)\n" \
+	    "\n" \
+	    "\t-t ttl\n" \
+	    "\t--ttl=ttl\n" \
+	    "\t\tOutgoing packet time-to-live (default: 0)\n" \
+	    "\n" \
+	    "\t-Q tos\n" \
+	    "\t--tos=tos\n" \
+	    "\t\tOutgoing packet type of service (default: 0)\n" \
+	    "\n" \
+	    "\t--dont_fragment\n" \
+	    "\t\tDisable packet fragmentation (default: enabled)\n" \
+	    "\n" \
+	    "\t-v\n" \
+	    "\t--verbose\n" \
+	    "\t\tVerbose operation\n" \
+	    "\n" \
+	    "\t-h\n" \
+	    "\t--help\n" \
+	    "\t\tPrint this usage information\n"
+	);
+}
+
+static int arg_short_long(const char *arg, const char *ashort,
+    const char *along)
+{
+	if (str_cmp(arg, ashort) == 0)
+		return 0;
+	
+	if (str_lcmp(arg, along, str_length(along)) == 0)
+		return str_length(along);
+	
+	return -1;
+}
+
+static int args_parse(int argc, char *argv[], ping_config_t *config)
+{
+	if (argc < 2)
+		return CL_USAGE;
+	
+	int i;
+	int ret;
+	
+	for (i = 1; i < argc; i++) {
+		
+		/* Not an option */
+		if (argv[i][0] != '-')
 			break;
-		case AF_INET6:
-			address_in6->sin6_family = AF_INET6;
-			address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
-			addrlen = sizeof(struct sockaddr_in6);
+		
+		/* Options terminator */
+		if (str_cmp(argv[i], "--") == 0) {
+			i++;
+			break;
+		}
+		
+		int off;
+		int tmp;
+		
+		/* Usage */
+		if ((off = arg_short_long(argv[i], "-h", "--help")) != -1)
+			return CL_USAGE;
+		
+		/* Verbose */
+		if ((off = arg_short_long(argv[i], "-v", "--verbose")) != -1) {
+			config->verbose = true;
+			continue;
+		}
+		
+		/* Don't fragment */
+		if (str_cmp(argv[i], "--dont_fragment") == 0) {
+			config->fragments = false;
+			continue;
+		}
+		
+		/* Count */
+		if ((off = arg_short_long(argv[i], "-c", "--count=")) != -1) {
+			ret = arg_parse_int(argc, argv, &i, &tmp, off);
+			
+			if ((ret != EOK) || (tmp < 0))
+				return i;
+			
+			config->count = (unsigned int) tmp;
+			continue;
+		}
+		
+		/* Outgoing packet size */
+		if ((off = arg_short_long(argv[i], "-s", "--size=")) != -1) {
+			ret = arg_parse_int(argc, argv, &i, &tmp, off);
+			
+			if ((ret != EOK) || (tmp < 0))
+				return i;
+			
+			config->size = (size_t) tmp;
+			continue;
+		}
+		
+		/* Reply wait timeout */
+		if ((off = arg_short_long(argv[i], "-W", "--timeout=")) != -1) {
+			ret = arg_parse_int(argc, argv, &i, &tmp, off);
+			
+			if ((ret != EOK) || (tmp < 0))
+				return i;
+			
+			config->timeout = (suseconds_t) tmp;
+			continue;
+		}
+		
+		/* Address family */
+		if ((off = arg_short_long(argv[i], "-f", "--family=")) != -1) {
+			ret = arg_parse_name_int(argc, argv, &i, &config->af, off,
+			    socket_parse_address_family);
+			
+			if (ret != EOK)
+				return i;
+			
+			continue;
+		}
+		
+		/* Type of service */
+		if ((off = arg_short_long(argv[i], "-Q", "--tos=")) != -1) {
+			ret = arg_parse_name_int(argc, argv, &i, &tmp, off,
+			    socket_parse_address_family);
+			
+			if ((ret != EOK) || (tmp < 0))
+				return i;
+			
+			config->tos = (ip_tos_t) tmp;
+			continue;
+		}
+		
+		/* Time to live */
+		if ((off = arg_short_long(argv[i], "-t", "--ttl=")) != -1) {
+			ret = arg_parse_name_int(argc, argv, &i, &tmp, off,
+			    socket_parse_address_family);
+			
+			if ((ret != EOK) || (tmp < 0))
+				return i;
+			
+			config->ttl = (ip_ttl_t) tmp;
+			continue;
+		}
+	}
+	
+	if (i >= argc)
+		return CL_MISSING;
+	
+	config->dest_addr = argv[i];
+	
+	/* Resolve destionation address */
+	switch (config->af) {
+	case AF_INET:
+		config->dest_raw = (struct sockaddr *) &config->dest;
+		config->dest_len = sizeof(config->dest);
+		config->dest.sin_family = config->af;
+		ret = inet_pton(config->af, config->dest_addr,
+		    (uint8_t *) &config->dest.sin_addr.s_addr);
+		break;
+	case AF_INET6:
+		config->dest_raw = (struct sockaddr *) &config->dest6;
+		config->dest_len = sizeof(config->dest6);
+		config->dest6.sin6_family = config->af;
+		ret = inet_pton(config->af, config->dest_addr,
+		    (uint8_t *) &config->dest6.sin6_addr.s6_addr);
+		break;
+	default:
+		return CL_UNSUPPORTED;
+	}
+	
+	if (ret != EOK)
+		return CL_INVALID;
+	
+	/* Convert destination address back to string */
+	switch (config->af) {
+	case AF_INET:
+		ret = inet_ntop(config->af,
+		    (uint8_t *) &config->dest.sin_addr.s_addr,
+		    config->dest_str, sizeof(config->dest_str));
+		break;
+	case AF_INET6:
+		ret = inet_ntop(config->af,
+		    (uint8_t *) &config->dest6.sin6_addr.s6_addr,
+		    config->dest_str, sizeof(config->dest_str));
+		break;
+	default:
+		return CL_UNSUPPORTED;
+	}
+	
+	if (ret != EOK)
+		return CL_ERROR;
+	
+	return CL_OK;
+}
+
+int main(int argc, char *argv[])
+{
+	ping_config_t config;
+	
+	/* Default configuration */
+	config.verbose = false;
+	config.size = 56;
+	config.count = 4;
+	config.timeout = 3000;
+	config.af = AF_INET;
+	config.tos = 0;
+	config.ttl = 0;
+	config.fragments = true;
+	
+	int ret = args_parse(argc, argv, &config);
+	
+	switch (ret) {
+	case CL_OK:
+		break;
+	case CL_USAGE:
+		usage();
+		return 0;
+	case CL_MISSING:
+		fprintf(stderr, "%s: Destination address missing\n", NAME);
+		return 1;
+	case CL_INVALID:
+		fprintf(stderr, "%s: Destination address '%s' invalid or malformed\n",
+		    NAME, config.dest_addr);
+		return 2;
+	case CL_UNSUPPORTED:
+		fprintf(stderr, "%s: Destination address '%s' unsupported\n",
+		    NAME, config.dest_addr);
+		return 3;
+	case CL_ERROR:
+		fprintf(stderr, "%s: Destination address '%s' error\n",
+		    NAME, config.dest_addr);
+		return 4;
+	default:
+		fprintf(stderr, "%s: Unknown or invalid option '%s'\n", NAME,
+		    argv[ret]);
+		return 5;
+	}
+	
+	printf("PING %s (%s) %u(%u) bytes of data\n", config.dest_addr,
+	    config.dest_str, config.size, config.size);
+	
+	int icmp_phone = icmp_connect_module(SERVICE_ICMP, ICMP_CONNECT_TIMEOUT);
+	if (icmp_phone < 0) {
+		fprintf(stderr, "%s: Unable to connect to ICMP service (%s)\n", NAME,
+		    str_error(icmp_phone));
+		return icmp_phone;
+	}
+	
+	unsigned int seq;
+	for (seq = 0; seq < config.count; seq++) {
+		struct timeval t0;
+		ret = gettimeofday(&t0, NULL);
+		if (ret != EOK) {
+			fprintf(stderr, "%s: gettimeofday failed (%s)\n", NAME,
+			    str_error(ret));
+			
+			ipc_hangup(icmp_phone);
+			return ret;
+		}
+		
+		/* Ping! */
+		int result = icmp_echo_msg(icmp_phone, config.size, config.timeout,
+		    config.ttl, config.tos, !config.fragments, config.dest_raw,
+		    config.dest_len);
+		
+		struct timeval t1;
+		ret = gettimeofday(&t1, NULL);
+		if (ret != EOK) {
+			fprintf(stderr, "%s: gettimeofday failed (%s)\n", NAME,
+			    str_error(ret));
+			
+			ipc_hangup(icmp_phone);
+			return ret;
+		}
+		
+		suseconds_t elapsed = tv_sub(&t1, &t0);
+		
+		switch (result) {
+		case ICMP_ECHO:
+			printf("%u bytes from ? (?): icmp_seq=%u ttl=? time=%u.%04u\n",
+				config.size, seq, elapsed / 1000, elapsed % 1000);
+			break;
+		case ETIMEOUT:
+			printf("%u bytes from ? (?): icmp_seq=%u Timed out\n",
+				config.size, seq);
 			break;
 		default:
-			fprintf(stderr, "Address family is not supported\n");
-			return EAFNOSUPPORT;
-	}
-
-	// parse the last argument which should contain the address
-	if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
-		fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
-		return ERROR_CODE;
-	}
-
-	// connect to the ICMP module
-	icmp_phone = icmp_connect_module(SERVICE_ICMP, ICMP_CONNECT_TIMEOUT);
-	if(icmp_phone < 0){
-		fprintf(stderr, "ICMP connect error %d\n", icmp_phone);
-		return icmp_phone;
-	}
-
-	// print the ping header
-	printf("PING %d bytes of data\n", size);
-	if(ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))){
-		fprintf(stderr, "Address error %d\n", ERROR_CODE);
-	}else{
-		printf("Address %s:\n", address_string);
-	}
-
-	// do count times
-	while(count > 0){
-
-		// get the starting time
-		if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
-			fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
-			// release the ICMP phone
-			ipc_hangup(icmp_phone);
-			return ERROR_CODE;
-		}
-
-		// request the ping
-		result = icmp_echo_msg(icmp_phone, size, timeout, ttl, tos, dont_fragment, address, addrlen);
-
-		// get the ending time
-		if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
-			fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
-			// release the ICMP phone
-			ipc_hangup(icmp_phone);
-			return ERROR_CODE;
-		}
-
-		// print the result
-		switch(result){
-			case ICMP_ECHO:
-				printf("Ping round trip time %d miliseconds\n", tv_sub(&time_after, &time_before) / 1000);
-				break;
-			case ETIMEOUT:
-				printf("Timed out.\n");
-				break;
-			default:
-				print_error(stdout, result, NULL, "\n");
-		}
-		-- count;
-	}
-
-	if(verbose){
-		printf("Exiting\n");
-	}
-
-	// release the ICMP phone
+			print_error(stdout, result, NULL, "\n");
+		}
+	}
+	
 	ipc_hangup(icmp_phone);
-
-	return EOK;
-}
-
-void ping_print_help(void){
-	printf(
-		"Network Ping aplication\n" \
-		"Usage: ping [options] numeric_address\n" \
-		"Where options are:\n" \
-		"\n" \
-		"-c request_count | --count=request_count\n" \
-		"\tThe number of packets the application sends. The default is three (3).\n" \
-		"\n" \
-		"--dont_fragment\n" \
-		"\tDisable packet fragmentation.\n"
-		"\n" \
-		"-f address_family | --family=address_family\n" \
-		"\tThe given address family. Only the AF_INET and AF_INET6 are supported.\n"
-		"\n" \
-		"-h | --help\n" \
-		"\tShow this application help.\n"
-		"\n" \
-		"-s packet_size | --size=packet_size\n" \
-		"\tThe packet data size the application sends. The default is 38 bytes.\n" \
-		"\n" \
-		"-t timeout | --timeout=timeout\n" \
-		"\tThe number of miliseconds the application waits for a reply. The default is three thousands (3 000).\n" \
-		"\n" \
-		"--tos=tos\n" \
-		"\tThe type of service to be used.\n" \
-		"\n" \
-		"--ttl=ttl\n" \
-		"\tThe time to live to be used.\n" \
-		"\n" \
-		"-v | --verbose\n" \
-		"\tShow all output messages.\n"
-	);
+	
+	return 0;
 }
 
