Index: uspace/srv/net/tl/udp/udp.c
===================================================================
--- uspace/srv/net/tl/udp/udp.c	(revision 89e57ceef2a2fce4e3518b2109ffcd674896bf36)
+++ uspace/srv/net/tl/udp/udp.c	(revision 457a6f59b904523e0be54317725910db9a097905)
@@ -28,11 +28,15 @@
 
 /** @addtogroup udp
- *  @{
+ * @{
  */
 
 /** @file
- *  UDP module implementation.
- *  @see udp.h
- */
+ * UDP module implementation.
+ * @see udp.h
+ */
+
+#include "udp.h"
+#include "udp_header.h"
+#include "udp_module.h"
 
 #include <async.h>
@@ -45,4 +49,5 @@
 #include <ipc/tl.h>
 #include <ipc/socket.h>
+#include <adt/dynamic_fifo.h>
 #include <errno.h>
 #include <err.h>
@@ -55,5 +60,4 @@
 #include <net/modules.h>
 
-#include <adt/dynamic_fifo.h>
 #include <packet_client.h>
 #include <packet_remote.h>
@@ -69,8 +73,4 @@
 #include <tl_interface.h>
 
-#include "udp.h"
-#include "udp_header.h"
-#include "udp_module.h"
-
 /** UDP module name. */
 #define NAME	"UDP protocol"
@@ -91,130 +91,14 @@
 #define UDP_FREE_PORTS_END		65535
 
-/** Processes the received UDP packet queue.
- *
- *  Is used as an entry point from the underlying IP module.
- *  Locks the global lock and calls udp_process_packet() function.
- *
- *  @param[in] device_id The receiving device identifier.
- *  @param[in,out] packet The received packet queue.
- *  @param receiver	The target service. Ignored parameter.
- *  @param[in] error	The packet error reporting service. Prefixes the
- *			received packet.
- *  @returns		EOK on success.
- *  @returns		Other error codes as defined for the
- *			udp_process_packet() function.
- */
-int
-udp_received_msg(device_id_t device_id, packet_t packet, services_t receiver,
-    services_t error);
-
-/** Processes the received UDP packet queue.
- *
- *  Notifies the destination socket application.
- *  Releases the packet on error or sends an ICMP error notification.
- *
- *  @param[in] device_id The receiving device identifier.
- *  @param[in,out] packet The received packet queue.
- *  @param[in] error	The packet error reporting service. Prefixes the
- *			received packet.
- *  @returns		EOK on success.
- *  @returns		EINVAL if the packet is not valid.
- *  @returns		EINVAL if the stored packet address is not the
- *			an_addr_t.
- *  @returns		EINVAL if the packet does not contain any data.
- *  @returns 		NO_DATA if the packet content is shorter than the user
- *			datagram header.
- *  @returns		ENOMEM if there is not enough memory left.
- *  @returns		EADDRNOTAVAIL if the destination socket does not exist.
- *  @returns		Other error codes as defined for the
- *			ip_client_process_packet() function.
- */
-int
-udp_process_packet(device_id_t device_id, packet_t packet, services_t error);
-
-/** Releases the packet and returns the result.
- *
- *  @param[in] packet	The packet queue to be released.
- *  @param[in] result	The result to be returned.
- *  @return		The result parameter.
- */
-int udp_release_and_return(packet_t packet, int result);
-
-/** @name Socket messages processing functions
- */
-/*@{*/
-
-/** Processes the socket client messages.
- *
- *  Runs until the client module disconnects.
- *
- *  @param[in] callid 	The message identifier.
- *  @param[in] call	The message parameters.
- *  @returns		EOK on success.
- *  @see		socket.h
- */
-int udp_process_client_messages(ipc_callid_t callid, ipc_call_t call);
-
-/** Sends data from the socket to the remote address.
- *
- *  Binds the socket to a free port if not already connected/bound.
- *  Handles the NET_SOCKET_SENDTO message.
- *  Supports AF_INET and AF_INET6 address families.
- *
- *  @param[in,out] local_sockets The application local sockets.
- *  @param[in] socket_id Socket identifier.
- *  @param[in] addr	The destination address.
- *  @param[in] addrlen	The address length.
- *  @param[in] fragments The number of data fragments.
- *  @param[out] data_fragment_size The data fragment size in bytes.
- *  @param[in] flags	Various send flags.
- *  @returns		EOK on success.
- *  @returns		EAFNOTSUPPORT if the address family is not supported.
- *  @returns		ENOTSOCK if the socket is not found.
- *  @returns		EINVAL if the address is invalid.
- *  @returns		ENOTCONN if the sending socket is not and cannot be
- *			bound.
- *  @returns		ENOMEM if there is not enough memory left.
- *  @returns		Other error codes as defined for the
- *			socket_read_packet_data() function.
- *  @returns		Other error codes as defined for the
- *			ip_client_prepare_packet() function.
- *  @returns		Other error codes as defined for the ip_send_msg()
- *			function.
- */
-int
-udp_sendto_message(socket_cores_ref local_sockets, int socket_id,
-    const struct sockaddr * addr, socklen_t addrlen, int fragments,
-    size_t * data_fragment_size, int flags);
-
-/** Receives data to the socket.
- *
- *  Handles the NET_SOCKET_RECVFROM message.
- *  Replies the source address as well.
- *
- *  @param[in] local_sockets The application local sockets.
- *  @param[in] socket_id Socket identifier.
- *  @param[in] flags	Various receive flags.
- *  @param[out] addrlen	The source address length.
- *  @returns		The number of bytes received.
- *  @returns		ENOTSOCK if the socket is not found.
- *  @returns		NO_DATA if there are no received packets or data.
- *  @returns		ENOMEM if there is not enough memory left.
- *  @returns		EINVAL if the received address is not an IP address.
- *  @returns		Other error codes as defined for the packet_translate()
- *			function.
- *  @returns		Other error codes as defined for the data_reply()
- *			function.
- */
-int
-udp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags,
-    size_t * addrlen);
-
-/*@}*/
-
-/** UDP global data.
- */
+/** UDP global data.  */
 udp_globals_t udp_globals;
 
