Index: uspace/app/netstart/self_test.c
===================================================================
--- uspace/app/netstart/self_test.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
+++ uspace/app/netstart/self_test.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -0,0 +1,334 @@
+/*
+ * 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 net
+ * @{
+ */
+
+/** @file
+ * Networking self-tests implementation.
+ *
+ */
+
+#include <errno.h>
+#include <malloc.h>
+#include <stdio.h>
+
+#include <net_checksum.h>
+#include <adt/int_map.h>
+#include <adt/char_map.h>
+#include <adt/generic_char_map.h>
+#include <adt/measured_strings.h>
+#include <adt/dynamic_fifo.h>
+
+#include "self_test.h"
+
+/** Test the statement, compare the result and evaluate.
+ *
+ * @param[in] statement The statement to test.
+ * @param[in] result    The expected result.
+ *
+ */
+#define TEST(statement, result) \
+	do { \
+		printf("\n\t%s == %s", #statement, #result); \
+		if ((statement) != (result)) { \
+			printf("\tfailed\n"); \
+			fprintf(stderr, "\nNetwork self-test failed\n"); \
+			return EINVAL; \
+		} else \
+			printf("\tOK"); \
+	} while (0)
+
+#define XMALLOC(var, type) \
+	do { \
+		(var) = (type *) malloc(sizeof(type)); \
+		if ((var) == NULL) { \
+			fprintf(stderr, "\nMemory allocation error\n"); \
+			return ENOMEM; \
+		} \
+	} while (0)
+
+GENERIC_CHAR_MAP_DECLARE(int_char_map, int);
+GENERIC_CHAR_MAP_IMPLEMENT(int_char_map, int);
+
+GENERIC_FIELD_DECLARE(int_field, int);
+GENERIC_FIELD_IMPLEMENT(int_field, int);
+
+INT_MAP_DECLARE(int_map, int);
+INT_MAP_IMPLEMENT(int_map, int);
+
+/** Self-test start function.
+ *
+ * Run all self-tests.
+ *
+ * @returns EOK on success.
+ * @returns The first error occurred.
+ *
+ */
+int self_test(void)
+{
+	printf("Running networking self-tests\n");
+	
+	printf("\nChar map test");
+	char_map_t cm;
+	
+	TEST(char_map_update(&cm, "ucho", 0, 3), EINVAL);
+	TEST(char_map_initialize(&cm), EOK);
+	TEST(char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL);
+	TEST(char_map_find(&cm, "bla", 0), CHAR_MAP_NULL);
+	TEST(char_map_add(&cm, "bla", 0, 1), EOK);
+	TEST(char_map_find(&cm, "bla", 0), 1);
+	TEST(char_map_add(&cm, "bla", 0, 10), EEXISTS);
+	TEST(char_map_update(&cm, "bla", 0, 2), EOK);
+	TEST(char_map_find(&cm, "bla", 0), 2);
+	TEST(char_map_update(&cm, "ucho", 0, 2), EOK);
+	TEST(char_map_exclude(&cm, "bla", 0), 2);
+	TEST(char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL);
+	TEST(char_map_find(&cm, "ucho", 0), 2);
+	TEST(char_map_update(&cm, "ucho", 0, 3), EOK);
+	TEST(char_map_find(&cm, "ucho", 0), 3);
+	TEST(char_map_add(&cm, "blabla", 0, 5), EOK);
+	TEST(char_map_find(&cm, "blabla", 0), 5);
+	TEST(char_map_add(&cm, "bla", 0, 6), EOK);
+	TEST(char_map_find(&cm, "bla", 0), 6);
+	TEST(char_map_exclude(&cm, "bla", 0), 6);
+	TEST(char_map_find(&cm, "bla", 0), CHAR_MAP_NULL);
+	TEST(char_map_find(&cm, "blabla", 0), 5);
+	TEST(char_map_add(&cm, "auto", 0, 7), EOK);
+	TEST(char_map_find(&cm, "auto", 0), 7);
+	TEST(char_map_add(&cm, "kara", 0, 8), EOK);
+	TEST(char_map_find(&cm, "kara", 0), 8);
+	TEST(char_map_add(&cm, "nic", 0, 9), EOK);
+	TEST(char_map_find(&cm, "nic", 0), 9);
+	TEST(char_map_find(&cm, "blabla", 0), 5);
+	TEST(char_map_add(&cm, "micnicnic", 5, 9), EOK);
+	TEST(char_map_find(&cm, "micni", 0), 9);
+	TEST(char_map_find(&cm, "micnicn", 5), 9);
+	TEST(char_map_add(&cm, "\x10\x0\x2\x2", 4, 15), EOK);
+	TEST(char_map_find(&cm, "\x10\x0\x2\x2", 4), 15);
+	
+	TEST((char_map_destroy(&cm), EOK), EOK);
+	TEST(char_map_update(&cm, "ucho", 0, 3), EINVAL);
+	
+	printf("\nCRC computation test");
+	uint32_t value;
+	
+	TEST(value = ~compute_crc32(~0, "123456789", 8 * 9), 0xcbf43926);
+	TEST(value = ~compute_crc32(~0, "1", 8), 0x83dcefb7);
+	TEST(value = ~compute_crc32(~0, "12", 8 * 2), 0x4f5344cd);
+	TEST(value = ~compute_crc32(~0, "123", 8 * 3), 0x884863d2);
+	TEST(value = ~compute_crc32(~0, "1234", 8 * 4), 0x9be3e0a3);
+	TEST(value = ~compute_crc32(~0, "12345678", 8 * 8), 0x9ae0daaf);
+	TEST(value = ~compute_crc32(~0, "ahoj pane", 8 * 9), 0x5fc3d706);
+	
+	printf("\nDynamic fifo test");
+	dyn_fifo_t fifo;
+	
+	TEST(dyn_fifo_push(&fifo, 1, 0), EINVAL);
+	TEST(dyn_fifo_initialize(&fifo, 1), EOK);
+	TEST(dyn_fifo_push(&fifo, 1, 0), EOK);
+	TEST(dyn_fifo_pop(&fifo), 1);
+	TEST(dyn_fifo_pop(&fifo), ENOENT);
+	TEST(dyn_fifo_push(&fifo, 2, 1), EOK);
+	TEST(dyn_fifo_push(&fifo, 3, 1), ENOMEM);
+	TEST(dyn_fifo_push(&fifo, 3, 0), EOK);
+	TEST(dyn_fifo_pop(&fifo), 2);
+	TEST(dyn_fifo_pop(&fifo), 3);
+	TEST(dyn_fifo_push(&fifo, 4, 2), EOK);
+	TEST(dyn_fifo_push(&fifo, 5, 2), EOK);
+	TEST(dyn_fifo_push(&fifo, 6, 2), ENOMEM);
+	TEST(dyn_fifo_push(&fifo, 6, 5), EOK);
+	TEST(dyn_fifo_push(&fifo, 7, 5), EOK);
+	TEST(dyn_fifo_pop(&fifo), 4);
+	TEST(dyn_fifo_pop(&fifo), 5);
+	TEST(dyn_fifo_push(&fifo, 8, 5), EOK);
+	TEST(dyn_fifo_push(&fifo, 9, 5), EOK);
+	TEST(dyn_fifo_push(&fifo, 10, 6), EOK);
+	TEST(dyn_fifo_push(&fifo, 11, 6), EOK);
+	TEST(dyn_fifo_pop(&fifo), 6);
+	TEST(dyn_fifo_pop(&fifo), 7);
+	TEST(dyn_fifo_push(&fifo, 12, 6), EOK);
+	TEST(dyn_fifo_push(&fifo, 13, 6), EOK);
+	TEST(dyn_fifo_push(&fifo, 14, 6), ENOMEM);
+	TEST(dyn_fifo_push(&fifo, 14, 8), EOK);
+	TEST(dyn_fifo_pop(&fifo), 8);
+	TEST(dyn_fifo_pop(&fifo), 9);
+	TEST(dyn_fifo_pop(&fifo), 10);
+	TEST(dyn_fifo_pop(&fifo), 11);
+	TEST(dyn_fifo_pop(&fifo), 12);
+	TEST(dyn_fifo_pop(&fifo), 13);
+	TEST(dyn_fifo_pop(&fifo), 14);
+	TEST(dyn_fifo_destroy(&fifo), EOK);
+	TEST(dyn_fifo_push(&fifo, 1, 0), EINVAL);
+	
+	printf("\nGeneric char map test");
+	
+	int *x;
+	int *y;
+	int *z;
+	int *u;
+	int *v;
+	int *w;
+	
+	XMALLOC(x, int);
+	XMALLOC(y, int);
+	XMALLOC(z, int);
+	XMALLOC(u, int);
+	XMALLOC(v, int);
+	XMALLOC(w, int);
+	
+	int_char_map_t icm;
+	icm.magic = 0;
+	
+	TEST(int_char_map_add(&icm, "ucho", 0, z), EINVAL);
+	TEST(int_char_map_initialize(&icm), EOK);
+	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
+	TEST(int_char_map_find(&icm, "bla", 0), NULL);
+	TEST(int_char_map_add(&icm, "bla", 0, x), EOK);
+	TEST(int_char_map_find(&icm, "bla", 0), x);
+	TEST(int_char_map_add(&icm, "bla", 0, y), EEXISTS);
+	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
+	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
+	TEST(int_char_map_add(&icm, "blabla", 0, v), EOK);
+	TEST(int_char_map_find(&icm, "blabla", 0), v);
+	TEST(int_char_map_add(&icm, "bla", 0, w), EOK);
+	TEST(int_char_map_find(&icm, "bla", 0), w);
+	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
+	TEST(int_char_map_find(&icm, "bla", 0), NULL);
+	TEST(int_char_map_find(&icm, "blabla", 0), v);
+	TEST(int_char_map_add(&icm, "auto", 0, u), EOK);
+	TEST(int_char_map_find(&icm, "auto", 0), u);
+	TEST((int_char_map_destroy(&icm), EOK), EOK);
+	TEST(int_char_map_add(&icm, "ucho", 0, z), EINVAL);
+	
+	printf("\nGeneric field test");
+	
+	XMALLOC(x, int);
+	XMALLOC(y, int);
+	XMALLOC(z, int);
+	XMALLOC(u, int);
+	XMALLOC(v, int);
+	XMALLOC(w, int);
+	
+	int_field_t gf;
+	gf.magic = 0;
+	
+	TEST(int_field_add(&gf, x), EINVAL);
+	TEST(int_field_count(&gf), -1);
+	TEST(int_field_initialize(&gf), EOK);
+	TEST(int_field_count(&gf), 0);
+	TEST(int_field_get_index(&gf, 1), NULL);
+	TEST(int_field_add(&gf, x), 0);
+	TEST(int_field_get_index(&gf, 0), x);
+	TEST((int_field_exclude_index(&gf, 0), EOK), EOK);
+	TEST(int_field_get_index(&gf, 0), NULL);
+	TEST(int_field_add(&gf, y), 1);
+	TEST(int_field_get_index(&gf, 1), y);
+	TEST(int_field_add(&gf, z), 2);
+	TEST(int_field_get_index(&gf, 2), z);
+	TEST(int_field_get_index(&gf, 1), y);
+	TEST(int_field_count(&gf), 3);
+	TEST(int_field_add(&gf, u), 3);
+	TEST(int_field_get_index(&gf, 3), u);
+	TEST(int_field_add(&gf, v), 4);
+	TEST(int_field_get_index(&gf, 4), v);
+	TEST(int_field_add(&gf, w), 5);
+	TEST(int_field_get_index(&gf, 5), w);
+	TEST(int_field_count(&gf), 6);
+	TEST((int_field_exclude_index(&gf, 1), EOK), EOK);
+	TEST(int_field_get_index(&gf, 1), NULL);
+	TEST(int_field_get_index(&gf, 3), u);
+	TEST((int_field_exclude_index(&gf, 7), EOK), EOK);
+	TEST(int_field_get_index(&gf, 3), u);
+	TEST(int_field_get_index(&gf, 5), w);
+	TEST((int_field_exclude_index(&gf, 4), EOK), EOK);
+	TEST(int_field_get_index(&gf, 4), NULL);
+	TEST((int_field_destroy(&gf), EOK), EOK);
+	TEST(int_field_count(&gf), -1);
+	
+	printf("\nInt map test");
+	
+	XMALLOC(x, int);
+	XMALLOC(y, int);
+	XMALLOC(z, int);
+	XMALLOC(u, int);
+	XMALLOC(v, int);
+	XMALLOC(w, int);
+	
+	int_map_t im;
+	im.magic = 0;
+	
+	TEST(int_map_add(&im, 1, x), EINVAL);
+	TEST(int_map_count(&im), -1);
+	TEST(int_map_initialize(&im), EOK);
+	TEST(int_map_count(&im), 0);
+	TEST(int_map_find(&im, 1), NULL);
+	TEST(int_map_add(&im, 1, x), 0);
+	TEST(int_map_find(&im, 1), x);
+	TEST((int_map_exclude(&im, 1), EOK), EOK);
+	TEST(int_map_find(&im, 1), NULL);
+	TEST(int_map_add(&im, 1, y), 1);
+	TEST(int_map_find(&im, 1), y);
+	TEST(int_map_add(&im, 4, z), 2);
+	TEST(int_map_get_index(&im, 2), z);
+	TEST(int_map_find(&im, 4), z);
+	TEST(int_map_find(&im, 1), y);
+	TEST(int_map_count(&im), 3);
+	TEST(int_map_add(&im, 2, u), 3);
+	TEST(int_map_find(&im, 2), u);
+	TEST(int_map_add(&im, 3, v), 4);
+	TEST(int_map_find(&im, 3), v);
+	TEST(int_map_get_index(&im, 4), v);
+	TEST(int_map_add(&im, 6, w), 5);
+	TEST(int_map_find(&im, 6), w);
+	TEST(int_map_count(&im), 6);
+	TEST((int_map_exclude(&im, 1), EOK), EOK);
+	TEST(int_map_find(&im, 1), NULL);
+	TEST(int_map_find(&im, 2), u);
+	TEST((int_map_exclude(&im, 7), EOK), EOK);
+	TEST(int_map_find(&im, 2), u);
+	TEST(int_map_find(&im, 6), w);
+	TEST((int_map_exclude_index(&im, 4), EOK), EOK);
+	TEST(int_map_get_index(&im, 4), NULL);
+	TEST(int_map_find(&im, 3), NULL);
+	TEST((int_map_destroy(&im), EOK), EOK);
+	TEST(int_map_count(&im), -1);
+	
+	printf("\nMeasured strings test");
+	
+	measured_string_ref string =
+	    measured_string_create_bulk("I am a measured string!", 0);
+	printf("\n%x, %s at %x of %d\n", string, string->value, string->value,
+	    string->length);
+	
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/app/netstart/self_test.h
===================================================================
--- uspace/app/netstart/self_test.h	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
+++ uspace/app/netstart/self_test.h	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -0,0 +1,41 @@
+/*
+ * 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 net
+ * @{
+ */
+
+#ifndef __SELF_TEST_H__
+#define __SELF_TEST_H__
+
+extern int self_test(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/packet/include/netdb.h
===================================================================
--- uspace/lib/packet/include/netdb.h	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
+++ uspace/lib/packet/include/netdb.h	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -0,0 +1,109 @@
+/*
+ * 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 netdb
+ *  @{
+ */
+
+/** @file
+ *  Structures and interfaces according to the BSD netdb.h file.
+ */
+
+#ifndef __NET_NETDB_H__
+#define __NET_NETDB_H__
+
+#include <sys/types.h>
+
+/** Structure returned by network data base library.
+ *  All addresses are supplied in host order, and returned in network order (suitable for use in system calls).
+ */
+struct	hostent {
+	/** Official host name.
+	 */
+	char * h_name;
+	/** Alias list.
+	 */
+	char **	h_aliases;
+	/** Host address type.
+	 */
+	int h_addrtype;
+	/** Address length.
+	 */
+	int h_length;
+	/** List of addresses from name server.
+	 */
+	char **	h_addr_list;
+	/** Address, for backward compatiblity.
+	 */
+#define	h_addr	h_addr_list[0]
+};
+
+/** @name Host entry address types definitions.
+ */
+/*@{*/
+
+/** Authoritative Answer Host not found address type.
+ */
+#define	HOST_NOT_FOUND	1
+
+/** Non-Authoritive Host not found, or SERVERFAIL address type.
+ */
+#define	TRY_AGAIN	2
+
+/** Non recoverable errors, FORMERR, REFUSED, NOTIMP address type.
+ */
+#define	NO_RECOVERY	3
+
+/** Valid name, no data record of requested type address type.
+ */
+#define	NO_DATA		4
+
+/** No address, look for MX record address type.
+ */
+#define	NO_ADDRESS	NO_DATA
+
+/*@}*/
+
+/** Returns host entry by the host address.
+ *  @param[in] address The host address.
+ *  @param[in] len The address length.
+ *  @param[in] type The address type.
+ *  @returns Host entry information.
+ */
+//struct hostent *	gethostbyaddr(const void * address, int len, int type);
+
+/** Returns host entry by the host name.
+ *  @param[in] name The host name.
+ *  @returns Host entry information.
+ */
+//struct hostent *	gethostbyname(const char * name);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/packet/include/tcp_codes.h
===================================================================
--- uspace/lib/packet/include/tcp_codes.h	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
+++ uspace/lib/packet/include/tcp_codes.h	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -0,0 +1,88 @@
+/*
+ * 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 tcp
+ *  @{
+ */
+
+/** @file
+ *  TCP options definitions.
+ */
+
+#ifndef __NET_TCP_CODES_H__
+#define __NET_TCP_CODES_H__
+
+/** End of list TCP option.
+ */
+#define TCPOPT_END_OF_LIST				0x0
+
+/** No operation TCP option.
+ */
+#define TCPOPT_NO_OPERATION				0x1
+
+/** Maximum segment size TCP option.
+ */
+#define TCPOPT_MAX_SEGMENT_SIZE			0x2
+
+/** Maximum segment size TCP option length.
+ */
+#define TCPOPT_MAX_SEGMENT_SIZE_LENGTH	4
+
+/** Window scale TCP option.
+ */
+#define TCPOPT_WINDOW_SCALE				0x3
+
+/** Window scale TCP option length.
+ */
+#define TCPOPT_WINDOW_SCALE_LENGTH		3
+
+/** Selective acknowledgement permitted TCP option.
+ */
+#define TCPOPT_SACK_PERMITTED			0x4
+
+/** Selective acknowledgement permitted TCP option length.
+ */
+#define TCPOPT_SACK_PERMITTED_LENGTH	2
+
+/** Selective acknowledgement TCP option.
+ *  Has variable length.
+ */
+#define TCPOPT_SACK						0x5
+
+/** Timestamp TCP option.
+ */
+#define TCPOPT_TIMESTAMP				0x8
+
+/** Timestamp TCP option length.
+ */
+#define TCPOPT_TIMESTAMP_LENGTH			10
+
+#endif
+
+/** @}
+ */
Index: uspace/srv/net/il/arp/arp.c
===================================================================
--- uspace/srv/net/il/arp/arp.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/il/arp/arp.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -55,5 +55,5 @@
 #include <ipc/il.h>
 #include <byteorder.h>
-#include <errno.h>
+#include <err.h>
 
 #include <net/modules.h>
@@ -179,20 +179,16 @@
     measured_string_ref address)
 {
-	int rc;
+	ERROR_DECLARE;
 
 	*proto = (arp_proto_ref) malloc(sizeof(arp_proto_t));
 	if (!*proto)
 		return ENOMEM;
-	
 	(*proto)->service = service;
 	(*proto)->addr = address;
 	(*proto)->addr_data = address->value;
-	
-	rc = arp_addr_initialize(&(*proto)->addresses);
-	if (rc != EOK) {
+	if (ERROR_OCCURRED(arp_addr_initialize(&(*proto)->addresses))) {
 		free(*proto);
-		return rc;
-	}
-	
+		return ERROR_CODE;
+	}
 	return EOK;
 }
@@ -218,9 +214,10 @@
     services_t protocol, measured_string_ref address)
 {
+	ERROR_DECLARE;
+
 	arp_device_ref device;
 	arp_proto_ref proto;
+	int index;
 	hw_type_t hardware;
-	int index;
-	int rc;
 
 	fibril_rwlock_write_lock(&arp_globals.lock);
@@ -240,8 +237,8 @@
 			proto->addr_data = address->value;
 		} else {
-			rc = arp_proto_create(&proto, protocol, address);
-			if (rc != EOK) {
+			if (ERROR_OCCURRED(arp_proto_create(&proto, protocol,
+			    address))) {
 				fibril_rwlock_write_unlock(&arp_globals.lock);
-				return rc;
+				return ERROR_CODE;
 			}
 			index = arp_protos_add(&device->protos, proto->service,
@@ -268,15 +265,10 @@
 		device->hardware = hardware;
 		device->device_id = device_id;
-		rc = arp_protos_initialize(&device->protos);
-		if (rc != EOK) {
+		if (ERROR_OCCURRED(arp_protos_initialize(&device->protos)) ||
+		    ERROR_OCCURRED(arp_proto_create(&proto, protocol,
+		    address))) {
 			fibril_rwlock_write_unlock(&arp_globals.lock);
 			free(device);
-			return rc;
-		}
-		rc = arp_proto_create(&proto, protocol, address);
-		if (rc != EOK) {
-			fibril_rwlock_write_unlock(&arp_globals.lock);
-			free(device);
-			return rc;
+			return ERROR_CODE;
 		}
 		index = arp_protos_add(&device->protos, proto->service, proto);
@@ -301,27 +293,25 @@
 		
 		// get packet dimensions
-		rc = nil_packet_size_req(device->phone, device_id,
-		    &device->packet_dimension);
-		if (rc != EOK) {
+		if (ERROR_OCCURRED(nil_packet_size_req(device->phone, device_id,
+		    &device->packet_dimension))) {
 			fibril_rwlock_write_unlock(&arp_globals.lock);
 			arp_protos_destroy(&device->protos);
 			free(device);
-			return rc;
+			return ERROR_CODE;
 		}
 		
 		// get hardware address
-		rc = nil_get_addr_req(device->phone, device_id, &device->addr,
-		    &device->addr_data);
-		if (rc != EOK) {
+		if (ERROR_OCCURRED(nil_get_addr_req(device->phone, device_id,
+		    &device->addr, &device->addr_data))) {
 			fibril_rwlock_write_unlock(&arp_globals.lock);
 			arp_protos_destroy(&device->protos);
 			free(device);
-			return rc;
+			return ERROR_CODE;
 		}
 		
 		// get broadcast address
-		rc = nil_get_broadcast_addr_req(device->phone, device_id,
-		    &device->broadcast_addr, &device->broadcast_data);
-		if (rc != EOK) {
+		if (ERROR_OCCURRED(nil_get_broadcast_addr_req(device->phone,
+		    device_id, &device->broadcast_addr,
+		    &device->broadcast_data))) {
 			fibril_rwlock_write_unlock(&arp_globals.lock);
 			free(device->addr);
@@ -329,10 +319,9 @@
 			arp_protos_destroy(&device->protos);
 			free(device);
-			return rc;
-		}
-		
-		rc = arp_cache_add(&arp_globals.cache, device->device_id,
-		    device);
-		if (rc != EOK) {
+			return ERROR_CODE;
+		}
+		
+		if (ERROR_OCCURRED(arp_cache_add(&arp_globals.cache,
+		    device->device_id, device))) {
 			fibril_rwlock_write_unlock(&arp_globals.lock);
 			free(device->addr);
@@ -342,5 +331,5 @@
 			arp_protos_destroy(&device->protos);
 			free(device);
-			return rc;
+			return ERROR_CODE;
 		}
 		printf("%s: Device registered (id: %d, type: 0x%x, service: %d,"
@@ -362,13 +351,12 @@
 int arp_initialize(async_client_conn_t client_connection)
 {
-	int rc;
+	ERROR_DECLARE;
 
 	fibril_rwlock_initialize(&arp_globals.lock);
 	fibril_rwlock_write_lock(&arp_globals.lock);
 	arp_globals.client_connection = client_connection;
-	rc = arp_cache_initialize(&arp_globals.cache);
+	ERROR_PROPAGATE(arp_cache_initialize(&arp_globals.cache));
 	fibril_rwlock_write_unlock(&arp_globals.lock);
-	
-	return rc;
+	return EOK;
 }
 
@@ -418,4 +406,6 @@
 static int arp_receive_message(device_id_t device_id, packet_t packet)
 {
+	ERROR_DECLARE;
+
 	size_t length;
 	arp_header_ref header;
@@ -427,5 +417,4 @@
 	uint8_t *des_hw;
 	uint8_t *des_proto;
-	int rc;
 
 	length = packet_get_data_length(packet);
@@ -478,9 +467,7 @@
 				return ENOMEM;
 
-			rc = arp_addr_add(&proto->addresses, (char *) src_proto,
-			    CONVERT_SIZE(uint8_t, char,
-			    header->protocol_length), hw_source);
-			if (rc != EOK)
-				return rc;
+			ERROR_PROPAGATE(arp_addr_add(&proto->addresses,
+			    (char *) src_proto, CONVERT_SIZE(uint8_t, char,
+			    header->protocol_length), hw_source));
 		}
 		if (ntohs(header->operation) == ARPOP_REQUEST) {
@@ -493,10 +480,6 @@
 			memcpy(des_hw, hw_source->value,
 			    header->hardware_length);
-			
-			rc = packet_set_addr(packet, src_hw, des_hw,
-			    header->hardware_length);
-			if (rc != EOK)
-				return rc;
-			
+			ERROR_PROPAGATE(packet_set_addr(packet, src_hw, des_hw,
+			    header->hardware_length));
 			nil_send_msg(device->phone, device_id, packet,
 			    SERVICE_ARP);
@@ -613,4 +596,6 @@
     ipc_call_t *answer, int *answer_count)
 {
+	ERROR_DECLARE;
+	
 	measured_string_ref address;
 	measured_string_ref translation;
@@ -618,5 +603,4 @@
 	packet_t packet;
 	packet_t next;
-	int rc;
 	
 	*answer_count = 0;
@@ -626,21 +610,14 @@
 	
 	case NET_ARP_DEVICE:
-		rc = measured_strings_receive(&address, &data, 1);
-		if (rc != EOK)
-			return rc;
-		
-		rc = arp_device_message(IPC_GET_DEVICE(call),
-		    IPC_GET_SERVICE(call), ARP_GET_NETIF(call), address);
-		if (rc != EOK) {
+		ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1));
+		if (ERROR_OCCURRED(arp_device_message(IPC_GET_DEVICE(call),
+		    IPC_GET_SERVICE(call), ARP_GET_NETIF(call), address))) {
 			free(address);
 			free(data);
 		}
-		return rc;
+		return ERROR_CODE;
 	
 	case NET_ARP_TRANSLATE:
-		rc = measured_strings_receive(&address, &data, 1);
-		if (rc != EOK)
-			return rc;
-		
+		ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1));
 		fibril_rwlock_read_lock(&arp_globals.lock);
 		translation = arp_translate_message(IPC_GET_DEVICE(call),
@@ -652,7 +629,7 @@
 			return ENOENT;
 		}
-		rc = measured_strings_reply(translation, 1);
+		ERROR_CODE = measured_strings_reply(translation, 1);
 		fibril_rwlock_read_unlock(&arp_globals.lock);
-		return rc;
+		return ERROR_CODE;
 
 	case NET_ARP_CLEAR_DEVICE:
@@ -660,8 +637,5 @@
 
 	case NET_ARP_CLEAR_ADDRESS:
-		rc = measured_strings_receive(&address, &data, 1);
-		if (rc != EOK)
-			return rc;
-		
+		ERROR_PROPAGATE(measured_strings_receive(&address, &data, 1));
 		arp_clear_address_req(0, IPC_GET_DEVICE(call),
 		    IPC_GET_SERVICE(call), address);
@@ -678,22 +652,21 @@
 	
 	case NET_IL_RECEIVED:
-		rc = packet_translate_remote(arp_globals.net_phone, &packet,
-		    IPC_GET_PACKET(call));
-		if (rc != EOK)
-			return rc;
-		
-		fibril_rwlock_read_lock(&arp_globals.lock);
-		do {
-			next = pq_detach(packet);
-			rc = arp_receive_message(IPC_GET_DEVICE(call), packet);
-			if (rc != 1) {
-				pq_release_remote(arp_globals.net_phone,
-				    packet_get_id(packet));
-			}
-			packet = next;
-		} while (packet);
-		fibril_rwlock_read_unlock(&arp_globals.lock);
-		
-		return EOK;
+		if (ERROR_NONE(packet_translate_remote(arp_globals.net_phone,
+		    &packet, IPC_GET_PACKET(call)))) {
+			fibril_rwlock_read_lock(&arp_globals.lock);
+			do {
+				next = pq_detach(packet);
+				ERROR_CODE =
+				    arp_receive_message(IPC_GET_DEVICE(call),
+				    packet);
+				if (ERROR_CODE != 1) {
+					pq_release_remote(arp_globals.net_phone,
+					    packet_get_id(packet));
+				}
+				packet = next;
+			} while (packet);
+			fibril_rwlock_read_unlock(&arp_globals.lock);
+		}
+		return ERROR_CODE;
 	
 	case NET_IL_MTU_CHANGED:
@@ -754,9 +727,9 @@
 int main(int argc, char *argv[])
 {
-	int rc;
+	ERROR_DECLARE;
 	
 	/* Start the module */
-	rc = il_module_start_standalone(il_client_connection);
-	return rc;
+	ERROR_PROPAGATE(il_module_start_standalone(il_client_connection));
+	return EOK;
 }
 
Index: uspace/srv/net/il/arp/arp_module.c
===================================================================
--- uspace/srv/net/il/arp/arp_module.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/il/arp/arp_module.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -41,5 +41,5 @@
 #include <async.h>
 #include <stdio.h>
-#include <errno.h>
+#include <err.h>
 
 #include <ipc/ipc.h>
@@ -66,27 +66,21 @@
 int il_module_start_standalone(async_client_conn_t client_connection)
 {
-	ipcarg_t phonehash;
-	int rc;
+	ERROR_DECLARE;
 	
 	async_set_client_connection(client_connection);
 	arp_globals.net_phone = net_connect_module();
+	ERROR_PROPAGATE(pm_init());
 	
-	rc = pm_init();
-	if (rc != EOK)
-		return rc;
-	
-	rc = arp_initialize(client_connection);
-	if (rc != EOK)
-		goto out;
-	
-	rc = REGISTER_ME(SERVICE_ARP, &phonehash);
-	if (rc != EOK)
-		goto out;
+	ipcarg_t phonehash;
+	if (ERROR_OCCURRED(arp_initialize(client_connection)) ||
+	    ERROR_OCCURRED(REGISTER_ME(SERVICE_ARP, &phonehash))) {
+		pm_destroy();
+		return ERROR_CODE;
+	}
 	
 	async_manager();
-
-out:
+	
 	pm_destroy();
-	return rc;
+	return EOK;
 }
 
Index: uspace/srv/net/il/ip/ip.c
===================================================================
--- uspace/srv/net/il/ip/ip.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/il/ip/ip.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -41,4 +41,5 @@
 #include <async.h>
 #include <errno.h>
+#include <err.h>
 #include <fibril_synch.h>
 #include <stdio.h>
@@ -253,5 +254,5 @@
 int ip_initialize(async_client_conn_t client_connection)
 {
-	int rc;
+	ERROR_DECLARE;
 
 	fibril_rwlock_initialize(&ip_globals.lock);
@@ -264,22 +265,13 @@
 	ip_globals.gateway.gateway.s_addr = 0;
 	ip_globals.gateway.netif = NULL;
+	ERROR_PROPAGATE(ip_netifs_initialize(&ip_globals.netifs));
+	ERROR_PROPAGATE(ip_protos_initialize(&ip_globals.protos));
 	ip_globals.client_connection = client_connection;
-	
-	rc = ip_netifs_initialize(&ip_globals.netifs);
-	if (rc != EOK)
-		goto out;
-	rc = ip_protos_initialize(&ip_globals.protos);
-	if (rc != EOK)
-		goto out;
-	rc = modules_initialize(&ip_globals.modules);
-	if (rc != EOK)
-		goto out;
-	rc = add_module(NULL, &ip_globals.modules, ARP_NAME, ARP_FILENAME,
-	    SERVICE_ARP, 0, arp_connect_module);
-
-out:
+	ERROR_PROPAGATE(modules_initialize(&ip_globals.modules));
+	ERROR_PROPAGATE(add_module(NULL, &ip_globals.modules, ARP_NAME,
+	    ARP_FILENAME, SERVICE_ARP, 0, arp_connect_module));
 	fibril_rwlock_write_unlock(&ip_globals.lock);
 
-	return rc;
+	return EOK;
 }
 
@@ -310,4 +302,6 @@
 static int ip_netif_initialize(ip_netif_ref ip_netif)
 {
+	ERROR_DECLARE;
+
 	measured_string_t names[] = {
 		{
@@ -348,8 +342,7 @@
 	char *data;
 	measured_string_t address;
+	int index;
 	ip_route_ref route;
 	in_addr_t gateway;
-	int index;
-	int rc;
 
 	ip_netif->arp = NULL;
@@ -361,9 +354,6 @@
 
 	// get configuration
-	rc = net_get_device_conf_req(ip_globals.net_phone, ip_netif->device_id,
-	    &configuration, count, &data);
-	if (rc != EOK)
-		return rc;
-	
+	ERROR_PROPAGATE(net_get_device_conf_req(ip_globals.net_phone,
+	    ip_netif->device_id, &configuration, count, &data));
 	if (configuration) {
 		if (configuration[0].value)
@@ -393,9 +383,10 @@
 				return index;
 			}
-			
-			if ((inet_pton(AF_INET, configuration[2].value,
-			    (uint8_t *) &route->address.s_addr) != EOK) ||
-			    (inet_pton(AF_INET, configuration[3].value,
-			    (uint8_t *) &route->netmask.s_addr) != EOK) ||
+			if (ERROR_OCCURRED(inet_pton(AF_INET,
+			    configuration[2].value,
+			    (uint8_t *) &route->address.s_addr)) ||
+			    ERROR_OCCURRED(inet_pton(AF_INET,
+			    configuration[3].value,
+			    (uint8_t *) &route->netmask.s_addr)) ||
 			    (inet_pton(AF_INET, configuration[4].value,
 			    (uint8_t *) &gateway.s_addr) == EINVAL) ||
@@ -443,10 +434,7 @@
 			address.value = (char *) &route->address.s_addr;
 			address.length = CONVERT_SIZE(in_addr_t, char, 1);
-			
-			rc = arp_device_req(ip_netif->arp->phone,
+			ERROR_PROPAGATE(arp_device_req(ip_netif->arp->phone,
 			    ip_netif->device_id, SERVICE_IP, ip_netif->service,
-			    &address);
-			if (rc != EOK)
-				return rc;
+			    &address));
 		} else {
 			ip_netif->arp = 0;
@@ -455,9 +443,6 @@
 
 	// get packet dimensions
-	rc = nil_packet_size_req(ip_netif->phone, ip_netif->device_id,
-	    &ip_netif->packet_dimension);
-	if (rc != EOK)
-		return rc;
-	
+	ERROR_PROPAGATE(nil_packet_size_req(ip_netif->phone,
+	    ip_netif->device_id, &ip_netif->packet_dimension));
 	if (ip_netif->packet_dimension.content < IP_MIN_CONTENT) {
 		printf("Maximum transmission unit %d bytes is too small, at "
@@ -625,4 +610,6 @@
     measured_string_ref destination)
 {
+	ERROR_DECLARE;
+
 	size_t length;
 	ip_header_ref header;
@@ -630,5 +617,4 @@
 	ip_header_ref middle_header;
 	packet_t next;
-	int rc;
 
 	length = packet_get_data_length(packet);
@@ -638,12 +624,10 @@
 	header = (ip_header_ref) packet_get_data(packet);
 	if (destination) {
-		rc = packet_set_addr(packet, NULL, (uint8_t *) destination->value,
-		    CONVERT_SIZE(char, uint8_t, destination->length));
+		ERROR_PROPAGATE(packet_set_addr(packet, NULL,
+		    (uint8_t *) destination->value,
+		    CONVERT_SIZE(char, uint8_t, destination->length)));
 	} else {
-		rc = packet_set_addr(packet, NULL, NULL, 0);
-	}
-	if (rc != EOK)
-		return rc;
-	
+		ERROR_PROPAGATE(packet_set_addr(packet, NULL, NULL, 0));
+	}
 	header->version = IPV4;
 	header->fragment_offset_high = 0;
@@ -685,11 +669,10 @@
 			    IP_HEADER_CHECKSUM(middle_header);
 			if (destination) {
-				rc = packet_set_addr(next, NULL,
+				if (ERROR_OCCURRED(packet_set_addr(next, NULL,
 				    (uint8_t *) destination->value,
 				    CONVERT_SIZE(char, uint8_t,
-				    destination->length));
-				if (rc != EOK) {
+				    destination->length)))) {
 				    	free(last_header);
-					return rc;
+					return ERROR_CODE;
 				}
 			}
@@ -716,11 +699,11 @@
 		    IP_HEADER_CHECKSUM(middle_header);
 		if (destination) {
-			rc = packet_set_addr(next, NULL,
+			if (ERROR_OCCURRED(packet_set_addr(next, NULL,
 			    (uint8_t *) destination->value,
-			    CONVERT_SIZE(char, uint8_t, destination->length));
-			if (rc != EOK) {
+			    CONVERT_SIZE(char, uint8_t,
+			    destination->length)))) {
 				free(last_header);
-				return rc;
-			}
+				return ERROR_CODE;
+			    }
 		}
 		length += packet_get_data_length(next);
@@ -758,7 +741,8 @@
     const struct sockaddr *src, const struct sockaddr *dest, socklen_t addrlen)
 {
+	ERROR_DECLARE;
+
 	void *data;
 	size_t offset;
-	int rc;
 
 	data = packet_suffix(new_packet, length);
@@ -768,9 +752,5 @@
 	memcpy(data, ((void *) header) + IP_TOTAL_LENGTH(header) - length,
 	    length);
-	
-	rc = packet_trim(packet, 0, length);
-	if (rc != EOK)
-		return rc;
-	
+	ERROR_PROPAGATE(packet_trim(packet, 0, length));
 	header->total_length = htons(IP_TOTAL_LENGTH(header) - length);
 	new_header->total_length = htons(IP_HEADER_LENGTH(new_header) + length);
@@ -781,9 +761,6 @@
 	    IP_COMPUTE_FRAGMENT_OFFSET_LOW(offset);
 	new_header->header_checksum = IP_HEADER_CHECKSUM(new_header);
-	
-	rc = packet_set_addr(new_packet, (const uint8_t *) src,
-	    (const uint8_t *) dest, addrlen);
-	if (rc != EOK)
-		return rc;
+	ERROR_PROPAGATE(packet_set_addr(new_packet, (const uint8_t *) src,
+	    (const uint8_t *) dest, addrlen));
 
 	return pq_insert_after(packet, new_packet);
@@ -819,4 +796,6 @@
     socklen_t addr_len)
 {
+	ERROR_DECLARE;
+
 	packet_t new_packet;
 	ip_header_ref header;
@@ -827,5 +806,4 @@
 	socklen_t addrlen;
 	int result;
-	int rc;
 
 	result = packet_get_addr(packet, (uint8_t **) &src, (uint8_t **) &dest);
@@ -861,20 +839,20 @@
 
 	// trim the unused space
-	rc = packet_trim(new_packet, 0,
-	    IP_HEADER_LENGTH(header) - IP_HEADER_LENGTH(last_header));
-	if (rc != EOK)
-		return ip_release_and_return(packet, rc);
+	if (ERROR_OCCURRED(packet_trim(new_packet, 0,
+	    IP_HEADER_LENGTH(header) - IP_HEADER_LENGTH(last_header)))) {
+		return ip_release_and_return(packet, ERROR_CODE);
+	}
 
 	// biggest multiple of 8 lower than content
 	// TODO even fragmentation?
 	length = length & ~0x7;
-	
-	rc = ip_fragment_packet_data(packet, new_packet, header, last_header,
+	if (ERROR_OCCURRED(ip_fragment_packet_data(packet, new_packet, header,
+	    last_header,
 	    ((IP_HEADER_DATA_LENGTH(header) -
 	    ((length - IP_HEADER_LENGTH(header)) & ~0x7)) %
-	    ((length - IP_HEADER_LENGTH(last_header)) & ~0x7)),
-	    src, dest, addrlen);
-	if (rc != EOK)
-		return ip_release_and_return(packet, rc);
+	    ((length - IP_HEADER_LENGTH(last_header)) & ~0x7)), src, dest,
+	    addrlen))) {
+		return ip_release_and_return(packet, ERROR_CODE);
+	}
 
 	// mark the first as fragmented
@@ -894,10 +872,10 @@
 			return ip_release_and_return(packet, ENOMEM);
 
-		rc = ip_fragment_packet_data(packet, new_packet, header,
-		    middle_header,
-		    (length - IP_HEADER_LENGTH(middle_header)) & ~0x7,
-		    src, dest, addrlen);
-		if (rc != EOK)
-			return ip_release_and_return(packet, rc);
+		if (ERROR_OCCURRED(ip_fragment_packet_data(packet, new_packet,
+		    header, middle_header,
+		    (length - IP_HEADER_LENGTH(middle_header)) & ~0x7, src,
+		    dest, addrlen))) {
+			return ip_release_and_return(packet, ERROR_CODE);
+		}
 	}
 
@@ -996,9 +974,10 @@
     in_addr_t *src, in_addr_t dest, services_t error)
 {
+	ERROR_DECLARE;
+
 	measured_string_t destination;
 	measured_string_ref translation;
 	char *data;
 	int phone;
-	int rc;
 
 	// get destination hardware address
@@ -1008,10 +987,10 @@
 		destination.length = CONVERT_SIZE(dest.s_addr, char, 1);
 
-		rc = arp_translate_req(netif->arp->phone, netif->device_id,
-		    SERVICE_IP, &destination, &translation, &data);
-		if (rc != EOK) {
+		if (ERROR_OCCURRED(arp_translate_req(netif->arp->phone,
+		    netif->device_id, SERVICE_IP, &destination, &translation,
+		    &data))) {
 			pq_release_remote(ip_globals.net_phone,
 			    packet_get_id(packet));
-			return rc;
+			return ERROR_CODE;
 		}
 
@@ -1035,6 +1014,5 @@
 	}
 
-	rc = ip_prepare_packet(src, dest, packet, translation);
-	if (rc != EOK) {
+	if (ERROR_OCCURRED(ip_prepare_packet(src, dest, packet, translation))) {
 		pq_release_remote(ip_globals.net_phone, packet_get_id(packet));
 	} else {
@@ -1054,5 +1032,5 @@
 	}
 
-	return rc;
+	return ERROR_CODE;
 }
 
@@ -1180,8 +1158,9 @@
 ip_device_req_local(int il_phone, device_id_t device_id, services_t netif)
 {
+	ERROR_DECLARE;
+
 	ip_netif_ref ip_netif;
 	ip_route_ref route;
 	int index;
-	int rc;
 
 	ip_netif = (ip_netif_ref) malloc(sizeof(ip_netif_t));
@@ -1189,8 +1168,7 @@
 		return ENOMEM;
 
-	rc = ip_routes_initialize(&ip_netif->routes);
-	if (rc != EOK) {
+	if (ERROR_OCCURRED(ip_routes_initialize(&ip_netif->routes))) {
 		free(ip_netif);
-		return rc;
+		return ERROR_CODE;
 	}
 
@@ -1200,11 +1178,9 @@
 
 	fibril_rwlock_write_lock(&ip_globals.netifs_lock);
-
-	rc = ip_netif_initialize(ip_netif);
-	if (rc != EOK) {
+	if (ERROR_OCCURRED(ip_netif_initialize(ip_netif))) {
 		fibril_rwlock_write_unlock(&ip_globals.netifs_lock);
 		ip_routes_destroy(&ip_netif->routes);
 		free(ip_netif);
-		return rc;
+		return ERROR_CODE;
 	}
 	if (ip_netif->arp)
@@ -1250,4 +1226,6 @@
     services_t sender, services_t error)
 {
+	ERROR_DECLARE;
+
 	int addrlen;
 	ip_netif_ref netif;
@@ -1258,5 +1236,4 @@
 	in_addr_t *src;
 	int phone;
-	int rc;
 
 	// addresses in the host byte order
@@ -1346,8 +1323,8 @@
 	}
 
-	rc = ip_send_route(packet, netif, route, src, *dest, error);
+	ERROR_CODE = ip_send_route(packet, netif, route, src, *dest, error);
 	fibril_rwlock_read_unlock(&ip_globals.netifs_lock);
 
-	return rc;
+	return ERROR_CODE;
 }
 
@@ -1454,4 +1431,6 @@
     services_t error)
 {
+	ERROR_DECLARE;
+
 	ip_proto_ref proto;
 	int phone;
@@ -1463,5 +1442,4 @@
 	struct sockaddr_in dest_in;
 	socklen_t addrlen;
-	int rc;
 
 	if ((header->flags & IPFLAG_MORE_FRAGMENTS) ||
@@ -1489,16 +1467,15 @@
 	}
 
-	rc = packet_set_addr(packet, (uint8_t *) src, (uint8_t *) dest,
-	    addrlen);
-	if (rc != EOK)
-		return ip_release_and_return(packet, rc);
+	if (ERROR_OCCURRED(packet_set_addr(packet, (uint8_t *) src,
+	    (uint8_t *) dest, addrlen))) {
+		return ip_release_and_return(packet, ERROR_CODE);
+	}
 
 	// trim padding if present
 	if (!error &&
 	    (IP_TOTAL_LENGTH(header) < packet_get_data_length(packet))) {
-		rc = packet_trim(packet, 0,
-		    packet_get_data_length(packet) - IP_TOTAL_LENGTH(header));
-		if (rc != EOK)
-			return ip_release_and_return(packet, rc);
+		if (ERROR_OCCURRED(packet_trim(packet, 0,
+		    packet_get_data_length(packet) - IP_TOTAL_LENGTH(header))))
+			return ip_release_and_return(packet, ERROR_CODE);
 	}
 
@@ -1521,12 +1498,12 @@
 		received_msg = proto->received_msg;
 		fibril_rwlock_read_unlock(&ip_globals.protos_lock);
-		rc = received_msg(device_id, packet, service, error);
+		ERROR_CODE = received_msg(device_id, packet, service, error);
 	} else {
-		rc = tl_received_msg(proto->phone, device_id, packet,
+		ERROR_CODE = tl_received_msg(proto->phone, device_id, packet,
 		    proto->service, error);
 		fibril_rwlock_read_unlock(&ip_globals.protos_lock);
 	}
 
-	return rc;
+	return ERROR_CODE;
 }
 
@@ -1555,4 +1532,6 @@
 ip_process_packet(device_id_t device_id, packet_t packet)
 {
+	ERROR_DECLARE;
+
 	ip_header_ref header;
 	in_addr_t dest;
@@ -1562,5 +1541,4 @@
 	struct sockaddr_in addr_in;
 	socklen_t addrlen;
-	int rc;
 
 	header = (ip_header_ref) packet_get_data(packet);
@@ -1607,7 +1585,6 @@
 	}
 
-	rc = packet_set_addr(packet, NULL, (uint8_t *) &addr, addrlen);
-	if (rc != EOK)
-		return rc;
+	ERROR_PROPAGATE(packet_set_addr(packet, NULL, (uint8_t *) &addr,
+	    addrlen));
 
 	route = ip_find_route(dest);
@@ -1890,4 +1867,6 @@
     int *answer_count)
 {
+	ERROR_DECLARE;
+	
 	packet_t packet;
 	struct sockaddr *addr;
@@ -1899,5 +1878,4 @@
 	size_t headerlen;
 	device_id_t device_id;
-	int rc;
 	
 	*answer_count = 0;
@@ -1915,8 +1893,6 @@
 	
 	case NET_IL_SEND:
-		rc = packet_translate_remote(ip_globals.net_phone, &packet,
-		    IPC_GET_PACKET(call));
-		if (rc != EOK)
-			return rc;
+		ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone,
+		    &packet, IPC_GET_PACKET(call)));
 		return ip_send_msg_local(0, IPC_GET_DEVICE(call), packet, 0,
 		    IPC_GET_ERROR(call));
@@ -1927,15 +1903,11 @@
 	
 	case NET_IL_RECEIVED:
-		rc = packet_translate_remote(ip_globals.net_phone, &packet,
-		    IPC_GET_PACKET(call));
-		if (rc != EOK)
-			return rc;
+		ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone,
+		    &packet, IPC_GET_PACKET(call)));
 		return ip_receive_message(IPC_GET_DEVICE(call), packet);
 	
 	case NET_IP_RECEIVED_ERROR:
-		rc = packet_translate_remote(ip_globals.net_phone, &packet,
-		    IPC_GET_PACKET(call));
-		if (rc != EOK)
-			return rc;
+		ERROR_PROPAGATE(packet_translate_remote(ip_globals.net_phone,
+		    &packet, IPC_GET_PACKET(call)));
 		return ip_received_error_msg_local(0, IPC_GET_DEVICE(call),
 		    packet, IPC_GET_TARGET(call), IPC_GET_ERROR(call));
@@ -1951,31 +1923,22 @@
 
 	case NET_IP_GET_ROUTE:
-		rc = data_receive((void **) &addr, &addrlen);
-		if (rc != EOK)
-			return rc;
-		
-		rc = ip_get_route_req_local(0, IP_GET_PROTOCOL(call), addr,
-		    (socklen_t) addrlen, &device_id, &header, &headerlen);
-		if (rc != EOK)
-			return rc;
-		
+		ERROR_PROPAGATE(data_receive((void **) &addr, &addrlen));
+		ERROR_PROPAGATE(ip_get_route_req_local(0, IP_GET_PROTOCOL(call),
+		    addr, (socklen_t) addrlen, &device_id, &header,
+		    &headerlen));
 		IPC_SET_DEVICE(answer, device_id);
 		IP_SET_HEADERLEN(answer, headerlen);
 		
 		*answer_count = 2;
-		
-		rc = data_reply(&headerlen, sizeof(headerlen));
-		if (rc == EOK)
-			rc = data_reply(header, headerlen);
+			
+		if (ERROR_NONE(data_reply(&headerlen, sizeof(headerlen))))
+			ERROR_CODE = data_reply(header, headerlen);
 			
 		free(header);
-		return rc;
+		return ERROR_CODE;
 	
 	case NET_IL_PACKET_SPACE:
-		rc = ip_packet_size_message(IPC_GET_DEVICE(call), &addrlen,
-		    &prefix, &content, &suffix);
-		if (rc != EOK)
-			return rc;
-		
+		ERROR_PROPAGATE(ip_packet_size_message(IPC_GET_DEVICE(call),
+		    &addrlen, &prefix, &content, &suffix));
 		IPC_SET_ADDR(answer, addrlen);
 		IPC_SET_PREFIX(answer, prefix);
@@ -2042,9 +2005,9 @@
 int main(int argc, char *argv[])
 {
-	int rc;
+	ERROR_DECLARE;
 	
 	/* Start the module */
-	rc = il_module_start_standalone(il_client_connection);
-	return rc;
+	ERROR_PROPAGATE(il_module_start_standalone(il_client_connection));
+	return EOK;
 }
 
Index: uspace/srv/net/il/ip/ip_module.c
===================================================================
--- uspace/srv/net/il/ip/ip_module.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/il/ip/ip_module.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -44,5 +44,5 @@
 #include <ipc/ipc.h>
 #include <ipc/services.h>
-#include <errno.h>
+#include <err.h>
 
 #include <net/modules.h>
@@ -66,27 +66,21 @@
 int il_module_start_standalone(async_client_conn_t client_connection)
 {
-	ipcarg_t phonehash;
-	int rc;
+	ERROR_DECLARE;
 	
 	async_set_client_connection(client_connection);
 	ip_globals.net_phone = net_connect_module();
-
-	rc = pm_init();
-	if (rc != EOK)
-		return rc;
+	ERROR_PROPAGATE(pm_init());
 	
-	rc = ip_initialize(client_connection);
-	if (rc != EOK)
-		goto out;
-	
-	rc = REGISTER_ME(SERVICE_IP, &phonehash);
-	if (rc != EOK)
-		goto out;
+	ipcarg_t phonehash;
+	if (ERROR_OCCURRED(ip_initialize(client_connection)) ||
+	    ERROR_OCCURRED(REGISTER_ME(SERVICE_IP, &phonehash))) {
+		pm_destroy();
+		return ERROR_CODE;
+	}
 	
 	async_manager();
-
-out:
+	
 	pm_destroy();
-	return rc;
+	return EOK;
 }
 
Index: uspace/srv/net/netif/lo/lo.c
===================================================================
--- uspace/srv/net/netif/lo/lo.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/netif/lo/lo.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -37,4 +37,5 @@
 #include <async.h>
 #include <errno.h>
+#include <err.h>
 #include <stdio.h>
 #include <str.h>
@@ -82,12 +83,11 @@
 int netif_get_device_stats(device_id_t device_id, device_stats_ref stats)
 {
+	ERROR_DECLARE;
+
 	netif_device_t *device;
-	int rc;
 
 	if (!stats)
 		return EBADMEM;
-	rc = find_device(device_id, &device);
-	if (rc != EOK)
-		return rc;
+	ERROR_PROPAGATE(find_device(device_id, &device));
 	memcpy(stats, (device_stats_ref) device->specific,
 	    sizeof(device_stats_t));
@@ -164,11 +164,10 @@
 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io)
 {
+	ERROR_DECLARE;
+
 	netif_device_t *device;
-	int rc;
 
 	// create a new device
-	rc = create(device_id, &device);
-	if (rc != EOK)
-		return rc;
+	ERROR_PROPAGATE(create(device_id, &device));
 	// print the settings
 	printf("%s: Device created (id: %d)\n", NAME, device->device_id);
@@ -178,13 +177,12 @@
 int netif_send_message(device_id_t device_id, packet_t packet, services_t sender)
 {
+	ERROR_DECLARE;
+
 	netif_device_t *device;
 	size_t length;
 	packet_t next;
 	int phone;
-	int rc;
-
-	rc = find_device(device_id, &device);
-	if (rc != EOK)
-		return EOK;
+
+	ERROR_PROPAGATE(find_device(device_id, &device));
 	if (device->state != NETIF_ACTIVE) {
 		netif_pq_release(packet_get_id(packet));
@@ -261,9 +259,9 @@
 int main(int argc, char *argv[])
 {
-	int rc;
+	ERROR_DECLARE;
 	
 	/* Start the module */
-	rc = netif_module_start(netif_client_connection);
-	return rc;
+	ERROR_PROPAGATE(netif_module_start(netif_client_connection));
+	return EOK;
 }
 
Index: uspace/srv/net/nil/eth/eth.c
===================================================================
--- uspace/srv/net/nil/eth/eth.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/nil/eth/eth.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -42,5 +42,5 @@
 #include <byteorder.h>
 #include <str.h>
-#include <errno.h>
+#include <err.h>
 
 #include <ipc/ipc.h>
@@ -196,5 +196,5 @@
 int nil_initialize(int net_phone)
 {
-	int rc;
+	ERROR_DECLARE;
 
 	fibril_rwlock_initialize(&eth_globals.devices_lock);
@@ -208,14 +208,12 @@
 	    CONVERT_SIZE(uint8_t, char, ETH_ADDR));
 	if (!eth_globals.broadcast_addr) {
-		rc = ENOMEM;
+		ERROR_CODE = ENOMEM;
 		goto out;
 	}
-	rc = eth_devices_initialize(&eth_globals.devices);
-	if (rc != EOK) {
+	if (ERROR_OCCURRED(eth_devices_initialize(&eth_globals.devices))) {
 		free(eth_globals.broadcast_addr);
 		goto out;
 	}
-	rc = eth_protos_initialize(&eth_globals.protos);
-	if (rc != EOK) {
+	if (ERROR_OCCURRED(eth_protos_initialize(&eth_globals.protos))) {
 		free(eth_globals.broadcast_addr);
 		eth_devices_destroy(&eth_globals.devices);
@@ -225,5 +223,5 @@
 	fibril_rwlock_write_unlock(&eth_globals.devices_lock);
 	
-	return rc;
+	return ERROR_CODE;
 }
 
@@ -236,6 +234,7 @@
 static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall)
 {
+	ERROR_DECLARE;
+
 	packet_t packet;
-	int rc;
 
 	while (true) {
@@ -247,11 +246,11 @@
 			break;
 		case NET_NIL_RECEIVED:
-			rc = packet_translate_remote(eth_globals.net_phone,
-			    &packet, IPC_GET_PACKET(icall));
-			if (rc == EOK) {
-				rc = nil_received_msg_local(0,
+			if (ERROR_NONE(packet_translate_remote(
+			    eth_globals.net_phone, &packet,
+			    IPC_GET_PACKET(icall)))) {
+				ERROR_CODE = nil_received_msg_local(0,
 				    IPC_GET_DEVICE(icall), packet, 0);
 			}
-			ipc_answer_0(iid, (ipcarg_t) rc);
+			ipc_answer_0(iid, (ipcarg_t) ERROR_CODE);
 			break;
 		default:
@@ -283,4 +282,6 @@
 eth_device_message(device_id_t device_id, services_t service, size_t mtu)
 {
+	ERROR_DECLARE;
+
 	eth_device_ref device;
 	int index;
@@ -299,5 +300,4 @@
 	char *data;
 	eth_proto_ref proto;
-	int rc;
 
 	fibril_rwlock_write_lock(&eth_globals.devices_lock);
@@ -351,10 +351,9 @@
 
 	configuration = &names[0];
-	rc = net_get_device_conf_req(eth_globals.net_phone, device->device_id,
-	    &configuration, count, &data);
-	if (rc != EOK) {
+	if (ERROR_OCCURRED(net_get_device_conf_req(eth_globals.net_phone,
+	    device->device_id, &configuration, count, &data))) {
 		fibril_rwlock_write_unlock(&eth_globals.devices_lock);
 		free(device);
-		return rc;
+		return ERROR_CODE;
 	}
 	if (configuration) {
@@ -388,10 +387,9 @@
 	
 	// get hardware address
-	rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,
-	    &device->addr_data);
-	if (rc != EOK) {
+	if (ERROR_OCCURRED(netif_get_addr_req(device->phone, device->device_id,
+	    &device->addr, &device->addr_data))) {
 		fibril_rwlock_write_unlock(&eth_globals.devices_lock);
 		free(device);
-		return rc;
+		return ERROR_CODE;
 	}
 	
@@ -431,4 +429,6 @@
 static eth_proto_ref eth_process_packet(int flags, packet_t packet)
 {
+	ERROR_DECLARE;
+
 	eth_header_snap_ref header;
 	size_t length;
@@ -437,6 +437,5 @@
 	size_t suffix;
 	eth_fcs_ref fcs;
-	uint8_t *data;
-	int rc;
+	uint8_t * data;
 
 	length = packet_get_data_length(packet);
@@ -489,17 +488,14 @@
 	
 	if (IS_DUMMY(flags)) {
-		if (~compute_crc32(~0U, data, length * 8) != ntohl(*fcs))
+		if ((~compute_crc32(~0U, data, length * 8)) != ntohl(*fcs))
 			return NULL;
 		suffix += sizeof(eth_fcs_t);
 	}
 	
-	rc = packet_set_addr(packet, header->header.source_address,
-	    header->header.destination_address, ETH_ADDR);
-	if (rc != EOK)
+	if (ERROR_OCCURRED(packet_set_addr(packet,
+	    header->header.source_address, header->header.destination_address,
+	    ETH_ADDR)) || ERROR_OCCURRED(packet_trim(packet, prefix, suffix))) {
 		return NULL;
-
-	rc = packet_trim(packet, prefix, suffix);
-	if (rc != EOK)
-		return NULL;
+	}
 	
 	return eth_protos_find(&eth_globals.protos, type);
@@ -785,9 +781,10 @@
 eth_send_message(device_id_t device_id, packet_t packet, services_t sender)
 {
+	ERROR_DECLARE;
+
 	eth_device_ref device;
 	packet_t next;
 	packet_t tmp;
 	int ethertype;
-	int rc;
 
 	ethertype = htons(protocol_map(SERVICE_ETHERNET, sender));
@@ -807,7 +804,6 @@
 	next = packet;
 	do {
-		rc = eth_prepare_packet(device->flags, next,
-		    (uint8_t *) device->addr->value, ethertype, device->mtu);
-		if (rc != EOK) {
+		if (ERROR_OCCURRED(eth_prepare_packet(device->flags, next,
+		    (uint8_t *) device->addr->value, ethertype, device->mtu))) {
 			// release invalid packet
 			tmp = pq_detach(next);
@@ -836,4 +832,6 @@
     ipc_call_t *answer, int *answer_count)
 {
+	ERROR_DECLARE;
+	
 	measured_string_ref address;
 	packet_t packet;
@@ -842,5 +840,4 @@
 	size_t suffix;
 	size_t content;
-	int rc;
 	
 	*answer_count = 0;
@@ -853,15 +850,11 @@
 		    IPC_GET_SERVICE(call), IPC_GET_MTU(call));
 	case NET_NIL_SEND:
-		rc = packet_translate_remote(eth_globals.net_phone, &packet,
-		    IPC_GET_PACKET(call));
-		if (rc != EOK)
-			return rc;
+		ERROR_PROPAGATE(packet_translate_remote(eth_globals.net_phone,
+		    &packet, IPC_GET_PACKET(call)));
 		return eth_send_message(IPC_GET_DEVICE(call), packet,
 		    IPC_GET_SERVICE(call));
 	case NET_NIL_PACKET_SPACE:
-		rc = eth_packet_space_message(IPC_GET_DEVICE(call), &addrlen,
-		    &prefix, &content, &suffix);
-		if (rc != EOK)
-			return rc;
+		ERROR_PROPAGATE(eth_packet_space_message(IPC_GET_DEVICE(call),
+		    &addrlen, &prefix, &content, &suffix));
 		IPC_SET_ADDR(answer, addrlen);
 		IPC_SET_PREFIX(answer, prefix);
@@ -871,14 +864,10 @@
 		return EOK;
 	case NET_NIL_ADDR:
-		rc = eth_addr_message(IPC_GET_DEVICE(call), ETH_LOCAL_ADDR,
-		    &address);
-		if (rc != EOK)
-			return rc;
+		ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call),
+		    ETH_LOCAL_ADDR, &address));
 		return measured_strings_reply(address, 1);
 	case NET_NIL_BROADCAST_ADDR:
-		rc = eth_addr_message(IPC_GET_DEVICE(call), ETH_BROADCAST_ADDR,
-		    &address);
-		if (rc != EOK)
-			return EOK;
+		ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call),
+		    ETH_BROADCAST_ADDR, &address));
 		return measured_strings_reply(address, 1);
 	case IPC_M_CONNECT_TO_ME:
@@ -934,9 +923,9 @@
 int main(int argc, char *argv[])
 {
-	int rc;
+	ERROR_DECLARE;
 	
 	/* Start the module */
-	rc = nil_module_start_standalone(nil_client_connection);
-	return rc;
+	ERROR_PROPAGATE(nil_module_start_standalone(nil_client_connection));
+	return EOK;
 }
 
Index: uspace/srv/net/nil/eth/eth_module.c
===================================================================
--- uspace/srv/net/nil/eth/eth_module.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/nil/eth/eth_module.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -40,5 +40,5 @@
 #include <async.h>
 #include <stdio.h>
-#include <errno.h>
+#include <err.h>
 
 #include <ipc/ipc.h>
@@ -52,27 +52,21 @@
 int nil_module_start_standalone(async_client_conn_t client_connection)
 {
-	ipcarg_t phonehash;
-	int rc;
+	ERROR_DECLARE;
 	
 	async_set_client_connection(client_connection);
 	int net_phone = net_connect_module();
-
-	rc = pm_init();
-	if (rc != EOK)
-		return rc;
+	ERROR_PROPAGATE(pm_init());
 	
-	rc = nil_initialize(net_phone);
-	if (rc != EOK)
-		goto out;
-
-	rc = REGISTER_ME(SERVICE_ETHERNET, &phonehash);
-	if (rc != EOK)
-		goto out;
+	ipcarg_t phonehash;
+	if (ERROR_OCCURRED(nil_initialize(net_phone)) ||
+	    ERROR_OCCURRED(REGISTER_ME(SERVICE_ETHERNET, &phonehash))) {
+		pm_destroy();
+		return ERROR_CODE;
+	}
 	
 	async_manager();
-
-out:
+	
 	pm_destroy();
-	return rc;
+	return EOK;
 }
 
Index: uspace/srv/net/nil/nildummy/nildummy.c
===================================================================
--- uspace/srv/net/nil/nildummy/nildummy.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/nil/nildummy/nildummy.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -41,4 +41,5 @@
 #include <stdio.h>
 #include <str.h>
+#include <err.h>
 #include <ipc/ipc.h>
 #include <ipc/net.h>
@@ -81,5 +82,5 @@
 int nil_initialize(int net_phone)
 {
-	int rc;
+	ERROR_DECLARE;
 	
 	fibril_rwlock_initialize(&nildummy_globals.devices_lock);
@@ -90,10 +91,10 @@
 	nildummy_globals.net_phone = net_phone;
 	nildummy_globals.proto.phone = 0;
-	rc = nildummy_devices_initialize(&nildummy_globals.devices);
+	ERROR_CODE = nildummy_devices_initialize(&nildummy_globals.devices);
 	
 	fibril_rwlock_write_unlock(&nildummy_globals.protos_lock);
 	fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
 	
-	return rc;
+	return ERROR_CODE;
 }
 
@@ -106,23 +107,24 @@
 static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall)
 {
+	ERROR_DECLARE;
+
 	packet_t packet;
-	int rc;
 
 	while (true) {
 		switch (IPC_GET_METHOD(*icall)) {
 		case NET_NIL_DEVICE_STATE:
-			rc = nil_device_state_msg_local(0,
+			ERROR_CODE = nil_device_state_msg_local(0,
 			    IPC_GET_DEVICE(icall), IPC_GET_STATE(icall));
-			ipc_answer_0(iid, (ipcarg_t) rc);
+			ipc_answer_0(iid, (ipcarg_t) ERROR_CODE);
 			break;
 		
 		case NET_NIL_RECEIVED:
-			rc = packet_translate_remote(nildummy_globals.net_phone,
-			    &packet, IPC_GET_PACKET(icall));
-			if (rc == EOK) {
-				rc = nil_received_msg_local(0,
+			if (ERROR_NONE(packet_translate_remote(
+			    nildummy_globals.net_phone, &packet,
+			    IPC_GET_PACKET(icall)))) {
+				ERROR_CODE = nil_received_msg_local(0,
 				    IPC_GET_DEVICE(icall), packet, 0);
 			}
-			ipc_answer_0(iid, (ipcarg_t) rc);
+			ipc_answer_0(iid, (ipcarg_t) ERROR_CODE);
 			break;
 		
@@ -153,7 +155,8 @@
 nildummy_device_message(device_id_t device_id, services_t service, size_t mtu)
 {
+	ERROR_DECLARE;
+
 	nildummy_device_ref device;
 	int index;
-	int rc;
 
 	fibril_rwlock_write_lock(&nildummy_globals.devices_lock);
@@ -213,10 +216,9 @@
 	
 	// get hardware address
-	rc = netif_get_addr_req(device->phone, device->device_id, &device->addr,
-	    &device->addr_data);
-	if (rc != EOK) {
+	if (ERROR_OCCURRED(netif_get_addr_req(device->phone, device->device_id,
+	    &device->addr, &device->addr_data))) {
 		fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
 		free(device);
-		return rc;
+		return ERROR_CODE;
 	}
 	
@@ -378,4 +380,6 @@
     ipc_call_t *answer, int *answer_count)
 {
+	ERROR_DECLARE;
+	
 	measured_string_ref address;
 	packet_t packet;
@@ -384,5 +388,4 @@
 	size_t suffix;
 	size_t content;
-	int rc;
 	
 	*answer_count = 0;
@@ -396,16 +399,13 @@
 	
 	case NET_NIL_SEND:
-		rc = packet_translate_remote(nildummy_globals.net_phone,
-		    &packet, IPC_GET_PACKET(call));
-		if (rc != EOK)
-			return rc;
+		ERROR_PROPAGATE(packet_translate_remote(
+		    nildummy_globals.net_phone, &packet, IPC_GET_PACKET(call)));
 		return nildummy_send_message(IPC_GET_DEVICE(call), packet,
 		    IPC_GET_SERVICE(call));
 	
 	case NET_NIL_PACKET_SPACE:
-		rc = nildummy_packet_space_message(IPC_GET_DEVICE(call),
-		    &addrlen, &prefix, &content, &suffix);
-		if (rc != EOK)
-			return rc;
+		ERROR_PROPAGATE(nildummy_packet_space_message(
+		    IPC_GET_DEVICE(call), &addrlen, &prefix, &content,
+		    &suffix));
 		IPC_SET_ADDR(answer, addrlen);
 		IPC_SET_PREFIX(answer, prefix);
@@ -416,13 +416,11 @@
 	
 	case NET_NIL_ADDR:
-		rc = nildummy_addr_message(IPC_GET_DEVICE(call), &address);
-		if (rc != EOK)
-			return rc;
+		ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call),
+		    &address));
 		return measured_strings_reply(address, 1);
 	
 	case NET_NIL_BROADCAST_ADDR:
-		rc = nildummy_addr_message(IPC_GET_DEVICE(call), &address);
-		if (rc != EOK)
-			return rc;
+		ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call),
+		    &address));
 		return measured_strings_reply(address, 1);
 	
@@ -478,9 +476,9 @@
 int main(int argc, char *argv[])
 {
-	int rc;
+	ERROR_DECLARE;
 	
 	/* Start the module */
-	rc = nil_module_start_standalone(nil_client_connection);
-	return rc;
+	ERROR_PROPAGATE(nil_module_start_standalone(nil_client_connection));
+	return EOK;
 }
 
Index: uspace/srv/net/nil/nildummy/nildummy.h
===================================================================
--- uspace/srv/net/nil/nildummy/nildummy.h	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/nil/nildummy/nildummy.h	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -62,5 +62,5 @@
  * @see nildummy_proto
  */
-typedef struct nildummy_proto nildummy_proto_t;
+typedef struct nildummy_proto	nildummy_proto_t;
 
 /** Type definition of the dummy nil protocol specific data pointer.
@@ -100,5 +100,5 @@
 
 /** Dummy nil global data. */
-struct nildummy_globals {
+struct	nildummy_globals {
 	/** Networking module phone. */
 	int net_phone;
Index: uspace/srv/net/nil/nildummy/nildummy_module.c
===================================================================
--- uspace/srv/net/nil/nildummy/nildummy_module.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/nil/nildummy/nildummy_module.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -38,5 +38,5 @@
 #include <async.h>
 #include <stdio.h>
-#include <errno.h>
+#include <err.h>
 
 #include <ipc/ipc.h>
@@ -52,28 +52,21 @@
 int nil_module_start_standalone(async_client_conn_t client_connection)
 {
-	ipcarg_t phonehash;
-	int rc;
+	ERROR_DECLARE;
 	
 	async_set_client_connection(client_connection);
 	int net_phone = net_connect_module();
+	ERROR_PROPAGATE(pm_init());
 	
-	rc = pm_init();
-	if (rc != EOK)
-		return rc;
-	
-	
-	rc = nil_initialize(net_phone);
-	if (rc != EOK)
-		goto out;
-	
-	rc = REGISTER_ME(SERVICE_NILDUMMY, &phonehash);
-	if (rc != EOK)
-		goto out;
+	ipcarg_t phonehash;
+	if (ERROR_OCCURRED(nil_initialize(net_phone)) ||
+	    ERROR_OCCURRED(REGISTER_ME(SERVICE_NILDUMMY, &phonehash))) {
+		pm_destroy();
+		return ERROR_CODE;
+	}
 	
 	async_manager();
-
-out:
+	
 	pm_destroy();
-	return rc;
+	return EOK;
 }
 
Index: uspace/srv/net/tl/icmp/icmp.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/tl/icmp/icmp.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -54,4 +54,5 @@
 #include <byteorder.h>
 #include <errno.h>
+#include <err.h>
 
 #include <net/socket_codes.h>
@@ -160,5 +161,5 @@
     int dont_fragment)
 {
-	int rc;
+	ERROR_DECLARE;
 
 	// do not send an error if disabled
@@ -171,9 +172,8 @@
 	header->checksum = ICMP_CHECKSUM(header,
 	    packet_get_data_length(packet));
-	
-	rc = ip_client_prepare_packet(packet, IPPROTO_ICMP, ttl, tos,
-	    dont_fragment, 0);
-	if (rc != EOK)
-		return icmp_release_and_return(packet, rc);
+	if (ERROR_OCCURRED(ip_client_prepare_packet(packet, IPPROTO_ICMP, ttl,
+	    tos, dont_fragment, 0))) {
+		return icmp_release_and_return(packet, ERROR_CODE);
+	}
 
 	return ip_send_msg(icmp_globals.ip_phone, -1, packet, SERVICE_ICMP,
@@ -249,4 +249,6 @@
     const struct sockaddr * addr, socklen_t addrlen)
 {
+	ERROR_DECLARE;
+
 	icmp_header_ref header;
 	packet_t packet;
@@ -255,6 +257,6 @@
 	icmp_reply_ref reply;
 	int reply_key;
+	int result;
 	int index;
-	int rc;
 
 	if (addrlen <= 0)
@@ -263,8 +265,6 @@
 	length = (size_t) addrlen;
 	// TODO do not ask all the time
-	rc = ip_packet_size_req(icmp_globals.ip_phone, -1,
-	    &icmp_globals.packet_dimension);
-	if (rc != EOK)
-		return rc;
+	ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1,
+	    &icmp_globals.packet_dimension));
 
 	packet = packet_get_4_remote(icmp_globals.net_phone, size,
@@ -277,7 +277,8 @@
 	// prepare the requesting packet
 	// set the destination address
-	rc = packet_set_addr(packet, NULL, (const uint8_t *) addr, length);
-	if (rc != EOK)
-		return icmp_release_and_return(packet, rc);
+	if (ERROR_OCCURRED(packet_set_addr(packet, NULL, (const uint8_t *) addr,
+	    length))) {
+		return icmp_release_and_return(packet, ERROR_CODE);
+	}
 
 	// allocate space in the packet
@@ -328,8 +329,11 @@
 	// wait for the reply
 	// timeout in microseconds
-	rc = fibril_condvar_wait_timeout(&reply->condvar, &reply->mutex,
-	    timeout * 1000);
-	if (rc == EOK)
-		rc = reply->result;
+	if (ERROR_OCCURRED(fibril_condvar_wait_timeout(&reply->condvar,
+	    &reply->mutex, timeout * 1000))) {
+		result = ERROR_CODE;
+	} else {
+		// read the result
+		result = reply->result;
+	}
 
 	// drop the reply mutex before locking the globals again
@@ -340,5 +344,5 @@
 	icmp_replies_exclude_index(&icmp_globals.replies, index);
 
-	return rc;
+	return result;
 }
 
@@ -409,4 +413,6 @@
 int icmp_initialize(async_client_conn_t client_connection)
 {
+	ERROR_DECLARE;
+
 	measured_string_t names[] = {
 		{
@@ -422,5 +428,4 @@
 	size_t count = sizeof(names) / sizeof(measured_string_t);
 	char *data;
-	int rc;
 
 	fibril_rwlock_initialize(&icmp_globals.lock);
@@ -428,19 +433,11 @@
 	icmp_replies_initialize(&icmp_globals.replies);
 	icmp_echo_data_initialize(&icmp_globals.echo_data);
-	
 	icmp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_ICMP,
 	    SERVICE_ICMP, client_connection);
-	if (icmp_globals.ip_phone < 0) {
-		fibril_rwlock_write_unlock(&icmp_globals.lock);
+	if (icmp_globals.ip_phone < 0)
 		return icmp_globals.ip_phone;
-	}
-	
-	rc = ip_packet_size_req(icmp_globals.ip_phone, -1,
-	    &icmp_globals.packet_dimension);
-	if (rc != EOK) {
-		fibril_rwlock_write_unlock(&icmp_globals.lock);
-		return rc;
-	}
-
+
+	ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1,
+	    &icmp_globals.packet_dimension));
 	icmp_globals.packet_dimension.prefix += ICMP_HEADER_SIZE;
 	icmp_globals.packet_dimension.content -= ICMP_HEADER_SIZE;
@@ -451,11 +448,6 @@
 	// get configuration
 	configuration = &names[0];
-	rc = net_get_conf_req(icmp_globals.net_phone, &configuration, count,
-	    &data);
-	if (rc != EOK) {
-		fibril_rwlock_write_unlock(&icmp_globals.lock);
-		return rc;
-	}
-	
+	ERROR_PROPAGATE(net_get_conf_req(icmp_globals.net_phone, &configuration,
+	    count, &data));
 	if (configuration) {
 		if (configuration[0].value) {
@@ -527,4 +519,6 @@
 static int icmp_process_packet(packet_t packet, services_t error)
 {
+	ERROR_DECLARE;
+
 	size_t length;
 	uint8_t *src;
@@ -535,5 +529,4 @@
 	icmp_type_t type;
 	icmp_code_t code;
-	int rc;
 
 	switch (error) {
@@ -548,7 +541,5 @@
 		length = (size_t) result;
 		// remove the error header
-		rc = packet_trim(packet, length, 0);
-		if (rc != EOK)
-			return rc;
+		ERROR_PROPAGATE(packet_trim(packet, length, 0));
 		break;
 	default:
@@ -558,7 +549,5 @@
 	// get rid of the ip header
 	length = ip_client_header_length(packet);
-	rc = packet_trim(packet, length, 0);
-	if (rc != EOK)
-		return rc;
+	ERROR_PROPAGATE(packet_trim(packet, length, 0));
 
 	length = packet_get_data_length(packet);
@@ -593,5 +582,5 @@
 	switch (header->type) {
 	case ICMP_ECHOREPLY:
-		if (error)
+		if (error) 
 			icmp_process_echo_reply(packet, header, type, code);
 		else
@@ -665,9 +654,8 @@
     services_t receiver, services_t error)
 {
-	int rc;
-
-	rc = icmp_process_packet(packet, error);
-	if (rc != EOK)
-		return icmp_release_and_return(packet, rc);
+	ERROR_DECLARE;
+
+	if (ERROR_OCCURRED(icmp_process_packet(packet, error)))
+		return icmp_release_and_return(packet, ERROR_CODE);
 
 	return EOK;
@@ -694,35 +682,37 @@
 static int icmp_process_message(ipc_call_t *call)
 {
+	ERROR_DECLARE;
+
 	packet_t packet;
-	int rc;
 
 	switch (IPC_GET_METHOD(*call)) {
 	case NET_ICMP_DEST_UNREACH:
-		rc = packet_translate_remote(icmp_globals.net_phone, &packet,
-		    IPC_GET_PACKET(call));
-		if (rc != EOK)
-			return rc;
-		return icmp_destination_unreachable_msg_local(0,
-		    ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet);
+		if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
+		    &packet, IPC_GET_PACKET(call)))) {
+			ERROR_CODE = icmp_destination_unreachable_msg_local(0,
+			    ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet);
+		}
+		return ERROR_CODE;
 	case NET_ICMP_SOURCE_QUENCH:
-		rc = packet_translate_remote(icmp_globals.net_phone, &packet,
-		    IPC_GET_PACKET(call));
-		if (rc != EOK)
-			return rc;
-		return icmp_source_quench_msg_local(0, packet);
+		if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
+		    &packet, IPC_GET_PACKET(call)))) {
+			ERROR_CODE = icmp_source_quench_msg_local(0, packet);
+		}
+		return ERROR_CODE;
 	case NET_ICMP_TIME_EXCEEDED:
-		rc = packet_translate_remote(icmp_globals.net_phone, &packet,
-		    IPC_GET_PACKET(call));
-		if (rc != EOK)
-			return rc;
-		return icmp_time_exceeded_msg_local(0, ICMP_GET_CODE(call),
-		    packet);
+		if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
+		    &packet, IPC_GET_PACKET(call)))) {
+			ERROR_CODE = icmp_time_exceeded_msg_local(0,
+			    ICMP_GET_CODE(call), packet);
+		}
+		return ERROR_CODE;
 	case NET_ICMP_PARAMETERPROB:
-		rc = packet_translate_remote(icmp_globals.net_phone, &packet,
-		    IPC_GET_PACKET(call));
-		if (rc != EOK)
-			return rc;
-		return icmp_parameter_problem_msg_local(0, ICMP_GET_CODE(call),
-		    ICMP_GET_POINTER(call), packet);
+		if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
+		    &packet, IPC_GET_PACKET(call)))) {
+			ERROR_CODE = icmp_parameter_problem_msg_local(0,
+			    ICMP_GET_CODE(call), ICMP_GET_POINTER(call),
+			    packet);
+		}
+		return ERROR_CODE;
 	default:
 		return ENOTSUP;
@@ -767,5 +757,5 @@
 			break;
 		}
-	} while (icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL);
+	} while(icmp_echo_data_find(&icmp_globals.echo_data, index) != NULL);
 
 	echo_data->identifier = index;
@@ -789,4 +779,6 @@
 static int icmp_process_client_messages(ipc_callid_t callid, ipc_call_t call)
 {
+	ERROR_DECLARE;
+
 	bool keep_on_going = true;
 	ipc_call_t answer;
@@ -796,5 +788,5 @@
 	ipc_callid_t data_callid;
 	icmp_echo_ref echo_data;
-	int rc = EOK;
+	int res;
 
 	/*
@@ -802,4 +794,5 @@
 	 *  - Answer the first NET_ICMP_INIT call.
 	 */
+	res = EOK;
 	answer_count = 0;
 
@@ -810,14 +803,14 @@
 	// assign a new identifier
 	fibril_rwlock_write_lock(&icmp_globals.lock);
-	rc = icmp_bind_free_id(echo_data);
+	res = icmp_bind_free_id(echo_data);
 	fibril_rwlock_write_unlock(&icmp_globals.lock);
-	if (rc < 0) {
+	if (res < 0) {
 		free(echo_data);
-		return rc;
+		return res;
 	}
 
 	while (keep_on_going) {
 		// answer the call
-		answer_call(callid, rc, &answer, answer_count);
+		answer_call(callid, res, &answer, answer_count);
 
 		// refresh data
@@ -831,10 +824,10 @@
 		case IPC_M_PHONE_HUNGUP:
 			keep_on_going = false;
-			rc = EHANGUP;
+			res = EHANGUP;
 			break;
 		
 		case NET_ICMP_ECHO:
 			if (!async_data_write_receive(&data_callid, &length)) {
-				rc = EINVAL;
+				res = EINVAL;
 				break;
 			}
@@ -842,17 +835,17 @@
 			addr = malloc(length);
 			if (!addr) {
-				rc = ENOMEM;
+				res = ENOMEM;
 				break;
 			}
 			
-			rc = async_data_write_finalize(data_callid, addr,
-			    length);
-			if (rc != EOK) {
+			if (ERROR_OCCURRED(async_data_write_finalize(
+			    data_callid, addr, length))) {
 				free(addr);
+				res = ERROR_CODE;
 				break;
 			}
 
 			fibril_rwlock_write_lock(&icmp_globals.lock);
-			rc = icmp_echo(echo_data->identifier,
+			res = icmp_echo(echo_data->identifier,
 			    echo_data->sequence_number, ICMP_GET_SIZE(call),
 			    ICMP_GET_TIMEOUT(call), ICMP_GET_TTL(call),
@@ -871,5 +864,5 @@
 
 		default:
-			rc = icmp_process_message(&call);
+			res = icmp_process_message(&call);
 		}
 
@@ -881,5 +874,5 @@
 	fibril_rwlock_write_unlock(&icmp_globals.lock);
 
-	return rc;
+	return res;
 }
 
@@ -901,16 +894,18 @@
     ipc_call_t *answer, int *answer_count)
 {
+	ERROR_DECLARE;
+
 	packet_t packet;
-	int rc;
 
 	*answer_count = 0;
 	switch (IPC_GET_METHOD(*call)) {
 	case NET_TL_RECEIVED:
-		rc = packet_translate_remote(icmp_globals.net_phone, &packet,
-		    IPC_GET_PACKET(call));
-		if (rc != EOK)
-			return rc;
-		return icmp_received_msg_local(IPC_GET_DEVICE(call), packet,
-		    SERVICE_ICMP, IPC_GET_ERROR(call));
+		if (ERROR_NONE(packet_translate_remote(icmp_globals.net_phone,
+		    &packet, IPC_GET_PACKET(call)))) {
+			ERROR_CODE =
+			    icmp_received_msg_local(IPC_GET_DEVICE(call),
+			    packet, SERVICE_ICMP, IPC_GET_ERROR(call));
+		}
+		return ERROR_CODE;
 	
 	case NET_ICMP_INIT:
@@ -975,9 +970,9 @@
 int main(int argc, char *argv[])
 {
-	int rc;
+	ERROR_DECLARE;
 	
 	/* Start the module */
-	rc = tl_module_start_standalone(tl_client_connection);
-	return rc;
+	ERROR_PROPAGATE(tl_module_start_standalone(tl_client_connection));
+	return EOK;
 }
 
Index: uspace/srv/net/tl/icmp/icmp_module.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp_module.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/tl/icmp/icmp_module.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -43,5 +43,5 @@
 #include <async.h>
 #include <stdio.h>
-#include <errno.h>
+#include <err.h>
 #include <ipc/ipc.h>
 #include <ipc/services.h>
@@ -58,6 +58,7 @@
 int tl_module_start_standalone(async_client_conn_t client_connection)
 {
+	ERROR_DECLARE;
+
 	ipcarg_t phonehash;
-	int rc;
 
 	async_set_client_connection(client_connection);
@@ -66,21 +67,15 @@
 		return icmp_globals.net_phone;
 
-	rc = pm_init();
-	if (rc != EOK)
-		return rc;
-	
-	rc = icmp_initialize(client_connection);
-	if (rc != EOK)
-		goto out;
-
-	rc = REGISTER_ME(SERVICE_ICMP, &phonehash);
-	if (rc != EOK)
-		goto out;
+	ERROR_PROPAGATE(pm_init());
+	if (ERROR_OCCURRED(icmp_initialize(client_connection)) ||
+	    ERROR_OCCURRED(REGISTER_ME(SERVICE_ICMP, &phonehash))) {
+		pm_destroy();
+		return ERROR_CODE;
+	}
 
 	async_manager();
 
-out:
 	pm_destroy();
-	return rc;
+	return EOK;
 }
 
@@ -94,2 +89,3 @@
 /** @}
  */
+
Index: uspace/srv/net/tl/udp/udp.c
===================================================================
--- uspace/srv/net/tl/udp/udp.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/tl/udp/udp.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -51,4 +51,5 @@
 #include <adt/dynamic_fifo.h>
 #include <errno.h>
+#include <err.h>
 
 #include <net/socket_codes.h>
@@ -102,4 +103,6 @@
 int udp_initialize(async_client_conn_t client_connection)
 {
+	ERROR_DECLARE;
+
 	measured_string_t names[] = {
 		{
@@ -115,5 +118,4 @@
 	size_t count = sizeof(names) / sizeof(measured_string_t);
 	char *data;
-	int rc;
 
 	fibril_rwlock_initialize(&udp_globals.lock);
@@ -122,33 +124,18 @@
 	udp_globals.icmp_phone = icmp_connect_module(SERVICE_ICMP,
 	    ICMP_CONNECT_TIMEOUT);
-	
 	udp_globals.ip_phone = ip_bind_service(SERVICE_IP, IPPROTO_UDP,
 	    SERVICE_UDP, client_connection);
-	if (udp_globals.ip_phone < 0) {
-		fibril_rwlock_write_unlock(&udp_globals.lock);
+	if (udp_globals.ip_phone < 0)
 		return udp_globals.ip_phone;
-	}
 
 	// read default packet dimensions
-	rc = ip_packet_size_req(udp_globals.ip_phone, -1,
-	    &udp_globals.packet_dimension);
-	if (rc != EOK) {
-		fibril_rwlock_write_unlock(&udp_globals.lock);
-		return rc;
-	}
-	
-	rc = socket_ports_initialize(&udp_globals.sockets);
-	if (rc != EOK) {
-		fibril_rwlock_write_unlock(&udp_globals.lock);
-		return rc;
-	}
-	
-	rc = packet_dimensions_initialize(&udp_globals.dimensions);
-	if (rc != EOK) {
+	ERROR_PROPAGATE(ip_packet_size_req(udp_globals.ip_phone, -1,
+	    &udp_globals.packet_dimension));
+	ERROR_PROPAGATE(socket_ports_initialize(&udp_globals.sockets));
+	if (ERROR_OCCURRED(packet_dimensions_initialize(
+	    &udp_globals.dimensions))) {
 		socket_ports_destroy(&udp_globals.sockets);
-		fibril_rwlock_write_unlock(&udp_globals.lock);
-		return rc;
-	}
-	
+		return ERROR_CODE;
+	}
 	udp_globals.packet_dimension.prefix += sizeof(udp_header_t);
 	udp_globals.packet_dimension.content -= sizeof(udp_header_t);
@@ -160,12 +147,6 @@
 	// get configuration
 	configuration = &names[0];
-	rc = net_get_conf_req(udp_globals.net_phone, &configuration, count,
-	    &data);
-	if (rc != EOK) {
-		socket_ports_destroy(&udp_globals.sockets);
-		fibril_rwlock_write_unlock(&udp_globals.lock);
-		return rc;
-	}
-	
+	ERROR_PROPAGATE(net_get_conf_req(udp_globals.net_phone, &configuration,
+	    count, &data));
 	if (configuration) {
 		if (configuration[0].value)
@@ -220,4 +201,6 @@
 udp_process_packet(device_id_t device_id, packet_t packet, services_t error)
 {
+	ERROR_DECLARE;
+
 	size_t length;
 	size_t offset;
@@ -236,5 +219,4 @@
 	struct sockaddr *dest;
 	packet_dimension_ref packet_dimension;
-	int rc;
 
 	switch (error) {
@@ -250,7 +232,7 @@
 			return udp_release_and_return(packet, result);
 		length = (size_t) result;
-		rc = packet_trim(packet, length, 0);
-		if (rc != EOK)
-			return udp_release_and_return(packet, rc);
+		if (ERROR_OCCURRED(packet_trim(packet, length, 0)))
+			return udp_release_and_return(packet,
+			    ERROR_CODE);
 		break;
 	default:
@@ -271,7 +253,6 @@
 
 	// trim all but UDP header
-	rc = packet_trim(packet, offset, 0);
-	if (rc != EOK)
-		return udp_release_and_return(packet, rc);
+	if (ERROR_OCCURRED(packet_trim(packet, offset, 0)))
+		return udp_release_and_return(packet, ERROR_CODE);
 
 	// get udp header
@@ -303,9 +284,9 @@
 		if (result <= 0)
 			return udp_release_and_return(packet, result);
-		
-		rc = ip_client_get_pseudo_header(IPPROTO_UDP, src, result, dest,
-		    result, total_length, &ip_header, &length);
-		if (rc != EOK) {
-			return udp_release_and_return(packet, rc);
+
+		if (ERROR_OCCURRED(ip_client_get_pseudo_header(IPPROTO_UDP,
+		    src, result, dest, result, total_length, &ip_header,
+		    &length))) {
+			return udp_release_and_return(packet, ERROR_CODE);
 		} else {
 			checksum = compute_checksum(0, ip_header, length);
@@ -326,7 +307,9 @@
 
 		if (total_length < length) {
-			rc = packet_trim(next_packet, 0, length - total_length);
-			if (rc != EOK)
-				return udp_release_and_return(packet, rc);
+			if (ERROR_OCCURRED(packet_trim(next_packet, 0,
+			    length - total_length))) {
+				return udp_release_and_return(packet,
+				    ERROR_CODE);
+			}
 
 			// add partial checksum if set
@@ -377,13 +360,10 @@
 
 	// queue the received packet
-	rc = dyn_fifo_push(&socket->received, packet_get_id(packet),
-	    SOCKET_MAX_RECEIVED_SIZE);
-	if (rc != EOK)
-		return udp_release_and_return(packet, rc);
-		
-	rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
-	    &udp_globals.dimensions, device_id, &packet_dimension);
-	if (rc != EOK)
-		return udp_release_and_return(packet, rc);
+	if (ERROR_OCCURRED(dyn_fifo_push(&socket->received,
+	    packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE)) ||
+	    ERROR_OCCURRED(tl_get_ip_packet_dimension(udp_globals.ip_phone,
+	    &udp_globals.dimensions, device_id, &packet_dimension))) {
+		return udp_release_and_return(packet, ERROR_CODE);
+	}
 
 	// notify the destination socket
@@ -456,4 +436,6 @@
     size_t *data_fragment_size, int flags)
 {
+	ERROR_DECLARE;
+
 	socket_core_ref socket;
 	packet_t packet;
@@ -469,9 +451,6 @@
 	device_id_t device_id;
 	packet_dimension_ref packet_dimension;
-	int rc;
-	
-	rc = tl_get_address_port(addr, addrlen, &dest_port);
-	if (rc != EOK)
-		return rc;
+
+	ERROR_PROPAGATE(tl_get_address_port(addr, addrlen, &dest_port));
 
 	socket = socket_cores_find(local_sockets, socket_id);
@@ -481,30 +460,44 @@
 	if ((socket->port <= 0) && udp_globals.autobinding) {
 		// bind the socket to a random free port if not bound
-		rc = socket_bind_free_port(&udp_globals.sockets, socket,
-		    UDP_FREE_PORTS_START, UDP_FREE_PORTS_END,
-		    udp_globals.last_used_port);
-		if (rc != EOK)
-			return rc;
-		// set the next port as the search starting port number
-		udp_globals.last_used_port = socket->port;
+//		do {
+			// try to find a free port
+//			fibril_rwlock_read_unlock(&udp_globals.lock);
+//			fibril_rwlock_write_lock(&udp_globals.lock);
+			// might be changed in the meantime
+//			if (socket->port <= 0) {
+				if (ERROR_OCCURRED(socket_bind_free_port(
+				    &udp_globals.sockets, socket,
+				    UDP_FREE_PORTS_START, UDP_FREE_PORTS_END,
+				    udp_globals.last_used_port))) {
+//					fibril_rwlock_write_unlock(
+//					    &udp_globals.lock);
+//					fibril_rwlock_read_lock(
+//					    &udp_globals.lock);
+					return ERROR_CODE;
+				}
+				// set the next port as the search starting port
+				// number
+				udp_globals.last_used_port = socket->port;
+//			}
+//			fibril_rwlock_write_unlock(&udp_globals.lock);
+//			fibril_rwlock_read_lock(&udp_globals.lock);
+			// might be changed in the meantime
+//		} while (socket->port <= 0);
 	}
 
 	if (udp_globals.checksum_computing) {
-		rc = ip_get_route_req(udp_globals.ip_phone, IPPROTO_UDP, addr,
-		    addrlen, &device_id, &ip_header, &headerlen);
-		if (rc != EOK)
-			return rc;
+		if (ERROR_OCCURRED(ip_get_route_req(udp_globals.ip_phone,
+		    IPPROTO_UDP, addr, addrlen, &device_id, &ip_header,
+		    &headerlen))) {
+			return udp_release_and_return(packet, ERROR_CODE);
+		}
 		// get the device packet dimension
-//		rc = tl_get_ip_packet_dimension(udp_globals.ip_phone,
-//		    &udp_globals.dimensions, device_id, &packet_dimension);
-//		if (rc != EOK)
-//			return rc;
+//		ERROR_PROPAGATE(tl_get_ip_packet_dimension(udp_globals.ip_phone,
+//		    &udp_globals.dimensions, device_id, &packet_dimension));
 	}
 //	} else {
 		// do not ask all the time
-		rc = ip_packet_size_req(udp_globals.ip_phone, -1,
-		    &udp_globals.packet_dimension);
-		if (rc != EOK)
-			return rc;
+		ERROR_PROPAGATE(ip_packet_size_req(udp_globals.ip_phone, -1,
+		    &udp_globals.packet_dimension));
 		packet_dimension = &udp_globals.packet_dimension;
 //	}
@@ -536,7 +529,6 @@
 			return udp_release_and_return(packet, result);
 
-		rc = pq_add(&packet, next_packet, index, 0);
-		if (rc != EOK)
-			return udp_release_and_return(packet, rc);
+		if (ERROR_OCCURRED(pq_add(&packet, next_packet, index, 0)))
+			return udp_release_and_return(packet, ERROR_CODE);
 
 		total_length += (size_t) result;
@@ -555,9 +547,8 @@
 	if (udp_globals.checksum_computing) {
 		// update the pseudo header
-		rc = ip_client_set_pseudo_header_data_length(ip_header,
-		    headerlen, total_length + UDP_HEADER_SIZE);
-		if (rc != EOK) {
+		if (ERROR_OCCURRED(ip_client_set_pseudo_header_data_length(
+		    ip_header, headerlen, total_length + UDP_HEADER_SIZE))) {
 			free(ip_header);
-			return udp_release_and_return(packet, rc);
+			return udp_release_and_return(packet, ERROR_CODE);
 		}
 
@@ -574,12 +565,11 @@
 
 	// prepare the first packet fragment
-	rc = ip_client_prepare_packet(packet, IPPROTO_UDP, 0, 0, 0, 0);
-	if (rc != EOK)
-		return udp_release_and_return(packet, rc);
-
-	/* Release the UDP global lock on success. */
+	if (ERROR_OCCURRED(ip_client_prepare_packet(packet, IPPROTO_UDP, 0, 0,
+	    0, 0))) {
+		return udp_release_and_return(packet, ERROR_CODE);
+	}
+
+	// send the packet
 	fibril_rwlock_write_unlock(&udp_globals.lock);
-
-	// send the packet
 	ip_send_msg(udp_globals.ip_phone, device_id, packet, SERVICE_UDP, 0);
 
@@ -610,4 +600,6 @@
     size_t *addrlen)
 {
+	ERROR_DECLARE;
+
 	socket_core_ref socket;
 	int packet_id;
@@ -618,5 +610,4 @@
 	uint8_t *data;
 	int result;
-	int rc;
 
 	// find the socket
@@ -626,42 +617,43 @@
 
 	// get the next received packet
-	packet_id = dyn_fifo_pop(&socket->received);
+	packet_id = dyn_fifo_value(&socket->received);
 	if (packet_id < 0)
 		return NO_DATA;
-	
-	rc = packet_translate_remote(udp_globals.net_phone, &packet, packet_id);
-	if (rc != EOK)
-		return rc;
+
+	ERROR_PROPAGATE(packet_translate_remote(udp_globals.net_phone, &packet,
+	    packet_id));
 
 	// get udp header
 	data = packet_get_data(packet);
-	if (!data)
-		return udp_release_and_return(packet, NO_DATA);
+	if (!data) {
+		pq_release_remote(udp_globals.net_phone, packet_id);
+		return NO_DATA;
+	}
 	header = (udp_header_ref) data;
 
 	// set the source address port
 	result = packet_get_addr(packet, (uint8_t **) &addr, NULL);
-	rc = tl_set_address_port(addr, result, ntohs(header->source_port));
-	if (rc != EOK)
-		return udp_release_and_return(packet, rc);
+	if (ERROR_OCCURRED(tl_set_address_port(addr, result,
+	    ntohs(header->source_port)))) {
+		pq_release_remote(udp_globals.net_phone, packet_id);
+		return ERROR_CODE;
+	}
 	*addrlen = (size_t) result;
 
 	// send the source address
-	rc = data_reply(addr, *addrlen);
-	if (rc != EOK)
-		return udp_release_and_return(packet, rc);
+	ERROR_PROPAGATE(data_reply(addr, *addrlen));
 
 	// trim the header
-	rc = packet_trim(packet, UDP_HEADER_SIZE, 0);
-	if (rc != EOK)
-		return udp_release_and_return(packet, rc);
+	ERROR_PROPAGATE(packet_trim(packet, UDP_HEADER_SIZE, 0));
 
 	// reply the packets
-	rc = socket_reply_packets(packet, &length);
-	if (rc != EOK)
-		return udp_release_and_return(packet, rc);
-
-	// release the packet and return the total length
-	return udp_release_and_return(packet, (int) length);
+	ERROR_PROPAGATE(socket_reply_packets(packet, &length));
+
+	// release the packet
+	dyn_fifo_pop(&socket->received);
+	pq_release_remote(udp_globals.net_phone, packet_get_id(packet));
+
+	// return the total length
+	return (int) length;
 }
 
@@ -834,6 +826,7 @@
     ipc_call_t *answer, int *answer_count)
 {
+	ERROR_DECLARE;
+
 	packet_t packet;
-	int rc;
 
 	*answer_count = 0;
@@ -841,10 +834,11 @@
 	switch (IPC_GET_METHOD(*call)) {
 	case NET_TL_RECEIVED:
-		rc = packet_translate_remote(udp_globals.net_phone, &packet,
-		    IPC_GET_PACKET(call));
-		if (rc != EOK)
-			return rc;
-		return udp_received_msg(IPC_GET_DEVICE(call), packet,
-		    SERVICE_UDP, IPC_GET_ERROR(call));
+		if (ERROR_NONE(packet_translate_remote(udp_globals.net_phone,
+		    &packet, IPC_GET_PACKET(call)))) {
+			ERROR_CODE = udp_received_msg(IPC_GET_DEVICE(call),
+			    packet, SERVICE_UDP, IPC_GET_ERROR(call));
+		}
+		return ERROR_CODE;
+	
 	case IPC_M_CONNECT_TO_ME:
 		return udp_process_client_messages(callid, * call);
@@ -856,6 +850,7 @@
 /** Default thread for new connections.
  *
- * @param[in] iid	The initial message identifier.
- * @param[in] icall	The initial message call structure.
+ *  @param[in] iid	The initial message identifier.
+ *  @param[in] icall	The initial message call structure.
+ *
  */
 static void tl_client_connection(ipc_callid_t iid, ipc_call_t * icall)
@@ -903,9 +898,11 @@
 int main(int argc, char *argv[])
 {
-	int rc;
+	ERROR_DECLARE;
 	
 	/* Start the module */
-	rc = tl_module_start_standalone(tl_client_connection);
-	return rc;
+	if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection)))
+		return ERROR_CODE;
+	
+	return EOK;
 }
 
Index: uspace/srv/net/tl/udp/udp_module.c
===================================================================
--- uspace/srv/net/tl/udp/udp_module.c	(revision 60898b690649d9e809606e6d12c17b2fb77db316)
+++ uspace/srv/net/tl/udp/udp_module.c	(revision a66e299372bdb43d55e8f9e08081d47accc2dbdf)
@@ -44,5 +44,5 @@
 #include <async.h>
 #include <stdio.h>
-#include <errno.h>
+#include <err.h>
 #include <ipc/ipc.h>
 #include <ipc/services.h>
@@ -59,6 +59,7 @@
 int tl_module_start_standalone(async_client_conn_t client_connection)
 {
+	ERROR_DECLARE;
+
 	ipcarg_t phonehash;
-	int rc;
 
 	async_set_client_connection(client_connection);
@@ -66,22 +67,16 @@
 	if (udp_globals.net_phone < 0)
 		return udp_globals.net_phone;
-	
-	rc = pm_init();
-	if (rc != EOK)
-		return EOK;
-		
-	rc = udp_initialize(client_connection);
-	if (rc != EOK)
-		goto out;
-	
-	rc = REGISTER_ME(SERVICE_UDP, &phonehash);
-	if (rc != EOK)
-		goto out;
+
+	ERROR_PROPAGATE(pm_init());
+	if (ERROR_OCCURRED(udp_initialize(client_connection)) ||
+	    ERROR_OCCURRED(REGISTER_ME(SERVICE_UDP, &phonehash))) {
+		pm_destroy();
+		return ERROR_CODE;
+	}
 
 	async_manager();
 
-out:
 	pm_destroy();
-	return rc;
+	return EOK;
 }
 
