Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/c/Makefile	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -101,5 +101,4 @@
 	generic/net/inet.c \
 	generic/net/modules.c \
-	generic/net/packet.c \
 	generic/net/socket_client.c \
 	generic/net/socket_parse.c \
Index: pace/lib/c/generic/net/packet.c
===================================================================
--- uspace/lib/c/generic/net/packet.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ 	(revision )
@@ -1,424 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- *  @{
- */
-
-/** @file
- *  Packet map and queue implementation.
- *  This file has to be compiled with both the packet server and the client.
- */
-
-#include <malloc.h>
-#include <mem.h>
-#include <fibril_synch.h>
-#include <unistd.h>
-#include <errno.h>
-#include <err.h>
-
-#include <sys/mman.h>
-
-#include <adt/generic_field.h>
-#include <net/packet.h>
-#include <net/packet_header.h>
-
-/** Packet map page size. */
-#define PACKET_MAP_SIZE	100
-
-/** Returns the packet map page index.
- * @param[in] packet_id The packet identifier.
- */
-#define PACKET_MAP_PAGE(packet_id)	(((packet_id) - 1) / PACKET_MAP_SIZE)
-
-/** Returns the packet index in the corresponding packet map page.
- *  @param[in] packet_id The packet identifier.
- */
-#define PACKET_MAP_INDEX(packet_id)	(((packet_id) - 1) % PACKET_MAP_SIZE)
-
-/** Type definition of the packet map page. */
-typedef packet_t packet_map_t[PACKET_MAP_SIZE];
-
-/** Type definition of the packet map page pointer. */
-typedef packet_map_t * packet_map_ref;
-
-/** Packet map.
- * Maps packet identifiers to the packet references.
- * @see generic_field.h
- */
-GENERIC_FIELD_DECLARE(gpm, packet_map_t);
-
-/** Packet map global data. */
-static struct {
-	/** Safety lock. */
-	fibril_rwlock_t lock;
-	/** Packet map. */
-	gpm_t packet_map;
-} pm_globals;
-
-GENERIC_FIELD_IMPLEMENT(gpm, packet_map_t);
-
-/** Initializes the packet map.
- *
- * @returns		EOK on success.
- * @returns		ENOMEM if there is not enough memory left.
- */
-int pm_init(void)
-{
-	ERROR_DECLARE;
-
-	fibril_rwlock_initialize(&pm_globals.lock);
-	fibril_rwlock_write_lock(&pm_globals.lock);
-	ERROR_PROPAGATE(gpm_initialize(&pm_globals.packet_map));
-	fibril_rwlock_write_unlock(&pm_globals.lock);
-	return EOK;
-}
-
-/** Finds the packet mapping.
- *
- * @param[in] packet_id	The packet identifier to be found.
- * @returns		The found packet reference.
- * @returns		NULL if the mapping does not exist.
- */
-packet_t pm_find(packet_id_t packet_id)
-{
-	packet_map_ref map;
-	packet_t packet;
-
-	if (!packet_id)
-		return NULL;
-
-	fibril_rwlock_read_lock(&pm_globals.lock);
-	if (packet_id > PACKET_MAP_SIZE * gpm_count(&pm_globals.packet_map)) {
-		fibril_rwlock_read_unlock(&pm_globals.lock);
-		return NULL;
-	}
-	map = gpm_get_index(&pm_globals.packet_map, PACKET_MAP_PAGE(packet_id));
-	if (!map) {
-		fibril_rwlock_read_unlock(&pm_globals.lock);
-		return NULL;
-	}
-	packet = (*map) [PACKET_MAP_INDEX(packet_id)];
-	fibril_rwlock_read_unlock(&pm_globals.lock);
-	return packet;
-}
-
-/** Adds the packet mapping.
- *
- * @param[in] packet	The packet to be remembered.
- * @returns		EOK on success.
- * @returns		EINVAL if the packet is not valid.
- * @returns		EINVAL if the packet map is not initialized.
- * @returns		ENOMEM if there is not enough memory left.
- */
-int pm_add(packet_t packet)
-{
-	ERROR_DECLARE;
-
-	packet_map_ref map;
-
-	if (!packet_is_valid(packet))
-		return EINVAL;
-
-	fibril_rwlock_write_lock(&pm_globals.lock);
-
-	if (PACKET_MAP_PAGE(packet->packet_id) <
-	    gpm_count(&pm_globals.packet_map)) {
-		map = gpm_get_index(&pm_globals.packet_map,
-		    PACKET_MAP_PAGE(packet->packet_id));
-	} else {
-		do {
-			map = (packet_map_ref) malloc(sizeof(packet_map_t));
-			if (!map) {
-				fibril_rwlock_write_unlock(&pm_globals.lock);
-				return ENOMEM;
-			}
-			bzero(map, sizeof(packet_map_t));
-			if ((ERROR_CODE =
-			    gpm_add(&pm_globals.packet_map, map)) < 0) {
-				fibril_rwlock_write_unlock(&pm_globals.lock);
-				free(map);
-				return ERROR_CODE;
-			}
-		} while (PACKET_MAP_PAGE(packet->packet_id) >=
-		    gpm_count(&pm_globals.packet_map));
-	}
-
-	(*map) [PACKET_MAP_INDEX(packet->packet_id)] = packet;
-	fibril_rwlock_write_unlock(&pm_globals.lock);
-	return EOK;
-}
-
-/** Releases the packet map. */
-void pm_destroy(void)
-{
-	int count;
-	int index;
-	packet_map_ref map;
-	packet_t packet;
-
-	fibril_rwlock_write_lock(&pm_globals.lock);
-	count = gpm_count(&pm_globals.packet_map);
-	while (count > 0) {
-		map = gpm_get_index(&pm_globals.packet_map, count - 1);
-		for (index = PACKET_MAP_SIZE - 1; index >= 0; --index) {
-			packet = (*map)[index];
-			if (packet_is_valid(packet))
-				munmap(packet, packet->length);
-		}
-	}
-	gpm_destroy(&pm_globals.packet_map);
-	// leave locked
-}
-
-/** Add packet to the sorted queue.
- *
- * The queue is sorted in the ascending order.
- * The packet is inserted right before the packets of the same order value.
- *
- * @param[in,out] first	The first packet of the queue. Sets the first packet of
- *			the queue. The original first packet may be shifted by
- *			the new packet.
- * @param[in] packet	The packet to be added.
- * @param[in] order	The packet order value.
- * @param[in] metric	The metric value of the packet.
- * @returns		EOK on success.
- * @returns		EINVAL if the first parameter is NULL.
- * @returns		EINVAL if the packet is not valid.
- */
-int pq_add(packet_t * first, packet_t packet, size_t order, size_t metric)
-{
-	packet_t item;
-
-	if (!first || !packet_is_valid(packet))
-		return EINVAL;
-
-	pq_set_order(packet, order, metric);
-	if (packet_is_valid(*first)) {
-		item = * first;
-		do {
-			if (item->order < order) {
-				if (item->next) {
-					item = pm_find(item->next);
-				} else {
-					item->next = packet->packet_id;
-					packet->previous = item->packet_id;
-					return EOK;
-				}
-			} else {
-				packet->previous = item->previous;
-				packet->next = item->packet_id;
-				item->previous = packet->packet_id;
-				item = pm_find(packet->previous);
-				if (item)
-					item->next = packet->packet_id;
-				else
-					*first = packet;
-				return EOK;
-			}
-		} while (packet_is_valid(item));
-	}
-	*first = packet;
-	return EOK;
-}
-
-/** Finds the packet with the given order.
- *
- * @param[in] first	The first packet of the queue.
- * @param[in] order	The packet order value.
- * @returns		The packet with the given order.
- * @returns		NULL if the first packet is not valid.
- * @returns		NULL if the packet is not found.
- */
-packet_t pq_find(packet_t packet, size_t order)
-{
-	packet_t item;
-
-	if (!packet_is_valid(packet))
-		return NULL;
-
-	item = packet;
-	do {
-		if (item->order == order)
-			return item;
-
-		item = pm_find(item->next);
-	} while (item && (item != packet) && packet_is_valid(item));
-
-	return NULL;
-}
-
-/** Inserts packet after the given one.
- *
- * @param[in] packet	The packet in the queue.
- * @param[in] new_packet The new packet to be inserted.
- * @returns		EOK on success.
- * @returns		EINVAL if etiher of the packets is invalid.
- */
-int pq_insert_after(packet_t packet, packet_t new_packet)
-{
-	packet_t item;
-
-	if (!packet_is_valid(packet) || !packet_is_valid(new_packet))
-		return EINVAL;
-
-	new_packet->previous = packet->packet_id;
-	new_packet->next = packet->next;
-	item = pm_find(packet->next);
-	if (item)
-		item->previous = new_packet->packet_id;
-	packet->next = new_packet->packet_id;
-
-	return EOK;
-}
-
-/** Detach the packet from the queue.
- *
- * @param[in] packet	The packet to be detached.
- * @returns		The next packet in the queue. If the packet is the first
- *			one of the queue, this becomes the new first one.
- * @returns		NULL if there is no packet left.
- * @returns		NULL if the packet is not valid.
- */
-packet_t pq_detach(packet_t packet)
-{
-	packet_t next;
-	packet_t previous;
-
-	if (!packet_is_valid(packet))
-		return NULL;
-
-	next = pm_find(packet->next);
-	if (next) {
-		next->previous = packet->previous;
-		previous = pm_find(next->previous);
-		if (previous)
-			previous->next = next->packet_id;
-	}
-	packet->previous = 0;
-	packet->next = 0;
-	return next;
-}
-
-/** Sets the packet order and metric attributes.
- *
- * @param[in] packeti	The packet to be set.
- * @param[in] order	The packet order value.
- * @param[in] metric	The metric value of the packet.
- * @returns		EOK on success.
- * @returns		EINVAL if the packet is invalid.
- */
-int pq_set_order(packet_t packet, size_t order, size_t metric)
-{
-	if (!packet_is_valid(packet))
-		return EINVAL;
-
-	packet->order = order;
-	packet->metric = metric;
-	return EOK;
-}
-
-/** Sets the packet order and metric attributes.
- *
- * @param[in] packet	The packet to be set.
- * @param[out] order	The packet order value.
- * @param[out] metric	The metric value of the packet.
- * @returns		EOK on success.
- * @returns		EINVAL if the packet is invalid.
- */
-int pq_get_order(packet_t packet, size_t *order, size_t *metric)
-{
-	if (!packet_is_valid(packet))
-		return EINVAL;
-
-	if (order)
-		*order = packet->order;
-
-	if (metric)
-		*metric = packet->metric;
-
-	return EOK;
-}
-
-/** Releases the whole queue.
- *
- * Detaches all packets of the queue and calls the packet_release() for each of
- * them.
- *
- * @param[in] first	The first packet of the queue.
- * @param[in] packet_release The releasing function called for each of the
- *			packets after its detachment.
- */
-void pq_destroy(packet_t first, void (*packet_release)(packet_t packet))
-{
-	packet_t actual;
-	packet_t next;
-
-	actual = first;
-	while (packet_is_valid(actual)) {
-		next = pm_find(actual->next);
-		actual->next = 0;
-		actual->previous = 0;
-		if(packet_release)
-			packet_release(actual);
-		actual = next;
-	}
-}
-
-/** Returns the next packet in the queue.
- *
- * @param[in] packet	The packet queue member.
- * @returns		The next packet in the queue.
- * @returns		NULL if there is no next packet.
- * @returns		NULL if the packet is not valid.
- */
-packet_t pq_next(packet_t packet)
-{
-	if (!packet_is_valid(packet))
-		return NULL;
-
-	return pm_find(packet->next);
-}
-
-/** Returns the previous packet in the queue.
- *
- * @param[in] packet	The packet queue member.
- * @returns		The previous packet in the queue.
- * @returns		NULL if there is no previous packet.
- * @returns		NULL if the packet is not valid.
- */
-packet_t pq_previous(packet_t packet)
-{
-	if (!packet_is_valid(packet))
-		return NULL;
-
-	return pm_find(packet->previous);
-}
-
-/** @}
- */
Index: pace/lib/c/include/ipc/packet.h
===================================================================
--- uspace/lib/c/include/ipc/packet.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ 	(revision )
@@ -1,93 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- *  @{
- */
-
-/** @file
- *  Packet server module messages.
- */
-
-#ifndef LIBC_PACKET_MESSAGES_
-#define LIBC_PACKET_MESSAGES_
-
-#include <ipc/ipc.h>
-#include <ipc/net.h>
-
-/** Packet server module messages. */
-typedef enum {
-	/** Create packet message with specified content length.
-	 * @see packet_get_1()
-	 */
-	NET_PACKET_CREATE_1 = NET_PACKET_FIRST,
-	
-	/**
-	 * Create packet message with specified address length, prefix, content
-	 * and suffix.
-	 * @see packet_get_4()
-	 */
-	NET_PACKET_CREATE_4,
-	
-	/** Get packet message.
-	 * @see packet_return() */
-	NET_PACKET_GET,
-	
-	/** Get packet size message.
-	 * @see packet_translate()
-	 */
-	NET_PACKET_GET_SIZE,
-	
-	/** Release packet message.
-	 * @see pq_release()
-	 */
-	NET_PACKET_RELEASE
-} packet_messages;
-
-/** Returns the protocol service message parameter. */
-#define ARP_GET_PROTO(call)	(services_t) IPC_GET_ARG2(*call)
-
-/** Returns the packet identifier message parameter. */
-#define IPC_GET_ID(call)	(packet_id_t) IPC_GET_ARG1(*call)
-
-/** Returns the maximal content length message parameter. */
-#define IPC_GET_CONTENT(call)	(size_t) IPC_GET_ARG1(*call)
-
-/** Returns the maximal address length message parameter. */
-#define IPC_GET_ADDR_LEN(call)	(size_t) IPC_GET_ARG2(*call)
-
-/** Returns the maximal prefix length message parameter. */
-#define IPC_GET_PREFIX(call)	(size_t) IPC_GET_ARG3(*call)
-
-/** Returns the maximal suffix length message parameter. */
-#define IPC_GET_SUFFIX(call)	(size_t) IPC_GET_ARG4(*call)
-
-#endif
-
-/** @}
- */
Index: pace/lib/c/include/net/packet.h
===================================================================
--- uspace/lib/c/include/net/packet.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ 	(revision )
@@ -1,101 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc 
- *  @{
- */
-
-/** @file
- *  Packet map and queue.
- */
-
-#ifndef LIBC_PACKET_H_
-#define LIBC_PACKET_H_
-
-/** Packet identifier type.
- * Value zero is used as an invalid identifier.
- */
-typedef int packet_id_t;
-
-/** Type definition of the packet.
- * @see packet
- */
-typedef struct packet * packet_t;
-
-/** Type definition of the packet pointer.
- * @see packet
- */
-typedef packet_t * packet_ref;
-
-/** Type definition of the packet dimension.
- * @see packet_dimension
- */
-typedef struct packet_dimension	packet_dimension_t;
-
-/** Type definition of the packet dimension pointer.
- * @see packet_dimension
- */
-typedef packet_dimension_t * packet_dimension_ref;
-
-/** Packet dimension. */
-struct packet_dimension {
-	/** Reserved packet prefix length. */
-	size_t prefix;
-	/** Maximal packet content length. */
-	size_t content;
-	/** Reserved packet suffix length. */
-	size_t suffix;
-	/** Maximal packet address length. */
-	size_t addr_len;
-};
-
-/** @name Packet management system interface
- */
-/*@{*/
-
-extern packet_t pm_find(packet_id_t);
-extern int pm_add(packet_t);
-extern int pm_init(void);
-extern void pm_destroy(void);
-
-extern int pq_add(packet_t *, packet_t, size_t, size_t);
-extern packet_t pq_find(packet_t, size_t);
-extern int pq_insert_after(packet_t, packet_t);
-extern packet_t pq_detach(packet_t);
-extern int pq_set_order(packet_t, size_t, size_t);
-extern int pq_get_order(packet_t, size_t *, size_t *);
-extern void pq_destroy(packet_t, void (*)(packet_t));
-extern packet_t pq_next(packet_t);
-extern packet_t pq_previous(packet_t);
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/lib/c/include/net/packet_header.h
===================================================================
--- uspace/lib/c/include/net/packet_header.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ 	(revision )
@@ -1,138 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc 
- *  @{
- */
-
-/** @file
- * Packet header.
- */
-
-#ifndef LIBC_PACKET_HEADER_H_
-#define LIBC_PACKET_HEADER_H_
-
-#include <net/packet.h>
-
-/** Returns the actual packet data length.
- * @param[in] header	The packet header.
- */
-#define PACKET_DATA_LENGTH(header) \
-	((header)->data_end - (header)->data_start)
-
-/** Returns the maximum packet address length.
- * @param[in] header	The packet header.
- */
-#define PACKET_MAX_ADDRESS_LENGTH(header) \
-	((header)->dest_addr - (header)->src_addr)
-
-/** Returns the minimum packet suffix.
- *  @param[in] header	The packet header.
- */
-#define PACKET_MIN_SUFFIX(header) \
-	((header)->length - (header)->data_start - (header)->max_content)
-
-/** Packet integrity check magic value. */
-#define PACKET_MAGIC_VALUE	0x11227788
-
-/** Packet header. */
-struct packet {
-	/** Packet identifier. */
-	packet_id_t packet_id;
-
-	/**
-	 * Packet queue sorting value.
-	 * The packet queue is sorted the ascending order.
-	 */
-	size_t order;
-
-	/** Packet metric. */
-	size_t metric;
-	/** Previous packet in the queue. */
-	packet_id_t previous;
-	/** Next packet in the queue. */
-	packet_id_t next;
-
-	/**
-	 * Total length of the packet.
-	 * Contains the header, the addresses and the data of the packet.
-	 * Corresponds to the mapped sharable memory block.
-	 */
-	size_t length;
-
-	/** Stored source and destination addresses length. */
-	size_t addr_len;
-
-	/**
-	 * Souce address offset in bytes from the beginning of the packet
-	 * header.
-	 */
-	size_t src_addr;
-
-	/**
-	 * Destination address offset in bytes from the beginning of the packet
-	 * header.
-	 */
-	size_t dest_addr;
-
-	/** Reserved data prefix length in bytes. */
-	size_t max_prefix;
-	/** Reserved content length in bytes. */
-	size_t max_content;
-
-	/**
-	 * Actual data start offset in bytes from the beginning of the packet
-	 * header.
-	 */
-	size_t data_start;
-
-	/**
-	 * Actual data end offset in bytes from the beginning of the packet
-	 * header.
-	 */
-	size_t data_end;
-
-	/** Integrity check magic value. */
-	int magic_value;
-};
-
-/** Returns whether the packet is valid.
- * @param[in] packet	The packet to be checked.
- * @returns		True if the packet is not NULL and the magic value is
- *			correct.
- * @returns		False otherwise.
- */
-static inline int packet_is_valid(const packet_t packet)
-{
-	return packet && (packet->magic_value == PACKET_MAGIC_VALUE);
-}
-
-#endif
-
-/** @}
- */
Index: uspace/lib/net/Makefile
===================================================================
--- uspace/lib/net/Makefile	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/Makefile	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -35,7 +35,5 @@
 	generic/net_remote.c \
 	generic/net_checksum.c \
-	generic/packet_client.c \
 	generic/packet_remote.c \
-	generic/socket_core.c \
 	adt/module_map.c \
 	netif/netif_local.c \
Index: pace/lib/net/generic/packet_client.c
===================================================================
--- uspace/lib/net/generic/packet_client.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ 	(revision )
@@ -1,208 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup packet
- *  @{
- */
-
-/** @file
- *  Packet client implementation.
- */
-
-#include <errno.h>
-#include <mem.h>
-#include <unistd.h>
-
-#include <sys/mman.h>
-
-#include <packet_client.h>
-
-#include <net_messages.h>
-#include <net/packet.h>
-#include <net/packet_header.h>
-
-int packet_copy_data(packet_t packet, const void * data, size_t length)
-{
-	if (!packet_is_valid(packet))
-		return EINVAL;
-
-	if (packet->data_start + length >= packet->length)
-		return ENOMEM;
-
-	memcpy((void *) packet + packet->data_start, data, length);
-	if (packet->data_start + length > packet->data_end) 
-		packet->data_end = packet->data_start + length;
-
-	return EOK;
-}
-
-void *packet_prefix(packet_t packet, size_t length)
-{
-	if ((!packet_is_valid(packet)) ||
-	    (packet->data_start - sizeof(struct packet) -
-	    2 * (packet->dest_addr - packet->src_addr) < length)) {
-		return NULL;
-	}
-
-	packet->data_start -= length;
-	return (void *) packet + packet->data_start;
-}
-
-void *packet_suffix(packet_t packet, size_t length)
-{
-	if ((!packet_is_valid(packet)) ||
-	    (packet->data_end + length >= packet->length)) {
-		return NULL;
-	}
-
-	packet->data_end += length;
-	return (void *) packet + packet->data_end - length;
-}
-
-int packet_trim(packet_t packet, size_t prefix, size_t suffix)
-{
-	if (!packet_is_valid(packet))
-		return EINVAL;
-
-	if (prefix + suffix > PACKET_DATA_LENGTH(packet))
-		return ENOMEM;
-
-	packet->data_start += prefix;
-	packet->data_end -= suffix;
-	return EOK;
-}
-
-packet_id_t packet_get_id(const packet_t packet)
-{
-	return packet_is_valid(packet) ? packet->packet_id : 0;
-}
-
-int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest)
-{
-	if (!packet_is_valid(packet))
-		return EINVAL;
-	if (!packet->addr_len)
-		return 0;
-	if (src)
-		*src = (void *) packet + packet->src_addr;
-	if (dest)
-		*dest = (void *) packet + packet->dest_addr;
-
-	return packet->addr_len;
-}
-
-size_t packet_get_data_length(const packet_t packet)
-{
-	if (!packet_is_valid(packet))
-		return 0;
-
-	return PACKET_DATA_LENGTH(packet);
-}
-
-void *packet_get_data(const packet_t packet)
-{
-	if (!packet_is_valid(packet))
-		return NULL;
-
-	return (void *) packet + packet->data_start;
-}
-
-int
-packet_set_addr(packet_t packet, const uint8_t * src, const uint8_t * dest,
-    size_t addr_len)
-{
-	size_t padding;
-	size_t allocated;
-
-	if (!packet_is_valid(packet))
-		return EINVAL;
-
-	allocated = PACKET_MAX_ADDRESS_LENGTH(packet);
-	if (allocated < addr_len)
-		return ENOMEM;
-
-	padding = allocated - addr_len;
-	packet->addr_len = addr_len;
-
-	if (src) {
-		memcpy((void *) packet + packet->src_addr, src, addr_len);
-		if (padding)
-			bzero((void *) packet + packet->src_addr + addr_len,
-			    padding);
-	} else {
-		bzero((void *) packet + packet->src_addr, allocated);
-	}
-
-	if (dest) {
-		memcpy((void *) packet + packet->dest_addr, dest, addr_len);
-		if (padding)
-			bzero((void *) packet + packet->dest_addr + addr_len,
-			    padding);
-	} else {
-		bzero((void *) packet + packet->dest_addr, allocated);
-	}
-
-	return EOK;
-}
-
-packet_t packet_get_copy(int phone, packet_t packet)
-{
-	packet_t copy;
-	uint8_t * src = NULL;
-	uint8_t * dest = NULL;
-	size_t addrlen;
-
-	if (!packet_is_valid(packet))
-		return NULL;
-
-	// get a new packet
-	copy = packet_get_4_remote(phone, PACKET_DATA_LENGTH(packet),
-	    PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix,
-	    PACKET_MIN_SUFFIX(packet));
-	if (!copy)
-		return NULL;
-
-	// get addresses
-	addrlen = packet_get_addr(packet, &src, &dest);
-	// copy data
-	if ((packet_copy_data(copy, packet_get_data(packet),
-	    PACKET_DATA_LENGTH(packet)) == EOK) &&
-	    // copy addresses if present
-	    ((addrlen <= 0) ||
-	    (packet_set_addr(copy, src, dest, addrlen) == EOK))) {
-		copy->order = packet->order;
-		copy->metric = packet->metric;
-		return copy;
-	} else {
-		pq_release_remote(phone, copy->packet_id);
-		return NULL;
-	}
-}
-
-/** @}
- */
Index: uspace/lib/net/generic/packet_remote.c
===================================================================
--- uspace/lib/net/generic/packet_remote.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/generic/packet_remote.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -40,13 +40,12 @@
 #include <err.h>
 #include <ipc/ipc.h>
-#include <ipc/packet.h>
 #include <sys/mman.h>
 
 #include <net_messages.h>
-#include <packet_client.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+#include <packet/packet_header.h>
+#include <packet/packet_messages.h>
 #include <packet_remote.h>
-
-#include <net/packet.h>
-#include <net/packet_header.h>
 
 /** Obtain the packet from the packet server as the shared memory block.
Index: pace/lib/net/generic/socket_core.c
===================================================================
--- uspace/lib/net/generic/socket_core.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ 	(revision )
@@ -1,478 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup socket
- *  @{
- */
-
-/** @file
- *  Socket common core implementation.
- */
-
-#include <net/socket_codes.h>
-#include <net/in.h>
-#include <net/inet.h>
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <err.h>
-
-#include <adt/dynamic_fifo.h>
-#include <adt/int_map.h>
-#include <net/packet.h>
-#include <packet_client.h>
-#include <packet_remote.h>
-#include <net/modules.h>
-#include <socket_core.h>
-
-/** Maximum number of random attempts to find a new socket identifier before switching to the sequence.
- */
-#define SOCKET_ID_TRIES					100
-
-/** Bound port sockets.
- */
-struct socket_port{
-	/** The bound sockets map.
-	 */
-	socket_port_map_t map;
-	/** The bound sockets count.
-	 */
-	int count;
-};
-
-INT_MAP_IMPLEMENT(socket_cores, socket_core_t);
-
-GENERIC_CHAR_MAP_IMPLEMENT(socket_port_map, socket_core_ref);
-
-INT_MAP_IMPLEMENT(socket_ports, socket_port_t);
-
-/** Destroys the socket.
- *  If the socket is bound, the port is released.
- *  Releases all buffered packets, calls the release function and removes the socket from the local sockets.
- *  @param[in] packet_phone The packet server phone to release buffered packets.
- *  @param[in] socket The socket to be destroyed.
- *  @param[in,out] local_sockets The local sockets to be updated.
- *  @param[in,out] global_sockets The global sockets to be updated.
- *  @param[in] socket_release The client release callback function.
- */
-static void socket_destroy_core(int packet_phone, socket_core_ref socket, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket)){
-	int packet_id;
-
-	// if bound
-	if(socket->port){
-		// release the port
-		socket_port_release(global_sockets, socket);
-	}
-	// release all received packets
-	while((packet_id = dyn_fifo_pop(&socket->received)) >= 0){
-		pq_release_remote(packet_phone, packet_id);
-	}
-	dyn_fifo_destroy(&socket->received);
-	dyn_fifo_destroy(&socket->accepted);
-	if(socket_release){
-		socket_release(socket);
-	}
-	socket_cores_exclude(local_sockets, socket->socket_id);
-}
-
-void socket_cores_release(int packet_phone, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket)){
-	if(socket_cores_is_valid(local_sockets)){
-		int index;
-
-		local_sockets->magic = 0;
-		for(index = 0; index < local_sockets->next; ++ index){
-			if(socket_cores_item_is_valid(&(local_sockets->items[index]))){
-				local_sockets->items[index].magic = 0;
-				if(local_sockets->items[index].value){
-					socket_destroy_core(packet_phone, local_sockets->items[index].value, local_sockets, global_sockets, socket_release);
-					free(local_sockets->items[index].value);
-					local_sockets->items[index].value = NULL;
-				}
-			}
-		}
-		free(local_sockets->items);
-	}
-}
-
-/** Adds the socket to a socket port.
- *  @param[in,out] socket_port The socket port structure.
- *  @param[in] socket The socket to be added.
- *  @param[in] key The socket key identifier.
- *  @param[in] key_length The socket key length.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left.
- */
-static int socket_port_add_core(socket_port_ref socket_port, socket_core_ref socket, const char * key, size_t key_length){
-	ERROR_DECLARE;
-
-	socket_core_ref * socket_ref;
-
-	// create a wrapper
-	socket_ref = malloc(sizeof(*socket_ref));
-	if(! socket_ref){
-		return ENOMEM;
-	}
-	*socket_ref = socket;
-	// add the wrapper
-	if(ERROR_OCCURRED(socket_port_map_add(&socket_port->map, key, key_length, socket_ref))){
-		free(socket_ref);
-		return ERROR_CODE;
-	}
-	++ socket_port->count;
-	socket->key = key;
-	socket->key_length = key_length;
-	return EOK;
-}
-
-/** Binds the socket to the port.
- *  The SOCKET_MAP_KEY_LISTENING key identifier is used.
- *  @param[in] global_sockets The global sockets to be updated.
- *  @param[in] socket The socket to be added.
- *  @param[in] port The port number to be bound to.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns Other error codes as defined for the socket_ports_add() function.
- */
-static int socket_bind_insert(socket_ports_ref global_sockets, socket_core_ref socket, int port){
-	ERROR_DECLARE;
-
-	socket_port_ref socket_port;
-
-	// create a wrapper
-	socket_port = malloc(sizeof(*socket_port));
-	if(! socket_port){
-		return ENOMEM;
-	}
-	socket_port->count = 0;
-	if(ERROR_OCCURRED(socket_port_map_initialize(&socket_port->map))
-		|| ERROR_OCCURRED(socket_port_add_core(socket_port, socket, SOCKET_MAP_KEY_LISTENING, 0))){
-		socket_port_map_destroy(&socket_port->map);
-		free(socket_port);
-		return ERROR_CODE;
-	}
-	// register the incomming port
-	ERROR_CODE = socket_ports_add(global_sockets, port, socket_port);
-	if(ERROR_CODE < 0){
-		socket_port_map_destroy(&socket_port->map);
-		free(socket_port);
-		return ERROR_CODE;
-	}
-	socket->port = port;
-	return EOK;
-}
-
-int socket_bind(socket_cores_ref local_sockets, socket_ports_ref global_sockets, int socket_id, void * addr, size_t addrlen, int free_ports_start, int free_ports_end, int last_used_port){
-	socket_core_ref socket;
-	socket_port_ref socket_port;
-	struct sockaddr * address;
-	struct sockaddr_in * address_in;
-
-	if(addrlen < sizeof(struct sockaddr)){
-		return EINVAL;
-	}
-	address = (struct sockaddr *) addr;
-	switch(address->sa_family){
-		case AF_INET:
-			if(addrlen != sizeof(struct sockaddr_in)){
-				return EINVAL;
-			}
-			address_in = (struct sockaddr_in *) addr;
-			// find the socket
-			socket = socket_cores_find(local_sockets, socket_id);
-			if(! socket){
-				return ENOTSOCK;
-			}
-			// bind a free port?
-			if(address_in->sin_port <= 0){
-				return socket_bind_free_port(global_sockets, socket, free_ports_start, free_ports_end, last_used_port);
-			}
-			// try to find the port
-			socket_port = socket_ports_find(global_sockets, ntohs(address_in->sin_port));
-			if(socket_port){
-				// already used
-				return EADDRINUSE;
-			}
-			// if bound
-			if(socket->port){
-				// release the port
-				socket_port_release(global_sockets, socket);
-			}
-			socket->port = -1;
-			return socket_bind_insert(global_sockets, socket, ntohs(address_in->sin_port));
-			break;
-		// TODO IPv6
-	}
-	return EAFNOSUPPORT;
-}
-
-int socket_bind_free_port(socket_ports_ref global_sockets, socket_core_ref socket, int free_ports_start, int free_ports_end, int last_used_port){
-	int index;
-
-	// from the last used one
-	index = last_used_port;
-	do{
-		++ index;
-		// til the range end
-		if(index >= free_ports_end){
-			// start from the range beginning
-			index = free_ports_start - 1;
-			do{
-				++ index;
-				// til the last used one
-				if(index >= last_used_port){
-					// none found
-					return ENOTCONN;
-				}
-			}while(socket_ports_find(global_sockets, index) != NULL);
-			// found, break immediately
-			break;
-		}
-	}while(socket_ports_find(global_sockets, index) != NULL);
-	return socket_bind_insert(global_sockets, socket, index);
-}
-
-/** Tries to find a new free socket identifier.
- *  @param[in] local_sockets The local sockets to be searched.
- *  @param[in] positive A value indicating whether a positive identifier is requested. A negative identifier is requested if set to false.
- *	@returns The new socket identifier.
- *  @returns ELIMIT if there is no socket identifier available.
- */
-static int socket_generate_new_id(socket_cores_ref local_sockets, int positive){
-	int socket_id;
-	int count;
-
-	count = 0;
-//	socket_id = socket_globals.last_id;
-	do{
-		if(count < SOCKET_ID_TRIES){
-			socket_id = rand() % INT_MAX;
-			++ count;
-		}else if(count == SOCKET_ID_TRIES){
-			socket_id = 1;
-			++ count;
-		// only this branch for last_id
-		}else{
-			if(socket_id < INT_MAX){
-				++ socket_id;
-/*			}else if(socket_globals.last_id){
-*				socket_globals.last_id = 0;
-*				socket_id = 1;
-*/			}else{
-				return ELIMIT;
-			}
-		}
-	}while(socket_cores_find(local_sockets, ((positive ? 1 : -1) * socket_id)));
-//	last_id = socket_id
-	return socket_id;
-}
-
-int socket_create(socket_cores_ref local_sockets, int app_phone, void * specific_data, int * socket_id){
-	ERROR_DECLARE;
-
-	socket_core_ref socket;
-	int res;
-	int positive;
-
-	if(! socket_id){
-		return EINVAL;
-	}
-	// store the socket
-	if(*socket_id <= 0){
-		positive = (*socket_id == 0);
-		*socket_id = socket_generate_new_id(local_sockets, positive);
-		if(*socket_id <= 0){
-			return * socket_id;
-		}
-		if(! positive){
-			*socket_id *= -1;
-		}
-	}else if(socket_cores_find(local_sockets, * socket_id)){
-		return EEXIST;
-	}
-	socket = (socket_core_ref) malloc(sizeof(*socket));
-	if(! socket){
-		return ENOMEM;
-	}
-	// initialize
-	socket->phone = app_phone;
-	socket->port = -1;
-	socket->key = NULL;
-	socket->key_length = 0;
-	socket->specific_data = specific_data;
-	if(ERROR_OCCURRED(dyn_fifo_initialize(&socket->received, SOCKET_INITIAL_RECEIVED_SIZE))){
-		free(socket);
-		return ERROR_CODE;
-	}
-	if(ERROR_OCCURRED(dyn_fifo_initialize(&socket->accepted, SOCKET_INITIAL_ACCEPTED_SIZE))){
-		dyn_fifo_destroy(&socket->received);
-		free(socket);
-		return ERROR_CODE;
-	}
-	socket->socket_id = * socket_id;
-	res = socket_cores_add(local_sockets, socket->socket_id, socket);
-	if(res < 0){
-		dyn_fifo_destroy(&socket->received);
-		dyn_fifo_destroy(&socket->accepted);
-		free(socket);
-		return res;
-	}
-	return EOK;
-}
-
-int socket_destroy(int packet_phone, int socket_id, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket)){
-	socket_core_ref socket;
-	int accepted_id;
-
-	// find the socket
-	socket = socket_cores_find(local_sockets, socket_id);
-	if(! socket){
-		return ENOTSOCK;
-	}
-	// destroy all accepted sockets
-	while((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0){
-		socket_destroy(packet_phone, accepted_id, local_sockets, global_sockets, socket_release);
-	}
-	socket_destroy_core(packet_phone, socket, local_sockets, global_sockets, socket_release);
-	return EOK;
-}
-
-int socket_reply_packets(packet_t packet, size_t * length){
-	ERROR_DECLARE;
-
-	packet_t next_packet;
-	size_t fragments;
-	size_t * lengths;
-	size_t index;
-
-	if(! length){
-		return EBADMEM;
-	}
-	next_packet = pq_next(packet);
-	if(! next_packet){
-		// write all if only one fragment
-		ERROR_PROPAGATE(data_reply(packet_get_data(packet), packet_get_data_length(packet)));
-		// store the total length
-		*length = packet_get_data_length(packet);
-	}else{
-		// count the packet fragments
-		fragments = 1;
-		next_packet = pq_next(packet);
-		while((next_packet = pq_next(next_packet))){
-			++ fragments;
-		}
-		// compute and store the fragment lengths
-		lengths = (size_t *) malloc(sizeof(size_t) * fragments + sizeof(size_t));
-		if(! lengths){
-			return ENOMEM;
-		}
-		lengths[0] = packet_get_data_length(packet);
-		lengths[fragments] = lengths[0];
-		next_packet = pq_next(packet);
-		for(index = 1; index < fragments; ++ index){
-			lengths[index] = packet_get_data_length(next_packet);
-			lengths[fragments] += lengths[index];
-			next_packet = pq_next(packet);
-		}while(next_packet);
-		// write the fragment lengths
-		ERROR_PROPAGATE(data_reply(lengths, sizeof(int) * (fragments + 1)));
-		next_packet = packet;
-		// write the fragments
-		for(index = 0; index < fragments; ++ index){
-			ERROR_PROPAGATE(data_reply(packet_get_data(next_packet), lengths[index]));
-			next_packet = pq_next(next_packet);
-		}while(next_packet);
-		// store the total length
-		*length = lengths[fragments];
-		free(lengths);
-	}
-	return EOK;
-}
-
-socket_core_ref socket_port_find(socket_ports_ref global_sockets, int port, const char * key, size_t key_length){
-	socket_port_ref socket_port;
-	socket_core_ref * socket_ref;
-
-	socket_port = socket_ports_find(global_sockets, port);
-	if(socket_port && (socket_port->count > 0)){
-		socket_ref = socket_port_map_find(&socket_port->map, key, key_length);
-		if(socket_ref){
-			return * socket_ref;
-		}
-	}
-	return NULL;
-}
-
-void socket_port_release(socket_ports_ref global_sockets, socket_core_ref socket){
-	socket_port_ref socket_port;
-	socket_core_ref * socket_ref;
-
-	if(socket->port){
-		// find ports
-		socket_port = socket_ports_find(global_sockets, socket->port);
-		if(socket_port){
-			// find the socket
-			socket_ref = socket_port_map_find(&socket_port->map, socket->key, socket->key_length);
-			if(socket_ref){
-				-- socket_port->count;
-				// release if empty
-				if(socket_port->count <= 0){
-					// destroy the map
-					socket_port_map_destroy(&socket_port->map);
-					// release the port
-					socket_ports_exclude(global_sockets, socket->port);
-				}else{
-					// remove
-					socket_port_map_exclude(&socket_port->map, socket->key, socket->key_length);
-				}
-			}
-		}
-		socket->port = 0;
-		socket->key = NULL;
-		socket->key_length = 0;
-	}
-}
-
-int socket_port_add(socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length){
-	ERROR_DECLARE;
-
-	socket_port_ref socket_port;
-
-	// find ports
-	socket_port = socket_ports_find(global_sockets, port);
-	if(! socket_port){
-		return ENOENT;
-	}
-	// add the socket
-	ERROR_PROPAGATE(socket_port_add_core(socket_port, socket, key, key_length));
-	socket->port = port;
-	return EOK;
-}
-
-/** @}
- */
Index: uspace/lib/net/il/ip_client.c
===================================================================
--- uspace/lib/net/il/ip_client.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/il/ip_client.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -40,8 +40,7 @@
 
 #include <ip_client.h>
-#include <packet_client.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
 #include <ip_header.h>
-
-#include <net/packet.h>
 
 size_t ip_client_header_length(packet_t packet){
Index: uspace/lib/net/il/ip_remote.c
===================================================================
--- uspace/lib/net/il/ip_remote.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/il/ip_remote.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -47,5 +47,5 @@
 #include <net/inet.h>
 #include <ip_interface.h>
-#include <packet_client.h>
+#include <packet/packet_client.h>
 #include <il_messages.h>
 #include <ip_messages.h>
Index: uspace/lib/net/include/icmp_client.h
===================================================================
--- uspace/lib/net/include/icmp_client.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/include/icmp_client.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -39,5 +39,5 @@
 
 #include <icmp_codes.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 
 /** Processes the received packet prefixed with an ICMP header.
Index: uspace/lib/net/include/icmp_interface.h
===================================================================
--- uspace/lib/net/include/icmp_interface.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/include/icmp_interface.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -39,5 +39,5 @@
 #include <net_device.h>
 #include <adt/measured_strings.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <net/inet.h>
 #include <ip_codes.h>
Index: uspace/lib/net/include/il_interface.h
===================================================================
--- uspace/lib/net/include/il_interface.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/include/il_interface.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -45,6 +45,6 @@
 #include <net_messages.h>
 #include <net_device.h>
-#include <net/packet.h>
-#include <packet_client.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
 #include <il_messages.h>
 
Index: uspace/lib/net/include/ip_client.h
===================================================================
--- uspace/lib/net/include/ip_client.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/include/ip_client.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -41,5 +41,5 @@
 #include <sys/types.h>
 
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <ip_codes.h>
 #include <ip_interface.h>
Index: uspace/lib/net/include/ip_interface.h
===================================================================
--- uspace/lib/net/include/ip_interface.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/include/ip_interface.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -39,5 +39,5 @@
 
 #include <net_device.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 
 #include <net/in.h>
Index: uspace/lib/net/include/netif_interface.h
===================================================================
--- uspace/lib/net/include/netif_interface.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/include/netif_interface.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -53,5 +53,5 @@
 
 #include <netif_remote.h>
-#include <packet_client.h>
+#include <packet/packet_client.h>
 
 #define netif_module_message    netif_module_message_standalone
Index: uspace/lib/net/include/netif_local.h
===================================================================
--- uspace/lib/net/include/netif_local.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/include/netif_local.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -48,5 +48,5 @@
 #include <adt/measured_strings.h>
 #include <net_device.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 
 /** Network interface device specific data.
Index: uspace/lib/net/include/nil_interface.h
===================================================================
--- uspace/lib/net/include/nil_interface.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/include/nil_interface.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -41,5 +41,5 @@
 #include <net_messages.h>
 #include <adt/measured_strings.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <nil_messages.h>
 #include <net_device.h>
Index: pace/lib/net/include/packet_client.h
===================================================================
--- uspace/lib/net/include/packet_client.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ 	(revision )
@@ -1,221 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup packet
- *  @{
- */
-
-/** @file
- *  Packet client.
- *  The hosting module has to be compiled with both the packet.c and the packet_client.c source files.
- *  To function correctly, initialization of the packet map by the pm_init() function has to happen at the first place.
- *  The module should not send the packet messages to the packet server but use the functions provided.
- *  The packet map should be released by the pm_destroy() function during the module termination.
- *  The packets and the packet queues can't be locked at all.
- *  The processing modules should process them sequentially -&nbsp;by passing the packets to the next module and stopping using the passed ones.
- *  @see packet.h
- */
-
-#ifndef __NET_PACKET_CLIENT_H__
-#define __NET_PACKET_CLIENT_H__
-
-#include <net/packet.h>
-
-/** @name Packet client interface
- */
-/*@{*/
-
-/** Allocates the specified type right before the actual packet content and returns its pointer.
- *  The wrapper of the packet_prepend() function.
- *  @param[in] packet The packet to be used.
- *  @param[in] type The type to be allocated at the beginning of the packet content.
- *  @returns The typed pointer to the allocated memory.
- *  @returns NULL if the packet is not valid.
- *  @returns NULL if there is not enough memory left.
- */
-#define PACKET_PREFIX(packet, type)	(type *) packet_prefix((packet), sizeof(type))
-
-/** Allocates the specified type right after the actual packet content and returns its pointer.
- *  The wrapper of the packet_append() function.
- *  @param[in] packet The packet to be used.
- *  @param[in] type The type to be allocated at the end of the packet content.
- *  @returns The typed pointer to the allocated memory.
- *  @returns NULL if the packet is not valid.
- *  @returns NULL if there is not enough memory left.
- */
-#define PACKET_SUFFIX(packet, type)	(type *) packet_suffix((packet), sizeof(type))
-
-/** Trims the actual packet content by the specified prefix and suffix types.
- *  The wrapper of the packet_trim() function.
- *  @param[in] packet The packet to be trimmed.
- *  @param[in] prefix The type of the prefix to be removed from the beginning of the packet content.
- *  @param[in] suffix The type of the suffix to be removed from the end of the packet content.
- *  @returns EOK on success.
- *  @returns EINVAL if the packet is not valid.
- *  @returns ENOMEM if there is not enough memory left.
- */
-#define PACKET_TRIM(packet, prefix, suffix)	packet_trim((packet), sizeof(prefix), sizeof(suffix))
-
-/** Allocates the specified space right before the actual packet content and returns its pointer.
- *  @param[in] packet The packet to be used.
- *  @param[in] length The space length to be allocated at the beginning of the packet content.
- *  @returns The pointer to the allocated memory.
- *  @returns NULL if there is not enough memory left.
- */
-extern void * packet_prefix(packet_t packet, size_t length);
-
-/** Allocates the specified space right after the actual packet content and returns its pointer.
- *  @param[in] packet The packet to be used.
- *  @param[in] length The space length to be allocated at the end of the packet content.
- *  @returns The pointer to the allocated memory.
- *  @returns NULL if there is not enough memory left.
- */
-extern void * packet_suffix(packet_t packet, size_t length);
-
-/** Trims the actual packet content by the specified prefix and suffix lengths.
- *  @param[in] packet The packet to be trimmed.
- *  @param[in] prefix The prefix length to be removed from the beginning of the packet content.
- *  @param[in] suffix The suffix length to be removed from the end of the packet content.
- *  @returns EOK on success.
- *  @returns EINVAL if the packet is not valid.
- *  @returns ENOMEM if there is not enough memory left.
- */
-extern int packet_trim(packet_t packet, size_t prefix, size_t suffix);
-
-/** Copies the specified data to the beginning of the actual packet content.
- *  Pushes the content end if needed.
- *  @param[in] packet The packet to be filled.
- *  @param[in] data The data to be copied.
- *  @param[in] length The length of the copied data.
- *  @returns EOK on success.
- *  @returns EINVAL if the packet is not valid.
- *  @returns ENOMEM if there is not enough memory left.
- */
-extern int packet_copy_data(packet_t packet, const void * data, size_t length);
-
-/** Returns the packet identifier.
- *  @param[in] packet The packet.
- *  @returns The packet identifier.
- *  @returns Zero (0) if the packet is not valid.
- */
-extern packet_id_t packet_get_id(const packet_t packet);
-
-/** Returns the packet content length.
- *  @param[in] packet The packet.
- *  @returns The packet content length in bytes.
- *  @returns Zero (0) if the packet is not valid.
- */
-extern size_t packet_get_data_length(const packet_t packet);
-
-/** Returns the pointer to the beginning of the packet content.
- *  @param[in] packet The packet.
- *  @returns The pointer to the beginning of the packet content.
- *  @returns NULL if the packet is not valid.
- */
-extern void * packet_get_data(const packet_t packet);
-
-/** Returns the stored packet addresses and their length.
- *  @param[in] packet The packet.
- *  @param[out] src The source address. May be NULL if not desired.
- *  @param[out] dest The destination address. May be NULL if not desired.
- *  @returns The stored addresses length.
- *  @returns Zero (0) if the addresses are not present.
- *  @returns EINVAL if the packet is not valid.
- */
-extern int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest);
-
-/** Sets the packet addresses.
- *  @param[in] packet The packet.
- *  @param[in] src The new source address. May be NULL.
- *  @param[in] dest The new destination address. May be NULL.
- *  @param[in] addr_len The addresses length.
- *  @returns EOK on success.
- *  @returns EINVAL if the packet is not valid.
- *  @returns ENOMEM if there is not enough memory left.
- */
-extern int packet_set_addr(packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len);
-
-/** Translates the packet identifier to the packet reference.
- *  Tries to find mapping first.
- *  Contacts the packet server to share the packet if the mapping is not present.
- *  @param[in] phone The packet server module phone.
- *  @param[out] packet The packet reference.
- *  @param[in] packet_id The packet identifier.
- *  @returns EOK on success.
- *  @returns EINVAL if the packet parameter is NULL.
- *  @returns Other error codes as defined for the NET_PACKET_GET_SIZE message.
- *  @returns Other error codes as defined for the packet_return() function.
- */
-extern int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id);
-
-/** Obtains the packet of the given dimensions.
- *  Contacts the packet server to return the appropriate packet.
- *  @param[in] phone The packet server module phone.
- *  @param[in] addr_len The source and destination addresses maximal length in bytes.
- *  @param[in] max_prefix The maximal prefix length in bytes.
- *  @param[in] max_content The maximal content length in bytes.
- *  @param[in] max_suffix The maximal suffix length in bytes.
- *  @returns The packet reference.
- *  @returns NULL on error.
- */
-extern packet_t packet_get_4_remote(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix);
-
-/** Obtains the packet of the given content size.
- *  Contacts the packet server to return the appropriate packet.
- *  @param[in] phone The packet server module phone.
- *  @param[in] content The maximal content length in bytes.
- *  @returns The packet reference.
- *  @returns NULL on error.
- */
-extern packet_t packet_get_1_remote(int phone, size_t content);
-
-/** Releases the packet queue.
- *  All packets in the queue are marked as free for use.
- *  The packet queue may be one packet only.
- *  The module should not use the packets after this point until they are received or obtained again.
- *  @param[in] phone The packet server module phone.
- *  @param[in] packet_id The packet identifier.
- */
-extern void pq_release_remote(int phone, packet_id_t packet_id);
-
-/** Returns the packet copy.
- *  Copies the addresses, data, order and metric values.
- *  Does not copy the queue placement.
- *  @param[in] phone The packet server module phone.
- *  @param[in] packet The original packet.
- *  @returns The packet copy.
- *  @returns NULL on error.
- */
-extern packet_t packet_get_copy(int phone, packet_t packet);
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: uspace/lib/net/include/packet_remote.h
===================================================================
--- uspace/lib/net/include/packet_remote.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/include/packet_remote.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -34,5 +34,5 @@
 #define __NET_PACKET_REMOTE_H__
 
-#include <net/packet.h>
+#include <packet/packet.h>
 
 extern int packet_translate_remote(int, packet_ref, packet_id_t);
Index: pace/lib/net/include/socket_core.h
===================================================================
--- uspace/lib/net/include/socket_core.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ 	(revision )
@@ -1,242 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup socket
- *  @{
- */
-
-/** @file
- *  Socket common core.
- */
-
-#ifndef __NET_SOCKET_CORE_H__
-#define __NET_SOCKET_CORE_H__
-
-#include <sys/types.h>
-
-#include <net/in.h>
-#include <net_device.h>
-#include <adt/generic_char_map.h>
-#include <adt/dynamic_fifo.h>
-#include <adt/int_map.h>
-#include <net/packet.h>
-
-/** Initial size of the received packet queue.
- */
-#define SOCKET_INITIAL_RECEIVED_SIZE	4
-
-/** Maximum size of the received packet queue.
- */
-#define SOCKET_MAX_RECEIVED_SIZE		0
-
-/** Initial size of the sockets for acceptance queue.
- */
-#define SOCKET_INITIAL_ACCEPTED_SIZE	1
-
-/** Maximum size of the sockets for acceptance queue.
- */
-#define SOCKET_MAX_ACCEPTEDED_SIZE		0
-
-/** Listening sockets' port map key.
- */
-#define SOCKET_MAP_KEY_LISTENING	"L"
-
-/** Type definition of the socket core.
- *  @see socket_core
- */
-typedef struct socket_core	socket_core_t;
-
-/** Type definition of the socket core pointer.
- *  @see socket_core
- */
-typedef socket_core_t *	socket_core_ref;
-
-/** Type definition of the socket port.
- *  @see socket_port
- */
-typedef struct socket_port	socket_port_t;
-
-/** Type definition of the socket port pointer.
- *  @see socket_port
- */
-typedef socket_port_t *	socket_port_ref;
-
-/** Socket core.
- */
-struct socket_core{
-	/** Socket identifier.
-	 */
-	int socket_id;
-	/** Client application phone.
-	 */
-	int phone;
-	/** Bound port.
-	 */
-	int port;
-	/** Received packets queue.
-	 */
-	dyn_fifo_t received;
-	/** Sockets for acceptance queue.
-	 */
-	dyn_fifo_t accepted;
-	/** Protocol specific data.
-	 */
-	void * specific_data;
-	/** Socket ports map key.
-	 */
-	const char * key;
-	/** Length of the Socket ports map key.
-	 */
-	size_t key_length;
-};
-
-/** Sockets map.
- *  The key is the socket identifier.
- */
-INT_MAP_DECLARE(socket_cores, socket_core_t);
-
-/** Bount port sockets map.
- *  The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas the other use the remote addresses.
- */
-GENERIC_CHAR_MAP_DECLARE(socket_port_map, socket_core_ref);
-
-/** Ports map.
- *  The key is the port number.
- */
-INT_MAP_DECLARE(socket_ports, socket_port_t);
-
-/** Destroys local sockets.
- *  Releases all buffered packets and calls the release function for each of the sockets.
- *  @param[in] packet_phone The packet server phone to release buffered packets.
- *  @param[in] local_sockets The local sockets to be destroyed.
- *  @param[in,out] global_sockets The global sockets to be updated.
- *  @param[in] socket_release The client release callback function.
- */
-extern void socket_cores_release(int packet_phone, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket));
-
-/** Binds the socket to the port.
- *  The address port is used if set, a free port is used if not.
- *  @param[in] local_sockets The local sockets to be searched.
- *  @param[in,out] global_sockets The global sockets to be updated.
- *  @param[in] socket_id The new socket identifier.
- *  @param[in] addr The address to be bound to.
- *  @param[in] addrlen The address length.
- *  @param[in] free_ports_start The minimum free port.
- *  @param[in] free_ports_end The maximum free port.
- *  @param[in] last_used_port The last used free port.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket was not found.
- *  @returns EAFNOSUPPORT if the address family is not supported.
- *  @returns EADDRINUSE if the port is already in use.
- *  @returns Other error codes as defined for the socket_bind_free_port() function.
- *  @returns Other error codes as defined for the socket_bind_insert() function.
- */
-extern int socket_bind(socket_cores_ref local_sockets, socket_ports_ref global_sockets, int socket_id, void * addr, size_t addrlen, int free_ports_start, int free_ports_end, int last_used_port);
-
-/** Binds the socket to a free port.
- *  The first free port is used.
- *  @param[in,out] global_sockets The global sockets to be updated.
- *  @param[in,out] socket The socket to be bound.
- *  @param[in] free_ports_start The minimum free port.
- *  @param[in] free_ports_end The maximum free port.
- *  @param[in] last_used_port The last used free port.
- *  @returns EOK on success.
- *  @returns ENOTCONN if no free port was found.
- *  @returns Other error codes as defined for the socket_bind_insert() function.
- */
-extern int socket_bind_free_port(socket_ports_ref global_sockets, socket_core_ref socket, int free_ports_start, int free_ports_end, int last_used_port);
-
-/** Creates a new socket.
- *  @param[in,out] local_sockets The local sockets to be updated.
- *  @param[in] app_phone The application phone.
- *  @param[in] specific_data The socket specific data.
- *  @param[in,out] socket_id The new socket identifier. A new identifier is chosen if set to zero (0) or negative. A negative identifier is chosen if set to negative.
- *  @returns EOK on success.
- *  @returns EINVAL if the socket_id parameter is NULL.
- *  @returns ENOMEM if there is not enough memory left.
- */
-extern int socket_create(socket_cores_ref local_sockets, int app_phone, void * specific_data, int * socket_id);
-
-/** Destroys the socket.
- *  If the socket is bound, the port is released.
- *  Releases all buffered packets, calls the release function and removes the socket from the local sockets.
- *  @param[in] packet_phone The packet server phone to release buffered packets.
- *  @param[in] socket_id The socket identifier.
- *  @param[in,out] local_sockets The local sockets to be updated.
- *  @param[in,out] global_sockets The global sockets to be updated.
- *  @param[in] socket_release The client release callback function.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket is not found.
- */
-extern int socket_destroy(int packet_phone, int socket_id, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket));
-
-/** Replies the packet or the packet queue data to the application via the socket.
- *  Uses the current message processing fibril.
- *  @param[in] packet The packet to be transfered.
- *  @param[out] length The total data length.
- *  @returns EOK on success.
- *  @returns EBADMEM if the length parameter is NULL.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns Other error codes as defined for the data_reply() function.
- */
-extern int socket_reply_packets(packet_t packet, size_t * length);
-
-/** Finds the bound port socket.
- *  @param[in] global_sockets The global sockets to be searched.
- *  @param[in] port The port number.
- *  @param[in] key The socket key identifier.
- *  @param[in] key_length The socket key length.
- *  @returns The found socket.
- *  @returns NULL if no socket was found.
- */
-extern socket_core_ref socket_port_find(socket_ports_ref global_sockets, int port, const char * key, size_t key_length);
-
-/** Releases the socket port.
- *  If the socket is bound the port entry is released.
- *  If there are no more port entries the port is release.
- *  @param[in] global_sockets The global sockets to be updated.
- *  @param[in] socket The socket to be unbound.
- */
-extern void socket_port_release(socket_ports_ref global_sockets, socket_core_ref socket);
-
-/** Adds the socket to an already bound port.
- *  @param[in] global_sockets The global sockets to be updated.
- *  @param[in] port The port number to be bound to.
- *  @param[in] socket The socket to be added.
- *  @param[in] key The socket key identifier.
- *  @param[in] key_length The socket key length.
- *  @returns EOK on success.
- *  @returns ENOENT if the port is not already used.
- *  @returns Other error codes as defined for the socket_port_add_core() function.
- */
-extern int socket_port_add(socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/net/include/tl_common.h
===================================================================
--- uspace/lib/net/include/tl_common.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/include/tl_common.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -39,5 +39,6 @@
 
 #include <net/socket_codes.h>
-#include <net/packet.h>
+
+#include <packet/packet.h>
 #include <net_device.h>
 #include <net/inet.h>
Index: uspace/lib/net/include/tl_interface.h
===================================================================
--- uspace/lib/net/include/tl_interface.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/include/tl_interface.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -43,6 +43,6 @@
 #include <net_messages.h>
 #include <net_device.h>
-#include <net/packet.h>
-#include <packet_client.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
 #include <tl_messages.h>
 
Index: uspace/lib/net/netif/netif_local.c
===================================================================
--- uspace/lib/net/netif/netif_local.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/netif/netif_local.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -46,6 +46,6 @@
 #include <net_messages.h>
 #include <net/modules.h>
-#include <net/packet.h>
-#include <packet_client.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
 #include <packet/packet_server.h>
 #include <packet_remote.h>
Index: uspace/lib/net/netif/netif_nil_bundle.c
===================================================================
--- uspace/lib/net/netif/netif_nil_bundle.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/netif/netif_nil_bundle.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -40,5 +40,5 @@
 #include <ipc/net.h>
 
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <netif_nil_bundle.h>
 #include <netif_local.h>
Index: uspace/lib/net/netif/netif_remote.c
===================================================================
--- uspace/lib/net/netif/netif_remote.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/netif/netif_remote.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -39,6 +39,6 @@
 #include <net/modules.h>
 #include <adt/measured_strings.h>
-#include <net/packet.h>
-#include <packet_client.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
 #include <net_device.h>
 #include <netif_remote.h>
Index: uspace/lib/net/nil/nil_remote.c
===================================================================
--- uspace/lib/net/nil/nil_remote.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/nil/nil_remote.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -39,6 +39,6 @@
 #include <net_device.h>
 #include <nil_interface.h>
-#include <net/packet.h>
-#include <packet_client.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
 #include <nil_messages.h>
 #include <nil_remote.h>
Index: uspace/lib/net/tl/icmp_client.c
===================================================================
--- uspace/lib/net/tl/icmp_client.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/tl/icmp_client.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -45,6 +45,6 @@
 #include <icmp_codes.h>
 #include <icmp_client.h>
-#include <net/packet.h>
-#include <packet_client.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
 #include <icmp_header.h>
 
Index: uspace/lib/net/tl/icmp_remote.c
===================================================================
--- uspace/lib/net/tl/icmp_remote.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/tl/icmp_remote.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -45,5 +45,5 @@
 #include <net/modules.h>
 #include <icmp_interface.h>
-#include <packet_client.h>
+#include <packet/packet_client.h>
 #include <icmp_messages.h>
 
Index: uspace/lib/net/tl/tl_common.c
===================================================================
--- uspace/lib/net/tl/tl_common.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/net/tl/tl_common.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -45,6 +45,6 @@
 #include <err.h>
 
-#include <net/packet.h>
-#include <packet_client.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
 #include <packet_remote.h>
 #include <net_device.h>
Index: uspace/lib/socket/Makefile
===================================================================
--- uspace/lib/socket/Makefile	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/socket/Makefile	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -33,7 +33,10 @@
 
 SOURCES = \
+	generic/socket_core.c \
 	generic/icmp_common.c \
 	generic/icmp_api.c \
-	packet/packet_server.c
+	packet/packet.c \
+	packet/packet_client.c \
+	packet/packet_server.c 
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/socket/generic/socket_core.c
===================================================================
--- uspace/lib/socket/generic/socket_core.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
+++ uspace/lib/socket/generic/socket_core.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -0,0 +1,477 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup socket
+ *  @{
+ */
+
+/** @file
+ *  Socket common core implementation.
+ */
+
+#include <net/socket_codes.h>
+#include <net/in.h>
+#include <net/inet.h>
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <err.h>
+
+#include <adt/dynamic_fifo.h>
+#include <adt/int_map.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+#include <net/modules.h>
+#include <socket_core.h>
+
+/** Maximum number of random attempts to find a new socket identifier before switching to the sequence.
+ */
+#define SOCKET_ID_TRIES					100
+
+/** Bound port sockets.
+ */
+struct socket_port{
+	/** The bound sockets map.
+	 */
+	socket_port_map_t map;
+	/** The bound sockets count.
+	 */
+	int count;
+};
+
+INT_MAP_IMPLEMENT(socket_cores, socket_core_t);
+
+GENERIC_CHAR_MAP_IMPLEMENT(socket_port_map, socket_core_ref);
+
+INT_MAP_IMPLEMENT(socket_ports, socket_port_t);
+
+/** Destroys the socket.
+ *  If the socket is bound, the port is released.
+ *  Releases all buffered packets, calls the release function and removes the socket from the local sockets.
+ *  @param[in] packet_phone The packet server phone to release buffered packets.
+ *  @param[in] socket The socket to be destroyed.
+ *  @param[in,out] local_sockets The local sockets to be updated.
+ *  @param[in,out] global_sockets The global sockets to be updated.
+ *  @param[in] socket_release The client release callback function.
+ */
+static void socket_destroy_core(int packet_phone, socket_core_ref socket, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket)){
+	int packet_id;
+
+	// if bound
+	if(socket->port){
+		// release the port
+		socket_port_release(global_sockets, socket);
+	}
+	// release all received packets
+	while((packet_id = dyn_fifo_pop(&socket->received)) >= 0){
+		pq_release_local(packet_phone, packet_id);
+	}
+	dyn_fifo_destroy(&socket->received);
+	dyn_fifo_destroy(&socket->accepted);
+	if(socket_release){
+		socket_release(socket);
+	}
+	socket_cores_exclude(local_sockets, socket->socket_id);
+}
+
+void socket_cores_release(int packet_phone, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket)){
+	if(socket_cores_is_valid(local_sockets)){
+		int index;
+
+		local_sockets->magic = 0;
+		for(index = 0; index < local_sockets->next; ++ index){
+			if(socket_cores_item_is_valid(&(local_sockets->items[index]))){
+				local_sockets->items[index].magic = 0;
+				if(local_sockets->items[index].value){
+					socket_destroy_core(packet_phone, local_sockets->items[index].value, local_sockets, global_sockets, socket_release);
+					free(local_sockets->items[index].value);
+					local_sockets->items[index].value = NULL;
+				}
+			}
+		}
+		free(local_sockets->items);
+	}
+}
+
+/** Adds the socket to a socket port.
+ *  @param[in,out] socket_port The socket port structure.
+ *  @param[in] socket The socket to be added.
+ *  @param[in] key The socket key identifier.
+ *  @param[in] key_length The socket key length.
+ *  @returns EOK on success.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+static int socket_port_add_core(socket_port_ref socket_port, socket_core_ref socket, const char * key, size_t key_length){
+	ERROR_DECLARE;
+
+	socket_core_ref * socket_ref;
+
+	// create a wrapper
+	socket_ref = malloc(sizeof(*socket_ref));
+	if(! socket_ref){
+		return ENOMEM;
+	}
+	*socket_ref = socket;
+	// add the wrapper
+	if(ERROR_OCCURRED(socket_port_map_add(&socket_port->map, key, key_length, socket_ref))){
+		free(socket_ref);
+		return ERROR_CODE;
+	}
+	++ socket_port->count;
+	socket->key = key;
+	socket->key_length = key_length;
+	return EOK;
+}
+
+/** Binds the socket to the port.
+ *  The SOCKET_MAP_KEY_LISTENING key identifier is used.
+ *  @param[in] global_sockets The global sockets to be updated.
+ *  @param[in] socket The socket to be added.
+ *  @param[in] port The port number to be bound to.
+ *  @returns EOK on success.
+ *  @returns ENOMEM if there is not enough memory left.
+ *  @returns Other error codes as defined for the socket_ports_add() function.
+ */
+static int socket_bind_insert(socket_ports_ref global_sockets, socket_core_ref socket, int port){
+	ERROR_DECLARE;
+
+	socket_port_ref socket_port;
+
+	// create a wrapper
+	socket_port = malloc(sizeof(*socket_port));
+	if(! socket_port){
+		return ENOMEM;
+	}
+	socket_port->count = 0;
+	if(ERROR_OCCURRED(socket_port_map_initialize(&socket_port->map))
+		|| ERROR_OCCURRED(socket_port_add_core(socket_port, socket, SOCKET_MAP_KEY_LISTENING, 0))){
+		socket_port_map_destroy(&socket_port->map);
+		free(socket_port);
+		return ERROR_CODE;
+	}
+	// register the incomming port
+	ERROR_CODE = socket_ports_add(global_sockets, port, socket_port);
+	if(ERROR_CODE < 0){
+		socket_port_map_destroy(&socket_port->map);
+		free(socket_port);
+		return ERROR_CODE;
+	}
+	socket->port = port;
+	return EOK;
+}
+
+int socket_bind(socket_cores_ref local_sockets, socket_ports_ref global_sockets, int socket_id, void * addr, size_t addrlen, int free_ports_start, int free_ports_end, int last_used_port){
+	socket_core_ref socket;
+	socket_port_ref socket_port;
+	struct sockaddr * address;
+	struct sockaddr_in * address_in;
+
+	if(addrlen < sizeof(struct sockaddr)){
+		return EINVAL;
+	}
+	address = (struct sockaddr *) addr;
+	switch(address->sa_family){
+		case AF_INET:
+			if(addrlen != sizeof(struct sockaddr_in)){
+				return EINVAL;
+			}
+			address_in = (struct sockaddr_in *) addr;
+			// find the socket
+			socket = socket_cores_find(local_sockets, socket_id);
+			if(! socket){
+				return ENOTSOCK;
+			}
+			// bind a free port?
+			if(address_in->sin_port <= 0){
+				return socket_bind_free_port(global_sockets, socket, free_ports_start, free_ports_end, last_used_port);
+			}
+			// try to find the port
+			socket_port = socket_ports_find(global_sockets, ntohs(address_in->sin_port));
+			if(socket_port){
+				// already used
+				return EADDRINUSE;
+			}
+			// if bound
+			if(socket->port){
+				// release the port
+				socket_port_release(global_sockets, socket);
+			}
+			socket->port = -1;
+			return socket_bind_insert(global_sockets, socket, ntohs(address_in->sin_port));
+			break;
+		// TODO IPv6
+	}
+	return EAFNOSUPPORT;
+}
+
+int socket_bind_free_port(socket_ports_ref global_sockets, socket_core_ref socket, int free_ports_start, int free_ports_end, int last_used_port){
+	int index;
+
+	// from the last used one
+	index = last_used_port;
+	do{
+		++ index;
+		// til the range end
+		if(index >= free_ports_end){
+			// start from the range beginning
+			index = free_ports_start - 1;
+			do{
+				++ index;
+				// til the last used one
+				if(index >= last_used_port){
+					// none found
+					return ENOTCONN;
+				}
+			}while(socket_ports_find(global_sockets, index) != NULL);
+			// found, break immediately
+			break;
+		}
+	}while(socket_ports_find(global_sockets, index) != NULL);
+	return socket_bind_insert(global_sockets, socket, index);
+}
+
+/** Tries to find a new free socket identifier.
+ *  @param[in] local_sockets The local sockets to be searched.
+ *  @param[in] positive A value indicating whether a positive identifier is requested. A negative identifier is requested if set to false.
+ *	@returns The new socket identifier.
+ *  @returns ELIMIT if there is no socket identifier available.
+ */
+static int socket_generate_new_id(socket_cores_ref local_sockets, int positive){
+	int socket_id;
+	int count;
+
+	count = 0;
+//	socket_id = socket_globals.last_id;
+	do{
+		if(count < SOCKET_ID_TRIES){
+			socket_id = rand() % INT_MAX;
+			++ count;
+		}else if(count == SOCKET_ID_TRIES){
+			socket_id = 1;
+			++ count;
+		// only this branch for last_id
+		}else{
+			if(socket_id < INT_MAX){
+				++ socket_id;
+/*			}else if(socket_globals.last_id){
+*				socket_globals.last_id = 0;
+*				socket_id = 1;
+*/			}else{
+				return ELIMIT;
+			}
+		}
+	}while(socket_cores_find(local_sockets, ((positive ? 1 : -1) * socket_id)));
+//	last_id = socket_id
+	return socket_id;
+}
+
+int socket_create(socket_cores_ref local_sockets, int app_phone, void * specific_data, int * socket_id){
+	ERROR_DECLARE;
+
+	socket_core_ref socket;
+	int res;
+	int positive;
+
+	if(! socket_id){
+		return EINVAL;
+	}
+	// store the socket
+	if(*socket_id <= 0){
+		positive = (*socket_id == 0);
+		*socket_id = socket_generate_new_id(local_sockets, positive);
+		if(*socket_id <= 0){
+			return * socket_id;
+		}
+		if(! positive){
+			*socket_id *= -1;
+		}
+	}else if(socket_cores_find(local_sockets, * socket_id)){
+		return EEXIST;
+	}
+	socket = (socket_core_ref) malloc(sizeof(*socket));
+	if(! socket){
+		return ENOMEM;
+	}
+	// initialize
+	socket->phone = app_phone;
+	socket->port = -1;
+	socket->key = NULL;
+	socket->key_length = 0;
+	socket->specific_data = specific_data;
+	if(ERROR_OCCURRED(dyn_fifo_initialize(&socket->received, SOCKET_INITIAL_RECEIVED_SIZE))){
+		free(socket);
+		return ERROR_CODE;
+	}
+	if(ERROR_OCCURRED(dyn_fifo_initialize(&socket->accepted, SOCKET_INITIAL_ACCEPTED_SIZE))){
+		dyn_fifo_destroy(&socket->received);
+		free(socket);
+		return ERROR_CODE;
+	}
+	socket->socket_id = * socket_id;
+	res = socket_cores_add(local_sockets, socket->socket_id, socket);
+	if(res < 0){
+		dyn_fifo_destroy(&socket->received);
+		dyn_fifo_destroy(&socket->accepted);
+		free(socket);
+		return res;
+	}
+	return EOK;
+}
+
+int socket_destroy(int packet_phone, int socket_id, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket)){
+	socket_core_ref socket;
+	int accepted_id;
+
+	// find the socket
+	socket = socket_cores_find(local_sockets, socket_id);
+	if(! socket){
+		return ENOTSOCK;
+	}
+	// destroy all accepted sockets
+	while((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0){
+		socket_destroy(packet_phone, accepted_id, local_sockets, global_sockets, socket_release);
+	}
+	socket_destroy_core(packet_phone, socket, local_sockets, global_sockets, socket_release);
+	return EOK;
+}
+
+int socket_reply_packets(packet_t packet, size_t * length){
+	ERROR_DECLARE;
+
+	packet_t next_packet;
+	size_t fragments;
+	size_t * lengths;
+	size_t index;
+
+	if(! length){
+		return EBADMEM;
+	}
+	next_packet = pq_next(packet);
+	if(! next_packet){
+		// write all if only one fragment
+		ERROR_PROPAGATE(data_reply(packet_get_data(packet), packet_get_data_length(packet)));
+		// store the total length
+		*length = packet_get_data_length(packet);
+	}else{
+		// count the packet fragments
+		fragments = 1;
+		next_packet = pq_next(packet);
+		while((next_packet = pq_next(next_packet))){
+			++ fragments;
+		}
+		// compute and store the fragment lengths
+		lengths = (size_t *) malloc(sizeof(size_t) * fragments + sizeof(size_t));
+		if(! lengths){
+			return ENOMEM;
+		}
+		lengths[0] = packet_get_data_length(packet);
+		lengths[fragments] = lengths[0];
+		next_packet = pq_next(packet);
+		for(index = 1; index < fragments; ++ index){
+			lengths[index] = packet_get_data_length(next_packet);
+			lengths[fragments] += lengths[index];
+			next_packet = pq_next(packet);
+		}while(next_packet);
+		// write the fragment lengths
+		ERROR_PROPAGATE(data_reply(lengths, sizeof(int) * (fragments + 1)));
+		next_packet = packet;
+		// write the fragments
+		for(index = 0; index < fragments; ++ index){
+			ERROR_PROPAGATE(data_reply(packet_get_data(next_packet), lengths[index]));
+			next_packet = pq_next(next_packet);
+		}while(next_packet);
+		// store the total length
+		*length = lengths[fragments];
+		free(lengths);
+	}
+	return EOK;
+}
+
+socket_core_ref socket_port_find(socket_ports_ref global_sockets, int port, const char * key, size_t key_length){
+	socket_port_ref socket_port;
+	socket_core_ref * socket_ref;
+
+	socket_port = socket_ports_find(global_sockets, port);
+	if(socket_port && (socket_port->count > 0)){
+		socket_ref = socket_port_map_find(&socket_port->map, key, key_length);
+		if(socket_ref){
+			return * socket_ref;
+		}
+	}
+	return NULL;
+}
+
+void socket_port_release(socket_ports_ref global_sockets, socket_core_ref socket){
+	socket_port_ref socket_port;
+	socket_core_ref * socket_ref;
+
+	if(socket->port){
+		// find ports
+		socket_port = socket_ports_find(global_sockets, socket->port);
+		if(socket_port){
+			// find the socket
+			socket_ref = socket_port_map_find(&socket_port->map, socket->key, socket->key_length);
+			if(socket_ref){
+				-- socket_port->count;
+				// release if empty
+				if(socket_port->count <= 0){
+					// destroy the map
+					socket_port_map_destroy(&socket_port->map);
+					// release the port
+					socket_ports_exclude(global_sockets, socket->port);
+				}else{
+					// remove
+					socket_port_map_exclude(&socket_port->map, socket->key, socket->key_length);
+				}
+			}
+		}
+		socket->port = 0;
+		socket->key = NULL;
+		socket->key_length = 0;
+	}
+}
+
+int socket_port_add(socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length){
+	ERROR_DECLARE;
+
+	socket_port_ref socket_port;
+
+	// find ports
+	socket_port = socket_ports_find(global_sockets, port);
+	if(! socket_port){
+		return ENOENT;
+	}
+	// add the socket
+	ERROR_PROPAGATE(socket_port_add_core(socket_port, socket, key, key_length));
+	socket->port = port;
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/socket/include/icmp_api.h
===================================================================
--- uspace/lib/socket/include/icmp_api.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/socket/include/icmp_api.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -44,5 +44,5 @@
 #include <net_device.h>
 #include <adt/measured_strings.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <ip_codes.h>
 #include <icmp_codes.h>
Index: uspace/lib/socket/include/net_messages.h
===================================================================
--- uspace/lib/socket/include/net_messages.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/socket/include/net_messages.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -44,5 +44,5 @@
 #include <net_device.h>
 #include <adt/measured_strings.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 
 /** @name Networking specific message arguments definitions
Index: uspace/lib/socket/include/packet/packet.h
===================================================================
--- uspace/lib/socket/include/packet/packet.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
+++ uspace/lib/socket/include/packet/packet.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup packet
+ *  @{
+ */
+
+/** @file
+ *  Packet map and queue.
+ */
+
+#ifndef __NET_PACKET_H__
+#define __NET_PACKET_H__
+
+/** Packet identifier type.
+ *  Value zero (0) is used as an invalid identifier.
+ */
+typedef int	packet_id_t;
+
+/** Type definition of the packet.
+ *  @see packet
+ */
+typedef struct packet *	packet_t;
+
+/** Type definition of the packet pointer.
+ *  @see packet
+ */
+typedef packet_t *		packet_ref;
+
+/** Type definition of the packet dimension.
+ *  @see packet_dimension
+ */
+typedef struct packet_dimension	packet_dimension_t;
+
+/** Type definition of the packet dimension pointer.
+ *  @see packet_dimension
+ */
+typedef packet_dimension_t *	packet_dimension_ref;
+
+/** Packet dimension.
+ */
+struct packet_dimension{
+	/** Reserved packet prefix length.
+	 */
+	size_t prefix;
+	/** Maximal packet content length.
+	 */
+	size_t content;
+	/** Reserved packet suffix length.
+	 */
+	size_t suffix;
+	/** Maximal packet address length.
+	 */
+	size_t addr_len;
+};
+
+/** @name Packet management system interface
+ */
+/*@{*/
+
+/** Finds the packet mapping.
+ *  @param[in] packet_id The packet identifier to be found.
+ *  @returns The found packet reference.
+ *  @returns NULL if the mapping does not exist.
+ */
+extern packet_t pm_find(packet_id_t packet_id);
+
+/** Adds the packet mapping.
+ *  @param[in] packet The packet to be remembered.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the packet is not valid.
+ *  @returns EINVAL if the packet map is not initialized.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int pm_add(packet_t packet);
+
+/** Initializes the packet map.
+ *  @returns EOK on success.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int pm_init(void);
+
+/** Releases the packet map.
+ */
+extern void pm_destroy(void);
+
+/** Add packet to the sorted queue.
+ *  The queue is sorted in the ascending order.
+ *  The packet is inserted right before the packets of the same order value.
+ *  @param[in,out] first The first packet of the queue. Sets the first packet of the queue. The original first packet may be shifted by the new packet.
+ *  @param[in] packet The packet to be added.
+ *  @param[in] order The packet order value.
+ *  @param[in] metric The metric value of the packet.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the first parameter is NULL.
+ *  @returns EINVAL if the packet is not valid.
+ */
+extern int pq_add(packet_t * first, packet_t packet, size_t order, size_t metric);
+
+/** Finds the packet with the given order.
+ *  @param[in] first The first packet of the queue.
+ *  @param[in] order The packet order value.
+ *  @returns The packet with the given order.
+ *  @returns NULL if the first packet is not valid.
+ *  @returns NULL if the packet is not found.
+ */
+extern packet_t pq_find(packet_t first, size_t order);
+
+/** Inserts packet after the given one.
+ *  @param[in] packet The packet in the queue.
+ *  @param[in] new_packet The new packet to be inserted.
+ *  @returns EOK on success.
+ *  @returns EINVAL if etiher of the packets is invalid.
+ */
+extern int pq_insert_after(packet_t packet, packet_t new_packet);
+
+/** Detach the packet from the queue.
+ *  @param[in] packet The packet to be detached.
+ *  @returns The next packet in the queue. If the packet is the first one of the queue, this becomes the new first one.
+ *  @returns NULL if there is no packet left.
+ *  @returns NULL if the packet is not valid.
+ */
+extern packet_t pq_detach(packet_t packet);
+
+/** Sets the packet order and metric attributes.
+ *  @param[in] packet The packet to be set.
+ *  @param[in] order The packet order value.
+ *  @param[in] metric The metric value of the packet.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the packet is invalid..
+ */
+extern int pq_set_order(packet_t packet, size_t order, size_t metric);
+
+/** Sets the packet order and metric attributes.
+ *  @param[in] packet The packet to be set.
+ *  @param[out] order The packet order value.
+ *  @param[out] metric The metric value of the packet.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the packet is invalid..
+ */
+extern int pq_get_order(packet_t packet, size_t * order, size_t * metric);
+
+/** Releases the whole queue.
+ *  Detaches all packets of the queue and calls the packet_release() for each of them.
+ *  @param[in] first The first packet of the queue.
+ *  @param[in] packet_release The releasing function called for each of the packets after its detachment.
+ */
+extern void pq_destroy(packet_t first, void (*packet_release)(packet_t packet));
+
+/** Returns the next packet in the queue.
+ *  @param[in] packet The packet queue member.
+ *  @returns The next packet in the queue.
+ *  @returns NULL if there is no next packet.
+ *  @returns NULL if the packet is not valid.
+ */
+extern packet_t pq_next(packet_t packet);
+
+/** Returns the previous packet in the queue.
+ *  @param[in] packet The packet queue member.
+ *  @returns The previous packet in the queue.
+ *  @returns NULL if there is no previous packet.
+ *  @returns NULL if the packet is not valid.
+ */
+extern packet_t pq_previous(packet_t packet);
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/packet/packet_client.h
===================================================================
--- uspace/lib/socket/include/packet/packet_client.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
+++ uspace/lib/socket/include/packet/packet_client.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup packet
+ *  @{
+ */
+
+/** @file
+ *  Packet client.
+ *  The hosting module has to be compiled with both the packet.c and the packet_client.c source files.
+ *  To function correctly, initialization of the packet map by the pm_init() function has to happen at the first place.
+ *  The module should not send the packet messages to the packet server but use the functions provided.
+ *  The packet map should be released by the pm_destroy() function during the module termination.
+ *  The packets and the packet queues can't be locked at all.
+ *  The processing modules should process them sequentially -&nbsp;by passing the packets to the next module and stopping using the passed ones.
+ *  @see packet.h
+ */
+
+#ifndef __NET_PACKET_CLIENT_H__
+#define __NET_PACKET_CLIENT_H__
+
+#include <packet/packet.h>
+
+/** @name Packet client interface
+ */
+/*@{*/
+
+/** Allocates the specified type right before the actual packet content and returns its pointer.
+ *  The wrapper of the packet_prepend() function.
+ *  @param[in] packet The packet to be used.
+ *  @param[in] type The type to be allocated at the beginning of the packet content.
+ *  @returns The typed pointer to the allocated memory.
+ *  @returns NULL if the packet is not valid.
+ *  @returns NULL if there is not enough memory left.
+ */
+#define PACKET_PREFIX(packet, type)	(type *) packet_prefix((packet), sizeof(type))
+
+/** Allocates the specified type right after the actual packet content and returns its pointer.
+ *  The wrapper of the packet_append() function.
+ *  @param[in] packet The packet to be used.
+ *  @param[in] type The type to be allocated at the end of the packet content.
+ *  @returns The typed pointer to the allocated memory.
+ *  @returns NULL if the packet is not valid.
+ *  @returns NULL if there is not enough memory left.
+ */
+#define PACKET_SUFFIX(packet, type)	(type *) packet_suffix((packet), sizeof(type))
+
+/** Trims the actual packet content by the specified prefix and suffix types.
+ *  The wrapper of the packet_trim() function.
+ *  @param[in] packet The packet to be trimmed.
+ *  @param[in] prefix The type of the prefix to be removed from the beginning of the packet content.
+ *  @param[in] suffix The type of the suffix to be removed from the end of the packet content.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the packet is not valid.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+#define PACKET_TRIM(packet, prefix, suffix)	packet_trim((packet), sizeof(prefix), sizeof(suffix))
+
+/** Allocates the specified space right before the actual packet content and returns its pointer.
+ *  @param[in] packet The packet to be used.
+ *  @param[in] length The space length to be allocated at the beginning of the packet content.
+ *  @returns The pointer to the allocated memory.
+ *  @returns NULL if there is not enough memory left.
+ */
+extern void * packet_prefix(packet_t packet, size_t length);
+
+/** Allocates the specified space right after the actual packet content and returns its pointer.
+ *  @param[in] packet The packet to be used.
+ *  @param[in] length The space length to be allocated at the end of the packet content.
+ *  @returns The pointer to the allocated memory.
+ *  @returns NULL if there is not enough memory left.
+ */
+extern void * packet_suffix(packet_t packet, size_t length);
+
+/** Trims the actual packet content by the specified prefix and suffix lengths.
+ *  @param[in] packet The packet to be trimmed.
+ *  @param[in] prefix The prefix length to be removed from the beginning of the packet content.
+ *  @param[in] suffix The suffix length to be removed from the end of the packet content.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the packet is not valid.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int packet_trim(packet_t packet, size_t prefix, size_t suffix);
+
+/** Copies the specified data to the beginning of the actual packet content.
+ *  Pushes the content end if needed.
+ *  @param[in] packet The packet to be filled.
+ *  @param[in] data The data to be copied.
+ *  @param[in] length The length of the copied data.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the packet is not valid.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int packet_copy_data(packet_t packet, const void * data, size_t length);
+
+/** Returns the packet identifier.
+ *  @param[in] packet The packet.
+ *  @returns The packet identifier.
+ *  @returns Zero (0) if the packet is not valid.
+ */
+extern packet_id_t packet_get_id(const packet_t packet);
+
+/** Returns the packet content length.
+ *  @param[in] packet The packet.
+ *  @returns The packet content length in bytes.
+ *  @returns Zero (0) if the packet is not valid.
+ */
+extern size_t packet_get_data_length(const packet_t packet);
+
+/** Returns the pointer to the beginning of the packet content.
+ *  @param[in] packet The packet.
+ *  @returns The pointer to the beginning of the packet content.
+ *  @returns NULL if the packet is not valid.
+ */
+extern void * packet_get_data(const packet_t packet);
+
+/** Returns the stored packet addresses and their length.
+ *  @param[in] packet The packet.
+ *  @param[out] src The source address. May be NULL if not desired.
+ *  @param[out] dest The destination address. May be NULL if not desired.
+ *  @returns The stored addresses length.
+ *  @returns Zero (0) if the addresses are not present.
+ *  @returns EINVAL if the packet is not valid.
+ */
+extern int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest);
+
+/** Sets the packet addresses.
+ *  @param[in] packet The packet.
+ *  @param[in] src The new source address. May be NULL.
+ *  @param[in] dest The new destination address. May be NULL.
+ *  @param[in] addr_len The addresses length.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the packet is not valid.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int packet_set_addr(packet_t packet, const uint8_t * src, const uint8_t * dest, size_t addr_len);
+
+/** Translates the packet identifier to the packet reference.
+ *  Tries to find mapping first.
+ *  Contacts the packet server to share the packet if the mapping is not present.
+ *  @param[in] phone The packet server module phone.
+ *  @param[out] packet The packet reference.
+ *  @param[in] packet_id The packet identifier.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the packet parameter is NULL.
+ *  @returns Other error codes as defined for the NET_PACKET_GET_SIZE message.
+ *  @returns Other error codes as defined for the packet_return() function.
+ */
+extern int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id);
+
+/** Obtains the packet of the given dimensions.
+ *  Contacts the packet server to return the appropriate packet.
+ *  @param[in] phone The packet server module phone.
+ *  @param[in] addr_len The source and destination addresses maximal length in bytes.
+ *  @param[in] max_prefix The maximal prefix length in bytes.
+ *  @param[in] max_content The maximal content length in bytes.
+ *  @param[in] max_suffix The maximal suffix length in bytes.
+ *  @returns The packet reference.
+ *  @returns NULL on error.
+ */
+extern packet_t packet_get_4_local(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix);
+
+/** Obtains the packet of the given content size.
+ *  Contacts the packet server to return the appropriate packet.
+ *  @param[in] phone The packet server module phone.
+ *  @param[in] content The maximal content length in bytes.
+ *  @returns The packet reference.
+ *  @returns NULL on error.
+ */
+extern packet_t packet_get_1_local(int phone, size_t content);
+
+/** Releases the packet queue.
+ *  All packets in the queue are marked as free for use.
+ *  The packet queue may be one packet only.
+ *  The module should not use the packets after this point until they are received or obtained again.
+ *  @param[in] phone The packet server module phone.
+ *  @param[in] packet_id The packet identifier.
+ */
+extern void pq_release_local(int phone, packet_id_t packet_id);
+
+/** Returns the packet copy.
+ *  Copies the addresses, data, order and metric values.
+ *  Does not copy the queue placement.
+ *  @param[in] phone The packet server module phone.
+ *  @param[in] packet The original packet.
+ *  @returns The packet copy.
+ *  @returns NULL on error.
+ */
+extern packet_t packet_get_copy(int phone, packet_t packet);
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/packet/packet_header.h
===================================================================
--- uspace/lib/socket/include/packet/packet_header.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
+++ uspace/lib/socket/include/packet/packet_header.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup packet
+ *  @{
+ */
+
+/** @file
+ *  Packet header.
+ */
+
+#ifndef __NET_PACKET_HEADER_H__
+#define __NET_PACKET_HEADER_H__
+
+#include <packet/packet.h>
+
+/** Returns the actual packet data length.
+ *  @param[in] header The packet header.
+ */
+#define PACKET_DATA_LENGTH(header)		((header)->data_end - (header)->data_start)
+
+/** Returns the maximum packet address length.
+ *  @param[in] header The packet header.
+ */
+#define PACKET_MAX_ADDRESS_LENGTH(header)		((header)->dest_addr - (header)->src_addr)
+
+/** Returns the minimum packet suffix.
+ *  @param[in] header The packet header.
+ */
+#define PACKET_MIN_SUFFIX(header)		((header)->length - (header)->data_start - (header)->max_content)
+
+/** Packet integrity check magic value.
+ */
+#define PACKET_MAGIC_VALUE	0x11227788
+
+/** Packet header.
+ */
+struct packet{
+	/** Packet identifier.
+	 */
+	packet_id_t packet_id;
+	/** Packet queue sorting value.
+	 *  The packet queue is sorted the ascending order.
+	 */
+	size_t order;
+	/** Packet metric.
+	 */
+	size_t metric;
+	/** Previous packet in the queue.
+	 */
+	packet_id_t previous;
+	/** Next packet in the queue.
+	 */
+	packet_id_t next;
+	/** Total length of the packet.
+	 *  Contains the header, the addresses and the data of the packet.
+	 *  Corresponds to the mapped sharable memory block.
+	 */
+	size_t length;
+	/** Stored source and destination addresses length.
+	 */
+	size_t addr_len;
+	/** Souce address offset in bytes from the beginning of the packet header.
+	 */
+	size_t src_addr;
+	/** Destination address offset in bytes from the beginning of the packet header.
+	 */
+	size_t dest_addr;
+	/** Reserved data prefix length in bytes.
+	 */
+	size_t max_prefix;
+	/** Reserved content length in bytes.
+	 */
+	size_t max_content;
+	/** Actual data start offset in bytes from the beginning of the packet header.
+	 */
+	size_t data_start;
+	/** Actual data end offset in bytes from the beginning of the packet header.
+	 */
+	size_t data_end;
+	/** Integrity check magic value.
+	 */
+	int magic_value;
+};
+
+/** Returns whether the packet is valid.
+ *  @param[in] packet The packet to be checked.
+ *  @returns true if the packet is not NULL and the magic value is correct.
+ *  @returns false otherwise.
+ */
+static inline int packet_is_valid(const packet_t packet){
+	return packet && (packet->magic_value == PACKET_MAGIC_VALUE);
+}
+
+#endif
+
+/** @}
+ */
Index: pace/lib/socket/include/packet/packet_local.h
===================================================================
--- uspace/lib/socket/include/packet/packet_local.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ 	(revision )
@@ -1,55 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup packet
- *  @{
- */
-
-/** @file
- */
-
-#ifndef __NET_PACKET_LOCAL_H__
-#define __NET_PACKET_LOCAL_H__
-
-#include <net/packet.h>
-
-/** @name Packet local interface
- */
-/*@{*/
-
-extern int packet_translate_local(int, packet_ref, packet_id_t);
-extern packet_t packet_get_4_local(int, size_t, size_t, size_t, size_t);
-extern packet_t packet_get_1_local(int, size_t);
-extern void pq_release_local(int, packet_id_t);
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: uspace/lib/socket/include/packet/packet_messages.h
===================================================================
--- uspace/lib/socket/include/packet/packet_messages.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
+++ uspace/lib/socket/include/packet/packet_messages.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup packet
+ *  @{
+ */
+
+/** @file
+ *  Packet server module messages.
+ */
+
+#ifndef __NET_PACKET_MESSAGES__
+#define __NET_PACKET_MESSAGES__
+
+#include <ipc/ipc.h>
+#include <ipc/net.h>
+
+/** Packet server module messages.
+ */
+typedef enum {
+	/** Create packet message with specified content length.
+	 *  @see packet_get_1()
+	 */
+	NET_PACKET_CREATE_1 = NET_PACKET_FIRST,
+	/** Create packet message with specified address length, prefix, content and suffix.
+	 *  @see packet_get_4()
+	 */
+	NET_PACKET_CREATE_4,
+	/** Get packet message.
+	 *  @see packet_return()
+	 */
+	NET_PACKET_GET,
+	/** Get packet size message.
+	 *  @see packet_translate()
+	 */
+	NET_PACKET_GET_SIZE,
+	/** Release packet message.
+	 *  @see pq_release()
+	 */
+	NET_PACKET_RELEASE
+} packet_messages;
+
+/** Returns the protocol service message parameter.
+ */
+#define ARP_GET_PROTO(call)		(services_t) IPC_GET_ARG2(*call)
+
+/** Returns the packet identifier message parameter.
+ */
+#define IPC_GET_ID(call)			(packet_id_t) IPC_GET_ARG1(*call)
+
+/** Returns the maximal content length message parameter.
+ */
+#define IPC_GET_CONTENT(call)		(size_t) IPC_GET_ARG1(*call)
+
+/** Returns the maximal address length message parameter.
+ */
+#define IPC_GET_ADDR_LEN(call)	(size_t) IPC_GET_ARG2(*call)
+
+/** Returns the maximal prefix length message parameter.
+ */
+#define IPC_GET_PREFIX(call)		(size_t) IPC_GET_ARG3(*call)
+
+/** Returns the maximal suffix length message parameter.
+ */
+#define IPC_GET_SUFFIX(call)		(size_t) IPC_GET_ARG4(*call)
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/socket_core.h
===================================================================
--- uspace/lib/socket/include/socket_core.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
+++ uspace/lib/socket/include/socket_core.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup socket
+ *  @{
+ */
+
+/** @file
+ *  Socket common core.
+ */
+
+#ifndef __NET_SOCKET_CORE_H__
+#define __NET_SOCKET_CORE_H__
+
+#include <sys/types.h>
+
+#include <net/in.h>
+#include <net_device.h>
+#include <adt/generic_char_map.h>
+#include <adt/dynamic_fifo.h>
+#include <adt/int_map.h>
+#include <packet/packet.h>
+
+/** Initial size of the received packet queue.
+ */
+#define SOCKET_INITIAL_RECEIVED_SIZE	4
+
+/** Maximum size of the received packet queue.
+ */
+#define SOCKET_MAX_RECEIVED_SIZE		0
+
+/** Initial size of the sockets for acceptance queue.
+ */
+#define SOCKET_INITIAL_ACCEPTED_SIZE	1
+
+/** Maximum size of the sockets for acceptance queue.
+ */
+#define SOCKET_MAX_ACCEPTEDED_SIZE		0
+
+/** Listening sockets' port map key.
+ */
+#define SOCKET_MAP_KEY_LISTENING	"L"
+
+/** Type definition of the socket core.
+ *  @see socket_core
+ */
+typedef struct socket_core	socket_core_t;
+
+/** Type definition of the socket core pointer.
+ *  @see socket_core
+ */
+typedef socket_core_t *	socket_core_ref;
+
+/** Type definition of the socket port.
+ *  @see socket_port
+ */
+typedef struct socket_port	socket_port_t;
+
+/** Type definition of the socket port pointer.
+ *  @see socket_port
+ */
+typedef socket_port_t *	socket_port_ref;
+
+/** Socket core.
+ */
+struct socket_core{
+	/** Socket identifier.
+	 */
+	int socket_id;
+	/** Client application phone.
+	 */
+	int phone;
+	/** Bound port.
+	 */
+	int port;
+	/** Received packets queue.
+	 */
+	dyn_fifo_t received;
+	/** Sockets for acceptance queue.
+	 */
+	dyn_fifo_t accepted;
+	/** Protocol specific data.
+	 */
+	void * specific_data;
+	/** Socket ports map key.
+	 */
+	const char * key;
+	/** Length of the Socket ports map key.
+	 */
+	size_t key_length;
+};
+
+/** Sockets map.
+ *  The key is the socket identifier.
+ */
+INT_MAP_DECLARE(socket_cores, socket_core_t);
+
+/** Bount port sockets map.
+ *  The listening socket has the SOCKET_MAP_KEY_LISTENING key identifier whereas the other use the remote addresses.
+ */
+GENERIC_CHAR_MAP_DECLARE(socket_port_map, socket_core_ref);
+
+/** Ports map.
+ *  The key is the port number.
+ */
+INT_MAP_DECLARE(socket_ports, socket_port_t);
+
+/** Destroys local sockets.
+ *  Releases all buffered packets and calls the release function for each of the sockets.
+ *  @param[in] packet_phone The packet server phone to release buffered packets.
+ *  @param[in] local_sockets The local sockets to be destroyed.
+ *  @param[in,out] global_sockets The global sockets to be updated.
+ *  @param[in] socket_release The client release callback function.
+ */
+extern void socket_cores_release(int packet_phone, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket));
+
+/** Binds the socket to the port.
+ *  The address port is used if set, a free port is used if not.
+ *  @param[in] local_sockets The local sockets to be searched.
+ *  @param[in,out] global_sockets The global sockets to be updated.
+ *  @param[in] socket_id The new socket identifier.
+ *  @param[in] addr The address to be bound to.
+ *  @param[in] addrlen The address length.
+ *  @param[in] free_ports_start The minimum free port.
+ *  @param[in] free_ports_end The maximum free port.
+ *  @param[in] last_used_port The last used free port.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket was not found.
+ *  @returns EAFNOSUPPORT if the address family is not supported.
+ *  @returns EADDRINUSE if the port is already in use.
+ *  @returns Other error codes as defined for the socket_bind_free_port() function.
+ *  @returns Other error codes as defined for the socket_bind_insert() function.
+ */
+extern int socket_bind(socket_cores_ref local_sockets, socket_ports_ref global_sockets, int socket_id, void * addr, size_t addrlen, int free_ports_start, int free_ports_end, int last_used_port);
+
+/** Binds the socket to a free port.
+ *  The first free port is used.
+ *  @param[in,out] global_sockets The global sockets to be updated.
+ *  @param[in,out] socket The socket to be bound.
+ *  @param[in] free_ports_start The minimum free port.
+ *  @param[in] free_ports_end The maximum free port.
+ *  @param[in] last_used_port The last used free port.
+ *  @returns EOK on success.
+ *  @returns ENOTCONN if no free port was found.
+ *  @returns Other error codes as defined for the socket_bind_insert() function.
+ */
+extern int socket_bind_free_port(socket_ports_ref global_sockets, socket_core_ref socket, int free_ports_start, int free_ports_end, int last_used_port);
+
+/** Creates a new socket.
+ *  @param[in,out] local_sockets The local sockets to be updated.
+ *  @param[in] app_phone The application phone.
+ *  @param[in] specific_data The socket specific data.
+ *  @param[in,out] socket_id The new socket identifier. A new identifier is chosen if set to zero (0) or negative. A negative identifier is chosen if set to negative.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the socket_id parameter is NULL.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int socket_create(socket_cores_ref local_sockets, int app_phone, void * specific_data, int * socket_id);
+
+/** Destroys the socket.
+ *  If the socket is bound, the port is released.
+ *  Releases all buffered packets, calls the release function and removes the socket from the local sockets.
+ *  @param[in] packet_phone The packet server phone to release buffered packets.
+ *  @param[in] socket_id The socket identifier.
+ *  @param[in,out] local_sockets The local sockets to be updated.
+ *  @param[in,out] global_sockets The global sockets to be updated.
+ *  @param[in] socket_release The client release callback function.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket is not found.
+ */
+extern int socket_destroy(int packet_phone, int socket_id, socket_cores_ref local_sockets, socket_ports_ref global_sockets, void (*socket_release)(socket_core_ref socket));
+
+/** Replies the packet or the packet queue data to the application via the socket.
+ *  Uses the current message processing fibril.
+ *  @param[in] packet The packet to be transfered.
+ *  @param[out] length The total data length.
+ *  @returns EOK on success.
+ *  @returns EBADMEM if the length parameter is NULL.
+ *  @returns ENOMEM if there is not enough memory left.
+ *  @returns Other error codes as defined for the data_reply() function.
+ */
+extern int socket_reply_packets(packet_t packet, size_t * length);
+
+/** Finds the bound port socket.
+ *  @param[in] global_sockets The global sockets to be searched.
+ *  @param[in] port The port number.
+ *  @param[in] key The socket key identifier.
+ *  @param[in] key_length The socket key length.
+ *  @returns The found socket.
+ *  @returns NULL if no socket was found.
+ */
+extern socket_core_ref socket_port_find(socket_ports_ref global_sockets, int port, const char * key, size_t key_length);
+
+/** Releases the socket port.
+ *  If the socket is bound the port entry is released.
+ *  If there are no more port entries the port is release.
+ *  @param[in] global_sockets The global sockets to be updated.
+ *  @param[in] socket The socket to be unbound.
+ */
+extern void socket_port_release(socket_ports_ref global_sockets, socket_core_ref socket);
+
+/** Adds the socket to an already bound port.
+ *  @param[in] global_sockets The global sockets to be updated.
+ *  @param[in] port The port number to be bound to.
+ *  @param[in] socket The socket to be added.
+ *  @param[in] key The socket key identifier.
+ *  @param[in] key_length The socket key length.
+ *  @returns EOK on success.
+ *  @returns ENOENT if the port is not already used.
+ *  @returns Other error codes as defined for the socket_port_add_core() function.
+ */
+extern int socket_port_add(socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/packet/packet.c
===================================================================
--- uspace/lib/socket/packet/packet.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
+++ uspace/lib/socket/packet/packet.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -0,0 +1,330 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup packet
+ *  @{
+ */
+
+/** @file
+ *  Packet map and queue implementation.
+ *  This file has to be compiled with both the packet server and the client.
+ */
+
+#include <malloc.h>
+#include <mem.h>
+#include <fibril_synch.h>
+#include <unistd.h>
+#include <errno.h>
+#include <err.h>
+
+#include <sys/mman.h>
+
+#include <adt/generic_field.h>
+#include <packet/packet.h>
+#include <packet/packet_header.h>
+
+/** Packet map page size.
+ */
+#define PACKET_MAP_SIZE	100
+
+/** Returns the packet map page index.
+ *  @param[in] packet_id The packet identifier.
+ */
+#define PACKET_MAP_PAGE(packet_id)	(((packet_id) - 1) / PACKET_MAP_SIZE)
+
+/** Returns the packet index in the corresponding packet map page.
+ *  @param[in] packet_id The packet identifier.
+ */
+#define PACKET_MAP_INDEX(packet_id)	(((packet_id) - 1) % PACKET_MAP_SIZE)
+
+/** Type definition of the packet map page.
+ */
+typedef packet_t packet_map_t[PACKET_MAP_SIZE];
+/** Type definition of the packet map page pointer.
+ */
+typedef packet_map_t * packet_map_ref;
+
+/** Packet map.
+ *  Maps packet identifiers to the packet references.
+ *  @see generic_field.h
+ */
+GENERIC_FIELD_DECLARE(gpm, packet_map_t);
+
+/** Releases the packet.
+ *  @param[in] packet The packet to be released.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the packet is not valid.
+ */
+int packet_destroy(packet_t packet);
+
+/** Packet map global data.
+ */
+static struct{
+	/** Safety lock.
+	 */
+	fibril_rwlock_t lock;
+	/** Packet map.
+	 */
+	gpm_t packet_map;
+} pm_globals;
+
+GENERIC_FIELD_IMPLEMENT(gpm, packet_map_t);
+
+int packet_destroy(packet_t packet){
+	if(! packet_is_valid(packet)){
+		return EINVAL;
+	}
+	return munmap(packet, packet->length);
+}
+
+int pm_init(void){
+	ERROR_DECLARE;
+
+	fibril_rwlock_initialize(&pm_globals.lock);
+	fibril_rwlock_write_lock(&pm_globals.lock);
+	ERROR_PROPAGATE(gpm_initialize(&pm_globals.packet_map));
+	fibril_rwlock_write_unlock(&pm_globals.lock);
+	return EOK;
+}
+
+packet_t pm_find(packet_id_t packet_id){
+	packet_map_ref map;
+	packet_t packet;
+
+	if(! packet_id){
+		return NULL;
+	}
+	fibril_rwlock_read_lock(&pm_globals.lock);
+	if(packet_id > PACKET_MAP_SIZE * gpm_count(&pm_globals.packet_map)){
+		fibril_rwlock_read_unlock(&pm_globals.lock);
+		return NULL;
+	}
+	map = gpm_get_index(&pm_globals.packet_map, PACKET_MAP_PAGE(packet_id));
+	if(! map){
+		fibril_rwlock_read_unlock(&pm_globals.lock);
+		return NULL;
+	}
+	packet = (*map)[PACKET_MAP_INDEX(packet_id)];
+	fibril_rwlock_read_unlock(&pm_globals.lock);
+	return packet;
+}
+
+int pm_add(packet_t packet){
+	ERROR_DECLARE;
+
+	packet_map_ref map;
+
+	if(! packet_is_valid(packet)){
+		return EINVAL;
+	}
+	fibril_rwlock_write_lock(&pm_globals.lock);
+	if(PACKET_MAP_PAGE(packet->packet_id) < gpm_count(&pm_globals.packet_map)){
+		map = gpm_get_index(&pm_globals.packet_map, PACKET_MAP_PAGE(packet->packet_id));
+	}else{
+		do{
+			map = (packet_map_ref) malloc(sizeof(packet_map_t));
+			if(! map){
+				fibril_rwlock_write_unlock(&pm_globals.lock);
+				return ENOMEM;
+			}
+			bzero(map, sizeof(packet_map_t));
+			if((ERROR_CODE = gpm_add(&pm_globals.packet_map, map)) < 0){
+				fibril_rwlock_write_unlock(&pm_globals.lock);
+				free(map);
+				return ERROR_CODE;
+			}
+		}while(PACKET_MAP_PAGE(packet->packet_id) >= gpm_count(&pm_globals.packet_map));
+	}
+	(*map)[PACKET_MAP_INDEX(packet->packet_id)] = packet;
+	fibril_rwlock_write_unlock(&pm_globals.lock);
+	return EOK;
+}
+
+void pm_destroy(void){
+	int count;
+	int index;
+	packet_map_ref map;
+	packet_t packet;
+
+	fibril_rwlock_write_lock(&pm_globals.lock);
+	count = gpm_count(&pm_globals.packet_map);
+	while(count > 0){
+		map = gpm_get_index(&pm_globals.packet_map, count - 1);
+		for(index = PACKET_MAP_SIZE - 1; index >= 0; -- index){
+			packet = (*map)[index];
+			if(packet_is_valid(packet)){
+				munmap(packet, packet->length);
+			}
+		}
+	}
+	gpm_destroy(&pm_globals.packet_map);
+	// leave locked
+}
+
+int pq_add(packet_t * first, packet_t packet, size_t order, size_t metric){
+	packet_t item;
+
+	if((! first) || (! packet_is_valid(packet))){
+		return EINVAL;
+	}
+	pq_set_order(packet, order, metric);
+	if(packet_is_valid(*first)){
+		item = * first;
+		do{
+			if(item->order < order){
+				if(item->next){
+					item = pm_find(item->next);
+				}else{
+					item->next = packet->packet_id;
+					packet->previous = item->packet_id;
+					return EOK;
+				}
+			}else{
+				packet->previous = item->previous;
+				packet->next = item->packet_id;
+				item->previous = packet->packet_id;
+				item = pm_find(packet->previous);
+				if(item){
+					item->next = packet->packet_id;
+				}else{
+					*first = packet;
+				}
+				return EOK;
+			}
+		}while(packet_is_valid(item));
+	}
+	*first = packet;
+	return EOK;
+}
+
+packet_t pq_find(packet_t packet, size_t order){
+	packet_t item;
+
+	if(! packet_is_valid(packet)){
+		return NULL;
+	}
+	item = packet;
+	do{
+		if(item->order == order){
+			return item;
+		}
+		item = pm_find(item->next);
+	}while(item && (item != packet) && packet_is_valid(item));
+	return NULL;
+}
+
+int pq_insert_after(packet_t packet, packet_t new_packet){
+	packet_t item;
+
+	if(!(packet_is_valid(packet) && packet_is_valid(new_packet))){
+		return EINVAL;
+	}
+	new_packet->previous = packet->packet_id;
+	new_packet->next = packet->next;
+	item = pm_find(packet->next);
+	if(item){
+		item->previous = new_packet->packet_id;
+	}
+	packet->next = new_packet->packet_id;
+	return EOK;
+}
+
+packet_t pq_detach(packet_t packet){
+	packet_t next;
+	packet_t previous;
+
+	if(! packet_is_valid(packet)){
+		return NULL;
+	}
+	next = pm_find(packet->next);
+	if(next){
+		next->previous = packet->previous;
+		previous = pm_find(next->previous);
+		if(previous){
+			previous->next = next->packet_id;
+		}
+	}
+	packet->previous = 0;
+	packet->next = 0;
+	return next;
+}
+
+int pq_set_order(packet_t packet, size_t order, size_t metric){
+	if(! packet_is_valid(packet)){
+		return EINVAL;
+	}
+	packet->order = order;
+	packet->metric = metric;
+	return EOK;
+}
+
+int pq_get_order(packet_t packet, size_t * order, size_t * metric){
+	if(! packet_is_valid(packet)){
+		return EINVAL;
+	}
+	if(order){
+		*order = packet->order;
+	}
+	if(metric){
+		*metric = packet->metric;
+	}
+	return EOK;
+}
+
+void pq_destroy(packet_t first, void (*packet_release)(packet_t packet)){
+	packet_t actual;
+	packet_t next;
+
+	actual = first;
+	while(packet_is_valid(actual)){
+		next = pm_find(actual->next);
+		actual->next = 0;
+		actual->previous = 0;
+		if(packet_release){
+			packet_release(actual);
+		}
+		actual = next;
+	}
+}
+
+packet_t pq_next(packet_t packet){
+	if(! packet_is_valid(packet)){
+		return NULL;
+	}
+	return pm_find(packet->next);
+}
+
+packet_t pq_previous(packet_t packet){
+	if(! packet_is_valid(packet)){
+		return NULL;
+	}
+	return pm_find(packet->previous);
+}
+
+/** @}
+ */
Index: uspace/lib/socket/packet/packet_client.c
===================================================================
--- uspace/lib/socket/packet/packet_client.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
+++ uspace/lib/socket/packet/packet_client.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup packet
+ *  @{
+ */
+
+/** @file
+ *  Packet client implementation.
+ */
+
+#include <errno.h>
+#include <mem.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+
+#include <net_messages.h>
+#include <packet/packet.h>
+#include <packet/packet_header.h>
+#include <packet/packet_client.h>
+
+int packet_copy_data(packet_t packet, const void * data, size_t length)
+{
+	if (!packet_is_valid(packet))
+		return EINVAL;
+
+	if (packet->data_start + length >= packet->length)
+		return ENOMEM;
+
+	memcpy((void *) packet + packet->data_start, data, length);
+	if (packet->data_start + length > packet->data_end) 
+		packet->data_end = packet->data_start + length;
+
+	return EOK;
+}
+
+void *packet_prefix(packet_t packet, size_t length)
+{
+	if ((!packet_is_valid(packet)) ||
+	    (packet->data_start - sizeof(struct packet) -
+	    2 * (packet->dest_addr - packet->src_addr) < length)) {
+		return NULL;
+	}
+
+	packet->data_start -= length;
+	return (void *) packet + packet->data_start;
+}
+
+void *packet_suffix(packet_t packet, size_t length)
+{
+	if ((!packet_is_valid(packet)) ||
+	    (packet->data_end + length >= packet->length)) {
+		return NULL;
+	}
+
+	packet->data_end += length;
+	return (void *) packet + packet->data_end - length;
+}
+
+int packet_trim(packet_t packet, size_t prefix, size_t suffix)
+{
+	if (!packet_is_valid(packet))
+		return EINVAL;
+
+	if (prefix + suffix > PACKET_DATA_LENGTH(packet))
+		return ENOMEM;
+
+	packet->data_start += prefix;
+	packet->data_end -= suffix;
+	return EOK;
+}
+
+packet_id_t packet_get_id(const packet_t packet)
+{
+	return packet_is_valid(packet) ? packet->packet_id : 0;
+}
+
+int packet_get_addr(const packet_t packet, uint8_t ** src, uint8_t ** dest)
+{
+	if (!packet_is_valid(packet))
+		return EINVAL;
+	if (!packet->addr_len)
+		return 0;
+	if (src)
+		*src = (void *) packet + packet->src_addr;
+	if (dest)
+		*dest = (void *) packet + packet->dest_addr;
+
+	return packet->addr_len;
+}
+
+size_t packet_get_data_length(const packet_t packet)
+{
+	if (!packet_is_valid(packet))
+		return 0;
+
+	return PACKET_DATA_LENGTH(packet);
+}
+
+void *packet_get_data(const packet_t packet)
+{
+	if (!packet_is_valid(packet))
+		return NULL;
+
+	return (void *) packet + packet->data_start;
+}
+
+int
+packet_set_addr(packet_t packet, const uint8_t * src, const uint8_t * dest,
+    size_t addr_len)
+{
+	size_t padding;
+	size_t allocated;
+
+	if (!packet_is_valid(packet))
+		return EINVAL;
+
+	allocated = PACKET_MAX_ADDRESS_LENGTH(packet);
+	if (allocated < addr_len)
+		return ENOMEM;
+
+	padding = allocated - addr_len;
+	packet->addr_len = addr_len;
+
+	if (src) {
+		memcpy((void *) packet + packet->src_addr, src, addr_len);
+		if (padding)
+			bzero((void *) packet + packet->src_addr + addr_len,
+			    padding);
+	} else {
+		bzero((void *) packet + packet->src_addr, allocated);
+	}
+
+	if (dest) {
+		memcpy((void *) packet + packet->dest_addr, dest, addr_len);
+		if (padding)
+			bzero((void *) packet + packet->dest_addr + addr_len,
+			    padding);
+	} else {
+		bzero((void *) packet + packet->dest_addr, allocated);
+	}
+
+	return EOK;
+}
+
+packet_t packet_get_copy(int phone, packet_t packet)
+{
+	packet_t copy;
+	uint8_t * src = NULL;
+	uint8_t * dest = NULL;
+	size_t addrlen;
+
+	if (!packet_is_valid(packet))
+		return NULL;
+
+	// get a new packet
+	copy = packet_get_4_local(phone, PACKET_DATA_LENGTH(packet),
+	    PACKET_MAX_ADDRESS_LENGTH(packet), packet->max_prefix,
+	    PACKET_MIN_SUFFIX(packet));
+	if (!copy)
+		return NULL;
+
+	// get addresses
+	addrlen = packet_get_addr(packet, &src, &dest);
+	// copy data
+	if ((packet_copy_data(copy, packet_get_data(packet),
+	    PACKET_DATA_LENGTH(packet)) == EOK) &&
+	    // copy addresses if present
+	    ((addrlen <= 0) ||
+	    (packet_set_addr(copy, src, dest, addrlen) == EOK))) {
+		copy->order = packet->order;
+		copy->metric = packet->metric;
+		return copy;
+	} else {
+		pq_release_local(phone, copy->packet_id);
+		return NULL;
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/socket/packet/packet_server.c
===================================================================
--- uspace/lib/socket/packet/packet_server.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/lib/socket/packet/packet_server.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -42,14 +42,14 @@
 #include <fibril_synch.h>
 #include <unistd.h>
+
+#include <ipc/ipc.h>
 #include <sys/mman.h>
 
-#include <ipc/ipc.h>
-#include <ipc/packet.h>
-#include <net/packet.h>
-#include <net/packet_header.h>
+#include <net_messages.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+#include <packet/packet_header.h>
+#include <packet/packet_messages.h>
 #include <packet/packet_server.h>
-
-#include <net_messages.h>
-#include <packet/packet_local.h>
 
 #define FREE_QUEUES_COUNT	7
Index: uspace/srv/hw/netif/dp8390/dp8390.c
===================================================================
--- uspace/srv/hw/netif/dp8390/dp8390.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/hw/netif/dp8390/dp8390.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -38,6 +38,6 @@
 
 #include <netif_local.h>
-#include <net/packet.h>
-#include <packet_client.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
 
 #include "dp8390_drv.h"
Index: uspace/srv/hw/netif/dp8390/dp8390.h
===================================================================
--- uspace/srv/hw/netif/dp8390/dp8390.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/hw/netif/dp8390/dp8390.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -36,5 +36,5 @@
 #define __NET_NETIF_DP8390_H__
 
-#include <net/packet.h>
+#include <packet/packet.h>
 
 #include "dp8390_port.h"
Index: uspace/srv/hw/netif/dp8390/dp8390_module.c
===================================================================
--- uspace/srv/hw/netif/dp8390/dp8390_module.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/hw/netif/dp8390/dp8390_module.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -46,5 +46,5 @@
 #include <net_messages.h>
 #include <net/modules.h>
-#include <packet_client.h>
+#include <packet/packet_client.h>
 #include <adt/measured_strings.h>
 #include <net_device.h>
Index: uspace/srv/net/il/arp/arp.c
===================================================================
--- uspace/srv/net/il/arp/arp.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/il/arp/arp.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -55,6 +55,6 @@
 #include <protocol_map.h>
 #include <adt/measured_strings.h>
-#include <net/packet.h>
-#include <packet_client.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
 #include <packet_remote.h>
 #include <il_messages.h>
Index: uspace/srv/net/il/arp/arp_module.c
===================================================================
--- uspace/srv/net/il/arp/arp_module.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/il/arp/arp_module.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -47,5 +47,5 @@
 #include <net/modules.h>
 #include <net_interface.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <il_local.h>
 
Index: uspace/srv/net/il/ip/ip.c
===================================================================
--- uspace/srv/net/il/ip/ip.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/il/ip/ip.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -68,5 +68,5 @@
 #include <adt/measured_strings.h>
 #include <adt/module_map.h>
-#include <packet_client.h>
+#include <packet/packet_client.h>
 #include <packet_remote.h>
 #include <nil_messages.h>
Index: uspace/srv/net/il/ip/ip_module.c
===================================================================
--- uspace/srv/net/il/ip/ip_module.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/il/ip/ip_module.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -46,5 +46,5 @@
 #include <net/modules.h>
 #include <net_interface.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <il_local.h>
 
Index: uspace/srv/net/net/net.c
===================================================================
--- uspace/srv/net/net/net.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/net/net.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -54,5 +54,5 @@
 #include <adt/measured_strings.h>
 #include <adt/module_map.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <il_messages.h>
 #include <netif_remote.h>
Index: uspace/srv/net/net/net.h
===================================================================
--- uspace/srv/net/net/net.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/net/net.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -46,5 +46,5 @@
 #include <adt/measured_strings.h>
 #include <adt/module_map.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 
 /** @name Modules definitions
Index: uspace/srv/net/netif/lo/lo.c
===================================================================
--- uspace/srv/net/netif/lo/lo.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/netif/lo/lo.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -47,5 +47,5 @@
 #include <net/modules.h>
 #include <adt/measured_strings.h>
-#include <packet_client.h>
+#include <packet/packet_client.h>
 #include <net_device.h>
 #include <nil_interface.h>
Index: uspace/srv/net/nil/eth/eth.c
===================================================================
--- uspace/srv/net/nil/eth/eth.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/nil/eth/eth.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -59,5 +59,5 @@
 #include <il_interface.h>
 #include <adt/measured_strings.h>
-#include <packet_client.h>
+#include <packet/packet_client.h>
 #include <packet_remote.h>
 #include <nil_local.h>
Index: uspace/srv/net/nil/eth/eth_module.c
===================================================================
--- uspace/srv/net/nil/eth/eth_module.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/nil/eth/eth_module.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -45,5 +45,5 @@
 #include <net/modules.h>
 #include <net_interface.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <nil_local.h>
 
Index: uspace/srv/net/nil/nildummy/nildummy.c
===================================================================
--- uspace/srv/net/nil/nildummy/nildummy.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/nil/nildummy/nildummy.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -52,5 +52,5 @@
 #include <il_interface.h>
 #include <adt/measured_strings.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <packet_remote.h>
 #include <nil_local.h>
Index: uspace/srv/net/nil/nildummy/nildummy_module.c
===================================================================
--- uspace/srv/net/nil/nildummy/nildummy_module.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/nil/nildummy/nildummy_module.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -45,5 +45,5 @@
 #include <net/modules.h>
 #include <net_interface.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <nil_local.h>
 
Index: uspace/srv/net/tl/icmp/icmp.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/tl/icmp/icmp.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -56,5 +56,5 @@
 #include <net_messages.h>
 #include <net/modules.h>
-#include <packet_client.h>
+#include <packet/packet_client.h>
 #include <packet_remote.h>
 #include <net_checksum.h>
Index: uspace/srv/net/tl/icmp/icmp_module.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp_module.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/tl/icmp/icmp_module.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -45,5 +45,5 @@
 
 #include <net/modules.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <net_interface.h>
 #include <tl_local.h>
Index: uspace/srv/net/tl/tcp/tcp.c
===================================================================
--- uspace/srv/net/tl/tcp/tcp.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/tl/tcp/tcp.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -58,5 +58,5 @@
 #include <net_messages.h>
 #include <adt/dynamic_fifo.h>
-#include <packet_client.h>
+#include <packet/packet_client.h>
 #include <packet_remote.h>
 #include <net_checksum.h>
Index: uspace/srv/net/tl/tcp/tcp.h
===================================================================
--- uspace/srv/net/tl/tcp/tcp.h	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/tl/tcp/tcp.h	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -40,5 +40,5 @@
 #include <fibril_synch.h>
 
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <net_device.h>
 #include <socket_core.h>
Index: uspace/srv/net/tl/tcp/tcp_module.c
===================================================================
--- uspace/srv/net/tl/tcp/tcp_module.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/tl/tcp/tcp_module.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -47,5 +47,5 @@
 #include <net/modules.h>
 
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <net_interface.h>
 #include <ip_interface.h>
Index: uspace/srv/net/tl/udp/udp.c
===================================================================
--- uspace/srv/net/tl/udp/udp.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/tl/udp/udp.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -55,5 +55,5 @@
 #include <net_messages.h>
 #include <adt/dynamic_fifo.h>
-#include <packet_client.h>
+#include <packet/packet_client.h>
 #include <packet_remote.h>
 #include <net_checksum.h>
Index: uspace/srv/net/tl/udp/udp_module.c
===================================================================
--- uspace/srv/net/tl/udp/udp_module.c	(revision ae97283472fc2d5817a40291d04f4a8dfae12fb0)
+++ uspace/srv/net/tl/udp/udp_module.c	(revision c0e74b13d7e036bbd53eaf5b45055d2eb8907678)
@@ -45,5 +45,5 @@
 
 #include <net/modules.h>
-#include <net/packet.h>
+#include <packet/packet.h>
 #include <net_interface.h>
 #include <tl_local.h>