+/** Initializes the UDP module.
+ *
+ * @param[in] client_connection The client connection processing function. The
+ *			module skeleton propagates its own one.
+ * @returns		EOK on success.
+ * @returns		ENOMEM if there is not enough memory left.
+ */
 int udp_initialize(async_client_conn_t client_connection)
 {
@@ -233,5 +117,5 @@
 	measured_string_ref configuration;
 	size_t count = sizeof(names) / sizeof(measured_string_t);
-	char * data;
+	char *data;
 
 	fibril_rwlock_initialize(&udp_globals.lock);
@@ -280,19 +164,39 @@
 }
 
-int
-udp_received_msg(device_id_t device_id, packet_t packet, services_t receiver,
-    services_t error)
+/** Releases the packet and returns the result.
+ *
+ * @param[in] packet	The packet queue to be released.
+ * @param[in] result	The result to be returned.
+ * @return		The result parameter.
+ */
+static int udp_release_and_return(packet_t packet, int result)
 {
-	int result;
-
-	fibril_rwlock_write_lock(&udp_globals.lock);
-	result = udp_process_packet(device_id, packet, error);
-	if (result != EOK)
-		fibril_rwlock_write_unlock(&udp_globals.lock);
-
+	pq_release_remote(udp_globals.net_phone, packet_get_id(packet));
 	return result;
 }
 
