Index: uspace/srv/net/tl/tcp/tcp.c
===================================================================
--- uspace/srv/net/tl/tcp/tcp.c	(revision 0578271269331fb048f182ef5c3d26dae37c84ea)
+++ uspace/srv/net/tl/tcp/tcp.c	(revision fb04cba8d949f8b13de326b3aefd058316d54046)
@@ -44,5 +44,5 @@
 #include <fibril_synch.h>
 #include <malloc.h>
-//TODO remove stdio
+/* TODO remove stdio */
 #include <stdio.h>
 #include <errno.h>
@@ -267,7 +267,6 @@
 }
 
-int
-tcp_received_msg(device_id_t device_id, packet_t packet, services_t receiver,
-    services_t error)
+int tcp_received_msg(device_id_t device_id, packet_t packet,
+    services_t receiver, services_t error)
 {
 	int rc;
@@ -309,5 +308,5 @@
 		break;
 	case SERVICE_ICMP:
-		// process error
+		/* Process error */
 		result = icmp_client_process_packet(packet, &type, &code, NULL,
 		    NULL);
@@ -324,5 +323,5 @@
 	}
 
-	// TODO process received ipopts?
+	/* TODO process received ipopts? */
 	result = ip_client_process_packet(packet, NULL, NULL, NULL, NULL, NULL);
 	if (result < 0)
@@ -338,10 +337,10 @@
 		return tcp_release_and_return(packet, NO_DATA);
 
-	// trim all but TCP header
+	/* Trim all but TCP header */
 	rc = packet_trim(packet, offset, 0);
 	if (rc != EOK)
 		return tcp_release_and_return(packet, rc);
 
-	// get tcp header
+	/* Get tcp header */
 	header = (tcp_header_ref) packet_get_data(packet);
 	if (!header)
@@ -361,13 +360,14 @@
 		return tcp_release_and_return(packet, rc);
 	
-	// find the destination socket
+	/* Find the destination socket */
 	socket = socket_port_find(&tcp_globals.sockets,
 	    ntohs(header->destination_port), (const char *) src, addrlen);
 	if (!socket) {
-		// find the listening destination socket
+		/* Find the listening destination socket */
 		socket = socket_port_find(&tcp_globals.sockets,
 		    ntohs(header->destination_port), SOCKET_MAP_KEY_LISTENING,
 		    0);
 	}
