Index: uspace/srv/net/app/echo/echo.c
===================================================================
--- uspace/srv/net/app/echo/echo.c	(revision aadf01ebd2c032bc8dd43a6e06ae5715e6c2710f)
+++ uspace/srv/net/app/echo/echo.c	(revision 858fc9083f1f538a864233e8551633863fb17e0b)
@@ -55,4 +55,8 @@
 #define NAME	"Echo"
 
+/** Prints the application help.
+ */
+void echo_print_help(void);
+
 /** Module entry point.
  *  Reads command line parameters and starts listenning.
@@ -62,22 +66,4 @@
  */
 int main(int argc, char * argv[]);
-
-/** Prints the application help.
- */
-void echo_print_help(void);
-
-/** 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.
- */
-int echo_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.
- */
-int echo_parse_socket_type(const char * name);
 
 void echo_print_help(void){
@@ -115,22 +101,4 @@
 }
 
-int echo_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 echo_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;
-}
-
 int main(int argc, char * argv[]){
 	ERROR_DECLARE;
@@ -138,14 +106,14 @@
 	size_t size			= 1024;
 	int verbose			= 0;
-	char * reply			= NULL;
-	sock_type_t type			= SOCK_DGRAM;
+	char * reply		= NULL;
+	sock_type_t type	= SOCK_DGRAM;
 	int count			= -1;
 	int family			= PF_INET;
-	uint16_t port			= 7;
+	uint16_t port		= 7;
 	int backlog			= 3;
 
-	socklen_t max_length		= sizeof(struct sockaddr_in6);
+	socklen_t max_length				= sizeof(struct sockaddr_in6);
 	uint8_t address_data[max_length];
-	struct sockaddr * address		= (struct sockaddr *) address_data;
+	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;
@@ -155,5 +123,5 @@
 	int socket_id;
 	int listening_id;
-	char * 				data;
+	char * data;
 	size_t length;
 	int index;
@@ -161,7 +129,9 @@
 	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){
 		if(argv[index][0] == '-'){
@@ -174,5 +144,5 @@
 					break;
 				case 'f':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, echo_parse_protocol_family));
+					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, parse_protocol_family));
 					break;
 				case 'h':
@@ -192,5 +162,5 @@
 					break;
 				case 't':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, echo_parse_socket_type));
+					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, parse_socket_type));
 					type = (sock_type_t) value;
 					break;
@@ -198,4 +168,5 @@
 					verbose = 1;
 					break;
+				// long options with the double minus sign ('-')
 				case '-':
 					if(str_lcmp(argv[index] + 2, "backlog=", 6) == 0){
@@ -204,5 +175,5 @@
 						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "message 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, echo_parse_protocol_family));
+						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, parse_protocol_family));
 					}else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
 						echo_print_help();
@@ -217,5 +188,5 @@
 						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, echo_parse_socket_type));
+						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, parse_socket_type));
 						type = (sock_type_t) value;
 					}else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
@@ -239,9 +210,10 @@
 	}
 
+	// check the buffer size
 	if(size <= 0){
 		fprintf(stderr, "Receive size too small (%d). Using 1024 bytes instead.\n", size);
 		size = 1024;
 	}
-	// size plus terminating null (\0)
+	// size plus the terminating null (\0)
 	data = (char *) malloc(size + 1);
 	if(! data){
@@ -250,12 +222,8 @@
 	}
 
+	// set the reply size if set
 	reply_length = reply ? str_length(reply) : 0;
 
-	listening_id = socket(family, type, 0);
-	if(listening_id < 0){
-		socket_print_error(stderr, listening_id, "Socket create: ", "\n");
-		return listening_id;
-	}
-
+	// prepare the address buffer
 	bzero(address_data, max_length);
 	switch(family){
@@ -275,4 +243,5 @@
 	}
 
+	// get a listening socket
 	listening_id = socket(family, type, 0);
 	if(listening_id < 0){
@@ -281,9 +250,12 @@
 	}
 
+	// if the stream socket is used
 	if(type == SOCK_STREAM){
+		// check the backlog
 		if(backlog <= 0){
 			fprintf(stderr, "Accepted sockets queue size too small (%d). Using 3 instead.\n", size);
 			backlog = 3;
 		}
+		// set the backlog
 		if(ERROR_OCCURRED(listen(listening_id, backlog))){
 			socket_print_error(stderr, ERROR_CODE, "Socket listen: ", "\n");
@@ -292,4 +264,5 @@
 	}
 
+	// bind the listenning socket
 	if(ERROR_OCCURRED(bind(listening_id, address, addrlen))){
 		socket_print_error(stderr, ERROR_CODE, "Socket bind: ", "\n");
@@ -303,7 +276,11 @@
 	socket_id = listening_id;
 
+	// do count times
+	// or indefinitely if set to a negative value
 	while(count){
+
 		addrlen = max_length;
 		if(type == SOCK_STREAM){
+			// acceept a socket if the stream socket is used
 			socket_id = accept(listening_id, address, &addrlen);
 			if(socket_id <= 0){
@@ -315,5 +292,9 @@
 			}
 		}
+
+		// if the datagram socket is used or the stream socked was accepted
 		if(socket_id > 0){
+
+			// receive an echo request
 			value = recvfrom(socket_id, data, size, 0, address, &addrlen);
 			if(value < 0){
@@ -322,4 +303,7 @@
 				length = (size_t) value;
 				if(verbose){
+					// print the header
+
+					// get the source port and prepare the address buffer
 					address_start = NULL;
 					switch(address->sa_family){
@@ -335,4 +319,5 @@
 							fprintf(stderr, "Address family %d (0x%X) is not supported.\n", address->sa_family);
 					}
+					// parse the source address
 					if(address_start){
 						if(ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))){
@@ -344,8 +329,13 @@
 					}
 				}
+
+				// answer the request either with the static reply or the original data
 				if(ERROR_OCCURRED(sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen))){
 					socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
 				}
-			}
+
+			}
+
+			// close the accepted stream socket
 			if(type == SOCK_STREAM){
 				if(ERROR_OCCURRED(closesocket(socket_id))){
@@ -353,5 +343,8 @@
 				}
 			}
-		}
+
+		}
+
+		// decrease the count if positive
 		if(count > 0){
 			-- count;
@@ -366,4 +359,5 @@
 	}
 
+	// close the listenning socket
 	if(ERROR_OCCURRED(closesocket(listening_id))){
 		socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n");