-int udp_process_packet(device_id_t device_id, packet_t packet, services_t error)
+/** Processes the received UDP packet queue.
+ *
+ * Notifies the destination socket application.
+ * Releases the packet on error or sends an ICMP error notification.
+ *
+ * @param[in] device_id	The receiving device identifier.
+ * @param[in,out] packet The received packet queue.
+ * @param[in] error	The packet error reporting service. Prefixes the
+ *			received packet.
+ * @returns		EOK on success.
+ * @returns		EINVAL if the packet is not valid.
+ * @returns		EINVAL if the stored packet address is not the
+ *			an_addr_t.
+ * @returns		EINVAL if the packet does not contain any data.
+ * @returns 		NO_DATA if the packet content is shorter than the user
+ *			datagram header.
+ * @returns		ENOMEM if there is not enough memory left.
+ * @returns		EADDRNOTAVAIL if the destination socket does not exist.
+ * @returns		Other error codes as defined for the
+ *			ip_client_process_packet() function.
+ */
+static int
+udp_process_packet(device_id_t device_id, packet_t packet, services_t error)
 {
 	ERROR_DECLARE;
@@ -315,22 +219,22 @@
 	packet_dimension_ref packet_dimension;
 
-	if (error) {
-		switch (error) {
-		case SERVICE_ICMP:
-			// ignore error
-			// length = icmp_client_header_length(packet);
-			// process error
-			result = icmp_client_process_packet(packet, &type,
-			    &code, NULL, NULL);
-			if (result < 0)
-				return udp_release_and_return(packet, result);
-			length = (size_t) result;
-			if (ERROR_OCCURRED(packet_trim(packet, length, 0)))
-				return udp_release_and_return(packet,
-				    ERROR_CODE);
-			break;
-		default:
-			return udp_release_and_return(packet, ENOTSUP);
-		}
+	switch (error) {
+	case SERVICE_NONE:
+		break;
+	case SERVICE_ICMP:
+		// ignore error
+		// length = icmp_client_header_length(packet);
+		// process error
+		result = icmp_client_process_packet(packet, &type,
+		    &code, NULL, NULL);
+		if (result < 0)
+			return udp_release_and_return(packet, result);
+		length = (size_t) result;
+		if (ERROR_OCCURRED(packet_trim(packet, length, 0)))
+			return udp_release_and_return(packet,
+			    ERROR_CODE);
+		break;
+	default:
+		return udp_release_and_return(packet, ENOTSUP);
 	}
 
@@ -374,8 +278,8 @@
 
 	// compute header checksum if set
-	if (header->checksum && (!error)) {
+	if (header->checksum && !error) {
 		result = packet_get_addr(packet, (uint8_t **) &src,
 		    (uint8_t **) &dest);
-		if( result <= 0)
+		if (result <= 0)
 			return udp_release_and_return(packet, result);
 
@@ -396,5 +300,5 @@
 
 	do {
-		++ fragments;
+		fragments++;
 		length = packet_get_data_length(next_packet);
 		if (length <= 0)
@@ -471,172 +375,60 @@
 }
 
-int
-udp_message_standalone(ipc_callid_t callid, ipc_call_t * call,
-    ipc_call_t * answer, int * answer_count)
+/** Processes the received UDP packet queue.
+ *
+ * Is used as an entry point from the underlying IP module.
+ * Locks the global lock and calls udp_process_packet() function.
+ *
+ * @param[in] device_id	The receiving device identifier.
+ * @param[in,out] packet The received packet queue.
+ * @param receiver	The target service. Ignored parameter.
+ * @param[in] error	The packet error reporting service. Prefixes the
+ *			received packet.
+ * @returns		EOK on success.
+ * @returns		Other error codes as defined for the
+ *			udp_process_packet() function.
+ */
+static int
+udp_received_msg(device_id_t device_id, packet_t packet, services_t receiver,
+    services_t error)
 {
-	ERROR_DECLARE;
-
-	packet_t packet;
-
-	*answer_count = 0;
-
-	switch (IPC_GET_METHOD(*call)) {
-	case NET_TL_RECEIVED:
-		if (!ERROR_OCCURRED(packet_translate_remote(
-		    udp_globals.net_phone, &packet, IPC_GET_PACKET(call)))) {
-			ERROR_CODE = udp_received_msg(IPC_GET_DEVICE(call),
-			    packet, SERVICE_UDP, IPC_GET_ERROR(call));
-		}
-		return ERROR_CODE;
-	
-	case IPC_M_CONNECT_TO_ME:
-		return udp_process_client_messages(callid, * call);
-	}
-
-	return ENOTSUP;
+	int result;
+
+	fibril_rwlock_write_lock(&udp_globals.lock);
+	result = udp_process_packet(device_id, packet, error);
+	if (result != EOK)
+		fibril_rwlock_write_unlock(&udp_globals.lock);
+
+	return result;
 }
 
-int udp_process_client_messages(ipc_callid_t callid, ipc_call_t call)
-{
-	int res;
-	bool keep_on_going = true;
-	socket_cores_t local_sockets;
-	int app_phone = IPC_GET_PHONE(&call);
-	struct sockaddr *addr;
-	int socket_id;
-	size_t addrlen;
-	size_t size;
-	ipc_call_t answer;
-	int answer_count;
-	packet_dimension_ref packet_dimension;
-
-	/*
-	 * Accept the connection
-	 *  - Answer the first IPC_M_CONNECT_TO_ME call.
-	 */
-	res = EOK;
-	answer_count = 0;
-
-	// The client connection is only in one fibril and therefore no
-	// additional locks are needed.
-
-	socket_cores_initialize(&local_sockets);
-
-	while (keep_on_going) {
-
-		// answer the call
-		answer_call(callid, res, &answer, answer_count);
-
-		// refresh data
-		refresh_answer(&answer, &answer_count);
-
-		// get the next call
-		callid = async_get_call(&call);
-
-		// process the call
-		switch (IPC_GET_METHOD(call)) {
-		case IPC_M_PHONE_HUNGUP:
-			keep_on_going = false;
-			res = EHANGUP;
-			break;
-
-		case NET_SOCKET:
-			socket_id = SOCKET_GET_SOCKET_ID(call);
-			res = socket_create(&local_sockets, app_phone, NULL,
-			    &socket_id);
-			SOCKET_SET_SOCKET_ID(answer, socket_id);
-
-			if (res != EOK)
-				break;
-			
-			if (tl_get_ip_packet_dimension(udp_globals.ip_phone,
-			    &udp_globals.dimensions, DEVICE_INVALID_ID,
-			    &packet_dimension) == EOK) {
-				SOCKET_SET_DATA_FRAGMENT_SIZE(answer,
-				    packet_dimension->content);
-			}
-
-//			SOCKET_SET_DATA_FRAGMENT_SIZE(answer,
-//			    MAX_UDP_FRAGMENT_SIZE);
-			SOCKET_SET_HEADER_SIZE(answer, UDP_HEADER_SIZE);
-			answer_count = 3;
-			break;
-
-		case NET_SOCKET_BIND:
-			res = data_receive((void **) &addr, &addrlen);
-			if (res != EOK)
-				break;
-			fibril_rwlock_write_lock(&udp_globals.lock);
-			res = socket_bind(&local_sockets, &udp_globals.sockets,
-			    SOCKET_GET_SOCKET_ID(call), addr, addrlen,
-			    UDP_FREE_PORTS_START, UDP_FREE_PORTS_END,
-			    udp_globals.last_used_port);
-			fibril_rwlock_write_unlock(&udp_globals.lock);
-			free(addr);
-			break;
-
-		case NET_SOCKET_SENDTO:
-			res = data_receive((void **) &addr, &addrlen);
-			if (res != EOK)
-				break;
-
-			fibril_rwlock_write_lock(&udp_globals.lock);
-			res = udp_sendto_message(&local_sockets,
-			    SOCKET_GET_SOCKET_ID(call), addr, addrlen,
-			    SOCKET_GET_DATA_FRAGMENTS(call), &size,
-			    SOCKET_GET_FLAGS(call));
-			SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
-
-			if (res != EOK)
-				fibril_rwlock_write_unlock(&udp_globals.lock);
-			else
-				answer_count = 2;
-			
-			free(addr);
-			break;
-
-		case NET_SOCKET_RECVFROM:
-			fibril_rwlock_write_lock(&udp_globals.lock);
-			res = udp_recvfrom_message(&local_sockets,
-			     SOCKET_GET_SOCKET_ID(call), SOCKET_GET_FLAGS(call),
-			     &addrlen);
-			fibril_rwlock_write_unlock(&udp_globals.lock);
-
-			if (res <= 0)
-				break;
-
-			SOCKET_SET_READ_DATA_LENGTH(answer, res);
-			SOCKET_SET_ADDRESS_LENGTH(answer, addrlen);
-			answer_count = 3;
-			res = EOK;
-			break;
-			
-		case NET_SOCKET_CLOSE:
-			fibril_rwlock_write_lock(&udp_globals.lock);
-			res = socket_destroy(udp_globals.net_phone,
-			    SOCKET_GET_SOCKET_ID(call), &local_sockets,
-			    &udp_globals.sockets, NULL);
-			fibril_rwlock_write_unlock(&udp_globals.lock);
-			break;
-
-		case NET_SOCKET_GETSOCKOPT:
-		case NET_SOCKET_SETSOCKOPT:
-		default:
-			res = ENOTSUP;
-			break;
-		}
-	}
-
-	// release the application phone
-	ipc_hangup(app_phone);
-
-	// release all local sockets
-	socket_cores_release(udp_globals.net_phone, &local_sockets,
-	    &udp_globals.sockets, NULL);
-
-	return res;
-}
-
-int
+/** Sends data from the socket to the remote address.
+ *
+ * Binds the socket to a free port if not already connected/bound.
+ * Handles the NET_SOCKET_SENDTO message.
+ * Supports AF_INET and AF_INET6 address families.
+ *
+ * @param[in,out] local_sockets The application local sockets.
+ * @param[in] socket_id	Socket identifier.
+ * @param[in] addr	The destination address.
+ * @param[in] addrlen	The address length.
+ * @param[in] fragments	The number of data fragments.
+ * @param[out] data_fragment_size The data fragment size in bytes.
+ * @param[in] flags	Various send flags.
+ * @returns		EOK on success.
+ * @returns		EAFNOTSUPPORT if the address family is not supported.
+ * @returns		ENOTSOCK if the socket is not found.
+ * @returns		EINVAL if the address is invalid.
+ * @returns		ENOTCONN if the sending socket is not and cannot be
+ *			bound.
+ * @returns		ENOMEM if there is not enough memory left.
+ * @returns		Other error codes as defined for the
+ *			socket_read_packet_data() function.
+ * @returns		Other error codes as defined for the
+ *			ip_client_prepare_packet() function.
+ * @returns		Other error codes as defined for the ip_send_msg()
+ *			function.
+ */
+static int
 udp_sendto_message(socket_cores_ref local_sockets, int socket_id,
     const struct sockaddr *addr, socklen_t addrlen, int fragments,
@@ -725,10 +517,10 @@
 	// prefix the udp header
 	header = PACKET_PREFIX(packet, udp_header_t);
-	if(! header)
+	if (!header)
 		return udp_release_and_return(packet, ENOMEM);
 
 	bzero(header, sizeof(*header));
 	// read the rest of the packet fragments
-	for (index = 1; index < fragments; ++ index) {
+	for (index = 1; index < fragments; index++) {
 		result = tl_socket_read_packet_data(udp_globals.net_phone,
 		    &next_packet, 0, packet_dimension, addr, addrlen);
@@ -784,5 +576,24 @@
 }
 
-int
+/** Receives data to the socket.
+ *
+ * Handles the NET_SOCKET_RECVFROM message.
+ * Replies the source address as well.
+ *
+ * @param[in] local_sockets The application local sockets.
+ * @param[in] socket_id	Socket identifier.
+ * @param[in] flags	Various receive flags.
+ * @param[out] addrlen	The source address length.
+ * @returns		The number of bytes received.
+ * @returns		ENOTSOCK if the socket is not found.
+ * @returns		NO_DATA if there are no received packets or data.
+ * @returns		ENOMEM if there is not enough memory left.
+ * @returns		EINVAL if the received address is not an IP address.
+ * @returns		Other error codes as defined for the packet_translate()
+ *			function.
+ * @returns		Other error codes as defined for the data_reply()
+ *			function.
+ */
+static int
 udp_recvfrom_message(socket_cores_ref local_sockets, int socket_id, int flags,
     size_t *addrlen)
@@ -830,5 +641,5 @@
 
 	// send the source address
-	ERROR_PROPAGATE(data_reply(addr, * addrlen));
+	ERROR_PROPAGATE(data_reply(addr, *addrlen));
 
 	// trim the header
@@ -846,8 +657,192 @@
 }
 
-int udp_release_and_return(packet_t packet, int result)
+/** Processes the socket client messages.
+ *
+ * Runs until the client module disconnects.
+ *
+ * @param[in] callid 	The message identifier.
+ * @param[in] call	The message parameters.
+ * @returns		EOK on success.
+ *
+ * @see	socket.h
+ */
+static int udp_process_client_messages(ipc_callid_t callid, ipc_call_t call)
 {
-	pq_release_remote(udp_globals.net_phone, packet_get_id(packet));
-	return result;
+	int res;
+	bool keep_on_going = true;
+	socket_cores_t local_sockets;
+	int app_phone = IPC_GET_PHONE(&call);
+	struct sockaddr *addr;
+	int socket_id;
+	size_t addrlen;
+	size_t size;
+	ipc_call_t answer;
+	int answer_count;
+	packet_dimension_ref packet_dimension;
+
+	/*
+	 * Accept the connection
+	 *  - Answer the first IPC_M_CONNECT_TO_ME call.
+	 */
+	res = EOK;
+	answer_count = 0;
+
+	// The client connection is only in one fibril and therefore no
+	// additional locks are needed.
+
+	socket_cores_initialize(&local_sockets);
+
+	while (keep_on_going) {
+
+		// answer the call
+		answer_call(callid, res, &answer, answer_count);
+
+		// refresh data
+		refresh_answer(&answer, &answer_count);
+
+		// get the next call
+		callid = async_get_call(&call);
+
+		// process the call
+		switch (IPC_GET_METHOD(call)) {
+		case IPC_M_PHONE_HUNGUP:
+			keep_on_going = false;
+			res = EHANGUP;
+			break;
+
+		case NET_SOCKET:
+			socket_id = SOCKET_GET_SOCKET_ID(call);
+			res = socket_create(&local_sockets, app_phone, NULL,
+			    &socket_id);
+			SOCKET_SET_SOCKET_ID(answer, socket_id);
+
+			if (res != EOK)
+				break;
+			
+			if (tl_get_ip_packet_dimension(udp_globals.ip_phone,
+			    &udp_globals.dimensions, DEVICE_INVALID_ID,
+			    &packet_dimension) == EOK) {
+				SOCKET_SET_DATA_FRAGMENT_SIZE(answer,
+				    packet_dimension->content);
+			}
+
+//			SOCKET_SET_DATA_FRAGMENT_SIZE(answer,
+//			    MAX_UDP_FRAGMENT_SIZE);
+			SOCKET_SET_HEADER_SIZE(answer, UDP_HEADER_SIZE);
+			answer_count = 3;
+			break;
+
+		case NET_SOCKET_BIND:
+			res = data_receive((void **) &addr, &addrlen);
+			if (res != EOK)
+				break;
+			fibril_rwlock_write_lock(&udp_globals.lock);
+			res = socket_bind(&local_sockets, &udp_globals.sockets,
+			    SOCKET_GET_SOCKET_ID(call), addr, addrlen,
+			    UDP_FREE_PORTS_START, UDP_FREE_PORTS_END,
+			    udp_globals.last_used_port);
+			fibril_rwlock_write_unlock(&udp_globals.lock);
+			free(addr);
+			break;
+
+		case NET_SOCKET_SENDTO:
+			res = data_receive((void **) &addr, &addrlen);
+			if (res != EOK)
+				break;
+
+			fibril_rwlock_write_lock(&udp_globals.lock);
+			res = udp_sendto_message(&local_sockets,
+			    SOCKET_GET_SOCKET_ID(call), addr, addrlen,
+			    SOCKET_GET_DATA_FRAGMENTS(call), &size,
+			    SOCKET_GET_FLAGS(call));
+			SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
+
+			if (res != EOK)
+				fibril_rwlock_write_unlock(&udp_globals.lock);
+			else
+				answer_count = 2;
+			
+			free(addr);
+			break;
+
+		case NET_SOCKET_RECVFROM:
+			fibril_rwlock_write_lock(&udp_globals.lock);
+			res = udp_recvfrom_message(&local_sockets,
+			     SOCKET_GET_SOCKET_ID(call), SOCKET_GET_FLAGS(call),
+			     &addrlen);
+			fibril_rwlock_write_unlock(&udp_globals.lock);
+
+			if (res <= 0)
+				break;
+
+			SOCKET_SET_READ_DATA_LENGTH(answer, res);
+			SOCKET_SET_ADDRESS_LENGTH(answer, addrlen);
+			answer_count = 3;
+			res = EOK;
+			break;
+			
+		case NET_SOCKET_CLOSE:
+			fibril_rwlock_write_lock(&udp_globals.lock);
+			res = socket_destroy(udp_globals.net_phone,
+			    SOCKET_GET_SOCKET_ID(call), &local_sockets,
+			    &udp_globals.sockets, NULL);
+			fibril_rwlock_write_unlock(&udp_globals.lock);
+			break;
+
+		case NET_SOCKET_GETSOCKOPT:
+		case NET_SOCKET_SETSOCKOPT:
+		default:
+			res = ENOTSUP;
+			break;
+		}
+	}
+
+	// release the application phone
+	ipc_hangup(app_phone);
+
+	// release all local sockets
+	socket_cores_release(udp_globals.net_phone, &local_sockets,
+	    &udp_globals.sockets, NULL);
+
+	return res;
+}
+
+/** Processes the UDP message.
+ *
+ * @param[in] callid	The message identifier.
+ * @param[in] call	The message parameters.
+ * @param[out] answer	The message answer parameters.
+ * @param[out] answer_count The last parameter for the actual answer in the
+ *			answer parameter.
+ * @returns		EOK on success.
+ * @returns		ENOTSUP if the message is not known.
+ *
+ * @see udp_interface.h
+ * @see IS_NET_UDP_MESSAGE()
+ */
+int
+udp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, int *answer_count)
+{
+	ERROR_DECLARE;
+
+	packet_t packet;
+
+	*answer_count = 0;
+
+	switch (IPC_GET_METHOD(*call)) {
+	case NET_TL_RECEIVED:
+		if (ERROR_NONE(packet_translate_remote(udp_globals.net_phone,
+		    &packet, IPC_GET_PACKET(call)))) {
+			ERROR_CODE = udp_received_msg(IPC_GET_DEVICE(call),
+			    packet, SERVICE_UDP, IPC_GET_ERROR(call));
+		}
+		return ERROR_CODE;
+	
+	case IPC_M_CONNECT_TO_ME:
+		return udp_process_client_messages(callid, * call);
+	}
+
+	return ENOTSUP;
 }
 
@@ -882,5 +877,6 @@
 		
 		/*
-		 * End if said to either by the message or the processing result
+		 * End if told to either by the message or the processing
+		 * result.
 		 */
 		if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) ||
@@ -895,10 +891,6 @@
 /** Starts the module.
  *
- *  @param argc		The count of the command line arguments. Ignored
- *			parameter.
- *  @param argv		The command line parameters. Ignored parameter.
- *
- *  @returns		EOK on success.
- *  @returns		Other error codes as defined for each specific module
+ * @returns		EOK on success.
+ * @returns		Other error codes as defined for each specific module
  *			start function.
  */
Index: uspace/srv/net/tl/udp/udp.h
===================================================================
--- uspace/srv/net/tl/udp/udp.h	(revision 89e57ceef2a2fce4e3518b2109ffcd674896bf36)
+++ uspace/srv/net/tl/udp/udp.h	(revision 457a6f59b904523e0be54317725910db9a097905)
@@ -28,13 +28,13 @@
 
 /** @addtogroup udp
- *  @{
+ * @{
  */
 
 /** @file
- *  UDP module.
+ * UDP module.
  */
 
-#ifndef __NET_UDP_H__
-#define __NET_UDP_H__
+#ifndef NET_UDP_H_
+#define NET_UDP_H_
 
 #include <fibril_synch.h>
@@ -43,40 +43,29 @@
 
 /** Type definition of the UDP global data.
- *  @see udp_globals
+ * @see udp_globals
  */
-typedef struct udp_globals	udp_globals_t;
+typedef struct udp_globals udp_globals_t;
 
-/** UDP global data.
- */
-struct	udp_globals{
-	/** Networking module phone.
-	 */
+/** UDP global data. */
+struct udp_globals {
+	/** Networking module phone. */
 	int net_phone;
-	/** IP module phone.
-	 */
+	/** IP module phone. */
 	int ip_phone;
-	/** ICMP module phone.
-	 */
+	/** ICMP module phone. */
 	int icmp_phone;
-	/** Packet dimension.
-	 */
+	/** Packet dimension. */
 	packet_dimension_t packet_dimension;
-	/** Indicates whether UDP checksum computing is enabled.
-	 */
+	/** Indicates whether UDP checksum computing is enabled. */
 	int checksum_computing;
-	/** Indicates whether UDP autobnding on send is enabled.
-	 */
+	/** Indicates whether UDP autobnding on send is enabled. */
 	int autobinding;
-	/** Last used free port.
-	 */
+	/** Last used free port. */
 	int last_used_port;
-	/** Active sockets.
-	 */
+	/** Active sockets. */
 	socket_ports_t sockets;
-	/** Device packet dimensions.
-	 */
+	/** Device packet dimensions. */
 	packet_dimensions_t dimensions;
-	/** Safety lock.
-	 */
+	/** Safety lock. */
 	fibril_rwlock_t lock;
 };
@@ -86,3 +75,2 @@
 /** @}
  */
-
Index: uspace/srv/net/tl/udp/udp_header.h
===================================================================
--- uspace/srv/net/tl/udp/udp_header.h	(revision 89e57ceef2a2fce4e3518b2109ffcd674896bf36)
+++ uspace/srv/net/tl/udp/udp_header.h	(revision 457a6f59b904523e0be54317725910db9a097905)
@@ -28,51 +28,35 @@
 
 /** @addtogroup udp
- *  @{
+ * @{
  */
 
 /** @file
- *  UDP header definition.
- *  Based on the RFC~768.
+ * UDP header definition.
+ * Based on the RFC 768.
  */
 
-#ifndef __NET_UDP_HEADER_H__
-#define __NET_UDP_HEADER_H__
+#ifndef NET_UDP_HEADER_H_
+#define NET_UDP_HEADER_H_
 
 #include <sys/types.h>
 
-/** UDP header size in bytes.
- */
-#define UDP_HEADER_SIZE			sizeof(udp_header_t)
+/** UDP header size in bytes. */
+#define UDP_HEADER_SIZE		sizeof(udp_header_t)
 
 /** Type definition of the user datagram header.
- *  @see udp_header
+ * @see udp_header
  */
-typedef struct udp_header	udp_header_t;
+typedef struct udp_header udp_header_t;
 
 /** Type definition of the user datagram header pointer.
- *  @see udp_header
+ * @see udp_header
  */
-typedef udp_header_t *		udp_header_ref;
+typedef udp_header_t *udp_header_ref;
 
-/** User datagram header.
- */
-struct udp_header{
-	/** Source Port is an optional field, when meaningful, it indicates the port of the sending process, and may be assumed to be the port to which a reply should be addressed in the absence of any other information.
-	 *  If not used, a value of zero is inserted.
-	 */
+/** User datagram header. */
+struct udp_header {
 	uint16_t source_port;
-	/** Destination port has a meaning within the context of a particular internet destination address.
-	 */
 	uint16_t destination_port;
-	/** Length is the length in octets of this user datagram including this header and the data.
-	 *  This means the minimum value of the length is eight.
-	 */
 	uint16_t total_length;
-	/** Checksum is the 16-bit one's complement of the one's complement sum of a pseudo header of information from the IP header, the UDP header, and the data, padded with zero octets at the end (if necessary) to make a multiple of two octets.
-	 *  The pseudo header conceptually prefixed to the UDP header contains the source address, the destination address, the protocol, and the UDP length.
-	 *  This information gives protection against misrouted datagrams.
-	 *  If the computed checksum is zero, it is transmitted as all ones (the equivalent in one's complement arithmetic).
-	 *  An all zero transmitted checksum value means that the transmitter generated no checksum (for debugging or for higher level protocols that don't care).
-	 */
 	uint16_t checksum;
 } __attribute__ ((packed));
Index: uspace/srv/net/tl/udp/udp_module.c
===================================================================
--- uspace/srv/net/tl/udp/udp_module.c	(revision 89e57ceef2a2fce4e3518b2109ffcd674896bf36)
+++ uspace/srv/net/tl/udp/udp_module.c	(revision 457a6f59b904523e0be54317725910db9a097905)
@@ -28,13 +28,17 @@
 
 /** @addtogroup udp
- *  @{
+ * @{
  */
 
 /** @file
- *  UDP standalone module implementation.
- *  Contains skeleton module functions mapping.
- *  The functions are used by the module skeleton as module specific entry points.
- *  @see module.c
+ * UDP standalone module implementation.
+ * Contains skeleton module functions mapping.
+ * The functions are used by the module skeleton as module specific entry
+ * points.
+ * @see module.c
  */
+
+#include "udp.h"
+#include "udp_module.h"
 
 #include <async.h>
@@ -46,22 +50,13 @@
 #include <net/modules.h>
 #include <net/packet.h>
+
 #include <net_interface.h>
 #include <tl_local.h>
 
-#include "udp.h"
-#include "udp_module.h"
+/** UDP module global data. */
+extern udp_globals_t udp_globals;
 
-/** UDP module global data.
- */
-extern udp_globals_t	udp_globals;
-
-/** Starts the UDP module.
- *  Initializes the client connection serving function, initializes the module, registers the module service and starts the async manager, processing IPC messages in an infinite loop.
- *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
- *  @returns EOK on successful module termination.
- *  @returns Other error codes as defined for the udp_initialize() function.
- *  @returns Other error codes as defined for the REGISTER_ME() macro function.
- */
-int tl_module_start_standalone(async_client_conn_t client_connection){
+int tl_module_start_standalone(async_client_conn_t client_connection)
+{
 	ERROR_DECLARE;
 
@@ -70,10 +65,10 @@
 	async_set_client_connection(client_connection);
 	udp_globals.net_phone = net_connect_module();
-	if(udp_globals.net_phone < 0){
+	if (udp_globals.net_phone < 0)
 		return udp_globals.net_phone;
-	}
+
 	ERROR_PROPAGATE(pm_init());
-	if(ERROR_OCCURRED(udp_initialize(client_connection))
-		|| ERROR_OCCURRED(REGISTER_ME(SERVICE_UDP, &phonehash))){
+	if (ERROR_OCCURRED(udp_initialize(client_connection)) ||
+	    ERROR_OCCURRED(REGISTER_ME(SERVICE_UDP, &phonehash))) {
 		pm_destroy();
 		return ERROR_CODE;
@@ -86,13 +81,8 @@
 }
 
-/** Processes the UDP message.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the udp_message() function.
- */
-int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+int
+tl_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, int *answer_count)
+{
 	return udp_message_standalone(callid, call, answer, answer_count);
 }
Index: uspace/srv/net/tl/udp/udp_module.h
===================================================================
--- uspace/srv/net/tl/udp/udp_module.h	(revision 89e57ceef2a2fce4e3518b2109ffcd674896bf36)
+++ uspace/srv/net/tl/udp/udp_module.h	(revision 457a6f59b904523e0be54317725910db9a097905)
@@ -28,36 +28,21 @@
 
 /** @addtogroup udp
- *  @{
+ * @{
  */
 
 /** @file
- *  UDP module functions.
- *  The functions are used as UDP module entry points.
+ * UDP module functions.
+ * The functions are used as UDP module entry points.
  */
 
-#ifndef __NET_UDP_MODULE_H__
-#define __NET_UDP_MODULE_H__
+#ifndef NET_UDP_MODULE_H_
+#define NET_UDP_MODULE_H_
 
 #include <async.h>
 #include <ipc/ipc.h>
 
-/** Initializes the UDP module.
- *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left.
- */
-extern int udp_initialize(async_client_conn_t client_connection);
-
-/** Processes the UDP message.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOTSUP if the message is not known.
- *  @see udp_interface.h
- *  @see IS_NET_UDP_MESSAGE()
- */
-extern int udp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
+extern int udp_initialize(async_client_conn_t);
+extern int udp_message_standalone(ipc_callid_t, ipc_call_t *, ipc_call_t *,
+    int *);
 
 #endif
