Index: uspace/srv/net/tl/udp/udp.c
===================================================================
--- uspace/srv/net/tl/udp/udp.c	(revision 8e3a65c6853b2023152999f5d7822941b153f9b7)
+++ 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.
  */