+
 	if (!socket) {
 		if (tl_prepare_icmp_packet(tcp_globals.net_phone,
@@ -383,8 +383,8 @@
 	assert(socket_data);
 
-	// some data received, clear the timeout counter
+	/* Some data received, clear the timeout counter */
 	socket_data->timeout_count = 0;
 
-	// count the received packet fragments
+	/* Count the received packet fragments */
 	next_packet = packet;
 	fragments = 0;
@@ -399,5 +399,5 @@
 		total_length += length;
 
-		// add partial checksum if set
+		/* Add partial checksum if set */
 		if (!error) {
 			checksum = compute_checksum(checksum,
@@ -447,5 +447,5 @@
 		    tcp_globals.icmp_phone, packet, error);
 		if (rc == EOK) {
-			// checksum error ICMP
+			/* Checksum error ICMP */
 			icmp_parameter_problem_msg(tcp_globals.icmp_phone,
 			    ICMP_PARAM_POINTER,
@@ -460,5 +460,5 @@
 	fibril_rwlock_read_unlock(&tcp_globals.lock);
 
-	// TODO error reporting/handling
+	/* TODO error reporting/handling */
 	switch (socket_data->state) {
 	case TCP_SOCKET_LISTEN:
@@ -474,11 +474,11 @@
 		break;
 	case TCP_SOCKET_FIN_WAIT_1:
-		// ack changing the state to FIN_WAIT_2 gets processed later
+		/* ack changing the state to FIN_WAIT_2 gets processed later */
 	case TCP_SOCKET_FIN_WAIT_2:
-		// fin changing state to LAST_ACK gets processed later
+		/* fin changing state to LAST_ACK gets processed later */
 	case TCP_SOCKET_LAST_ACK:
-		// ack releasing the socket get processed later
+		/* ack releasing the socket get processed later */
 	case TCP_SOCKET_CLOSING:
-		// ack releasing the socket gets processed later
+		/* ack releasing the socket gets processed later */
 	case TCP_SOCKET_ESTABLISHED:
 		rc = tcp_process_established(socket, socket_data, header,
@@ -497,7 +497,7 @@
 }
 
-int
-tcp_process_established(socket_core_ref socket, tcp_socket_data_ref socket_data,
-    tcp_header_ref header, packet_t packet, int fragments, size_t total_length)
+int tcp_process_established(socket_core_ref socket, tcp_socket_data_ref
+    socket_data, tcp_header_ref header, packet_t packet, int fragments,
+    size_t total_length)
 {
 	packet_t next_packet;
@@ -523,9 +523,9 @@
 		socket_data->fin_incoming = new_sequence_number;
 
-	// trim begining if containing expected data
+	/* Trim begining if containing expected data */
 	if (IS_IN_INTERVAL_OVERFLOW(new_sequence_number,
 	    socket_data->next_incoming, new_sequence_number + total_length)) {
 
-		// get the acknowledged offset
+		/* Get the acknowledged offset */
 		if (socket_data->next_incoming < new_sequence_number) {
 			offset = new_sequence_number -
@@ -539,7 +539,8 @@
 		total_length -= offset;
 		length = packet_get_data_length(packet);
-		// trim the acknowledged data
+
+		/* Trim the acknowledged data */
 		while (length <= offset) {
-			// release the acknowledged packets
+			/* Release the acknowledged packets */
 			next_packet = pq_next(packet);
 			pq_release_remote(tcp_globals.net_phone,
@@ -559,5 +560,5 @@
 	}
 
-	// release if overflowing the window
+	/* Release if overflowing the window */
 /*
 	if (IS_IN_INTERVAL_OVERFLOW(socket_data->next_incoming +
@@ -609,11 +610,11 @@
 	}
 */
-	// the expected one arrived?
+	/* The expected one arrived? */
 	if (new_sequence_number == socket_data->next_incoming) {
 		printf("expected\n");
-		// process acknowledgement
+		/* Process acknowledgement */
 		tcp_process_acknowledgement(socket, socket_data, header);
 
-		// remove the header
+		/* Remove the header */
 		total_length -= TCP_HEADER_LENGTH(header);
 		rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0);
@@ -635,5 +636,5 @@
 			rc = pq_get_order(socket_data->incoming, &order, NULL);
 			if (rc != EOK) {
-				// remove the corrupted packet
+				/* Remove the corrupted packet */
 				next_packet = pq_detach(packet);
 				if (packet == socket_data->incoming)
@@ -648,18 +649,18 @@
 			if (IS_IN_INTERVAL_OVERFLOW(sequence_number,
 			    old_incoming, socket_data->next_incoming)) {
-				// move to the next
+				/* Move to the next */
 				packet = pq_next(packet);
-				// coninual data?
+				/* Coninual data? */
 			} else if (IS_IN_INTERVAL_OVERFLOW(old_incoming,
 			    sequence_number, socket_data->next_incoming)) {
-				// detach the packet
+				/* Detach the packet */
 				next_packet = pq_detach(packet);
 				if (packet == socket_data->incoming)
 					socket_data->incoming = next_packet;
-				// get data length
+				/* Get data length */
 				length = packet_get_data_length(packet);
 				new_sequence_number = sequence_number + length;
 				if (length <= 0) {
-					// remove the empty packet
+					/* Remove the empty packet */
 					pq_release_remote(tcp_globals.net_phone,
 					    packet_get_id(packet));
@@ -667,8 +668,8 @@
 					continue;
 				}
-				// exactly following
+				/* Exactly following */
 				if (sequence_number ==
 				    socket_data->next_incoming) {
-					// queue received data
+					/* Queue received data */
 					rc = tcp_queue_received_packet(socket,
 					    socket_data, packet, 1,
@@ -680,5 +681,5 @@
 					packet = next_packet;
 					continue;
-					// at least partly following data?
+					/* At least partly following data? */
 				}
 				if (IS_IN_INTERVAL_OVERFLOW(sequence_number,
@@ -695,5 +696,5 @@
 					rc = packet_trim(packet,length, 0);
 					if (rc == EOK) {
-						// queue received data
+						/* Queue received data */
 						rc = tcp_queue_received_packet(
 						    socket, socket_data, packet,
@@ -708,5 +709,5 @@
 					}
 				}
-				// remove the duplicit or corrupted packet
+				/* Remove the duplicit or corrupted packet */
 				pq_release_remote(tcp_globals.net_phone,
 				    packet_get_id(packet));
@@ -721,8 +722,8 @@
 	    socket_data->next_incoming + socket_data->window)) {
 		printf("in window\n");
-		// process acknowledgement
+		/* Process acknowledgement */
 		tcp_process_acknowledgement(socket, socket_data, header);
 
-		// remove the header
+		/* Remove the header */
 		total_length -= TCP_HEADER_LENGTH(header);
 		rc = packet_trim(packet, TCP_HEADER_LENGTH(header), 0);
@@ -735,5 +736,5 @@
 		    length);
 		if (rc != EOK) {
-			// remove the corrupted packets
+			/* Remove the corrupted packets */
 			pq_release_remote(tcp_globals.net_phone,
 			    packet_get_id(packet));
@@ -762,9 +763,9 @@
 	} else {
 		printf("unexpected\n");
-		// release duplicite or restricted
+		/* Release duplicite or restricted */
 		pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 	}
 
-	// change state according to the acknowledging incoming fin
+	/* Change state according to the acknowledging incoming fin */
 	if (IS_IN_INTERVAL_OVERFLOW(old_incoming, socket_data->fin_incoming,
 	    socket_data->next_incoming)) {
@@ -775,5 +776,5 @@
 			socket_data->state = TCP_SOCKET_CLOSING;
 			break;
-			//case TCP_ESTABLISHED:
+		/*case TCP_ESTABLISHED:*/
 		default:
 			socket_data->state = TCP_SOCKET_CLOSE_WAIT;
@@ -784,5 +785,5 @@
 	packet = tcp_get_packets_to_send(socket, socket_data);
 	if (!packet) {
-		// create the notification packet
+		/* Create the notification packet */
 		rc = tcp_create_notification_packet(&packet, socket,
 		    socket_data, 0, 0);
@@ -798,5 +799,5 @@
 	fibril_rwlock_write_unlock(socket_data->local_lock);
 
-	// send the packet
+	/* Send the packet */
 	tcp_send_packets(socket_data->device_id, packet);
 
@@ -804,6 +805,5 @@
 }
 
-int
-tcp_queue_received_packet(socket_core_ref socket,
+int tcp_queue_received_packet(socket_core_ref socket,
     tcp_socket_data_ref socket_data, packet_t packet, int fragments,
     size_t total_length)
@@ -819,5 +819,5 @@
 	assert(socket_data->window > total_length);
 
-	// queue the received packet
+	/* Queue the received packet */
 	rc = dyn_fifo_push(&socket->received, packet_get_id(packet),
 	    SOCKET_MAX_RECEIVED_SIZE);
@@ -829,8 +829,8 @@
 		return tcp_release_and_return(packet, rc);
 
-	// decrease the window size
+	/* Decrease the window size */
 	socket_data->window -= total_length;
 
-	// notify the destination socket
+	/* Notify the destination socket */
 	async_msg_5(socket->phone, NET_SOCKET_RECEIVED,
 	    (ipcarg_t) socket->socket_id,
@@ -842,7 +842,6 @@
 }
 
-int
-tcp_process_syn_sent(socket_core_ref socket, tcp_socket_data_ref socket_data,
-    tcp_header_ref header, packet_t packet)
+int tcp_process_syn_sent(socket_core_ref socket, tcp_socket_data_ref
+    socket_data, tcp_header_ref header, packet_t packet)
 {
 	packet_t next_packet;
@@ -858,9 +857,10 @@
 		return tcp_release_and_return(packet, EINVAL);
 	
-	// process acknowledgement
+	/* Process acknowledgement */
 	tcp_process_acknowledgement(socket, socket_data, header);
 
 	socket_data->next_incoming = ntohl(header->sequence_number) + 1;
-	// release additional packets
+
+	/* Release additional packets */
 	next_packet = pq_detach(packet);
 	if (next_packet) {
@@ -868,5 +868,6 @@
 		    packet_get_id(next_packet));
 	}
-	// trim if longer than the header
+
+	/* Trim if longer than the header */
 	if (packet_get_data_length(packet) > sizeof(*header)) {
 		rc = packet_trim(packet, 0,
@@ -875,8 +876,10 @@
 			return tcp_release_and_return(packet, rc);
 	}
+
 	tcp_prepare_operation_header(socket, socket_data, header, 0, 0);
 	fibril_mutex_lock(&socket_data->operation.mutex);
 	socket_data->operation.result = tcp_queue_packet(socket, socket_data,
 	    packet, 1);
+
 	if (socket_data->operation.result == EOK) {
 		socket_data->state = TCP_SOCKET_ESTABLISHED;
@@ -884,7 +887,7 @@
 		if (packet) {
 			fibril_rwlock_write_unlock( socket_data->local_lock);
-			// send the packet
+			/* Send the packet */
 			tcp_send_packets(socket_data->device_id, packet);
-			// signal the result
+			/* Signal the result */
 			fibril_condvar_signal( &socket_data->operation.condvar);
 			fibril_mutex_unlock( &socket_data->operation.mutex);
@@ -892,10 +895,10 @@
 		}
 	}
+
 	fibril_mutex_unlock(&socket_data->operation.mutex);
 	return tcp_release_and_return(packet, EINVAL);
 }
 
-int
-tcp_process_listen(socket_core_ref listening_socket,
+int tcp_process_listen(socket_core_ref listening_socket,
     tcp_socket_data_ref listening_socket_data, tcp_header_ref header,
     packet_t packet, struct sockaddr *src, struct sockaddr *dest,
@@ -936,4 +939,5 @@
 		return tcp_release_and_return(packet, ENOMEM);
 	}
+
 	memcpy(socket_data->addr, src, socket_data->addrlen);
 	socket_data->dest_port = ntohs(header->source_port);
@@ -946,5 +950,5 @@
 	}
 
-	// create a socket
+	/* Create a socket */
 	socket_id = -1;
 	rc = socket_create(socket_data->local_sockets, listening_socket->phone,
@@ -965,5 +969,5 @@
 	fibril_rwlock_write_lock(&tcp_globals.lock);
 
-	// find the destination socket
+	/* Find the destination socket */
 	listening_socket = socket_port_find(&tcp_globals.sockets,
 	    listening_port, SOCKET_MAP_KEY_LISTENING, 0);
@@ -971,5 +975,5 @@
 	    (listening_socket->socket_id != listening_socket_id)) {
 		fibril_rwlock_write_unlock(&tcp_globals.lock);
-		// a shadow may remain until app hangs up
+		/* A shadow may remain until app hangs up */
 		return tcp_release_and_return(packet, EOK /*ENOTSOCK*/);
 	}
@@ -983,5 +987,5 @@
 	    socket_id);
 	if (!socket) {
-		// where is the socket?!?
+		/* Where is the socket?!? */
 		fibril_rwlock_write_unlock(&tcp_globals.lock);
 		return ENOTSOCK;
@@ -1010,5 +1014,5 @@
 	socket_data->next_incoming = ntohl(header->sequence_number) + 1;
 
-	// release additional packets
+	/* Release additional packets */
 	next_packet = pq_detach(packet);
 	if (next_packet) {
@@ -1017,5 +1021,5 @@
 	}
 
-	// trim if longer than the header
+	/* Trim if longer than the header */
 	if (packet_get_data_length(packet) > sizeof(*header)) {
 		rc = packet_trim(packet, 0,
@@ -1050,5 +1054,5 @@
 	fibril_rwlock_write_unlock(socket_data->local_lock);
 
-	// send the packet
+	/* Send the packet */
 	tcp_send_packets(socket_data->device_id, packet);
 
@@ -1056,6 +1060,5 @@
 }
 
-int
-tcp_process_syn_received(socket_core_ref socket,
+int tcp_process_syn_received(socket_core_ref socket,
     tcp_socket_data_ref socket_data, tcp_header_ref header, packet_t packet)
 {
@@ -1073,5 +1076,5 @@
 		return tcp_release_and_return(packet, EINVAL);
 
-	// process acknowledgement
+	/* Process acknowledgement */
 	tcp_process_acknowledgement(socket, socket_data, header);
 
@@ -1086,9 +1089,9 @@
 		assert(listening_socket_data);
 
-		// queue the received packet
+		/* Queue the received packet */
 		rc = dyn_fifo_push(&listening_socket->accepted,
 		    (-1 * socket->socket_id), listening_socket_data->backlog);
 		if (rc == EOK) {
-			// notify the destination socket
+			/* Notify the destination socket */
 			async_msg_5(socket->phone, NET_SOCKET_ACCEPTED,
 			    (ipcarg_t) listening_socket->socket_id,
@@ -1100,22 +1103,22 @@
 		}
 	}
-	// send FIN
+	/* Send FIN */
 	socket_data->state = TCP_SOCKET_FIN_WAIT_1;
 
-	// create the notification packet
+	/* Create the notification packet */
 	rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1);
 	if (rc != EOK)
 		return rc;
 
-	// send the packet
+	/* Send the packet */
 	rc = tcp_queue_packet(socket, socket_data, packet, 1);
 	if (rc != EOK)
 		return rc;
 
-	// flush packets
+	/* Flush packets */
 	packet = tcp_get_packets_to_send(socket, socket_data);
 	fibril_rwlock_write_unlock(socket_data->local_lock);
 	if (packet) {
-		// send the packet
+		/* Send the packet */
 		tcp_send_packets(socket_data->device_id, packet);
 	}
@@ -1124,6 +1127,5 @@
 }
 
-void
-tcp_process_acknowledgement(socket_core_ref socket,
+void tcp_process_acknowledgement(socket_core_ref socket,
     tcp_socket_data_ref socket_data, tcp_header_ref header)
 {
@@ -1144,5 +1146,6 @@
 
 	number = ntohl(header->acknowledgement_number);
-	// if more data acknowledged
+
+	/* If more data acknowledged */
 	if (number != socket_data->expected) {
 		old = socket_data->expected;
@@ -1155,6 +1158,8 @@
 			case TCP_SOCKET_LAST_ACK:
 			case TCP_SOCKET_CLOSING:
-				// fin acknowledged - release the socket in
-				// another fibril
+				/*
+				 * FIN acknowledged - release the socket in
+				 * another fibril.
+				 */
 				tcp_prepare_timeout(tcp_release_after_timeout,
 				    socket, socket_data, 0,
@@ -1166,5 +1171,6 @@
 			}
 		}
-		// update the treshold if higher than set
+
+		/* Update the treshold if higher than set */
 		if (number + ntohs(header->window) >
 		    socket_data->expected + socket_data->treshold) {
@@ -1172,5 +1178,6 @@
 			    socket_data->expected;
 		}
-		// set new expected sequence number
+
+		/* Set new expected sequence number */
 		socket_data->expected = number;
 		socket_data->expected_count = 1;
@@ -1184,5 +1191,5 @@
 					socket_data->outgoing = next;
 
-				// add to acknowledged or release
+				/* Add to acknowledged or release */
 				if (pq_add(&acknowledged, packet, 0, 0) != EOK)
 					pq_release_remote(tcp_globals.net_phone,
@@ -1192,5 +1199,6 @@
 				break;
 		}
-		// release acknowledged
+
+		/* Release acknowledged */
 		if (acknowledged) {
 			pq_release_remote(tcp_globals.net_phone,
@@ -1198,12 +1206,13 @@
 		}
 		return;
-		// if the same as the previous time
-	}
+		/* If the same as the previous time */
+	}
+
 	if (number == socket_data->expected) {
-		// increase the counter
+		/* Increase the counter */
 		socket_data->expected_count++;
 		if (socket_data->expected_count == TCP_FAST_RETRANSMIT_COUNT) {
 			socket_data->expected_count = 1;
-			// TODO retransmit lock
+			/* TODO retransmit lock */
 			//tcp_retransmit_packet(socket, socket_data, number);
 		}
@@ -1311,12 +1320,12 @@
 	while (keep_on_going) {
 
-		// answer the call
+		/* Answer the call */
 		answer_call(callid, res, &answer, answer_count);
-		// refresh data
+		/* Refresh data */
 		refresh_answer(&answer, &answer_count);
-		// get the next call
+		/* Get the next call */
 		callid = async_get_call(&call);
 
-		// process the call
+		/* Process the call */
 		switch (IPC_GET_METHOD(call)) {
 		case IPC_M_PHONE_HUNGUP:
@@ -1401,6 +1410,8 @@
 			if (res != EOK)
 				break;
-			// the global lock may be released in the
-			// tcp_connect_message() function
+			/*
+			 * The global lock may be released in the
+			 * tcp_connect_message() function.
+			 */
 			fibril_rwlock_write_lock(&tcp_globals.lock);
 			fibril_rwlock_write_lock(&lock);
@@ -1516,9 +1527,9 @@
 	}
 
-	// release the application phone
+	/* Release the application phone */
 	ipc_hangup(app_phone);
 
 	printf("release\n");
-	// release all local sockets
+	/* Release all local sockets */
 	socket_cores_release(tcp_globals.net_phone, &local_sockets,
 	    &tcp_globals.sockets, tcp_free_socket_data);
@@ -1536,7 +1547,7 @@
 	assert(timeout);
 
-	// sleep the given timeout
+	/* Sleep the given timeout */
 	async_usleep(timeout->timeout);
-	// lock the globals
+	/* Lock the globals */
 	if (timeout->globals_read_only) 
 		fibril_rwlock_read_lock(&tcp_globals.lock);
@@ -1544,5 +1555,5 @@
 		fibril_rwlock_write_lock(&tcp_globals.lock);
 
-	// find the pending operation socket
+	/* Find the pending operation socket */
 	socket = socket_port_find(&tcp_globals.sockets, timeout->port,
 	    timeout->key, timeout->key_length);
@@ -1557,12 +1568,12 @@
 	fibril_rwlock_write_lock(socket_data->local_lock);
 	if (timeout->sequence_number) {
-		// increase the timeout counter;
+		/* Increase the timeout counter */
 		socket_data->timeout_count++;
 		if (socket_data->timeout_count == TCP_MAX_TIMEOUTS) {
-			// TODO release as connection lost
+			/* TODO release as connection lost */
 			//tcp_refresh_socket_data(socket_data);
 			fibril_rwlock_write_unlock(socket_data->local_lock);
 		} else {
-			// retransmit
+			/* Retransmit */
 //                      tcp_retransmit_packet(socket,
 //			    socket_data, timeout->sequence_number);
@@ -1571,16 +1582,19 @@
 	} else {
 		fibril_mutex_lock(&socket_data->operation.mutex);
-		// set the timeout operation result if state not
-		// changed
+		/* Set the timeout operation result if state not changed */
 		if (socket_data->state == timeout->state) {
 			socket_data->operation.result = ETIMEOUT;
-			// notify the main fibril
+
+			/* Notify the main fibril */
 			fibril_condvar_signal(&socket_data->operation.condvar);
-			// keep the global write lock
+
+			/* Keep the global write lock */
 			keep_write_lock = true;
 		} else {
-			// operation is ok, do nothing
-			// unlocking from now on, so the unlocki
-			// order does not matter...
+			/*
+			 * Operation is ok, do nothing.
+			 * Unlocking from now on, so the unlocking
+			 * order does not matter.
+			 */
 			fibril_rwlock_write_unlock(socket_data->local_lock);
 		}
@@ -1589,12 +1603,12 @@
 
 out:
-	// unlock only if no socket
+	/* Unlock only if no socket */
 	if (timeout->globals_read_only)
 		fibril_rwlock_read_unlock(&tcp_globals.lock);
 	else if (!keep_write_lock)
-		// release if not desired
+		/* Release if not desired */
 		fibril_rwlock_write_unlock(&tcp_globals.lock);
 	
-	// release the timeout structure
+	/* Release the timeout structure */
 	free(timeout);
 	return EOK;
@@ -1610,11 +1624,14 @@
 	assert(timeout);
 
-	// sleep the given timeout
+	/* Sleep the given timeout */
 	async_usleep(timeout->timeout);
-	// lock the globals
+
+	/* Lock the globals */
 	fibril_rwlock_write_lock(&tcp_globals.lock);
-	// find the pending operation socket
+
+	/* Find the pending operation socket */
 	socket = socket_port_find(&tcp_globals.sockets, timeout->port,
 	    timeout->key, timeout->key_length);
+
 	if (socket && (socket->socket_id == timeout->socket_id)) {
 		socket_data = (tcp_socket_data_ref) socket->specific_data;
@@ -1629,14 +1646,16 @@
 		}
 	}
-	// unlock the globals
+
+	/* Unlock the globals */
 	fibril_rwlock_write_unlock(&tcp_globals.lock);
-	// release the timeout structure
+
+	/* Release the timeout structure */
 	free(timeout);
+
 	return EOK;
 }
 
-void
-tcp_retransmit_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
-    size_t sequence_number)
+void tcp_retransmit_packet(socket_core_ref socket, tcp_socket_data_ref
+    socket_data, size_t sequence_number)
 {
 	packet_t packet;
@@ -1648,5 +1667,5 @@
 	assert(socket->specific_data == socket_data);
 
-	// sent packet?
+	/* Sent packet? */
 	packet = pq_find(socket_data->outgoing, sequence_number);
 	printf("retransmit %d\n", packet_get_id(packet));
@@ -1664,6 +1683,6 @@
 }
 
-int
-tcp_listen_message(socket_cores_ref local_sockets, int socket_id, int backlog)
+int tcp_listen_message(socket_cores_ref local_sockets, int socket_id,
+    int backlog)
 {
 	socket_core_ref socket;
@@ -1675,13 +1694,14 @@
 		return EINVAL;
 
-	// find the socket
+	/* Find the socket */
 	socket = socket_cores_find(local_sockets, socket_id);
 	if (!socket) 
 		return ENOTSOCK;
 	
-	// get the socket specific data
+	/* Get the socket specific data */
 	socket_data = (tcp_socket_data_ref) socket->specific_data;
 	assert(socket_data);
-	// set the backlog
+
+	/* Set the backlog */
 	socket_data->backlog = backlog;
 
@@ -1689,6 +1709,5 @@
 }
 
-int
-tcp_connect_message(socket_cores_ref local_sockets, int socket_id,
+int tcp_connect_message(socket_cores_ref local_sockets, int socket_id,
     struct sockaddr *addr, socklen_t addrlen)
 {
@@ -1700,5 +1719,5 @@
 	assert(addrlen > 0);
 
-	// find the socket
+	/* Find the socket */
 	socket = socket_cores_find(local_sockets, socket_id);
 	if (!socket)
@@ -1708,5 +1727,5 @@
 	if (rc != EOK) {
 		tcp_free_socket_data(socket);
-		// unbind if bound
+		/* Unbind if bound */
 		if (socket->port > 0) {
 			socket_ports_exclude(&tcp_globals.sockets,
@@ -1718,6 +1737,5 @@
 }
 
-int
-tcp_connect_core(socket_core_ref socket, socket_cores_ref local_sockets,
+int tcp_connect_core(socket_core_ref socket, socket_cores_ref local_sockets,
     struct sockaddr *addr, socklen_t addrlen)
 {
@@ -1730,5 +1748,5 @@
 	assert(addrlen > 0);
 
-	// get the socket specific data
+	/* Get the socket specific data */
 	socket_data = (tcp_socket_data_ref) socket->specific_data;
 	assert(socket_data);
@@ -1739,5 +1757,5 @@
 		return EINVAL;
 
-	// get the destination port
+	/* Get the destination port */
 	rc = tl_get_address_port(addr, addrlen, &socket_data->dest_port);
 	if (rc != EOK)
@@ -1745,5 +1763,5 @@
 	
 	if (socket->port <= 0) {
-		// try to find a free port
+		/* Try to find a free port */
 		rc = socket_bind_free_port(&tcp_globals.sockets, socket,
 		    TCP_FREE_PORTS_START, TCP_FREE_PORTS_END,
@@ -1751,5 +1769,5 @@
 		if (rc != EOK)
 			return rc;
-		// set the next port as the search starting port number
+		/* Set the next port as the search starting port number */
 		tcp_globals.last_used_port = socket->port;
 	}
@@ -1761,15 +1779,16 @@
 		return rc;
 
-	// create the notification packet
+	/* Create the notification packet */
 	rc = tcp_create_notification_packet(&packet, socket, socket_data, 1, 0);
 	if (rc != EOK)
 		return rc;
 
-	// unlock the globals and wait for an operation
+	/* Unlock the globals and wait for an operation */
 	fibril_rwlock_write_unlock(&tcp_globals.lock);
 
 	socket_data->addr = addr;
 	socket_data->addrlen = addrlen;
-	// send the packet
+
+	/* Send the packet */
 
 	if (((rc = tcp_queue_packet(socket, socket_data, packet, 1)) != EOK) ||
@@ -1785,9 +1804,10 @@
 			fibril_mutex_lock(&socket_data->operation.mutex);
 			fibril_rwlock_write_unlock(socket_data->local_lock);
-			// send the packet
+
+			/* Send the packet */
 			printf("connecting %d\n", packet_get_id(packet));
 			tcp_send_packets(socket_data->device_id, packet);
 
-			// wait for a reply
+			/* Wait for a reply */
 			fibril_condvar_wait(&socket_data->operation.condvar,
 			    &socket_data->operation.mutex);
@@ -1805,11 +1825,8 @@
 
 	fibril_mutex_unlock(&socket_data->operation.mutex);
-
-	// return the result
 	return rc;
 }
 
-int
-tcp_queue_prepare_packet(socket_core_ref socket,
+int tcp_queue_prepare_packet(socket_core_ref socket,
     tcp_socket_data_ref socket_data, packet_t packet, size_t data_length)
 {
@@ -1821,5 +1838,5 @@
 	assert(socket->specific_data == socket_data);
 
-	// get tcp header
+	/* Get TCP header */
 	header = (tcp_header_ref) packet_get_data(packet);
 	if (!header)
@@ -1835,5 +1852,5 @@
 		return tcp_release_and_return(packet, EINVAL);
 
-	// remember the outgoing FIN
+	/* Remember the outgoing FIN */
 	if (header->finalize) 
 		socket_data->fin_outgoing = socket_data->next_outgoing;
@@ -1842,6 +1859,5 @@
 }
 
-int
-tcp_queue_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
+int tcp_queue_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
     packet_t packet, size_t data_length)
 {
@@ -1865,6 +1881,6 @@
 }
 
-packet_t
-tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_ref socket_data)
+packet_t tcp_get_packets_to_send(socket_core_ref socket, tcp_socket_data_ref
+    socket_data)
 {
 	packet_t packet;
@@ -1883,6 +1899,8 @@
 		pq_get_order(packet, NULL, &data_length);
 
-		// send only if fits into the window
-		// respecting the possible overflow
+		/*
+		 * Send only if fits into the window, respecting the possible
+		 * overflow.
+		 */
 		if (!IS_IN_INTERVAL_OVERFLOW(
 		    (uint32_t) socket_data->last_outgoing,
@@ -1909,9 +1927,10 @@
 		previous = copy;
 		packet = pq_next(packet);
-		// overflow occurred ?
+
+		/* Overflow occurred? */
 		if (!packet &&
 		    (socket_data->last_outgoing > socket_data->next_outgoing)) {
 			printf("gpts overflow\n");
-			// continue from the beginning
+			/* Continue from the beginning */
 			packet = socket_data->outgoing;
 		}
@@ -1922,7 +1941,6 @@
 }
 
-packet_t
-tcp_send_prepare_packet(socket_core_ref socket, tcp_socket_data_ref socket_data,
-    packet_t packet, size_t data_length, size_t sequence_number)
+packet_t tcp_send_prepare_packet(socket_core_ref socket, tcp_socket_data_ref
+    socket_data, packet_t packet, size_t data_length, size_t sequence_number)
 {
 	tcp_header_ref header;
@@ -1934,5 +1952,5 @@
 	assert(socket->specific_data == socket_data);
 
-	// adjust the pseudo header
+	/* Adjust the pseudo header */
 	rc = ip_client_set_pseudo_header_data_length(socket_data->pseudo_header,
 	    socket_data->headerlen, packet_get_data_length(packet));
@@ -1942,5 +1960,5 @@
 	}
 
-	// get the header
+	/* Get the header */
 	header = (tcp_header_ref) packet_get_data(packet);
 	if (!header) {
@@ -1950,5 +1968,5 @@
 	assert(ntohl(header->sequence_number) == sequence_number);
 
-	// adjust the header
+	/* Adjust the header */
 	if (socket_data->next_incoming) {
 		header->acknowledgement_number =
@@ -1958,5 +1976,5 @@
 	header->window = htons(socket_data->window);
 
-	// checksum
+	/* Checksum */
 	header->checksum = 0;
 	checksum = compute_checksum(0, socket_data->pseudo_header,
@@ -1967,5 +1985,5 @@
 	header->checksum = htons(flip_checksum(compact_checksum(checksum)));
 
-	// prepare the packet
+	/* Prepare the packet */
 	rc = ip_client_prepare_packet(packet, IPPROTO_TCP, 0, 0, 0, 0);
 	if (rc != EOK) {
@@ -1973,4 +1991,5 @@
 		return NULL;
 	}
+
 	rc = tcp_prepare_timeout(tcp_timeout, socket, socket_data,
 	    sequence_number, socket_data->state, socket_data->timeout, true);
@@ -1983,7 +2002,6 @@
 }
 
-packet_t
-tcp_prepare_copy(socket_core_ref socket, tcp_socket_data_ref socket_data,
-    packet_t packet, size_t data_length, size_t sequence_number)
+packet_t tcp_prepare_copy(socket_core_ref socket, tcp_socket_data_ref
+    socket_data, packet_t packet, size_t data_length, size_t sequence_number)
 {
 	packet_t copy;
@@ -1993,5 +2011,5 @@
 	assert(socket->specific_data == socket_data);
 
-	// make a copy of the packet
+	/* Make a copy of the packet */
 	copy = packet_get_copy(tcp_globals.net_phone, packet);
 	if (!copy)
@@ -2014,6 +2032,5 @@
 }
 
-void
-tcp_prepare_operation_header(socket_core_ref socket,
+void tcp_prepare_operation_header(socket_core_ref socket,
     tcp_socket_data_ref socket_data, tcp_header_ref header, int synchronize,
     int finalize)
@@ -2032,6 +2049,5 @@
 }
 
-int
-tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t),
+int tcp_prepare_timeout(int (*timeout_function)(void *tcp_timeout_t),
     socket_core_ref socket, tcp_socket_data_ref socket_data,
     size_t sequence_number, tcp_socket_state_t state, suseconds_t timeout,
@@ -2045,5 +2061,5 @@
 	assert(socket->specific_data == socket_data);
 
-	// prepare the timeout with key bundle structure
+	/* Prepare the timeout with key bundle structure */
 	operation_timeout = malloc(sizeof(*operation_timeout) +
 	    socket->key_length + 1);
@@ -2060,5 +2076,5 @@
 	operation_timeout->state = state;
 
-	// copy the key
+	/* Copy the key */
 	operation_timeout->key = ((char *) operation_timeout) +
 	    sizeof(*operation_timeout);
@@ -2067,5 +2083,5 @@
 	operation_timeout->key[operation_timeout->key_length] = '\0';
 
-	// prepare the timeouting thread
+	/* Prepare the timeouting thread */
 	fibril = fibril_create(timeout_function, operation_timeout);
 	if (!fibril) {
@@ -2074,5 +2090,5 @@
 	}
 //      fibril_mutex_lock(&socket_data->operation.mutex);
-	// start the timeouting fibril
+	/* Start the timeout fibril */
 	fibril_add_ready(fibril);
 	//socket_data->state = state;
@@ -2080,7 +2096,6 @@
 }
 
-int
-tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags,
-    size_t *addrlen)
+int tcp_recvfrom_message(socket_cores_ref local_sockets, int socket_id,
+    int flags, size_t *addrlen)
 {
 	socket_core_ref socket;
@@ -2093,10 +2108,10 @@
 	assert(local_sockets);
 
-	// find the socket
+	/* Find the socket */
 	socket = socket_cores_find(local_sockets, socket_id);
 	if (!socket)
 		return ENOTSOCK;
 
-	// get the socket specific data
+	/* Get the socket specific data */
 	if (!socket->specific_data)
 		return NO_DATA;
@@ -2104,10 +2119,10 @@
 	socket_data = (tcp_socket_data_ref) socket->specific_data;
 
-	// check state
+	/* Check state */
 	if ((socket_data->state != TCP_SOCKET_ESTABLISHED) &&
 	    (socket_data->state != TCP_SOCKET_CLOSE_WAIT))
 		return ENOTCONN;
 
-	// send the source address if desired
+	/* Send the source address if desired */
 	if (addrlen) {
 		rc = data_reply(socket_data->addr, socket_data->addrlen);
@@ -2117,5 +2132,5 @@
 	}
 
-	// get the next received packet
+	/* Get the next received packet */
 	packet_id = dyn_fifo_value(&socket->received);
 	if (packet_id < 0)
@@ -2126,19 +2141,19 @@
 		return rc;
 
-	// reply the packets
+	/* Reply the packets */
 	rc = socket_reply_packets(packet, &length);
 	if (rc != EOK)
 		return rc;
 
-	// release the packet
+	/* Release the packet */
 	dyn_fifo_pop(&socket->received);
 	pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
-	// return the total length
+
+	/* Return the total length */
 	return (int) length;
 }
 
-int
-tcp_send_message(socket_cores_ref local_sockets, int socket_id, int fragments,
-    size_t *data_fragment_size, int flags)
+int tcp_send_message(socket_cores_ref local_sockets, int socket_id,
+    int fragments, size_t *data_fragment_size, int flags)
 {
 	socket_core_ref socket;
@@ -2155,10 +2170,10 @@
 	assert(data_fragment_size);
 
-	// find the socket
+	/* Find the socket */
 	socket = socket_cores_find(local_sockets, socket_id);
 	if (!socket)
 		return ENOTSOCK;
 
-	// get the socket specific data
+	/* Get the socket specific data */
 	if (!socket->specific_data)
 		return NO_DATA;
@@ -2166,5 +2181,5 @@
 	socket_data = (tcp_socket_data_ref) socket->specific_data;
 
-	// check state
+	/* Check state */
 	if ((socket_data->state != TCP_SOCKET_ESTABLISHED) &&
 	    (socket_data->state != TCP_SOCKET_CLOSE_WAIT))
@@ -2181,5 +2196,5 @@
 
 	for (index = 0; index < fragments; index++) {
-		// read the data fragment
+		/* Read the data fragment */
 		result = tl_socket_read_packet_data(tcp_globals.net_phone,
 		    &packet, TCP_HEADER_SIZE, packet_dimension,
@@ -2189,5 +2204,6 @@
 
 		total_length = (size_t) result;
-		// prefix the tcp header
+
+		/* Prefix the TCP header */
 		header = PACKET_PREFIX(packet, tcp_header_t);
 		if (!header)
@@ -2200,5 +2216,5 @@
 	}
 
-	// flush packets
+	/* Flush packets */
 	packet = tcp_get_packets_to_send(socket, socket_data);
 	fibril_rwlock_write_unlock(socket_data->local_lock);
@@ -2206,5 +2222,5 @@
 
 	if (packet) {
-		// send the packet
+		/* Send the packet */
 		tcp_send_packets(socket_data->device_id, packet);
 	}
@@ -2221,14 +2237,14 @@
 	int rc;
 
-	// find the socket
+	/* Find the socket */
 	socket = socket_cores_find(local_sockets, socket_id);
 	if (!socket)
 		return ENOTSOCK;
 
-	// get the socket specific data
+	/* Get the socket specific data */
 	socket_data = (tcp_socket_data_ref) socket->specific_data;
 	assert(socket_data);
 
-	// check state
+	/* Check state */
 	switch (socket_data->state) {
 	case TCP_SOCKET_ESTABLISHED:
@@ -2243,5 +2259,5 @@
 
 	default:
-		// just destroy
+		/* Just destroy */
 		rc = socket_destroy(tcp_globals.net_phone, socket_id,
 		    local_sockets, &tcp_globals.sockets,
@@ -2254,18 +2270,20 @@
 	}
 
-	// send FIN
-	// TODO should I wait to complete?
-
-	// create the notification packet
+	/*
+	 * Send FIN.
+	 * TODO should I wait to complete?
+	 */
+
+	/* Create the notification packet */
 	rc = tcp_create_notification_packet(&packet, socket, socket_data, 0, 1);
 	if (rc != EOK)
 		return rc;
 
-	// send the packet
+	/* Send the packet */
 	rc = tcp_queue_packet(socket, socket_data, packet, 1);
 	if (rc != EOK)
 		return rc;
 
-	// flush packets
+	/* Flush packets */
 	packet = tcp_get_packets_to_send(socket, socket_data);
 	fibril_rwlock_write_unlock(socket_data->local_lock);
@@ -2273,5 +2291,5 @@
 
 	if (packet) {
-		// send the packet
+		/* Send the packet */
 		tcp_send_packets(socket_data->device_id, packet);
 	}
@@ -2280,6 +2298,5 @@
 }
 
-int
-tcp_create_notification_packet(packet_t *packet, socket_core_ref socket,
+int tcp_create_notification_packet(packet_t *packet, socket_core_ref socket,
     tcp_socket_data_ref socket_data, int synchronize, int finalize)
 {
@@ -2290,5 +2307,5 @@
 	assert(packet);
 
-	// get the device packet dimension
+	/* Get the device packet dimension */
 	rc = tl_get_ip_packet_dimension(tcp_globals.ip_phone,
 	    &tcp_globals.dimensions, socket_data->device_id, &packet_dimension);
@@ -2296,5 +2313,5 @@
 		return rc;
 
-	// get a new packet
+	/* Get a new packet */
 	*packet = packet_get_4_remote(tcp_globals.net_phone, TCP_HEADER_SIZE,
 	    packet_dimension->addr_len, packet_dimension->prefix,
@@ -2304,5 +2321,5 @@
 		return ENOMEM;
 
-	// allocate space in the packet
+	/* Allocate space in the packet */
 	header = PACKET_SUFFIX(*packet, tcp_header_t);
 	if (!header)
@@ -2315,6 +2332,5 @@
 }
 
-int
-tcp_accept_message(socket_cores_ref local_sockets, int socket_id,
+int tcp_accept_message(socket_cores_ref local_sockets, int socket_id,
     int new_socket_id, size_t *data_fragment_size, size_t *addrlen)
 {
@@ -2329,14 +2345,14 @@
 	assert(addrlen);
 
-	// find the socket
+	/* Find the socket */
 	socket = socket_cores_find(local_sockets, socket_id);
 	if (!socket)
 		return ENOTSOCK;
 
-	// get the socket specific data
+	/* Get the socket specific data */
 	socket_data = (tcp_socket_data_ref) socket->specific_data;
 	assert(socket_data);
 
-	// check state
+	/* Check state */
 	if (socket_data->state != TCP_SOCKET_LISTEN)
 		return EINVAL;
@@ -2352,8 +2368,8 @@
 			return ENOTSOCK;
 
-		// get the socket specific data
+		/* Get the socket specific data */
 		socket_data = (tcp_socket_data_ref) accepted->specific_data;
 		assert(socket_data);
-		// TODO can it be in another state?
+		/* TODO can it be in another state? */
 		if (socket_data->state == TCP_SOCKET_ESTABLISHED) {
 			rc = data_reply(socket_data->addr,
@@ -2389,6 +2405,5 @@
 }
 
-void
-tcp_free_socket_data(socket_core_ref socket)
+void tcp_free_socket_data(socket_core_ref socket)
 {
 	tcp_socket_data_ref socket_data;
@@ -2398,8 +2413,9 @@
 	printf("destroy_socket %d\n", socket->socket_id);
 
-	// get the socket specific data
+	/* Get the socket specific data */
 	socket_data = (tcp_socket_data_ref) socket->specific_data;
 	assert(socket_data);
-	//free the pseudo header
+
+	/* Free the pseudo header */
 	if (socket_data->pseudo_header) {
 		if (socket_data->headerlen) {
@@ -2410,6 +2426,8 @@
 		socket_data->pseudo_header = NULL;
 	}
+
 	socket_data->headerlen = 0;
-	// free the address
+
+	/* Free the address */
 	if (socket_data->addr) {
 		if (socket_data->addrlen) {
@@ -2473,5 +2491,5 @@
 
 		/*
-		   Answer the message 
+		 * Answer the message 
 		 */
 		answer_call(callid, res, &answer, answer_count);
