Index: HelenOS.config
===================================================================
--- HelenOS.config	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ HelenOS.config	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -345,5 +345,5 @@
 
 % Simics SMP Hack
-! [PROCESSOR=sun4v] CONFIG_SIMICS_SMP_HACK (y/n)
+! [PROCESSOR=sun4v&CONFIG_SMP=y] CONFIG_SIMICS_SMP_HACK (n/y)
 
 % Support for userspace debuggers
@@ -522,11 +522,4 @@
 ! CONFIG_WRITE_CORE_FILES (n/y)
 
-% Networking architecture
-@ "none" No networking
-@ "modular" Modular
-@ "module" One module
-! CONFIG_NETWORKING (choice)
-
-% DP8390 (NE2k) network interface
-! [CONFIG_NETWORKING=modular|CONFIG_NETWORKING=module] CONFIG_NETIF_DP8390 (y/n)
-
+% Bundle netif/nil network layer
+! CONFIG_NETIF_NIL_BUNDLE (n/y)
Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ boot/Makefile.common	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -40,7 +40,9 @@
 	$(USPACEDIR)/srv/bd/rd/rd \
 	$(USPACEDIR)/srv/vfs/vfs
+
 ifeq ($(RDFMT),tmpfs)
 	INIT_TASKS += $(USPACEDIR)/srv/fs/tmpfs/tmpfs
 endif
+
 ifeq ($(RDFMT),fat)
 	INIT_TASKS += $(USPACEDIR)/srv/fs/fat/fat
@@ -58,5 +60,20 @@
 	$(USPACEDIR)/srv/fs/tmpfs/tmpfs \
 	$(USPACEDIR)/srv/fs/fat/fat \
-	$(USPACEDIR)/srv/taskmon/taskmon
+	$(USPACEDIR)/srv/taskmon/taskmon \
+	$(USPACEDIR)/srv/hw/netif/dp8390/dp8390 \
+	$(USPACEDIR)/srv/net/netif/lo/lo \
+	$(USPACEDIR)/srv/net/il/arp/arp \
+	$(USPACEDIR)/srv/net/il/ip/ip \
+	$(USPACEDIR)/srv/net/tl/icmp/icmp \
+	$(USPACEDIR)/srv/net/tl/udp/udp \
+	$(USPACEDIR)/srv/net/tl/tcp/tcp \
+	$(USPACEDIR)/srv/net/net/net \
+	$(USPACEDIR)/srv/net/netstart/netstart \
+
+ifneq ($(CONFIG_NETIF_NIL_BUNDLE),y)
+	RD_SRVS += \
+		$(USPACEDIR)/srv/net/nil/eth/eth \
+		$(USPACEDIR)/srv/net/nil/nildummy/nildummy
+endif
 
 RD_APPS = \
@@ -66,4 +83,5 @@
 	$(USPACEDIR)/app/klog/klog \
 	$(USPACEDIR)/app/mkfat/mkfat \
+	$(USPACEDIR)/app/sbi/sbi \
 	$(USPACEDIR)/app/redir/redir \
 	$(USPACEDIR)/app/taskdump/taskdump \
@@ -71,4 +89,8 @@
 	$(USPACEDIR)/app/tetris/tetris \
 	$(USPACEDIR)/app/trace/trace \
+	$(USPACEDIR)/app/nettest1/nettest1 \
+	$(USPACEDIR)/app/nettest2/nettest2 \
+	$(USPACEDIR)/app/netecho/netecho \
+	$(USPACEDIR)/app/ping/ping \
 	$(USPACEDIR)/app/ps/ps \
 	$(USPACEDIR)/app/top/top \
@@ -84,52 +106,15 @@
 	$(USPACEDIR)/srv/bd/rd/rd \
 	$(USPACEDIR)/srv/vfs/vfs
+
 ifeq ($(RDFMT),tmpfs)
 	COMPONENTS += $(USPACEDIR)/srv/fs/tmpfs/tmpfs
 endif
+
 ifeq ($(RDFMT),fat)
 	COMPONENTS += $(USPACEDIR)/srv/fs/fat/fat
 endif
 
-CFG =
-
-NET_SRVS = \
-	$(USPACEDIR)/srv/net/net/net \
-	$(USPACEDIR)/srv/net/netif/lo/lo \
-	$(USPACEDIR)/srv/net/nil/eth/eth \
-	$(USPACEDIR)/srv/net/nil/nildummy/nildummy \
-	$(USPACEDIR)/srv/net/app/echo/echo
-
-NET_APPS = \
-	$(USPACEDIR)/srv/net/net/start/netstart \
-	$(USPACEDIR)/srv/net/app/ping/ping \
-	$(USPACEDIR)/srv/net/app/nettest1/nettest1 \
-	$(USPACEDIR)/srv/net/app/nettest2/nettest2
-
-ifneq ($(CONFIG_NETWORKING),none)
-	NET_CFG = \
-		$(USPACEDIR)/srv/net/cfg/$(CONFIG_NETWORKING)/general \
-		$(USPACEDIR)/srv/net/cfg/$(CONFIG_NETWORKING)/lo
-	
-	ifeq ($(CONFIG_NETIF_DP8390),y)
-		NET_SRVS += $(USPACEDIR)/srv/net/netif/dp8390/dp8390
-		NET_CFG += $(USPACEDIR)/srv/net/cfg/$(CONFIG_NETWORKING)/ne2k
-	endif
-	
-	ifeq ($(CONFIG_NETWORKING),module)
-		RD_APPS += $(NET_APPS)
-		RD_SRVS += $(NET_SRVS)
-		CFG += $(NET_CFG)
-	endif
-	
-	ifeq ($(CONFIG_NETWORKING),modular)
-		RD_APPS += $(NET_APPS)
-		RD_SRVS += $(NET_SRVS)
-		RD_SRVS += \
-			$(USPACEDIR)/srv/net/il/ip/ip \
-			$(USPACEDIR)/srv/net/il/arp/arp \
-			$(USPACEDIR)/srv/net/tl/udp/udp \
-			$(USPACEDIR)/srv/net/tl/tcp/tcp \
-			$(USPACEDIR)/srv/net/tl/icmp/icmp
-		CFG += $(NET_CFG)
-	endif
-endif
+NET_CFG = \
+	$(USPACEDIR)/srv/net/cfg/general \
+	$(USPACEDIR)/srv/net/cfg/lo \
+	$(USPACEDIR)/srv/net/cfg/ne2k
Index: boot/arch/amd64/Makefile.inc
===================================================================
--- boot/arch/amd64/Makefile.inc	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ boot/arch/amd64/Makefile.inc	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -39,5 +39,5 @@
 build: $(BASE)/image.iso
 
-$(BASE)/image.iso: arch/$(BARCH)/grub/stage2_eltorito $(KERNELDIR)/kernel.bin $(INIT_TASKS) $(RD_SRVS) $(RD_APPS) $(CFG)
+$(BASE)/image.iso: arch/$(BARCH)/grub/stage2_eltorito $(COMPONENTS) $(INIT_TASKS) $(RD_SRVS) $(RD_APPS) $(CFG)
 	mkdir -p $(TMP)/boot/grub
 	cp arch/$(BARCH)/grub/stage2_eltorito $(TMP)/boot/grub/
Index: boot/arch/arm32/Makefile.inc
===================================================================
--- boot/arch/arm32/Makefile.inc	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ boot/arch/arm32/Makefile.inc	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -27,7 +27,9 @@
 #
 
+include Makefile.common
+
 build: $(BASE)/image.boot
 
-$(BASE)/image.boot:
+$(BASE)/image.boot: $(COMPONENTS) $(INIT_TASKS) $(RD_SRVS) $(RD_APPS) $(CFG)
 	$(MAKE) -C arch/$(BARCH)/loader PRECHECK=$(PRECHECK)
 	cp arch/$(BARCH)/loader/image.boot $@
Index: boot/arch/arm32/loader/main.c
===================================================================
--- boot/arch/arm32/loader/main.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ boot/arch/arm32/loader/main.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -48,5 +48,5 @@
 
 /** Kernel entry point address. */
-#define KERNEL_VIRTUAL_ADDRESS 0x80200000
+#define KERNEL_VIRTUAL_ADDRESS 0x80800000
 
 
Index: boot/arch/ia64/Makefile.inc
===================================================================
--- boot/arch/ia64/Makefile.inc	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ boot/arch/ia64/Makefile.inc	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -27,7 +27,9 @@
 #
 
+include Makefile.common
+
 build: $(BASE)/image.boot
 
-$(BASE)/image.boot:
+$(BASE)/image.boot: $(COMPONENTS) $(INIT_TASKS) $(RD_SRVS) $(RD_APPS) $(CFG)
 	$(MAKE) -C arch/$(BARCH)/loader PRECHECK=$(PRECHECK)
 	cp arch/$(BARCH)/loader/image.boot $@
Index: boot/arch/mips32/Makefile.inc
===================================================================
--- boot/arch/mips32/Makefile.inc	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ boot/arch/mips32/Makefile.inc	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -27,7 +27,9 @@
 #
 
+include Makefile.common
+
 build: $(BASE)/image.boot
 
-$(BASE)/image.boot:
+$(BASE)/image.boot: $(COMPONENTS) $(INIT_TASKS) $(RD_SRVS) $(RD_APPS) $(CFG)
 	$(MAKE) -C arch/$(BARCH)/loader PRECHECK=$(PRECHECK)
 	cp arch/$(BARCH)/loader/image.boot $@
Index: boot/arch/ppc32/Makefile.inc
===================================================================
--- boot/arch/ppc32/Makefile.inc	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ boot/arch/ppc32/Makefile.inc	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -41,5 +41,5 @@
 	mkisofs -hfs -part -map arch/$(BARCH)/yaboot/maps -no-desktop -hfs-volid "HelenOS" -hfs-bless $(TMP)/boot -r -o $@ $(TMP)/
 
-arch/$(BARCH)/loader/image.boot:
+arch/$(BARCH)/loader/image.boot: $(COMPONENTS) $(INIT_TASKS) $(RD_SRVS) $(RD_APPS) $(CFG)
 	$(MAKE) -C arch/$(BARCH)/loader PRECHECK=$(PRECHECK)
 
Index: boot/arch/ppc32/loader/asm.h
===================================================================
--- boot/arch/ppc32/loader/asm.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ boot/arch/ppc32/loader/asm.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -33,5 +33,5 @@
 #define PAGE_SIZE   (1 << PAGE_WIDTH)
 
-#define TRANS_SIZE   1024
+#define TRANS_SIZE   2048
 #define BOOT_OFFSET  0x8000
 
Index: boot/arch/sparc64/Makefile.inc
===================================================================
--- boot/arch/sparc64/Makefile.inc	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ boot/arch/sparc64/Makefile.inc	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -54,5 +54,5 @@
 	mkisofs -f -G $(TMP)/boot/isofs.b -B ... -r -o $@ $(TMP)/
 
-arch/$(BARCH)/loader/image.boot:
+arch/$(BARCH)/loader/image.boot: $(COMPONENTS) $(INIT_TASKS) $(RD_SRVS) $(RD_APPS) $(CFG)
 	$(MAKE) -C arch/$(BARCH)/loader PRECHECK=$(PRECHECK)
 
Index: defaults/amd64/Makefile.config
===================================================================
--- defaults/amd64/Makefile.config	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ defaults/amd64/Makefile.config	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -62,4 +62,4 @@
 CONFIG_MOUNT_DATA = n
 
-# Default networking architecture
-CONFIG_NETWORKING = modular
+# Bundle netif/nil network layer
+CONFIG_NETIF_NIL_BUNDLE = n
Index: defaults/arm32/Makefile.config
===================================================================
--- defaults/arm32/Makefile.config	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ defaults/arm32/Makefile.config	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -38,4 +38,4 @@
 CONFIG_MOUNT_DATA = n
 
-# Default networking architecture
-CONFIG_NETWORKING = none
+# Bundle netif/nil network layer
+CONFIG_NETIF_NIL_BUNDLE = n
Index: defaults/ia32/Makefile.config
===================================================================
--- defaults/ia32/Makefile.config	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ defaults/ia32/Makefile.config	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -68,4 +68,4 @@
 CONFIG_MOUNT_DATA = n
 
-# Default networking architecture
-CONFIG_NETWORKING = modular
+# Bundle netif/nil network layer
+CONFIG_NETIF_NIL_BUNDLE = n
Index: defaults/ia64/Makefile.config
===================================================================
--- defaults/ia64/Makefile.config	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ defaults/ia64/Makefile.config	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -50,4 +50,4 @@
 CONFIG_MOUNT_DATA = n
 
-# Default networking architecture
-CONFIG_NETWORKING = modular
+# Bundle netif/nil network layer
+CONFIG_NETIF_NIL_BUNDLE = n
Index: defaults/mips32/Makefile.config
===================================================================
--- defaults/mips32/Makefile.config	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ defaults/mips32/Makefile.config	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -44,4 +44,4 @@
 CONFIG_MOUNT_DATA = n
 
-# Default networking architecture
-CONFIG_NETWORKING = none
+# Bundle netif/nil network layer
+CONFIG_NETIF_NIL_BUNDLE = n
Index: defaults/ppc32/Makefile.config
===================================================================
--- defaults/ppc32/Makefile.config	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ defaults/ppc32/Makefile.config	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -44,4 +44,4 @@
 CONFIG_MOUNT_DATA = n
 
-# Default networking architecture
-CONFIG_NETWORKING = none
+# Bundle netif/nil network layer
+CONFIG_NETIF_NIL_BUNDLE = n
Index: defaults/sparc64/Makefile.config
===================================================================
--- defaults/sparc64/Makefile.config	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ defaults/sparc64/Makefile.config	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -62,4 +62,4 @@
 CONFIG_MOUNT_DATA = n
 
-# Default networking architecture
-CONFIG_NETWORKING = modular
+# Bundle netif/nil network layer
+CONFIG_NETIF_NIL_BUNDLE = n
Index: defaults/sparc64/sun4v/Makefile.config
===================================================================
--- defaults/sparc64/sun4v/Makefile.config	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ defaults/sparc64/sun4v/Makefile.config	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -12,4 +12,2 @@
 
 CONFIG_FB = n
-
-CONFIG_NETWORKING = none
Index: defaults/special/Makefile.config
===================================================================
--- defaults/special/Makefile.config	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ defaults/special/Makefile.config	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,2 +28,5 @@
 # Load disk drivers on startup
 CONFIG_START_BD = n
+
+# Bundle netif/nil network layer
+CONFIG_NETIF_NIL_BUNDLE = n
Index: defaults/special/abs32le/Makefile.config
===================================================================
--- defaults/special/abs32le/Makefile.config	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ defaults/special/abs32le/Makefile.config	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -4,5 +4,2 @@
 # Cross-compiler target
 CROSS_TARGET = ia32
-
-# Networking architecture
-CONFIG_NETWORKING = none
Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -283,6 +283,5 @@
 		test/print/print3.c \
 		test/print/print4.c \
-		test/thread/thread1.c \
-		test/sysinfo/sysinfo1.c
+		test/thread/thread1.c
 	
 	ifeq ($(KARCH),mips32)
Index: kernel/arch/amd64/src/amd64.c
===================================================================
--- kernel/arch/amd64/src/amd64.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/arch/amd64/src/amd64.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -228,9 +228,10 @@
 	    (uintptr_t) I8042_BASE);
 #endif
-
-#ifdef CONFIG_NETIF_DP8390
+	
+	/*
+	 * This nasty hack should also go away ASAP.
+	 */
 	trap_virtual_enable_irqs(1 << IRQ_DP8390);
 	sysinfo_set_item_val("netif.dp8390.inr", NULL, IRQ_DP8390);
-#endif
 }
 
Index: kernel/arch/arm32/_link.ld.in
===================================================================
--- kernel/arch/arm32/_link.ld.in	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/arch/arm32/_link.ld.in	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -7,5 +7,5 @@
  */
 
-#define KERNEL_LOAD_ADDRESS 0x80200000
+#define KERNEL_LOAD_ADDRESS 0x80800000
 
 OUTPUT_ARCH(arm)
Index: kernel/arch/ia32/src/ia32.c
===================================================================
--- kernel/arch/ia32/src/ia32.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/arch/ia32/src/ia32.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -186,9 +186,10 @@
 	    (uintptr_t) I8042_BASE);
 #endif
-
-#ifdef CONFIG_NETIF_DP8390
+	
+	/*
+	 * This nasty hack should also go away ASAP.
+	 */
 	trap_virtual_enable_irqs(1 << IRQ_DP8390);
 	sysinfo_set_item_val("netif.dp8390.inr", NULL, IRQ_DP8390);
-#endif
 }
 
Index: kernel/arch/ia64/src/ia64.c
===================================================================
--- kernel/arch/ia64/src/ia64.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/arch/ia64/src/ia64.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -213,7 +213,5 @@
 #endif
 
-#ifdef CONFIG_NETIF_DP8390
 	sysinfo_set_item_val("netif.dp8390.inr", NULL, IRQ_DP8390);
-#endif
 
 	sysinfo_set_item_val("ia64_iospace", NULL, true);
Index: kernel/arch/sparc64/src/smp/sun4v/smp.c
===================================================================
--- kernel/arch/sparc64/src/smp/sun4v/smp.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/arch/sparc64/src/smp/sun4v/smp.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -54,4 +54,5 @@
 #include <arch/smp/sun4v/smp.h>
 #include <str.h>
+#include <errno.h>
 
 /** hypervisor code of the "running" state of the CPU */
Index: kernel/generic/include/ipc/sysipc.h
===================================================================
--- kernel/generic/include/ipc/sysipc.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/generic/include/ipc/sysipc.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -57,5 +57,5 @@
 unative_t sys_ipc_forward_slow(unative_t callid, unative_t phoneid,
     ipc_data_t *data, int mode);
-unative_t sys_ipc_hangup(int phoneid);
+unative_t sys_ipc_hangup(unative_t phoneid);
 unative_t sys_ipc_register_irq(inr_t inr, devno_t devno, unative_t method,
     irq_code_t *ucode);
Index: kernel/generic/include/str.h
===================================================================
--- kernel/generic/include/str.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/generic/include/str.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -89,4 +89,7 @@
 extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
 
+extern char *str_dup(const char *src);
+extern char *str_ndup(const char *src, size_t n);
+
 extern char *str_chr(const char *str, wchar_t ch);
 
Index: kernel/generic/include/syscall/syscall.h
===================================================================
--- kernel/generic/include/syscall/syscall.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/generic/include/syscall/syscall.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -82,6 +82,8 @@
 	SYS_PREEMPT_CONTROL,
 	
-	SYS_SYSINFO_VALID,
-	SYS_SYSINFO_VALUE,
+	SYS_SYSINFO_GET_TAG,
+	SYS_SYSINFO_GET_VALUE,
+	SYS_SYSINFO_GET_DATA_SIZE,
+	SYS_SYSINFO_GET_DATA,
 	
 	SYS_DEBUG_ENABLE_CONSOLE,
Index: kernel/generic/include/sysinfo/sysinfo.h
===================================================================
--- kernel/generic/include/sysinfo/sysinfo.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/generic/include/sysinfo/sysinfo.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -41,51 +41,79 @@
 extern bool fb_exported;
 
-typedef union sysinfo_item_val {
+typedef enum {
+	SYSINFO_VAL_UNDEFINED = 0,
+	SYSINFO_VAL_VAL = 1,
+	SYSINFO_VAL_DATA = 2,
+	SYSINFO_VAL_FUNCTION_VAL = 3,
+	SYSINFO_VAL_FUNCTION_DATA = 4
+} sysinfo_item_val_type_t;
+
+typedef enum {
+	SYSINFO_SUBTREE_NONE = 0,
+	SYSINFO_SUBTREE_TABLE = 1,
+	SYSINFO_SUBTREE_FUNCTION = 2
+} sysinfo_subtree_type_t;
+
+struct sysinfo_item;
+
+typedef unative_t (*sysinfo_fn_val_t)(struct sysinfo_item *);
+typedef void *(*sysinfo_fn_data_t)(struct sysinfo_item *, size_t *);
+typedef struct sysinfo_item *(*sysinfo_fn_subtree_t)(const char *);
+
+typedef struct {
+	void *data;
+	size_t size;
+} sysinfo_data_t;
+
+typedef union {
 	unative_t val;
-	void *fn; 
+	sysinfo_fn_val_t fn_val;
+	sysinfo_fn_data_t fn_data;
+	sysinfo_data_t data;
 } sysinfo_item_val_t;
+
+typedef union {
+	struct sysinfo_item *table;
+	sysinfo_fn_subtree_t find_item;
+} sysinfo_subtree_t;
 
 typedef struct sysinfo_item {
 	char *name;
+	
+	sysinfo_item_val_type_t val_type;
+	sysinfo_item_val_t val;
+	
+	sysinfo_subtree_type_t subtree_type;
+	sysinfo_subtree_t subtree;
+	
+	struct sysinfo_item *next;
+} sysinfo_item_t;
+
+typedef struct {
+	sysinfo_item_val_type_t tag;
 	union {
 		unative_t val;
-		void *fn; 
-	} val;
+		sysinfo_data_t data;
+	};
+} sysinfo_return_t;
 
-	union {
-		struct sysinfo_item *table;
-		void *fn;
-	} subinfo;
+extern void sysinfo_init(void);
 
-	struct sysinfo_item *next;
-	int val_type;
-	int subinfo_type;
-} sysinfo_item_t;
+extern void sysinfo_set_item_val(const char *, sysinfo_item_t **, unative_t);
+extern void sysinfo_set_item_data(const char *, sysinfo_item_t **, void *,
+    size_t);
+extern void sysinfo_set_item_val_fn(const char *, sysinfo_item_t **,
+    sysinfo_fn_val_t);
+extern void sysinfo_set_item_data_fn(const char *, sysinfo_item_t **,
+    sysinfo_fn_data_t);
+extern void sysinfo_set_item_undefined(const char *, sysinfo_item_t **);
 
-#define SYSINFO_VAL_VAL        0
-#define SYSINFO_VAL_FUNCTION   1
-#define SYSINFO_VAL_UNDEFINED  U_SPECIAL
+extern sysinfo_return_t sysinfo_get_item(const char *, sysinfo_item_t **);
+extern void sysinfo_dump(sysinfo_item_t **, unsigned int);
 
-#define SYSINFO_SUBINFO_NONE      0
-#define SYSINFO_SUBINFO_TABLE     1
-#define SYSINFO_SUBINFO_FUNCTION  2
-
-typedef unative_t (*sysinfo_val_fn_t)(sysinfo_item_t *root);
-typedef unative_t (*sysinfo_subinfo_fn_t)(const char *subname);
-
-typedef struct sysinfo_rettype {
-	unative_t val;
-	unative_t valid;
-} sysinfo_rettype_t;
-
-void sysinfo_set_item_val(const char *name, sysinfo_item_t **root, unative_t val);
-void sysinfo_dump(sysinfo_item_t **root, int depth);
-void sysinfo_set_item_function(const char *name, sysinfo_item_t **root, sysinfo_val_fn_t fn);
-void sysinfo_set_item_undefined(const char *name, sysinfo_item_t **root);
-
-sysinfo_rettype_t sysinfo_get_val(const char *name, sysinfo_item_t **root);
-
-unative_t sys_sysinfo_valid(unative_t ptr, unative_t len);
-unative_t sys_sysinfo_value(unative_t ptr, unative_t len);
+unative_t sys_sysinfo_get_tag(void *, size_t);
+unative_t sys_sysinfo_get_value(void *, size_t, void *);
+unative_t sys_sysinfo_get_data_size(void *, size_t, void *);
+unative_t sys_sysinfo_get_data(void *, size_t, void *, size_t);
 
 #endif
Index: kernel/generic/src/console/cmd.c
===================================================================
--- kernel/generic/src/console/cmd.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/generic/src/console/cmd.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -66,4 +66,5 @@
 #include <ipc/irq.h>
 #include <ipc/event.h>
+#include <sysinfo/sysinfo.h>
 #include <symtab.h>
 #include <errno.h>
@@ -387,4 +388,12 @@
 };
 
+static int cmd_sysinfo(cmd_arg_t *argv);
+static cmd_info_t sysinfo_info = {
+	.name = "sysinfo",
+	.description = "Dump sysinfo.",
+	.func = cmd_sysinfo,
+	.argc = 0
+};
+
 /* Data and methods for 'zones' command */
 static int cmd_zones(cmd_arg_t *argv);
@@ -475,4 +484,5 @@
 	&set4_info,
 	&slabs_info,
+	&sysinfo_info,
 	&symaddr_info,
 	&sched_info,
@@ -868,4 +878,16 @@
 }
 
+/** Command for dumping sysinfo
+ *
+ * @param argv Ignores
+ *
+ * @return Always 1
+ */
+int cmd_sysinfo(cmd_arg_t * argv)
+{
+	sysinfo_dump(NULL, 0);
+	return 1;
+}
+
 
 /** Command for listings Thread information
Index: kernel/generic/src/ipc/sysipc.c
===================================================================
--- kernel/generic/src/ipc/sysipc.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/generic/src/ipc/sysipc.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -58,10 +58,17 @@
 #define DATA_XFER_LIMIT		(64 * 1024)
 
-#define GET_CHECK_PHONE(phone, phoneid, err) \
-{ \
-	if (phoneid > IPC_MAX_PHONES) { \
-		err \
-	} \
-	phone = &TASK->phones[phoneid]; \
+/** Get phone from the current task by ID.
+ *
+ * @param phoneid	Phone ID.
+ * @param phone		Place to store pointer to phone.
+ * @return		EOK on success, EINVAL if ID is invalid.
+ */
+static int phone_get(unative_t phoneid, phone_t **phone)
+{
+	if (phoneid >= IPC_MAX_PHONES)
+		return EINVAL;
+
+	*phone = &TASK->phones[phoneid];
+	return EOK;
 }
 
@@ -374,7 +381,9 @@
 	case IPC_M_CONNECTION_CLONE: {
 		phone_t *cloned_phone;
-		GET_CHECK_PHONE(cloned_phone, IPC_GET_ARG1(call->data),
-		    return ENOENT;);
+
+		if (phone_get(IPC_GET_ARG1(call->data), &cloned_phone) != EOK)
+			return ENOENT;
 		phones_lock(cloned_phone, phone);
+
 		if ((cloned_phone->state != IPC_PHONE_CONNECTED) ||
 		    phone->state != IPC_PHONE_CONNECTED) {
@@ -534,6 +543,7 @@
 	int res;
 	int rc;
-	
-	GET_CHECK_PHONE(phone, phoneid, return ENOENT;);
+
+	if (phone_get(phoneid, &phone) != EOK)
+		return ENOENT;
 
 	call = ipc_call_alloc(0);
@@ -591,5 +601,6 @@
 	int rc;
 
-	GET_CHECK_PHONE(phone, phoneid, return ENOENT;);
+	if (phone_get(phoneid, &phone) != EOK)
+		return ENOENT;
 
 	call = ipc_call_alloc(0);
@@ -666,5 +677,6 @@
 		return IPC_CALLRET_TEMPORARY;
 
-	GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL;);
+	if (phone_get(phoneid, &phone) != EOK)
+		return IPC_CALLRET_FATAL;
 
 	call = ipc_call_alloc(0);
@@ -705,5 +717,6 @@
 		return IPC_CALLRET_TEMPORARY;
 
-	GET_CHECK_PHONE(phone, phoneid, return IPC_CALLRET_FATAL;);
+	if (phone_get(phoneid, &phone) != EOK)
+		return IPC_CALLRET_FATAL;
 
 	call = ipc_call_alloc(0);
@@ -755,9 +768,9 @@
 	call->flags |= IPC_CALL_FORWARDED;
 
-	GET_CHECK_PHONE(phone, phoneid, {
+	if (phone_get(phoneid, &phone) != EOK) {
 		IPC_SET_RETVAL(call->data, EFORWARD);
 		ipc_answer(&TASK->answerbox, call);
 		return ENOENT;
-	});
+	}
 
 	if (!method_is_forwardable(IPC_GET_METHOD(call->data))) {
@@ -956,9 +969,10 @@
  * @return		Return 0 on success or an error code.
  */
-unative_t sys_ipc_hangup(int phoneid)
+unative_t sys_ipc_hangup(unative_t phoneid)
 {
 	phone_t *phone;
 
-	GET_CHECK_PHONE(phone, phoneid, return ENOENT;);
+	if (phone_get(phoneid, &phone) != EOK)
+		return ENOENT;
 
 	if (ipc_phone_hangup(phone))
Index: kernel/generic/src/lib/str.c
===================================================================
--- kernel/generic/src/lib/str.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/generic/src/lib/str.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -537,25 +537,23 @@
  * null-terminated and containing only complete characters.
  *
- * @param dest   Destination buffer.
+ * @param dest  Destination buffer.
  * @param count Size of the destination buffer (must be > 0).
  * @param src   Source string.
+ *
  */
 void str_cpy(char *dest, size_t size, const char *src)
 {
-	wchar_t ch;
-	size_t src_off;
-	size_t dest_off;
-
 	/* There must be space for a null terminator in the buffer. */
 	ASSERT(size > 0);
 	
-	src_off = 0;
-	dest_off = 0;
-
+	size_t src_off = 0;
+	size_t dest_off = 0;
+	
+	wchar_t ch;
 	while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
 		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
 			break;
 	}
-
+	
 	dest[dest_off] = '\0';
 }
@@ -571,27 +569,84 @@
  * have to be null-terminated.
  *
- * @param dest   Destination buffer.
+ * @param dest  Destination buffer.
  * @param count Size of the destination buffer (must be > 0).
  * @param src   Source string.
- * @param n	Maximum number of bytes to read from @a src.
+ * @param n     Maximum number of bytes to read from @a src.
+ *
  */
 void str_ncpy(char *dest, size_t size, const char *src, size_t n)
 {
-	wchar_t ch;
-	size_t src_off;
-	size_t dest_off;
-
 	/* There must be space for a null terminator in the buffer. */
 	ASSERT(size > 0);
 	
-	src_off = 0;
-	dest_off = 0;
-
+	size_t src_off = 0;
+	size_t dest_off = 0;
+	
+	wchar_t ch;
 	while ((ch = str_decode(src, &src_off, n)) != 0) {
 		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
 			break;
 	}
-
+	
 	dest[dest_off] = '\0';
+}
+
+/** Duplicate string.
+ *
+ * Allocate a new string and copy characters from the source
+ * string into it. The duplicate string is allocated via sleeping
+ * malloc(), thus this function can sleep in no memory conditions.
+ *
+ * The allocation cannot fail and the return value is always
+ * a valid pointer. The duplicate string is always a well-formed
+ * null-terminated UTF-8 string, but it can differ from the source
+ * string on the byte level.
+ *
+ * @param src Source string.
+ *
+ * @return Duplicate string.
+ *
+ */
+char *str_dup(const char *src)
+{
+	size_t size = str_size(src) + 1;
+	char *dest = malloc(size, 0);
+	ASSERT(dest);
+	
+	str_cpy(dest, size, src);
+	return dest;
+}
+
+/** Duplicate string with size limit.
+ *
+ * Allocate a new string and copy up to @max_size bytes from the source
+ * string into it. The duplicate string is allocated via sleeping
+ * malloc(), thus this function can sleep in no memory conditions.
+ * No more than @max_size + 1 bytes is allocated, but if the size
+ * occupied by the source string is smaller than @max_size + 1,
+ * less is allocated.
+ *
+ * The allocation cannot fail and the return value is always
+ * a valid pointer. The duplicate string is always a well-formed
+ * null-terminated UTF-8 string, but it can differ from the source
+ * string on the byte level.
+ *
+ * @param src Source string.
+ * @param n   Maximum number of bytes to duplicate.
+ *
+ * @return Duplicate string.
+ *
+ */
+char *str_ndup(const char *src, size_t n)
+{
+	size_t size = str_size(src);
+	if (size > n)
+		size = n;
+	
+	char *dest = malloc(size + 1, 0);
+	ASSERT(dest);
+	
+	str_ncpy(dest, size + 1, src, size);
+	return dest;
 }
 
Index: kernel/generic/src/main/main.c
===================================================================
--- kernel/generic/src/main/main.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/generic/src/main/main.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -84,4 +84,5 @@
 #include <main/main.h>
 #include <ipc/event.h>
+#include <sysinfo/sysinfo.h>
 
 /** Global configuration structure. */
@@ -209,4 +210,5 @@
 	/* Initialize at least 1 memory segment big enough for slab to work. */
 	LOG_EXEC(slab_cache_init());
+	LOG_EXEC(sysinfo_init());
 	LOG_EXEC(btree_init());
 	LOG_EXEC(as_init());
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/generic/src/proc/task.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -33,5 +33,5 @@
 /**
  * @file
- * @brief	Task management.
+ * @brief Task management.
  */
 
@@ -66,4 +66,5 @@
  * The task is guaranteed to exist after it was found in the tasks_tree as
  * long as:
+ *
  * @li the tasks_lock is held,
  * @li the task's lock is held when task's lock is acquired before releasing
@@ -99,5 +100,5 @@
 	task_t *t = avltree_get_instance(node, task_t, tasks_tree_node);
 	unsigned *cnt = (unsigned *) arg;
-
+	
 	if (t != TASK) {
 		(*cnt)++;
@@ -107,6 +108,7 @@
 		task_kill_internal(t);
 	}
-
-	return true;	/* continue the walk */
+	
+	/* Continue the walk */
+	return true;
 }
 
@@ -115,5 +117,5 @@
 {
 	unsigned tasks_left;
-
+	
 	do { /* Repeat until there are any tasks except TASK */
 		/* Messing with task structures, avoid deadlock */
@@ -138,19 +140,19 @@
 	task_t *ta = obj;
 	int i;
-
+	
 	atomic_set(&ta->refcount, 0);
 	atomic_set(&ta->lifecount, 0);
 	atomic_set(&ta->active_calls, 0);
-
+	
 	spinlock_initialize(&ta->lock, "task_ta_lock");
 	mutex_initialize(&ta->futexes_lock, MUTEX_PASSIVE);
-
+	
 	list_initialize(&ta->th_head);
 	list_initialize(&ta->sync_box_head);
-
+	
 	ipc_answerbox_init(&ta->answerbox, ta);
 	for (i = 0; i < IPC_MAX_PHONES; i++)
 		ipc_phone_init(&ta->phones[i]);
-
+	
 #ifdef CONFIG_UDEBUG
 	/* Init kbox stuff */
@@ -159,5 +161,5 @@
 	mutex_initialize(&ta->kb.cleanup_lock, MUTEX_PASSIVE);
 #endif
-
+	
 	return 0;
 }
@@ -165,8 +167,8 @@
 /** Create new task with no threads.
  *
- * @param as		Task's address space.
- * @param name		Symbolic name (a copy is made).
- *
- * @return		New task's structure.
+ * @param as   Task's address space.
+ * @param name Symbolic name (a copy is made).
+ *
+ * @return New task's structure.
  *
  */
@@ -181,5 +183,5 @@
 	memcpy(ta->name, name, TASK_NAME_BUFLEN);
 	ta->name[TASK_NAME_BUFLEN - 1] = 0;
-
+	
 	ta->context = CONTEXT;
 	ta->capabilities = 0;
@@ -197,13 +199,13 @@
 	/* Init debugging stuff */
 	udebug_task_init(&ta->udebug);
-
+	
 	/* Init kbox stuff */
 	ta->kb.finished = false;
 #endif
-
+	
 	if ((ipc_phone_0) &&
 	    (context_check(ipc_phone_0->task->context, ta->context)))
 		ipc_phone_connect(&ta->phones[0], ipc_phone_0);
-
+	
 	btree_create(&ta->futexes);
 	
@@ -223,5 +225,6 @@
 /** Destroy task.
  *
- * @param t		Task to be destroyed.
+ * @param t Task to be destroyed.
+ *
  */
 void task_destroy(task_t *t)
@@ -233,15 +236,15 @@
 	avltree_delete(&tasks_tree, &t->tasks_tree_node);
 	spinlock_unlock(&tasks_lock);
-
+	
 	/*
 	 * Perform architecture specific task destruction.
 	 */
 	task_destroy_arch(t);
-
+	
 	/*
 	 * Free up dynamically allocated state.
 	 */
 	btree_destroy(&t->futexes);
-
+	
 	/*
 	 * Drop our reference to the address space.
@@ -256,8 +259,9 @@
 /** Syscall for reading task ID from userspace.
  *
- * @param		uspace_task_id userspace address of 8-byte buffer
- * 			where to store current task ID.
- *
- * @return		Zero on success or an error code from @ref errno.h.
+ * @param uspace_task_id Userspace address of 8-byte buffer
+ *                       where to store current task ID.
+ *
+ * @return Zero on success or an error code from @ref errno.h.
+ *
  */
 unative_t sys_task_get_id(task_id_t *uspace_task_id)
@@ -275,8 +279,9 @@
  * The name simplifies identifying the task in the task list.
  *
- * @param name	The new name for the task. (typically the same
- *		as the command used to execute it).
+ * @param name The new name for the task. (typically the same
+ *             as the command used to execute it).
  *
  * @return 0 on success or an error code from @ref errno.h.
+ *
  */
 unative_t sys_task_set_name(const char *uspace_name, size_t name_len)
@@ -284,17 +289,17 @@
 	int rc;
 	char namebuf[TASK_NAME_BUFLEN];
-
+	
 	/* Cap length of name and copy it from userspace. */
-
+	
 	if (name_len > TASK_NAME_BUFLEN - 1)
 		name_len = TASK_NAME_BUFLEN - 1;
-
+	
 	rc = copy_from_uspace(namebuf, uspace_name, name_len);
 	if (rc != 0)
 		return (unative_t) rc;
-
+	
 	namebuf[name_len] = '\0';
 	str_cpy(TASK->name, TASK_NAME_BUFLEN, namebuf);
-
+	
 	return EOK;
 }
@@ -305,15 +310,18 @@
  * interrupts must be disabled.
  *
- * @param id		Task ID.
- *
- * @return		Task structure address or NULL if there is no such task
- * 			ID.
- */
-task_t *task_find_by_id(task_id_t id) { avltree_node_t *node;
-	
+ * @param id Task ID.
+ *
+ * @return Task structure address or NULL if there is no such task
+ *         ID.
+ *
+ */
+task_t *task_find_by_id(task_id_t id)
+{
+	avltree_node_t *node;
 	node = avltree_search(&tasks_tree, (avltree_key_t) id);
-
+	
 	if (node)
 		return avltree_get_instance(node, task_t, tasks_tree_node); 
+	
 	return NULL;
 }
@@ -324,7 +332,8 @@
  * already disabled.
  *
- * @param t		Pointer to thread.
- * @param ucycles	Out pointer to sum of all user cycles.
- * @param kcycles	Out pointer to sum of all kernel cycles.
+ * @param t       Pointer to thread.
+ * @param ucycles Out pointer to sum of all user cycles.
+ * @param kcycles Out pointer to sum of all kernel cycles.
+ *
  */
 void task_get_accounting(task_t *t, uint64_t *ucycles, uint64_t *kcycles)
@@ -359,5 +368,5 @@
 {
 	link_t *cur;
-
+	
 	/*
 	 * Interrupt all threads.
@@ -387,7 +396,8 @@
  * It signals all the task's threads to bail it out.
  *
- * @param id		ID of the task to be killed.
- *
- * @return		Zero on success or an error code from errno.h.
+ * @param id ID of the task to be killed.
+ *
+ * @return Zero on success or an error code from errno.h.
+ *
  */
 int task_kill(task_id_t id)
@@ -416,7 +426,7 @@
 	task_t *t = avltree_get_instance(node, task_t, tasks_tree_node);
 	int j;
-		
+	
 	spinlock_lock(&t->lock);
-			
+	
 	uint64_t ucycles;
 	uint64_t kcycles;
@@ -425,5 +435,5 @@
 	order(ucycles, &ucycles, &usuffix);
 	order(kcycles, &kcycles, &ksuffix);
-
+	
 #ifdef __32_BITS__	
 	printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %10p %10p %9" PRIu64 "%c %9"
@@ -432,5 +442,5 @@
 		atomic_get(&t->active_calls));
 #endif
-
+	
 #ifdef __64_BITS__
 	printf("%-6" PRIu64 " %-12s %-3" PRIu32 " %18p %18p %9" PRIu64 "%c %9"
@@ -439,5 +449,5 @@
 		atomic_get(&t->active_calls));
 #endif
-
+	
 	for (j = 0; j < IPC_MAX_PHONES; j++) {
 		if (t->phones[j].callee)
@@ -445,5 +455,5 @@
 	}
 	printf("\n");
-			
+	
 	spinlock_unlock(&t->lock);
 	return true;
@@ -458,6 +468,6 @@
 	ipl = interrupts_disable();
 	spinlock_lock(&tasks_lock);
-
-#ifdef __32_BITS__	
+	
+#ifdef __32_BITS__
 	printf("taskid name         ctx address    as        "
 	    " ucycles    kcycles    threads calls  callee\n");
@@ -465,5 +475,5 @@
 	    " ---------- ---------- ------- ------ ------>\n");
 #endif
-
+	
 #ifdef __64_BITS__
 	printf("taskid name         ctx address            as                "
@@ -472,7 +482,7 @@
 	    " ---------- ---------- ---------- ------- ------ ------>\n");
 #endif
-
+	
 	avltree_walk(&tasks_tree, task_print_walker, NULL);
-
+	
 	spinlock_unlock(&tasks_lock);
 	interrupts_restore(ipl);
Index: kernel/generic/src/syscall/syscall.c
===================================================================
--- kernel/generic/src/syscall/syscall.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/generic/src/syscall/syscall.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -162,6 +162,8 @@
 	
 	/* Sysinfo syscalls */
-	(syshandler_t) sys_sysinfo_valid,
-	(syshandler_t) sys_sysinfo_value,
+	(syshandler_t) sys_sysinfo_get_tag,
+	(syshandler_t) sys_sysinfo_get_value,
+	(syshandler_t) sys_sysinfo_get_data_size,
+	(syshandler_t) sys_sysinfo_get_data,
 	
 	/* Debug calls */
Index: kernel/generic/src/sysinfo/sysinfo.c
===================================================================
--- kernel/generic/src/sysinfo/sysinfo.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/generic/src/sysinfo/sysinfo.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -37,281 +37,414 @@
 #include <print.h>
 #include <syscall/copy.h>
+#include <errno.h>
+
+#define SYSINFO_MAX_PATH  2048
 
 bool fb_exported = false;
-sysinfo_item_t *_root = NULL;
-
-static sysinfo_item_t *sysinfo_find_item(const char *name, sysinfo_item_t *subtree)
-{
-	if (subtree == NULL)
-		return NULL;
-	
-	while (subtree != NULL) {
-		int i = 0;
-		char *a = (char *) name;
-		char *b = subtree->name;
-		
-		while ((a[i] == b[i]) && (b[i]))
+
+static sysinfo_item_t *global_root = NULL;
+static slab_cache_t *sysinfo_item_slab;
+
+static int sysinfo_item_constructor(void *obj, int kmflag)
+{
+	sysinfo_item_t *item = (sysinfo_item_t *) obj;
+	
+	item->name = NULL;
+	item->val_type = SYSINFO_VAL_UNDEFINED;
+	item->subtree_type = SYSINFO_SUBTREE_NONE;
+	item->subtree.table = NULL;
+	item->next = NULL;
+	
+	return 0;
+}
+
+static int sysinfo_item_destructor(void *obj)
+{
+	sysinfo_item_t *item = (sysinfo_item_t *) obj;
+	
+	if (item->name != NULL)
+		free(item->name);
+	
+	return 0;
+}
+
+void sysinfo_init(void)
+{
+	sysinfo_item_slab = slab_cache_create("sysinfo_item_slab",
+	    sizeof(sysinfo_item_t), 0, sysinfo_item_constructor,
+	    sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED);
+}
+
+static sysinfo_item_t *sysinfo_find_item(const char *name,
+    sysinfo_item_t *subtree)
+{
+	sysinfo_item_t *cur = subtree;
+	
+	while (cur != NULL) {
+		size_t i = 0;
+		
+		/* Compare name with path */
+		while ((cur->name[i] != 0) && (name[i] == cur->name[i]))
 			i++;
 		
-		if ((!a[i]) && (!b[i]))  /* Last name in path matches */
-			return subtree;
-		
-		if ((a[i] == '.') && (!b[i])) { /* Middle name in path matches */
-			if (subtree->subinfo_type == SYSINFO_SUBINFO_TABLE)
-				return sysinfo_find_item(a + i + 1, subtree->subinfo.table);
+		/* Check for perfect name and path match */
+		if ((name[i] == 0) && (cur->name[i] == 0))
+			return cur;
+		
+		/* Partial match up to the delimiter */
+		if ((name[i] == '.') && (cur->name[i] == 0)) {
+			/* Look into the subtree */
+			switch (cur->subtree_type) {
+			case SYSINFO_SUBTREE_TABLE:
+				/* Recursively find in subtree */
+				return sysinfo_find_item(name + i + 1, cur->subtree.table);
+			case SYSINFO_SUBTREE_FUNCTION:
+				/* Get generated item */
+				return cur->subtree.find_item(name + i + 1);
+			default:
+				/* Not found */
+				return NULL;
+			}
+		}
+		
+		cur = cur->next;
+	}
+	
+	return NULL;
+}
+
+static sysinfo_item_t *sysinfo_create_path(const char *name,
+    sysinfo_item_t **psubtree)
+{
+	ASSERT(psubtree != NULL);
+	
+	if (*psubtree == NULL) {
+		/* No parent */
+		
+		size_t i = 0;
+		
+		/* Find the first delimiter in name */
+		while ((name[i] != 0) && (name[i] != '.'))
+			i++;
+		
+		*psubtree =
+		    (sysinfo_item_t *) slab_alloc(sysinfo_item_slab, 0);
+		ASSERT(*psubtree);
+		
+		/* Fill in item name up to the delimiter */
+		(*psubtree)->name = str_ndup(name, i);
+		ASSERT((*psubtree)->name);
+		
+		/* Create subtree items */
+		if (name[i] == '.') {
+			(*psubtree)->subtree_type = SYSINFO_SUBTREE_TABLE;
+			return sysinfo_create_path(name + i + 1,
+			    &((*psubtree)->subtree.table));
+		}
+		
+		/* No subtree needs to be created */
+		return *psubtree;
+	}
+	
+	sysinfo_item_t *cur = *psubtree;
+	
+	while (cur != NULL) {
+		size_t i = 0;
+		
+		/* Compare name with path */
+		while ((cur->name[i] != 0) && (name[i] == cur->name[i]))
+			i++;
+		
+		/* Check for perfect name and path match
+		 * -> item is already present.
+		 */
+		if ((name[i] == 0) && (cur->name[i] == 0))
+			return cur;
+		
+		/* Partial match up to the delimiter */
+		if ((name[i] == '.') && (cur->name[i] == 0)) {
+			switch (cur->subtree_type) {
+			case SYSINFO_SUBTREE_NONE:
+				/* No subtree yet, create one */
+				cur->subtree_type = SYSINFO_SUBTREE_TABLE;
+				return sysinfo_create_path(name + i + 1,
+				    &(cur->subtree.table));
+			case SYSINFO_SUBTREE_TABLE:
+				/* Subtree already created, add new sibling */
+				return sysinfo_create_path(name + i + 1,
+				    &(cur->subtree.table));
+			default:
+				/* Subtree items handled by a function, this
+				 * cannot be overriden.
+				 */
+				return NULL;
+			}
+		}
+		
+		/* No match and no more siblings to check
+		 * -> create a new sibling item.
+		 */
+		if (cur->next == NULL) {
+			/* Find the first delimiter in name */
+			i = 0;
+			while ((name[i] != 0) && (name[i] != '.'))
+				i++;
 			
-			//if (subtree->subinfo_type == SYSINFO_SUBINFO_FUNCTION) /* Subinfo managed by subsystem */
-			//	return NULL; 
+			sysinfo_item_t *item =
+			    (sysinfo_item_t *) slab_alloc(sysinfo_item_slab, 0);
+			ASSERT(item);
 			
-			return NULL; /* No subinfo */
-		}
-		/* No matches try next */
-		subtree = subtree->next;
-	}
-	return NULL;
-}
-
-static sysinfo_item_t *sysinfo_create_path(const char *name, sysinfo_item_t **psubtree)
-{
-	sysinfo_item_t *subtree;
-	subtree = *psubtree;
-	
-	if (subtree == NULL) {
-		sysinfo_item_t *item = malloc(sizeof(sysinfo_item_t), 0);
-		int i = 0, j;
+			cur->next = item;
 			
-		ASSERT(item);
-		*psubtree = item;
-		item->next = NULL;
-		item->val_type = SYSINFO_VAL_UNDEFINED;
-		item->subinfo.table = NULL;
-
-		while (name[i] && (name[i] != '.'))
-			i++;
+			/* Fill in item name up to the delimiter */
+			item->name = str_ndup(name, i);
+			ASSERT(item->name);
 			
-		item->name = malloc(i, 0);
-		ASSERT(item->name);
-
-		for (j = 0; j < i; j++)
-			item->name[j] = name[j];
-		item->name[j] = 0;
-			
-		if (name[i]) { /* =='.' */
-			item->subinfo_type = SYSINFO_SUBINFO_TABLE;
-			return sysinfo_create_path(name + i + 1, &(item->subinfo.table));
-		}
-		item->subinfo_type = SYSINFO_SUBINFO_NONE;
-		return item;
-	}
-
-	while (subtree != NULL) {
-		int i = 0, j;
-		char *a = (char *) name;
-		char *b = subtree->name;
-		
-		while ((a[i] == b[i]) && (b[i]))
-			i++;
-		
-		if ((!a[i]) && (!b[i])) /* Last name in path matches */
-			return subtree;
-		
-		if ((a[i] == '.') && (!b[i])) { /* Middle name in path matches */
-			if (subtree->subinfo_type == SYSINFO_SUBINFO_TABLE)
-				return sysinfo_create_path(a + i + 1, &(subtree->subinfo.table));
-			
-			if (subtree->subinfo_type == SYSINFO_SUBINFO_NONE) {
-				subtree->subinfo_type = SYSINFO_SUBINFO_TABLE;
-				return sysinfo_create_path(a + i + 1,&(subtree->subinfo.table));
+			/* Create subtree items */
+			if (name[i] == '.') {
+				item->subtree_type = SYSINFO_SUBTREE_TABLE;
+				return sysinfo_create_path(name + i + 1,
+				    &(item->subtree.table));
 			}
 			
-			//if (subtree->subinfo_type == SYSINFO_SUBINFO_FUNCTION) /* Subinfo managed by subsystem */
-			//	return NULL; 
-			
-			return NULL;
-		}
-		/* No matches try next or create new*/
-		if (subtree->next == NULL) {
-			sysinfo_item_t *item = malloc(sizeof(sysinfo_item_t), 0);
-			
-			ASSERT(item);
-			subtree->next = item;
-			item->next = NULL;
-			item->val_type = SYSINFO_VAL_UNDEFINED;
-			item->subinfo.table = NULL;
-
-			i = 0;
-			while (name[i] && (name[i] != '.'))
-				i++;
-
-			item->name = malloc(i, 0);
-			ASSERT(item->name);
-			
-			for (j = 0; j < i; j++)
-				item->name[j] = name[j];
-			
-			item->name[j] = 0;
-
-			if(name[i]) { /* =='.' */
-				item->subinfo_type = SYSINFO_SUBINFO_TABLE;
-				return sysinfo_create_path(name + i + 1, &(item->subinfo.table));
-			}
-			item->subinfo_type = SYSINFO_SUBINFO_NONE;
+			/* No subtree needs to be created */
 			return item;
-		} else
-			subtree = subtree->next;
-	}
-
-	panic("Not reached.");
+		}
+		
+		/* Get next sibling */
+		cur = cur->next;
+	}
+	
+	/* Unreachable */
+	ASSERT(false);
 	return NULL;
 }
 
-void sysinfo_set_item_val(const char *name, sysinfo_item_t **root, unative_t val)
-{
-	if (root == NULL)
-		root = &_root;
-	
-	/* If already created create only returns pointer 
-	   If not, create it */
+void sysinfo_set_item_val(const char *name, sysinfo_item_t **root,
+    unative_t val)
+{
+	if (root == NULL)
+		root = &global_root;
+	
 	sysinfo_item_t *item = sysinfo_create_path(name, root);
-	
-	if (item != NULL) { /* If in subsystem, unable to create or return so unable to set */
-		item->val.val = val;                   
+	if (item != NULL) {
 		item->val_type = SYSINFO_VAL_VAL;
-	}
-}
-
-void sysinfo_set_item_function(const char *name, sysinfo_item_t **root, sysinfo_val_fn_t fn)
-{
-	if (root == NULL)
-		root = &_root;
-	
-	/* If already created create only returns pointer 
-	   If not, create it */
+		item->val.val = val;
+	}
+}
+
+void sysinfo_set_item_data(const char *name, sysinfo_item_t **root,
+    void *data, size_t size)
+{
+	if (root == NULL)
+		root = &global_root;
+	
 	sysinfo_item_t *item = sysinfo_create_path(name, root);
-	
-	if (item != NULL) { /* If in subsystem, unable to create or return so  unable to set */
-		item->val.fn = fn;                   
-		item->val_type = SYSINFO_VAL_FUNCTION;
-	}
-}
-
+	if (item != NULL) {
+		item->val_type = SYSINFO_VAL_DATA;
+		item->val.data.data = data;
+		item->val.data.size = size;
+	}
+}
+
+void sysinfo_set_item_val_fn(const char *name, sysinfo_item_t **root,
+    sysinfo_fn_val_t fn)
+{
+	if (root == NULL)
+		root = &global_root;
+	
+	sysinfo_item_t *item = sysinfo_create_path(name, root);
+	if (item != NULL) {
+		item->val_type = SYSINFO_VAL_FUNCTION_VAL;
+		item->val.fn_val = fn;
+	}
+}
+
+void sysinfo_set_item_data_fn(const char *name, sysinfo_item_t **root,
+    sysinfo_fn_data_t fn)
+{
+	if (root == NULL)
+		root = &global_root;
+	
+	sysinfo_item_t *item = sysinfo_create_path(name, root);
+	if (item != NULL) {
+		item->val_type = SYSINFO_VAL_FUNCTION_DATA;
+		item->val.fn_data = fn;
+	}
+}
 
 void sysinfo_set_item_undefined(const char *name, sysinfo_item_t **root)
 {
 	if (root == NULL)
-		root = &_root;
-	
-	/* If already created create only returns pointer 
-	   If not, create it */
+		root = &global_root;
+	
 	sysinfo_item_t *item = sysinfo_create_path(name, root);
-	
 	if (item != NULL)
 		item->val_type = SYSINFO_VAL_UNDEFINED;
 }
 
-
-void sysinfo_dump(sysinfo_item_t **proot, int depth)
-{
-	sysinfo_item_t *root;
+static void sysinfo_indent(unsigned int depth)
+{
+	unsigned int i;
+	for (i = 0; i < depth; i++)
+		printf("  ");
+}
+
+void sysinfo_dump(sysinfo_item_t **proot, unsigned int depth)
+{
 	if (proot == NULL)
-		proot = &_root;
-	
-	root = *proot;
-	
-	while (root != NULL) {
-		int i;
-		unative_t val = 0;
-		const char *vtype = NULL;
-		
-		
-		for (i = 0; i < depth; i++)
-			printf("  ");
-		
-		switch (root->val_type) {
+		proot = &global_root;
+	
+	sysinfo_item_t *cur = *proot;
+	
+	while (cur != NULL) {
+		sysinfo_indent(depth);
+		
+		unative_t val;
+		size_t size;
+		
+		switch (cur->val_type) {
 		case SYSINFO_VAL_UNDEFINED:
-			val = 0;
-			vtype = "UND";
+			printf("+ %s\n", cur->name);
 			break;
 		case SYSINFO_VAL_VAL:
-			val = root->val.val;
-			vtype = "VAL";
-			break;
-		case SYSINFO_VAL_FUNCTION:
-			val = ((sysinfo_val_fn_t) (root->val.fn)) (root);
-			vtype = "FUN";
-			break;
-		}
-		
-		printf("%s    %s val:%" PRIun "(%" PRIxn ") sub:%s\n", root->name, vtype, val,
-			val, (root->subinfo_type == SYSINFO_SUBINFO_NONE) ?
-			"NON" : ((root->subinfo_type == SYSINFO_SUBINFO_TABLE) ?
-			"TAB" : "FUN"));
-		
-		if (root->subinfo_type == SYSINFO_SUBINFO_TABLE)
-			sysinfo_dump(&(root -> subinfo.table), depth + 1);
-		
-		root = root->next;
-	}
-}
-
-sysinfo_rettype_t sysinfo_get_val(const char *name, sysinfo_item_t **root)
-{
-	// TODO: Implement Subsystem subinfo (by function implemented subinfo)
-
-	sysinfo_rettype_t ret = {0, false};
-
-	if (root == NULL)
-		root = &_root;
+			printf("+ %s -> %" PRIun" (%#" PRIxn ")\n", cur->name,
+			    cur->val.val, cur->val.val);
+			break;
+		case SYSINFO_VAL_DATA:
+			printf("+ %s (%" PRIs" bytes)\n", cur->name,
+			    cur->val.data.size);
+			break;
+		case SYSINFO_VAL_FUNCTION_VAL:
+			val = cur->val.fn_val(cur);
+			printf("+ %s -> %" PRIun" (%#" PRIxn ") [generated]\n",
+			    cur->name, val, val);
+			break;
+		case SYSINFO_VAL_FUNCTION_DATA:
+			cur->val.fn_data(cur, &size);
+			printf("+ %s (%" PRIs" bytes) [generated]\n", cur->name,
+			    size);
+			break;
+		default:
+			printf("+ %s [unknown]\n", cur->name);
+		}
+		
+		switch (cur->subtree_type) {
+		case SYSINFO_SUBTREE_NONE:
+			break;
+		case SYSINFO_SUBTREE_TABLE:
+			sysinfo_dump(&(cur->subtree.table), depth + 1);
+			break;
+		case SYSINFO_SUBTREE_FUNCTION:
+			sysinfo_indent(depth + 1);
+			printf("  [generated subtree]\n");
+			break;
+		default:
+			sysinfo_indent(depth + 1);
+			printf("  [unknown subtree]\n");
+		}
+		
+		cur = cur->next;
+	}
+}
+
+sysinfo_return_t sysinfo_get_item(const char *name, sysinfo_item_t **root)
+{
+	if (root == NULL)
+		root = &global_root;
 	
 	sysinfo_item_t *item = sysinfo_find_item(name, *root);
+	sysinfo_return_t ret;
 	
 	if (item != NULL) {
-		if (item->val_type == SYSINFO_VAL_UNDEFINED) 
-			return ret;
-		else
-			ret.valid = true;
-		
-		if (item->val_type == SYSINFO_VAL_VAL)
+		switch (item->val_type) {
+		case SYSINFO_VAL_UNDEFINED:
+			ret.tag = SYSINFO_VAL_UNDEFINED;
+			break;
+		case SYSINFO_VAL_VAL:
+			ret.tag = SYSINFO_VAL_VAL;
 			ret.val = item->val.val;
-		else
-			ret.val = ((sysinfo_val_fn_t) (item->val.fn)) (item);
-	}
+			break;
+		case SYSINFO_VAL_DATA:
+			ret.tag = SYSINFO_VAL_DATA;
+			ret.data = item->val.data;
+			break;
+		case SYSINFO_VAL_FUNCTION_VAL:
+			ret.tag = SYSINFO_VAL_VAL;
+			ret.val = item->val.fn_val(item);
+			break;
+		case SYSINFO_VAL_FUNCTION_DATA:
+			ret.tag = SYSINFO_VAL_DATA;
+			ret.data.data = item->val.fn_data(item, &ret.data.size);
+			break;
+		}
+	} else
+		ret.tag = SYSINFO_VAL_UNDEFINED;
+	
 	return ret;
 }
 
-#define SYSINFO_MAX_LEN	1024
-
-unative_t sys_sysinfo_valid(unative_t ptr, unative_t len)
-{
-	char *str;
-	sysinfo_rettype_t ret = {0, 0};
-
-	if (len > SYSINFO_MAX_LEN)
-		return ret.valid;
-	str = malloc(len + 1, 0);
-	
-	ASSERT(str);
-	if (!((copy_from_uspace(str, (void *) ptr, len + 1)) || (str[len])))
-		ret = sysinfo_get_val(str, NULL);
-	
-	free(str);
-	return ret.valid;
-}
-
-unative_t sys_sysinfo_value(unative_t ptr, unative_t len)
-{
-	char *str;
-	sysinfo_rettype_t ret = {0, 0};
-	
-	if (len > SYSINFO_MAX_LEN)
-		return ret.val;
-	str = malloc(len + 1, 0);
-	
-	ASSERT(str);
-	if (!((copy_from_uspace(str, (void *) ptr, len + 1)) || (str[len]))) 
-		ret = sysinfo_get_val(str, NULL);
-	
-	free(str);
-	return ret.val;
+static sysinfo_return_t sysinfo_get_item_uspace(void *ptr, size_t size)
+{
+	sysinfo_return_t ret;
+	ret.tag = SYSINFO_VAL_UNDEFINED;
+	
+	if (size > SYSINFO_MAX_PATH)
+		return ret;
+	
+	char *path = (char *) malloc(size + 1, 0);
+	ASSERT(path);
+	
+	if ((copy_from_uspace(path, ptr, size + 1) == 0)
+	    && (path[size] == 0)) {
+		ret = sysinfo_get_item(path, NULL);
+		free(path);
+	}
+	
+	return ret;
+}
+
+unative_t sys_sysinfo_get_tag(void *path_ptr, size_t path_size)
+{
+	return (unative_t) sysinfo_get_item_uspace(path_ptr, path_size).tag;
+}
+
+unative_t sys_sysinfo_get_value(void *path_ptr, size_t path_size,
+    void *value_ptr)
+{
+	sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size);
+	
+	if (ret.tag != SYSINFO_VAL_VAL)
+		return (unative_t) EINVAL;
+	
+	return (unative_t) copy_to_uspace(value_ptr, &ret.val,
+	    sizeof(ret.val));
+}
+
+unative_t sys_sysinfo_get_data_size(void *path_ptr, size_t path_size,
+    void *size_ptr)
+{
+	sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size);
+	
+	if (ret.tag != SYSINFO_VAL_DATA)
+		return (unative_t) EINVAL;
+	
+	return (unative_t) copy_to_uspace(size_ptr, &ret.data.size,
+	    sizeof(ret.data.size));
+}
+
+unative_t sys_sysinfo_get_data(void *path_ptr, size_t path_size,
+    void *buffer_ptr, size_t buffer_size)
+{
+	sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size);
+	
+	if (ret.tag != SYSINFO_VAL_DATA)
+		return (unative_t) EINVAL;
+	
+	if (ret.data.size != buffer_size)
+		return ENOMEM;
+	
+	return (unative_t) copy_to_uspace(buffer_ptr, ret.data.data,
+	    ret.data.size);
 }
 
Index: rnel/test/sysinfo/sysinfo1.c
===================================================================
--- kernel/test/sysinfo/sysinfo1.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,40 +1,0 @@
-/*
- * Copyright (c) 2005 Jakub Vana
- * 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.
- */
-
-#include <print.h>
-#include <debug.h>
-
-#include <test.h>
-#include <sysinfo/sysinfo.h>
-
-const char *test_sysinfo1(void)
-{
-	if (!test_quiet)
-		sysinfo_dump(NULL, 0);
-	return NULL;
-}
Index: rnel/test/sysinfo/sysinfo1.def
===================================================================
--- kernel/test/sysinfo/sysinfo1.def	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,6 +1,0 @@
-{
-	"sysinfo1",
-	"Sysinfo test",
-	&test_sysinfo1,
-	true
-},
Index: kernel/test/test.c
===================================================================
--- kernel/test/test.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/test/test.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -63,5 +63,4 @@
 #include <print/print4.def>
 #include <thread/thread1.def>
-#include <sysinfo/sysinfo1.def>
 	{
 		.name = NULL,
Index: kernel/test/test.h
===================================================================
--- kernel/test/test.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ kernel/test/test.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -82,5 +82,4 @@
 extern const char *test_print4(void);
 extern const char *test_thread1(void);
-extern const char *test_sysinfo1(void);
 
 extern test_t tests[];
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -41,4 +41,5 @@
 	app/mkfat \
 	app/redir \
+	app/sbi \
 	app/taskdump \
 	app/tester \
@@ -68,5 +69,32 @@
 	srv/hid/fb \
 	srv/hid/kbd \
-	srv/hw/char/i8042
+	srv/hw/char/i8042 \
+	srv/hw/netif/dp8390 \
+	srv/net/cfg \
+	srv/net/netif/lo \
+	srv/net/il/arp \
+	srv/net/il/ip \
+	srv/net/tl/icmp \
+	srv/net/tl/udp \
+	srv/net/tl/tcp \
+	srv/net/net \
+	srv/net/netstart \
+	app/netecho \
+	app/nettest1 \
+	app/nettest2 \
+	app/ping
+
+## Networking
+#
+
+ifeq ($(CONFIG_NETIF_NIL_BUNDLE),y)
+	LIBN = \
+		srv/net/nil/eth \
+		srv/net/nil/nildummy
+else
+	DIRS += \
+		srv/net/nil/eth \
+		srv/net/nil/nildummy
+endif
 
 ## Platform-specific hardware support
@@ -95,30 +123,4 @@
 endif
 
-## Networking
-#
-
-ifeq ($(CONFIG_NETIF_DP8390),y)
-	DIRS += srv/net/netif/dp8390
-endif
-
-NETWORKING_COMMON = \
-	srv/net/netif/lo \
-	srv/net/nil/eth \
-	srv/net/nil/nildummy \
-	srv/net/net \
-	srv/net/net/start \
-	srv/net/socket \
-	srv/net/app/echo \
-	srv/net/app/ping \
-	srv/net/app/nettest1 \
-	srv/net/app/nettest2
-
-NETWORKING_MODULAR = \
-	srv/net/il/arp \
-	srv/net/il/ip \
-	srv/net/tl/icmp \
-	srv/net/tl/udp \
-	srv/net/tl/tcp
-
 ## System libraries
 #
@@ -128,6 +130,9 @@
 	lib/fs \
 	lib/block \
+	lib/clui \
 	lib/softint \
 	lib/softfloat \
+	lib/socket \
+	lib/net
 
 ifeq ($(UARCH),amd64)
@@ -142,20 +147,10 @@
 LIBC_BUILD = $(addsuffix .build,$(LIBC))
 LIBS_BUILD = $(addsuffix .build,$(LIBS))
+LIBN_BUILD = $(addsuffix .build,$(LIBN))
+BUILDS := $(addsuffix .build,$(DIRS))
 
-ifeq ($(CONFIG_NETWORKING),modular)
-	BUILDS := $(addsuffix .build,$(DIRS)) $(addsuffix .build,$(NETWORKING_COMMON)) $(addsuffix .build,$(NETWORKING_MODULAR))
-endif
+CLEANS := $(addsuffix .clean,$(DIRS)) $(addsuffix .clean,$(LIBN)) $(addsuffix .clean,$(LIBS)) $(addsuffix .clean,$(LIBC))
 
-ifeq ($(CONFIG_NETWORKING),module)
-	BUILDS := $(addsuffix .build,$(DIRS)) $(addsuffix .build,$(NETWORKING_COMMON))
-endif
-
-ifeq ($(CONFIG_NETWORKING),none)
-	BUILDS := $(addsuffix .build,$(DIRS))
-endif
-
-CLEANS := $(addsuffix .clean,$(DIRS)) $(addsuffix .clean,$(NETWORKING_COMMON)) $(addsuffix .clean,$(NETWORKING_MODULAR)) $(addsuffix .clean,$(LIBS)) $(addsuffix .clean,$(LIBC))
-
-.PHONY: all $(LIBC_BUILD) $(LIBS_BUILD) $(BUILDS) $(CLEANS) clean
+.PHONY: all $(LIBC_BUILD) $(LIBS_BUILD) $(LIBN_BUILD) $(BUILDS) $(CLEANS) clean
 
 all: $(BUILDS)
@@ -166,5 +161,8 @@
 	-$(MAKE) -C $(basename $@) clean
 
-$(BUILDS): $(LIBC_BUILD) $(LIBS_BUILD)
+$(BUILDS): $(LIBC_BUILD) $(LIBS_BUILD) $(LIBN_BUILD)
+	$(MAKE) -C $(basename $@) all PRECHECK=$(PRECHECK)
+
+$(LIBN_BUILD): $(LIBC_BUILD) $(LIBS_BUILD)
 	$(MAKE) -C $(basename $@) all PRECHECK=$(PRECHECK)
 
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/Makefile.common	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -76,12 +76,20 @@
 DEPEND_PREV = $(DEPEND).prev
 
-LIBC_PREFIX = $(USPACE_PREFIX)/lib/c
-LIBBLOCK_PREFIX = $(USPACE_PREFIX)/lib/block
-LIBFS_PREFIX = $(USPACE_PREFIX)/lib/fs
-LIBPCI_PREFIX = $(USPACE_PREFIX)/lib/pci
-SOFTFLOAT_PREFIX = $(USPACE_PREFIX)/lib/softfloat
-SOFTINT_PREFIX = $(USPACE_PREFIX)/lib/softint
+LIB_PREFIX = $(USPACE_PREFIX)/lib
 
-BASE_LIBS = $(LIBC_PREFIX)/libc.a $(SOFTINT_PREFIX)/libsoftint.a
+LIBC_PREFIX = $(LIB_PREFIX)/c
+LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
+LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
+
+LIBBLOCK_PREFIX = $(LIB_PREFIX)/block
+LIBFS_PREFIX = $(LIB_PREFIX)/fs
+LIBCLUI_PREFIX = $(LIB_PREFIX)/clui
+
+LIBPCI_PREFIX = $(LIB_PREFIX)/pci
+
+LIBSOCKET_PREFIX = $(LIB_PREFIX)/socket
+LIBNET_PREFIX = $(LIB_PREFIX)/net
+
+BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
 
 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
Index: uspace/app/bdsh/Makefile
===================================================================
--- uspace/app/bdsh/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/app/bdsh/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -29,6 +29,7 @@
 
 USPACE_PREFIX = ../..
-LIBS = $(LIBBLOCK_PREFIX)/libblock.a
-EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I. -Icmds/ -Icmds/builtins -Icmds/modules
+LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBCLUI_PREFIX)/libclui.a
+EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBCLUI_PREFIX) -I. -Icmds/ \
+	-Icmds/builtins -Icmds/modules
 BINARY = bdsh
 
Index: uspace/app/bdsh/exec.c
===================================================================
--- uspace/app/bdsh/exec.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/app/bdsh/exec.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -40,4 +40,5 @@
 #include <str.h>
 #include <fcntl.h>
+#include <str_error.h>
 
 #include "config.h"
@@ -120,9 +121,10 @@
 	free(found);
 
-	tid = task_spawn(tmp, (const char **) argv);
+	tid = task_spawn(tmp, (const char **) argv, &retval);
 	free(tmp);
 
 	if (tid == 0) {
-		cli_error(CL_EEXEC, "Cannot spawn `%s'.", cmd);
+		cli_error(CL_EEXEC, "%s: Cannot spawn `%s' (%s)", progname, cmd,
+		    str_error(retval));
 		return 1;
 	}
@@ -130,7 +132,8 @@
 	task_wait(tid, &texit, &retval);
 	if (texit != TASK_EXIT_NORMAL) {
-		printf("Command failed (unexpectedly terminated).\n");
+		printf("%s: Command failed (unexpectedly terminated)\n", progname);
 	} else if (retval != 0) {
-		printf("Command failed (return value %d).\n", retval);
+		printf("%s: Command failed (%s)\n",
+		    progname, str_error(retval));
 	}
 
Index: uspace/app/bdsh/input.c
===================================================================
--- uspace/app/bdsh/input.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/app/bdsh/input.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -1,5 +1,4 @@
 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
  * All rights reserved.
- * Copyright (c) 2008, Jiri Svoboda - All Rights Reserved
  *
  * Redistribution and use in source and binary forms, with or without
@@ -43,4 +42,5 @@
 #include <assert.h>
 #include <bool.h>
+#include <tinput.h>
 
 #include "config.h"
@@ -51,51 +51,8 @@
 #include "exec.h"
 
-#define HISTORY_LEN 10
+extern volatile unsigned int cli_quit;
 
 /** Text input field. */
-typedef struct {
-	/** Buffer holding text currently being edited */
-	wchar_t buffer[INPUT_MAX + 1];
-	/** Screen coordinates of the top-left corner of the text field */
-	int col0, row0;
-	/** Screen dimensions */
-	int con_cols, con_rows;
-	/** Number of characters in @c buffer */
-	int nc;
-	/** Caret position within buffer */
-	int pos;
-	/** Selection mark position within buffer */
-	int sel_start;
-
-	/** History (dynamically allocated strings) */
-	char *history[1 + HISTORY_LEN];
-	/** Number of entries in @c history, not counting [0] */
-	int hnum;
-	/** Current position in history */
-	int hpos;
-	/** Exit flag */
-	bool done;
-} tinput_t;
-
-/** Seek direction */
-typedef enum {
-	seek_backward = -1,
-	seek_forward = 1
-} seek_dir_t;
-
-static tinput_t tinput;
-
-static char *tinput_read(tinput_t *ti);
-static void tinput_insert_string(tinput_t *ti, const char *str);
-static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb);
-static bool tinput_sel_active(tinput_t *ti);
-static void tinput_sel_all(tinput_t *ti);
-static void tinput_sel_delete(tinput_t *ti);
-static void tinput_key_ctrl(tinput_t *ti, console_event_t *ev);
-static void tinput_key_shift(tinput_t *ti, console_event_t *ev);
-static void tinput_key_ctrl_shift(tinput_t *ti, console_event_t *ev);
-static void tinput_key_unmod(tinput_t *ti, console_event_t *ev);
-static void tinput_pre_seek(tinput_t *ti, bool shift_held);
-static void tinput_post_seek(tinput_t *ti, bool shift_held);
+static tinput_t *tinput;
 
 /* Tokenizes input from console, sees if the first word is a built-in, if so
@@ -149,620 +106,8 @@
 }
 
-static void tinput_display_tail(tinput_t *ti, int start, int pad)
-{
-	static wchar_t dbuf[INPUT_MAX + 1];
-	int sa, sb;
-	int i, p;
-
-	tinput_sel_get_bounds(ti, &sa, &sb);
-
-	console_goto(fphone(stdout), (ti->col0 + start) % ti->con_cols,
-	    ti->row0 + (ti->col0 + start) / ti->con_cols);
-	console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
-
-	p = start;
-	if (p < sa) {
-		memcpy(dbuf, ti->buffer + p, (sa - p) * sizeof(wchar_t));
-		dbuf[sa - p] = '\0';
-		printf("%ls", dbuf);
-		p = sa;
-	}
-
-	if (p < sb) {
-		fflush(stdout);
-		console_set_color(fphone(stdout), COLOR_BLACK, COLOR_RED, 0);
-		memcpy(dbuf, ti->buffer + p,
-		    (sb - p) * sizeof(wchar_t));
-		dbuf[sb - p] = '\0';
-		printf("%ls", dbuf);
-		p = sb;
-	}
-
-	fflush(stdout);
-	console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
-
-	if (p < ti->nc) {
-		memcpy(dbuf, ti->buffer + p,
-		    (ti->nc - p) * sizeof(wchar_t));
-		dbuf[ti->nc - p] = '\0';
-		printf("%ls", dbuf);
-	}
-
-	for (i = 0; i < pad; ++i)
-		putchar(' ');
-	fflush(stdout);
-}
-
-static char *tinput_get_str(tinput_t *ti)
-{
-	return wstr_to_astr(ti->buffer);
-}
-
-static void tinput_position_caret(tinput_t *ti)
-{
-	console_goto(fphone(stdout), (ti->col0 + ti->pos) % ti->con_cols,
-	    ti->row0 + (ti->col0 + ti->pos) / ti->con_cols);
-}
-
-/** Update row0 in case the screen could have scrolled. */
-static void tinput_update_origin(tinput_t *ti)
-{
-	int width, rows;
-
-	width = ti->col0 + ti->nc;
-	rows = (width / ti->con_cols) + 1;
-
-	/* Update row0 if the screen scrolled. */
-	if (ti->row0 + rows > ti->con_rows)
-		ti->row0 = ti->con_rows - rows;	
-}
-
-static void tinput_insert_char(tinput_t *ti, wchar_t c)
-{
-	int i;
-	int new_width, new_height;
-
-	if (ti->nc == INPUT_MAX)
-		return;
-
-	new_width = ti->col0 + ti->nc + 1;
-	if (new_width % ti->con_cols == 0) {
-		/* Advancing to new line. */
-		new_height = (new_width / ti->con_cols) + 1;
-		if (new_height >= ti->con_rows)
-			return; /* Disallow text longer than 1 page for now. */
-	}
-
-	for (i = ti->nc; i > ti->pos; --i)
-		ti->buffer[i] = ti->buffer[i - 1];
-
-	ti->buffer[ti->pos] = c;
-	ti->pos += 1;
-	ti->nc += 1;
-	ti->buffer[ti->nc] = '\0';
-	ti->sel_start = ti->pos;
-
-	tinput_display_tail(ti, ti->pos - 1, 0);
-	tinput_update_origin(ti);
-	tinput_position_caret(ti);
-}
-
-static void tinput_insert_string(tinput_t *ti, const char *str)
-{
-	int i;
-	int new_width, new_height;
-	int ilen;
-	wchar_t c;
-	size_t off;
-
-	ilen = min((ssize_t) str_length(str), INPUT_MAX - ti->nc);
-	if (ilen == 0)
-		return;
-
-	new_width = ti->col0 + ti->nc + ilen;
-	new_height = (new_width / ti->con_cols) + 1;
-	if (new_height >= ti->con_rows)
-		return; /* Disallow text longer than 1 page for now. */
-
-	for (i = ti->nc - 1; i >= ti->pos; --i)
-		ti->buffer[i + ilen] = ti->buffer[i];
-
-	off = 0; i = 0;
-	while (i < ilen) {
-		c = str_decode(str, &off, STR_NO_LIMIT);
-		if (c == '\0')
-			break;
-
-		/* Filter out non-printable chars. */
-		if (c < 32)
-			c = 32;
-
-		ti->buffer[ti->pos + i] = c;
-		++i;
-	}
-
-	ti->pos += ilen;
-	ti->nc += ilen;
-	ti->buffer[ti->nc] = '\0';
-	ti->sel_start = ti->pos;
-
-	tinput_display_tail(ti, ti->pos - ilen, 0);
-	tinput_update_origin(ti);
-	tinput_position_caret(ti);
-}
-
-static void tinput_backspace(tinput_t *ti)
-{
-	int i;
-
-	if (tinput_sel_active(ti)) {
-		tinput_sel_delete(ti);
-		return;
-	}
-
-	if (ti->pos == 0)
-		return;
-
-	for (i = ti->pos; i < ti->nc; ++i)
-		ti->buffer[i - 1] = ti->buffer[i];
-	ti->pos -= 1;
-	ti->nc -= 1;
-	ti->buffer[ti->nc] = '\0';
-	ti->sel_start = ti->pos;
-
-	tinput_display_tail(ti, ti->pos, 1);
-	tinput_position_caret(ti);
-}
-
-static void tinput_delete(tinput_t *ti)
-{
-	if (tinput_sel_active(ti)) {
-		tinput_sel_delete(ti);
-		return;
-	}
-
-	if (ti->pos == ti->nc)
-		return;
-
-	ti->pos += 1;
-	ti->sel_start = ti->pos;
-
-	tinput_backspace(ti);
-}
-
-static void tinput_seek_cell(tinput_t *ti, seek_dir_t dir, bool shift_held)
-{
-	tinput_pre_seek(ti, shift_held);
-
-	if (dir == seek_forward) {
-		if (ti->pos < ti->nc)
-			ti->pos += 1;
-	} else {
-		if (ti->pos > 0)
-			ti->pos -= 1;
-	}
-
-	tinput_post_seek(ti, shift_held);
-}
-
-static void tinput_seek_word(tinput_t *ti, seek_dir_t dir, bool shift_held)
-{
-	tinput_pre_seek(ti, shift_held);
-
-	if (dir == seek_forward) {
-		if (ti->pos == ti->nc)
-			return;
-
-		while (1) {
-			ti->pos += 1;
-
-			if (ti->pos == ti->nc)
-				break;
-
-			if (ti->buffer[ti->pos - 1] == ' ' &&
-			    ti->buffer[ti->pos] != ' ')
-				break;
-		}
-	} else {
-		if (ti->pos == 0)
-			return;
-
-		while (1) {
-			ti->pos -= 1;
-
-			if (ti->pos == 0)
-				break;
-
-			if (ti->buffer[ti->pos - 1] == ' ' &&
-			    ti->buffer[ti->pos] != ' ')
-				break;
-		}
-
-	}
-
-	tinput_post_seek(ti, shift_held);
-}
-
-static void tinput_seek_vertical(tinput_t *ti, seek_dir_t dir, bool shift_held)
-{
-	tinput_pre_seek(ti, shift_held);
-
-	if (dir == seek_forward) {
-		if (ti->pos + ti->con_cols <= ti->nc)
-			ti->pos = ti->pos + ti->con_cols;
-	} else {
-		if (ti->pos - ti->con_cols >= 0)
-			ti->pos = ti->pos - ti->con_cols;
-	}
-
-	tinput_post_seek(ti, shift_held);
-}
-
-static void tinput_seek_max(tinput_t *ti, seek_dir_t dir, bool shift_held)
-{
-	tinput_pre_seek(ti, shift_held);
-
-	if (dir == seek_backward)
-		ti->pos = 0;
-	else
-		ti->pos = ti->nc;
-
-	tinput_post_seek(ti, shift_held);
-}
-
-static void tinput_pre_seek(tinput_t *ti, bool shift_held)
-{
-	if (tinput_sel_active(ti) && !shift_held) {
-		/* Unselect and redraw. */
-		ti->sel_start = ti->pos;
-		tinput_display_tail(ti, 0, 0);
-		tinput_position_caret(ti);
-	}
-}
-
-static void tinput_post_seek(tinput_t *ti, bool shift_held)
-{
-	if (shift_held) {
-		/* Selecting text. Need redraw. */
-		tinput_display_tail(ti, 0, 0);
-	} else {
-		/* Shift not held. Keep selection empty. */
-		ti->sel_start = ti->pos;
-	}
-	tinput_position_caret(ti);
-}
-
-static void tinput_history_insert(tinput_t *ti, char *str)
-{
-	int i;
-
-	if (ti->hnum < HISTORY_LEN) {
-		ti->hnum += 1;
-	} else {
-		if (ti->history[HISTORY_LEN] != NULL)
-			free(ti->history[HISTORY_LEN]);
-	}
-
-	for (i = ti->hnum; i > 1; --i)
-		ti->history[i] = ti->history[i - 1];
-
-	ti->history[1] = str_dup(str);
-
-	if (ti->history[0] != NULL) {
-		free(ti->history[0]);
-		ti->history[0] = NULL;
-	}
-}
-
-static void tinput_set_str(tinput_t *ti, char *str)
-{
-	str_to_wstr(ti->buffer, INPUT_MAX, str);
-	ti->nc = wstr_length(ti->buffer);
-	ti->pos = ti->nc;
-	ti->sel_start = ti->pos;
-}
-
-static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb)
-{
-	if (ti->sel_start < ti->pos) {
-		*sa = ti->sel_start;
-		*sb = ti->pos;
-	} else {
-		*sa = ti->pos;
-		*sb = ti->sel_start;
-	}
-}
-
-static bool tinput_sel_active(tinput_t *ti)
-{
-	return ti->sel_start != ti->pos;
-}
-
-static void tinput_sel_all(tinput_t *ti)
-{
-	ti->sel_start = 0;
-	ti->pos = ti->nc;
-	tinput_display_tail(ti, 0, 0);
-	tinput_position_caret(ti);
-}
-
-static void tinput_sel_delete(tinput_t *ti)
-{
-	int sa, sb;
-
-	tinput_sel_get_bounds(ti, &sa, &sb);
-	if (sa == sb)
-		return;
-
-	memmove(ti->buffer + sa, ti->buffer + sb,
-	    (ti->nc - sb) * sizeof(wchar_t));
-	ti->pos = ti->sel_start = sa;
-	ti->nc -= (sb - sa);
-	ti->buffer[ti->nc] = '\0';
-
-	tinput_display_tail(ti, sa, sb - sa);
-	tinput_position_caret(ti);
-}
-
-static void tinput_sel_copy_to_cb(tinput_t *ti)
-{
-	int sa, sb;
-	char *str;
-
-	tinput_sel_get_bounds(ti, &sa, &sb);
-
-	if (sb < ti->nc) {
-		wchar_t tmp_c = ti->buffer[sb];
-		ti->buffer[sb] = '\0';
-		str = wstr_to_astr(ti->buffer + sa);
-		ti->buffer[sb] = tmp_c;
-	} else
-		str = wstr_to_astr(ti->buffer + sa);
-	
-	if (str == NULL)
-		goto error;
-
-	if (clipboard_put_str(str) != EOK)
-		goto error;
-
-	free(str);
-	return;
-error:
-	return;
-	/* TODO: Give the user some warning. */
-}
-
-static void tinput_paste_from_cb(tinput_t *ti)
+void get_input(cliuser_t *usr)
 {
 	char *str;
 	int rc;
-
-	rc = clipboard_get_str(&str);
-	if (rc != EOK || str == NULL)
-		return; /* TODO: Give the user some warning. */
-
-	tinput_insert_string(ti, str);
-	free(str);
-}
-
-static void tinput_history_seek(tinput_t *ti, int offs)
-{
-	int pad;
-
-	if (ti->hpos + offs < 0 || ti->hpos + offs > ti->hnum)
-		return;
-
-	if (ti->history[ti->hpos] != NULL) {
-		free(ti->history[ti->hpos]);
-		ti->history[ti->hpos] = NULL;
-	}
-
-	ti->history[ti->hpos] = tinput_get_str(ti);
-	ti->hpos += offs;
-
-	pad = ti->nc - str_length(ti->history[ti->hpos]);
-	if (pad < 0) pad = 0;
-
-	tinput_set_str(ti, ti->history[ti->hpos]);
-	tinput_display_tail(ti, 0, pad);
-	tinput_update_origin(ti);
-	tinput_position_caret(ti);
-}
-
-/** Initialize text input field.
- *
- * Must be called before using the field. It clears the history.
- */
-static void tinput_init(tinput_t *ti)
-{
-	ti->hnum = 0;
-	ti->hpos = 0;
-	ti->history[0] = NULL;
-}
-
-/** Read in one line of input. */
-static char *tinput_read(tinput_t *ti)
-{
-	console_event_t ev;
-	char *str;
-
-	fflush(stdout);
-
-	if (console_get_size(fphone(stdin), &ti->con_cols, &ti->con_rows) != EOK)
-		return NULL;
-	if (console_get_pos(fphone(stdin), &ti->col0, &ti->row0) != EOK)
-		return NULL;
-
-	ti->pos = ti->sel_start = 0;
-	ti->nc = 0;
-	ti->buffer[0] = '\0';
-	ti->done = false;
-
-	while (!ti->done) {
-		fflush(stdout);
-		if (!console_get_event(fphone(stdin), &ev))
-			return NULL;
-
-		if (ev.type != KEY_PRESS)
-			continue;
-
-		if ((ev.mods & KM_CTRL) != 0 &&
-		    (ev.mods & (KM_ALT | KM_SHIFT)) == 0) {
-			tinput_key_ctrl(ti, &ev);
-		}
-
-		if ((ev.mods & KM_SHIFT) != 0 &&
-		    (ev.mods & (KM_CTRL | KM_ALT)) == 0) {
-			tinput_key_shift(ti, &ev);
-		}
-
-		if ((ev.mods & KM_CTRL) != 0 &&
-		    (ev.mods & KM_SHIFT) != 0 &&
-		    (ev.mods & KM_ALT) == 0) {
-			tinput_key_ctrl_shift(ti, &ev);
-		}
-
-		if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {
-			tinput_key_unmod(ti, &ev);
-		}
-
-		if (ev.c >= ' ') {
-			tinput_sel_delete(ti);
-			tinput_insert_char(ti, ev.c);
-		}
-	}
-
-	ti->pos = ti->nc;
-	tinput_position_caret(ti);
-	putchar('\n');
-
-	str = tinput_get_str(ti);
-	if (str_cmp(str, "") != 0)
-		tinput_history_insert(ti, str);
-
-	ti->hpos = 0;
-
-	return str;
-}
-
-static void tinput_key_ctrl(tinput_t *ti, console_event_t *ev)
-{
-	switch (ev->key) {
-	case KC_LEFT:
-		tinput_seek_word(ti, seek_backward, false);
-		break;
-	case KC_RIGHT:
-		tinput_seek_word(ti, seek_forward, false);
-		break;
-	case KC_UP:
-		tinput_seek_vertical(ti, seek_backward, false);
-		break;
-	case KC_DOWN:
-		tinput_seek_vertical(ti, seek_forward, false);
-		break;
-	case KC_X:
-		tinput_sel_copy_to_cb(ti);
-		tinput_sel_delete(ti);
-		break;
-	case KC_C:
-		tinput_sel_copy_to_cb(ti);
-		break;
-	case KC_V:
-		tinput_sel_delete(ti);
-		tinput_paste_from_cb(ti);
-		break;
-	case KC_A:
-		tinput_sel_all(ti);
-		break;
-	default:
-		break;
-	}
-}
-
-static void tinput_key_ctrl_shift(tinput_t *ti, console_event_t *ev)
-{
-	switch (ev->key) {
-	case KC_LEFT:
-		tinput_seek_word(ti, seek_backward, true);
-		break;
-	case KC_RIGHT:
-		tinput_seek_word(ti, seek_forward, true);
-		break;
-	case KC_UP:
-		tinput_seek_vertical(ti, seek_backward, true);
-		break;
-	case KC_DOWN:
-		tinput_seek_vertical(ti, seek_forward, true);
-		break;
-	default:
-		break;
-	}
-}
-
-static void tinput_key_shift(tinput_t *ti, console_event_t *ev)
-{
-	switch (ev->key) {
-	case KC_LEFT:
-		tinput_seek_cell(ti, seek_backward, true);
-		break;
-	case KC_RIGHT:
-		tinput_seek_cell(ti, seek_forward, true);
-		break;
-	case KC_UP:
-		tinput_seek_vertical(ti, seek_backward, true);
-		break;
-	case KC_DOWN:
-		tinput_seek_vertical(ti, seek_forward, true);
-		break;
-	case KC_HOME:
-		tinput_seek_max(ti, seek_backward, true);
-		break;
-	case KC_END:
-		tinput_seek_max(ti, seek_forward, true);
-		break;
-	default:
-		break;
-	}
-}
-
-static void tinput_key_unmod(tinput_t *ti, console_event_t *ev)
-{
-	switch (ev->key) {
-	case KC_ENTER:
-	case KC_NENTER:
-		ti->done = true;
-		break;
-	case KC_BACKSPACE:
-		tinput_backspace(ti);
-		break;
-	case KC_DELETE:
-		tinput_delete(ti);
-		break;
-	case KC_LEFT:
-		tinput_seek_cell(ti, seek_backward, false);
-		break;
-	case KC_RIGHT:
-		tinput_seek_cell(ti, seek_forward, false);
-		break;
-	case KC_HOME:
-		tinput_seek_max(ti, seek_backward, false);
-		break;
-	case KC_END:
-		tinput_seek_max(ti, seek_forward, false);
-		break;
-	case KC_UP:
-		tinput_history_seek(ti, +1);
-		break;
-	case KC_DOWN:
-		tinput_history_seek(ti, -1);
-		break;
-	default:
-		break;
-	}
-}
-
-void get_input(cliuser_t *usr)
-{
-	char *str;
 
 	fflush(stdout);
@@ -772,5 +117,16 @@
 	console_set_style(fphone(stdout), STYLE_NORMAL);
 
-	str = tinput_read(&tinput);
+	rc = tinput_read(tinput, &str);
+	if (rc == ENOENT) {
+		/* User requested exit */
+		cli_quit = 1;
+		putchar('\n');
+		return;
+	}
+
+	if (rc != EOK) {
+		/* Error in communication with console */
+		return;
+	}
 
 	/* Check for empty input. */
@@ -784,6 +140,12 @@
 }
 
-void input_init(void)
+int input_init(void)
 {
-	tinput_init(&tinput);
+	tinput = tinput_new();
+	if (tinput == NULL) {
+		printf("Failed to initialize input.\n");
+		return 1;
+	}
+
+	return 0;
 }
Index: uspace/app/bdsh/input.h
===================================================================
--- uspace/app/bdsh/input.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/app/bdsh/input.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -8,5 +8,5 @@
 extern void get_input(cliuser_t *);
 extern int tok_input(cliuser_t *);
-extern void input_init(void);
+extern int input_init(void);
 
 #endif
Index: uspace/app/bdsh/scli.c
===================================================================
--- uspace/app/bdsh/scli.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/app/bdsh/scli.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -65,5 +65,6 @@
 	usr->lasterr = 0;
 
-	input_init();
+	if (input_init() != 0)
+		return 1;
 
 	return (int) cli_set_prompt(usr);
@@ -99,7 +100,7 @@
 		}
 	}
-	goto finit;
 
-finit:
+	printf("Leaving %s.\n", progname);
+
 	cli_finit(&usr);
 	return ret;
Index: uspace/app/bdsh/scli.h
===================================================================
--- uspace/app/bdsh/scli.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/app/bdsh/scli.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -13,3 +13,5 @@
 } cliuser_t;
 
+extern const char *progname;
+
 #endif
Index: uspace/app/getterm/getterm.c
===================================================================
--- uspace/app/getterm/getterm.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/app/getterm/getterm.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -40,9 +40,12 @@
 #include <stdio.h>
 #include <task.h>
+#include <str_error.h>
 #include "version.h"
+
+#define APP_NAME  "getterm"
 
 static void usage(void)
 {
-	printf("Usage: getterm <terminal> <path>\n");
+	printf("Usage: %s <terminal> <path>\n", APP_NAME);
 }
 
@@ -76,8 +79,10 @@
 	args[1] = NULL;
 	
-	task_id_t id = task_spawn(fname, args);
+	int err;
+	task_id_t id = task_spawn(fname, args, &err);
 	
 	if (id == 0)
-		printf("Error spawning %s\n", fname);
+		printf("%s: Error spawning %s (%s)\n", APP_NAME, fname,
+		    str_error(err));
 	
 	return id;
Index: uspace/app/init/init.c
===================================================================
--- uspace/app/init/init.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/app/init/init.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -48,7 +48,19 @@
 #include <str.h>
 #include <devmap.h>
+#include <str_error.h>
 #include "init.h"
 
+#define ROOT_DEVICE       "bd/initrd"
+#define ROOT_MOUNT_POINT  "/"
+
+#define DEVFS_FS_TYPE      "devfs"
 #define DEVFS_MOUNT_POINT  "/dev"
+
+#define SCRATCH_FS_TYPE      "tmpfs"
+#define SCRATCH_MOUNT_POINT  "/scratch"
+
+#define DATA_FS_TYPE      "fat"
+#define DATA_DEVICE       "bd/disk0"
+#define DATA_MOUNT_POINT  "/data"
 
 #define SRV_CONSOLE  "/srv/console"
@@ -57,5 +69,34 @@
 static void info_print(void)
 {
-	printf(NAME ": HelenOS init\n");
+	printf("%s: HelenOS init\n", NAME);
+}
+
+static bool mount_report(const char *desc, const char *mntpt,
+    const char *fstype, const char *dev, int rc)
+{
+	switch (rc) {
+	case EOK:
+		if (dev != NULL)
+			printf("%s: %s mounted on %s (%s at %s)\n", NAME, desc, mntpt,
+			    fstype, dev);
+		else
+			printf("%s: %s mounted on %s (%s)\n", NAME, desc, mntpt, fstype);
+		break;
+	case EBUSY:
+		printf("%s: %s already mounted on %s\n", NAME, desc, mntpt);
+		return false;
+	case ELIMIT:
+		printf("%s: %s limit exceeded\n", NAME, desc);
+		return false;
+	case ENOENT:
+		printf("%s: %s unknown type (%s)\n", NAME, desc, fstype);
+		return false;
+	default:
+		printf("%s: %s not mounted on %s (%s)\n", NAME, desc, mntpt,
+		    str_error(rc));
+		return false;
+	}
+	
+	return true;
 }
 
@@ -63,56 +104,20 @@
 {
 	const char *opts = "";
-	const char *root_dev = "bd/initrd";
 	
 	if (str_cmp(fstype, "tmpfs") == 0)
 		opts = "restore";
 	
-	int rc = mount(fstype, "/", root_dev, opts, IPC_FLAG_BLOCKING);
-	
-	switch (rc) {
-	case EOK:
-		printf(NAME ": Root filesystem mounted, %s at %s\n",
-		    fstype, root_dev);
-		break;
-	case EBUSY:
-		printf(NAME ": Root filesystem already mounted\n");
-		return false;
-	case ELIMIT:
-		printf(NAME ": Unable to mount root filesystem\n");
-		return false;
-	case ENOENT:
-		printf(NAME ": Unknown filesystem type (%s)\n", fstype);
-		return false;
-	default:
-		printf(NAME ": Error mounting root filesystem (%d)\n", rc);
-		return false;
-	}
-	
-	return true;
+	int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
+	    IPC_FLAG_BLOCKING);
+	return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
+	    ROOT_DEVICE, rc);
 }
 
 static bool mount_devfs(void)
 {
-	int rc = mount("devfs", DEVFS_MOUNT_POINT, "", "", IPC_FLAG_BLOCKING);
-	
-	switch (rc) {
-	case EOK:
-		printf(NAME ": Device filesystem mounted\n");
-		break;
-	case EBUSY:
-		printf(NAME ": Device filesystem already mounted\n");
-		return false;
-	case ELIMIT:
-		printf(NAME ": Unable to mount device filesystem\n");
-		return false;
-	case ENOENT:
-		printf(NAME ": Unknown filesystem type (devfs)\n");
-		return false;
-	default:
-		printf(NAME ": Error mounting device filesystem (%d)\n", rc);
-		return false;
-	}
-	
-	return true;
+	int rc = mount(DEVFS_FS_TYPE, DEVFS_MOUNT_POINT, "", "",
+	    IPC_FLAG_BLOCKING);
+	return mount_report("Device filesystem", DEVFS_MOUNT_POINT, DEVFS_FS_TYPE,
+	    NULL, rc);
 }
 
@@ -125,11 +130,13 @@
 		return;
 	
-	printf(NAME ": Spawning %s\n", fname);
+	printf("%s: Spawning %s\n", NAME, fname);
 	
 	argv[0] = fname;
 	argv[1] = NULL;
 	
-	if (!task_spawn(fname, argv))
-		printf(NAME ": Error spawning %s\n", fname);
+	int err;
+	if (!task_spawn(fname, argv, &err))
+		printf("%s: Error spawning %s (%s)\n", NAME, fname,
+		    str_error(err));
 }
 
@@ -145,24 +152,26 @@
 		return;
 	
-	printf(NAME ": Starting %s\n", fname);
+	printf("%s: Starting %s\n", NAME, fname);
 	
 	argv[0] = fname;
 	argv[1] = NULL;
 	
-	id = task_spawn(fname, argv);
+	id = task_spawn(fname, argv, &retval);
 	if (!id) {
-		printf(NAME ": Error spawning %s\n", fname);
+		printf("%s: Error spawning %s (%s)\n", NAME, fname,
+		    str_error(retval));
 		return;
 	}
-
+	
 	rc = task_wait(id, &texit, &retval);
 	if (rc != EOK) {
-		printf(NAME ": Error waiting for %s\n", fname);
+		printf("%s: Error waiting for %s (%s(\n", NAME, fname,
+		    str_error(retval));
 		return;
 	}
-
+	
 	if ((texit != TASK_EXIT_NORMAL) || (retval != 0)) {
-		printf(NAME ": Server %s failed to start (returned %d)\n",
-			fname, retval);
+		printf("%s: Server %s failed to start (%s)\n", NAME,
+			fname, str_error(retval));
 	}
 }
@@ -176,5 +185,5 @@
 	snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
 	
-	printf(NAME ": Spawning %s with %s\n", SRV_CONSOLE, hid_in);
+	printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in);
 	
 	/* Wait for the input device to be ready */
@@ -187,8 +196,10 @@
 		argv[2] = NULL;
 		
-		if (!task_spawn(SRV_CONSOLE, argv))
-			printf(NAME ": Error spawning %s with %s\n", SRV_CONSOLE, hid_in);
+		if (!task_spawn(SRV_CONSOLE, argv, &rc))
+			printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE,
+			    hid_in, str_error(rc));
 	} else
-		printf(NAME ": Error waiting on %s\n", hid_in);
+		printf("%s: Error waiting on %s (%s)\n", NAME, hid_in,
+		    str_error(rc));
 }
 
@@ -201,5 +212,5 @@
 	snprintf(term, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev);
 	
-	printf(NAME ": Spawning %s with %s %s\n", APP_GETTERM, term, app);
+	printf("%s: Spawning %s %s %s\n", NAME, APP_GETTERM, term, app);
 	
 	/* Wait for the terminal device to be ready */
@@ -213,37 +224,24 @@
 		argv[3] = NULL;
 		
-		if (!task_spawn(APP_GETTERM, argv))
-			printf(NAME ": Error spawning %s with %s %s\n", APP_GETTERM,
-			    term, app);
+		if (!task_spawn(APP_GETTERM, argv, &rc))
+			printf("%s: Error spawning %s %s %s (%s)\n", NAME, APP_GETTERM,
+			    term, app, str_error(rc));
 	} else
-		printf(NAME ": Error waiting on %s\n", term);
-}
-
-static void mount_scratch(void)
-{
-	int rc;
-
-	printf("Trying to mount null/0 on /scratch... ");
-	fflush(stdout);
-
-	rc = mount("tmpfs", "/scratch", "null/0", "", 0);
-	if (rc == EOK)
-		printf("OK\n");
-	else
-		printf("Failed\n");
-}
-
-static void mount_data(void)
-{
-	int rc;
-
-	printf("Trying to mount bd/disk0 on /data... ");
-	fflush(stdout);
-
-	rc = mount("fat", "/data", "bd/disk0", "wtcache", 0);
-	if (rc == EOK)
-		printf("OK\n");
-	else
-		printf("Failed\n");
+		printf("%s: Error waiting on %s (%s)\n", NAME, term,
+		    str_error(rc));
+}
+
+static bool mount_scratch(void)
+{
+	int rc = mount(SCRATCH_FS_TYPE, SCRATCH_MOUNT_POINT, "", "", 0);
+	return mount_report("Scratch filesystem", SCRATCH_MOUNT_POINT,
+	    SCRATCH_FS_TYPE, NULL, rc);
+}
+
+static bool mount_data(void)
+{
+	int rc = mount(DATA_FS_TYPE, DATA_MOUNT_POINT, DATA_DEVICE, "wtcache", 0);
+	return mount_report("Data filesystem", DATA_MOUNT_POINT, DATA_FS_TYPE,
+	    DATA_DEVICE, rc);
 }
 
@@ -253,8 +251,8 @@
 	
 	if (!mount_root(STRING(RDFMT))) {
-		printf(NAME ": Exiting\n");
+		printf("%s: Exiting\n", NAME);
 		return -1;
 	}
-
+	
 	/* Make sure tmpfs is running. */
 	if (str_cmp(STRING(RDFMT), "tmpfs") != 0) {
@@ -266,8 +264,8 @@
 	
 	if (!mount_devfs()) {
-		printf(NAME ": Exiting\n");
+		printf("%s: Exiting\n", NAME);
 		return -2;
 	}
-
+	
 	mount_scratch();
 	
@@ -278,5 +276,5 @@
 	srv_start("/srv/adb_ms");
 	srv_start("/srv/char_ms");
-
+	
 	spawn("/srv/fb");
 	spawn("/srv/kbd");
@@ -284,5 +282,5 @@
 	
 	spawn("/srv/clip");
-
+	
 	/*
 	 * Start these synchronously so that mount_data() can be
@@ -295,5 +293,5 @@
 	(void) srv_start;
 #endif
-
+	
 #ifdef CONFIG_MOUNT_DATA
 	mount_data();
@@ -301,5 +299,5 @@
 	(void) mount_data;
 #endif
-
+	
 	getterm("term/vc0", "/app/bdsh");
 	getterm("term/vc1", "/app/bdsh");
@@ -309,5 +307,5 @@
 	getterm("term/vc5", "/app/bdsh");
 	getterm("term/vc6", "/app/klog");
-
+	
 	return 0;
 }
Index: uspace/app/klog/klog.c
===================================================================
--- uspace/app/klog/klog.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/app/klog/klog.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -64,5 +64,10 @@
 int main(int argc, char *argv[])
 {
-	size_t klog_pages = sysinfo_value("klog.pages");
+	size_t klog_pages;
+	if (sysinfo_get_value("klog.pages", &klog_pages) != EOK) {
+		printf("%s: Error getting klog address\n", NAME);
+		return -1;
+	}
+	
 	size_t klog_size = klog_pages * PAGE_SIZE;
 	klog_length = klog_size / sizeof(wchar_t);
@@ -70,5 +75,5 @@
 	klog = (wchar_t *) as_get_mappable_page(klog_size);
 	if (klog == NULL) {
-		printf(NAME ": Error allocating memory area\n");
+		printf("%s: Error allocating memory area\n", NAME);
 		return -1;
 	}
@@ -77,10 +82,10 @@
 	    klog_size, SERVICE_MEM_KLOG);
 	if (res != EOK) {
-		printf(NAME ": Error initializing memory area\n");
+		printf("%s: Error initializing memory area\n", NAME);
 		return -1;
 	}
 	
 	if (event_subscribe(EVENT_KLOG, 0) != EOK) {
-		printf(NAME ": Error registering klog notifications\n");
+		printf("%s: Error registering klog notifications\n", NAME);
 		return -1;
 	}
Index: uspace/app/netecho/Makefile
===================================================================
--- uspace/app/netecho/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/netecho/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,39 @@
+#
+# Copyright (c) 2005 Martin Decky
+# Copyright (c) 2007 Jakub Jermar
+# 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.
+#
+
+USPACE_PREFIX = ../..
+LIBS = $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBSOCKET_PREFIX)/include
+BINARY = netecho
+
+SOURCES = \
+	netecho.c \
+	print_error.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/netecho/netecho.c
===================================================================
--- uspace/app/netecho/netecho.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/netecho/netecho.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,368 @@
+/*
+ * 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 netecho
+ *  @{
+ */
+
+/** @file
+ *  Network echo application.
+ *  Answers received packets.
+ */
+
+#include <malloc.h>
+#include <stdio.h>
+#include <str.h>
+#include <task.h>
+#include <arg_parse.h>
+
+#include <in.h>
+#include <in6.h>
+#include <inet.h>
+#include <socket.h>
+#include <net_err.h>
+#include <socket_parse.h>
+
+#include "print_error.h"
+
+/** Network echo module name.
+ */
+#define NAME	"Network Echo"
+
+/** Prints the application help.
+ */
+void echo_print_help(void);
+
+/** Module entry point.
+ *  Reads command line parameters and starts listenning.
+ *  @param[in] argc The number of command line parameters.
+ *  @param[in] argv The command line parameters.
+ *  @returns EOK on success.
+ */
+int main(int argc, char * argv[]);
+
+void echo_print_help(void){
+	printf(
+		"Network Echo aplication\n" \
+		"Usage: echo [options]\n" \
+		"Where options are:\n" \
+		"-b backlog | --backlog=size\n" \
+		"\tThe size of the accepted sockets queue. Only for SOCK_STREAM. The default is 3.\n" \
+		"\n" \
+		"-c count | --count=count\n" \
+		"\tThe number of received messages to handle. A negative number means infinity. The default is infinity.\n" \
+		"\n" \
+		"-f protocol_family | --family=protocol_family\n" \
+		"\tThe listenning socket protocol family. Only the PF_INET and PF_INET6 are supported.\n"
+		"\n" \
+		"-h | --help\n" \
+		"\tShow this application help.\n"
+		"\n" \
+		"-p port_number | --port=port_number\n" \
+		"\tThe port number the application should listen at. The default is 7.\n" \
+		"\n" \
+		"-r reply_string | --reply=reply_string\n" \
+		"\tThe constant reply string. The default is the original data received.\n" \
+		"\n" \
+		"-s receive_size | --size=receive_size\n" \
+		"\tThe maximum receive data size the application should accept. The default is 1024 bytes.\n" \
+		"\n" \
+		"-t socket_type | --type=socket_type\n" \
+		"\tThe listenning socket type. Only the SOCK_DGRAM and the SOCK_STREAM are supported.\n" \
+		"\n" \
+		"-v | --verbose\n" \
+		"\tShow all output messages.\n"
+	);
+}
+
+int main(int argc, char * argv[]){
+	ERROR_DECLARE;
+
+	size_t size			= 1024;
+	int verbose			= 0;
+	char * reply		= NULL;
+	sock_type_t type	= SOCK_DGRAM;
+	int count			= -1;
+	int family			= PF_INET;
+	uint16_t port		= 7;
+	int backlog			= 3;
+
+	socklen_t max_length				= sizeof(struct sockaddr_in6);
+	uint8_t address_data[max_length];
+	struct sockaddr * address			= (struct sockaddr *) address_data;
+	struct sockaddr_in * address_in		= (struct sockaddr_in *) address;
+	struct sockaddr_in6 * address_in6	= (struct sockaddr_in6 *) address;
+	socklen_t addrlen;
+	char address_string[INET6_ADDRSTRLEN];
+	uint8_t * address_start;
+	int socket_id;
+	int listening_id;
+	char * data;
+	size_t length;
+	int index;
+	size_t reply_length;
+	int value;
+
+	// parse the command line arguments
+	for(index = 1; index < argc; ++ index){
+		if(argv[index][0] == '-'){
+			switch(argv[index][1]){
+				case 'b':
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 0));
+					break;
+				case 'c':
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 0));
+					break;
+				case 'f':
+					ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family));
+					break;
+				case 'h':
+					echo_print_help();
+					return EOK;
+					break;
+				case 'p':
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
+					port = (uint16_t) value;
+					break;
+				case 'r':
+					ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 0));
+					break;
+				case 's':
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
+					size = (value >= 0) ? (size_t) value : 0;
+					break;
+				case 't':
+					ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type));
+					type = (sock_type_t) value;
+					break;
+				case 'v':
+					verbose = 1;
+					break;
+				// long options with the double minus sign ('-')
+				case '-':
+					if(str_lcmp(argv[index] + 2, "backlog=", 6) == 0){
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &backlog, 8));
+					}else if(str_lcmp(argv[index] + 2, "count=", 6) == 0){
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &count, 8));
+					}else if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
+						ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family));
+					}else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
+						echo_print_help();
+						return EOK;
+					}else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
+						port = (uint16_t) value;
+					}else if(str_lcmp(argv[index] + 2, "reply=", 6) == 0){
+						ERROR_PROPAGATE(arg_parse_string(argc, argv, &index, &reply, 8));
+					}else if(str_lcmp(argv[index] + 2, "size=", 5) == 0){
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
+						size = (value >= 0) ? (size_t) value : 0;
+					}else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
+						ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type));
+						type = (sock_type_t) value;
+					}else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
+						verbose = 1;
+					}else{
+						echo_print_help();
+						return EINVAL;
+					}
+					break;
+				default:
+					echo_print_help();
+					return EINVAL;
+			}
+		}else{
+			echo_print_help();
+			return EINVAL;
+		}
+	}
+
+	// check the buffer size
+	if(size <= 0){
+		fprintf(stderr, "Receive size too small (%d). Using 1024 bytes instead.\n", size);
+		size = 1024;
+	}
+	// size plus the terminating null (\0)
+	data = (char *) malloc(size + 1);
+	if(! data){
+		fprintf(stderr, "Failed to allocate receive buffer.\n");
+		return ENOMEM;
+	}
+
+	// set the reply size if set
+	reply_length = reply ? str_length(reply) : 0;
+
+	// prepare the address buffer
+	bzero(address_data, max_length);
+	switch(family){
+		case PF_INET:
+			address_in->sin_family = AF_INET;
+			address_in->sin_port = htons(port);
+			addrlen = sizeof(struct sockaddr_in);
+			break;
+		case PF_INET6:
+			address_in6->sin6_family = AF_INET6;
+			address_in6->sin6_port = htons(port);
+			addrlen = sizeof(struct sockaddr_in6);
+			break;
+		default:
+			fprintf(stderr, "Protocol family is not supported\n");
+			return EAFNOSUPPORT;
+	}
+
+	// get a listening socket
+	listening_id = socket(family, type, 0);
+	if(listening_id < 0){
+		socket_print_error(stderr, listening_id, "Socket create: ", "\n");
+		return listening_id;
+	}
+
+	// if the stream socket is used
+	if(type == SOCK_STREAM){
+		// check the backlog
+		if(backlog <= 0){
+			fprintf(stderr, "Accepted sockets queue size too small (%d). Using 3 instead.\n", size);
+			backlog = 3;
+		}
+		// set the backlog
+		if(ERROR_OCCURRED(listen(listening_id, backlog))){
+			socket_print_error(stderr, ERROR_CODE, "Socket listen: ", "\n");
+			return ERROR_CODE;
+		}
+	}
+
+	// bind the listenning socket
+	if(ERROR_OCCURRED(bind(listening_id, address, addrlen))){
+		socket_print_error(stderr, ERROR_CODE, "Socket bind: ", "\n");
+		return ERROR_CODE;
+	}
+
+	if(verbose){
+		printf("Socket %d listenning at %d\n", listening_id, port);
+	}
+
+	socket_id = listening_id;
+
+	// do count times
+	// or indefinitely if set to a negative value
+	while(count){
+
+		addrlen = max_length;
+		if(type == SOCK_STREAM){
+			// acceept a socket if the stream socket is used
+			socket_id = accept(listening_id, address, &addrlen);
+			if(socket_id <= 0){
+				socket_print_error(stderr, socket_id, "Socket accept: ", "\n");
+			}else{
+				if(verbose){
+					printf("Socket %d accepted\n", socket_id);
+				}
+			}
+		}
+
+		// if the datagram socket is used or the stream socked was accepted
+		if(socket_id > 0){
+
+			// receive an echo request
+			value = recvfrom(socket_id, data, size, 0, address, &addrlen);
+			if(value < 0){
+				socket_print_error(stderr, value, "Socket receive: ", "\n");
+			}else{
+				length = (size_t) value;
+				if(verbose){
+					// print the header
+
+					// get the source port and prepare the address buffer
+					address_start = NULL;
+					switch(address->sa_family){
+						case AF_INET:
+							port = ntohs(address_in->sin_port);
+							address_start = (uint8_t *) &address_in->sin_addr.s_addr;
+							break;
+						case AF_INET6:
+							port = ntohs(address_in6->sin6_port);
+							address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
+							break;
+						default:
+							fprintf(stderr, "Address family %d (0x%X) is not supported.\n", address->sa_family);
+					}
+					// parse the source address
+					if(address_start){
+						if(ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))){
+							fprintf(stderr, "Received address error %d\n", ERROR_CODE);
+						}else{
+							data[length] = '\0';
+							printf("Socket %d received %d bytes from %s:%d\n%s\n", socket_id, length, address_string, port, data);
+						}
+					}
+				}
+
+				// answer the request either with the static reply or the original data
+				if(ERROR_OCCURRED(sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen))){
+					socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
+				}
+
+			}
+
+			// close the accepted stream socket
+			if(type == SOCK_STREAM){
+				if(ERROR_OCCURRED(closesocket(socket_id))){
+					socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n");
+				}
+			}
+
+		}
+
+		// decrease the count if positive
+		if(count > 0){
+			-- count;
+			if(verbose){
+				printf("Waiting for next %d packet(s)\n", count);
+			}
+		}
+	}
+
+	if(verbose){
+		printf("Closing the socket\n");
+	}
+
+	// close the listenning socket
+	if(ERROR_OCCURRED(closesocket(listening_id))){
+		socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n");
+		return ERROR_CODE;
+	}
+
+	if(verbose){
+		printf("Exiting\n");
+	}
+
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/app/netecho/print_error.c
===================================================================
--- uspace/app/netecho/print_error.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/netecho/print_error.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,150 @@
+/*
+ * 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_app
+ *  @{
+ */
+
+/** @file
+ *  Generic application error printing functions implementation.
+ */
+
+#include <stdio.h>
+
+#include <icmp_codes.h>
+#include <socket_errno.h>
+
+#include "print_error.h"
+
+void icmp_print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
+	if(output){
+		if(prefix){
+			fprintf(output, "%s", prefix);
+		}
+		switch(error_code){
+			case ICMP_DEST_UNREACH:
+				fprintf(output, "ICMP Destination Unreachable (%d) error", error_code);
+				break;
+			case ICMP_SOURCE_QUENCH:
+				fprintf(output, "ICMP Source Quench (%d) error", error_code);
+				break;
+			case ICMP_REDIRECT:
+				fprintf(output, "ICMP Redirect (%d) error", error_code);
+				break;
+			case ICMP_ALTERNATE_ADDR:
+				fprintf(output, "ICMP Alternate Host Address (%d) error", error_code);
+				break;
+			case ICMP_ROUTER_ADV:
+				fprintf(output, "ICMP Router Advertisement (%d) error", error_code);
+				break;
+			case ICMP_ROUTER_SOL:
+				fprintf(output, "ICMP Router Solicitation (%d) error", error_code);
+				break;
+			case ICMP_TIME_EXCEEDED:
+				fprintf(output, "ICMP Time Exceeded (%d) error", error_code);
+				break;
+			case ICMP_PARAMETERPROB:
+				fprintf(output, "ICMP Paramenter Problem (%d) error", error_code);
+				break;
+			case ICMP_CONVERSION_ERROR:
+				fprintf(output, "ICMP Datagram Conversion Error (%d) error", error_code);
+				break;
+			case ICMP_REDIRECT_MOBILE:
+				fprintf(output, "ICMP Mobile Host Redirect (%d) error", error_code);
+				break;
+			case ICMP_SKIP:
+				fprintf(output, "ICMP SKIP (%d) error", error_code);
+				break;
+			case ICMP_PHOTURIS:
+				fprintf(output, "ICMP Photuris (%d) error", error_code);
+				break;
+			default:
+				fprintf(output, "Other (%d) error", error_code);
+		}
+		if(suffix){
+			fprintf(output, "%s", suffix);
+		}
+	}
+}
+
+void print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
+	if(IS_ICMP_ERROR(error_code)){
+		icmp_print_error(output, error_code, prefix, suffix);
+	}else if(IS_SOCKET_ERROR(error_code)){
+		socket_print_error(output, error_code, prefix, suffix);
+	}
+}
+
+void socket_print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
+	if(output){
+		if(prefix){
+			fprintf(output, "%s", prefix);
+		}
+		switch(error_code){
+			case ENOTSOCK:
+				fprintf(output, "Not a socket (%d) error", error_code);
+				break;
+			case EPROTONOSUPPORT:
+				fprintf(output, "Protocol not supported (%d) error", error_code);
+				break;
+			case ESOCKTNOSUPPORT:
+				fprintf(output, "Socket type not supported (%d) error", error_code);
+				break;
+			case EPFNOSUPPORT:
+				fprintf(output, "Protocol family not supported (%d) error", error_code);
+				break;
+			case EAFNOSUPPORT:
+				fprintf(output, "Address family not supported (%d) error", error_code);
+				break;
+			case EADDRINUSE:
+				fprintf(output, "Address already in use (%d) error", error_code);
+				break;
+			case ENOTCONN:
+				fprintf(output, "Socket not connected (%d) error", error_code);
+				break;
+			case NO_DATA:
+				fprintf(output, "No data (%d) error", error_code);
+				break;
+			case EINPROGRESS:
+				fprintf(output, "Another operation in progress (%d) error", error_code);
+				break;
+			case EDESTADDRREQ:
+				fprintf(output, "Destination address required (%d) error", error_code);
+			case TRY_AGAIN:
+				fprintf(output, "Try again (%d) error", error_code);
+			default:
+				fprintf(output, "Other (%d) error", error_code);
+		}
+		if(suffix){
+			fprintf(output, "%s", suffix);
+		}
+	}
+}
+
+/** @}
+ */
Index: uspace/app/netecho/print_error.h
===================================================================
--- uspace/app/netecho/print_error.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/netecho/print_error.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,80 @@
+/*
+ * 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_app
+ *  @{
+ */
+
+/** @file
+ *  Generic application error printing functions.
+ */
+
+#ifndef __NET_APP_PRINT__
+#define __NET_APP_PRINT__
+
+/** Returns whether the error code may be an ICMP error code.
+ *  @param[in] error_code The error code.
+ *  @returns A value indicating whether the error code may be an ICMP error code.
+ */
+#define IS_ICMP_ERROR(error_code)		((error_code) > 0)
+
+/** Returns whether the error code may be socket error code.
+ *  @param[in] error_code The error code.
+ *  @returns A value indicating whether the error code may be a socket error code.
+ */
+#define IS_SOCKET_ERROR(error_code)	((error_code) < 0)
+
+/** Prints the specific ICMP error description.
+ *  @param[in] output The description output stream. May be NULL.
+ *  @param[in] error_code The ICMP error code.
+ *  @param[in] prefix The error description prefix. May be NULL.
+ *  @param[in] suffix The error description suffix. May be NULL.
+ */
+extern void icmp_print_error(FILE * output, int error_code, const char * prefix, const char * suffix);
+
+/** Prints the error description.
+ *  Supports ICMP and socket error codes.
+ *  @param[in] output The description output stream. May be NULL.
+ *  @param[in] error_code The error code.
+ *  @param[in] prefix The error description prefix. May be NULL.
+ *  @param[in] suffix The error description suffix. May be NULL.
+ */
+extern void print_error(FILE * output, int error_code, const char * prefix, const char * suffix);
+
+/** Prints the specific socket error description.
+ *  @param[in] output The description output stream. May be NULL.
+ *  @param[in] error_code The socket error code.
+ *  @param[in] prefix The error description prefix. May be NULL.
+ *  @param[in] suffix The error description suffix. May be NULL.
+ */
+extern void socket_print_error(FILE * output, int error_code, const char * prefix, const char * suffix);
+
+#endif
+
+/** @}
+ */
Index: uspace/app/nettest1/Makefile
===================================================================
--- uspace/app/nettest1/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/nettest1/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2005 Martin Decky
+# Copyright (c) 2007 Jakub Jermar
+# 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.
+#
+
+USPACE_PREFIX = ../..
+LIBS = $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBSOCKET_PREFIX)/include
+BINARY = nettest1
+
+SOURCES = \
+	nettest1.c \
+	nettest.c \
+	print_error.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/nettest1/nettest.c
===================================================================
--- uspace/app/nettest1/nettest.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/nettest1/nettest.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,201 @@
+/*
+ * 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 nettest
+ *  @{
+ */
+
+/** @file
+ *  Networking test support functions implementation.
+ */
+
+#include <stdio.h>
+
+#include <socket.h>
+#include <net_err.h>
+
+#include "nettest.h"
+#include "print_error.h"
+
+int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type){
+	int index;
+
+	if(verbose){
+		printf("Create\t");
+	}
+	fflush(stdout);
+	for(index = 0; index < sockets; ++ index){
+		socket_ids[index] = socket(family, type, 0);
+		if(socket_ids[index] < 0){
+			printf("Socket %d (%d) error:\n", index, socket_ids[index]);
+			socket_print_error(stderr, socket_ids[index], "Socket create: ", "\n");
+			return socket_ids[index];
+		}
+		if(verbose){
+			print_mark(index);
+		}
+	}
+	return EOK;
+}
+
+int sockets_close(int verbose, int * socket_ids, int sockets){
+	ERROR_DECLARE;
+
+	int index;
+
+	if(verbose){
+		printf("\tClose\t");
+	}
+	fflush(stdout);
+	for(index = 0; index < sockets; ++ index){
+		if(ERROR_OCCURRED(closesocket(socket_ids[index]))){
+			printf("Socket %d (%d) error:\n", index, socket_ids[index]);
+			socket_print_error(stderr, ERROR_CODE, "Socket close: ", "\n");
+			return ERROR_CODE;
+		}
+		if(verbose){
+			print_mark(index);
+		}
+	}
+	return EOK;
+}
+
+int sockets_connect(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen){
+	ERROR_DECLARE;
+
+	int index;
+
+	if(verbose){
+		printf("\tConnect\t");
+	}
+	fflush(stdout);
+	for(index = 0; index < sockets; ++ index){
+		if(ERROR_OCCURRED(connect(socket_ids[index], address, addrlen))){
+			socket_print_error(stderr, ERROR_CODE, "Socket connect: ", "\n");
+			return ERROR_CODE;
+		}
+		if(verbose){
+			print_mark(index);
+		}
+	}
+	return EOK;
+}
+
+int sockets_sendto(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages){
+	ERROR_DECLARE;
+
+	int index;
+	int message;
+
+	if(verbose){
+		printf("\tSendto\t");
+	}
+	fflush(stdout);
+	for(index = 0; index < sockets; ++ index){
+		for(message = 0; message < messages; ++ message){
+			if(ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, addrlen))){
+				printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
+				socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
+				return ERROR_CODE;
+			}
+		}
+		if(verbose){
+			print_mark(index);
+		}
+	}
+	return EOK;
+}
+
+int sockets_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){
+	int value;
+	int index;
+	int message;
+
+	if(verbose){
+		printf("\tRecvfrom\t");
+	}
+	fflush(stdout);
+	for(index = 0; index < sockets; ++ index){
+		for(message = 0; message < messages; ++ message){
+			value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
+			if(value < 0){
+				printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
+				socket_print_error(stderr, value, "Socket receive: ", "\n");
+				return value;
+			}
+		}
+		if(verbose){
+			print_mark(index);
+		}
+	}
+	return EOK;
+}
+
+int sockets_sendto_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){
+	ERROR_DECLARE;
+
+	int value;
+	int index;
+	int message;
+
+	if(verbose){
+		printf("\tSendto and recvfrom\t");
+	}
+	fflush(stdout);
+	for(index = 0; index < sockets; ++ index){
+		for(message = 0; message < messages; ++ message){
+			if(ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, * addrlen))){
+				printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
+				socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
+				return ERROR_CODE;
+			}
+			value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
+			if(value < 0){
+				printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
+				socket_print_error(stderr, value, "Socket receive: ", "\n");
+				return value;
+			}
+		}
+		if(verbose){
+			print_mark(index);
+		}
+	}
+	return EOK;
+}
+
+void print_mark(int index){
+	if((index + 1) % 10){
+		printf("*");
+	}else{
+		printf("|");
+	}
+	fflush(stdout);
+}
+
+/** @}
+ */
Index: uspace/app/nettest1/nettest.h
===================================================================
--- uspace/app/nettest1/nettest.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/nettest1/nettest.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,126 @@
+/*
+ * 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 nettest
+ *  @{
+ */
+
+/** @file
+ *  Networking test support functions.
+ */
+
+#ifndef __NET_TEST__
+#define __NET_TEST__
+
+#include <socket.h>
+
+/** Prints a mark.
+ *  If the index is a multiple of ten, a different mark is printed.
+ *  @param[in] index The index of the mark to be printed.
+ */
+extern void print_mark(int index);
+
+/** Creates new sockets.
+ *  @param[in] verbose A value indicating whether to print out verbose information.
+ *  @param[out] socket_ids A field to store the socket identifiers.
+ *  @param[in] sockets The number of sockets to create. Should be at most the size of the field.
+ *  @param[in] family The socket address family.
+ *  @param[in] type The socket type.
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for the socket() function.
+ */
+extern int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type);
+
+/** Closes sockets.
+ *  @param[in] verbose A value indicating whether to print out verbose information.
+ *  @param[in] socket_ids A field of stored socket identifiers.
+ *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for the closesocket() function.
+ */
+extern int sockets_close(int verbose, int * socket_ids, int sockets);
+
+/** Connects sockets.
+ *  @param[in] verbose A value indicating whether to print out verbose information.
+ *  @param[in] socket_ids A field of stored socket identifiers.
+ *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
+ *  @param[in] address The destination host address to connect to.
+ *  @param[in] addrlen The length of the destination address in bytes.
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for the connect() function.
+ */
+extern int sockets_connect(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen);
+
+/** Sends data via sockets.
+ *  @param[in] verbose A value indicating whether to print out verbose information.
+ *  @param[in] socket_ids A field of stored socket identifiers.
+ *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
+ *  @param[in] address The destination host address to send data to.
+ *  @param[in] addrlen The length of the destination address in bytes.
+ *  @param[in] data The data to be sent.
+ *  @param[in] size The data size in bytes.
+ *  @param[in] messages The number of datagrams per socket to be sent.
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for the sendto() function.
+ */
+extern int sockets_sendto(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages);
+
+/** Receives data via sockets.
+ *  @param[in] verbose A value indicating whether to print out verbose information.
+ *  @param[in] socket_ids A field of stored socket identifiers.
+ *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
+ *  @param[in] address The source host address of received datagrams.
+ *  @param[in,out] addrlen The maximum length of the source address in bytes. The actual size of the source address is set instead.
+ *  @param[out] data The received data.
+ *  @param[in] size The maximum data size in bytes.
+ *  @param[in] messages The number of datagrams per socket to be received.
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for the recvfrom() function.
+ */
+extern int sockets_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages);
+
+/** Sends and receives data via sockets.
+ *  Each datagram is sent and a reply read consequently.
+ *  The next datagram is sent after the reply is received.
+ *  @param[in] verbose A value indicating whether to print out verbose information.
+ *  @param[in] socket_ids A field of stored socket identifiers.
+ *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
+ *  @param[in,out] address The destination host address to send data to. The source host address of received datagrams is set instead.
+ *  @param[in] addrlen The length of the destination address in bytes.
+ *  @param[in,out] data The data to be sent. The received data are set instead.
+ *  @param[in] size The data size in bytes.
+ *  @param[in] messages The number of datagrams per socket to be received.
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for the recvfrom() function.
+ */
+extern int sockets_sendto_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages);
+
+#endif
+
+/** @}
+ */
Index: uspace/app/nettest1/nettest1.c
===================================================================
--- uspace/app/nettest1/nettest1.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/nettest1/nettest1.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,418 @@
+/*
+ * 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 nettest
+ *  @{
+ */
+
+/** @file
+ *  Networking test 1 application - sockets.
+ */
+
+#include <malloc.h>
+#include <stdio.h>
+#include <str.h>
+#include <task.h>
+#include <time.h>
+#include <arg_parse.h>
+
+#include <in.h>
+#include <in6.h>
+#include <inet.h>
+#include <socket.h>
+#include <net_err.h>
+#include <socket_parse.h>
+
+#include "nettest.h"
+#include "print_error.h"
+
+/** Echo module name.
+ */
+#define NAME	"Nettest1"
+
+/** Packet data pattern.
+ */
+#define NETTEST1_TEXT	"Networking test 1 - sockets"
+
+/** Module entry point.
+ *  Starts testing.
+ *  @param[in] argc The number of command line parameters.
+ *  @param[in] argv The command line parameters.
+ *  @returns EOK on success.
+ */
+int main(int argc, char * argv[]);
+
+/** Prints the application help.
+ */
+void nettest1_print_help(void);
+
+/** Refreshes the data.
+ *  Fills the data block with the NETTEST1_TEXT pattern.
+ *  @param[out] data The data block.
+ *  @param[in] size The data block size in bytes.
+ */
+void nettest1_refresh_data(char * data, size_t size);
+
+int main(int argc, char * argv[]){
+	ERROR_DECLARE;
+
+	size_t size			= 27;
+	int verbose			= 0;
+	sock_type_t type	= SOCK_DGRAM;
+	int sockets			= 10;
+	int messages		= 10;
+	int family			= PF_INET;
+	uint16_t port		= 7;
+
+	socklen_t max_length				= sizeof(struct sockaddr_in6);
+	uint8_t address_data[max_length];
+	struct sockaddr * address			= (struct sockaddr *) address_data;
+	struct sockaddr_in * address_in		= (struct sockaddr_in *) address;
+	struct sockaddr_in6 * address_in6	= (struct sockaddr_in6 *) address;
+	socklen_t addrlen;
+//	char address_string[INET6_ADDRSTRLEN];
+	uint8_t * address_start;
+
+	int * socket_ids;
+	char * data;
+	int value;
+	int index;
+	struct timeval time_before;
+	struct timeval time_after;
+
+	// parse the command line arguments
+	// stop before the last argument if it does not start with the minus sign ('-')
+	for(index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index){
+		// options should start with the minus sign ('-')
+		if(argv[index][0] == '-'){
+			switch(argv[index][1]){
+				// short options with only one letter
+				case 'f':
+					ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family));
+					break;
+				case 'h':
+					nettest1_print_help();
+					return EOK;
+					break;
+				case 'm':
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 0));
+					break;
+				case 'n':
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 0));
+					break;
+				case 'p':
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
+					port = (uint16_t) value;
+					break;
+				case 's':
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
+					size = (value >= 0) ? (size_t) value : 0;
+					break;
+				case 't':
+					ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type));
+					type = (sock_type_t) value;
+					break;
+				case 'v':
+					verbose = 1;
+					break;
+				// long options with the double minus sign ('-')
+				case '-':
+					if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
+						ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family));
+					}else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
+						nettest1_print_help();
+						return EOK;
+					}else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 8));
+					}else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 8));
+					}else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
+						port = (uint16_t) value;
+					}else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
+						ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type));
+						type = (sock_type_t) value;
+					}else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
+						verbose = 1;
+					}else{
+						nettest1_print_help();
+						return EINVAL;
+					}
+					break;
+				default:
+					nettest1_print_help();
+					return EINVAL;
+			}
+		}else{
+			nettest1_print_help();
+			return EINVAL;
+		}
+	}
+
+	// if not before the last argument containing the address
+	if(index >= argc){
+		printf("Command line error: missing address\n");
+		nettest1_print_help();
+		return EINVAL;
+	}
+
+	// prepare the address buffer
+	bzero(address_data, max_length);
+	switch(family){
+		case PF_INET:
+			address_in->sin_family = AF_INET;
+			address_in->sin_port = htons(port);
+			address_start = (uint8_t *) &address_in->sin_addr.s_addr;
+			addrlen = sizeof(struct sockaddr_in);
+			break;
+		case PF_INET6:
+			address_in6->sin6_family = AF_INET6;
+			address_in6->sin6_port = htons(port);
+			address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
+			addrlen = sizeof(struct sockaddr_in6);
+			break;
+		default:
+			fprintf(stderr, "Address family is not supported\n");
+			return EAFNOSUPPORT;
+	}
+
+	// parse the last argument which should contain the address
+	if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
+		fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
+		return ERROR_CODE;
+	}
+
+	// check the buffer size
+	if(size <= 0){
+		fprintf(stderr, "Data buffer size too small (%d). Using 1024 bytes instead.\n", size);
+		size = 1024;
+	}
+
+	// prepare the buffer
+	// size plus the terminating null (\0)
+	data = (char *) malloc(size + 1);
+	if(! data){
+		fprintf(stderr, "Failed to allocate data buffer.\n");
+		return ENOMEM;
+	}
+	nettest1_refresh_data(data, size);
+
+	// check the socket count
+	if(sockets <= 0){
+		fprintf(stderr, "Socket count too small (%d). Using 2 instead.\n", sockets);
+		sockets = 2;
+	}
+
+	// prepare the socket buffer
+	// count plus the terminating null (\0)
+	socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
+	if(! socket_ids){
+		fprintf(stderr, "Failed to allocate receive buffer.\n");
+		return ENOMEM;
+	}
+	socket_ids[sockets] = NULL;
+
+	if(verbose){
+		printf("Starting tests\n");
+	}
+
+	if(verbose){
+		printf("1 socket, 1 message\n");
+	}
+
+	if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
+		fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
+		return ERROR_CODE;
+	}
+
+	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
+	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
+	if(verbose){
+		printf("\tOK\n");
+	}
+
+	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
+	if(type == SOCK_STREAM){
+		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
+	}
+	ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, 1));
+	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
+	if(verbose){
+		printf("\tOK\n");
+	}
+
+	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
+	if(type == SOCK_STREAM){
+		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
+	}
+	ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, 1, address, addrlen, data, size, 1));
+	ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, 1));
+	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
+	if(verbose){
+		printf("\tOK\n");
+	}
+
+	if(verbose){
+		printf("1 socket, %d messages\n", messages);
+	}
+
+	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
+	if(type == SOCK_STREAM){
+		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
+	}
+	ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, messages));
+	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
+	if(verbose){
+		printf("\tOK\n");
+	}
+
+	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
+	if(type == SOCK_STREAM){
+		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
+	}
+	ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, 1, address, addrlen, data, size, messages));
+	ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, messages));
+	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
+	if(verbose){
+		printf("\tOK\n");
+	}
+
+	if(verbose){
+		printf("%d sockets, 1 message\n", sockets);
+	}
+
+	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
+	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
+	if(verbose){
+		printf("\tOK\n");
+	}
+
+	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
+	if(type == SOCK_STREAM){
+		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
+	}
+	ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, 1));
+	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
+	if(verbose){
+		printf("\tOK\n");
+	}
+
+	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
+	if(type == SOCK_STREAM){
+		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
+	}
+	ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, 1));
+	ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, 1));
+	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
+	if(verbose){
+		printf("\tOK\n");
+	}
+
+	if(verbose){
+		printf("%d sockets, %d messages\n", sockets, messages);
+	}
+
+	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
+	if(type == SOCK_STREAM){
+		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
+	}
+	ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
+	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
+	if(verbose){
+		printf("\tOK\n");
+	}
+
+	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
+	if(type == SOCK_STREAM){
+		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
+	}
+	ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages));
+	ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
+	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
+
+	if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
+		fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
+		return ERROR_CODE;
+	}
+
+	if(verbose){
+		printf("\tOK\n");
+	}
+
+	printf("Tested in %d microseconds\n", tv_sub(&time_after, &time_before));
+
+	if(verbose){
+		printf("Exiting\n");
+	}
+
+	return EOK;
+}
+
+void nettest1_print_help(void){
+	printf(
+		"Network Networking test 1 aplication - sockets\n" \
+		"Usage: echo [options] numeric_address\n" \
+		"Where options are:\n" \
+		"-f protocol_family | --family=protocol_family\n" \
+		"\tThe listenning socket protocol family. Only the PF_INET and PF_INET6 are supported.\n"
+		"\n" \
+		"-h | --help\n" \
+		"\tShow this application help.\n"
+		"\n" \
+		"-m count | --messages=count\n" \
+		"\tThe number of messages to send and receive per socket. The default is 10.\n" \
+		"\n" \
+		"-n sockets | --sockets=count\n" \
+		"\tThe number of sockets to use. The default is 10.\n" \
+		"\n" \
+		"-p port_number | --port=port_number\n" \
+		"\tThe port number the application should send messages to. The default is 7.\n" \
+		"\n" \
+		"-s packet_size | --size=packet_size\n" \
+		"\tThe packet data size the application sends. The default is 28 bytes.\n" \
+		"\n" \
+		"-v | --verbose\n" \
+		"\tShow all output messages.\n"
+	);
+}
+
+void nettest1_refresh_data(char * data, size_t size){
+	size_t length;
+
+	// fill the data
+	length = 0;
+	while(size > length + sizeof(NETTEST1_TEXT) - 1){
+		memcpy(data + length, NETTEST1_TEXT, sizeof(NETTEST1_TEXT) - 1);
+		length += sizeof(NETTEST1_TEXT) - 1;
+	}
+	memcpy(data + length, NETTEST1_TEXT, size - length);
+	data[size] = '\0';
+}
+
+/** @}
+ */
Index: uspace/app/nettest1/print_error.c
===================================================================
--- uspace/app/nettest1/print_error.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/nettest1/print_error.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1 @@
+../netecho/print_error.c
Index: uspace/app/nettest1/print_error.h
===================================================================
--- uspace/app/nettest1/print_error.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/nettest1/print_error.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1 @@
+../netecho/print_error.h
Index: uspace/app/nettest2/Makefile
===================================================================
--- uspace/app/nettest2/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/nettest2/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2005 Martin Decky
+# Copyright (c) 2007 Jakub Jermar
+# 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.
+#
+
+USPACE_PREFIX = ../..
+LIBS = $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBSOCKET_PREFIX)/include
+BINARY = nettest2
+
+SOURCES = \
+	nettest2.c \
+	nettest.c \
+	print_error.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/nettest2/nettest.c
===================================================================
--- uspace/app/nettest2/nettest.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/nettest2/nettest.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1 @@
+../nettest1/nettest.c
Index: uspace/app/nettest2/nettest.h
===================================================================
--- uspace/app/nettest2/nettest.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/nettest2/nettest.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1 @@
+../nettest1/nettest.h
Index: uspace/app/nettest2/nettest2.c
===================================================================
--- uspace/app/nettest2/nettest2.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/nettest2/nettest2.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,342 @@
+/*
+ * 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 nettest
+ *  @{
+ */
+
+/** @file
+ *  Networking test 2 application - transfer.
+ */
+
+#include <malloc.h>
+#include <stdio.h>
+#include <str.h>
+#include <task.h>
+#include <time.h>
+#include <arg_parse.h>
+
+#include <in.h>
+#include <in6.h>
+#include <inet.h>
+#include <socket.h>
+#include <net_err.h>
+#include <socket_parse.h>
+
+#include "nettest.h"
+#include "print_error.h"
+
+/** Echo module name.
+ */
+#define NAME	"Nettest2"
+
+/** Packet data pattern.
+ */
+#define NETTEST2_TEXT	"Networking test 2 - transfer"
+
+/** Module entry point.
+ *  Starts testing.
+ *  @param[in] argc The number of command line parameters.
+ *  @param[in] argv The command line parameters.
+ *  @returns EOK on success.
+ */
+int main(int argc, char * argv[]);
+
+/** Prints the application help.
+ */
+void nettest2_print_help(void);
+
+/** Refreshes the data.
+ *  Fills the data block with the NETTEST1_TEXT pattern.
+ *  @param[out] data The data block.
+ *  @param[in] size The data block size in bytes.
+ */
+void nettest2_refresh_data(char * data, size_t size);
+
+int main(int argc, char * argv[]){
+	ERROR_DECLARE;
+
+	size_t size			= 28;
+	int verbose			= 0;
+	sock_type_t type	= SOCK_DGRAM;
+	int sockets			= 10;
+	int messages		= 10;
+	int family			= PF_INET;
+	uint16_t port		= 7;
+
+	socklen_t max_length				= sizeof(struct sockaddr_in6);
+	uint8_t address_data[max_length];
+	struct sockaddr * address			= (struct sockaddr *) address_data;
+	struct sockaddr_in * address_in		= (struct sockaddr_in *) address;
+	struct sockaddr_in6 * address_in6	= (struct sockaddr_in6 *) address;
+	socklen_t addrlen;
+//	char address_string[INET6_ADDRSTRLEN];
+	uint8_t * address_start;
+
+	int * socket_ids;
+	char * data;
+	int value;
+	int index;
+	struct timeval time_before;
+	struct timeval time_after;
+
+	// parse the command line arguments
+	// stop before the last argument if it does not start with the minus sign ('-')
+	for(index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index){
+		// options should start with the minus sign ('-')
+		if(argv[index][0] == '-'){
+			switch(argv[index][1]){
+				// short options with only one letter
+				case 'f':
+					ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 0, socket_parse_protocol_family));
+					break;
+				case 'h':
+					nettest2_print_help();
+					return EOK;
+					break;
+				case 'm':
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 0));
+					break;
+				case 'n':
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 0));
+					break;
+				case 'p':
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
+					port = (uint16_t) value;
+					break;
+				case 's':
+					ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 0));
+					size = (value >= 0) ? (size_t) value : 0;
+					break;
+				case 't':
+					ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 0, socket_parse_socket_type));
+					type = (sock_type_t) value;
+					break;
+				case 'v':
+					verbose = 1;
+					break;
+				// long options with the double minus sign ('-')
+				case '-':
+					if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
+						ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &family, 9, socket_parse_protocol_family));
+					}else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
+						nettest2_print_help();
+						return EOK;
+					}else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &messages, 8));
+					}else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &sockets, 8));
+					}else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
+						ERROR_PROPAGATE(arg_parse_int(argc, argv, &index, &value, 7));
+						port = (uint16_t) value;
+					}else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
+						ERROR_PROPAGATE(arg_parse_name_int(argc, argv, &index, &value, 7, socket_parse_socket_type));
+						type = (sock_type_t) value;
+					}else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
+						verbose = 1;
+					}else{
+						nettest2_print_help();
+						return EINVAL;
+					}
+					break;
+				default:
+					nettest2_print_help();
+					return EINVAL;
+			}
+		}else{
+			nettest2_print_help();
+			return EINVAL;
+		}
+	}
+
+	// if not before the last argument containing the address
+	if(index >= argc){
+		printf("Command line error: missing address\n");
+		nettest2_print_help();
+		return EINVAL;
+	}
+
+	// prepare the address buffer
+	bzero(address_data, max_length);
+	switch(family){
+		case PF_INET:
+			address_in->sin_family = AF_INET;
+			address_in->sin_port = htons(port);
+			address_start = (uint8_t *) &address_in->sin_addr.s_addr;
+			addrlen = sizeof(struct sockaddr_in);
+			break;
+		case PF_INET6:
+			address_in6->sin6_family = AF_INET6;
+			address_in6->sin6_port = htons(port);
+			address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
+			addrlen = sizeof(struct sockaddr_in6);
+			break;
+		default:
+			fprintf(stderr, "Address family is not supported\n");
+			return EAFNOSUPPORT;
+	}
+
+	// parse the last argument which should contain the address
+	if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
+		fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
+		return ERROR_CODE;
+	}
+
+	// check the buffer size
+	if(size <= 0){
+		fprintf(stderr, "Data buffer size too small (%d). Using 1024 bytes instead.\n", size);
+		size = 1024;
+	}
+
+	// prepare the buffer
+	// size plus terminating null (\0)
+	data = (char *) malloc(size + 1);
+	if(! data){
+		fprintf(stderr, "Failed to allocate data buffer.\n");
+		return ENOMEM;
+	}
+	nettest2_refresh_data(data, size);
+
+	// check the socket count
+	if(sockets <= 0){
+		fprintf(stderr, "Socket count too small (%d). Using 2 instead.\n", sockets);
+		sockets = 2;
+	}
+
+	// prepare the socket buffer
+	// count plus the terminating null (\0)
+	socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
+	if(! socket_ids){
+		fprintf(stderr, "Failed to allocate receive buffer.\n");
+		return ENOMEM;
+	}
+	socket_ids[sockets] = NULL;
+
+	if(verbose){
+		printf("Starting tests\n");
+	}
+
+	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
+
+	if(type == SOCK_STREAM){
+		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
+	}
+
+	if(verbose){
+		printf("\n");
+	}
+
+	if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
+		fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
+		return ERROR_CODE;
+	}
+
+	ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
+
+	if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
+		fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
+		return ERROR_CODE;
+	}
+
+	if(verbose){
+		printf("\tOK\n");
+	}
+
+	printf("sendto + recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before));
+
+	if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
+		fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
+		return ERROR_CODE;
+	}
+
+	ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages));
+	ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
+
+	if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
+		fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
+		return ERROR_CODE;
+	}
+
+	if(verbose){
+		printf("\tOK\n");
+	}
+
+	printf("sendto, recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before));
+
+	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
+
+	if(verbose){
+		printf("\nExiting\n");
+	}
+
+	return EOK;
+}
+
+void nettest2_print_help(void){
+	printf(
+		"Network Networking test 2 aplication - UDP transfer\n" \
+		"Usage: echo [options] numeric_address\n" \
+		"Where options are:\n" \
+		"-f protocol_family | --family=protocol_family\n" \
+		"\tThe listenning socket protocol family. Only the PF_INET and PF_INET6 are supported.\n"
+		"\n" \
+		"-h | --help\n" \
+		"\tShow this application help.\n"
+		"\n" \
+		"-m count | --messages=count\n" \
+		"\tThe number of messages to send and receive per socket. The default is 10.\n" \
+		"\n" \
+		"-n sockets | --sockets=count\n" \
+		"\tThe number of sockets to use. The default is 10.\n" \
+		"\n" \
+		"-p port_number | --port=port_number\n" \
+		"\tThe port number the application should send messages to. The default is 7.\n" \
+		"\n" \
+		"-s packet_size | --size=packet_size\n" \
+		"\tThe packet data size the application sends. The default is 29 bytes.\n" \
+		"\n" \
+		"-v | --verbose\n" \
+		"\tShow all output messages.\n"
+	);
+}
+
+void nettest2_refresh_data(char * data, size_t size){
+	size_t length;
+
+	// fill the data
+	length = 0;
+	while(size > length + sizeof(NETTEST2_TEXT) - 1){
+		memcpy(data + length, NETTEST2_TEXT, sizeof(NETTEST2_TEXT) - 1);
+		length += sizeof(NETTEST2_TEXT) - 1;
+	}
+	memcpy(data + length, NETTEST2_TEXT, size - length);
+	data[size] = '\0';
+}
+
+/** @}
+ */
Index: uspace/app/nettest2/print_error.c
===================================================================
--- uspace/app/nettest2/print_error.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/nettest2/print_error.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1 @@
+../netecho/print_error.c
Index: uspace/app/nettest2/print_error.h
===================================================================
--- uspace/app/nettest2/print_error.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/nettest2/print_error.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1 @@
+../netecho/print_error.h
Index: uspace/app/ping/Makefile
===================================================================
--- uspace/app/ping/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/ping/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,39 @@
+#
+# Copyright (c) 2005 Martin Decky
+# Copyright (c) 2007 Jakub Jermar
+# 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.
+#
+
+USPACE_PREFIX = ../..
+LIBS = $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBSOCKET_PREFIX)/include
+BINARY = ping
+
+SOURCES = \
+	ping.c \
+	print_error.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/ping/ping.c
===================================================================
--- uspace/app/ping/ping.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/ping/ping.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,406 @@
+/*
+ * 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 ping
+ * @{
+ */
+
+/** @file
+ * Packet Internet Network Grouper.
+ */
+
+#include <stdio.h>
+#include <str.h>
+#include <task.h>
+#include <time.h>
+#include <ipc/ipc.h>
+#include <ipc/services.h>
+#include <str_error.h>
+#include <arg_parse.h>
+
+#include <icmp_api.h>
+#include <in.h>
+#include <in6.h>
+#include <inet.h>
+#include <ip_codes.h>
+#include <socket_errno.h>
+#include <socket_parse.h>
+
+#include "print_error.h"
+
+#define NAME  "ping"
+
+#define CL_OK           0
+#define CL_USAGE        -1
+#define CL_MISSING      -2
+#define CL_INVALID      -3
+#define CL_UNSUPPORTED  -4
+#define CL_ERROR        -5
+
+/** Ping configuration
+ *
+ */
+typedef struct {
+	bool verbose;               /**< Verbose printouts. */
+	size_t size;                /**< Outgoing packet size. */
+	unsigned int count;         /**< Number of packets to send. */
+	suseconds_t timeout;        /**< Reply wait timeout. */
+	int af;                     /**< Address family. */
+	ip_tos_t tos;               /**< Type of service. */
+	ip_ttl_t ttl;               /**< Time-to-live. */
+	bool fragments;             /**< Fragmentation. */
+	
+	char *dest_addr;            /**< Destination address. */
+	struct sockaddr_in dest;    /**< IPv4 destionation. */
+	struct sockaddr_in6 dest6;  /**< IPv6 destionation. */
+	
+	struct sockaddr *dest_raw;  /**< Raw destination address. */
+	socklen_t dest_len;         /**< Raw destination address length. */
+	
+	/** Converted address string. */
+	char dest_str[INET6_ADDRSTRLEN];
+} ping_config_t;
+
+
+static void usage(void)
+{
+	printf(
+	    "Usage: ping [-c count] [-s size] [-W timeout] [-f family] [-t ttl]\n" \
+	    "            [-Q tos] [--dont_fragment] destination\n" \
+	    "\n" \
+	    "Options:\n" \
+	    "\t-c count\n" \
+	    "\t--count=count\n" \
+	    "\t\tNumber of outgoing packets (default: 4)\n" \
+	    "\n" \
+	    "\t-s size\n" \
+	    "\t--size=bytes\n" \
+	    "\t\tOutgoing packet size (default: 56 bytes)\n" \
+	    "\n" \
+	    "\t-W timeout\n" \
+	    "\t--timeout=ms\n" \
+	    "\t\tReply wait timeout (default: 3000 ms)\n" \
+	    "\n" \
+	    "\t-f family\n" \
+	    "\t--family=family\n" \
+	    "\t\tDestination address family, AF_INET or AF_INET6 (default: AF_INET)\n" \
+	    "\n" \
+	    "\t-t ttl\n" \
+	    "\t--ttl=ttl\n" \
+	    "\t\tOutgoing packet time-to-live (default: 0)\n" \
+	    "\n" \
+	    "\t-Q tos\n" \
+	    "\t--tos=tos\n" \
+	    "\t\tOutgoing packet type of service (default: 0)\n" \
+	    "\n" \
+	    "\t--dont_fragment\n" \
+	    "\t\tDisable packet fragmentation (default: enabled)\n" \
+	    "\n" \
+	    "\t-v\n" \
+	    "\t--verbose\n" \
+	    "\t\tVerbose operation\n" \
+	    "\n" \
+	    "\t-h\n" \
+	    "\t--help\n" \
+	    "\t\tPrint this usage information\n"
+	);
+}
+
+static int arg_short_long(const char *arg, const char *ashort,
+    const char *along)
+{
+	if (str_cmp(arg, ashort) == 0)
+		return 0;
+	
+	if (str_lcmp(arg, along, str_length(along)) == 0)
+		return str_length(along);
+	
+	return -1;
+}
+
+static int args_parse(int argc, char *argv[], ping_config_t *config)
+{
+	if (argc < 2)
+		return CL_USAGE;
+	
+	int i;
+	int ret;
+	
+	for (i = 1; i < argc; i++) {
+		
+		/* Not an option */
+		if (argv[i][0] != '-')
+			break;
+		
+		/* Options terminator */
+		if (str_cmp(argv[i], "--") == 0) {
+			i++;
+			break;
+		}
+		
+		int off;
+		int tmp;
+		
+		/* Usage */
+		if ((off = arg_short_long(argv[i], "-h", "--help")) != -1)
+			return CL_USAGE;
+		
+		/* Verbose */
+		if ((off = arg_short_long(argv[i], "-v", "--verbose")) != -1) {
+			config->verbose = true;
+			continue;
+		}
+		
+		/* Don't fragment */
+		if (str_cmp(argv[i], "--dont_fragment") == 0) {
+			config->fragments = false;
+			continue;
+		}
+		
+		/* Count */
+		if ((off = arg_short_long(argv[i], "-c", "--count=")) != -1) {
+			ret = arg_parse_int(argc, argv, &i, &tmp, off);
+			
+			if ((ret != EOK) || (tmp < 0))
+				return i;
+			
+			config->count = (unsigned int) tmp;
+			continue;
+		}
+		
+		/* Outgoing packet size */
+		if ((off = arg_short_long(argv[i], "-s", "--size=")) != -1) {
+			ret = arg_parse_int(argc, argv, &i, &tmp, off);
+			
+			if ((ret != EOK) || (tmp < 0))
+				return i;
+			
+			config->size = (size_t) tmp;
+			continue;
+		}
+		
+		/* Reply wait timeout */
+		if ((off = arg_short_long(argv[i], "-W", "--timeout=")) != -1) {
+			ret = arg_parse_int(argc, argv, &i, &tmp, off);
+			
+			if ((ret != EOK) || (tmp < 0))
+				return i;
+			
+			config->timeout = (suseconds_t) tmp;
+			continue;
+		}
+		
+		/* Address family */
+		if ((off = arg_short_long(argv[i], "-f", "--family=")) != -1) {
+			ret = arg_parse_name_int(argc, argv, &i, &config->af, off,
+			    socket_parse_address_family);
+			
+			if (ret != EOK)
+				return i;
+			
+			continue;
+		}
+		
+		/* Type of service */
+		if ((off = arg_short_long(argv[i], "-Q", "--tos=")) != -1) {
+			ret = arg_parse_name_int(argc, argv, &i, &tmp, off,
+			    socket_parse_address_family);
+			
+			if ((ret != EOK) || (tmp < 0))
+				return i;
+			
+			config->tos = (ip_tos_t) tmp;
+			continue;
+		}
+		
+		/* Time to live */
+		if ((off = arg_short_long(argv[i], "-t", "--ttl=")) != -1) {
+			ret = arg_parse_name_int(argc, argv, &i, &tmp, off,
+			    socket_parse_address_family);
+			
+			if ((ret != EOK) || (tmp < 0))
+				return i;
+			
+			config->ttl = (ip_ttl_t) tmp;
+			continue;
+		}
+	}
+	
+	if (i >= argc)
+		return CL_MISSING;
+	
+	config->dest_addr = argv[i];
+	
+	/* Resolve destionation address */
+	switch (config->af) {
+	case AF_INET:
+		config->dest_raw = (struct sockaddr *) &config->dest;
+		config->dest_len = sizeof(config->dest);
+		config->dest.sin_family = config->af;
+		ret = inet_pton(config->af, config->dest_addr,
+		    (uint8_t *) &config->dest.sin_addr.s_addr);
+		break;
+	case AF_INET6:
+		config->dest_raw = (struct sockaddr *) &config->dest6;
+		config->dest_len = sizeof(config->dest6);
+		config->dest6.sin6_family = config->af;
+		ret = inet_pton(config->af, config->dest_addr,
+		    (uint8_t *) &config->dest6.sin6_addr.s6_addr);
+		break;
+	default:
+		return CL_UNSUPPORTED;
+	}
+	
+	if (ret != EOK)
+		return CL_INVALID;
+	
+	/* Convert destination address back to string */
+	switch (config->af) {
+	case AF_INET:
+		ret = inet_ntop(config->af,
+		    (uint8_t *) &config->dest.sin_addr.s_addr,
+		    config->dest_str, sizeof(config->dest_str));
+		break;
+	case AF_INET6:
+		ret = inet_ntop(config->af,
+		    (uint8_t *) &config->dest6.sin6_addr.s6_addr,
+		    config->dest_str, sizeof(config->dest_str));
+		break;
+	default:
+		return CL_UNSUPPORTED;
+	}
+	
+	if (ret != EOK)
+		return CL_ERROR;
+	
+	return CL_OK;
+}
+
+int main(int argc, char *argv[])
+{
+	ping_config_t config;
+	
+	/* Default configuration */
+	config.verbose = false;
+	config.size = 56;
+	config.count = 4;
+	config.timeout = 3000;
+	config.af = AF_INET;
+	config.tos = 0;
+	config.ttl = 0;
+	config.fragments = true;
+	
+	int ret = args_parse(argc, argv, &config);
+	
+	switch (ret) {
+	case CL_OK:
+		break;
+	case CL_USAGE:
+		usage();
+		return 0;
+	case CL_MISSING:
+		fprintf(stderr, "%s: Destination address missing\n", NAME);
+		return 1;
+	case CL_INVALID:
+		fprintf(stderr, "%s: Destination address '%s' invalid or malformed\n",
+		    NAME, config.dest_addr);
+		return 2;
+	case CL_UNSUPPORTED:
+		fprintf(stderr, "%s: Destination address '%s' unsupported\n",
+		    NAME, config.dest_addr);
+		return 3;
+	case CL_ERROR:
+		fprintf(stderr, "%s: Destination address '%s' error\n",
+		    NAME, config.dest_addr);
+		return 4;
+	default:
+		fprintf(stderr, "%s: Unknown or invalid option '%s'\n", NAME,
+		    argv[ret]);
+		return 5;
+	}
+	
+	printf("PING %s (%s) %u(%u) bytes of data\n", config.dest_addr,
+	    config.dest_str, config.size, config.size);
+	
+	int icmp_phone = icmp_connect_module(SERVICE_ICMP, ICMP_CONNECT_TIMEOUT);
+	if (icmp_phone < 0) {
+		fprintf(stderr, "%s: Unable to connect to ICMP service (%s)\n", NAME,
+		    str_error(icmp_phone));
+		return icmp_phone;
+	}
+	
+	unsigned int seq;
+	for (seq = 0; seq < config.count; seq++) {
+		struct timeval t0;
+		ret = gettimeofday(&t0, NULL);
+		if (ret != EOK) {
+			fprintf(stderr, "%s: gettimeofday failed (%s)\n", NAME,
+			    str_error(ret));
+			
+			ipc_hangup(icmp_phone);
+			return ret;
+		}
+		
+		/* Ping! */
+		int result = icmp_echo_msg(icmp_phone, config.size, config.timeout,
+		    config.ttl, config.tos, !config.fragments, config.dest_raw,
+		    config.dest_len);
+		
+		struct timeval t1;
+		ret = gettimeofday(&t1, NULL);
+		if (ret != EOK) {
+			fprintf(stderr, "%s: gettimeofday failed (%s)\n", NAME,
+			    str_error(ret));
+			
+			ipc_hangup(icmp_phone);
+			return ret;
+		}
+		
+		suseconds_t elapsed = tv_sub(&t1, &t0);
+		
+		switch (result) {
+		case ICMP_ECHO:
+			printf("%u bytes from ? (?): icmp_seq=%u ttl=? time=%u.%04u\n",
+				config.size, seq, elapsed / 1000, elapsed % 1000);
+			break;
+		case ETIMEOUT:
+			printf("%u bytes from ? (?): icmp_seq=%u Timed out\n",
+				config.size, seq);
+			break;
+		default:
+			print_error(stdout, result, NULL, "\n");
+		}
+	}
+	
+	ipc_hangup(icmp_phone);
+	
+	return 0;
+}
+
+/** @}
+ */
Index: uspace/app/ping/print_error.c
===================================================================
--- uspace/app/ping/print_error.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/ping/print_error.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1 @@
+../netecho/print_error.c
Index: uspace/app/ping/print_error.h
===================================================================
--- uspace/app/ping/print_error.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/ping/print_error.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1 @@
+../netecho/print_error.h
Index: uspace/app/redir/redir.c
===================================================================
--- uspace/app/redir/redir.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/app/redir/redir.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -42,8 +42,12 @@
 #include <stdio.h>
 #include <task.h>
+#include <str_error.h>
+
+#define NAME  "redir"
 
 static void usage(void)
 {
-	printf("Usage: redir [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n");
+	printf("Usage: %s [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n",
+	    NAME);
 }
 
@@ -84,10 +88,12 @@
 	args[argc] = NULL;
 	
-	task_id_t id = task_spawn(argv[0], args);
+	int err;
+	task_id_t id = task_spawn(argv[0], args, &err);
 	
 	free(args);
 	
 	if (id == 0)
-		printf("Error spawning %s\n", argv[0]);
+		printf("%s: Error spawning %s (%s)\n", NAME, argv[0],
+		    str_error(err));
 	
 	return id;
Index: uspace/app/sbi/Makefile
===================================================================
--- uspace/app/sbi/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,64 @@
+#
+# Copyright (c) 2010 Jiri Svoboda
+# 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.
+#
+
+USPACE_PREFIX = ../..
+LIBS = $(LIBCLUI_PREFIX)/libclui.a
+EXTRA_CFLAGS = -D__HELENOS__ -I$(LIBCLUI_PREFIX)
+
+BINARY = sbi
+
+SOURCES = \
+	src/builtin/bi_error.c \
+	src/builtin/bi_fun.c \
+	src/builtin/bi_textfile.c \
+	src/os/helenos.c \
+	src/ancr.c \
+	src/bigint.c \
+	src/builtin.c \
+	src/imode.c \
+	src/input.c \
+	src/intmap.c \
+	src/lex.c \
+	src/list.c \
+	src/main.c \
+	src/p_expr.c \
+	src/p_type.c \
+	src/parse.c \
+	src/program.c \
+	src/rdata.c \
+	src/run.c \
+	src/run_expr.c \
+	src/run_texpr.c \
+	src/stree.c \
+	src/strtab.c \
+	src/stype.c \
+	src/stype_expr.c \
+	src/symbol.c \
+	src/tdata.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/sbi/src/ancr.c
===================================================================
--- uspace/app/sbi/src/ancr.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/ancr.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Ancestry resolver.
+ *
+ * A chicken-and-egg problem is that in order to match identifiers to CSI
+ * definitions we need to know CSI ancestry. To know CSI ancestry we need
+ * to match identifiers to CSI definitions. Thus both must be done at the
+ * same time. Once we know the ancestry of some CSI, we are able to resolve
+ * symbols referenced within the scope of that CSI (but not in nested scopes).
+ *
+ * Here lies probably the most complicated (although not so complicated)
+ * algorithm. To process node N we must first process outer(N). This allows
+ * us to find all base(N) nodes and process them.
+ *
+ * To ensure all nodes get processed correctly, we use a two-layer walk.
+ * In the lower layer (ancr_csi_process) we follow the dependencies.
+ * ancr_csi_process(N) ensures N (and possibly other nodes) get resolved.
+ *
+ * In the second layer we simply do a DFS of the CSI tree, calling
+ * ancr_csi_process() on each node. This ensures that eventually all
+ * nodes get processed.
+ */
+
+#include <stdlib.h>
+#include <assert.h>
+#include "builtin.h"
+#include "list.h"
+#include "mytypes.h"
+#include "stree.h"
+#include "strtab.h"
+#include "symbol.h"
+
+#include "ancr.h"
+
+static void ancr_csi_dfs(stree_program_t *prog, stree_csi_t *csi);
+static void ancr_csi_process(stree_program_t *prog, stree_csi_t *node);
+static void ancr_csi_print_cycle(stree_program_t *prog, stree_csi_t *node);
+
+/** Process ancestry of all CSIs in a module.
+ *
+ * Note that currently we expect there to be exactly one module in the
+ * whole program.
+ *
+ * @param prog		Program being processed.
+ * @param module	Module to process.
+ */
+void ancr_module_process(stree_program_t *prog, stree_module_t *module)
+{
+	list_node_t *node;
+	stree_modm_t *modm;
+
+	(void) module;
+	node = list_first(&prog->module->members);
+
+	while (node != NULL) {
+		modm = list_node_data(node, stree_modm_t *);
+		assert(modm->mc == mc_csi); /* XXX */
+		ancr_csi_dfs(prog, modm->u.csi);
+
+		node = list_next(&prog->module->members, node);
+	}
+}
+
+/** Walk CSI node tree depth-first.
+ *
+ * This is the outer depth-first walk whose purpose is to eventually
+ * process all CSI nodes by calling ancr_csi_process() on them.
+ * (Which causes that and possibly some other nodes to be processed).
+ *
+ * @param prog		Program being processed.
+ * @param csi		CSI node to visit.
+ */
+static void ancr_csi_dfs(stree_program_t *prog, stree_csi_t *csi)
+{
+	list_node_t *node;
+	stree_csimbr_t *csimbr;
+
+	/* Process this node first. */
+	ancr_csi_process(prog, csi);
+
+	/* Now visit all children. */
+	node = list_first(&csi->members);
+	while (node != NULL) {
+		csimbr = list_node_data(node, stree_csimbr_t *);
+		if (csimbr->cc == csimbr_csi)
+			ancr_csi_dfs(prog, csimbr->u.csi);
+
+		node = list_next(&csi->members, node);
+	}
+}
+
+/** Process csi node.
+ *
+ * Fist processes the pre-required nodes (outer CSI and base CSIs),
+ * then processes @a node. This is the core 'outward-and-baseward' walk.
+ *
+ * @param prog		Program being processed.
+ * @param node		CSI node to process.
+ */
+static void ancr_csi_process(stree_program_t *prog, stree_csi_t *node)
+{
+	stree_symbol_t *base_sym;
+	stree_csi_t *base_csi, *outer_csi;
+	stree_csi_t *gf_class;
+
+	if (node->ancr_state == ws_visited) {
+		/* Node already processed */
+		return;
+	}
+
+	if (node->ancr_state == ws_active) {
+		/* Error, closed reference loop. */
+		printf("Error: Circular class, struct or interface chain: ");
+		ancr_csi_print_cycle(prog, node);
+		printf(".\n");
+		exit(1);
+	}
+
+	node->ancr_state = ws_active;
+
+	outer_csi = csi_to_symbol(node)->outer_csi;
+	gf_class = builtin_get_gf_class(prog->builtin);
+
+	/* Process outer CSI */
+	if (outer_csi != NULL)
+		ancr_csi_process(prog, outer_csi);
+
+	if (node->base_csi_ref != NULL) {
+		/* Resolve base CSI. */
+		base_sym = symbol_xlookup_in_csi(prog, outer_csi,
+			node->base_csi_ref);
+		base_csi = symbol_to_csi(base_sym);
+		assert(base_csi != NULL);
+
+		/* Process base CSI. */
+		ancr_csi_process(prog, base_csi);
+	} else if (node != gf_class) {
+		/* Implicit inheritance from grandfather class. */
+		base_csi = gf_class;
+	} else {
+		/* Grandfather class has no base class. */
+		base_csi = NULL;
+	}
+
+	/* Store base CSI and update node state. */
+	node->ancr_state = ws_visited;
+	node->base_csi = base_csi;
+}
+
+/** Print loop in CSI ancestry.
+ *
+ * We have detected a loop in CSI ancestry. Traverse it (by following the
+ * nodes in ws_active state and print it.
+ *
+ * @param prog		Program.
+ * @param node		CSI node participating in an ancestry cycle.
+ */
+static void ancr_csi_print_cycle(stree_program_t *prog, stree_csi_t *node)
+{
+	stree_csi_t *n;
+	stree_symbol_t *base_sym, *node_sym;
+	stree_csi_t *base_csi, *outer_csi;
+
+	n = node;
+	do {
+		node_sym = csi_to_symbol(node);
+		symbol_print_fqn(node_sym);
+		printf(", ");
+
+		outer_csi = node_sym->outer_csi;
+
+		if (outer_csi != NULL && outer_csi->ancr_state == ws_active) {
+			node = outer_csi;
+		} else if (node->base_csi_ref != NULL) {
+			/* Resolve base CSI. */
+			base_sym = symbol_xlookup_in_csi(prog, outer_csi,
+				node->base_csi_ref);
+			base_csi = symbol_to_csi(base_sym);
+			assert(base_csi != NULL);
+
+			assert(base_csi->ancr_state == ws_active);
+			node = base_csi;
+		} else {
+			assert(b_false);
+		}
+	} while (n != node);
+
+	node_sym = csi_to_symbol(node);
+	symbol_print_fqn(node_sym);
+}
Index: uspace/app/sbi/src/ancr.h
===================================================================
--- uspace/app/sbi/src/ancr.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/ancr.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef ANCR_H_
+#define ANCR_H_
+
+#include "mytypes.h"
+
+void ancr_module_process(stree_program_t *prog, stree_module_t *module);
+
+#endif
Index: uspace/app/sbi/src/bigint.c
===================================================================
--- uspace/app/sbi/src/bigint.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/bigint.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,668 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Big integers.
+ *
+ * Sysel type @c int should accomodate large numbers. This implementation
+ * is limited by the available memory and range of the @c size_t type used
+ * to index digits.
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "debug.h"
+#include "mytypes.h"
+
+#include "bigint.h"
+
+static void bigint_sign_comb(bool_t srf_a, bigint_t *a, bool_t srf_b,
+    bigint_t *b, bigint_t *dest);
+static void bigint_add_abs(bigint_t *a, bigint_t *b, bigint_t *dest);
+static void bigint_sub_abs(bigint_t *a, bigint_t *b, bigint_t *dest);
+static void bigint_shift_mul_dig(bigint_t *a, bigint_word_t b, size_t shift,
+    bigint_t *dest);
+
+static void bigint_alloc(bigint_t *bigint, size_t length);
+static void bigint_refine_len(bigint_t *bigint);
+
+/** Initialize bigint with value from small integer.
+ *
+ * Initializes a bigint structure with the provided small value.
+ *
+ * @param value		Initial value (small int).
+ */
+void bigint_init(bigint_t *bigint, int value)
+{
+	size_t length;
+	size_t idx;
+	int t;
+
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Initialize bigint with int value %d.\n", value);
+#endif
+
+	if (value < 0) {
+		bigint->negative = b_true;
+		value = -value;
+	} else {
+		bigint->negative = b_false;
+	}
+
+	/* Determine length. */
+	length = 0;
+	t = value;
+	while (t > 0) {
+		length += 1;
+		t = t / BIGINT_BASE;
+	}
+
+	/* Allocate digit array. */
+	bigint_alloc(bigint, length);
+
+	/* Compute digits. */
+	t = value;
+	for (idx = 0; idx < length; ++idx) {
+		bigint->digit[idx] = t % BIGINT_BASE;
+		t = t / BIGINT_BASE;
+	}
+}
+
+/** Shallow copy of integer.
+ *
+ * @param src		Source.
+ * @param dest		Destination.
+ */
+void bigint_shallow_copy(bigint_t *src, bigint_t *dest)
+{
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Shallow copy of bigint.\n");
+#endif
+	dest->negative = src->negative;
+	dest->digit = src->digit;
+	dest->length = src->length;
+}
+/** Clone big integer.
+ *
+ * @param src		Source.
+ * @param dest		Destination.
+ */
+void bigint_clone(bigint_t *src, bigint_t *dest)
+{
+	size_t idx;
+
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Clone bigint.\n");
+#endif
+	/* Copy sign. */
+	dest->negative = src->negative;
+
+	/* Allocate dest digit array. */
+	bigint_alloc(dest, src->length);
+
+	/* Copy digits. */
+	for (idx = 0; idx < dest->length; ++idx)
+		dest->digit[idx] = src->digit[idx];
+}
+
+/** Compute big integer with reversed sign.
+ *
+ * @param src		Source.
+ * @param dest		Destination.
+ */
+void bigint_reverse_sign(bigint_t *src, bigint_t *dest)
+{
+	size_t idx;
+
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Reverse-sign copy of bigint.\n");
+#endif
+	/* Copy reversed sign. */
+	dest->negative = !src->negative;
+
+	/* Allocate dest digit array. */
+	bigint_alloc(dest, src->length);
+
+	/* Copy digits. */
+	for (idx = 0; idx < dest->length; ++idx)
+		dest->digit[idx] = src->digit[idx];
+}
+
+/** Destroy big integer.
+ *
+ * Any bigint that is initialized via bigint_init() or any other bigint
+ * function that constructs a new bigint value should be destroyed with
+ * this function to free memory associated with the bigint. It should
+ * also be used to destroy a bigint before it is reused.
+ *
+ * @param bigint	The bigint to destroy.
+ */
+void bigint_destroy(bigint_t *bigint)
+{
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Destroy bigint.\n");
+#endif
+	bigint->negative = b_false;
+
+	bigint->length = 0;
+
+	free(bigint->digit);
+	bigint->digit = NULL;
+}
+
+/** Get value of big integer.
+ *
+ * Allows to obtain the value of big integer, provided that it fits
+ * into a small integer.
+ *
+ * @param bigint	Bigint to obtain value from.
+ * @param dval		Place to store value.
+ * @return		EOK on success, ELIMIT if bigint is too big to fit
+ *			to @a dval.
+ */
+int bigint_get_value_int(bigint_t *bigint, int *dval)
+{
+	bigint_t vval, diff;
+	size_t idx;
+	int val;
+	bool_t zf;
+
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Get int value of bigint.\n");
+#endif
+	val = 0;
+	for (idx = 0; idx < bigint->length; ++idx) {
+		val = val * BIGINT_BASE + bigint->digit[idx];
+	}
+
+	if (bigint->negative)
+		val = - val;
+
+	/* If the value did not fit @c val now contains garbage. Verify. */
+	bigint_init(&vval, val);
+
+	bigint_sub(bigint, &vval, &diff);
+	zf = bigint_is_zero(&diff);
+
+	bigint_destroy(&vval);
+	bigint_destroy(&diff);
+
+	/* If the difference is not zero, the verification failed. */
+	if (zf != b_true)
+		return EINVAL;
+
+	*dval = val;
+	return EOK;
+}
+
+/** Determine if bigint is zero.
+ *
+ * @param bigint	Big integer.
+ * @return		b_true if @a bigint is zero, b_false otherwise.
+ */
+bool_t bigint_is_zero(bigint_t *bigint)
+{
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Determine if bigint is zero.\n");
+#endif
+	return (bigint->length == 0);
+}
+
+/** Determine if bigint is negative.
+ *
+ * @param bigint	Big integer.
+ * @return		b_true if @a bigint is negative, b_false otherwise.
+ */
+bool_t bigint_is_negative(bigint_t *bigint)
+{
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Determine if bigint is negative\n");
+#endif
+	/* Verify that we did not accidentaly introduce a negative zero. */
+	assert(bigint->negative == b_false || bigint->length > 0);
+
+	return bigint->negative;
+}
+
+/** Divide bigint by (unsigned) digit.
+ *
+ * @param a		Bigint dividend.
+ * @param b		Divisor digit.
+ * @param quot		Output bigint quotient.
+ * @param rem		Output remainder digit.
+ */
+void bigint_div_digit(bigint_t *a, bigint_word_t b, bigint_t *quot,
+    bigint_word_t *rem)
+{
+	size_t lbound;
+	size_t idx;
+	bigint_dword_t da, db;
+	bigint_dword_t q, r;
+
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Divide bigint by digit.\n");
+#endif
+	lbound = a->length;
+	bigint_alloc(quot, lbound);
+
+	quot->negative = a->negative;
+
+	r = 0;
+	idx = lbound;
+	while (idx > 0) {
+		--idx;
+
+		da = a->digit[idx] + r * BIGINT_BASE;
+		db = b;
+
+		q = da / db;
+		r = da % db;
+
+		quot->digit[idx] = q;
+	}
+
+	bigint_refine_len(quot);
+	*rem = r;
+}
+
+/** Add two big integers.
+ *
+ * The big integers @a a and @a b are added and the result is stored in
+ * @a dest.
+ *
+ * @param a		First addend.
+ * @param b		Second addend.
+ * @param dest		Destination bigint.
+ */
+void bigint_add(bigint_t *a, bigint_t *b, bigint_t *dest)
+{
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Add bigints.\n");
+#endif
+	bigint_sign_comb(b_false, a, b_false, b, dest);
+}
+
+/** Subtract two big integers.
+ *
+ * The big integers @a a and @a b are subtracted and the result is stored in
+ * @a dest.
+ *
+ * @param a		Minuend.
+ * @param b		Subtrahend.
+ * @param dest		Destination bigint.
+ */
+void bigint_sub(bigint_t *a, bigint_t *b, bigint_t *dest)
+{
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Subtract bigints.\n");
+#endif
+	bigint_sign_comb(b_false, a, b_true, b, dest);
+}
+
+/** Multiply two big integers.
+ *
+ * The big integers @a a and @a b are multiplied and the result is stored in
+ * @a dest.
+ *
+ * @param a		First factor.
+ * @param b		Second factor.
+ * @param dest		Destination bigint.
+ */
+void bigint_mul(bigint_t *a, bigint_t *b, bigint_t *dest)
+{
+	size_t idx;
+	bigint_t dprod;
+	bigint_t sum;
+	bigint_t tmp;
+
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Multiply bigints.\n");
+#endif
+	bigint_init(&sum, 0);
+	for (idx = 0; idx < b->length; ++idx) {
+		bigint_shift_mul_dig(a, b->digit[idx], idx, &dprod);
+		bigint_add(&dprod, &sum, &tmp);
+		bigint_destroy(&dprod);
+
+		bigint_destroy(&sum);
+		bigint_shallow_copy(&tmp, &sum);
+	}
+
+	if (b->negative)
+		sum.negative = !sum.negative;
+
+	bigint_shallow_copy(&sum, dest);
+}
+
+/** Print bigint to standard output. */
+void bigint_print(bigint_t *bigint)
+{
+	bigint_t val, tmp;
+	bigint_word_t rem;
+	size_t ndigits;
+	int *digits;
+	size_t idx;
+
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Print bigint.\n");
+#endif
+	assert(BIGINT_BASE >= 10);
+
+	if (bigint_is_zero(bigint)) {
+		putchar('0');
+		return;
+	}
+
+	if (bigint->negative)
+		putchar('-');
+
+	/* Compute number of digits. */
+	ndigits = 0;
+	bigint_clone(bigint, &val);
+	while (bigint_is_zero(&val) != b_true) {
+		bigint_div_digit(&val, 10, &tmp, &rem);
+		bigint_destroy(&val);
+		bigint_shallow_copy(&tmp, &val);
+
+		ndigits += 1;
+	}
+	bigint_destroy(&val);
+
+	/* Store digits to array. */
+
+	digits = malloc(ndigits * sizeof(int));
+	if (digits == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	idx = 0;
+	bigint_clone(bigint, &val);
+	while (bigint_is_zero(&val) != b_true) {
+		bigint_div_digit(&val, 10, &tmp, &rem);
+		bigint_destroy(&val);
+		bigint_shallow_copy(&tmp, &val);
+
+		digits[idx++] = (int) rem;
+	}
+	bigint_destroy(&val);
+
+	for (idx = 0; idx < ndigits; ++idx)
+		printf("%u", digits[ndigits - 1 - idx]);
+
+	free(digits);
+}
+
+/** Compute sign combination of two big integers.
+ *
+ * Of the big integers @a a and @a b each is optionally sign-reversed and then
+ * they are added and the result is stored in @a dest.
+ *
+ * @param srf_a		First sign reversal flag.
+ * @param a		First bigint.
+ * @param srf_b		Second sign reversal flag.
+ * @param b		Second bigint.
+ * @param dest		Destination bigint.
+ */
+static void bigint_sign_comb(bool_t srf_a, bigint_t *a, bool_t srf_b,
+    bigint_t *b, bigint_t *dest)
+{
+	bool_t neg_a, neg_b;
+
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Signed combination of two bigints.\n");
+#endif
+	/* Compute resulting signs of combination elements. */
+	neg_a = (srf_a != a->negative);
+	neg_b = (srf_b != b->negative);
+
+	if (neg_a == neg_b) {
+		bigint_add_abs(a, b, dest);
+		dest->negative = neg_a;
+	} else {
+		bigint_sub_abs(a, b, dest);
+		dest->negative = (neg_a != dest->negative);
+	}
+}
+
+/** Add absolute values of two big integers.
+ *
+ * The absolute values of big integers @a a and @a b are added and the result
+ * is stored in @a dest.
+ *
+ * @param a		First addend.
+ * @param b		Second addend.
+ * @param dest		Destination bigint.
+ */
+static void bigint_add_abs(bigint_t *a, bigint_t *b, bigint_t *dest)
+{
+	size_t lbound;
+	size_t idx;
+	bigint_dword_t da, db;
+	bigint_dword_t tmp;
+	bigint_word_t res, carry;
+
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Add absolute values of bigints.\n");
+#endif
+	/* max(a->length, b->length) + 1 */
+	lbound = (a->length > b->length ? a->length : b->length) + 1;
+	dest->negative = b_false;
+
+	bigint_alloc(dest, lbound);
+	carry = 0;
+
+	for (idx = 0; idx < lbound; ++idx) {
+		da = idx < a->length ? a->digit[idx] : 0;
+		db = idx < b->length ? b->digit[idx] : 0;
+
+		tmp = da + db + (bigint_word_t) carry;
+
+		carry = (bigint_word_t) (tmp / BIGINT_BASE);
+		res = (bigint_word_t) (tmp % BIGINT_BASE);
+
+		dest->digit[idx] = res;
+	}
+
+	/* If our lbound is correct, carry must be zero. */
+	assert(carry == 0);
+
+	bigint_refine_len(dest);
+}
+
+/** Subtract absolute values of two big integers.
+ *
+ * The absolute values of big integers @a a and @a b are subtracted and the
+ * result is stored in @a dest.
+ *
+ * @param a		Minuend.
+ * @param b		Subtrahend.
+ * @param dest		Destination bigint.
+ */
+static void bigint_sub_abs(bigint_t *a, bigint_t *b, bigint_t *dest)
+{
+	size_t lbound;
+	size_t idx;
+	bigint_dword_t da, db;
+	bigint_dword_t tmp;
+	bigint_word_t res, borrow;
+
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Subtract absolute values of bigints.\n");
+#endif
+	/* max(a->length, b->length) */
+	lbound = a->length > b->length ? a->length : b->length;
+
+	bigint_alloc(dest, lbound);
+	borrow = 0;
+
+	for (idx = 0; idx < lbound; ++idx) {
+		da = idx < a->length ? a->digit[idx] : 0;
+		db = idx < b->length ? b->digit[idx] : 0;
+
+		if (da > db + borrow) {
+			tmp = da - db - borrow;
+			borrow = 0;
+		} else {
+			tmp = da + BIGINT_BASE - db - borrow;
+			borrow = 1;
+		}
+
+		res = (bigint_word_t) tmp;
+		dest->digit[idx] = res;
+	}
+
+	if (borrow != 0) {
+		/* We subtracted the greater number from the smaller. */
+		dest->negative = b_true;
+
+		/*
+		 * Now we must complement the number to get the correct
+		 * absolute value. We do this by subtracting from 10..0
+		 * (0 repeated lbound-times).
+		 */
+		borrow = 0;
+
+		for (idx = 0; idx < lbound; ++idx) {
+			da = 0;
+			db = dest->digit[idx];
+
+			if (da > db + borrow) {
+				tmp = da - db - borrow;
+				borrow = 0;
+			} else {
+				tmp = da + BIGINT_BASE - db - borrow;
+				borrow = 1;
+			}
+
+			res = (bigint_word_t) tmp;
+			dest->digit[idx] = res;
+		}
+
+		/* The last step is the '1'. */
+		assert(borrow == 1);
+	} else {
+		dest->negative = b_false;
+	}
+
+	bigint_refine_len(dest);
+}
+
+/** Multiply big integer by digit.
+ *
+ * @param a		Bigint factor.
+ * @param b		Digit factor.
+ * @param dest		Destination bigint.
+ */
+static void bigint_shift_mul_dig(bigint_t *a, bigint_word_t b, size_t shift,
+    bigint_t *dest)
+{
+	size_t lbound;
+	size_t idx;
+
+	bigint_dword_t da, db;
+	bigint_dword_t tmp;
+	bigint_word_t res, carry;
+
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Multiply bigint by digit.\n");
+#endif
+	/* Compute length bound and allocate. */
+	lbound = a->length + shift + 1;
+	bigint_alloc(dest, lbound);
+
+	/* Copy sign. */
+	dest->negative = a->negative;
+
+	for (idx = 0; idx < shift; ++idx)
+		dest->digit[idx] = 0;
+
+	carry = 0;
+	for (idx = 0; idx < lbound - shift; ++idx) {
+		da = idx < a->length ? a->digit[idx] : 0;
+		db = b;
+
+		tmp = (da * db) + (bigint_word_t) carry;
+
+		carry = (bigint_word_t) (tmp / BIGINT_BASE);
+		res = (bigint_word_t) (tmp % BIGINT_BASE);
+
+		dest->digit[shift + idx] = res;
+	}
+
+	/* If our lbound is correct, carry must be zero. */
+	assert(carry == 0);
+
+	bigint_refine_len(dest);
+}
+
+
+/** Allocate bigint of the given length.
+ *
+ * @param bigint	Bigint whose digit array should be allocated.
+ * @param length	Length of array (also set as bigint length).
+ */
+static void bigint_alloc(bigint_t *bigint, size_t length)
+{
+	size_t a_length;
+
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Allocate bigint digit array.\n");
+#endif
+	/* malloc() sometimes cannot allocate blocks of zero size. */
+	if (length == 0)
+		a_length = 1;
+	else
+		a_length = length;
+
+	bigint->digit = malloc(a_length * sizeof(bigint_word_t));
+	if (bigint->digit == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	bigint->length = length;
+}
+
+/** Adjust length field of bigint to be exact.
+ *
+ * When bigint is allocated with bigint_alloc() its length can be
+ * imprecise (higher than actually number of non-zero digits).
+ * Then this function is used to lower @c length to the exact value.
+ */
+static void bigint_refine_len(bigint_t *bigint)
+{
+#ifdef DEBUG_BIGINT_TRACE
+	printf("Refine bigint length.\n");
+#endif
+	while (bigint->length > 0 && bigint->digit[bigint->length - 1] == 0)
+		bigint->length -= 1;
+
+	if (bigint->length == 0)
+		bigint->negative = b_false;
+}
Index: uspace/app/sbi/src/bigint.h
===================================================================
--- uspace/app/sbi/src/bigint.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/bigint.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef BIGINT_H_
+#define BIGINT_H_
+
+#include "mytypes.h"
+
+void bigint_init(bigint_t *bigint, int value);
+void bigint_shallow_copy(bigint_t *src, bigint_t *dest);
+void bigint_clone(bigint_t *src, bigint_t *dest);
+void bigint_reverse_sign(bigint_t *src, bigint_t *dest);
+void bigint_destroy(bigint_t *bigint);
+
+int bigint_get_value_int(bigint_t *bigint, int *dval);
+bool_t bigint_is_zero(bigint_t *bigint);
+bool_t bigint_is_negative(bigint_t *bigint);
+
+void bigint_div_digit(bigint_t *a, bigint_word_t b, bigint_t *quot,
+    bigint_word_t *rem);
+
+void bigint_add(bigint_t *a, bigint_t *b, bigint_t *dest);
+void bigint_sub(bigint_t *a, bigint_t *b, bigint_t *dest);
+void bigint_mul(bigint_t *a, bigint_t *b, bigint_t *dest);
+void bigint_print(bigint_t *bigint);
+
+#endif
Index: uspace/app/sbi/src/bigint_t.h
===================================================================
--- uspace/app/sbi/src/bigint_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/bigint_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef BIGINT_T_H_
+#define BIGINT_T_H_
+
+#include <sys/types.h>
+#include <stdint.h>
+
+typedef uint8_t bigint_word_t;
+typedef uint16_t bigint_dword_t;
+
+#define BIGINT_BASE ((bigint_dword_t) 256UL)
+
+/** Big integer.
+ *
+ * Used to implement Sysel @c int type.
+ */
+typedef struct bigint {
+	/** Number of non-zero digits in the @c digit array. */
+	size_t length;
+
+	/** Sign. */
+	bool_t negative;
+
+	/** Digits starting from the least significant. */
+	bigint_word_t *digit;
+} bigint_t;
+
+#endif
Index: uspace/app/sbi/src/builtin.c
===================================================================
--- uspace/app/sbi/src/builtin.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/builtin.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,351 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Builtin symbol binding.
+ *
+ * 'Builtin' symbols are implemented outside of the language itself.
+ * Here we refer to entities residing within the interpreted universe
+ * as 'internal', while anything implemented outside this universe
+ * as 'external'. This module facilitates declaration of builtin
+ * symbols and the binding of these symbols to their external
+ * implementation.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "ancr.h"
+#include "builtin/bi_error.h"
+#include "builtin/bi_fun.h"
+#include "builtin/bi_textfile.h"
+#include "input.h"
+#include "intmap.h"
+#include "lex.h"
+#include "list.h"
+#include "mytypes.h"
+#include "os/os.h"
+#include "parse.h"
+#include "run.h"
+#include "stree.h"
+#include "strtab.h"
+#include "symbol.h"
+
+#include "builtin.h"
+
+static builtin_t *builtin_new(void);
+
+/** Declare builtin symbols in the program.
+ *
+ * Declares symbols that will be hooked to builtin interpreter procedures.
+ *
+ * @param program	Program in which to declare builtin symbols.
+ */
+void builtin_declare(stree_program_t *program)
+{
+	builtin_t *bi;
+
+	bi = builtin_new();
+	bi->program = program;
+	program->builtin = bi;
+
+	/*
+	 * Declare grandfather class.
+	 */
+
+	builtin_code_snippet(bi,
+		"class Object is\n"
+		"end\n");
+	bi->gf_class = builtin_find_lvl0(bi, "Object");
+
+	/*
+	 * Declare other builtin classes/functions.
+	 */
+
+	bi_error_declare(bi);
+	bi_fun_declare(bi);
+	bi_textfile_declare(bi);
+
+	/* Need to process ancestry so that symbol lookups work. */
+	ancr_module_process(program, program->module);
+
+	bi_error_bind(bi);
+	bi_fun_bind(bi);
+	bi_textfile_bind(bi);
+}
+
+/** Get grandfather class.
+ *
+ * Grandfather class is the class from which all other classes are
+ * (directly or indirectly) derived.
+ *
+ * @param builtin	Builtin context (corresponsds to program).
+ * @return		Grandfather class (CSI).
+ */
+stree_csi_t *builtin_get_gf_class(builtin_t *builtin)
+{
+	if (builtin->gf_class == NULL)
+		return NULL;
+
+	return symbol_to_csi(builtin->gf_class);
+}
+
+/** Allocate new builtin context object.
+ *
+ * @return	Builtin context object.
+ */
+static builtin_t *builtin_new(void)
+{
+	builtin_t *builtin;
+
+	builtin = calloc(1, sizeof(builtin_t));
+	if (builtin == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return builtin;
+}
+
+/** Parse a declaration code snippet.
+ *
+ * Parses a piece of code from a string at the module level. This can be
+ * used to declare builtin symbols easily and without need for an external
+ * file.
+ */
+void builtin_code_snippet(builtin_t *bi, const char *snippet)
+{
+	input_t *input;
+	lex_t lex;
+	parse_t parse;
+
+	input_new_string(&input, snippet);
+	lex_init(&lex, input);
+	parse_init(&parse, bi->program, &lex);
+	parse_module(&parse);
+}
+
+/** Simplifed search for a global symbol.
+ *
+ * The specified symbol must exist.
+ *
+ * @param bi		Builtin context object.
+ * @param sym_name	Name of symbol to find.
+ * @return		Symbol.
+ */
+stree_symbol_t *builtin_find_lvl0(builtin_t *bi, const char *sym_name)
+{
+	stree_symbol_t *sym;
+	stree_ident_t *ident;
+
+	ident = stree_ident_new();
+
+	ident->sid = strtab_get_sid(sym_name);
+	sym = symbol_lookup_in_csi(bi->program, NULL, ident);
+	assert(sym != NULL);
+
+	return sym;
+}
+
+/** Simplifed search for a level 1 symbol.
+ *
+ * The specified symbol must exist.
+ *
+ * @param bi		Builtin context object.
+ * @param csi_name	CSI in which to look for symbol.
+ * @param sym_name	Name of symbol to find.
+ * @return		Symbol.
+ */
+stree_symbol_t *builtin_find_lvl1(builtin_t *bi, const char *csi_name,
+    const char *sym_name)
+{
+	stree_symbol_t *csi_sym;
+	stree_csi_t *csi;
+
+	stree_symbol_t *mbr_sym;
+	stree_ident_t *ident;
+
+	ident = stree_ident_new();
+
+	ident->sid = strtab_get_sid(csi_name);
+	csi_sym = symbol_lookup_in_csi(bi->program, NULL, ident);
+	assert(csi_sym != NULL);
+	csi = symbol_to_csi(csi_sym);
+	assert(csi != NULL);
+
+	ident->sid = strtab_get_sid(sym_name);
+	mbr_sym = symbol_lookup_in_csi(bi->program, csi, ident);
+	assert(mbr_sym != NULL);
+
+	return mbr_sym;
+}
+
+/** Bind level 1 member function to external implementation.
+ *
+ * Binds a member function (of a global class) to external implementation.
+ * The specified CSI and member function must exist.
+ *
+ * @param bi		Builtin context object.
+ * @param csi_name	CSI which contains the function.
+ * @param sym_name	Function name.
+ * @param bproc		Pointer to C function implementation.
+ */
+void builtin_fun_bind(builtin_t *bi, const char *csi_name,
+    const char *sym_name, builtin_proc_t bproc)
+{
+	stree_symbol_t *fun_sym;
+	stree_fun_t *fun;
+
+	fun_sym = builtin_find_lvl1(bi, csi_name, sym_name);
+	assert(fun_sym != NULL);
+	fun = symbol_to_fun(fun_sym);
+	assert(fun != NULL);
+
+	fun->proc->bi_handler = bproc;
+}
+
+/** Execute a builtin procedure.
+ *
+ * Executes a procedure that has an external implementation.
+ *
+ * @param run		Runner object.
+ * @param proc		Procedure that has an external implementation.
+ */
+void builtin_run_proc(run_t *run, stree_proc_t *proc)
+{
+	stree_symbol_t *fun_sym;
+	builtin_t *bi;
+	builtin_proc_t bproc;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run builtin procedure.\n");
+#endif
+	fun_sym = proc->outer_symbol;
+	bi = run->program->builtin;
+
+	bproc = proc->bi_handler;
+	if (bproc == NULL) {
+		printf("Error: Unrecognized builtin function '");
+		symbol_print_fqn(fun_sym);
+		printf("'.\n");
+		exit(1);
+	}
+
+	/* Run the builtin procedure handler. */
+	(*bproc)(run);
+}
+
+/** Get pointer to member var of current object.
+ *
+ * Returns the var node that corresponds to a member of the currently
+ * active object with the given name. This member must exist.
+ *
+ * @param run		Runner object.
+ * @param mbr_name	Name of member to find.
+ * @return		Var node of the member.
+ */
+rdata_var_t *builtin_get_self_mbr_var(run_t *run, const char *mbr_name)
+{
+	run_proc_ar_t *proc_ar;
+	rdata_object_t *object;
+	sid_t mbr_name_sid;
+	rdata_var_t *mbr_var;
+
+	proc_ar = run_get_current_proc_ar(run);
+	assert(proc_ar->obj->vc == vc_object);
+	object = proc_ar->obj->u.object_v;
+
+	mbr_name_sid = strtab_get_sid(mbr_name);
+	mbr_var = intmap_get(&object->fields, mbr_name_sid);
+	assert(mbr_var != NULL);
+
+	return mbr_var;
+}
+
+/** Declare a builtin function in @a csi.
+ *
+ * Declare a builtin function member of CSI @a csi. Deprecated in favor
+ * of builtin_code_snippet().
+ *
+ * @param csi		CSI in which to declare function.
+ * @param name		Name of member function to declare.
+ * @return		Symbol of newly declared function.
+ */
+stree_symbol_t *builtin_declare_fun(stree_csi_t *csi, const char *name)
+{
+	stree_ident_t *ident;
+	stree_fun_t *fun;
+	stree_csimbr_t *csimbr;
+	stree_symbol_t *fun_sym;
+
+	ident = stree_ident_new();
+	ident->sid = strtab_get_sid(name);
+
+	fun = stree_fun_new();
+	fun->name = ident;
+	fun->proc = stree_proc_new();
+	fun->proc->body = NULL;
+	list_init(&fun->args);
+
+	csimbr = stree_csimbr_new(csimbr_fun);
+	csimbr->u.fun = fun;
+
+	fun_sym = stree_symbol_new(sc_fun);
+	fun_sym->u.fun = fun;
+	fun_sym->outer_csi = csi;
+	fun->symbol = fun_sym;
+	fun->proc->outer_symbol = fun_sym;
+
+	list_append(&csi->members, csimbr);
+
+	return fun_sym;
+}
+
+/** Add one formal parameter to function.
+ *
+ * Used to incrementally construct formal parameter list of a builtin
+ * function. Deprecated in favor of builtin_code_snippet(). Does not
+ * support type checking.
+ *
+ * @param fun_sym	Symbol of function to add parameters to.
+ * @param name		Name of parameter to add.
+ */
+void builtin_fun_add_arg(stree_symbol_t *fun_sym, const char *name)
+{
+	stree_proc_arg_t *proc_arg;
+	stree_fun_t *fun;
+
+	fun = symbol_to_fun(fun_sym);
+	assert(fun != NULL);
+
+	proc_arg = stree_proc_arg_new();
+	proc_arg->name = stree_ident_new();
+	proc_arg->name->sid = strtab_get_sid(name);
+	proc_arg->type = NULL; /* XXX */
+
+	list_append(&fun->args, proc_arg);
+}
Index: uspace/app/sbi/src/builtin.h
===================================================================
--- uspace/app/sbi/src/builtin.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/builtin.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef BUILTIN_H_
+#define BUILTIN_H_
+
+#include "mytypes.h"
+
+void builtin_declare(stree_program_t *program);
+void builtin_code_snippet(builtin_t *bi, const char *snippet);
+
+stree_csi_t *builtin_get_gf_class(builtin_t *builtin);
+void builtin_run_proc(run_t *run, stree_proc_t *proc);
+
+rdata_var_t *builtin_get_self_mbr_var(run_t *run, const char *mbr_name);
+
+stree_symbol_t *builtin_declare_fun(stree_csi_t *csi, const char *name);
+void builtin_fun_add_arg(stree_symbol_t *fun_sym, const char *name);
+
+stree_symbol_t *builtin_find_lvl0(builtin_t *bi, const char *sym_name);
+stree_symbol_t *builtin_find_lvl1(builtin_t *bi, const char *csi_name,
+    const char *sym_name);
+
+void builtin_fun_bind(builtin_t *bi, const char *csi_name,
+    const char *sym_name, builtin_proc_t bproc);
+
+#endif
Index: uspace/app/sbi/src/builtin/bi_error.c
===================================================================
--- uspace/app/sbi/src/builtin/bi_error.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/builtin/bi_error.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Error classes (used with exception handling). */
+
+#include <assert.h>
+#include "../builtin.h"
+#include "../mytypes.h"
+#include "../symbol.h"
+
+#include "bi_error.h"
+
+/** Declare error class hierarchy. */
+void bi_error_declare(builtin_t *bi)
+{
+	/*
+	 * Declare class Error and its subclasses.
+	 * Here, class Error supplants a package or namespace.
+	 */
+
+	builtin_code_snippet(bi,
+		"class Error is\n"
+			/* Common ancestor of all error classes */
+			"class Base is\n"
+			"end\n"
+			/* Accessing nil reference */
+			"class NilReference : Base is\n"
+			"end\n"
+			/* Array index out of bounds */
+			"class OutOfBounds : Base is\n"
+			"end\n"
+		"end\n");}
+
+/** Bind error class hierarchy. */
+void bi_error_bind(builtin_t *bi)
+{
+	stree_symbol_t *sym;
+
+	/* Declare class Error and its subclasses. */
+
+	sym = builtin_find_lvl1(bi, "Error", "OutOfBounds");
+	bi->error_outofbounds = symbol_to_csi(sym);
+	assert(bi->error_outofbounds != NULL);
+
+	sym = builtin_find_lvl1(bi, "Error", "NilReference");
+	bi->error_nilreference = symbol_to_csi(sym);
+	assert(bi->error_nilreference != NULL);
+}
Index: uspace/app/sbi/src/builtin/bi_error.h
===================================================================
--- uspace/app/sbi/src/builtin/bi_error.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/builtin/bi_error.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef BI_ERROR_H_
+#define BI_ERROR_H_
+
+#include "../mytypes.h"
+
+void bi_error_declare(builtin_t *bi);
+void bi_error_bind(builtin_t *bi);
+
+#endif
Index: uspace/app/sbi/src/builtin/bi_fun.c
===================================================================
--- uspace/app/sbi/src/builtin/bi_fun.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/builtin/bi_fun.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Builtin functions. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "../bigint.h"
+#include "../builtin.h"
+#include "../list.h"
+#include "../mytypes.h"
+#include "../os/os.h"
+#include "../run.h"
+#include "../stree.h"
+#include "../strtab.h"
+#include "../symbol.h"
+
+#include "bi_fun.h"
+
+static void bi_fun_builtin_writeline(run_t *run);
+static void bi_fun_task_exec(run_t *run);
+
+/** Declare builtin functions. */
+void bi_fun_declare(builtin_t *bi)
+{
+	stree_modm_t *modm;
+	stree_csi_t *csi;
+	stree_ident_t *ident;
+	stree_symbol_t *symbol;
+	stree_symbol_t *fun_sym;
+
+	/* Declare class Builtin */
+
+	ident = stree_ident_new();
+	ident->sid = strtab_get_sid("Builtin");
+
+	csi = stree_csi_new(csi_class);
+	csi->name = ident;
+	list_init(&csi->members);
+
+	modm = stree_modm_new(mc_csi);
+	modm->u.csi = csi;
+
+	symbol = stree_symbol_new(sc_csi);
+	symbol->u.csi = csi;
+	symbol->outer_csi = NULL;
+	csi->symbol = symbol;
+
+	list_append(&bi->program->module->members, modm);
+
+	/* Declare Builtin.WriteLine(). */
+
+	fun_sym = builtin_declare_fun(csi, "WriteLine");
+	builtin_fun_add_arg(fun_sym, "arg");
+
+	/* Declare class Task. */
+
+	builtin_code_snippet(bi,
+		"class Task is\n"
+			"fun Exec(args : string[], packed), builtin;\n"
+		"end\n");
+}
+
+/** Bind builtin functions. */
+void bi_fun_bind(builtin_t *bi)
+{
+	builtin_fun_bind(bi, "Builtin", "WriteLine", bi_fun_builtin_writeline);
+	builtin_fun_bind(bi, "Task", "Exec", bi_fun_task_exec);
+}
+
+/** Write a line of output. */
+static void bi_fun_builtin_writeline(run_t *run)
+{
+	rdata_var_t *var;
+	int char_val;
+	int rc;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Called Builtin.WriteLine()\n");
+#endif
+	var = run_local_vars_lookup(run, strtab_get_sid("arg"));
+	assert(var);
+
+	switch (var->vc) {
+	case vc_char:
+		rc = bigint_get_value_int(&var->u.char_v->value, &char_val);
+		if (rc == EOK)
+			printf("%lc\n", char_val);
+		else
+			printf("???\n");
+		break;
+	case vc_int:
+		bigint_print(&var->u.int_v->value);
+		putchar('\n');
+		break;
+	case vc_string:
+		printf("%s\n", var->u.string_v->value);
+		break;
+	default:
+		printf("Unimplemented: writeLine() with unsupported type.\n");
+		exit(1);
+	}
+}
+
+/** Start an executable and wait for it to finish. */
+static void bi_fun_task_exec(run_t *run)
+{
+	rdata_var_t *args;
+	rdata_var_t *var;
+	rdata_array_t *array;
+	rdata_var_t *arg;
+	int idx, dim;
+	char **cmd;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Called Task.Exec()\n");
+#endif
+	args = run_local_vars_lookup(run, strtab_get_sid("args"));
+
+	assert(args);
+	assert(args->vc == vc_ref);
+
+	var = args->u.ref_v->vref;
+	assert(var->vc == vc_array);
+
+	array = var->u.array_v;
+	assert(array->rank == 1);
+	dim = array->extent[0];
+
+	if (dim == 0) {
+		printf("Error: Builtin.Exec() expects at least one argument.\n");
+		exit(1);
+	}
+
+	cmd = calloc(dim + 1, sizeof(char *));
+	if (cmd == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	for (idx = 0; idx < dim; ++idx) {
+		arg = array->element[idx];
+		if (arg->vc != vc_string) {
+			printf("Error: Argument to Builtin.Exec() must be "
+			    "string (found %d).\n", arg->vc);
+			exit(1);
+		}
+
+		cmd[idx] = arg->u.string_v->value;
+	}
+
+	cmd[dim] = '\0';
+
+	if (os_exec(cmd) != EOK) {
+		printf("Error: Exec failed.\n");
+		exit(1);
+	}
+}
Index: uspace/app/sbi/src/builtin/bi_fun.h
===================================================================
--- uspace/app/sbi/src/builtin/bi_fun.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/builtin/bi_fun.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef BI_FUN_H_
+#define BI_FUN_H_
+
+#include "../mytypes.h"
+
+void bi_fun_declare(builtin_t *bi);
+void bi_fun_bind(builtin_t *bi);
+
+#endif
Index: uspace/app/sbi/src/builtin/bi_textfile.c
===================================================================
--- uspace/app/sbi/src/builtin/bi_textfile.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/builtin/bi_textfile.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,359 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file TextFile builtin binding. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "../bigint.h"
+#include "../builtin.h"
+#include "../debug.h"
+#include "../mytypes.h"
+#include "../os/os.h"
+#include "../rdata.h"
+#include "../run.h"
+#include "../strtab.h"
+
+#include "bi_textfile.h"
+
+#define LINE_BUF_SIZE 256
+static char line_buf[LINE_BUF_SIZE];
+
+static void bi_textfile_openread(run_t *run);
+static void bi_textfile_openwrite(run_t *run);
+static void bi_textfile_close(run_t *run);
+static void bi_textfile_readline(run_t *run);
+static void bi_textfile_writeline(run_t *run);
+static void bi_textfile_is_eof(run_t *run);
+
+/** Declare TextFile builtin. */
+void bi_textfile_declare(builtin_t *bi)
+{
+	/* Declare class TextFile. */
+
+	builtin_code_snippet(bi,
+		"class TextFile is\n"
+			"var f : resource;\n"
+			"\n"
+			"fun OpenRead(fname : string), builtin;\n"
+			"fun OpenWrite(fname : string), builtin;\n"
+			"fun Close(), builtin;\n"
+			"fun ReadLine() : string, builtin;\n"
+			"fun WriteLine(line : string), builtin;\n"
+			"\n"
+			"prop EOF : int is\n"
+				"get is\n"
+					"return is_eof();\n"
+				"end\n"
+			"end\n"
+			"\n"
+			"fun is_eof() : int, builtin;\n"
+		"end\n");
+
+}
+
+/** Bind TextFile builtin. */
+void bi_textfile_bind(builtin_t *bi)
+{
+	builtin_fun_bind(bi, "TextFile", "OpenRead", bi_textfile_openread);
+	builtin_fun_bind(bi, "TextFile", "OpenWrite", bi_textfile_openwrite);
+	builtin_fun_bind(bi, "TextFile", "Close", bi_textfile_close);
+	builtin_fun_bind(bi, "TextFile", "ReadLine", bi_textfile_readline);
+	builtin_fun_bind(bi, "TextFile", "WriteLine", bi_textfile_writeline);
+	builtin_fun_bind(bi, "TextFile", "is_eof", bi_textfile_is_eof);
+}
+
+/** Open a text file for reading. */
+static void bi_textfile_openread(run_t *run)
+{
+	rdata_var_t *fname_var;
+	char *fname;
+	FILE *file;
+
+	rdata_resource_t *resource;
+	rdata_var_t *res_var;
+	rdata_value_t *res_val;
+	rdata_var_t *self_f_var;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Called TextFile.OpenRead()\n");
+#endif
+	fname_var = run_local_vars_lookup(run, strtab_get_sid("fname"));
+	assert(fname_var);
+	assert(fname_var->vc == vc_string);
+
+	fname = fname_var->u.string_v->value;
+	file = fopen(fname, "rt");
+	if (file == NULL) {
+		printf("Error: Failed opening file '%s' for reading.\n",
+		    fname);
+		exit(1);
+	}
+
+	resource = rdata_resource_new();
+	resource->data = (void *) file;
+	res_var = rdata_var_new(vc_resource);
+	res_var->u.resource_v = resource;
+
+	res_val = rdata_value_new();
+	res_val->var = res_var;
+
+	/* Store resource handle into self.f */
+	self_f_var = builtin_get_self_mbr_var(run, "f");
+	rdata_var_write(self_f_var, res_val);
+}
+
+/** Open a text file for writing. */
+static void bi_textfile_openwrite(run_t *run)
+{
+	rdata_var_t *fname_var;
+	char *fname;
+	FILE *file;
+
+	rdata_resource_t *resource;
+	rdata_var_t *res_var;
+	rdata_value_t *res_val;
+	rdata_var_t *self_f_var;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Called TextFile.OpenWrite()\n");
+#endif
+	fname_var = run_local_vars_lookup(run, strtab_get_sid("fname"));
+	assert(fname_var);
+	assert(fname_var->vc == vc_string);
+
+	fname = fname_var->u.string_v->value;
+	file = fopen(fname, "wt");
+	if (file == NULL) {
+		printf("Error: Failed opening file '%s' for writing.\n",
+		    fname);
+		exit(1);
+	}
+
+	resource = rdata_resource_new();
+	resource->data = (void *) file;
+	res_var = rdata_var_new(vc_resource);
+	res_var->u.resource_v = resource;
+
+	res_val = rdata_value_new();
+	res_val->var = res_var;
+
+	/* Store resource handle into self.f */
+	self_f_var = builtin_get_self_mbr_var(run, "f");
+	rdata_var_write(self_f_var, res_val);
+}
+
+/** Close a text file. */
+static void bi_textfile_close(run_t *run)
+{
+	FILE *file;
+        rdata_var_t *self_f_var;
+	run_proc_ar_t *proc_ar;
+
+	/* Extract pointer to file structure. */
+	self_f_var = builtin_get_self_mbr_var(run, "f");
+	assert(self_f_var->vc == vc_resource);
+	file = (FILE *) self_f_var->u.resource_v->data;
+
+	if (file == NULL) {
+		printf("Error: TextFile not valid for Close.\n");
+		exit(1);
+	}
+
+	/* Close the file. */
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Close text file.\n");
+#endif
+	if (fclose(file) != 0) {
+		printf("Error: I/O error while closing file.\n");
+		exit(1);
+	}
+
+	/* Invalidate the resource handle. */
+	self_f_var->u.resource_v->data = NULL;
+
+	proc_ar = run_get_current_proc_ar(run);
+	proc_ar->retval = NULL;
+}
+
+
+/** Read one line from a text file. */
+static void bi_textfile_readline(run_t *run)
+{
+	FILE *file;
+        rdata_var_t *self_f_var;
+
+	rdata_string_t *str;
+	rdata_var_t *str_var;
+	rdata_value_t *str_val;
+	rdata_item_t *str_item;
+
+	run_proc_ar_t *proc_ar;
+	char *cp;
+
+	/* Extract pointer to file structure. */
+	self_f_var = builtin_get_self_mbr_var(run, "f");
+	assert(self_f_var->vc == vc_resource);
+	file = (FILE *) self_f_var->u.resource_v->data;
+
+	if (file == NULL) {
+		printf("Error: TextFile not valid for ReadLine.\n");
+		exit(1);
+	}
+
+	/* Check and read. */
+
+	if (feof(file)) {
+		printf("Error: Reading beyond end of file.\n");
+		exit(1);
+	}
+
+	if (fgets(line_buf, LINE_BUF_SIZE, file) == NULL)
+		line_buf[0] = '\0';
+
+	if (ferror(file)) {
+		printf("Error: I/O error while reading file.\n");
+		exit(1);
+	}
+
+	/* Remove trailing newline, if present. */
+
+	cp = line_buf;
+	while (*cp != '\0')
+		++cp;
+
+	if (cp != line_buf && cp[-1] == '\n')
+		cp[-1] = '\0';
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Read '%s' from file.\n", line_buf);
+#endif
+	/* Construct return value. */
+	str = rdata_string_new();
+	str->value = os_str_dup(line_buf);
+
+	str_var = rdata_var_new(vc_string);
+	str_var->u.string_v = str;
+	str_val = rdata_value_new();
+	str_val->var = str_var;
+
+	str_item = rdata_item_new(ic_value);
+	str_item->u.value = str_val;
+
+	proc_ar = run_get_current_proc_ar(run);
+	proc_ar->retval = str_item;
+}
+
+/** Write one line to a text file. */
+static void bi_textfile_writeline(run_t *run)
+{
+	FILE *file;
+        rdata_var_t *self_f_var;
+	rdata_var_t *line_var;
+	char *line;
+
+	run_proc_ar_t *proc_ar;
+
+	/* Get 'line' argument. */
+	line_var = run_local_vars_lookup(run, strtab_get_sid("line"));
+	assert(line_var);
+	assert(line_var->vc == vc_string);
+	line = line_var->u.string_v->value;
+
+	/* Extract pointer to file structure. */
+	self_f_var = builtin_get_self_mbr_var(run, "f");
+	assert(self_f_var->vc == vc_resource);
+	file = (FILE *) self_f_var->u.resource_v->data;
+
+	if (file == NULL) {
+		printf("Error: TextFile not valid for WriteLine.\n");
+		exit(1);
+	}
+
+	/* Write and check. */
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Write '%s' to file.\n", line);
+#endif
+	if (fprintf(file, "%s\n", line) < 0) {
+		printf("Error: I/O error while writing file.\n");
+		exit(1);
+	}
+
+	proc_ar = run_get_current_proc_ar(run);
+	proc_ar->retval = NULL;
+}
+
+/** Return value of EOF flag. */
+static void bi_textfile_is_eof(run_t *run)
+{
+	FILE *file;
+        rdata_var_t *self_f_var;
+
+	int eof_flag;
+	rdata_int_t *eof_int;
+	rdata_var_t *eof_var;
+	rdata_value_t *eof_val;
+	rdata_item_t *eof_item;
+
+	run_proc_ar_t *proc_ar;
+
+	/* Extract pointer to file structure. */
+	self_f_var = builtin_get_self_mbr_var(run, "f");
+	assert(self_f_var->vc == vc_resource);
+	file = (FILE *) self_f_var->u.resource_v->data;
+
+	if (file == NULL) {
+		printf("Error: TextFile not valid for EOF check.\n");
+		exit(1);
+	}
+
+	/* Get status of EOF flag. */
+
+	eof_flag = feof(file) ? 1 : 0;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Read EOF flag '%d'.\n", eof_flag);
+#endif
+	/* Construct return value. */
+	eof_int = rdata_int_new();
+	bigint_init(&eof_int->value, eof_flag);
+
+	eof_var = rdata_var_new(vc_int);
+	eof_var->u.int_v = eof_int;
+	eof_val = rdata_value_new();
+	eof_val->var = eof_var;
+
+	eof_item = rdata_item_new(ic_value);
+	eof_item->u.value = eof_val;
+
+	proc_ar = run_get_current_proc_ar(run);
+	proc_ar->retval = eof_item;
+}
Index: uspace/app/sbi/src/builtin/bi_textfile.h
===================================================================
--- uspace/app/sbi/src/builtin/bi_textfile.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/builtin/bi_textfile.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef BI_TEXTFILE_H_
+#define BI_TEXTFILE_H_
+
+#include "../mytypes.h"
+
+void bi_textfile_declare(builtin_t *bi);
+void bi_textfile_bind(builtin_t *bi);
+
+#endif
Index: uspace/app/sbi/src/builtin_t.h
===================================================================
--- uspace/app/sbi/src/builtin_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/builtin_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef BUILTIN_T_H_
+#define BUILTIN_T_H_
+
+#include "run_t.h"
+
+/** Builtin symbols object
+ *
+ * Aggregates references to builtin symbols.
+ */
+typedef struct builtin {
+	/** Containing program object */
+	struct stree_program *program;
+
+	/** Grandfather object */
+	struct stree_symbol *gf_class;
+
+	/** Error class for nil reference access. */
+	struct stree_csi *error_nilreference;
+
+	/** Error class for out-of-bounds array access. */
+	struct stree_csi *error_outofbounds;
+} builtin_t;
+
+/** Callback to run for a builtin procedure */
+typedef void (*builtin_proc_t)(run_t *);
+
+#endif
Index: uspace/app/sbi/src/compat.h
===================================================================
--- uspace/app/sbi/src/compat.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/compat.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file HelenOS compatibility hacks.
+ *
+ * This must be included later than HelenOS's list.h.
+ * XXX A better way must be found than this.
+ */
+
+#ifndef COMPAT_H_
+#define COMPAT_H_
+
+#ifdef __HELENOS__
+
+/*
+ * Avoid name conflicts with ADT library.
+ */
+#define list_append sbi_list_append
+#define list_prepend sbi_list_prepend
+#define list_remove sbi_list_remove
+
+#endif
+
+#endif
Index: uspace/app/sbi/src/debug.h
===================================================================
--- uspace/app/sbi/src/debug.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/debug.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef DEBUG_H_
+#define DEBUG_H_
+
+/** Uncomment this to get verbose debugging messages during parsing. */
+//#define DEBUG_PARSE_TRACE
+
+/**
+ *Uncomment this to get extra verbose messages from parser's lexing
+ * primitives.
+ */
+//#define DEBUG_LPARSE_TRACE
+
+/** Uncomment this to get verbose debugging messagges during typing. */
+//#define DEBUG_TYPE_TRACE
+
+/** Uncomment this to get verbose debugging messages during execution. */
+//#define DEBUG_RUN_TRACE
+
+/** Uncomment this to get verbose debugging messages for bigint computation. */
+//#define DEBUG_BIGINT_TRACE
+
+#endif
Index: uspace/app/sbi/src/imode.c
===================================================================
--- uspace/app/sbi/src/imode.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/imode.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Interactive mode.
+ *
+ * In interactive mode the user types in statements. As soon as the outermost
+ * statement is complete (terminated with ';' or 'end'), the interpreter
+ * executes it. Otherwise it prompts the user until the entire statement
+ * is read in.
+ *
+ * The user interface depends on the OS. In HelenOS we use the CLUI library
+ * which gives us rich line editing capabilities.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "os/os.h"
+#include "ancr.h"
+#include "assert.h"
+#include "builtin.h"
+#include "intmap.h"
+#include "list.h"
+#include "mytypes.h"
+#include "program.h"
+#include "rdata.h"
+#include "stree.h"
+#include "strtab.h"
+#include "stype.h"
+#include "input.h"
+#include "lex.h"
+#include "parse.h"
+#include "run.h"
+
+#include "imode.h"
+
+/** Run in interactive mode.
+ *
+ * Repeatedly read in statements from the user and execute them.
+ */
+void imode_run(void)
+{
+	input_t *input;
+	lex_t lex;
+	parse_t parse;
+	stree_program_t *program;
+	stree_stat_t *stat;
+	stree_proc_t *proc;
+	stree_fun_t *fun;
+	stree_symbol_t *fun_sym;
+	stype_t stype;
+	stype_block_vr_t *block_vr;
+	list_node_t *bvr_n;
+	rdata_item_t *rexpr;
+	rdata_item_t *rexpr_vi;
+
+	run_t run;
+	run_proc_ar_t *proc_ar;
+
+	bool_t quit_im;
+
+	/* Create an empty program. */
+	program = stree_program_new();
+	program->module = stree_module_new();
+
+	/* Declare builtin symbols. */
+	builtin_declare(program);
+
+	/* Process the library. */
+	if (program_lib_process(program) != EOK)
+		exit(1);
+
+	/* Resolve ancestry. */
+	ancr_module_process(program, program->module);
+
+	/* Construct typing context. */
+	stype.program = program;
+	stype.proc_vr = stype_proc_vr_new();
+	list_init(&stype.proc_vr->block_vr);
+	stype.current_csi = NULL;
+	proc = stree_proc_new();
+
+	fun = stree_fun_new();
+	fun_sym = stree_symbol_new(sc_fun);
+	fun_sym->u.fun = fun;
+	fun->name = stree_ident_new();
+	fun->name->sid = strtab_get_sid("$imode");
+
+	stype.proc_vr->proc = proc;
+	fun->symbol = fun_sym;
+	proc->outer_symbol = fun_sym;
+
+	/* Create block visit record. */
+	block_vr = stype_block_vr_new();
+	intmap_init(&block_vr->vdecls);
+
+	/* Add block visit record to the stack. */
+	list_append(&stype.proc_vr->block_vr, block_vr);
+
+	/* Construct run context. */
+	run.thread_ar = run_thread_ar_new();
+	list_init(&run.thread_ar->proc_ar);
+	run_proc_ar_create(&run, NULL, proc, &proc_ar);
+	list_append(&run.thread_ar->proc_ar, proc_ar);
+
+	printf("SBI interactive mode. ");
+	os_input_disp_help();
+
+	quit_im = b_false;
+	while (quit_im != b_true) {
+		parse.error = b_false;
+		stype.error = b_false;
+		run.thread_ar->exc_payload = NULL;
+		run.thread_ar->bo_mode = bm_none;
+
+		input_new_interactive(&input);
+
+		/* Parse input. */
+		lex_init(&lex, input);
+		parse_init(&parse, program, &lex);
+
+		if (lcur_lc(&parse) == lc_eof)
+			break;
+
+		stat = parse_stat(&parse);
+
+		if (parse.error != b_false)
+			continue;
+
+		/* Type statement. */
+		stype_stat(&stype, stat, b_true);
+
+		if (stype.error != b_false)
+			continue;
+
+		/* Run statement. */
+		run_init(&run);
+		run.program = program;
+		run_stat(&run, stat, &rexpr);
+
+		/* Check for unhandled exceptions. */
+		run_exc_check_unhandled(&run);
+
+		if (rexpr != NULL) {
+			/* Convert expression result to value item. */
+			run_cvt_value_item(&run, rexpr, &rexpr_vi);
+			assert(rexpr_vi->ic == ic_value);
+
+			/* Print result. */
+			printf("Result: ");
+			rdata_value_print(rexpr_vi->u.value);
+			printf("\n");
+		}
+	}
+
+	/* Remove block visit record from the stack, */
+	bvr_n = list_last(&stype.proc_vr->block_vr);
+	assert(list_node_data(bvr_n, stype_block_vr_t *) == block_vr);
+	list_remove(&stype.proc_vr->block_vr, bvr_n);
+
+	printf("\nBye!\n");
+}
Index: uspace/app/sbi/src/imode.h
===================================================================
--- uspace/app/sbi/src/imode.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/imode.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef IMODE_H_
+#define IMODE_H_
+
+void imode_run(void);
+
+#endif
Index: uspace/app/sbi/src/input.c
===================================================================
--- uspace/app/sbi/src/input.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/input.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,235 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Input module
+ *
+ * Reads source code. Currently input can be read from a file (standard
+ * case), from a string literal (when parsing builtin code) or interactively
+ * from the user.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "mytypes.h"
+#include "os/os.h"
+#include "strtab.h"
+
+#include "input.h"
+
+/** Size of input buffer. XXX This limits the maximum line length. */
+#define INPUT_BUFFER_SIZE 256
+
+static int input_init_file(input_t *input, const char *fname);
+static void input_init_interactive(input_t *input);
+static void input_init_string(input_t *input, const char *str);
+
+/** Create new input object for reading from file.
+ *
+ * @param input		Place to store pointer to new input object.
+ * @param fname		Name of file to read from.
+ *
+ * @return		EOK on success, ENOMEM when allocation fails,
+ *			ENOENT when opening file fails.
+ */
+int input_new_file(input_t **input, const char *fname)
+{
+	*input = malloc(sizeof(input_t));
+	if (*input == NULL)
+		return ENOMEM;
+
+	return input_init_file(*input, fname);
+}
+
+/** Create new input object for reading from interactive input.
+ *
+ * @param input		Place to store pointer to new input object.
+ * @return		EOK on success, ENOMEM when allocation fails.
+ */
+int input_new_interactive(input_t **input)
+{
+	*input = malloc(sizeof(input_t));
+	if (*input == NULL)
+		return ENOMEM;
+
+	input_init_interactive(*input);
+	return EOK;
+}
+
+/** Create new input object for reading from string.
+ *
+ * @param input		Place to store pointer to new input object.
+ * @param str		String literal from which to read input.
+ * @return		EOK on success, ENOMEM when allocation fails.
+ */
+int input_new_string(input_t **input, const char *str)
+{
+	*input = malloc(sizeof(input_t));
+	if (*input == NULL)
+		return ENOMEM;
+
+	input_init_string(*input, str);
+	return EOK;
+}
+
+/** Initialize input object for reading from file.
+ *
+ * @param input		Input object.
+ * @param fname		Name of file to read from.
+ *
+ * @return		EOK on success, ENOENT when opening file fails.
+*/
+static int input_init_file(input_t *input, const char *fname)
+{
+	FILE *f;
+
+	f = fopen(fname, "rt");
+	if (f == NULL)
+		return ENOENT;
+
+	input->buffer = malloc(INPUT_BUFFER_SIZE);
+	if (input->buffer == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	input->str = NULL;
+	input->line_no = 0;
+	input->fin = f;
+	return EOK;
+}
+
+/** Initialize input object for reading from interactive input.
+ *
+ * @param input		Input object.
+ */
+static void input_init_interactive(input_t *input)
+{
+	input->buffer = malloc(INPUT_BUFFER_SIZE);
+	if (input->buffer == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	input->str = NULL;
+	input->line_no = 0;
+	input->fin = NULL;
+}
+
+/** Initialize input object for reading from string.
+ *
+ * @param input		Input object.
+ * @param str		String literal from which to read input.
+ */
+static void input_init_string(input_t *input, const char *str)
+{
+	input->buffer = malloc(INPUT_BUFFER_SIZE);
+	if (input->buffer == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	input->str = str;
+	input->line_no = 0;
+	input->fin = NULL;
+}
+
+/** Get next line of input.
+ *
+ * The pointer stored in @a line is owned by @a input and is valid until the
+ * next call to input_get_line(). The caller is not to free it. The returned
+ * line is terminated with '\n' if another line is coming (potentially empty).
+ * An empty line ("") signals end of input.
+ *
+ * @param input		Input object.
+ * @param line		Place to store pointer to next line.
+ *
+ * @return		EOK on success, EIO on failure.
+ */
+int input_get_line(input_t *input, char **line)
+{
+	const char *sp;
+	char *dp;
+	char *line_p;
+	size_t cnt;
+
+	if (input->fin != NULL) {
+		/* Reading from file. */
+		if (fgets(input->buffer, INPUT_BUFFER_SIZE, input->fin) == NULL)
+			input->buffer[0] = '\0';
+
+		if (ferror(input->fin))
+			return EIO;
+
+		*line = input->buffer;
+	} else if (input->str != NULL) {
+		/* Reading from a string constant. */
+
+		/* Copy one line. */
+		sp = input->str;
+		dp = input->buffer;
+		cnt = 0;
+		while (*sp != '\n' && *sp != '\0' &&
+		    cnt < INPUT_BUFFER_SIZE - 2) {
+			*dp++ = *sp++;
+		}
+
+		/* Advance to start of next line. */
+		if (*sp == '\n')
+			*dp++ = *sp++;
+
+		*dp++ = '\0';
+		input->str = sp;
+		*line = input->buffer;
+	} else {
+		/* Interactive mode */
+		if (input->line_no == 0)
+			printf("sbi> ");
+		else
+			printf("...  ");
+
+		fflush(stdout);
+		if (os_input_line(&line_p) != EOK)
+			return EIO;
+
+		*line = line_p;
+	}
+
+	++input->line_no;
+	return EOK;
+}
+
+/** Get number of the last provided line of input.
+ *
+ * @param input		Input module.
+ * @return		Line number of the last provided input line (counting
+ *			from 1 up).
+ */
+int input_get_line_no(input_t *input)
+{
+	return input->line_no;
+}
Index: uspace/app/sbi/src/input.h
===================================================================
--- uspace/app/sbi/src/input.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/input.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef INPUT_H_
+#define INPUT_H_
+
+#include "mytypes.h"
+
+int input_new_file(input_t **input, const char *fname);
+int input_new_interactive(input_t **input);
+int input_new_string(input_t **input, const char *str);
+
+int input_get_line(input_t *input, char **line);
+int input_get_line_no(input_t *input);
+
+#endif
Index: uspace/app/sbi/src/input_t.h
===================================================================
--- uspace/app/sbi/src/input_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/input_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef INPUT_T_H_
+#define INPUT_T_H_
+
+#include <stdio.h>
+
+/** Input state object */
+typedef struct input {
+	/** Input file if reading from file. */
+	FILE *fin;
+
+	/** Input string if reading from string. */
+	const char *str;
+
+	/** Buffer holding current line. */
+	char *buffer;
+
+	/** Current line number */
+	int line_no;
+} input_t;
+
+#endif
Index: uspace/app/sbi/src/intmap.c
===================================================================
--- uspace/app/sbi/src/intmap.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/intmap.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Integer map.
+ *
+ * Maps integers to pointers (void *). Current implementation is trivial
+ * (linked list of key-value pairs).
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "list.h"
+#include "mytypes.h"
+
+#include "intmap.h"
+
+/** Initialize map.
+ *
+ * @param intmap	Map to initialize.
+ */
+void intmap_init(intmap_t *intmap)
+{
+	list_init(&intmap->elem);
+}
+
+/** Set value corresponding to a key.
+ *
+ * If there already exists a mapping for @a key in the map, it is
+ * silently replaced. If @a value is @c NULL, the mapping for @a key
+ * is removed from the map.
+ *
+ * @param intmap	Map.
+ * @param key		Key (integer).
+ * @param value		Value (must be a pointer) or @c NULL.
+ */
+void intmap_set(intmap_t *intmap, int key, void *value)
+{
+	list_node_t *node;
+	map_elem_t *elem;
+
+	node = list_first(&intmap->elem);
+	while (node != NULL) {
+		elem = list_node_data(node, map_elem_t *);
+		if (elem->key == key) {
+			if (value != NULL) {
+				/* Replace existing value. */
+				elem->value = value;
+			} else {
+				/* Remove map element. */
+				list_remove(&intmap->elem, node);
+				node->data = NULL;
+				free(node);
+			}
+			return;
+		}
+		node = list_next(&intmap->elem, node);
+	}
+
+	/* Allocate new map element and add it to the list. */
+
+	elem = calloc(1, sizeof(map_elem_t));
+	if (elem == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	elem->key = key;
+	elem->value = value;
+	list_append(&intmap->elem, elem);
+}
+
+/** Get value corresponding to a key.
+ *
+ * @param intmap	Map.
+ * @param key		Key for which to retrieve mapping.
+ *
+ * @return		Value correspoding to @a key or @c NULL if no mapping
+ *			exists.
+ */
+void *intmap_get(intmap_t *intmap, int key)
+{
+	list_node_t *node;
+	map_elem_t *elem;
+
+	node = list_first(&intmap->elem);
+	while (node != NULL) {
+		elem = list_node_data(node, map_elem_t *);
+		if (elem->key == key) {
+			return elem->value;
+		}
+		node = list_next(&intmap->elem, node);
+	}
+
+	/* Not found */
+	return NULL;
+}
Index: uspace/app/sbi/src/intmap.h
===================================================================
--- uspace/app/sbi/src/intmap.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/intmap.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef INTMAP_H_
+#define INTMAP_H_
+
+#include "mytypes.h"
+
+void intmap_init(intmap_t *intmap);
+void intmap_set(intmap_t *intmap, int key, void *data);
+void *intmap_get(intmap_t *intmap, int key);
+
+#endif
Index: uspace/app/sbi/src/intmap_t.h
===================================================================
--- uspace/app/sbi/src/intmap_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/intmap_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef INTMAP_T_H_
+#define INTMAP_T_H_
+
+#include "list_t.h"
+
+typedef struct {
+	int key;
+	void *value;
+} map_elem_t;
+
+typedef struct intmap {
+	list_t elem; /* of (map_elem_t *) */
+} intmap_t;
+
+#endif
Index: uspace/app/sbi/src/lex.c
===================================================================
--- uspace/app/sbi/src/lex.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/lex.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,694 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Lexer (lexical analyzer).
+ *
+ * Consumes a text file and produces a sequence of lexical elements (lems).
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "bigint.h"
+#include "mytypes.h"
+#include "input.h"
+#include "os/os.h"
+#include "strtab.h"
+
+#include "lex.h"
+
+#define TAB_WIDTH 8
+
+static void lex_touch(lex_t *lex);
+static bool_t lex_read_try(lex_t *lex);
+
+static void lex_skip_comment(lex_t *lex);
+static void lex_skip_ws(lex_t *lex);
+static bool_t is_wstart(char c);
+static bool_t is_wcont(char c);
+static bool_t is_digit(char c);
+static void lex_word(lex_t *lex);
+static void lex_char(lex_t *lex);
+static void lex_number(lex_t *lex);
+static void lex_string(lex_t *lex);
+static int digit_value(char c);
+
+/* Note: This imposes an implementation limit on identifier length. */
+#define IBUF_SIZE 128
+static char ident_buf[IBUF_SIZE + 1];
+
+/* XXX This imposes an implementation limit on string literal length. */
+#define SLBUF_SIZE 128
+static char strlit_buf[SLBUF_SIZE + 1];
+
+/** Lclass-string pair */
+struct lc_name {
+	lclass_t lclass;
+	const char *name;
+};
+
+/** Keyword names. Used both for printing and recognition. */
+static struct lc_name keywords[] = {
+	{ lc_as,	"as" },
+	{ lc_bool,	"bool" },
+	{ lc_char,	"char" },
+	{ lc_builtin,	"builtin" },
+	{ lc_class,	"class" },
+	{ lc_constructor,	"constructor" },
+	{ lc_do,	"do" },
+	{ lc_else,	"else" },
+	{ lc_end,	"end" },
+	{ lc_except,	"except" },
+	{ lc_false,	"false" },
+	{ lc_finally,	"finally" },
+	{ lc_for,	"for" },
+	{ lc_fun,	"fun" },
+	{ lc_get,	"get" },
+	{ lc_if,	"if" },
+	{ lc_in,	"in" },
+	{ lc_int,	"int" },
+	{ lc_interface,	"interface" },
+	{ lc_is,	"is" },
+	{ lc_new,	"new" },
+	{ lc_nil,	"nil" },
+	{ lc_override,	"override" },
+	{ lc_packed,	"packed" },
+	{ lc_private,	"private" },
+	{ lc_prop,	"prop" },
+	{ lc_protected,	"protected" },
+	{ lc_public,	"public" },
+	{ lc_raise,	"raise" },
+	{ lc_resource,	"resource" },
+	{ lc_return,	"return" },
+	{ lc_self,	"self" },
+	{ lc_set,	"set" },
+	{ lc_static,	"static" },
+	{ lc_string,	"string" },
+	{ lc_struct,	"struct" },
+	{ lc_then,	"then" },
+	{ lc_this,	"this" },
+	{ lc_true,	"true" },
+	{ lc_var,	"var" },
+	{ lc_with,	"with" },
+	{ lc_while,	"while" },
+	{ lc_yield,	"yield" },
+
+	{ 0,		NULL }
+};
+
+/** Other simple lclasses. Only used for printing. */
+static struct lc_name simple_lc[] = {
+	{ lc_invalid,	"INVALID" },
+	{ lc_eof,	"EOF" },
+
+	/* Operators */
+	{ lc_period,	"." },
+	{ lc_slash,	"/" },
+	{ lc_lparen,	"(" },
+	{ lc_rparen,	")" },
+	{ lc_lsbr,	"[" },
+	{ lc_rsbr,	"]" },
+	{ lc_equal,	"==" },
+	{ lc_notequal,	"!=" },
+	{ lc_lt,	"<" },
+	{ lc_gt,	">" },
+	{ lc_lt_equal,	"<=" },
+	{ lc_gt_equal,	">=" },
+	{ lc_assign,	"=" },
+	{ lc_plus,	"+" },
+	{ lc_minus,	"-" },
+	{ lc_mult,	"*" },
+	{ lc_increase,	"+=" },
+
+	/* Punctuators */
+	{ lc_comma,	"," },
+	{ lc_colon,	":" },
+	{ lc_scolon,	";" },
+
+	{ 0,		NULL },
+};
+
+/** Print lclass value.
+ *
+ * Prints lclass (lexical element class) value in human-readable form
+ * (for debugging).
+ *
+ * @param lclass	Lclass value for display.
+ */
+void lclass_print(lclass_t lclass)
+{
+	struct lc_name *dp;
+
+	dp = keywords;
+	while (dp->name != NULL) {
+		if (dp->lclass == lclass) {
+			printf("%s", dp->name);
+			return;
+		}
+		++dp;
+	}
+
+	dp = simple_lc;
+	while (dp->name != NULL) {
+		if (dp->lclass == lclass) {
+			printf("%s", dp->name);
+			return;
+		}
+		++dp;
+	}
+
+	switch (lclass) {
+	case lc_ident:
+		printf("ident");
+		break;
+	case lc_lit_int:
+		printf("int_literal");
+		break;
+	case lc_lit_string:
+		printf("string_literal");
+		break;
+	default:
+		printf("<unknown?>");
+		break;
+	}
+}
+
+/** Print lexical element.
+ *
+ * Prints lexical element in human-readable form (for debugging).
+ *
+ * @param lem		Lexical element for display.
+ */
+void lem_print(lem_t *lem)
+{
+	lclass_print(lem->lclass);
+
+	switch (lem->lclass) {
+	case lc_ident:
+		printf("(%d)", lem->u.ident.sid);
+		break;
+	case lc_lit_int:
+		printf("(");
+		bigint_print(&lem->u.lit_int.value);
+		printf(")");
+		break;
+	case lc_lit_string:
+		printf("(\"%s\")", lem->u.lit_string.value);
+	default:
+		break;
+	}
+}
+
+/** Print lem coordinates.
+ *
+ * Print the coordinates (line number, column number) of a lexical element.
+ *
+ * @param lem		Lexical element for coordinate printing.
+ */
+void lem_print_coords(lem_t *lem)
+{
+	printf("%d:%d", lem->line_no, lem->col_0);
+}
+
+/** Initialize lexer instance.
+ *
+ * @param lex		Lexer object to initialize.
+ * @param input		Input to associate with lexer.
+ */
+void lex_init(lex_t *lex, struct input *input)
+{
+	int rc;
+
+	lex->input = input;
+
+	rc = input_get_line(lex->input, &lex->inbuf);
+	if (rc != EOK) {
+		printf("Error reading input.\n");
+		exit(1);
+	}
+
+	lex->ibp = lex->inbuf;
+	lex->col_adj = 0;
+	lex->current_valid = b_true;
+}
+
+/** Advance to next lexical element.
+ *
+ * The new element is read in lazily then it is actually accessed.
+ *
+ * @param lex		Lexer object.
+ */
+void lex_next(lex_t *lex)
+{
+	/* Make sure the current lem has already been read in. */
+	lex_touch(lex);
+
+	/* Force a new lem to be read on next access. */
+	lex->current_valid = b_false;
+}
+
+/** Get current lem.
+ *
+ * The returned pointer is invalidated by next call to lex_next()
+ *
+ * @param lex		Lexer object.
+ * @return		Pointer to current lem. Owned by @a lex and only valid
+ *			until next call to lex_next().
+ */
+lem_t *lex_get_current(lex_t *lex)
+{
+	lex_touch(lex);
+	return &lex->current;
+}
+
+/** Read in the current lexical element (unless already read in).
+ *
+ * @param lex		Lexer object.
+ */
+static void lex_touch(lex_t *lex)
+{
+	bool_t got_lem;
+
+	if (lex->current_valid == b_true)
+		return;
+
+	do {
+		got_lem = lex_read_try(lex);
+	} while (got_lem == b_false);
+
+	lex->current_valid = b_true;
+}
+
+/** Try reading next lexical element.
+ *
+ * Attemps to read the next lexical element. In some cases (such as a comment)
+ * this function will need to give it another try and returns @c b_false
+ * in such case.
+ *
+ * @param lex		Lexer object.
+ * @return		@c b_true on success or @c b_false if it needs
+ *			restarting. On success the lem is stored to
+ *			the current lem in @a lex.
+ */
+static bool_t lex_read_try(lex_t *lex)
+{
+	char *bp;
+
+	lex_skip_ws(lex);
+
+	/*
+	 * Record lem coordinates. Line number we already have. For column
+	 * number we start with position in the input buffer. This works
+	 * for all characters except tab. Thus we keep track of tabs
+	 * separately using col_adj.
+	 */
+	lex->current.line_no = input_get_line_no(lex->input);
+	lex->current.col_0 = 1 + lex->col_adj + (lex->ibp - lex->inbuf);
+
+	bp = lex->ibp;
+
+	if (bp[0] == '\0') {
+		/* End of input */
+		lex->current.lclass = lc_eof;
+		return b_true;
+	}
+
+	if (is_wstart(bp[0])) {
+		lex_word(lex);
+		return b_true;
+	}
+
+	if (bp[0] == '\'') {
+		lex_char(lex);
+		return b_true;
+	}
+
+	if (is_digit(bp[0])) {
+		lex_number(lex);
+		return b_true;
+	}
+
+	if (bp[0] == '"') {
+		lex_string(lex);
+		return b_true;
+	}
+
+	if (bp[0] == '-' && bp[1] == '-') {
+		lex_skip_comment(lex);
+		return b_false;
+	}
+
+	switch (bp[0]) {
+	case ',': lex->current.lclass = lc_comma; ++bp; break;
+	case ':': lex->current.lclass = lc_colon; ++bp; break;
+	case ';': lex->current.lclass = lc_scolon; ++bp; break;
+
+	case '.': lex->current.lclass = lc_period; ++bp; break;
+	case '/': lex->current.lclass = lc_slash; ++bp; break;
+	case '(': lex->current.lclass = lc_lparen; ++bp; break;
+	case ')': lex->current.lclass = lc_rparen; ++bp; break;
+	case '[': lex->current.lclass = lc_lsbr; ++bp; break;
+	case ']': lex->current.lclass = lc_rsbr; ++bp; break;
+
+	case '=':
+		if (bp[1] == '=') {
+			lex->current.lclass = lc_equal; bp += 2; break;
+		}
+		lex->current.lclass = lc_assign; ++bp; break;
+
+	case '!':
+		if (bp[1] == '=') {
+			lex->current.lclass = lc_notequal; bp += 2; break;
+		}
+		goto invalid;
+
+	case '+':
+		if (bp[1] == '=') {
+			lex->current.lclass = lc_increase; bp += 2; break;
+		}
+		lex->current.lclass = lc_plus; ++bp; break;
+
+	case '-':
+		lex->current.lclass = lc_minus; ++bp; break;
+
+	case '*':
+		lex->current.lclass = lc_mult; ++bp; break;
+
+	case '<':
+		if (bp[1] == '=') {
+			lex->current.lclass = lc_lt_equal; bp += 2; break;
+		}
+		lex->current.lclass = lc_lt; ++bp; break;
+
+	case '>':
+		if (bp[1] == '=') {
+			lex->current.lclass = lc_gt_equal; bp += 2; break;
+		}
+		lex->current.lclass = lc_gt; ++bp; break;
+
+	default:
+		goto invalid;
+	}
+
+	lex->ibp = bp;
+	return b_true;
+
+invalid:
+	lex->current.lclass = lc_invalid;
+	++bp;
+	lex->ibp = bp;
+
+	return b_true;
+}
+
+/** Lex a word (identifier or keyword).
+ *
+ * Read in a word. This may later turn out to be a keyword or a regular
+ * identifier. It is stored in the current lem in @a lex.
+ *
+ * @param lex		Lexer object.
+ */
+static void lex_word(lex_t *lex)
+{
+	struct lc_name *dp;
+	char *bp;
+	int idx;
+
+	bp = lex->ibp;
+	ident_buf[0] = bp[0];
+	idx = 1;
+
+	while (is_wcont(bp[idx])) {
+		if (idx >= IBUF_SIZE) {
+			printf("Error: Identifier too long.\n");
+			exit(1);
+		}
+
+		ident_buf[idx] = bp[idx];
+		++idx;
+	}
+
+	lex->ibp = bp + idx;
+
+	ident_buf[idx] = '\0';
+
+	dp = keywords;
+	while (dp->name != NULL) {
+		if (os_str_cmp(ident_buf, dp->name) == 0) {
+			/* Match */
+			lex->current.lclass = dp->lclass;
+			return;
+		}
+		++dp;
+	}
+
+	/* No matching keyword -- it must be an identifier. */
+	lex->current.lclass = lc_ident;
+	lex->current.u.ident.sid = strtab_get_sid(ident_buf);
+}
+
+/** Lex a character literal.
+ *
+ * Reads in a character literal and stores it in the current lem in @a lex.
+ *
+ * @param lex		Lexer object.
+ */
+static void lex_char(lex_t *lex)
+{
+	char *bp;
+	int idx;
+	size_t len;
+	int char_val;
+
+	bp = lex->ibp + 1;
+	idx = 0;
+
+	while (bp[idx] != '\'') {
+		if (idx >= SLBUF_SIZE) {
+			printf("Error: Character literal too long.\n");
+			exit(1);
+		}
+
+		if (bp[idx] == '\0') {
+			printf("Error: Unterminated character literal.\n");
+			exit(1);
+		}
+
+		strlit_buf[idx] = bp[idx];
+		++idx;
+	}
+
+	lex->ibp = bp + idx + 1;
+
+	strlit_buf[idx] = '\0';
+	len = os_str_length(strlit_buf);
+	if (len != 1) {
+		printf("Character literal should contain one character, "
+		    "but contains %u characters instead.\n", (unsigned) len);
+		exit(1);
+	}
+
+	os_str_get_char(strlit_buf, 0, &char_val);
+	lex->current.lclass = lc_lit_char;
+	bigint_init(&lex->current.u.lit_char.value, char_val);
+}
+
+/** Lex a numeric literal.
+ *
+ * Reads in a numeric literal and stores it in the current lem in @a lex.
+ *
+ * @param lex		Lexer object.
+ */
+static void lex_number(lex_t *lex)
+{
+	char *bp;
+	bigint_t value;
+	bigint_t dgval;
+	bigint_t base;
+	bigint_t tprod;
+
+	bp = lex->ibp;
+
+	bigint_init(&value, 0);
+	bigint_init(&base, 10);
+
+	while (is_digit(*bp)) {
+		bigint_mul(&value, &base, &tprod);
+		bigint_init(&dgval, digit_value(*bp));
+
+		bigint_destroy(&value);
+		bigint_add(&tprod, &dgval, &value);
+		bigint_destroy(&tprod);
+		bigint_destroy(&dgval);
+
+		++bp;
+	}
+
+	bigint_destroy(&base);
+
+	lex->ibp = bp;
+
+	lex->current.lclass = lc_lit_int;
+	bigint_shallow_copy(&value, &lex->current.u.lit_int.value);
+}
+
+/** Lex a string literal.
+ *
+ * Reads in a string literal and stores it in the current lem in @a lex.
+ *
+ * @param lex		Lexer object.
+ */
+static void lex_string(lex_t *lex)
+{
+	char *bp;
+	int idx;
+
+	bp = lex->ibp + 1;
+	idx = 0;
+
+	while (bp[idx] != '"') {
+		if (idx >= SLBUF_SIZE) {
+			printf("Error: String literal too long.\n");
+			exit(1);
+		}
+
+		if (bp[idx] == '\0') {
+			printf("Error: Unterminated string literal.\n");
+			exit(1);
+		}
+
+		strlit_buf[idx] = bp[idx];
+		++idx;
+	}
+
+	lex->ibp = bp + idx + 1;
+
+	strlit_buf[idx] = '\0';
+
+	lex->current.lclass = lc_lit_string;
+	lex->current.u.lit_string.value = os_str_dup(strlit_buf);
+}
+
+/** Lex a single-line comment.
+ *
+ * This does not produce any lem. The comment is just skipped.
+ *
+ * @param lex		Lexer object.
+ */
+static void lex_skip_comment(lex_t *lex)
+{
+	char *bp;
+
+	bp = lex->ibp + 2;
+
+	while (*bp != '\n' && *bp != '\0') {
+		++bp;
+	}
+
+	lex->ibp = bp;
+}
+
+/** Skip whitespace characters.
+ *
+ * This does not produce any lem. The whitespace is just skipped.
+ *
+ * @param lex		Lexer object.
+ */
+static void lex_skip_ws(lex_t *lex)
+{
+	char *bp;
+	int rc;
+
+	bp = lex->ibp;
+
+	while (b_true) {
+		while (*bp == ' ' || *bp == '\t') {
+			if (*bp == '\t') {
+				/* XXX This is too simplifed. */
+				lex->col_adj += (TAB_WIDTH - 1);
+			}
+			++bp;
+		}
+
+		if (*bp != '\n')
+			break;
+
+		/* Read next line */
+		rc = input_get_line(lex->input, &lex->inbuf);
+		if (rc != EOK) {
+			printf("Error reading input.\n");
+			exit(1);
+		}
+
+		bp = lex->inbuf;
+		lex->col_adj = 0;
+	}
+
+	lex->ibp = bp;
+}
+
+/** Determine if character can start a word.
+ *
+ * @param c 	Character.
+ * @return	@c b_true if @a c can start a word, @c b_false otherwise.
+ */
+static bool_t is_wstart(char c)
+{
+	return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) ||
+	    (c == '_');
+}
+
+/** Determine if character can continue a word.
+ *
+ * @param c 	Character.
+ * @return	@c b_true if @a c can start continue word, @c b_false
+ *		otherwise.
+ */
+static bool_t is_wcont(char c)
+{
+	return is_digit(c) || is_wstart(c);
+}
+
+/** Determine if character is a numeric digit.
+ *
+ * @param c 	Character.
+ * @return	@c b_true if @a c is a numeric digit, @c b_false otherwise.
+ */
+static bool_t is_digit(char c)
+{
+	return ((c >= '0') && (c <= '9'));
+}
+
+/** Determine numeric value of digit character.
+ *
+ * @param c 	Character, must be a valid decimal digit.
+ * @return	Value of the digit (0-9).
+ */
+static int digit_value(char c)
+{
+	return (c - '0');
+}
Index: uspace/app/sbi/src/lex.h
===================================================================
--- uspace/app/sbi/src/lex.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/lex.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef LEX_H_
+#define LEX_H_
+
+#include "mytypes.h"
+
+void lclass_print(lclass_t lclass);
+void lem_print(lem_t *lem);
+void lem_print_coords(lem_t *lem);
+
+void lex_init(lex_t *lex, struct input *input);
+void lex_next(lex_t *lex);
+lem_t *lex_get_current(lex_t *lex);
+
+#endif
Index: uspace/app/sbi/src/lex_t.h
===================================================================
--- uspace/app/sbi/src/lex_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/lex_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef LEX_T_H_
+#define LEX_T_H_
+
+#include "bigint_t.h"
+
+/** Lexical element class */
+typedef enum {
+	lc_invalid,
+	lc_eof,
+
+	lc_ident,
+	lc_lit_char,
+	lc_lit_int,
+	lc_lit_string,
+
+	/* Keywords */
+	lc_as,
+	lc_bool,
+	lc_builtin,
+	lc_char,
+	lc_class,
+	lc_constructor,
+	lc_do,
+	lc_else,
+	lc_end,
+	lc_except,
+	lc_false,
+	lc_finally,
+	lc_for,
+	lc_fun,
+	lc_new,
+	lc_get,
+	lc_if,
+	lc_in,
+	lc_int,
+	lc_interface,
+	lc_is,
+	lc_nil,
+	lc_override,
+	lc_packed,
+	lc_private,
+	lc_prop,
+	lc_protected,
+	lc_public,
+	lc_raise,
+	lc_resource,
+	lc_return,
+	lc_self,
+	lc_set,
+	lc_static,
+	lc_string,
+	lc_struct,
+	lc_then,
+	lc_this,
+	lc_true,
+	lc_var,
+	lc_with,
+	lc_while,
+	lc_yield,
+
+	/* Operators */
+	lc_period,
+	lc_slash,
+	lc_lparen,
+	lc_rparen,
+	lc_lsbr,
+	lc_rsbr,
+	lc_equal,
+	lc_notequal,
+	lc_lt,
+	lc_gt,
+	lc_lt_equal,
+	lc_gt_equal,
+	lc_assign,
+	lc_plus,
+	lc_minus,
+	lc_mult,
+	lc_increase,
+
+	/* Punctuators */
+	lc_comma,
+	lc_colon,
+	lc_scolon,
+
+	lc__limit
+} lclass_t;
+
+typedef struct {
+	/* String ID */
+	int sid;
+} lem_ident_t;
+
+typedef struct {
+	/* Character value */
+	bigint_t value;
+} lem_lit_char_t;
+
+typedef struct {
+	/* Integer value */
+	bigint_t value;
+} lem_lit_int_t;
+
+typedef struct {
+	/* String value */
+	char *value;
+} lem_lit_string_t;
+
+/** Lexical element */
+typedef struct {
+	/* Lexical element class */
+	lclass_t lclass;
+
+	union {
+		lem_ident_t ident;
+		lem_lit_char_t lit_char;
+		lem_lit_int_t lit_int;
+		lem_lit_string_t lit_string;
+	} u;
+
+	/** Coordinates of this lexical element */
+	int line_no, col_0;
+} lem_t;
+
+/** Lexer state object */
+typedef struct lex {
+	/** Input object */
+	struct input *input;
+
+	/** Lexing buffer */
+	char *inbuf;
+
+	/** Pointer to current position in lexing buffer */
+	char *ibp;
+
+	/** Number of the line currently in inbuf */
+	int ib_line;
+
+	/** Column number adjustment (due to tabs) */
+	int col_adj;
+
+	/** @c b_true if we have the next lem in @c current */
+	bool_t current_valid;
+
+	/** Curent lem (only valid if @c current_valid is true) */
+	lem_t current;
+} lex_t;
+
+#endif
Index: uspace/app/sbi/src/list.c
===================================================================
--- uspace/app/sbi/src/list.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/list.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,288 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Doubly linked list.
+ *
+ * Circular, with a head. Nodes structures are allocated separately from data.
+ * Data is stored as 'void *'. We implement several sanity checks to prevent
+ * common usage errors.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "mytypes.h"
+
+#include "list.h"
+
+static list_node_t *list_node_new(void *data);
+static void list_node_delete(list_node_t *node);
+static void list_node_insert_between(list_node_t *n, list_node_t *a, list_node_t *b);
+static void list_node_unlink(list_node_t *n);
+static bool_t list_node_present(list_t *list, list_node_t *node);
+
+/** Initialize list.
+ *
+ * @param list	List to initialize.
+ */
+void list_init(list_t *list)
+{
+	list->head.prev = &list->head;
+	list->head.next = &list->head;
+}
+
+/** Append data to list.
+ *
+ * Create a new list node and append it at the end of the list.
+ *
+ * @param list	Linked list.
+ * @param data	Data for the new node.
+ */
+void list_append(list_t *list, void *data)
+{
+	list_node_t *node;
+
+	node = list_node_new(data);
+	list_node_insert_between(node, list->head.prev, &list->head);
+}
+
+/** Prepend data to list.
+ *
+ * Create a new list node and prepend it at the beginning of the list.
+ *
+ * @param list	Linked list.
+ * @param data	Data for the new node.
+ */
+void list_prepend(list_t *list, void *data)
+{
+	list_node_t *node;
+
+	node = list_node_new(data);
+	list_node_insert_between(node, list->head.prev, &list->head);
+}
+
+/** Remove data from list.
+ *
+ * Removes the given node from a list and destroys it. Any data the node might
+ * have is ignored. If asserts are on, we check wheter node is really present
+ * in the list the caller is requesting us to remove it from.
+ *
+ * @param list	Linked list.
+ * @param node	List node to remove.
+ */
+void list_remove(list_t *list, list_node_t *node)
+{
+	/* Check whether node is in the list as claimed. */
+	assert(list_node_present(list, node));
+	list_node_unlink(node);
+	node->data = NULL;
+	list_node_delete(node);
+}
+
+/** Return first list node or NULL if list is empty.
+ *
+ * @param list	Linked list.
+ * @return	First node of the list or @c NULL if the list is empty.
+ */
+list_node_t *list_first(list_t *list)
+{
+	list_node_t *node;
+
+	assert(list != NULL);
+	node = list->head.next;
+
+	return (node != &list->head) ? node : NULL;
+}
+
+/** Return last list node or NULL if list is empty.
+ *
+ * @param list	Linked list.
+ * @return	Last node of the list or @c NULL if the list is empty.
+ */
+list_node_t *list_last(list_t *list)
+{
+	list_node_t *node;
+
+	assert(list != NULL);
+	node = list->head.prev;
+
+	return (node != &list->head) ? node : NULL;
+}
+
+/** Return next list node or NULL if this was the last one.
+ *
+ * @param list	Linked list.
+ * @param node	Node whose successor we are interested in.
+ * @return	Following list node or @c NULL if @a node is last.
+ */
+list_node_t *list_next(list_t *list, list_node_t *node)
+{
+	(void) list;
+	assert(list != NULL);
+	assert(node != NULL);
+
+	return (node->next != &list->head) ? node->next : NULL;
+}
+
+/** Return previous list node or NULL if this was the last one.
+ *
+ * @param list	Linked list.
+ * @param node	Node whose predecessor we are interested in.
+ * @return	Preceding list node or @c NULL if @a node is last.
+ */
+list_node_t *list_prev(list_t *list, list_node_t *node)
+{
+	(void) list;
+	assert(list != NULL);
+	assert(node != NULL);
+
+	return (node->prev != &list->head) ? node->prev : NULL;
+}
+
+/** Return b_true if list is empty.
+ *
+ * @param list	Linked list.
+ * @return	@c b_true if list is empty, @c b_false otherwise.
+ */
+bool_t list_is_empty(list_t *list)
+{
+	return (list_first(list) == NULL);
+}
+
+/** Change node data.
+ *
+ * Change the data associated with a node.
+ *
+ * @param node	List node.
+ * @param data	New data for node.
+ */
+void list_node_setdata(list_node_t *node, void *data)
+{
+	node->data = data;
+}
+
+/** Create new node.
+ *
+ * @param data	Initial data for node.
+ * @return	New list node.
+ */
+static list_node_t *list_node_new(void *data)
+{
+	list_node_t *node;
+
+	node = malloc(sizeof(list_node_t));
+	if (node == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	node->prev = NULL;
+	node->next = NULL;
+	node->data = data;
+
+	return node;
+}
+
+/** Delete node.
+ *
+ * @param node	List node. Must not take part in any list.
+ */
+static void list_node_delete(list_node_t *node)
+{
+	assert(node->prev == NULL);
+	assert(node->next == NULL);
+	assert(node->data == NULL);
+	free(node);
+}
+
+/** Insert node between two other nodes.
+ *
+ * Inserts @a n between neighboring nodes @a a and @a b.
+ *
+ * @param n	Node to insert.
+ * @param a	Node to precede @a n.
+ * @param b	Node to follow @a n.
+ */
+static void list_node_insert_between(list_node_t *n, list_node_t *a,
+    list_node_t *b)
+{
+	assert(n->prev == NULL);
+	assert(n->next == NULL);
+	n->prev = a;
+	n->next = b;
+
+	assert(a->next == b);
+	assert(b->prev == a);
+	a->next = n;
+	b->prev = n;
+}
+
+/** Unlink node.
+ *
+ * Unlink node from the list it is currently in.
+ * 
+ * @param n	Node to unlink from its current list.
+ */
+static void list_node_unlink(list_node_t *n)
+{
+	list_node_t *a, *b;
+	assert(n->prev != NULL);
+	assert(n->next != NULL);
+
+	a = n->prev;
+	b = n->next;
+
+	assert(a->next == n);
+	assert(b->prev == n);
+
+	a->next = b;
+	b->prev = a;
+
+	n->prev = NULL;
+	n->next = NULL;
+}
+
+/** Check whether @a node is in list @a list.
+ *
+ * @param list	Linked list.
+ * @param node	Node.
+ * @return	@c b_true if @a node is part of @a list, @c b_false otherwise.
+ */
+static bool_t list_node_present(list_t *list, list_node_t *node)
+{
+	list_node_t *m;
+
+	m = list->head.next;
+	while (m != &list->head) {
+		if (m == node)
+			return b_true;
+		m = m->next;
+	}
+
+	return b_false;
+}
Index: uspace/app/sbi/src/list.h
===================================================================
--- uspace/app/sbi/src/list.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/list.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef LIST_H_
+#define LIST_H_
+
+#include "mytypes.h"
+#include "compat.h"
+
+void list_init(list_t *list);
+void list_append(list_t *list, void *data);
+void list_prepend(list_t *list, void *data);
+void list_remove(list_t *list, list_node_t *node);
+
+list_node_t *list_first(list_t *list);
+list_node_t *list_last(list_t *list);
+list_node_t *list_next(list_t *list, list_node_t *node);
+list_node_t *list_prev(list_t *list, list_node_t *node);
+bool_t list_is_empty(list_t *list);
+
+void list_node_setdata(list_node_t *node, void *data);
+
+#define list_node_data(node, dtype) ((dtype)(node->data))
+
+#endif
Index: uspace/app/sbi/src/list_t.h
===================================================================
--- uspace/app/sbi/src/list_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/list_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef LIST_T_H_
+#define LIST_T_H_
+
+typedef struct list_node {
+	struct list_node *prev, *next;
+	void *data;
+} list_node_t;
+
+typedef struct list {
+	/** Empty head (no data) */
+	list_node_t head;
+} list_t;
+
+#endif
Index: uspace/app/sbi/src/main.c
===================================================================
--- uspace/app/sbi/src/main.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/main.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Main module.
+ *
+ * Main entry point for SBI, the Sysel Bootstrap Interpreter.
+ * When run without parameters, the interpreter will enter interactive
+ * mode.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "ancr.h"
+#include "os/os.h"
+#include "builtin.h"
+#include "imode.h"
+#include "mytypes.h"
+#include "program.h"
+#include "strtab.h"
+#include "stree.h"
+#include "stype.h"
+#include "input.h"
+#include "lex.h"
+#include "parse.h"
+#include "run.h"
+
+static void syntax_print(void);
+
+/** Main entry point.
+ *
+ * @return	Zero on success, non-zero on error.
+ */
+int main(int argc, char *argv[])
+{
+	stree_program_t *program;
+	stype_t stype;
+	run_t run;
+	int rc;
+
+	/* Store executable file path under which we have been invoked. */
+	os_store_ef_path(*argv);
+
+	argv += 1;
+	argc -= 1;
+
+	if (argc == 0) {
+		/* Enter interactive mode */
+		strtab_init();
+		imode_run();
+		return 0;
+	}
+
+	if (os_str_cmp(*argv, "-h") == 0) {
+		syntax_print();
+		return 0;
+	}
+
+	strtab_init();
+	program = stree_program_new();
+	program->module = stree_module_new();
+
+	/* Declare builtin symbols. */
+	builtin_declare(program);
+
+	/* Process source files in the library. */
+	if (program_lib_process(program) != EOK)
+		return 1;
+
+	/* Process all source files specified in command-line arguments. */
+	while (argc > 0) {
+		rc = program_file_process(program, *argv);
+		if (rc != EOK)
+			return 1;
+
+		argv += 1;
+		argc -= 1;
+	}
+
+	/* Resolve ancestry. */
+	ancr_module_process(program, program->module);
+
+	/* Type program. */
+	stype.program = program;
+	stype.error = b_false;
+	stype_module(&stype, program->module);
+
+	/* Check for typing errors. */
+	if (stype.error)
+		return 1;
+
+	/* Run program. */
+	run_init(&run);
+	run_program(&run, program);
+
+	/* Check for run-time errors. */
+	if (run.thread_ar->error)
+		return 1;
+
+	return 0;
+}
+
+/** Print command-line syntax help. */
+static void syntax_print(void)
+{
+	printf("Syntax: sbi <source_file.sy>\n");
+}
Index: uspace/app/sbi/src/mytypes.h
===================================================================
--- uspace/app/sbi/src/mytypes.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/mytypes.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef MYTYPES_H_
+#define MYTYPES_H_
+
+/** Boolean type compatible with builtin C 'boolean' operators. */
+typedef enum {
+	b_false = 0,
+	b_true = 1
+} bool_t;
+
+/** Node state for walks. */
+typedef enum {
+	ws_unvisited,
+	ws_active,
+	ws_visited
+} walk_state_t;
+
+/** Error return codes. */
+#include <errno.h>
+#define EOK 0
+
+#include "bigint_t.h"
+#include "builtin_t.h"
+#include "input_t.h"
+#include "intmap_t.h"
+#include "lex_t.h"
+#include "list_t.h"
+#include "parse_t.h"
+#include "rdata_t.h"
+#include "run_t.h"
+#include "stree_t.h"
+#include "strtab_t.h"
+#include "stype_t.h"
+#include "tdata_t.h"
+
+#endif
Index: uspace/app/sbi/src/os/helenos.c
===================================================================
--- uspace/app/sbi/src/os/helenos.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/os/helenos.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,183 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file HelenOS-specific code. */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <str.h>
+#include <task.h>
+#include <tinput.h>
+#include <str_error.h>
+
+#include "os.h"
+
+/** Path to executable file via which we have been invoked. */
+static char *ef_path;
+
+/*
+ * Using HelenOS-specific string API.
+ */
+
+static tinput_t *tinput = NULL;
+
+/** Concatenate two strings. */
+char *os_str_acat(const char *a, const char *b)
+{
+	int a_size, b_size;
+	char *str;
+
+	a_size = str_size(a);
+	b_size = str_size(b);
+
+	str = malloc(a_size + b_size + 1);
+	if (str == NULL) {
+		printf("Memory allocation error.\n");
+		exit(1);
+	}
+
+	memcpy(str, a, a_size);
+	memcpy(str + a_size, b, b_size);
+	str[a_size + b_size] = '\0';
+
+	return str;
+}
+
+/** Compare two strings. */
+int os_str_cmp(const char *a, const char *b)
+{
+	return str_cmp(a, b);
+}
+
+/** Return number of characters in string. */
+size_t os_str_length(const char *str)
+{
+	return str_length(str);
+}
+
+/** Duplicate string. */
+char *os_str_dup(const char *str)
+{
+	return str_dup(str);
+}
+
+/** Get character from string at the given index. */
+int os_str_get_char(const char *str, int index, int *out_char)
+{
+	size_t offset;
+	int i;
+	wchar_t c;
+
+	if (index < 0)
+		return EINVAL;
+
+	offset = 0;
+	for (i = 0; i <= index; ++i) {
+		c = str_decode(str, &offset, STR_NO_LIMIT);
+		if (c == '\0')
+			return EINVAL;
+		if (c == U_SPECIAL)
+			return EIO;
+	}
+
+	*out_char = (int) c;
+	return EOK;
+}
+
+/** Display survival help message. */
+void os_input_disp_help(void)
+{
+	printf("Press Ctrl-Q to quit.\n");
+}
+
+/** Read one line of input from the user. */
+int os_input_line(char **ptr)
+{
+	char *line;
+	int rc;
+
+	if (tinput == NULL) {
+		tinput = tinput_new();
+		if (tinput == NULL)
+			return EIO;
+	}
+
+	rc = tinput_read(tinput, &line);
+	if (rc == ENOENT) {
+		/* User-requested abort */
+		*ptr = os_str_dup("");
+		return EOK;
+	}
+
+	if (rc != EOK) {
+		/* Error in communication with console */
+		return EIO;
+	}
+
+	/* XXX Input module needs trailing newline to keep going. */
+	*ptr = os_str_acat(line, "\n");
+	free(line);
+
+	return EOK;
+}
+
+/** Simple command execution. */
+int os_exec(char *const cmd[])
+{
+	task_id_t tid;
+	task_exit_t texit;
+	int retval;
+
+	tid = task_spawn(cmd[0], (char const * const *) cmd, &retval);
+	if (tid == 0) {
+		printf("Error: Failed spawning '%s' (%s).\n", cmd[0],
+		    str_error(retval));
+		exit(1);
+	}
+
+	/* XXX Handle exit status and return value. */
+	task_wait(tid, &texit, &retval);
+
+	return EOK;
+}
+
+/** Store the executable file path via which we were executed. */
+void os_store_ef_path(char *path)
+{
+	ef_path = path;
+}
+
+/** Return path to the Sysel library
+ *
+ * @return New string. Caller should deallocate it using @c free().
+ */
+char *os_get_lib_path(void)
+{
+	return os_str_dup("/src/sysel/lib");
+}
Index: uspace/app/sbi/src/os/os.h
===================================================================
--- uspace/app/sbi/src/os/os.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/os/os.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef OS_H_
+#define OS_H_
+
+char *os_str_acat(const char *a, const char *b);
+int os_str_cmp(const char *a, const char *b);
+char *os_str_dup(const char *str);
+size_t os_str_length(const char *str);
+int os_str_get_char(const char *str, int index, int *out_char);
+void os_input_disp_help(void);
+int os_input_line(char **ptr);
+int os_exec(char *const cmd[]);
+
+void os_store_ef_path(char *path);
+char *os_get_lib_path(void);
+
+#endif
Index: uspace/app/sbi/src/os/posix.c
===================================================================
--- uspace/app/sbi/src/os/posix.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/os/posix.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file POSIX-specific code. */
+
+#include <libgen.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <errno.h>
+#include "../mytypes.h"
+
+#include "os.h"
+
+/** Path to executable file via which we have been invoked. */
+static char *ef_path;
+
+/*
+ * The string functions are in fact standard C, but would not work under
+ * HelenOS.
+ */
+
+/** Concatenate two strings. */
+char *os_str_acat(const char *a, const char *b)
+{
+	int a_len, b_len;
+	char *str;
+
+	a_len = strlen(a);
+	b_len = strlen(b);
+
+	str = malloc(a_len + b_len + 1);
+	if (str == NULL) {
+		printf("Memory allocation error.\n");
+		exit(1);
+	}
+
+	memcpy(str, a, a_len);
+	memcpy(str + a_len, b, b_len);
+	str[a_len + b_len] = '\0';
+
+	return str;
+}
+
+/** Compare two strings. */
+int os_str_cmp(const char *a, const char *b)
+{
+	return strcmp(a, b);
+}
+
+/** Return number of characters in string. */
+size_t os_str_length(const char *str)
+{
+	return strlen(str);
+}
+
+/** Duplicate string. */
+char *os_str_dup(const char *str)
+{
+	return strdup(str);
+}
+
+/** Get character from string at the given index. */
+int os_str_get_char(const char *str, int index, int *out_char)
+{
+	size_t len;
+
+	len = strlen(str);
+	if (index < 0 || (size_t) index >= len)
+		return EINVAL;
+
+	*out_char = str[index];
+	return EOK;
+}
+
+#define OS_INPUT_BUFFER_SIZE 256
+static char os_input_buffer[OS_INPUT_BUFFER_SIZE];
+
+/** Display survival help message. */
+void os_input_disp_help(void)
+{
+	printf("Send ^C (SIGINT) to quit.\n");
+}
+
+/** Read one line of input from the user. */
+int os_input_line(char **ptr)
+{
+	if (fgets(os_input_buffer, OS_INPUT_BUFFER_SIZE, stdin) == NULL)
+		os_input_buffer[0] = '\0';
+
+	if (ferror(stdin)) {
+		*ptr = NULL;
+		return EIO;
+	}
+
+	*ptr = strdup(os_input_buffer);
+	return EOK;
+}
+
+/** Simple command execution. */
+int os_exec(char *const cmd[])
+{
+	pid_t pid;
+	int status;
+
+	pid = vfork();
+
+	if (pid == 0) {
+		execvp(cmd[0], cmd);
+		/* If we get here, exec failed. */
+		exit(1);
+	} else if (pid == -1) {
+		/* fork() failed */
+		return EBUSY;
+	}
+
+	if (waitpid(pid, &status, 0) == -1) {
+		/* waitpid() failed */
+		printf("Error: Waitpid failed.\n");
+		exit(1);
+	}
+
+	if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
+		printf("Error: Exec failed or child returned non-zero "
+		    "exit status.\n");
+	}
+
+	return EOK;
+}
+
+/** Store the executable file path via which we were executed. */
+void os_store_ef_path(char *path)
+{
+	ef_path = path;
+}
+
+/** Return path to the Sysel library
+ *
+ * @return New string. Caller should deallocate it using @c free().
+ */
+char *os_get_lib_path(void)
+{
+	return os_str_acat(dirname(ef_path), "/lib");
+}
Index: uspace/app/sbi/src/p_expr.c
===================================================================
--- uspace/app/sbi/src/p_expr.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/p_expr.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,692 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Parse arithmetic expressions. */
+
+#include <assert.h>
+#include <stdlib.h>
+#include "bigint.h"
+#include "debug.h"
+#include "lex.h"
+#include "list.h"
+#include "mytypes.h"
+#include "p_type.h"
+#include "parse.h"
+#include "stree.h"
+
+#include "p_expr.h"
+
+static stree_expr_t *parse_assign(parse_t *parse);
+static stree_expr_t *parse_comparative(parse_t *parse);
+static stree_expr_t *parse_additive(parse_t *parse);
+static stree_expr_t *parse_multip(parse_t *parse);
+static stree_expr_t *parse_prefix(parse_t *parse);
+static stree_expr_t *parse_prefix_new(parse_t *parse);
+static stree_expr_t *parse_postfix(parse_t *parse);
+static stree_expr_t *parse_pf_access(parse_t *parse, stree_expr_t *a);
+static stree_expr_t *parse_pf_call(parse_t *parse, stree_expr_t *a);
+static stree_expr_t *parse_pf_index(parse_t *parse, stree_expr_t *a);
+static stree_expr_t *parse_pf_as(parse_t *parse, stree_expr_t *a);
+static stree_expr_t *parse_paren(parse_t *parse);
+static stree_expr_t *parse_primitive(parse_t *parse);
+static stree_expr_t *parse_nameref(parse_t *parse);
+static stree_expr_t *parse_lit_bool(parse_t *parse);
+static stree_expr_t *parse_lit_char(parse_t *parse);
+static stree_expr_t *parse_lit_int(parse_t *parse);
+static stree_expr_t *parse_lit_ref(parse_t *parse);
+static stree_expr_t *parse_lit_string(parse_t *parse);
+static stree_expr_t *parse_self_ref(parse_t *parse);
+
+static stree_expr_t *parse_recovery_expr(parse_t *parse);
+
+/** Parse expression.
+ *
+ * Input is read from the input object associated with @a parse. If any
+ * error occurs, parse->error will @c b_true when this function
+ * returns. parse->error_bailout will be @c b_true if the error has not
+ * been recovered yet. Similar holds for other parsing functions in this
+ * module.
+ *
+ * @param parse		Parser object.
+ */
+stree_expr_t *parse_expr(parse_t *parse)
+{
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parse expression.\n");
+#endif
+	if (parse_is_error(parse))
+		return parse_recovery_expr(parse);
+
+	return parse_assign(parse);
+}
+
+/** Parse assignment expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_assign(parse_t *parse)
+{
+	stree_expr_t *a, *b, *tmp;
+	stree_assign_t *assign;
+
+	a = parse_comparative(parse);
+
+	switch (lcur_lc(parse)) {
+	case lc_assign:
+		assign = stree_assign_new(ac_set);
+		break;
+	case lc_increase:
+		assign = stree_assign_new(ac_increase);
+		break;
+	default:
+		return a;
+	}
+
+	lskip(parse);
+	b = parse_comparative(parse);
+
+	assign->dest = a;
+	assign->src = b;
+
+	tmp = stree_expr_new(ec_assign);
+	tmp->u.assign = assign;
+	return tmp;
+}
+
+/** Parse comparative expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_comparative(parse_t *parse)
+{
+	stree_expr_t *a, *b, *tmp;
+	stree_binop_t *binop;
+	binop_class_t bc;
+
+	a = parse_additive(parse);
+
+	while (lcur_lc(parse) == lc_equal || lcur_lc(parse) == lc_notequal ||
+	    lcur_lc(parse) == lc_lt || lcur_lc(parse) == lc_gt ||
+	    lcur_lc(parse) == lc_lt_equal || lcur_lc(parse) == lc_gt_equal) {
+
+		if (parse_is_error(parse))
+			break;
+
+		switch (lcur_lc(parse)) {
+		case lc_equal: bc = bo_equal; break;
+		case lc_notequal: bc = bo_notequal; break;
+		case lc_lt: bc = bo_lt; break;
+		case lc_gt: bc = bo_gt; break;
+		case lc_lt_equal: bc = bo_lt_equal; break;
+		case lc_gt_equal: bc = bo_gt_equal; break;
+		default: assert(b_false);
+		}
+
+		lskip(parse);
+		b = parse_additive(parse);
+
+		binop = stree_binop_new(bc);
+		binop->arg1 = a;
+		binop->arg2 = b;
+
+		tmp = stree_expr_new(ec_binop);
+		tmp->u.binop = binop;
+		a = tmp;
+	}
+
+	return a;
+}
+
+/** Parse additive expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_additive(parse_t *parse)
+{
+	stree_expr_t *a, *b, *tmp;
+	stree_binop_t *binop;
+	binop_class_t bc;
+
+	a = parse_multip(parse);
+	while (lcur_lc(parse) == lc_plus || lcur_lc(parse) == lc_minus) {
+		if (parse_is_error(parse))
+			break;
+
+		switch (lcur_lc(parse)) {
+		case lc_plus: bc = bo_plus; break;
+		case lc_minus: bc = bo_minus; break;
+		default: assert(b_false);
+		}
+
+		lskip(parse);
+		b = parse_multip(parse);
+
+		binop = stree_binop_new(bc);
+		binop->arg1 = a;
+		binop->arg2 = b;
+
+		tmp = stree_expr_new(ec_binop);
+		tmp->u.binop = binop;
+		a = tmp;
+	}
+
+	return a;
+}
+
+/** Parse multiplicative expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_multip(parse_t *parse)
+{
+	stree_expr_t *a, *b, *tmp;
+	stree_binop_t *binop;
+	binop_class_t bc;
+
+	a = parse_prefix(parse);
+	while (lcur_lc(parse) == lc_mult) {
+		if (parse_is_error(parse))
+			break;
+
+		switch (lcur_lc(parse)) {
+		case lc_mult: bc = bo_mult; break;
+		default: assert(b_false);
+		}
+
+		lskip(parse);
+		b = parse_prefix(parse);
+
+		binop = stree_binop_new(bc);
+		binop->arg1 = a;
+		binop->arg2 = b;
+
+		tmp = stree_expr_new(ec_binop);
+		tmp->u.binop = binop;
+		a = tmp;
+	}
+
+	return a;
+}
+
+/** Parse prefix expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_prefix(parse_t *parse)
+{
+	stree_expr_t *a;
+	stree_expr_t *tmp;
+	stree_unop_t *unop;
+	unop_class_t uc;
+
+	switch (lcur_lc(parse)) {
+	case lc_plus:
+	case lc_minus:
+		if (parse_is_error(parse))
+			return parse_recovery_expr(parse);
+
+		switch (lcur_lc(parse)) {
+		case lc_plus: uc = uo_plus; break;
+		case lc_minus: uc = uo_minus; break;
+		default: assert(b_false);
+		}
+
+		lskip(parse);
+		a = parse_postfix(parse);
+
+		unop = stree_unop_new(uc);
+		unop->arg = a;
+
+		tmp = stree_expr_new(ec_unop);
+		tmp->u.unop = unop;
+		a = tmp;
+		break;
+	case lc_new:
+		a = parse_prefix_new(parse);
+		break;
+	default:
+		a = parse_postfix(parse);
+		break;
+	}
+
+	return a;
+}
+
+/** Parse @c new operator.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_prefix_new(parse_t *parse)
+{
+	stree_texpr_t *texpr;
+	stree_new_t *new_op;
+	stree_expr_t *expr;
+
+	lmatch(parse, lc_new);
+	texpr = parse_texpr(parse);
+
+	/* Parenthesis should be present except for arrays. */
+	if (texpr->tc != tc_tindex) {
+		lmatch(parse, lc_lparen);
+		lmatch(parse, lc_rparen);
+	}
+
+	new_op = stree_new_new();
+	new_op->texpr = texpr;
+	expr = stree_expr_new(ec_new);
+	expr->u.new_op = new_op;
+
+	return expr;
+}
+
+/** Parse postfix expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_postfix(parse_t *parse)
+{
+	stree_expr_t *a;
+	stree_expr_t *tmp;
+
+	a = parse_paren(parse);
+
+	while (lcur_lc(parse) == lc_period || lcur_lc(parse) == lc_lparen ||
+	    lcur_lc(parse) == lc_lsbr || lcur_lc(parse) == lc_as) {
+
+		if (parse_is_error(parse))
+			break;
+
+		switch (lcur_lc(parse)) {
+		case lc_period:
+			tmp = parse_pf_access(parse, a);
+			break;
+		case lc_lparen:
+			tmp = parse_pf_call(parse, a);
+			break;
+		case lc_lsbr:
+			tmp = parse_pf_index(parse, a);
+			break;
+		case lc_as:
+			tmp = parse_pf_as(parse, a);
+			break;
+		default:
+			assert(b_false);
+		}
+
+		a = tmp;
+	}
+
+	return a;
+}
+
+/** Parse member access expression
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_pf_access(parse_t *parse, stree_expr_t *a)
+{
+	stree_ident_t *ident;
+	stree_expr_t *expr;
+	stree_access_t *access;
+
+	lmatch(parse, lc_period);
+	ident = parse_ident(parse);
+
+	access = stree_access_new();
+	access->arg = a;
+	access->member_name = ident;
+
+	expr = stree_expr_new(ec_access);
+	expr->u.access = access;
+
+	return expr;
+}
+
+/** Parse function call expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_pf_call(parse_t *parse, stree_expr_t *a)
+{
+	stree_expr_t *expr;
+	stree_call_t *call;
+	stree_expr_t *arg;
+
+	lmatch(parse, lc_lparen);
+
+	call = stree_call_new();
+	call->fun = a;
+	list_init(&call->args);
+
+	/* Parse function arguments */
+
+	if (lcur_lc(parse) != lc_rparen) {
+		while (!parse_is_error(parse)) {
+			arg = parse_expr(parse);
+			list_append(&call->args, arg);
+
+			if (lcur_lc(parse) == lc_rparen)
+				break;
+			lmatch(parse, lc_comma);
+		}
+	}
+
+	lmatch(parse, lc_rparen);
+
+	expr = stree_expr_new(ec_call);
+	expr->u.call = call;
+
+	return expr;
+}
+
+/** Parse index expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_pf_index(parse_t *parse, stree_expr_t *a)
+{
+	stree_expr_t *expr;
+	stree_index_t *index;
+	stree_expr_t *arg;
+
+	lmatch(parse, lc_lsbr);
+
+	index = stree_index_new();
+	index->base = a;
+	list_init(&index->args);
+
+	/* Parse indices */
+
+	if (lcur_lc(parse) != lc_rsbr) {
+		while (!parse_is_error(parse)) {
+			arg = parse_expr(parse);
+			list_append(&index->args, arg);
+
+			if (lcur_lc(parse) == lc_rsbr)
+				break;
+			lmatch(parse, lc_comma);
+		}
+	}
+
+	lmatch(parse, lc_rsbr);
+
+	expr = stree_expr_new(ec_index);
+	expr->u.index = index;
+
+	return expr;
+}
+
+/** Parse @c as operator.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_pf_as(parse_t *parse, stree_expr_t *a)
+{
+	stree_expr_t *expr;
+	stree_texpr_t *texpr;
+	stree_as_t *as_op;
+
+	lmatch(parse, lc_as);
+	texpr = parse_texpr(parse);
+
+	as_op = stree_as_new();
+	as_op->arg = a;
+	as_op->dtype = texpr;
+	expr = stree_expr_new(ec_as);
+	expr->u.as_op = as_op;
+
+	return expr;
+}
+
+/** Parse possibly partenthesized expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_paren(parse_t *parse)
+{
+	stree_expr_t *expr;
+
+	if (lcur_lc(parse) == lc_lparen) {
+		lskip(parse);
+		expr = parse_expr(parse);
+		lmatch(parse, lc_rparen);
+	} else {
+		expr = parse_primitive(parse);
+	}
+
+	return expr;
+}
+
+
+/** Parse primitive expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_primitive(parse_t *parse)
+{
+	stree_expr_t *expr;
+
+	switch (lcur_lc(parse)) {
+	case lc_ident:
+		expr = parse_nameref(parse);
+		break;
+	case lc_false:
+	case lc_true:
+		expr = parse_lit_bool(parse);
+		break;
+	case lc_lit_char:
+		expr = parse_lit_char(parse);
+		break;
+	case lc_lit_int:
+		expr = parse_lit_int(parse);
+		break;
+	case lc_nil:
+		expr = parse_lit_ref(parse);
+		break;
+	case lc_lit_string:
+		expr = parse_lit_string(parse);
+		break;
+	case lc_self:
+		expr = parse_self_ref(parse);
+		break;
+	default:
+		lunexpected_error(parse);
+		expr = parse_recovery_expr(parse);
+	}
+
+	return expr;
+}
+
+/** Parse name reference.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_nameref(parse_t *parse)
+{
+	stree_nameref_t *nameref;
+	stree_expr_t *expr;
+
+	nameref = stree_nameref_new();
+	nameref->name = parse_ident(parse);
+	expr = stree_expr_new(ec_nameref);
+	expr->u.nameref = nameref;
+
+	return expr;
+}
+
+/** Parse boolean literal.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_lit_bool(parse_t *parse)
+{
+	stree_literal_t *literal;
+	stree_expr_t *expr;
+	bool_t value;
+
+	switch (lcur_lc(parse)) {
+	case lc_false: value = b_false; break;
+	case lc_true: value = b_true; break;
+	default: assert(b_false);
+	}
+
+	lskip(parse);
+
+	literal = stree_literal_new(ltc_bool);
+	literal->u.lit_bool.value = value;
+
+	expr = stree_expr_new(ec_literal);
+	expr->u.literal = literal;
+
+	return expr;
+}
+
+/** Parse character literal.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_lit_char(parse_t *parse)
+{
+	stree_literal_t *literal;
+	stree_expr_t *expr;
+
+	lcheck(parse, lc_lit_char);
+
+	literal = stree_literal_new(ltc_char);
+	bigint_clone(&lcur(parse)->u.lit_char.value,
+	    &literal->u.lit_char.value);
+
+	lskip(parse);
+
+	expr = stree_expr_new(ec_literal);
+	expr->u.literal = literal;
+
+	return expr;
+}
+
+/** Parse integer literal.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_lit_int(parse_t *parse)
+{
+	stree_literal_t *literal;
+	stree_expr_t *expr;
+
+	lcheck(parse, lc_lit_int);
+
+	literal = stree_literal_new(ltc_int);
+	bigint_clone(&lcur(parse)->u.lit_int.value,
+	    &literal->u.lit_int.value);
+
+	lskip(parse);
+
+	expr = stree_expr_new(ec_literal);
+	expr->u.literal = literal;
+
+	return expr;
+}
+
+/** Parse reference literal (@c nil).
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_lit_ref(parse_t *parse)
+{
+	stree_literal_t *literal;
+	stree_expr_t *expr;
+
+	lmatch(parse, lc_nil);
+
+	literal = stree_literal_new(ltc_ref);
+
+	expr = stree_expr_new(ec_literal);
+	expr->u.literal = literal;
+
+	return expr;
+}
+
+/** Parse string literal.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_lit_string(parse_t *parse)
+{
+	stree_literal_t *literal;
+	stree_expr_t *expr;
+
+	lcheck(parse, lc_lit_string);
+
+	literal = stree_literal_new(ltc_string);
+	literal->u.lit_string.value = lcur(parse)->u.lit_string.value;
+
+	lskip(parse);
+
+	expr = stree_expr_new(ec_literal);
+	expr->u.literal = literal;
+
+	return expr;
+}
+
+/** Parse @c self keyword.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_self_ref(parse_t *parse)
+{
+	stree_self_ref_t *self_ref;
+	stree_expr_t *expr;
+
+	lmatch(parse, lc_self);
+
+	self_ref = stree_self_ref_new();
+
+	expr = stree_expr_new(ec_self_ref);
+	expr->u.self_ref = self_ref;
+
+	return expr;
+}
+
+/** Construct a special recovery expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_expr_t *parse_recovery_expr(parse_t *parse)
+{
+	stree_literal_t *literal;
+	stree_expr_t *expr;
+
+	(void) parse;
+
+	literal = stree_literal_new(ltc_ref);
+
+	expr = stree_expr_new(ec_literal);
+	expr->u.literal = literal;
+
+	return expr;
+}
Index: uspace/app/sbi/src/p_expr.h
===================================================================
--- uspace/app/sbi/src/p_expr.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/p_expr.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef P_EXPR_H_
+#define P_EXPR_H_
+
+#include "mytypes.h"
+
+stree_expr_t *parse_expr(parse_t *parse);
+
+#endif
Index: uspace/app/sbi/src/p_type.c
===================================================================
--- uspace/app/sbi/src/p_type.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/p_type.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,314 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Parse arithmetic expressions. */
+
+#include <assert.h>
+#include <stdlib.h>
+#include "debug.h"
+#include "lex.h"
+#include "list.h"
+#include "mytypes.h"
+#include "parse.h"
+#include "p_expr.h"
+#include "stree.h"
+
+#include "p_type.h"
+
+static stree_texpr_t *parse_tapply(parse_t *parse);
+static stree_texpr_t *parse_tpostfix(parse_t *parse);
+static stree_texpr_t *parse_pf_taccess(parse_t *parse, stree_texpr_t *a);
+static stree_texpr_t *parse_pf_tindex(parse_t *parse, stree_texpr_t *a);
+static stree_texpr_t *parse_tprimitive(parse_t *parse);
+static stree_tliteral_t *parse_tliteral(parse_t *parse);
+static stree_tnameref_t *parse_tnameref(parse_t *parse);
+
+static stree_texpr_t *parse_recovery_texpr(parse_t *parse);
+
+/** Parse type expression.
+ *
+ * Input is read from the input object associated with @a parse. If any
+ * error occurs, parse->error will @c b_true when this function
+ * returns. parse->error_bailout will be @c b_true if the error has not
+ * been recovered yet. Similar holds for other parsing functions in this
+ * module.
+ *
+ * @param parse		Parser object.
+ */
+stree_texpr_t *parse_texpr(parse_t *parse)
+{
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parse type expression.\n");
+#endif
+	if (parse_is_error(parse))
+		return parse_recovery_texpr(parse);
+
+	return parse_tapply(parse);
+}
+
+/** Parse type application expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_texpr_t *parse_tapply(parse_t *parse)
+{
+	stree_texpr_t *gtype;
+	stree_texpr_t *aexpr;
+	stree_texpr_t *targ;
+	stree_tapply_t *tapply;
+
+	gtype = parse_tpostfix(parse);
+	if (lcur_lc(parse) != lc_slash)
+		return gtype;
+
+	tapply = stree_tapply_new();
+	tapply->gtype = gtype;
+	list_init(&tapply->targs);
+
+	while (lcur_lc(parse) == lc_slash) {
+
+		if (parse_is_error(parse))
+			break;
+
+		lskip(parse);
+		targ = parse_tpostfix(parse);
+
+		list_append(&tapply->targs, targ);
+	}
+
+	aexpr = stree_texpr_new(tc_tapply);
+	aexpr->u.tapply = tapply;
+	return aexpr;
+}
+
+/** Parse postfix type expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_texpr_t *parse_tpostfix(parse_t *parse)
+{
+	stree_texpr_t *a;
+	stree_texpr_t *tmp;
+
+	a = parse_tprimitive(parse);
+
+	while (lcur_lc(parse) == lc_period || lcur_lc(parse) == lc_lsbr) {
+
+		if (parse_is_error(parse))
+			break;
+
+		switch (lcur_lc(parse)) {
+		case lc_period:
+			tmp = parse_pf_taccess(parse, a);
+			break;
+		case lc_lsbr:
+			tmp = parse_pf_tindex(parse, a);
+			break;
+		default:
+			lunexpected_error(parse);
+			tmp = parse_recovery_texpr(parse);
+			break;
+		}
+
+		a = tmp;
+	}
+
+	return a;
+}
+
+/** Parse access type expression.
+ *
+ * @param parse		Parser object.
+ * @param a		Base expression.
+ */
+static stree_texpr_t *parse_pf_taccess(parse_t *parse, stree_texpr_t *a)
+{
+	stree_texpr_t *texpr;
+	stree_ident_t *ident;
+	stree_taccess_t *taccess;
+
+	lmatch(parse, lc_period);
+	ident = parse_ident(parse);
+
+	taccess = stree_taccess_new();
+	taccess->arg = a;
+	taccess->member_name = ident;
+
+	texpr = stree_texpr_new(tc_taccess);
+	texpr->u.taccess = taccess;
+
+	return texpr;
+}
+
+/** Parse index type expression.
+ *
+ * @param parse		Parser object.
+ * @param a		Base expression.
+ */
+static stree_texpr_t *parse_pf_tindex(parse_t *parse, stree_texpr_t *a)
+{
+	stree_texpr_t *texpr;
+	stree_tindex_t *tindex;
+	stree_expr_t *expr;
+
+	tindex = stree_tindex_new();
+	tindex->base_type = a;
+
+	tindex->n_args = 0;
+	list_init(&tindex->args);
+
+	lmatch(parse, lc_lsbr);
+
+	if (lcur_lc(parse) != lc_rsbr && lcur_lc(parse) != lc_comma) {
+		while (b_true) {
+			if (parse_is_error(parse))
+				break;
+			expr = parse_expr(parse);
+			tindex->n_args += 1;
+			list_append(&tindex->args, expr);
+
+			if (lcur_lc(parse) == lc_rsbr)
+				break;
+
+			lmatch(parse, lc_comma);
+		}
+	} else {
+		tindex->n_args = 1;
+		while (lcur_lc(parse) == lc_comma) {
+			if (parse_is_error(parse))
+				break;
+			lskip(parse);
+			tindex->n_args += 1;
+		}
+	}
+
+	lmatch(parse, lc_rsbr);
+
+	texpr = stree_texpr_new(tc_tindex);
+	texpr->u.tindex = tindex;
+
+	return texpr;
+}
+
+/** Parse primitive type expression.
+ *
+ * @param parse		Parser object.
+ */
+static stree_texpr_t *parse_tprimitive(parse_t *parse)
+{
+	stree_texpr_t *texpr;
+
+	switch (lcur_lc(parse)) {
+	case lc_ident:
+		texpr = stree_texpr_new(tc_tnameref);
+		texpr->u.tnameref = parse_tnameref(parse);
+		break;
+	case lc_bool:
+	case lc_char:
+	case lc_int:
+	case lc_string:
+	case lc_resource:
+		texpr = stree_texpr_new(tc_tliteral);
+		texpr->u.tliteral = parse_tliteral(parse);
+		break;
+	default:
+		lunexpected_error(parse);
+		texpr = parse_recovery_texpr(parse);
+		break;
+	}
+
+	return texpr;
+}
+
+/** Parse type literal.
+ *
+ * @param parse		Parser object.
+ */
+static stree_tliteral_t *parse_tliteral(parse_t *parse)
+{
+	stree_tliteral_t *tliteral;
+	tliteral_class_t tlc;
+
+	switch (lcur_lc(parse)) {
+	case lc_bool:
+		tlc = tlc_bool;
+		break;
+	case lc_char:
+		tlc = tlc_char;
+		break;
+	case lc_int:
+		tlc = tlc_int;
+		break;
+	case lc_string:
+		tlc = tlc_string;
+		break;
+	case lc_resource:
+		tlc = tlc_resource;
+		break;
+	default:
+		assert(b_false);
+	}
+
+	lskip(parse);
+
+	tliteral = stree_tliteral_new(tlc);
+	return tliteral;
+}
+
+/** Parse type identifier.
+ *
+ * @param parse		Parser object.
+ */
+static stree_tnameref_t *parse_tnameref(parse_t *parse)
+{
+	stree_tnameref_t *tnameref;
+
+	tnameref = stree_tnameref_new();
+	tnameref->name = parse_ident(parse);
+
+	return tnameref;
+}
+
+/** Construct a special type expression fore recovery.
+ *
+ * @param parse		Parser object.
+ */
+static stree_texpr_t *parse_recovery_texpr(parse_t *parse)
+{
+	stree_tliteral_t *tliteral;
+	stree_texpr_t *texpr;
+
+	(void) parse;
+
+	tliteral = stree_tliteral_new(tlc_int);
+
+	texpr = stree_texpr_new(tc_tliteral);
+	texpr->u.tliteral = tliteral;
+
+	return texpr;
+}
Index: uspace/app/sbi/src/p_type.h
===================================================================
--- uspace/app/sbi/src/p_type.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/p_type.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef P_TYPE_H_
+#define P_TYPE_H_
+
+#include "mytypes.h"
+
+stree_texpr_t *parse_texpr(parse_t *parse);
+
+#endif
Index: uspace/app/sbi/src/parse.c
===================================================================
--- uspace/app/sbi/src/parse.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/parse.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1099 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Parser
+ *
+ * Consumes a sequence of lexical elements and produces a syntax tree (stree).
+ * Parsing primitives, module members, statements.
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include "debug.h"
+#include "lex.h"
+#include "list.h"
+#include "mytypes.h"
+#include "p_expr.h"
+#include "p_type.h"
+#include "stree.h"
+#include "strtab.h"
+#include "symbol.h"
+
+#include "parse.h"
+
+/*
+ * Module members
+ */
+static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass,
+    stree_csi_t *outer_csi);
+static stree_csimbr_t *parse_csimbr(parse_t *parse, stree_csi_t *outer_csi);
+
+static stree_fun_t *parse_fun(parse_t *parse, stree_csi_t *outer_csi);
+static stree_var_t *parse_var(parse_t *parse, stree_csi_t *outer_csi);
+static stree_prop_t *parse_prop(parse_t *parse, stree_csi_t *outer_csi);
+
+static stree_symbol_attr_t *parse_symbol_attr(parse_t *parse);
+
+static stree_proc_arg_t *parse_proc_arg(parse_t *parse);
+static stree_arg_attr_t *parse_arg_attr(parse_t *parse);
+
+/*
+ * Statements
+ */
+static stree_block_t *parse_block(parse_t *parse);
+
+static stree_vdecl_t *parse_vdecl(parse_t *parse);
+static stree_if_t *parse_if(parse_t *parse);
+static stree_while_t *parse_while(parse_t *parse);
+static stree_for_t *parse_for(parse_t *parse);
+static stree_raise_t *parse_raise(parse_t *parse);
+static stree_return_t *parse_return(parse_t *parse);
+static stree_wef_t *parse_wef(parse_t *parse);
+static stree_exps_t *parse_exps(parse_t *parse);
+
+static stree_except_t *parse_except(parse_t *parse);
+
+/** Initialize parser object.
+ *
+ * Set up parser @a parse to use lexer @a lex for input and to store
+ * output (i.e. new declarations) to program @a prog. @a prog is not
+ * necessarily empty, the declarations being parsed are simply added
+ * to it.
+ *
+ * @param parse		Parser object.
+ * @param prog		Destination program stree.
+ * @param lex		Input lexer.
+ */
+void parse_init(parse_t *parse, stree_program_t *prog, struct lex *lex)
+{
+	parse->program = prog;
+	parse->cur_mod = parse->program->module;
+	parse->lex = lex;
+
+	parse->error = b_false;
+	parse->error_bailout = b_false;
+
+	lex_next(parse->lex);
+}
+
+/** Parse module.
+ *
+ * Parse a program module.
+ *
+ * The input is read using the lexer associated with @a parse. The resulting
+ * declarations are added to existing declarations in the program associated
+ * with @a parse.
+ *
+ * If any parse error occurs, parse->error will @c b_true when this function
+ * returns. parse->error_bailout will be @c b_true if the error has not
+ * been recovered yet. Similar holds for other parsing functions in this
+ * module.
+ *
+ * @param parse		Parser object.
+ */
+void parse_module(parse_t *parse)
+{
+	stree_csi_t *csi;
+	stree_modm_t *modm;
+
+	while (lcur_lc(parse) != lc_eof && !parse_is_error(parse)) {
+		switch (lcur_lc(parse)) {
+		case lc_class:
+		case lc_struct:
+		case lc_interface:
+			csi = parse_csi(parse, lcur_lc(parse), NULL);
+			modm = stree_modm_new(mc_csi);
+			modm->u.csi = csi;
+
+			list_append(&parse->cur_mod->members, modm);
+			break;
+		default:
+			lunexpected_error(parse);
+			lex_next(parse->lex);
+			break;
+		}
+
+	}
+}
+
+/** Parse class, struct or interface declaration.
+ *
+ * @param parse		Parser object.
+ * @param dclass	What to parse: @c lc_class, @c lc_struct or @c lc_csi.
+ * @param outer_csi	CSI containing this declaration or @c NULL if global.
+ * @return		New syntax tree node.
+ */
+static stree_csi_t *parse_csi(parse_t *parse, lclass_t dclass,
+    stree_csi_t *outer_csi)
+{
+	stree_csi_t *csi;
+	csi_class_t cc;
+	stree_csimbr_t *csimbr;
+	stree_symbol_t *symbol;
+	stree_ident_t *targ_name;
+
+	switch (dclass) {
+	case lc_class: cc = csi_class; break;
+	case lc_struct: cc = csi_struct; break;
+	case lc_interface: cc = csi_interface; break;
+	default: assert(b_false);
+	}
+
+	lskip(parse);
+
+	csi = stree_csi_new(cc);
+	csi->name = parse_ident(parse);
+
+	list_init(&csi->targ_names);
+
+	while (lcur_lc(parse) == lc_slash) {
+		lskip(parse);
+		targ_name = parse_ident(parse);
+		list_append(&csi->targ_names, targ_name);
+	}
+
+	symbol = stree_symbol_new(sc_csi);
+	symbol->u.csi = csi;
+	symbol->outer_csi = outer_csi;
+	csi->symbol = symbol;
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("parse_csi: csi=%p, csi->name = %p (%s)\n", csi, csi->name,
+	    strtab_get_str(csi->name->sid));
+#endif
+	if (lcur_lc(parse) == lc_colon) {
+		/* Inheritance list */
+		lskip(parse);
+		csi->base_csi_ref = parse_texpr(parse);
+	} else {
+		csi->base_csi_ref = NULL;
+	}
+
+	lmatch(parse, lc_is);
+	list_init(&csi->members);
+
+	/* Parse class, struct or interface members. */
+	while (lcur_lc(parse) != lc_end && !parse_is_error(parse)) {
+		csimbr = parse_csimbr(parse, csi);
+		list_append(&csi->members, csimbr);
+	}
+
+	lmatch(parse, lc_end);
+
+	return csi;
+}
+
+/** Parse class, struct or interface member.
+ *
+ * @param parse		Parser object.
+ * @param outer_csi	CSI containing this declaration or @c NULL if global.
+ * @return		New syntax tree node.
+ */
+static stree_csimbr_t *parse_csimbr(parse_t *parse, stree_csi_t *outer_csi)
+{
+	stree_csimbr_t *csimbr;
+
+	stree_csi_t *csi;
+	stree_fun_t *fun;
+	stree_var_t *var;
+	stree_prop_t *prop;
+
+	switch (lcur_lc(parse)) {
+	case lc_class:
+	case lc_struct:
+	case lc_interface:
+		csi = parse_csi(parse, lcur_lc(parse), outer_csi);
+		csimbr = stree_csimbr_new(csimbr_csi);
+		csimbr->u.csi = csi;
+		break;
+	case lc_fun:
+		fun = parse_fun(parse, outer_csi);
+		csimbr = stree_csimbr_new(csimbr_fun);
+		csimbr->u.fun = fun;
+		break;
+	case lc_var:
+		var = parse_var(parse, outer_csi);
+		csimbr = stree_csimbr_new(csimbr_var);
+		csimbr->u.var = var;
+		break;
+	case lc_prop:
+		prop = parse_prop(parse, outer_csi);
+		csimbr = stree_csimbr_new(csimbr_prop);
+		csimbr->u.prop = prop;
+		break;
+	default:
+		lunexpected_error(parse);
+		lex_next(parse->lex);
+	}
+
+	return csimbr;
+}
+
+
+/** Parse member function.
+ *
+ * @param parse		Parser object.
+ * @param outer_csi	CSI containing this declaration or @c NULL if global.
+ * @return		New syntax tree node.
+ */
+static stree_fun_t *parse_fun(parse_t *parse, stree_csi_t *outer_csi)
+{
+	stree_fun_t *fun;
+	stree_proc_arg_t *arg;
+	stree_symbol_t *symbol;
+	stree_symbol_attr_t *attr;
+
+	fun = stree_fun_new();
+	symbol = stree_symbol_new(sc_fun);
+
+	symbol->u.fun = fun;
+	symbol->outer_csi = outer_csi;
+	fun->symbol = symbol;
+
+	lmatch(parse, lc_fun);
+	fun->name = parse_ident(parse);
+	lmatch(parse, lc_lparen);
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parsing function '%s'.\n", strtab_get_str(fun->name->sid));
+#endif
+
+	list_init(&fun->args);
+
+	if (lcur_lc(parse) != lc_rparen) {
+
+		/* Parse formal parameters. */
+		while (!parse_is_error(parse)) {
+			arg = parse_proc_arg(parse);
+
+			if (stree_arg_has_attr(arg, aac_packed)) {
+				fun->varg = arg;
+				break;
+			} else {
+				list_append(&fun->args, arg);
+			}
+
+			if (lcur_lc(parse) == lc_rparen)
+				break;
+
+			lmatch(parse, lc_scolon);
+		}
+	}
+
+	lmatch(parse, lc_rparen);
+
+	if (lcur_lc(parse) == lc_colon) {
+	    	lskip(parse);
+		fun->rtype = parse_texpr(parse);
+	} else {
+		fun->rtype = NULL;
+	}
+
+	list_init(&symbol->attr);
+
+	/* Parse attributes. */
+	while (lcur_lc(parse) == lc_comma && !parse_is_error(parse)) {
+		lskip(parse);
+		attr = parse_symbol_attr(parse);
+		list_append(&symbol->attr, attr);
+	}
+
+	fun->proc = stree_proc_new();
+	fun->proc->outer_symbol = symbol;
+
+	if (lcur_lc(parse) == lc_scolon) {
+		lskip(parse);
+
+		/* This function has no body. */
+		if (!stree_symbol_has_attr(symbol, sac_builtin)) {
+			printf("Error: Function '");
+			symbol_print_fqn(symbol);
+			printf("' has no body.\n");
+			parse_note_error(parse);
+		}
+		fun->proc->body = NULL;
+	} else {
+		lmatch(parse, lc_is);
+		fun->proc->body = parse_block(parse);
+		lmatch(parse, lc_end);
+	}
+
+	return fun;
+}
+
+/** Parse member variable.
+ *
+ * @param parse		Parser object.
+ * @param outer_csi	CSI containing this declaration or @c NULL if global.
+ * @return		New syntax tree node.
+ */
+static stree_var_t *parse_var(parse_t *parse, stree_csi_t *outer_csi)
+{
+	stree_var_t *var;
+	stree_symbol_t *symbol;
+
+	var = stree_var_new();
+	symbol = stree_symbol_new(sc_var);
+	symbol->u.var = var;
+	symbol->outer_csi = outer_csi;
+	var->symbol = symbol;
+
+	lmatch(parse, lc_var);
+	var->name = parse_ident(parse);
+	lmatch(parse, lc_colon);
+	var->type =  parse_texpr(parse);
+	lmatch(parse, lc_scolon);
+
+	return var;
+}
+
+/** Parse member property.
+ *
+ * @param parse		Parser object.
+ * @param outer_csi	CSI containing this declaration or @c NULL if global.
+ * @return		New syntax tree node.
+ */
+static stree_prop_t *parse_prop(parse_t *parse, stree_csi_t *outer_csi)
+{
+	stree_prop_t *prop;
+	stree_symbol_t *symbol;
+
+	stree_ident_t *ident;
+	stree_proc_arg_t *arg;
+
+	prop = stree_prop_new();
+	list_init(&prop->args);
+
+	symbol = stree_symbol_new(sc_prop);
+	symbol->u.prop = prop;
+	symbol->outer_csi = outer_csi;
+	prop->symbol = symbol;
+
+	lmatch(parse, lc_prop);
+
+	if (lcur_lc(parse) == lc_self) {
+		/* Indexed property set */
+
+		/* Use some name that is impossible as identifier. */
+		ident = stree_ident_new();
+		ident->sid = strtab_get_sid(INDEXER_IDENT);
+		prop->name = ident;
+
+		lskip(parse);
+		lmatch(parse, lc_lsbr);
+
+		/* Parse formal parameters. */
+		while (!parse_is_error(parse)) {
+			arg = parse_proc_arg(parse);
+			if (stree_arg_has_attr(arg, aac_packed)) {
+				prop->varg = arg;
+				break;
+			} else {
+				list_append(&prop->args, arg);
+			}
+
+			if (lcur_lc(parse) == lc_rsbr)
+				break;
+
+			lmatch(parse, lc_scolon);
+		}
+
+		lmatch(parse, lc_rsbr);
+	} else {
+		/* Named property */
+		prop->name = parse_ident(parse);
+	}
+
+	lmatch(parse, lc_colon);
+	prop->type = parse_texpr(parse);
+	lmatch(parse, lc_is);
+
+	while (lcur_lc(parse) != lc_end && !parse_is_error(parse)) {
+		switch (lcur_lc(parse)) {
+		case lc_get:
+			lskip(parse);
+			lmatch(parse, lc_is);
+			if (prop->getter != NULL) {
+				printf("Error: Duplicate getter.\n");
+				(void) parse_block(parse); /* XXX Free */
+				lmatch(parse, lc_end);
+				parse_note_error(parse);
+				break;
+			}
+
+			/* Create setter procedure */
+			prop->getter = stree_proc_new();
+			prop->getter->body = parse_block(parse);
+			prop->getter->outer_symbol = symbol;
+
+			lmatch(parse, lc_end);
+			break;
+		case lc_set:
+			lskip(parse);
+			prop->setter_arg = stree_proc_arg_new();
+			prop->setter_arg->name = parse_ident(parse);
+			prop->setter_arg->type = prop->type;
+			lmatch(parse, lc_is);
+			if (prop->setter != NULL) {
+				printf("Error: Duplicate setter.\n");
+				(void) parse_block(parse); /* XXX Free */
+				lmatch(parse, lc_end);
+				parse_note_error(parse);
+			}
+
+			/* Create setter procedure */
+			prop->setter = stree_proc_new();
+			prop->setter->body = parse_block(parse);
+			prop->setter->outer_symbol = symbol;
+
+			lmatch(parse, lc_end);
+			break;
+		default:
+			lunexpected_error(parse);
+		}
+	}
+
+	lmatch(parse, lc_end);
+
+	return prop;
+}
+
+/** Parse symbol attribute.
+ *
+ * @param parse		Parser object.
+ * @param outer_csi	CSI containing this declaration or @c NULL if global.
+ * @return		New syntax tree node.
+ */
+static stree_symbol_attr_t *parse_symbol_attr(parse_t *parse)
+{
+	stree_symbol_attr_t *attr;
+
+	if (lcur_lc(parse) != lc_builtin) {
+		printf("Error: Unexpected attribute '");
+		lem_print(lcur(parse));
+		printf("'.\n");
+		parse_note_error(parse);
+	}
+
+	lskip(parse);
+
+	attr = stree_symbol_attr_new(sac_builtin);
+	return attr;
+}
+
+/** Parse formal function argument.
+ *
+ * @param parse		Parser object.
+ * @return		New syntax tree node.
+ */
+static stree_proc_arg_t *parse_proc_arg(parse_t *parse)
+{
+	stree_proc_arg_t *arg;
+	stree_arg_attr_t *attr;
+
+	arg = stree_proc_arg_new();
+	arg->name = parse_ident(parse);
+	lmatch(parse, lc_colon);
+	arg->type = parse_texpr(parse);
+
+	list_init(&arg->attr);
+
+	/* Parse attributes. */
+	while (lcur_lc(parse) == lc_comma && !parse_is_error(parse)) {
+		lskip(parse);
+		attr = parse_arg_attr(parse);
+		list_append(&arg->attr, attr);
+	}
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parsed arg attr, type=%p.\n", arg->type);
+#endif
+	return arg;
+}
+
+/** Parse argument attribute.
+ *
+ * @param parse		Parser object.
+ * @return		New syntax tree node.
+ */
+static stree_arg_attr_t *parse_arg_attr(parse_t *parse)
+{
+	stree_arg_attr_t *attr;
+
+	if (lcur_lc(parse) != lc_packed) {
+		printf("Error: Unexpected attribute '");
+		lem_print(lcur(parse));
+		printf("'.\n");
+		parse_note_error(parse);
+	}
+
+	lskip(parse);
+
+	attr = stree_arg_attr_new(aac_packed);
+	return attr;
+}
+
+/** Parse statement block.
+ *
+ * @param parse		Parser object.
+ * @return		New syntax tree node.
+ */
+static stree_block_t *parse_block(parse_t *parse)
+{
+	stree_block_t *block;
+	stree_stat_t *stat;
+
+	block = stree_block_new();
+	list_init(&block->stats);
+
+	/* Avoid peeking if there is an error condition. */
+	if (parse_is_error(parse))
+		return block;
+
+	while (terminates_block(lcur_lc(parse)) != b_true &&
+	    !parse_is_error(parse)) {
+
+		stat = parse_stat(parse);
+		list_append(&block->stats, stat);
+	}
+
+	return block;
+}
+
+/** Parse statement.
+ *
+ * @param parse		Parser object.
+ * @return		New syntax tree node.
+ */
+stree_stat_t *parse_stat(parse_t *parse)
+{
+	stree_stat_t *stat;
+
+	stree_vdecl_t *vdecl_s;
+	stree_if_t *if_s;
+	stree_while_t *while_s;
+	stree_for_t *for_s;
+	stree_raise_t *raise_s;
+	stree_return_t *return_s;
+	stree_wef_t *wef_s;
+	stree_exps_t *exp_s;
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parse statement.\n");
+#endif
+	switch (lcur_lc(parse)) {
+	case lc_var:
+		vdecl_s = parse_vdecl(parse);
+		stat = stree_stat_new(st_vdecl);
+		stat->u.vdecl_s = vdecl_s;
+		break;
+	case lc_if:
+		if_s = parse_if(parse);
+		stat = stree_stat_new(st_if);
+		stat->u.if_s = if_s;
+		break;
+	case lc_while:
+		while_s = parse_while(parse);
+		stat = stree_stat_new(st_while);
+		stat->u.while_s = while_s;
+		break;
+	case lc_for:
+		for_s = parse_for(parse);
+		stat = stree_stat_new(st_for);
+		stat->u.for_s = for_s;
+		break;
+	case lc_raise:
+		raise_s = parse_raise(parse);
+		stat = stree_stat_new(st_raise);
+		stat->u.raise_s = raise_s;
+		break;
+	case lc_return:
+		return_s = parse_return(parse);
+		stat = stree_stat_new(st_return);
+		stat->u.return_s = return_s;
+		break;
+	case lc_do:
+	case lc_with:
+		wef_s = parse_wef(parse);
+		stat = stree_stat_new(st_wef);
+		stat->u.wef_s = wef_s;
+		break;
+	default:
+		exp_s = parse_exps(parse);
+		stat = stree_stat_new(st_exps);
+		stat->u.exp_s = exp_s;
+		break;
+	}
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parsed statement %p\n", stat);
+#endif
+	return stat;
+}
+
+/** Parse variable declaration statement.
+ *
+ * @param parse		Parser object.
+ * @return		New syntax tree node.
+ */
+static stree_vdecl_t *parse_vdecl(parse_t *parse)
+{
+	stree_vdecl_t *vdecl;
+
+	vdecl = stree_vdecl_new();
+
+	lmatch(parse, lc_var);
+	vdecl->name = parse_ident(parse);
+	lmatch(parse, lc_colon);
+	vdecl->type = parse_texpr(parse);
+
+	if (lcur_lc(parse) == lc_assign) {
+		lskip(parse);
+		(void) parse_expr(parse);
+	}
+
+	lmatch(parse, lc_scolon);
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parsed vdecl for '%s'\n", strtab_get_str(vdecl->name->sid));
+	printf("vdecl = %p, vdecl->name = %p, sid=%d\n",
+	    vdecl, vdecl->name, vdecl->name->sid);
+#endif
+	return vdecl;
+}
+
+/** Parse @c if statement.
+ *
+ * @param parse		Parser object.
+ * @return		New syntax tree node.
+ */
+static stree_if_t *parse_if(parse_t *parse)
+{
+	stree_if_t *if_s;
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parse 'if' statement.\n");
+#endif
+	if_s = stree_if_new();
+
+	lmatch(parse, lc_if);
+	if_s->cond = parse_expr(parse);
+	lmatch(parse, lc_then);
+	if_s->if_block = parse_block(parse);
+
+	if (lcur_lc(parse) == lc_else) {
+		lskip(parse);
+		if_s->else_block = parse_block(parse);
+	} else {
+		if_s->else_block = NULL;
+	}
+
+	lmatch(parse, lc_end);
+	return if_s;
+}
+
+/** Parse @c while statement.
+ *
+ * @param parse		Parser object.
+ */
+static stree_while_t *parse_while(parse_t *parse)
+{
+	stree_while_t *while_s;
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parse 'while' statement.\n");
+#endif
+	while_s = stree_while_new();
+
+	lmatch(parse, lc_while);
+	while_s->cond = parse_expr(parse);
+	lmatch(parse, lc_do);
+	while_s->body = parse_block(parse);
+	lmatch(parse, lc_end);
+
+	return while_s;
+}
+
+/** Parse @c for statement.
+ *
+ * @param parse		Parser object.
+ * @return		New syntax tree node.
+ */
+static stree_for_t *parse_for(parse_t *parse)
+{
+	stree_for_t *for_s;
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parse 'for' statement.\n");
+#endif
+	for_s = stree_for_new();
+
+	lmatch(parse, lc_for);
+	lmatch(parse, lc_ident);
+	lmatch(parse, lc_colon);
+	(void) parse_texpr(parse);
+	lmatch(parse, lc_in);
+	(void) parse_expr(parse);
+	lmatch(parse, lc_do);
+	for_s->body = parse_block(parse);
+	lmatch(parse, lc_end);
+
+	return for_s;
+}
+
+/** Parse @c raise statement.
+ *
+ * @param parse		Parser object.
+ */
+static stree_raise_t *parse_raise(parse_t *parse)
+{
+	stree_raise_t *raise_s;
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parse 'raise' statement.\n");
+#endif
+	raise_s = stree_raise_new();
+	lmatch(parse, lc_raise);
+	raise_s->expr = parse_expr(parse);
+	lmatch(parse, lc_scolon);
+
+	return raise_s;
+}
+
+/** Parse @c return statement.
+ *
+ * @param parse		Parser object.
+ * @return		New syntax tree node.
+ */
+static stree_return_t *parse_return(parse_t *parse)
+{
+	stree_return_t *return_s;
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parse 'return' statement.\n");
+#endif
+	return_s = stree_return_new();
+
+	lmatch(parse, lc_return);
+	return_s->expr = parse_expr(parse);
+	lmatch(parse, lc_scolon);
+
+	return return_s;
+}
+
+/* Parse @c with-except-finally statement.
+ *
+ * @param parse		Parser object.
+ * @return		New syntax tree node.
+ */
+static stree_wef_t *parse_wef(parse_t *parse)
+{
+	stree_wef_t *wef_s;
+	stree_except_t *except_c;
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parse WEF statement.\n");
+#endif
+	wef_s = stree_wef_new();
+	list_init(&wef_s->except_clauses);
+
+	if (lcur_lc(parse) == lc_with) {
+		lmatch(parse, lc_with);
+		lmatch(parse, lc_ident);
+		lmatch(parse, lc_colon);
+		(void) parse_texpr(parse);
+		lmatch(parse, lc_assign);
+		(void) parse_expr(parse);
+	}
+
+	lmatch(parse, lc_do);
+	wef_s->with_block = parse_block(parse);
+
+	while (lcur_lc(parse) == lc_except && !parse_is_error(parse)) {
+		except_c = parse_except(parse);
+		list_append(&wef_s->except_clauses, except_c);
+	}
+
+	if (lcur_lc(parse) == lc_finally) {
+		lmatch(parse, lc_finally);
+		lmatch(parse, lc_do);
+		wef_s->finally_block = parse_block(parse);
+	} else {
+		wef_s->finally_block = NULL;
+	}
+
+	lmatch(parse, lc_end);
+
+	return wef_s;
+}
+
+/* Parse expression statement.
+ *
+ * @param parse		Parser object.
+ * @return		New syntax tree node.
+ */
+static stree_exps_t *parse_exps(parse_t *parse)
+{
+	stree_expr_t *expr;
+	stree_exps_t *exps;
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parse expression statement.\n");
+#endif
+	expr = parse_expr(parse);
+	lmatch(parse, lc_scolon);
+
+	exps = stree_exps_new();
+	exps->expr = expr;
+
+	return exps;
+}
+
+/* Parse @c except clause.
+ *
+ * @param parse		Parser object.
+ * @return		New syntax tree node.
+ */
+static stree_except_t *parse_except(parse_t *parse)
+{
+	stree_except_t *except_c;
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parse 'except' statement.\n");
+#endif
+	except_c = stree_except_new();
+
+	lmatch(parse, lc_except);
+	except_c->evar = parse_ident(parse);
+	lmatch(parse, lc_colon);
+	except_c->etype = parse_texpr(parse);
+	lmatch(parse, lc_do);
+
+	except_c->block = parse_block(parse);
+
+	return except_c;
+}
+
+/** Parse identifier.
+ *
+ * @param parse		Parser object.
+ * @return		New syntax tree node.
+ */
+stree_ident_t *parse_ident(parse_t *parse)
+{
+	stree_ident_t *ident;
+
+#ifdef DEBUG_PARSE_TRACE
+	printf("Parse identifier.\n");
+#endif
+	lcheck(parse, lc_ident);
+	ident = stree_ident_new();
+	ident->sid = lcur(parse)->u.ident.sid;
+	lskip(parse);
+
+	return ident;
+}
+
+/** Signal a parse error, start bailing out from parser. 
+ *
+ * @param parse		Parser object.
+ */
+void parse_raise_error(parse_t *parse)
+{
+	parse->error = b_true;
+	parse->error_bailout = b_true;
+}
+
+/** Note a parse error that has been immediately recovered.
+ *
+ * @param parse		Parser object.
+ */
+void parse_note_error(parse_t *parse)
+{
+	parse->error = b_true;
+}
+
+/** Check if we are currently bailing out of parser due to a parse error.
+ *
+ * @param parse		Parser object.
+ */
+bool_t parse_is_error(parse_t *parse)
+{
+	return parse->error_bailout;
+}
+
+/** Recover from parse error bailout.
+ *
+ * Still remember that there was an error, but stop bailing out.
+ *
+ * @param parse		Parser object.
+ */
+void parse_recover_error(parse_t *parse)
+{
+	assert(parse->error == b_true);
+	assert(parse->error_bailout == b_true);
+
+	parse->error_bailout = b_false;
+}
+
+/** Return current lem.
+ *
+ * @param parse		Parser object.
+ * @return		Pointer to current lem. Only valid until the lexing
+ *			position is advanced.
+ */
+lem_t *lcur(parse_t *parse)
+{
+#ifdef DEBUG_LPARSE_TRACE
+	printf("lcur()\n");
+#endif
+	return lex_get_current(parse->lex);
+}
+
+/** Return current lem lclass.
+ *
+ * @param parse		Parser object.
+ * @return		Lclass of the current lem.
+ */
+lclass_t lcur_lc(parse_t *parse)
+{
+	lem_t *lem;
+
+	/*
+	 * This allows us to skip error checking in many places. If there is an
+	 * active error, lcur_lc() returns lc_invalid without reading input.
+	 *
+	 * Without this measure we would have to check for error all the time
+	 * or risk requiring extra input from the user (in interactive mode)
+	 * before actually bailing out from the parser.
+	 */
+	if (parse_is_error(parse))
+		return lc_invalid;
+
+	lem = lcur(parse);
+	return lem->lclass;
+}
+
+/** Skip to next lem.
+ *
+ * @param parse		Parser object.
+ */
+void lskip(parse_t *parse)
+{
+#ifdef DEBUG_LPARSE_TRACE
+	printf("lskip()\n");
+#endif
+	lex_next(parse->lex);
+}
+
+/** Verify that lclass of current lem is @a lc.
+ *
+ * If a lem of different lclass is found, a parse error is raised and
+ * a message is printed.
+ *
+ * @param parse		Parser object.
+ * @param lc		Expected lclass.
+ */
+void lcheck(parse_t *parse, lclass_t lc)
+{
+#ifdef DEBUG_LPARSE_TRACE
+	printf("lcheck(");
+	lclass_print(lc);
+	printf(")\n");
+#endif
+	if (lcur(parse)->lclass != lc) {
+		lem_print_coords(lcur(parse));
+		printf(" Error: expected '"); lclass_print(lc);
+		printf("', got '"); lem_print(lcur(parse));
+		printf("'.\n");
+		parse_raise_error(parse);
+	}
+}
+
+/** Verify that lclass of current lem is @a lc and go to next lem.
+ *
+ * If a lem of different lclass is found, a parse error is raised and
+ * a message is printed.
+ *
+ * @param parse		Parser object.
+ * @param lc		Expected lclass.
+ */
+void lmatch(parse_t *parse, lclass_t lc)
+{
+#ifdef DEBUG_LPARSE_TRACE
+	printf("lmatch(");
+	lclass_print(lc);
+	printf(")\n");
+#endif
+	/*
+	 * This allows us to skip error checking in many places. If there is an
+	 * active error, lmatch() does nothing (similar to parse_block(), etc.
+	 *
+	 * Without this measure we would have to check for error all the time
+	 * or risk requiring extra input from the user (in interactive mode)
+	 * before actually bailing out from the parser.
+	 */
+	if (parse_is_error(parse))
+		return;
+
+	lcheck(parse, lc);
+	lskip(parse);
+}
+
+/** Raise and display generic parsing error.
+ *
+ * @param parse		Parser object.
+ */
+void lunexpected_error(parse_t *parse)
+{
+	lem_print_coords(lcur(parse));
+	printf(" Error: unexpected token '");
+	lem_print(lcur(parse));
+	printf("'.\n");
+	parse_raise_error(parse);
+}
+
+/** Determine whether @a lclass is in follow(block).
+ *
+ * Tests whether @a lclass belongs to the follow(block) set, i.e. if it is
+ * lclass of a lem that can follow a block in the program.
+ *
+ * @param lclass	Lclass.
+ */
+bool_t terminates_block(lclass_t lclass)
+{
+	switch (lclass) {
+	case lc_else:
+	case lc_end:
+	case lc_except:
+	case lc_finally:
+		return b_true;
+	default:
+		return b_false;
+	}
+}
Index: uspace/app/sbi/src/parse.h
===================================================================
--- uspace/app/sbi/src/parse.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/parse.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef PARSE_H_
+#define PARSE_H_
+
+#include "mytypes.h"
+
+void parse_init(parse_t *parse, struct stree_program *prog, struct lex *lex);
+void parse_module(parse_t *parse);
+
+stree_stat_t *parse_stat(parse_t *parse);
+stree_ident_t *parse_ident(parse_t *parse);
+
+void parse_raise_error(parse_t *parse);
+void parse_note_error(parse_t *parse);
+bool_t parse_is_error(parse_t *parse);
+void parse_recover_error(parse_t *parse);
+
+/*
+ * Parsing primitives
+ */
+lem_t *lcur(parse_t *parse);
+lclass_t lcur_lc(parse_t *parse);
+void lskip(parse_t *parse);
+void lcheck(parse_t *parse, lclass_t lc);
+void lmatch(parse_t *parse, lclass_t lc);
+void lunexpected_error(parse_t *parse);
+
+bool_t terminates_block(lclass_t lclass);
+
+#endif
Index: uspace/app/sbi/src/parse_t.h
===================================================================
--- uspace/app/sbi/src/parse_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/parse_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef PARSE_T_H_
+#define PARSE_T_H_
+
+/** Parser state object */
+typedef struct {
+	/** Lexer object */
+	struct lex *lex;
+
+	/** Program being parsed */
+	struct stree_program *program;
+
+	/** Module currently being parsed */
+	struct stree_module *cur_mod;
+
+	/** @c b_true if an error occured. */
+	bool_t error;
+
+	/** @c b_true if bailing out due to an error. */
+	bool_t error_bailout;
+} parse_t;
+
+#endif
Index: uspace/app/sbi/src/program.c
===================================================================
--- uspace/app/sbi/src/program.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/program.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Main module.
+ *
+ * Main entry point for SBI, the Sysel Bootstrap Interpreter.
+ * When run without parameters, the interpreter will enter interactive
+ * mode.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "os/os.h"
+#include "mytypes.h"
+#include "stype.h"
+#include "input.h"
+#include "lex.h"
+#include "parse.h"
+
+#include "program.h"
+
+#define MAX_NAME_SIZE 64
+static char name_buf[MAX_NAME_SIZE + 1];
+
+/** Process one specified source file.
+ *
+ * @param program 	The program to which the parsed code is added.
+ * @param fname		Name of file to read from.
+ * @return		EOK on success, EIO if file is not found,
+ *			EINVAL if file has syntax errors.
+ */
+int program_file_process(stree_program_t *program, const char *fname)
+{
+	input_t *input;
+	lex_t lex;
+	parse_t parse;
+	int rc;
+
+	rc = input_new_file(&input, fname);
+	if (rc != EOK) {
+		printf("Failed opening source file '%s'.\n", fname);
+		return EIO;
+	}
+
+	/* Parse input file. */
+	lex_init(&lex, input);
+	parse_init(&parse, program, &lex);
+	parse_module(&parse);
+
+	/* Check for parse errors. */
+	if (parse.error)
+		return EINVAL;
+
+	return EOK;
+}
+
+/** Process sources of the library. 
+ *
+ * Processes all source files in the library. The list of library source files
+ * is read from '<libdir>/libflist'. Each line of the file contains one file
+ * name relative to <libdir>.
+ */
+int program_lib_process(stree_program_t *program)
+{
+	int rc;
+	char *path, *fname;
+	char *tmp;
+	char *cp;
+
+	FILE *f;
+
+	path = os_get_lib_path();
+	fname = os_str_acat(path, "/libflist");
+
+	f = fopen(fname, "rt");
+	if (f == NULL) {
+		printf("Failed opening library list file '%s'.\n", fname);
+		free(path);
+		free(fname);
+		return EIO;
+	}
+
+	free(fname);
+
+	while (b_true) {
+		if (fgets(name_buf, MAX_NAME_SIZE + 1, f) == NULL)
+			break;
+
+		/*
+		 * Remove trailing newline, if present.
+		 */
+		cp = name_buf;
+		while (*cp != '\0' && *cp != '\n')
+			++cp;
+
+		if (*cp == '\n')
+			*cp = '\0';
+
+		tmp = os_str_acat(path, "/");
+		fname = os_str_acat(tmp, name_buf);
+		free(tmp);
+
+		rc = program_file_process(program, fname);
+		if (rc != EOK) {
+			free(fname);
+			free(path);
+			fclose(f);
+			return rc;
+		}
+
+		free(fname);
+	}
+
+	if (ferror(f)) {
+		printf("Error reading from library list file.\n");
+		free(path);
+		fclose(f);
+		return EIO;
+	}
+
+	free(path);
+	fclose(f);
+
+	return rc;
+}
Index: uspace/app/sbi/src/program.h
===================================================================
--- uspace/app/sbi/src/program.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/program.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef PROGRAM_H_
+#define PROGRAM_H_
+
+#include "mytypes.h"
+
+int program_file_process(stree_program_t *program, const char *fname);
+int program_lib_process(stree_program_t *program);
+
+#endif
Index: uspace/app/sbi/src/rdata.c
===================================================================
--- uspace/app/sbi/src/rdata.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/rdata.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,736 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Run-time data representation.
+ *
+ * At run time SBI represents all data as a graph of interconnected @c var
+ * nodes (variable nodes). Any piece of memory addressable by the program
+ * (i.e. all variables) are stored in var nodes. However, var nodes are also
+ * used internally to implement value items. (I.e. values in value items
+ * have exactly the same structure as program variables).
+ *
+ * Unlike byte- or word-oriented memory on a real machine, var nodes provide
+ * structured and typed storage. (This typing is dynamic, however and has
+ * nothing to do with the static type system).
+ *
+ * There are several types of var nodes, one for each primitive type,
+ * reference, delegate, array, and object. A reference var node contains
+ * a pointer to another var node. Delegate var node points to some stree
+ * declaration. Array and object var nodes refer to a collection of child
+ * nodes (fields, elements).
+ */
+
+#include <stdlib.h>
+#include <assert.h>
+#include "bigint.h"
+#include "mytypes.h"
+#include "stree.h"
+#include "symbol.h"
+
+#include "rdata.h"
+
+static void rdata_bool_copy(rdata_bool_t *src, rdata_bool_t **dest);
+static void rdata_char_copy(rdata_char_t *src, rdata_char_t **dest);
+static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest);
+static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest);
+static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest);
+static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest);
+static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest);
+static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest);
+static void rdata_resource_copy(rdata_resource_t *src,
+    rdata_resource_t **dest);
+
+static int rdata_array_get_dim(rdata_array_t *array);
+
+static void rdata_address_print(rdata_address_t *address);
+static void rdata_var_print(rdata_var_t *var);
+
+/** Allocate new data item.
+ *
+ * @param ic	Item class.
+ * @return	New item.
+ */
+rdata_item_t *rdata_item_new(item_class_t ic)
+{
+	rdata_item_t *item;
+
+	item = calloc(1, sizeof(rdata_item_t));
+	if (item == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	item->ic = ic;
+	return item;
+}
+
+/** Allocate new address.
+ *
+ * @return	New address.
+ */
+rdata_addr_var_t *rdata_addr_var_new(void)
+{
+	rdata_addr_var_t *addr_var;
+
+	addr_var = calloc(1, sizeof(rdata_addr_var_t));
+	if (addr_var == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return addr_var;
+}
+
+/** Allocate new named property address.
+ *
+ * @return	New named property address.
+ */
+rdata_aprop_named_t *rdata_aprop_named_new(void)
+{
+	rdata_aprop_named_t *aprop_named;
+
+	aprop_named = calloc(1, sizeof(rdata_aprop_named_t));
+	if (aprop_named == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return aprop_named;
+}
+
+/** Allocate new indexed property address.
+ *
+ * @return	New indexed property address.
+ */
+rdata_aprop_indexed_t *rdata_aprop_indexed_new(void)
+{
+	rdata_aprop_indexed_t *aprop_indexed;
+
+	aprop_indexed = calloc(1, sizeof(rdata_aprop_indexed_t));
+	if (aprop_indexed == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return aprop_indexed;
+}
+
+/** Allocate new property address.
+ *
+ * @param apc	Property address class.
+ * @return	New property address.
+ */
+rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc)
+{
+	rdata_addr_prop_t *addr_prop;
+
+	addr_prop = calloc(1, sizeof(rdata_addr_prop_t));
+	if (addr_prop == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	addr_prop->apc = apc;
+	return addr_prop;
+}
+
+/** Allocate new address.
+ *
+ * @param ac	Address class.
+ * @return	New address.
+ */
+rdata_address_t *rdata_address_new(address_class_t ac)
+{
+	rdata_address_t *address;
+
+	address = calloc(1, sizeof(rdata_address_t));
+	if (address == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	address->ac = ac;
+	return address;
+}
+
+/** Allocate new value.
+ *
+ * @return	New value.
+ */
+rdata_value_t *rdata_value_new(void)
+{
+	rdata_value_t *value;
+
+	value = calloc(1, sizeof(rdata_value_t));
+	if (value == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return value;
+}
+
+/** Allocate new var node.
+ *
+ * @param vc	Var node class (varclass).
+ * @return	New var node.
+ */
+rdata_var_t *rdata_var_new(var_class_t vc)
+{
+	rdata_var_t *var;
+
+	var = calloc(1, sizeof(rdata_var_t));
+	if (var == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	var->vc = vc;
+	return var;
+}
+
+/** Allocate new reference.
+ *
+ * @return	New reference.
+ */
+rdata_ref_t *rdata_ref_new(void)
+{
+	rdata_ref_t *ref;
+
+	ref = calloc(1, sizeof(rdata_ref_t));
+	if (ref == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return ref;
+}
+
+/** Allocate new delegate.
+ *
+ * @return	New delegate.
+ */
+rdata_deleg_t *rdata_deleg_new(void)
+{
+	rdata_deleg_t *deleg;
+
+	deleg = calloc(1, sizeof(rdata_deleg_t));
+	if (deleg == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return deleg;
+}
+
+/** Allocate new array.
+ *
+ * @return	New array.
+ */
+rdata_array_t *rdata_array_new(int rank)
+{
+	rdata_array_t *array;
+
+	array = calloc(1, sizeof(rdata_array_t));
+	if (array == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	array->rank = rank;
+	array->extent = calloc(rank, sizeof(int));
+	if (array == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return array;
+}
+
+/** Allocate new object.
+ *
+ * @return	New object.
+ */
+rdata_object_t *rdata_object_new(void)
+{
+	rdata_object_t *object;
+
+	object = calloc(1, sizeof(rdata_object_t));
+	if (object == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return object;
+}
+
+/** Allocate new boolean.
+ *
+ * @return	New boolean.
+ */
+rdata_bool_t *rdata_bool_new(void)
+{
+	rdata_bool_t *bool_v;
+
+	bool_v = calloc(1, sizeof(rdata_bool_t));
+	if (bool_v == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return bool_v;
+}
+
+/** Allocate new character.
+ *
+ * @return	New character.
+ */
+rdata_char_t *rdata_char_new(void)
+{
+	rdata_char_t *char_v;
+
+	char_v = calloc(1, sizeof(rdata_char_t));
+	if (char_v == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return char_v;
+}
+
+/** Allocate new integer.
+ *
+ * @return	New integer.
+ */
+rdata_int_t *rdata_int_new(void)
+{
+	rdata_int_t *int_v;
+
+	int_v = calloc(1, sizeof(rdata_int_t));
+	if (int_v == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return int_v;
+}
+
+/** Allocate new string.
+ *
+ * @return	New string.
+ */
+rdata_string_t *rdata_string_new(void)
+{
+	rdata_string_t *string_v;
+
+	string_v = calloc(1, sizeof(rdata_string_t));
+	if (string_v == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return string_v;
+}
+
+/** Allocate new resource.
+ *
+ * @return	New resource.
+ */
+rdata_resource_t *rdata_resource_new(void)
+{
+	rdata_resource_t *resource_v;
+
+	resource_v = calloc(1, sizeof(rdata_resource_t));
+	if (resource_v == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return resource_v;
+}
+
+/** Allocate array elements.
+ *
+ * Allocates var nodes for elements of @a array.
+ *
+ * @param array		Array.
+ */
+void rdata_array_alloc_element(rdata_array_t *array)
+{
+	int dim, idx;
+
+	dim = rdata_array_get_dim(array);
+
+	array->element = calloc(dim, sizeof(rdata_var_t *));
+	if (array->element == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	for (idx = 0; idx < dim; ++idx) {
+		array->element[idx] = calloc(1, sizeof(rdata_var_t));
+		if (array->element[idx] == NULL) {
+			printf("Memory allocation failed.\n");
+			exit(1);
+		}
+	}
+}
+
+/** Get array dimension.
+ *
+ * Dimension is the total number of elements in an array, in other words,
+ * the product of all extents.
+ *
+ * @param array		Array.
+ */
+static int rdata_array_get_dim(rdata_array_t *array)
+{
+	int didx, dim;
+
+	dim = 1;
+	for (didx = 0; didx < array->rank; ++didx)
+		dim = dim * array->extent[didx];
+
+	return dim;
+}
+
+/** Make copy of a variable.
+ *
+ * Creates a new var node that is an exact copy of an existing var node.
+ * This can be thought of as a shallow copy.
+ *
+ * @param src		Source var node.
+ * @param dest		Place to store pointer to new var node.
+ */
+void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest)
+{
+	rdata_var_t *nvar;
+
+	nvar = rdata_var_new(src->vc);
+
+	switch (src->vc) {
+	case vc_bool:
+		rdata_bool_copy(src->u.bool_v, &nvar->u.bool_v);
+		break;
+	case vc_char:
+		rdata_char_copy(src->u.char_v, &nvar->u.char_v);
+		break;
+	case vc_int:
+		rdata_int_copy(src->u.int_v, &nvar->u.int_v);
+		break;
+	case vc_string:
+		rdata_string_copy(src->u.string_v, &nvar->u.string_v);
+		break;
+	case vc_ref:
+		rdata_ref_copy(src->u.ref_v, &nvar->u.ref_v);
+		break;
+	case vc_deleg:
+		rdata_deleg_copy(src->u.deleg_v, &nvar->u.deleg_v);
+		break;
+	case vc_array:
+		rdata_array_copy(src->u.array_v, &nvar->u.array_v);
+		break;
+	case vc_object:
+		rdata_object_copy(src->u.object_v, &nvar->u.object_v);
+		break;
+	case vc_resource:
+		rdata_resource_copy(src->u.resource_v, &nvar->u.resource_v);
+		break;
+	}
+
+	*dest = nvar;
+}
+
+/** Copy boolean.
+ *
+ * @param src		Source boolean.
+ * @param dest		Place to store pointer to new boolean.
+ */
+static void rdata_bool_copy(rdata_bool_t *src, rdata_bool_t **dest)
+{
+	*dest = rdata_bool_new();
+	(*dest)->value = src->value;
+}
+
+/** Copy character.
+ *
+ * @param src		Source character.
+ * @param dest		Place to store pointer to new character.
+ */
+static void rdata_char_copy(rdata_char_t *src, rdata_char_t **dest)
+{
+	*dest = rdata_char_new();
+	bigint_clone(&src->value, &(*dest)->value);
+}
+
+/** Copy integer.
+ *
+ * @param src		Source integer.
+ * @param dest		Place to store pointer to new integer.
+ */
+static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest)
+{
+	*dest = rdata_int_new();
+	bigint_clone(&src->value, &(*dest)->value);
+}
+
+/** Copy string.
+ *
+ * @param src		Source string.
+ * @param dest		Place to store pointer to new string.
+ */
+static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest)
+{
+	*dest = rdata_string_new();
+	(*dest)->value = src->value;
+}
+
+/** Copy reference.
+ *
+ * @param src		Source reference.
+ * @param dest		Place to store pointer to new reference.
+ */
+static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest)
+{
+	*dest = rdata_ref_new();
+	(*dest)->vref = src->vref;
+}
+
+/** Copy delegate.
+ *
+ * @param src		Source delegate.
+ * @param dest		Place to store pointer to new delegate.
+ */
+static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest)
+{
+	(void) src; (void) dest;
+	printf("Unimplemented: Copy delegate.\n");
+	exit(1);
+}
+
+/** Copy array.
+ *
+ * @param src		Source array.
+ * @param dest		Place to store pointer to new array.
+ */
+static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest)
+{
+	(void) src; (void) dest;
+	printf("Unimplemented: Copy array.\n");
+	exit(1);
+}
+
+/** Copy object.
+ *
+ * @param src		Source object.
+ * @param dest		Place to store pointer to new object.
+ */
+static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest)
+{
+	(void) src; (void) dest;
+	printf("Unimplemented: Copy object.\n");
+	exit(1);
+}
+
+/** Copy resource.
+ *
+ * @param src		Source resource.
+ * @param dest		Place to store pointer to new resource.
+ */
+static void rdata_resource_copy(rdata_resource_t *src, rdata_resource_t **dest)
+{
+	*dest = rdata_resource_new();
+	(*dest)->data = src->data;
+}
+
+/** Read data from a variable.
+ *
+ * This copies data from the variable to a value item. Ideally any read access
+ * to a program variable should go through this function. (Keep in mind
+ * that although values are composed of var nodes internally, but are not
+ * variables per se. Therefore this function is not used to read from values)
+ *
+ * @param var		Variable to read from (var node where it is stored).
+ * @param ritem		Place to store pointer to new value item read from
+ *			the variable.
+ */
+void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem)
+{
+	rdata_value_t *value;
+	rdata_var_t *rvar;
+
+	/* Perform a shallow copy of @a var. */
+	rdata_var_copy(var, &rvar);
+
+	value = rdata_value_new();
+	value->var = rvar;
+	*ritem = rdata_item_new(ic_value);
+	(*ritem)->u.value = value;
+}
+
+/** Write data to a variable.
+ *
+ * This copies data to the variable from a value. Ideally any write access
+ * to a program variable should go through this function. (Keep in mind
+ * that even though values are composed of var nodes internally, but are not
+ * variables per se. Therefore this function is not used to write to values)
+ *
+ * @param var		Variable to write to (var node where it is stored).
+ * @param value		The value to write.
+ */
+void rdata_var_write(rdata_var_t *var, rdata_value_t *value)
+{
+	rdata_var_t *nvar;
+
+	/* Perform a shallow copy of @c value->var. */
+	rdata_var_copy(value->var, &nvar);
+
+	/* XXX do this in a prettier way. */
+
+	var->vc = nvar->vc;
+	switch (nvar->vc) {
+	case vc_bool: var->u.bool_v = nvar->u.bool_v; break;
+	case vc_char: var->u.char_v = nvar->u.char_v; break;
+	case vc_int: var->u.int_v = nvar->u.int_v; break;
+	case vc_string: var->u.string_v = nvar->u.string_v; break;
+	case vc_ref: var->u.ref_v = nvar->u.ref_v; break;
+	case vc_deleg: var->u.deleg_v = nvar->u.deleg_v; break;
+	case vc_array: var->u.array_v = nvar->u.array_v; break;
+	case vc_object: var->u.object_v = nvar->u.object_v; break;
+	case vc_resource: var->u.resource_v = nvar->u.resource_v; break;
+	}
+
+	/* XXX We should free some stuff around here. */
+}
+
+/** Print data item in human-readable form.
+ *
+ * @param item		Item to print.
+ */
+void rdata_item_print(rdata_item_t *item)
+{
+	if (item == NULL) {
+		printf("none");
+		return;
+	}
+
+	switch (item->ic) {
+	case ic_address:
+		printf("address:");
+		rdata_address_print(item->u.address);
+		break;
+	case ic_value:
+		printf("value:");
+		rdata_value_print(item->u.value);
+		break;
+	}
+}
+
+/** Print address in human-readable form.
+ *
+ * Actually this displays contents of the var node that is being addressed.
+ *
+ * XXX Maybe we should really rather print the address and not the data
+ * it is pointing to?
+ *
+ * @param item		Address to print.
+ */
+static void rdata_address_print(rdata_address_t *address)
+{
+	switch (address->ac) {
+	case ac_var:
+		rdata_var_print(address->u.var_a->vref);
+		break;
+	case ac_prop:
+		printf("Warning: Unimplemented: Print property address.\n");
+		break;
+	}
+}
+
+/** Print value in human-readable form.
+ *
+ * @param value		Value to print.
+ */
+void rdata_value_print(rdata_value_t *value)
+{
+	rdata_var_print(value->var);
+}
+
+/** Print contents of var node in human-readable form.
+ *
+ * @param item		Var node to print.
+ */
+static void rdata_var_print(rdata_var_t *var)
+{
+	int val;
+
+	switch (var->vc) {
+	case vc_bool:
+		printf("bool(%s)", var->u.bool_v->value ? "true" : "false");
+		break;
+	case vc_char:
+		printf("char(");
+		if (bigint_get_value_int(&var->u.char_v->value, &val) == EOK)
+			printf("'%c'", val);
+		else
+			printf("???:x%x\n", (unsigned) val);
+		printf(")");
+		break;
+	case vc_int:
+		printf("int(");
+		bigint_print(&var->u.int_v->value);
+		printf(")");
+		break;
+	case vc_string:
+		printf("string(\"%s\")", var->u.string_v->value);
+		break;
+	case vc_ref:
+		printf("ref(");
+		rdata_var_print(var->u.ref_v->vref);
+		printf(")");
+		break;
+	case vc_deleg:
+		printf("deleg(");
+		if (var->u.deleg_v->obj != NULL) {
+			rdata_var_print(var->u.deleg_v->obj);
+			printf(",");
+		}
+		symbol_print_fqn(var->u.deleg_v->sym);
+		printf(")");
+		break;
+	case vc_array:
+		printf("array");
+		break;
+	case vc_object:
+		printf("object");
+		break;
+	case vc_resource:
+		printf("resource(%p)", var->u.resource_v->data);
+		break;
+	}
+}
Index: uspace/app/sbi/src/rdata.h
===================================================================
--- uspace/app/sbi/src/rdata.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/rdata.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef RDATA_H_
+#define RDATA_H_
+
+#include "mytypes.h"
+
+rdata_item_t *rdata_item_new(item_class_t ic);
+rdata_addr_var_t *rdata_addr_var_new(void);
+rdata_aprop_named_t *rdata_aprop_named_new(void);
+rdata_aprop_indexed_t *rdata_aprop_indexed_new(void);
+rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc);
+rdata_address_t *rdata_address_new(address_class_t ac);
+rdata_value_t *rdata_value_new(void);
+
+rdata_var_t *rdata_var_new(var_class_t vc);
+rdata_ref_t *rdata_ref_new(void);
+rdata_deleg_t *rdata_deleg_new(void);
+rdata_array_t *rdata_array_new(int rank);
+rdata_object_t *rdata_object_new(void);
+rdata_bool_t *rdata_bool_new(void);
+rdata_char_t *rdata_char_new(void);
+rdata_int_t *rdata_int_new(void);
+rdata_string_t *rdata_string_new(void);
+rdata_resource_t *rdata_resource_new(void);
+
+void rdata_array_alloc_element(rdata_array_t *array);
+void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest);
+
+void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem);
+void rdata_var_write(rdata_var_t *var, rdata_value_t *value);
+
+void rdata_item_print(rdata_item_t *item);
+void rdata_value_print(rdata_value_t *value);
+
+#endif
Index: uspace/app/sbi/src/rdata_t.h
===================================================================
--- uspace/app/sbi/src/rdata_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/rdata_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,277 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Run-time data representation. */
+
+
+#ifndef RDATA_T_H_
+#define RDATA_T_H_
+
+#include "intmap_t.h"
+
+/** Boolean variable. */
+typedef struct {
+	bool_t value;
+} rdata_bool_t;
+
+/** Character variable.
+ *
+ * Sysel character type should be able to store arbitrarily (or at least
+ * very) large character sets.
+ */
+typedef struct {
+	bigint_t value;
+} rdata_char_t;
+
+/** Integer variable.
+ *
+ * Sysel int type should be able to store arbitrarily (or at least
+ * very) large numbers.
+ */
+typedef struct {
+	bigint_t value;
+} rdata_int_t;
+
+/** String variable */
+typedef struct {
+	char *value;
+} rdata_string_t;
+
+/** Reference variable */
+typedef struct {
+	struct rdata_var *vref;
+} rdata_ref_t;
+
+/** Delegate variable
+ *
+ * A delegate variable points to a static or non-static symbol. If the
+ * symbol is non static, @c obj points to the object the symbol instance
+ * belongs to.
+ */
+typedef struct {
+	/** Object or @c NULL if deleg. points to a CSI or static member. */
+	struct rdata_var *obj;
+
+	/** Member symbol. */
+	struct stree_symbol *sym;
+} rdata_deleg_t;
+
+/** Array variable */
+typedef struct {
+	/** Rank */
+	int rank;
+
+	/** Extents (@c rank entries) */
+	int *extent;
+
+	/**
+	 * Elements (extent[0] * extent[1] * ... extent[rank - 1] entries)
+	 * stored in lexicographical order. Each element is (rdata_var_t *).
+	 */
+	struct rdata_var **element;
+} rdata_array_t;
+
+/** Object variable */
+typedef struct {
+	/** Class of this object (symbol) */
+	struct stree_symbol *class_sym;
+
+	/** Map field name SID to field data */
+	intmap_t fields; /* of (rdata_var_t *) */
+} rdata_object_t;
+
+/** Resource handle
+ *
+ * Binding to external data. This type can be used to refer to data used
+ * by builtin functions (such as files).
+ */
+typedef struct {
+	/** Only understood by the right builtin function. */
+	void *data;
+} rdata_resource_t;
+
+typedef enum var_class {
+	/** Boolean */
+	vc_bool,
+
+	/** Character **/
+	vc_char,
+
+	/** Integer */
+	vc_int,
+
+	/** String */
+	vc_string,
+
+	/** Reference */
+	vc_ref,
+
+	/** Delegate */
+	vc_deleg,
+
+	/** Array */
+	vc_array,
+
+	/** Object */
+	vc_object,
+
+	/** Interpreter builtin resource */
+	vc_resource
+} var_class_t;
+
+/** Variable.
+ *
+ * A piece of memory holding one of the basic types of data element.
+ * It is addressable (via rdata_var_t *) and mutable, at least from
+ * internal point of view of the interpreter.
+ */
+typedef struct rdata_var {
+	var_class_t vc;
+
+	union {
+		rdata_bool_t *bool_v;
+		rdata_char_t *char_v;
+		rdata_int_t *int_v;
+		rdata_string_t *string_v;
+		rdata_ref_t *ref_v;
+		rdata_deleg_t *deleg_v;
+		rdata_array_t *array_v;
+		rdata_object_t *object_v;
+		rdata_resource_t *resource_v;
+	} u;
+} rdata_var_t;
+
+/** Address class */
+typedef enum {
+	/** Variable address */
+	ac_var,
+
+	/** Property address */
+	ac_prop
+} address_class_t;
+
+/** Variable address */
+typedef struct {
+	/** Targeted variable */
+	rdata_var_t *vref;
+} rdata_addr_var_t;
+
+/** Named property address */
+typedef struct {
+	/** Delegate to the property */
+	rdata_deleg_t *prop_d;
+} rdata_aprop_named_t;
+
+/** Indexed property address */
+typedef struct {
+	/** Delegate to the object (or CSI) which is being indexed. */
+	rdata_deleg_t *object_d;
+
+	/** Arguments (indices) */
+	list_t args; /* of rdata_item_t */
+} rdata_aprop_indexed_t;
+
+typedef enum {
+	/* Named property address */
+	apc_named,
+
+	/* Indexed property address */
+	apc_indexed
+} aprop_class_t;
+
+/** Property address.
+ *
+ * When an access or index operation is performed on a property, the getter
+ * is run and the prefetched value is stored in @c tvalue. If the property
+ * is a non-scalar value type (a struct), then we might want to point to
+ * the proper @c var node inside it. @c tpos is used for this purpose.
+ *
+ * The assignment operator will modify @c tvalue and at the end the setter
+ * is called to store @c tvalue back into the property.
+ */
+typedef struct {
+	aprop_class_t apc;
+
+	/** Temporary copy of property value or @c NULL when not used. */
+	struct rdata_value *tvalue;
+
+	/**
+	 * Points to the specific var node within @c tvalue that is addressed
+	 * or @c NULL when @c tvalue is not used.
+	 */
+	rdata_var_t *tpos;
+
+	union {
+		rdata_aprop_named_t *named;
+		rdata_aprop_indexed_t *indexed;
+	} u;
+} rdata_addr_prop_t;
+
+/** Address item */
+typedef struct rdata_address {
+	address_class_t ac;
+
+	union {
+		rdata_addr_var_t *var_a;
+		rdata_addr_prop_t *prop_a;
+	} u;
+} rdata_address_t;
+
+/** Value item. */
+typedef struct rdata_value {
+	/**
+	 * Read-only Variable holding a copy of the data. The same @c var
+	 * can be shared between different instances of @c rdata_value_t.
+	 */
+	rdata_var_t *var;
+} rdata_value_t;
+
+typedef enum {
+	/** Address of a variable. */
+	ic_address,
+	/** Value */
+	ic_value
+} item_class_t;
+
+/** Data item.
+ *
+ * Data item is the result of evaluating an expression. An address expression
+ * yields an address item (a.k.a. L-value), a value expression yields a data
+ * item (a.k.a. R-value). This model is used to accomodate semantics of the
+ * assignment operator.
+ */
+typedef struct rdata_item {
+	item_class_t ic;
+
+	union {
+		rdata_address_t *address;
+		rdata_value_t *value;
+	} u;
+} rdata_item_t;
+
+#endif
Index: uspace/app/sbi/src/run.c
===================================================================
--- uspace/app/sbi/src/run.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/run.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1315 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Runner (executes the code). */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "bigint.h"
+#include "builtin.h"
+#include "debug.h"
+#include "intmap.h"
+#include "list.h"
+#include "mytypes.h"
+#include "rdata.h"
+#include "run_expr.h"
+#include "run_texpr.h"
+#include "stree.h"
+#include "strtab.h"
+#include "symbol.h"
+#include "tdata.h"
+
+#include "run.h"
+
+static void run_block(run_t *run, stree_block_t *block);
+static void run_exps(run_t *run, stree_exps_t *exps, rdata_item_t **res);
+static void run_vdecl(run_t *run, stree_vdecl_t *vdecl);
+static void run_if(run_t *run, stree_if_t *if_s);
+static void run_while(run_t *run, stree_while_t *while_s);
+static void run_raise(run_t *run, stree_raise_t *raise_s);
+static void run_return(run_t *run, stree_return_t *return_s);
+static void run_wef(run_t *run, stree_wef_t *wef_s);
+
+static bool_t run_exc_match(run_t *run, stree_except_t *except_c);
+static stree_csi_t *run_exc_payload_get_csi(run_t *run);
+
+static rdata_var_t *run_aprop_get_tpos(run_t *run, rdata_address_t *aprop);
+
+static void run_aprop_read(run_t *run, rdata_addr_prop_t *addr_prop,
+    rdata_item_t **ritem);
+static void run_aprop_write(run_t *run, rdata_addr_prop_t *addr_prop,
+    rdata_value_t *value);
+
+/** Initialize runner instance. */
+void run_init(run_t *run)
+{
+	(void) run;
+}
+
+/** Run program */
+void run_program(run_t *run, stree_program_t *prog)
+{
+	stree_symbol_t *main_fun_sym;
+	stree_fun_t *main_fun;
+	stree_ident_t *fake_ident;
+	list_t main_args;
+	run_proc_ar_t *proc_ar;
+	rdata_item_t *res;
+
+	/* Note down link to program code. */
+	run->program = prog;
+
+	/* Initialize thread activation record. */
+	run->thread_ar = run_thread_ar_new();
+	list_init(&run->thread_ar->proc_ar);
+	run->thread_ar->bo_mode = bm_none;
+
+	/*
+	 * Find entry point @c Main().
+	 */
+	fake_ident = stree_ident_new();
+	fake_ident->sid = strtab_get_sid("Main");
+	main_fun_sym = symbol_find_epoint(prog, fake_ident);
+	if (main_fun_sym == NULL) {
+		printf("Error: Entry point 'Main' not found.\n");
+		exit(1);
+	}
+
+	main_fun = symbol_to_fun(main_fun_sym);
+	assert(main_fun != NULL);
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Found function '"); symbol_print_fqn(main_fun_sym);
+	printf("'.\n");
+#endif
+
+	/* Run function @c main. */
+	list_init(&main_args);
+	run_proc_ar_create(run, NULL, main_fun->proc, &proc_ar);
+	run_proc_ar_set_args(run, proc_ar, &main_args);
+	run_proc(run, proc_ar, &res);
+
+	run_exc_check_unhandled(run);
+}
+
+/** Run procedure. */
+void run_proc(run_t *run, run_proc_ar_t *proc_ar, rdata_item_t **res)
+{
+	stree_proc_t *proc;
+	list_node_t *node;
+
+	proc = proc_ar->proc;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Start executing function '");
+	symbol_print_fqn(proc->outer_symbol);
+	printf("'.\n");
+#endif
+	/* Add procedure AR to the stack. */
+	list_append(&run->thread_ar->proc_ar, proc_ar);
+
+	/* Run main procedure block. */
+	if (proc->body != NULL) {
+		run_block(run, proc->body);
+	} else {
+		builtin_run_proc(run, proc);
+	}
+
+	/* Handle bailout. */
+	switch (run->thread_ar->bo_mode) {
+	case bm_stat:
+		printf("Error: Misplaced 'break' statement.\n");
+		exit(1);
+	case bm_proc:
+		run->thread_ar->bo_mode = bm_none;
+		break;
+	default:
+		break;
+	}
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Done executing procedure '");
+	symbol_print_fqn(proc->outer_symbol);
+	printf("'.\n");
+
+	run_print_fun_bt(run);
+#endif
+	/* Remove procedure activation record from the stack. */
+	node = list_last(&run->thread_ar->proc_ar);
+	assert(list_node_data(node, run_proc_ar_t *) == proc_ar);
+	list_remove(&run->thread_ar->proc_ar, node);
+
+	/* Procedure should not return an address. */
+	assert(proc_ar->retval == NULL || proc_ar->retval->ic == ic_value);
+	*res = proc_ar->retval;
+}
+
+/** Run code block */
+static void run_block(run_t *run, stree_block_t *block)
+{
+	run_proc_ar_t *proc_ar;
+	run_block_ar_t *block_ar;
+	list_node_t *node;
+	stree_stat_t *stat;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Executing one code block.\n");
+#endif
+
+	/* Create block activation record. */
+	block_ar = run_block_ar_new();
+	intmap_init(&block_ar->vars);
+
+	/* Add block activation record to the stack. */
+	proc_ar = run_get_current_proc_ar(run);
+	list_append(&proc_ar->block_ar, block_ar);
+
+	node = list_first(&block->stats);
+	while (node != NULL) {
+		stat = list_node_data(node, stree_stat_t *);
+		run_stat(run, stat, NULL);
+
+		if (run->thread_ar->bo_mode != bm_none)
+			break;
+
+		node = list_next(&block->stats, node);
+	}
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Done executing code block.\n");
+#endif
+
+	/* Remove block activation record from the stack. */
+	node = list_last(&proc_ar->block_ar);
+	assert(list_node_data(node, run_block_ar_t *) == block_ar);
+	list_remove(&proc_ar->block_ar, node);
+}
+
+/** Run statement.
+ *
+ * Executes a statement. If @a res is not NULL and the statement is an
+ * expression statement with a value, the value item will be stored to
+ * @a res.
+ *
+ * @param run	Runner object.
+ * @param stat	Statement to run.
+ * @param res	Place to store exps result or NULL if not interested.
+ */
+void run_stat(run_t *run, stree_stat_t *stat, rdata_item_t **res)
+{
+#ifdef DEBUG_RUN_TRACE
+	printf("Executing one statement %p.\n", stat);
+#endif
+
+	if (res != NULL)
+		*res = NULL;
+
+	switch (stat->sc) {
+	case st_exps:
+		run_exps(run, stat->u.exp_s, res);
+		break;
+	case st_vdecl:
+		run_vdecl(run, stat->u.vdecl_s);
+		break;
+	case st_if:
+		run_if(run, stat->u.if_s);
+		break;
+	case st_while:
+		run_while(run, stat->u.while_s);
+		break;
+	case st_raise:
+		run_raise(run, stat->u.raise_s);
+		break;
+	case st_return:
+		run_return(run, stat->u.return_s);
+		break;
+	case st_wef:
+		run_wef(run, stat->u.wef_s);
+		break;
+	case st_for:
+		printf("Ignoring unimplemented statement type %d.\n", stat->sc);
+		break;
+	default:
+		assert(b_false);
+	}
+}
+
+/** Run expression statement.
+ *
+ * Executes an expression statement. If @a res is not NULL then the value
+ * of the expression (or NULL if it has no value) will be stored to @a res.
+ *
+ * @param run	Runner object.
+ * @param exps	Expression statement to run.
+ * @param res	Place to store exps result or NULL if not interested.
+ */
+static void run_exps(run_t *run, stree_exps_t *exps, rdata_item_t **res)
+{
+	rdata_item_t *rexpr;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Executing expression statement.\n");
+#endif
+	run_expr(run, exps->expr, &rexpr);
+
+	if (res != NULL)
+		*res = rexpr;
+}
+
+/** Run variable declaration statement. */
+static void run_vdecl(run_t *run, stree_vdecl_t *vdecl)
+{
+	run_block_ar_t *block_ar;
+	rdata_var_t *var, *old_var;
+	rdata_int_t *int_v;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Executing variable declaration statement.\n");
+#endif
+
+	/* XXX Need to support other variables than int. */
+
+	var = rdata_var_new(vc_int);
+	int_v = rdata_int_new();
+
+	var->u.int_v = int_v;
+	bigint_init(&int_v->value, 0);
+
+	block_ar = run_get_current_block_ar(run);
+	old_var = (rdata_var_t *) intmap_get(&block_ar->vars, vdecl->name->sid);
+
+	if (old_var != NULL) {
+		printf("Error: Duplicate variable '%s'\n",
+		    strtab_get_str(vdecl->name->sid));
+		exit(1);
+	}
+
+	intmap_set(&block_ar->vars, vdecl->name->sid, var);
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Declared variable '%s'\n", strtab_get_str(vdecl->name->sid));
+#endif
+}
+
+/** Run @c if statement. */
+static void run_if(run_t *run, stree_if_t *if_s)
+{
+	rdata_item_t *rcond;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Executing if statement.\n");
+#endif
+	run_expr(run, if_s->cond, &rcond);
+	if (run_is_bo(run))
+		return;
+
+	if (run_item_boolean_value(run, rcond) == b_true) {
+#ifdef DEBUG_RUN_TRACE
+		printf("Taking true path.\n");
+#endif
+		run_block(run, if_s->if_block);
+	} else {
+#ifdef DEBUG_RUN_TRACE
+		printf("Taking false path.\n");
+#endif
+        	if (if_s->else_block != NULL)
+			run_block(run, if_s->else_block);
+	}
+
+#ifdef DEBUG_RUN_TRACE
+	printf("If statement terminated.\n");
+#endif
+}
+
+/** Run @c while statement. */
+static void run_while(run_t *run, stree_while_t *while_s)
+{
+	rdata_item_t *rcond;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Executing while statement.\n");
+#endif
+	run_expr(run, while_s->cond, &rcond);
+	if (run_is_bo(run))
+		return;
+
+	while (run_item_boolean_value(run, rcond) == b_true) {
+		run_block(run, while_s->body);
+		run_expr(run, while_s->cond, &rcond);
+		if (run_is_bo(run))
+			return;
+
+		if (run->thread_ar->bo_mode != bm_none)
+			break;
+	}
+
+#ifdef DEBUG_RUN_TRACE
+	printf("While statement terminated.\n");
+#endif
+}
+
+/** Run @c raise statement. */
+static void run_raise(run_t *run, stree_raise_t *raise_s)
+{
+	rdata_item_t *rexpr;
+	rdata_item_t *rexpr_vi;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Executing raise statement.\n");
+#endif
+	run_expr(run, raise_s->expr, &rexpr);
+	if (run_is_bo(run))
+		return;
+
+	run_cvt_value_item(run, rexpr, &rexpr_vi);
+
+	/* Store expression result in thread AR. */
+	run->thread_ar->exc_payload = rexpr_vi->u.value;
+
+	/* Start exception bailout. */
+	run->thread_ar->bo_mode = bm_exc;
+}
+
+/** Run @c return statement. */
+static void run_return(run_t *run, stree_return_t *return_s)
+{
+	rdata_item_t *rexpr;
+	rdata_item_t *rexpr_vi;
+	run_proc_ar_t *proc_ar;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Executing return statement.\n");
+#endif
+	run_expr(run, return_s->expr, &rexpr);
+	if (run_is_bo(run))
+		return;
+
+	run_cvt_value_item(run, rexpr, &rexpr_vi);
+
+	/* Store expression result in function AR. */
+	proc_ar = run_get_current_proc_ar(run);
+	proc_ar->retval = rexpr_vi;
+
+	/* Force control to ascend and leave the procedure. */
+	if (run->thread_ar->bo_mode == bm_none)
+		run->thread_ar->bo_mode = bm_proc;
+}
+
+/** Run @c with-except-finally statement. */
+static void run_wef(run_t *run, stree_wef_t *wef_s)
+{
+	list_node_t *except_n;
+	stree_except_t *except_c;
+	rdata_value_t *exc_payload;
+	run_bailout_mode_t bo_mode;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Executing with-except-finally statement.\n");
+#endif
+	run_block(run, wef_s->with_block);
+
+	if (run->thread_ar->bo_mode == bm_exc) {
+#ifdef DEBUG_RUN_TRACE
+		printf("With statement detected exception.\n");
+#endif
+		/* Reset to normal execution. */
+		run->thread_ar->bo_mode = bm_none;
+
+		/* Look for an except block. */
+		except_n = list_first(&wef_s->except_clauses);
+		while (except_n != NULL) {
+			except_c = list_node_data(except_n, stree_except_t *);
+			if (run_exc_match(run, except_c))
+				break;
+
+			except_n = list_next(&wef_s->except_clauses, except_n);
+		}
+
+		/* If one was found, execute it. */
+		if (except_n != NULL)
+			run_block(run, except_c->block);
+
+		/* Execute finally block */
+		if (wef_s->finally_block != NULL) {
+			/* Put exception on the side temporarily. */
+			bo_mode = run->thread_ar->bo_mode;
+			exc_payload = run->thread_ar->exc_payload;
+
+			run->thread_ar->bo_mode = bm_none;
+			run->thread_ar->exc_payload = NULL;
+
+			run_block(run, wef_s->finally_block);
+
+			if (bo_mode == bm_exc) {
+				/*
+				 * Restore the original exception. If another
+				 * exception occured in the finally block (i.e.
+				 * double fault), it is forgotten.
+				 */
+				run->thread_ar->bo_mode = bm_exc;
+				run->thread_ar->exc_payload = exc_payload;
+			}
+		}
+	}
+
+#ifdef DEBUG_RUN_TRACE
+	printf("With-except-finally statement terminated.\n");
+#endif
+}
+
+/** Determine whether currently active exception matches @c except clause.
+ *
+ * Checks if the currently active exception in the runner object @c run
+ * matches except clause @c except_c.
+ *
+ * @param run		Runner object.
+ * @param except_c	@c except clause.
+ * @return		@c b_true if there is a match, @c b_false otherwise.
+ */
+static bool_t run_exc_match(run_t *run, stree_except_t *except_c)
+{
+	stree_csi_t *exc_csi;
+	tdata_item_t *etype;
+
+	/* Get CSI of active exception. */
+	exc_csi = run_exc_payload_get_csi(run);
+
+	/* Evaluate type expression in except clause. */
+	run_texpr(run->program, run_get_current_csi(run), except_c->etype,
+	    &etype);
+
+	/* Determine if active exc. is derived from type in exc. clause. */
+	return tdata_is_csi_derived_from_ti(exc_csi, etype);
+}
+
+/** Return CSI of the active exception.
+ *
+ * @param run		Runner object.
+ * @return		CSI of the active exception.
+ */
+static stree_csi_t *run_exc_payload_get_csi(run_t *run)
+{
+	rdata_value_t *payload;
+	rdata_var_t *payload_v;
+	rdata_object_t *payload_o;
+
+	payload = run->thread_ar->exc_payload;
+	assert(payload != NULL);
+
+	if (payload->var->vc != vc_ref) {
+		/* XXX Prevent this via static type checking. */
+		printf("Error: Exception payload must be an object "
+		    "(found type %d).\n", payload->var->vc);
+		exit(1);
+	}
+
+	payload_v = payload->var->u.ref_v->vref;
+	if (payload_v->vc != vc_object) {
+		/* XXX Prevent this via static type checking. */
+		printf("Error: Exception payload must be an object "
+		    "(found type %d).\n", payload_v->vc);
+		exit(1);
+	}
+
+	payload_o = payload_v->u.object_v;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Active exception: '");
+	symbol_print_fqn(payload_o->class_sym);
+	printf("'.\n");
+#endif
+	assert(payload_o->class_sym != NULL);
+	assert(payload_o->class_sym->sc == sc_csi);
+
+	return payload_o->class_sym->u.csi;
+}
+
+
+/** Check for unhandled exception.
+ *
+ * Checks whether there is an active exception. If so, it prints an
+ * error message and raises a run-time error.
+ *
+ * @param run		Runner object.
+ */
+void run_exc_check_unhandled(run_t *run)
+{
+	stree_csi_t *exc_csi;
+
+	if (run->thread_ar->bo_mode != bm_none) {
+		assert(run->thread_ar->bo_mode == bm_exc);
+
+		exc_csi = run_exc_payload_get_csi(run);
+
+		printf("Error: Unhandled exception '");
+		symbol_print_fqn(csi_to_symbol(exc_csi));
+		printf("'.\n");
+
+		run_raise_error(run);
+	}
+}
+
+/** Raise an irrecoverable run-time error, start bailing out.
+ *
+ * Raises an error that cannot be handled by the user program.
+ */
+void run_raise_error(run_t *run)
+{
+	run->thread_ar->bo_mode = bm_error;
+	run->thread_ar->error = b_true;
+}
+
+/** Construct a special recovery item. */
+rdata_item_t *run_recovery_item(run_t *run)
+{
+	(void) run;
+	return NULL;
+}
+
+/** Find a local variable in the currently active function. */
+rdata_var_t *run_local_vars_lookup(run_t *run, sid_t name)
+{
+	run_proc_ar_t *proc_ar;
+	run_block_ar_t *block_ar;
+	rdata_var_t *var;
+	list_node_t *node;
+
+	proc_ar = run_get_current_proc_ar(run);
+	node = list_last(&proc_ar->block_ar);
+
+	/* Walk through all block activation records. */
+	while (node != NULL) {
+		block_ar = list_node_data(node, run_block_ar_t *);
+		var = intmap_get(&block_ar->vars, name);
+		if (var != NULL)
+			return var;
+
+		node = list_prev(&proc_ar->block_ar, node);
+	}
+
+	/* No match */
+	return NULL;
+}
+
+/** Get current function activation record. */
+run_proc_ar_t *run_get_current_proc_ar(run_t *run)
+{
+	list_node_t *node;
+
+	node = list_last(&run->thread_ar->proc_ar);
+	return list_node_data(node, run_proc_ar_t *);
+}
+
+/** Get current block activation record. */
+run_block_ar_t *run_get_current_block_ar(run_t *run)
+{
+	run_proc_ar_t *proc_ar;
+	list_node_t *node;
+
+	proc_ar = run_get_current_proc_ar(run);
+
+	node = list_last(&proc_ar->block_ar);
+	return list_node_data(node, run_block_ar_t *);
+}
+
+/** Get current CSI. */
+stree_csi_t *run_get_current_csi(run_t *run)
+{
+	run_proc_ar_t *proc_ar;
+
+	proc_ar = run_get_current_proc_ar(run);
+	return proc_ar->proc->outer_symbol->outer_csi;
+}
+
+/** Construct variable from a value item.
+ *
+ * XXX This should be in fact implemented using existing code as:
+ *
+ * (1) Create a variable of the desired type.
+ * (2) Initialize the variable with the provided value.
+ */
+void run_value_item_to_var(rdata_item_t *item, rdata_var_t **var)
+{
+	rdata_char_t *char_v;
+	rdata_int_t *int_v;
+	rdata_string_t *string_v;
+	rdata_ref_t *ref_v;
+	rdata_var_t *in_var;
+
+	assert(item->ic == ic_value);
+	in_var = item->u.value->var;
+
+	switch (in_var->vc) {
+	case vc_char:
+		*var = rdata_var_new(vc_char);
+		char_v = rdata_char_new();
+
+		(*var)->u.char_v = char_v;
+		bigint_clone(&item->u.value->var->u.char_v->value,
+		    &char_v->value);
+		break;
+	case vc_int:
+		*var = rdata_var_new(vc_int);
+		int_v = rdata_int_new();
+
+		(*var)->u.int_v = int_v;
+		bigint_clone(&item->u.value->var->u.int_v->value,
+		    &int_v->value);
+		break;
+	case vc_string:
+		*var = rdata_var_new(vc_string);
+		string_v = rdata_string_new();
+
+		(*var)->u.string_v = string_v;
+		string_v->value = item->u.value->var->u.string_v->value;
+		break;
+	case vc_ref:
+		*var = rdata_var_new(vc_ref);
+		ref_v = rdata_ref_new();
+
+		(*var)->u.ref_v = ref_v;
+		ref_v->vref = item->u.value->var->u.ref_v->vref;
+		break;
+	default:
+		printf("Error: Unimplemented argument type.\n");
+		exit(1);
+
+	}
+}
+
+/** Construct a function AR. */
+void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_proc_t *proc,
+    run_proc_ar_t **rproc_ar)
+{
+	run_proc_ar_t *proc_ar;
+	run_block_ar_t *block_ar;
+
+	(void) run;
+
+	/* Create function activation record. */
+	proc_ar = run_proc_ar_new();
+	proc_ar->obj = obj;
+	proc_ar->proc = proc;
+	list_init(&proc_ar->block_ar);
+
+	proc_ar->retval = NULL;
+
+	/* Create special block activation record to hold function arguments. */
+	block_ar = run_block_ar_new();
+	intmap_init(&block_ar->vars);
+	list_append(&proc_ar->block_ar, block_ar);
+
+	*rproc_ar = proc_ar;
+}
+
+/** Fill arguments in a procedure AR.
+ *
+ * When invoking a procedure this is used to store the argument values
+ * in the activation record.
+ */
+void run_proc_ar_set_args(run_t *run, run_proc_ar_t *proc_ar, list_t *arg_vals)
+{
+	stree_fun_t *fun;
+	stree_prop_t *prop;
+	list_t *args;
+	stree_proc_arg_t *varg;
+	stree_symbol_t *outer_symbol;
+
+	run_block_ar_t *block_ar;
+	list_node_t *block_ar_n;
+	list_node_t *rarg_n, *parg_n;
+	list_node_t *cn;
+	rdata_item_t *rarg;
+	stree_proc_arg_t *parg;
+	rdata_var_t *var;
+	rdata_var_t *ref_var;
+	rdata_ref_t *ref;
+	rdata_array_t *array;
+	int n_vargs, idx;
+
+	(void) run;
+
+	/* AR should have been created with run_proc_ar_create(). */
+	assert(proc_ar->proc != NULL);
+	outer_symbol = proc_ar->proc->outer_symbol;
+
+	/*
+	 * The procedure being activated should belong to a member function or
+	 * property getter/setter.
+	 */
+	switch (outer_symbol->sc) {
+	case sc_fun:
+		fun = symbol_to_fun(outer_symbol);
+		args = &fun->args;
+		varg = fun->varg;
+		break;
+	case sc_prop:
+		prop = symbol_to_prop(outer_symbol);
+		args = &prop->args;
+		varg = prop->varg;
+		break;
+	default:
+		assert(b_false);
+	}
+
+	/* Fetch first block activation record. */
+	block_ar_n = list_first(&proc_ar->block_ar);
+	assert(block_ar_n != NULL);
+	block_ar = list_node_data(block_ar_n, run_block_ar_t *);
+
+	/* Declare local variables to hold argument values. */
+	rarg_n = list_first(arg_vals);
+	parg_n = list_first(args);
+
+	while (parg_n != NULL) {
+		if (rarg_n == NULL) {
+			printf("Error: Too few arguments to '");
+			symbol_print_fqn(outer_symbol);
+			printf("'.\n");
+			exit(1);
+		}
+
+		rarg = list_node_data(rarg_n, rdata_item_t *);
+		parg = list_node_data(parg_n, stree_proc_arg_t *);
+
+		assert(rarg->ic == ic_value);
+
+		/* Construct a variable from the argument value. */
+		run_value_item_to_var(rarg, &var);
+
+		/* Declare variable using name of formal argument. */
+		intmap_set(&block_ar->vars, parg->name->sid, var);
+
+		rarg_n = list_next(arg_vals, rarg_n);
+		parg_n = list_next(args, parg_n);
+	}
+
+	if (varg != NULL) {
+		/* Function is variadic. Count number of variadic arguments. */
+		cn = rarg_n;
+		n_vargs = 0;
+		while (cn != NULL) {
+			n_vargs += 1;
+			cn = list_next(arg_vals, cn);
+		}
+
+		/* Prepare array to store variadic arguments. */
+		array = rdata_array_new(1);
+		array->extent[0] = n_vargs;
+		rdata_array_alloc_element(array);
+
+		/* Read variadic arguments. */
+
+		idx = 0;
+		while (rarg_n != NULL) {
+			rarg = list_node_data(rarg_n, rdata_item_t *);
+			assert(rarg->ic == ic_value);
+
+			rdata_var_write(array->element[idx], rarg->u.value);
+
+			rarg_n = list_next(arg_vals, rarg_n);
+			idx += 1;
+		}
+
+		var = rdata_var_new(vc_array);
+		var->u.array_v = array;
+
+		/* Create reference to the new array. */
+		ref_var = rdata_var_new(vc_ref);
+		ref = rdata_ref_new();
+		ref_var->u.ref_v = ref;
+		ref->vref = var;
+
+		/* Declare variable using name of formal argument. */
+		intmap_set(&block_ar->vars, varg->name->sid,
+		    ref_var);
+	}
+
+	/* Check for excess real parameters. */
+	if (rarg_n != NULL) {
+		printf("Error: Too many arguments to '");
+		symbol_print_fqn(outer_symbol);
+		printf("'.\n");
+		exit(1);
+	}
+}
+
+/** Fill setter argument in a procedure AR.
+ *
+ * When invoking a setter this is used to store its argument value in its
+ * procedure activation record.
+ */
+void run_proc_ar_set_setter_arg(run_t *run, run_proc_ar_t *proc_ar,
+    rdata_item_t *arg_val)
+{
+	stree_prop_t *prop;
+	run_block_ar_t *block_ar;
+	list_node_t *block_ar_n;
+	rdata_var_t *var;
+
+	(void) run;
+
+	/* AR should have been created with run_proc_ar_create(). */
+	assert(proc_ar->proc != NULL);
+
+	/* The procedure being activated should belong to a property setter. */
+	prop = symbol_to_prop(proc_ar->proc->outer_symbol);
+	assert(prop != NULL);
+	assert(proc_ar->proc == prop->setter);
+
+	/* Fetch first block activation record. */
+	block_ar_n = list_first(&proc_ar->block_ar);
+	assert(block_ar_n != NULL);
+	block_ar = list_node_data(block_ar_n, run_block_ar_t *);
+
+	assert(arg_val->ic == ic_value);
+
+	/* Construct a variable from the argument value. */
+	run_value_item_to_var(arg_val, &var);
+
+	/* Declare variable using name of formal argument. */
+	intmap_set(&block_ar->vars, prop->setter_arg->name->sid, var);
+}
+
+/** Print function activation backtrace. */
+void run_print_fun_bt(run_t *run)
+{
+	list_node_t *node;
+	run_proc_ar_t *proc_ar;
+
+	printf("Backtrace:\n");
+	node = list_last(&run->thread_ar->proc_ar);
+	while (node != NULL) {
+		printf(" * ");
+		proc_ar = list_node_data(node, run_proc_ar_t *);
+		symbol_print_fqn(proc_ar->proc->outer_symbol);
+		printf("\n");
+
+		node = list_prev(&run->thread_ar->proc_ar, node);
+	}
+}
+
+/** Convert item to value item.
+ *
+ * If @a item is a value, we just return a copy. If @a item is an address,
+ * we read from the address.
+ */
+void run_cvt_value_item(run_t *run, rdata_item_t *item, rdata_item_t **ritem)
+{
+	rdata_value_t *value;
+
+	/* 
+	 * This can happen when trying to use output of a function which
+	 * does not return a value.
+	 */
+	if (item == NULL) {
+		printf("Error: Sub-expression has no value.\n");
+		exit(1);
+	}
+
+	/* Address item. Perform read operation. */
+	if (item->ic == ic_address) {
+		run_address_read(run, item->u.address, ritem);
+		return;
+	}
+
+	/* It already is a value, we can share the @c var. */
+	value = rdata_value_new();
+	value->var = item->u.value->var;
+	*ritem = rdata_item_new(ic_value);
+	(*ritem)->u.value = value;
+}
+
+/** Get item var-class.
+ *
+ * Get var-class of @a item, regardless whether it is a value or address.
+ * (I.e. the var class of the value or variable at the given address).
+ */
+var_class_t run_item_get_vc(run_t *run, rdata_item_t *item)
+{
+	var_class_t vc;
+	rdata_var_t *tpos;
+
+	(void) run;
+
+	switch (item->ic) {
+	case ic_value:
+		vc = item->u.value->var->vc;
+		break;
+	case ic_address:
+		switch (item->u.address->ac) {
+		case ac_var:
+			vc = item->u.address->u.var_a->vref->vc;
+			break;
+		case ac_prop:
+			/* Prefetch the value of the property. */
+			tpos = run_aprop_get_tpos(run, item->u.address);
+			vc = tpos->vc;
+			break;
+		default:
+			assert(b_false);
+		}
+		break;
+	default:
+		assert(b_false);
+	}
+
+	return vc;
+}
+
+/** Get pointer to current var node in temporary copy in property address.
+ *
+ * A property address refers to a specific @c var node in a property.
+ * This function will fetch a copy of the property value (by running
+ * its getter) if there is not a temporary copy in the address yet.
+ * It returns a pointer to the relevant @c var node in the temporary
+ * copy.
+ *
+ * @param run	Runner object.
+ * @param addr	Address of class @c ac_prop.
+ * @param	Pointer to var node.
+ */
+static rdata_var_t *run_aprop_get_tpos(run_t *run, rdata_address_t *addr)
+{
+	rdata_item_t *ritem;
+
+	assert(addr->ac == ac_prop);
+
+	if (addr->u.prop_a->tvalue == NULL) {
+		/* Fetch value of the property. */
+		run_address_read(run, addr, &ritem);
+		assert(ritem->ic == ic_value);
+		addr->u.prop_a->tvalue = ritem->u.value;
+		addr->u.prop_a->tpos = addr->u.prop_a->tvalue->var;
+	}
+
+	return addr->u.prop_a->tpos;
+}
+
+/** Read data from an address.
+ *
+ * Return value stored in a variable at the specified address.
+ */
+void run_address_read(run_t *run, rdata_address_t *address,
+    rdata_item_t **ritem)
+{
+	(void) run;
+
+	switch (address->ac) {
+	case ac_var:
+		rdata_var_read(address->u.var_a->vref, ritem);
+		break;
+	case ac_prop:
+		run_aprop_read(run, address->u.prop_a, ritem);
+		break;
+	}
+
+	assert((*ritem)->ic == ic_value);
+}
+
+/** Write data to an address.
+ *
+ * Store @a value to the variable at @a address.
+ */
+void run_address_write(run_t *run, rdata_address_t *address,
+    rdata_value_t *value)
+{
+	(void) run;
+
+	switch (address->ac) {
+	case ac_var:
+		rdata_var_write(address->u.var_a->vref, value);
+		break;
+	case ac_prop:
+		run_aprop_write(run, address->u.prop_a, value);
+		break;
+	}
+}
+
+static void run_aprop_read(run_t *run, rdata_addr_prop_t *addr_prop,
+    rdata_item_t **ritem)
+{
+	rdata_deleg_t *deleg;
+	rdata_var_t *obj;
+	stree_symbol_t *prop_sym;
+	stree_prop_t *prop;
+
+	run_proc_ar_t *proc_ar;
+
+	rdata_var_t *cvar;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Read from property.\n");
+#endif
+	/*
+	 * If @c tvalue is present, we need to use the relevant part from that
+	 * instead of re-reading the whole thing.
+	 */
+	if (addr_prop->tvalue != NULL) {
+		/* Copy the value */
+		rdata_var_copy(addr_prop->tpos, &cvar);
+		*ritem = rdata_item_new(ic_value);
+		(*ritem)->u.value = rdata_value_new();
+		(*ritem)->u.value->var = cvar;
+		return;
+	}
+
+	if (addr_prop->apc == apc_named)
+		deleg = addr_prop->u.named->prop_d;
+	else
+		deleg = addr_prop->u.indexed->object_d;
+
+	obj = deleg->obj;
+	prop_sym = deleg->sym;
+	prop = symbol_to_prop(prop_sym);
+	assert(prop != NULL);
+
+	if (prop->getter == NULL) {
+		printf("Error: Property is not readable.\n");
+		exit(1);
+	}
+
+	/* Create procedure activation record. */
+	run_proc_ar_create(run, obj, prop->getter, &proc_ar);
+
+	/* Fill in arguments (indices). */
+	if (addr_prop->apc == apc_indexed) {
+		run_proc_ar_set_args(run, proc_ar,
+		    &addr_prop->u.indexed->args);
+	}
+
+	/* Run getter. */
+	run_proc(run, proc_ar, ritem);
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Getter returns ");
+	rdata_item_print(*ritem);
+	printf(".\n");
+	printf("Done reading from property.\n");
+#endif
+}
+
+static void run_aprop_write(run_t *run, rdata_addr_prop_t *addr_prop,
+    rdata_value_t *value)
+{
+	rdata_deleg_t *deleg;
+	rdata_var_t *obj;
+	stree_symbol_t *prop_sym;
+	stree_prop_t *prop;
+
+	run_proc_ar_t *proc_ar;
+	rdata_item_t *vitem;
+	rdata_item_t *ritem;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Write to property.\n");
+#endif
+	/* If @c tvalue is present, we need to modify it and write it back. */
+	if (addr_prop->tvalue != NULL) {
+		printf("Unimplemented: Read-modify-write property access.\n");
+		exit(1);
+	}
+
+	if (addr_prop->apc == apc_named)
+		deleg = addr_prop->u.named->prop_d;
+	else
+		deleg = addr_prop->u.indexed->object_d;
+
+	obj = deleg->obj;
+	prop_sym = deleg->sym;
+	prop = symbol_to_prop(prop_sym);
+	assert(prop != NULL);
+
+	if (prop->setter == NULL) {
+		printf("Error: Property is not writable.\n");
+		exit(1);
+	}
+
+	vitem = rdata_item_new(ic_value);
+	vitem->u.value = value;
+
+	/* Create procedure activation record. */
+	run_proc_ar_create(run, obj, prop->setter, &proc_ar);
+
+	/* Fill in arguments (indices). */
+	if (addr_prop->apc == apc_indexed) {
+		run_proc_ar_set_args(run, proc_ar,
+		    &addr_prop->u.indexed->args);
+	}
+
+	/* Fill in value argument for setter. */
+	run_proc_ar_set_setter_arg(run, proc_ar, vitem);
+
+	/* Run setter. */
+	run_proc(run, proc_ar, &ritem);
+
+	/* Setter should not return a value. */
+	assert(ritem == NULL);
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Done writing to property.\n");
+#endif
+}
+
+/** Return reference to a variable.
+ *
+ * Constructs a reference (value item) pointing to @a var.
+ */
+void run_reference(run_t *run, rdata_var_t *var, rdata_item_t **res)
+{
+	rdata_ref_t *ref;
+	rdata_var_t *ref_var;
+	rdata_value_t *ref_value;
+	rdata_item_t *ref_item;
+
+	(void) run;
+
+	/* Create reference to the variable. */
+	ref = rdata_ref_new();
+	ref_var = rdata_var_new(vc_ref);
+	ref->vref = var;
+	ref_var->u.ref_v = ref;
+
+	/* Construct value of the reference to return. */
+	ref_item = rdata_item_new(ic_value);
+	ref_value = rdata_value_new();
+	ref_item->u.value = ref_value;
+	ref_value->var = ref_var;
+
+	*res = ref_item;
+}
+
+/** Return address of reference target.
+ *
+ * Takes a reference (address or value) and returns the address (item) of
+ * the target of the reference.
+ */
+void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem)
+{
+	rdata_item_t *ref_val;
+	rdata_item_t *item;
+	rdata_address_t *address;
+	rdata_addr_var_t *addr_var;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("run_dereference()\n");
+#endif
+	run_cvt_value_item(run, ref, &ref_val);
+	assert(ref_val->u.value->var->vc == vc_ref);
+
+	item = rdata_item_new(ic_address);
+	address = rdata_address_new(ac_var);
+	addr_var = rdata_addr_var_new();
+	item->u.address = address;
+	address->u.var_a = addr_var;
+	addr_var->vref = ref_val->u.value->var->u.ref_v->vref;
+
+	if (addr_var->vref == NULL) {
+#ifdef DEBUG_RUN_TRACE
+		printf("Error: Accessing null reference.\n");
+#endif
+		/* Raise Error.NilReference */
+		run_raise_exc(run, run->program->builtin->error_nilreference);
+		*ritem = run_recovery_item(run);
+		return;
+	}
+
+#ifdef DEBUG_RUN_TRACE
+	printf("vref set to %p\n", addr_var->vref);
+#endif
+	*ritem = item;
+}
+
+/** Raise an exception of the given class.
+ *
+ * Used when the interpreter generates an exception due to a run-time
+ * error (not for the @c raise statement).
+ *
+ * @param run		Runner object.
+ * @param csi		Exception class.
+ */
+void run_raise_exc(run_t *run, stree_csi_t *csi)
+{
+	rdata_item_t *exc_vi;
+
+	/* Create exception object. */
+	run_new_csi_inst(run, csi, &exc_vi);
+	assert(exc_vi->ic == ic_value);
+
+	/* Store exception object in thread AR. */
+	run->thread_ar->exc_payload = exc_vi->u.value;
+
+	/* Start exception bailout. */
+	run->thread_ar->bo_mode = bm_exc;
+}
+
+/** Determine if we are bailing out. */
+bool_t run_is_bo(run_t *run)
+{
+	return run->thread_ar->bo_mode != bm_none;
+}
+
+run_thread_ar_t *run_thread_ar_new(void)
+{
+	run_thread_ar_t *thread_ar;
+
+	thread_ar = calloc(1, sizeof(run_thread_ar_t));
+	if (thread_ar == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return thread_ar;
+}
+
+run_proc_ar_t *run_proc_ar_new(void)
+{
+	run_proc_ar_t *proc_ar;
+
+	proc_ar = calloc(1, sizeof(run_proc_ar_t));
+	if (proc_ar == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return proc_ar;
+}
+
+run_block_ar_t *run_block_ar_new(void)
+{
+	run_block_ar_t *block_ar;
+
+	block_ar = calloc(1, sizeof(run_block_ar_t));
+	if (block_ar == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return block_ar;
+}
Index: uspace/app/sbi/src/run.h
===================================================================
--- uspace/app/sbi/src/run.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/run.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef RUN_H_
+#define RUN_H_
+
+#include "mytypes.h"
+
+void run_init(run_t *run);
+void run_program(run_t *run, stree_program_t *prog);
+void run_proc(run_t *run, run_proc_ar_t *proc_ar, rdata_item_t **res);
+void run_stat(run_t *run, stree_stat_t *stat, rdata_item_t **res);
+
+void run_print_fun_bt(run_t *run);
+
+void run_exc_check_unhandled(run_t *run);
+void run_raise_error(run_t *run);
+rdata_item_t *run_recovery_item(run_t *run);
+
+rdata_var_t *run_local_vars_lookup(run_t *run, sid_t name);
+run_proc_ar_t *run_get_current_proc_ar(run_t *run);
+run_block_ar_t *run_get_current_block_ar(run_t *run);
+stree_csi_t *run_get_current_csi(run_t *run);
+
+void run_value_item_to_var(rdata_item_t *item, rdata_var_t **var);
+void run_proc_ar_set_args(run_t *run, run_proc_ar_t *proc_ar,
+    list_t *arg_vals);
+void run_proc_ar_set_setter_arg(run_t *run, run_proc_ar_t *proc_ar,
+    rdata_item_t *arg_val);
+void run_proc_ar_create(run_t *run, rdata_var_t *obj, stree_proc_t *proc,
+    run_proc_ar_t **rproc_ar);
+
+var_class_t run_item_get_vc(run_t *run, rdata_item_t *item);
+void run_cvt_value_item(run_t *run, rdata_item_t *item, rdata_item_t **ritem);
+void run_address_read(run_t *run, rdata_address_t *address,
+    rdata_item_t **ritem);
+void run_address_write(run_t *run, rdata_address_t *address,
+    rdata_value_t *value);
+void run_reference(run_t *run, rdata_var_t *var, rdata_item_t **res);
+void run_dereference(run_t *run, rdata_item_t *ref, rdata_item_t **ritem);
+
+void run_raise_exc(run_t *run, stree_csi_t *csi);
+bool_t run_is_bo(run_t *run);
+
+run_thread_ar_t *run_thread_ar_new(void);
+run_proc_ar_t *run_proc_ar_new(void);
+run_block_ar_t *run_block_ar_new(void);
+
+#endif
Index: uspace/app/sbi/src/run_expr.c
===================================================================
--- uspace/app/sbi/src/run_expr.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/run_expr.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1862 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Runner (executes the code). */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "bigint.h"
+#include "debug.h"
+#include "intmap.h"
+#include "list.h"
+#include "mytypes.h"
+#include "os/os.h"
+#include "rdata.h"
+#include "run.h"
+#include "run_texpr.h"
+#include "symbol.h"
+#include "stree.h"
+#include "strtab.h"
+#include "tdata.h"
+
+#include "run_expr.h"
+
+static void run_nameref(run_t *run, stree_nameref_t *nameref,
+    rdata_item_t **res);
+
+static void run_literal(run_t *run, stree_literal_t *literal,
+    rdata_item_t **res);
+static void run_lit_bool(run_t *run, stree_lit_bool_t *lit_bool,
+    rdata_item_t **res);
+static void run_lit_char(run_t *run, stree_lit_char_t *lit_char,
+    rdata_item_t **res);
+static void run_lit_int(run_t *run, stree_lit_int_t *lit_int,
+    rdata_item_t **res);
+static void run_lit_ref(run_t *run, stree_lit_ref_t *lit_ref,
+    rdata_item_t **res);
+static void run_lit_string(run_t *run, stree_lit_string_t *lit_string,
+    rdata_item_t **res);
+
+static void run_self_ref(run_t *run, stree_self_ref_t *self_ref,
+    rdata_item_t **res);
+
+static void run_binop(run_t *run, stree_binop_t *binop, rdata_item_t **res);
+static void run_binop_bool(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
+    rdata_value_t *v2, rdata_item_t **res);
+static void run_binop_char(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
+    rdata_value_t *v2, rdata_item_t **res);
+static void run_binop_int(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
+    rdata_value_t *v2, rdata_item_t **res);
+static void run_binop_string(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
+    rdata_value_t *v2, rdata_item_t **res);
+static void run_binop_ref(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
+    rdata_value_t *v2, rdata_item_t **res);
+
+static void run_unop(run_t *run, stree_unop_t *unop, rdata_item_t **res);
+static void run_unop_int(run_t *run, stree_unop_t *unop, rdata_value_t *val,
+    rdata_item_t **res);
+
+static void run_new(run_t *run, stree_new_t *new_op, rdata_item_t **res);
+static void run_new_array(run_t *run, stree_new_t *new_op,
+    tdata_item_t *titem, rdata_item_t **res);
+static void run_new_object(run_t *run, stree_new_t *new_op,
+    tdata_item_t *titem, rdata_item_t **res);
+
+static void run_access(run_t *run, stree_access_t *access, rdata_item_t **res);
+static void run_access_item(run_t *run, stree_access_t *access,
+    rdata_item_t *arg, rdata_item_t **res);
+static void run_access_ref(run_t *run, stree_access_t *access,
+    rdata_item_t *arg, rdata_item_t **res);
+static void run_access_deleg(run_t *run, stree_access_t *access,
+    rdata_item_t *arg, rdata_item_t **res);
+static void run_access_object(run_t *run, stree_access_t *access,
+    rdata_item_t *arg, rdata_item_t **res);
+
+static void run_call(run_t *run, stree_call_t *call, rdata_item_t **res);
+static void run_index(run_t *run, stree_index_t *index, rdata_item_t **res);
+static void run_index_array(run_t *run, stree_index_t *index,
+    rdata_item_t *base, list_t *args, rdata_item_t **res);
+static void run_index_object(run_t *run, stree_index_t *index,
+    rdata_item_t *base, list_t *args, rdata_item_t **res);
+static void run_index_string(run_t *run, stree_index_t *index,
+    rdata_item_t *base, list_t *args, rdata_item_t **res);
+static void run_assign(run_t *run, stree_assign_t *assign, rdata_item_t **res);
+static void run_as(run_t *run, stree_as_t *as_op, rdata_item_t **res);
+
+/** Evaluate expression. */
+void run_expr(run_t *run, stree_expr_t *expr, rdata_item_t **res)
+{
+#ifdef DEBUG_RUN_TRACE
+	printf("Executing expression.\n");
+#endif
+
+	switch (expr->ec) {
+	case ec_nameref:
+		run_nameref(run, expr->u.nameref, res);
+		break;
+	case ec_literal:
+		run_literal(run, expr->u.literal, res);
+		break;
+	case ec_self_ref:
+		run_self_ref(run, expr->u.self_ref, res);
+		break;
+	case ec_binop:
+		run_binop(run, expr->u.binop, res);
+		break;
+	case ec_unop:
+		run_unop(run, expr->u.unop, res);
+		break;
+	case ec_new:
+		run_new(run, expr->u.new_op, res);
+		break;
+	case ec_access:
+		run_access(run, expr->u.access, res);
+		break;
+	case ec_call:
+		run_call(run, expr->u.call, res);
+		break;
+	case ec_index:
+		run_index(run, expr->u.index, res);
+		break;
+	case ec_assign:
+		run_assign(run, expr->u.assign, res);
+		break;
+	case ec_as:
+		run_as(run, expr->u.as_op, res);
+		break;
+	}
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Expression result: ");
+	rdata_item_print(*res);
+	printf(".\n");
+#endif
+}
+
+/** Evaluate name reference expression. */
+static void run_nameref(run_t *run, stree_nameref_t *nameref,
+    rdata_item_t **res)
+{
+	stree_symbol_t *sym;
+	rdata_item_t *item;
+	rdata_address_t *address;
+	rdata_addr_var_t *addr_var;
+	rdata_value_t *value;
+	rdata_var_t *var;
+	rdata_deleg_t *deleg_v;
+
+	run_proc_ar_t *proc_ar;
+	stree_symbol_t *csi_sym;
+	stree_csi_t *csi;
+	rdata_object_t *obj;
+	rdata_var_t *member_var;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run nameref.\n");
+#endif
+
+	/*
+	 * Look for a local variable.
+	 */
+	var = run_local_vars_lookup(run, nameref->name->sid);
+	if (var != NULL) {
+		/* Found a local variable. */
+		item = rdata_item_new(ic_address);
+		address = rdata_address_new(ac_var);
+		addr_var = rdata_addr_var_new();
+
+		item->u.address = address;
+		address->u.var_a = addr_var;
+		addr_var->vref = var;
+
+		*res = item;
+#ifdef DEBUG_RUN_TRACE
+		printf("Found local variable.\n");
+#endif
+		return;
+	}
+
+	/*
+	 * Look for a class-wide or global symbol.
+	 */
+
+	/* Determine currently active object or CSI. */
+	proc_ar = run_get_current_proc_ar(run);
+	if (proc_ar->obj != NULL) {
+		assert(proc_ar->obj->vc == vc_object);
+		obj = proc_ar->obj->u.object_v;
+		csi_sym = obj->class_sym;
+		csi = symbol_to_csi(csi_sym);
+		assert(csi != NULL);
+	} else {
+		csi = proc_ar->proc->outer_symbol->outer_csi;
+		obj = NULL;
+	}
+
+	sym = symbol_lookup_in_csi(run->program, csi, nameref->name);
+
+	/* Existence should have been verified in type checking phase. */
+	assert(sym != NULL);
+
+	switch (sym->sc) {
+	case sc_csi:
+#ifdef DEBUG_RUN_TRACE
+		printf("Referencing class.\n");
+#endif
+		item = rdata_item_new(ic_value);
+		value = rdata_value_new();
+		var = rdata_var_new(vc_deleg);
+		deleg_v = rdata_deleg_new();
+
+		item->u.value = value;
+		value->var = var;
+		var->u.deleg_v = deleg_v;
+
+		deleg_v->obj = NULL;
+		deleg_v->sym = sym;
+		*res = item;
+		break;
+	case sc_fun:
+		/* There should be no global functions. */
+		assert(csi != NULL);
+
+		if (sym->outer_csi != csi) {
+			/* Function is not in the current object. */
+			printf("Error: Cannot access non-static member "
+			    "function '");
+			symbol_print_fqn(sym);
+			printf("' from nested CSI '");
+			symbol_print_fqn(csi_sym);
+			printf("'.\n");
+			exit(1);
+		}
+
+		/* Construct delegate. */
+		item = rdata_item_new(ic_value);
+		value = rdata_value_new();
+		item->u.value = value;
+
+		var = rdata_var_new(vc_deleg);
+		deleg_v = rdata_deleg_new();
+		value->var = var;
+		var->u.deleg_v = deleg_v;
+
+		deleg_v->obj = proc_ar->obj;
+		deleg_v->sym = sym;
+
+		*res = item;
+		break;
+	case sc_var:
+#ifdef DEBUG_RUN_TRACE
+		printf("Referencing member variable.\n");
+#endif
+		/* There should be no global variables. */
+		assert(csi != NULL);
+
+		/* XXX Assume variable is not static for now. */
+		assert(obj != NULL);
+
+		if (sym->outer_csi != csi) {
+			/* Variable is not in the current object. */
+			printf("Error: Cannot access non-static member "
+			    "variable '");
+			symbol_print_fqn(sym);
+			printf("' from nested CSI '");
+			symbol_print_fqn(csi_sym);
+			printf("'.\n");
+			exit(1);
+		}
+
+		/* Find member variable in object. */
+		member_var = intmap_get(&obj->fields, nameref->name->sid);
+		assert(member_var != NULL);
+
+		/* Return address of the variable. */
+		item = rdata_item_new(ic_address);
+		address = rdata_address_new(ac_var);
+		addr_var = rdata_addr_var_new();
+
+		item->u.address = address;
+		address->u.var_a = addr_var;
+		addr_var->vref = member_var;
+
+		*res = item;
+		break;
+	default:
+		printf("Referencing symbol class %d unimplemented.\n", sym->sc);
+		*res = NULL;
+		break;
+	}
+}
+
+/** Evaluate literal. */
+static void run_literal(run_t *run, stree_literal_t *literal,
+    rdata_item_t **res)
+{
+#ifdef DEBUG_RUN_TRACE
+	printf("Run literal.\n");
+#endif
+	switch (literal->ltc) {
+	case ltc_bool:
+		run_lit_bool(run, &literal->u.lit_bool, res);
+		break;
+	case ltc_char:
+		run_lit_char(run, &literal->u.lit_char, res);
+		break;
+	case ltc_int:
+		run_lit_int(run, &literal->u.lit_int, res);
+		break;
+	case ltc_ref:
+		run_lit_ref(run, &literal->u.lit_ref, res);
+		break;
+	case ltc_string:
+		run_lit_string(run, &literal->u.lit_string, res);
+		break;
+	}
+}
+
+/** Evaluate Boolean literal. */
+static void run_lit_bool(run_t *run, stree_lit_bool_t *lit_bool,
+    rdata_item_t **res)
+{
+	rdata_item_t *item;
+	rdata_value_t *value;
+	rdata_var_t *var;
+	rdata_bool_t *bool_v;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run Boolean literal.\n");
+#endif
+	(void) run;
+
+	item = rdata_item_new(ic_value);
+	value = rdata_value_new();
+	var = rdata_var_new(vc_bool);
+	bool_v = rdata_bool_new();
+
+	item->u.value = value;
+	value->var = var;
+	var->u.bool_v = bool_v;
+	bool_v->value = lit_bool->value;
+
+	*res = item;
+}
+
+/** Evaluate character literal. */
+static void run_lit_char(run_t *run, stree_lit_char_t *lit_char,
+    rdata_item_t **res)
+{
+	rdata_item_t *item;
+	rdata_value_t *value;
+	rdata_var_t *var;
+	rdata_char_t *char_v;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run character literal.\n");
+#endif
+	(void) run;
+
+	item = rdata_item_new(ic_value);
+	value = rdata_value_new();
+	var = rdata_var_new(vc_char);
+	char_v = rdata_char_new();
+
+	item->u.value = value;
+	value->var = var;
+	var->u.char_v = char_v;
+	bigint_clone(&lit_char->value, &char_v->value);
+
+	*res = item;
+}
+
+/** Evaluate integer literal. */
+static void run_lit_int(run_t *run, stree_lit_int_t *lit_int,
+    rdata_item_t **res)
+{
+	rdata_item_t *item;
+	rdata_value_t *value;
+	rdata_var_t *var;
+	rdata_int_t *int_v;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run integer literal.\n");
+#endif
+	(void) run;
+
+	item = rdata_item_new(ic_value);
+	value = rdata_value_new();
+	var = rdata_var_new(vc_int);
+	int_v = rdata_int_new();
+
+	item->u.value = value;
+	value->var = var;
+	var->u.int_v = int_v;
+	bigint_clone(&lit_int->value, &int_v->value);
+
+	*res = item;
+}
+
+/** Evaluate reference literal (@c nil). */
+static void run_lit_ref(run_t *run, stree_lit_ref_t *lit_ref,
+    rdata_item_t **res)
+{
+	rdata_item_t *item;
+	rdata_value_t *value;
+	rdata_var_t *var;
+	rdata_ref_t *ref_v;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run reference literal (nil).\n");
+#endif
+	(void) run;
+	(void) lit_ref;
+
+	item = rdata_item_new(ic_value);
+	value = rdata_value_new();
+	var = rdata_var_new(vc_ref);
+	ref_v = rdata_ref_new();
+
+	item->u.value = value;
+	value->var = var;
+	var->u.ref_v = ref_v;
+	ref_v->vref = NULL;
+
+	*res = item;
+}
+
+/** Evaluate string literal. */
+static void run_lit_string(run_t *run, stree_lit_string_t *lit_string,
+    rdata_item_t **res)
+{
+	rdata_item_t *item;
+	rdata_value_t *value;
+	rdata_var_t *var;
+	rdata_string_t *string_v;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run integer literal.\n");
+#endif
+	(void) run;
+
+	item = rdata_item_new(ic_value);
+	value = rdata_value_new();
+	var = rdata_var_new(vc_string);
+	string_v = rdata_string_new();
+
+	item->u.value = value;
+	value->var = var;
+	var->u.string_v = string_v;
+	string_v->value = lit_string->value;
+
+	*res = item;
+}
+
+/** Evaluate @c self reference. */
+static void run_self_ref(run_t *run, stree_self_ref_t *self_ref,
+    rdata_item_t **res)
+{
+	run_proc_ar_t *proc_ar;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run self reference.\n");
+#endif
+	(void) self_ref;
+	proc_ar = run_get_current_proc_ar(run);
+
+	/* Return reference to the currently active object. */
+	run_reference(run, proc_ar->obj, res);
+}
+
+/** Evaluate binary operation. */
+static void run_binop(run_t *run, stree_binop_t *binop, rdata_item_t **res)
+{
+	rdata_item_t *rarg1_i, *rarg2_i;
+	rdata_item_t *rarg1_vi, *rarg2_vi;
+	rdata_value_t *v1, *v2;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run binary operation.\n");
+#endif
+	run_expr(run, binop->arg1, &rarg1_i);
+	if (run_is_bo(run)) {
+		*res = NULL;
+		return;
+	}
+
+	run_expr(run, binop->arg2, &rarg2_i);
+	if (run_is_bo(run)) {
+		*res = NULL;
+		return;
+	}
+
+	switch (binop->bc) {
+	case bo_plus:
+	case bo_minus:
+	case bo_mult:
+	case bo_equal:
+	case bo_notequal:
+	case bo_lt:
+	case bo_gt:
+	case bo_lt_equal:
+	case bo_gt_equal:
+		/* These are implemented so far. */
+		break;
+	default:
+		printf("Unimplemented: Binary operation type %d.\n",
+		    binop->bc);
+		exit(1);
+	}
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Check binop argument results.\n");
+#endif
+
+	run_cvt_value_item(run, rarg1_i, &rarg1_vi);
+	run_cvt_value_item(run, rarg2_i, &rarg2_vi);
+
+	v1 = rarg1_vi->u.value;
+	v2 = rarg2_vi->u.value;
+
+	if (v1->var->vc != v2->var->vc) {
+		printf("Unimplemented: Binary operation arguments have "
+		    "different type.\n");
+		exit(1);
+	}
+
+	switch (v1->var->vc) {
+	case vc_bool:
+		run_binop_bool(run, binop, v1, v2, res);
+		break;
+	case vc_char:
+		run_binop_char(run, binop, v1, v2, res);
+		break;
+	case vc_int:
+		run_binop_int(run, binop, v1, v2, res);
+		break;
+	case vc_string:
+		run_binop_string(run, binop, v1, v2, res);
+		break;
+	case vc_ref:
+		run_binop_ref(run, binop, v1, v2, res);
+		break;
+	case vc_deleg:
+	case vc_array:
+	case vc_object:
+	case vc_resource:
+		assert(b_false);
+	}
+}
+
+/** Evaluate binary operation on bool arguments. */
+static void run_binop_bool(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
+    rdata_value_t *v2, rdata_item_t **res)
+{
+	rdata_item_t *item;
+	rdata_value_t *value;
+	rdata_var_t *var;
+	rdata_bool_t *bool_v;
+
+	bool_t b1, b2;
+
+	(void) run;
+
+	item = rdata_item_new(ic_value);
+	value = rdata_value_new();
+	var = rdata_var_new(vc_bool);
+	bool_v = rdata_bool_new();
+
+	item->u.value = value;
+	value->var = var;
+	var->u.bool_v = bool_v;
+
+	b1 = v1->var->u.bool_v->value;
+	b2 = v2->var->u.bool_v->value;
+
+	switch (binop->bc) {
+	case bo_plus:
+	case bo_minus:
+	case bo_mult:
+		assert(b_false);
+
+	case bo_equal:
+		bool_v->value = (b1 == b2);
+		break;
+	case bo_notequal:
+		bool_v->value = (b1 != b2);
+		break;
+	case bo_lt:
+		bool_v->value = (b1 == b_false) && (b2 == b_true);
+		break;
+	case bo_gt:
+		bool_v->value = (b1 == b_true) && (b2 == b_false);
+		break;
+	case bo_lt_equal:
+		bool_v->value = (b1 == b_false) || (b2 == b_true);
+		break;
+	case bo_gt_equal:
+		bool_v->value = (b1 == b_true) || (b2 == b_false);
+		break;
+	}
+
+	*res = item;
+}
+
+/** Evaluate binary operation on char arguments. */
+static void run_binop_char(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
+    rdata_value_t *v2, rdata_item_t **res)
+{
+	rdata_item_t *item;
+	rdata_value_t *value;
+	rdata_var_t *var;
+	rdata_bool_t *bool_v;
+
+	bigint_t *c1, *c2;
+	bigint_t diff;
+	bool_t zf, nf;
+
+	(void) run;
+
+	item = rdata_item_new(ic_value);
+	value = rdata_value_new();
+
+	item->u.value = value;
+
+	c1 = &v1->var->u.char_v->value;
+	c2 = &v2->var->u.char_v->value;
+
+	var = rdata_var_new(vc_bool);
+	bool_v = rdata_bool_new();
+	var->u.bool_v = bool_v;
+	value->var = var;
+
+	bigint_sub(c1, c2, &diff);
+	zf = bigint_is_zero(&diff);
+	nf = bigint_is_negative(&diff);
+
+	switch (binop->bc) {
+	case bo_plus:
+	case bo_minus:
+	case bo_mult:
+		assert(b_false);
+
+	case bo_equal:
+		bool_v->value = zf;
+		break;
+	case bo_notequal:
+		bool_v->value = !zf;
+		break;
+	case bo_lt:
+		bool_v->value = (!zf && nf);
+		break;
+	case bo_gt:
+		bool_v->value = (!zf && !nf);
+		break;
+	case bo_lt_equal:
+		bool_v->value = (zf || nf);
+		break;
+	case bo_gt_equal:
+		bool_v->value = !nf;
+		break;
+	default:
+		assert(b_false);
+	}
+
+	*res = item;
+}
+
+/** Evaluate binary operation on int arguments. */
+static void run_binop_int(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
+    rdata_value_t *v2, rdata_item_t **res)
+{
+	rdata_item_t *item;
+	rdata_value_t *value;
+	rdata_var_t *var;
+	rdata_int_t *int_v;
+	rdata_bool_t *bool_v;
+
+	bigint_t *i1, *i2;
+	bigint_t diff;
+	bool_t done;
+	bool_t zf, nf;
+
+	(void) run;
+
+	item = rdata_item_new(ic_value);
+	value = rdata_value_new();
+
+	item->u.value = value;
+
+	i1 = &v1->var->u.int_v->value;
+	i2 = &v2->var->u.int_v->value;
+
+	done = b_true;
+
+	switch (binop->bc) {
+	case bo_plus:
+		int_v = rdata_int_new();
+		bigint_add(i1, i2, &int_v->value);
+		break;
+	case bo_minus:
+		int_v = rdata_int_new();
+		bigint_sub(i1, i2, &int_v->value);
+		break;
+	case bo_mult:
+		int_v = rdata_int_new();
+		bigint_mul(i1, i2, &int_v->value);
+		break;
+	default:
+		done = b_false;
+		break;
+	}
+
+	if (done) {
+		var = rdata_var_new(vc_int);
+		var->u.int_v = int_v;
+		value->var = var;
+		*res = item;
+		return;
+	}
+
+	var = rdata_var_new(vc_bool);
+	bool_v = rdata_bool_new();
+	var->u.bool_v = bool_v;
+	value->var = var;
+
+	/* Relational operation. */
+
+	bigint_sub(i1, i2, &diff);
+	zf = bigint_is_zero(&diff);
+	nf = bigint_is_negative(&diff);
+
+	switch (binop->bc) {
+	case bo_equal:
+		bool_v->value = zf;
+		break;
+	case bo_notequal:
+		bool_v->value = !zf;
+		break;
+	case bo_lt:
+		bool_v->value = (!zf && nf);
+		break;
+	case bo_gt:
+		bool_v->value = (!zf && !nf);
+		break;
+	case bo_lt_equal:
+		bool_v->value = (zf || nf);
+		break;
+	case bo_gt_equal:
+		bool_v->value = !nf;
+		break;
+	default:
+		assert(b_false);
+	}
+
+	*res = item;
+}
+
+/** Evaluate binary operation on string arguments. */
+static void run_binop_string(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
+    rdata_value_t *v2, rdata_item_t **res)
+{
+	rdata_item_t *item;
+	rdata_value_t *value;
+	rdata_var_t *var;
+	rdata_string_t *string_v;
+
+	char *s1, *s2;
+
+	(void) run;
+
+	item = rdata_item_new(ic_value);
+	value = rdata_value_new();
+	var = rdata_var_new(vc_string);
+	string_v = rdata_string_new();
+
+	item->u.value = value;
+	value->var = var;
+	var->u.string_v = string_v;
+
+	s1 = v1->var->u.string_v->value;
+	s2 = v2->var->u.string_v->value;
+
+	switch (binop->bc) {
+	case bo_plus:
+		/* Concatenate strings. */
+		string_v->value = os_str_acat(s1, s2);
+		break;
+	default:
+		printf("Error: Invalid binary operation on string "
+		    "arguments (%d).\n", binop->bc);
+		assert(b_false);
+	}
+
+	*res = item;
+}
+
+/** Evaluate binary operation on ref arguments. */
+static void run_binop_ref(run_t *run, stree_binop_t *binop, rdata_value_t *v1,
+    rdata_value_t *v2, rdata_item_t **res)
+{
+	rdata_item_t *item;
+	rdata_value_t *value;
+	rdata_var_t *var;
+	rdata_bool_t *bool_v;
+
+	rdata_var_t *ref1, *ref2;
+
+	(void) run;
+
+	item = rdata_item_new(ic_value);
+	value = rdata_value_new();
+	var = rdata_var_new(vc_bool);
+	bool_v = rdata_bool_new();
+
+	item->u.value = value;
+	value->var = var;
+	var->u.bool_v = bool_v;
+
+	ref1 = v1->var->u.ref_v->vref;
+	ref2 = v2->var->u.ref_v->vref;
+
+	switch (binop->bc) {
+	case bo_equal:
+		bool_v->value = (ref1 == ref2);
+		break;
+	case bo_notequal:
+		bool_v->value = (ref1 != ref2);
+		break;
+	default:
+		printf("Error: Invalid binary operation on reference "
+		    "arguments (%d).\n", binop->bc);
+		assert(b_false);
+	}
+
+	*res = item;
+}
+
+
+/** Evaluate unary operation. */
+static void run_unop(run_t *run, stree_unop_t *unop, rdata_item_t **res)
+{
+	rdata_item_t *rarg_i;
+	rdata_item_t *rarg_vi;
+	rdata_value_t *val;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run unary operation.\n");
+#endif
+	run_expr(run, unop->arg, &rarg_i);
+	if (run_is_bo(run)) {
+		*res = NULL;
+		return;
+	}
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Check unop argument result.\n");
+#endif
+	run_cvt_value_item(run, rarg_i, &rarg_vi);
+
+	val = rarg_vi->u.value;
+
+	switch (val->var->vc) {
+	case vc_int:
+		run_unop_int(run, unop, val, res);
+		break;
+	default:
+		printf("Unimplemented: Unrary operation argument of "
+		    "type %d.\n", val->var->vc);
+		run_raise_error(run);
+		*res = NULL;
+		break;
+	}
+}
+
+/** Evaluate unary operation on int argument. */
+static void run_unop_int(run_t *run, stree_unop_t *unop, rdata_value_t *val,
+    rdata_item_t **res)
+{
+	rdata_item_t *item;
+	rdata_value_t *value;
+	rdata_var_t *var;
+	rdata_int_t *int_v;
+
+	(void) run;
+
+	item = rdata_item_new(ic_value);
+	value = rdata_value_new();
+	var = rdata_var_new(vc_int);
+	int_v = rdata_int_new();
+
+	item->u.value = value;
+	value->var = var;
+	var->u.int_v = int_v;
+
+	switch (unop->uc) {
+	case uo_plus:
+	        bigint_clone(&val->var->u.int_v->value, &int_v->value);
+		break;
+	case uo_minus:
+		bigint_reverse_sign(&val->var->u.int_v->value,
+		    &int_v->value);
+		break;
+	}
+
+	*res = item;
+}
+
+
+/** Evaluate @c new operation. */
+static void run_new(run_t *run, stree_new_t *new_op, rdata_item_t **res)
+{
+	tdata_item_t *titem;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run 'new' operation.\n");
+#endif
+	/* Evaluate type expression */
+	run_texpr(run->program, run_get_current_csi(run), new_op->texpr,
+	    &titem);
+
+	switch (titem->tic) {
+	case tic_tarray:
+		run_new_array(run, new_op, titem, res);
+		break;
+	case tic_tobject:
+		run_new_object(run, new_op, titem, res);
+		break;
+	default:
+		printf("Error: Invalid argument to operator 'new', "
+		    "expected object.\n");
+		exit(1);
+	}
+}
+
+/** Create new array. */
+static void run_new_array(run_t *run, stree_new_t *new_op,
+    tdata_item_t *titem, rdata_item_t **res)
+{
+	tdata_array_t *tarray;
+	rdata_array_t *array;
+	rdata_var_t *array_var;
+	rdata_var_t *elem_var;
+
+	rdata_item_t *rexpr, *rexpr_vi;
+	rdata_var_t *rexpr_var;
+
+	stree_expr_t *expr;
+
+	list_node_t *node;
+	int length;
+	int i;
+	int rc;
+	int iextent;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Create new array.\n");
+#endif
+	(void) run;
+	(void) new_op;
+
+	assert(titem->tic == tic_tarray);
+	tarray = titem->u.tarray;
+
+	/* Create the array. */
+	assert(titem->u.tarray->rank > 0);
+	array = rdata_array_new(titem->u.tarray->rank);
+
+	/* Compute extents. */
+	node = list_first(&tarray->extents);
+	if (node == NULL) {
+		printf("Error: Extents must be specified when constructing "
+		    "an array with 'new'.\n");
+		exit(1);
+	}
+
+	i = 0; length = 1;
+	while (node != NULL) {
+		expr = list_node_data(node, stree_expr_t *);
+
+		/* Evaluate extent argument. */
+		run_expr(run, expr, &rexpr);
+		if (run_is_bo(run)) {
+			*res = NULL;
+			return;
+		}
+
+		run_cvt_value_item(run, rexpr, &rexpr_vi);
+		assert(rexpr_vi->ic == ic_value);
+		rexpr_var = rexpr_vi->u.value->var;
+
+		if (rexpr_var->vc != vc_int) {
+			printf("Error: Array extent must be an integer.\n");
+			exit(1);
+		}
+
+#ifdef DEBUG_RUN_TRACE
+		printf("Array extent: ");
+		bigint_print(&rexpr_var->u.int_v->value);
+		printf(".\n");
+#endif
+		rc = bigint_get_value_int(&rexpr_var->u.int_v->value,
+		    &iextent);
+		if (rc != EOK) {
+			printf("Memory allocation failed (big int used).\n");
+			exit(1);
+		}
+
+		array->extent[i] = iextent;
+		length = length * array->extent[i];
+
+		node = list_next(&tarray->extents, node);
+		i += 1;
+	}
+
+	array->element = calloc(length, sizeof(rdata_var_t *));
+	if (array->element == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	/* Create member variables */
+	for (i = 0; i < length; ++i) {
+		/* XXX Depends on member variable type. */
+		elem_var = rdata_var_new(vc_int);
+		elem_var->u.int_v = rdata_int_new();
+		bigint_init(&elem_var->u.int_v->value, 0);
+
+		array->element[i] = elem_var;
+	}
+
+	/* Create array variable. */
+	array_var = rdata_var_new(vc_array);
+	array_var->u.array_v = array;
+
+	/* Create reference to the new array. */
+	run_reference(run, array_var, res);
+}
+
+/** Create new object. */
+static void run_new_object(run_t *run, stree_new_t *new_op,
+    tdata_item_t *titem, rdata_item_t **res)
+{
+	stree_csi_t *csi;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Create new object.\n");
+#endif
+	(void) new_op;
+
+	/* Lookup object CSI. */
+	assert(titem->tic == tic_tobject);
+	csi = titem->u.tobject->csi;
+
+	/* Create CSI instance. */
+	run_new_csi_inst(run, csi, res);
+}
+
+/** Evaluate member acccess. */
+static void run_access(run_t *run, stree_access_t *access, rdata_item_t **res)
+{
+	rdata_item_t *rarg;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run access operation.\n");
+#endif
+	run_expr(run, access->arg, &rarg);
+	if (run_is_bo(run)) {
+		*res = NULL;
+		return;
+    	}
+
+	if (rarg == NULL) {
+		printf("Error: Sub-expression has no value.\n");
+		exit(1);
+	}
+
+	run_access_item(run, access, rarg, res);
+}
+
+/** Evaluate member acccess (with base already evaluated). */
+static void run_access_item(run_t *run, stree_access_t *access,
+    rdata_item_t *arg, rdata_item_t **res)
+{
+	var_class_t vc;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run access operation on pre-evaluated base.\n");
+#endif
+	vc = run_item_get_vc(run, arg);
+
+	switch (vc) {
+	case vc_ref:
+		run_access_ref(run, access, arg, res);
+		break;
+	case vc_deleg:
+		run_access_deleg(run, access, arg, res);
+		break;
+	case vc_object:
+		run_access_object(run, access, arg, res);
+		break;
+	default:
+		printf("Unimplemented: Using access operator ('.') "
+		    "with unsupported data type (value/%d).\n", vc);
+		exit(1);
+	}
+}
+
+/** Evaluate reference acccess. */
+static void run_access_ref(run_t *run, stree_access_t *access,
+    rdata_item_t *arg, rdata_item_t **res)
+{
+	rdata_item_t *darg;
+
+	/* Implicitly dereference. */
+	run_dereference(run, arg, &darg);
+
+	if (run->thread_ar->bo_mode != bm_none) {
+		*res = run_recovery_item(run);
+		return;
+	}
+
+	/* Try again. */
+	run_access_item(run, access, darg, res);
+}
+
+/** Evaluate delegate-member acccess. */
+static void run_access_deleg(run_t *run, stree_access_t *access,
+    rdata_item_t *arg, rdata_item_t **res)
+{
+	rdata_item_t *arg_vi;
+	rdata_value_t *arg_val;
+	rdata_deleg_t *deleg_v;
+	stree_symbol_t *member;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run delegate access operation.\n");
+#endif
+	run_cvt_value_item(run, arg, &arg_vi);
+	arg_val = arg_vi->u.value;
+	assert(arg_val->var->vc == vc_deleg);
+
+	deleg_v = arg_val->var->u.deleg_v;
+	if (deleg_v->obj != NULL || deleg_v->sym->sc != sc_csi) {
+		printf("Error: Using '.' with delegate to different object "
+		    "than a CSI (%d).\n", deleg_v->sym->sc);
+		exit(1);
+	}
+
+	member = symbol_search_csi(run->program, deleg_v->sym->u.csi,
+	    access->member_name);
+
+	/* Member existence should be ensured by static type checking. */
+	assert(member != NULL);
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Found member '%s'.\n",
+	    strtab_get_str(access->member_name->sid));
+#endif
+
+	/*
+	 * Reuse existing item, value, var, deleg.
+	 * XXX This is maybe not a good idea because it complicates memory
+	 * management as there is not a single owner 
+	 */
+	deleg_v->sym = member;
+	*res = arg;
+}
+
+/** Evaluate object member acccess. */
+static void run_access_object(run_t *run, stree_access_t *access,
+    rdata_item_t *arg, rdata_item_t **res)
+{
+	stree_symbol_t *member;
+	rdata_var_t *object_var;
+	rdata_object_t *object;
+	rdata_item_t *ritem;
+	rdata_address_t *address;
+	rdata_addr_var_t *addr_var;
+	rdata_addr_prop_t *addr_prop;
+	rdata_aprop_named_t *aprop_named;
+	rdata_deleg_t *deleg_p;
+
+	rdata_value_t *value;
+	rdata_deleg_t *deleg_v;
+	rdata_var_t *var;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run object access operation.\n");
+#endif
+	assert(arg->ic == ic_address);
+	assert(arg->u.address->ac == ac_var);
+	assert(arg->u.address->u.var_a->vref->vc == vc_object);
+
+	object_var = arg->u.address->u.var_a->vref;
+	object = object_var->u.object_v;
+
+	member = symbol_search_csi(run->program, object->class_sym->u.csi,
+	    access->member_name);
+
+	if (member == NULL) {
+		printf("Error: Object of class '");
+		symbol_print_fqn(object->class_sym);
+		printf("' has no member named '%s'.\n",
+		    strtab_get_str(access->member_name->sid));
+		exit(1);
+	}
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Found member '%s'.\n",
+	    strtab_get_str(access->member_name->sid));
+#endif
+
+	switch (member->sc) {
+	case sc_csi:
+		printf("Error: Accessing object member which is nested CSI.\n");
+		exit(1);
+	case sc_fun:
+		/* Construct delegate. */
+		ritem = rdata_item_new(ic_value);
+		value = rdata_value_new();
+		ritem->u.value = value;
+
+		var = rdata_var_new(vc_deleg);
+		value->var = var;
+		deleg_v = rdata_deleg_new();
+		var->u.deleg_v = deleg_v;
+
+		deleg_v->obj = arg->u.address->u.var_a->vref;
+		deleg_v->sym = member;
+		break;
+	case sc_var:
+		/* Construct variable address item. */
+		ritem = rdata_item_new(ic_address);
+		address = rdata_address_new(ac_var);
+		addr_var = rdata_addr_var_new();
+		ritem->u.address = address;
+		address->u.var_a = addr_var;
+
+		addr_var->vref = intmap_get(&object->fields,
+		    access->member_name->sid);
+		assert(addr_var->vref != NULL);
+		break;
+	case sc_prop:
+		/* Construct named property address. */
+		ritem = rdata_item_new(ic_address);
+		address = rdata_address_new(ac_prop);
+		addr_prop = rdata_addr_prop_new(apc_named);
+		aprop_named = rdata_aprop_named_new();
+		ritem->u.address = address;
+		address->u.prop_a = addr_prop;
+		addr_prop->u.named = aprop_named;
+
+		deleg_p = rdata_deleg_new();
+		deleg_p->obj = object_var;
+		deleg_p->sym = member;
+		addr_prop->u.named->prop_d = deleg_p;
+		break;
+	}
+
+	*res = ritem;
+}
+
+/** Call a function. */
+static void run_call(run_t *run, stree_call_t *call, rdata_item_t **res)
+{
+	rdata_item_t *rfun;
+	rdata_deleg_t *deleg_v;
+	list_t arg_vals;
+	list_node_t *node;
+	stree_expr_t *arg;
+	rdata_item_t *rarg_i, *rarg_vi;
+
+	stree_fun_t *fun;
+	run_proc_ar_t *proc_ar;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run call operation.\n");
+#endif
+	run_expr(run, call->fun, &rfun);
+	if (run_is_bo(run)) {
+		*res = NULL;
+		return;
+	}
+
+	if (run->thread_ar->bo_mode != bm_none) {
+		*res = run_recovery_item(run);
+		return;
+	}
+
+	if (rfun->ic != ic_value || rfun->u.value->var->vc != vc_deleg) {
+		printf("Unimplemented: Call expression of this type.\n");
+		exit(1);
+	}
+
+	deleg_v = rfun->u.value->var->u.deleg_v;
+
+	if (deleg_v->sym->sc != sc_fun) {
+		printf("Error: Called symbol is not a function.\n");
+		exit(1);
+	}
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Call function '");
+	symbol_print_fqn(deleg_v->sym);
+	printf("'\n");
+#endif
+	/* Evaluate function arguments. */
+	list_init(&arg_vals);
+	node = list_first(&call->args);
+
+	while (node != NULL) {
+		arg = list_node_data(node, stree_expr_t *);
+		run_expr(run, arg, &rarg_i);
+		if (run_is_bo(run)) {
+			*res = NULL;
+			return;
+		}
+
+		run_cvt_value_item(run, rarg_i, &rarg_vi);
+
+		list_append(&arg_vals, rarg_vi);
+		node = list_next(&call->args, node);
+	}
+
+	fun = symbol_to_fun(deleg_v->sym);
+	assert(fun != NULL);
+
+	/* Create procedure activation record. */
+	run_proc_ar_create(run, deleg_v->obj, fun->proc, &proc_ar);
+
+	/* Fill in argument values. */
+	run_proc_ar_set_args(run, proc_ar, &arg_vals);
+
+	/* Run the function. */
+	run_proc(run, proc_ar, res);
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Returned from function call.\n");
+#endif
+}
+
+/** Run index operation. */
+static void run_index(run_t *run, stree_index_t *index, rdata_item_t **res)
+{
+	rdata_item_t *rbase;
+	rdata_item_t *base_i;
+	list_node_t *node;
+	stree_expr_t *arg;
+	rdata_item_t *rarg_i, *rarg_vi;
+	var_class_t vc;
+	list_t arg_vals;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run index operation.\n");
+#endif
+	run_expr(run, index->base, &rbase);
+	if (run_is_bo(run)) {
+		*res = NULL;
+		return;
+	}
+
+	vc = run_item_get_vc(run, rbase);
+
+	/* Implicitly dereference. */
+	if (vc == vc_ref) {
+		run_dereference(run, rbase, &base_i);
+	} else {
+		base_i = rbase;
+	}
+
+	vc = run_item_get_vc(run, base_i);
+
+	/* Evaluate arguments (indices). */
+	node = list_first(&index->args);
+	list_init(&arg_vals);
+
+	while (node != NULL) {
+		arg = list_node_data(node, stree_expr_t *);
+		run_expr(run, arg, &rarg_i);
+		if (run_is_bo(run)) {
+			*res = NULL;
+			return;
+		}
+
+		run_cvt_value_item(run, rarg_i, &rarg_vi);
+
+		list_append(&arg_vals, rarg_vi);
+
+		node = list_next(&index->args, node);
+	}
+
+	switch (vc) {
+	case vc_array:
+		run_index_array(run, index, base_i, &arg_vals, res);
+		break;
+	case vc_object:
+		run_index_object(run, index, base_i, &arg_vals, res);
+		break;
+	case vc_string:
+		run_index_string(run, index, base_i, &arg_vals, res);
+		break;
+	default:
+		printf("Error: Indexing object of bad type (%d).\n", vc);
+		exit(1);
+	}
+}
+
+/** Run index operation on array. */
+static void run_index_array(run_t *run, stree_index_t *index,
+    rdata_item_t *base, list_t *args, rdata_item_t **res)
+{
+	list_node_t *node;
+	rdata_array_t *array;
+	rdata_item_t *arg;
+
+	int i;
+	int elem_index;
+	int arg_val;
+	int rc;
+
+	rdata_item_t *ritem;
+	rdata_address_t *address;
+	rdata_addr_var_t *addr_var;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run array index operation.\n");
+#endif
+	(void) run;
+	(void) index;
+
+	assert(base->ic == ic_address);
+	assert(base->u.address->ac == ac_var);
+	assert(base->u.address->u.var_a->vref->vc == vc_array);
+	array = base->u.address->u.var_a->vref->u.array_v;
+
+	/*
+	 * Linear index of the desired element. Elements are stored in
+	 * lexicographic order with the last index changing the fastest.
+	 */
+	elem_index = 0;
+
+	node = list_first(args);
+	i = 0;
+
+	while (node != NULL) {
+		if (i >= array->rank) {
+			printf("Error: Too many indices for array of rank %d",
+			    array->rank);
+			exit(1);
+		}
+
+		arg = list_node_data(node, rdata_item_t *);
+		assert(arg->ic == ic_value);
+
+		if (arg->u.value->var->vc != vc_int) {
+			printf("Error: Array index is not an integer.\n");
+			exit(1);
+		}
+
+		rc = bigint_get_value_int(
+		    &arg->u.value->var->u.int_v->value,
+		    &arg_val);
+
+		if (rc != EOK || arg_val < 0 || arg_val >= array->extent[i]) {
+#ifdef DEBUG_RUN_TRACE
+			printf("Error: Array index (value: %d) is out of range.\n",
+			    arg_val);
+#endif
+			/* Raise Error.OutOfBounds */
+			run_raise_exc(run,
+			    run->program->builtin->error_outofbounds);
+			*res = run_recovery_item(run);
+			return;
+		}
+
+		elem_index = elem_index * array->extent[i] + arg_val;
+
+		node = list_next(args, node);
+		i += 1;
+	}
+
+	if (i < array->rank) {
+		printf("Error: Too few indices for array of rank %d",
+		    array->rank);
+		exit(1);
+	}
+
+	/* Construct variable address item. */
+	ritem = rdata_item_new(ic_address);
+	address = rdata_address_new(ac_var);
+	addr_var = rdata_addr_var_new();
+	ritem->u.address = address;
+	address->u.var_a = addr_var;
+
+	addr_var->vref = array->element[elem_index];
+
+	*res = ritem;
+}
+
+/** Index an object (via its indexer). */
+static void run_index_object(run_t *run, stree_index_t *index,
+    rdata_item_t *base, list_t *args, rdata_item_t **res)
+{
+	rdata_item_t *ritem;
+	rdata_address_t *address;
+	rdata_addr_prop_t *addr_prop;
+	rdata_aprop_indexed_t *aprop_indexed;
+	rdata_var_t *obj_var;
+	stree_csi_t *obj_csi;
+	rdata_deleg_t *object_d;
+	stree_symbol_t *indexer_sym;
+	stree_ident_t *indexer_ident;
+
+	list_node_t *node;
+	rdata_item_t *arg;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run object index operation.\n");
+#endif
+	(void) index;
+
+	/* Construct property address item. */
+	ritem = rdata_item_new(ic_address);
+	address = rdata_address_new(ac_prop);
+	addr_prop = rdata_addr_prop_new(apc_indexed);
+	aprop_indexed = rdata_aprop_indexed_new();
+	ritem->u.address = address;
+	address->u.prop_a = addr_prop;
+	addr_prop->u.indexed = aprop_indexed;
+
+	if (base->ic != ic_address || base->u.address->ac != ac_var) {
+		/* XXX Several other cases can occur. */
+		printf("Unimplemented: Indexing object varclass via something "
+		    "which is not a simple variable reference.\n");
+		exit(1);
+	}
+
+	/* Find indexer symbol. */
+	obj_var = base->u.address->u.var_a->vref;
+	assert(obj_var->vc == vc_object);
+	indexer_ident = stree_ident_new();
+	indexer_ident->sid = strtab_get_sid(INDEXER_IDENT);
+	obj_csi = symbol_to_csi(obj_var->u.object_v->class_sym);
+	assert(obj_csi != NULL);
+	indexer_sym = symbol_search_csi(run->program, obj_csi, indexer_ident);
+
+	if (indexer_sym == NULL) {
+		printf("Error: Accessing object which does not have an "
+		    "indexer.\n");
+		exit(1);
+	}
+
+	/* Construct delegate. */
+	object_d = rdata_deleg_new();
+	object_d->obj = obj_var;
+	object_d->sym = indexer_sym;
+	aprop_indexed->object_d = object_d;
+
+	/* Copy list of argument values. */
+	list_init(&aprop_indexed->args);
+
+	node = list_first(args);
+	while (node != NULL) {
+		arg = list_node_data(node, rdata_item_t *);
+		list_append(&aprop_indexed->args, arg);
+		node = list_next(args, node);
+	}
+
+	*res = ritem;
+}
+
+/** Run index operation on string. */
+static void run_index_string(run_t *run, stree_index_t *index,
+    rdata_item_t *base, list_t *args, rdata_item_t **res)
+{
+	list_node_t *node;
+	rdata_string_t *string;
+	rdata_item_t *base_vi;
+	rdata_item_t *arg;
+
+	int i;
+	int elem_index;
+	int arg_val;
+	int rc1, rc2;
+
+	rdata_value_t *value;
+	rdata_var_t *cvar;
+	rdata_item_t *ritem;
+	int cval;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run string index operation.\n");
+#endif
+	(void) run;
+	(void) index;
+
+	run_cvt_value_item(run, base, &base_vi);
+	assert(base_vi->u.value->var->vc == vc_string);
+	string = base_vi->u.value->var->u.string_v;
+
+	/*
+	 * Linear index of the desired element. Elements are stored in
+	 * lexicographic order with the last index changing the fastest.
+	 */
+	node = list_first(args);
+	elem_index = 0;
+
+	i = 0;
+	while (node != NULL) {
+		if (i >= 1) {
+			printf("Error: Too many indices string.\n");
+			exit(1);
+		}
+
+		arg = list_node_data(node, rdata_item_t *);
+		assert(arg->ic == ic_value);
+
+		if (arg->u.value->var->vc != vc_int) {
+			printf("Error: String index is not an integer.\n");
+			exit(1);
+		}
+
+		rc1 = bigint_get_value_int(
+		    &arg->u.value->var->u.int_v->value,
+		    &arg_val);
+
+		elem_index = arg_val;
+
+		node = list_next(args, node);
+		i += 1;
+	}
+
+	if (i < 1) {
+		printf("Error: Too few indices for string.\n");
+		exit(1);
+	}
+
+	if (rc1 == EOK)
+		rc2 = os_str_get_char(string->value, elem_index, &cval);
+
+	if (rc1 != EOK || rc2 != EOK) {
+#ifdef DEBUG_RUN_TRACE
+		printf("Error: String index (value: %d) is out of range.\n",
+		    arg_val);
+#endif
+		/* Raise Error.OutOfBounds */
+		run_raise_exc(run, run->program->builtin->error_outofbounds);
+		*res = run_recovery_item(run);
+		return;
+	}
+
+	/* Construct character value. */
+	ritem = rdata_item_new(ic_value);
+	value = rdata_value_new();
+	ritem->u.value = value;
+
+	cvar = rdata_var_new(vc_char);
+	cvar->u.char_v = rdata_char_new();
+	bigint_init(&cvar->u.char_v->value, cval);
+	value->var = cvar;
+
+	*res = ritem;
+}
+
+/** Execute assignment. */
+static void run_assign(run_t *run, stree_assign_t *assign, rdata_item_t **res)
+{
+	rdata_item_t *rdest_i, *rsrc_i;
+	rdata_item_t *rsrc_vi;
+	rdata_value_t *src_val;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run assign operation.\n");
+#endif
+	run_expr(run, assign->dest, &rdest_i);
+	if (run_is_bo(run)) {
+		*res = NULL;
+		return;
+	}
+
+	run_expr(run, assign->src, &rsrc_i);
+	if (run_is_bo(run)) {
+		*res = NULL;
+		return;
+	}
+
+	run_cvt_value_item(run, rsrc_i, &rsrc_vi);
+	assert(rsrc_vi->ic == ic_value);
+	src_val = rsrc_vi->u.value;
+
+	if (rdest_i->ic != ic_address) {
+		printf("Error: Address expression required on left side of "
+		    "assignment operator.\n");
+		exit(1);
+	}
+
+	run_address_write(run, rdest_i->u.address, rsrc_vi->u.value);
+
+	*res = NULL;
+}
+
+/** Execute @c as conversion. */
+static void run_as(run_t *run, stree_as_t *as_op, rdata_item_t **res)
+{
+	rdata_item_t *rarg_i;
+	rdata_item_t *rarg_vi;
+	rdata_item_t *rarg_di;
+	rdata_var_t *arg_vref;
+	tdata_item_t *dtype;
+	run_proc_ar_t *proc_ar;
+
+	stree_symbol_t *obj_csi_sym;
+	stree_csi_t *obj_csi;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Run @c as conversion operation.\n");
+#endif
+	run_expr(run, as_op->arg, &rarg_i);
+	if (run_is_bo(run)) {
+		*res = NULL;
+		return;
+	}
+
+	/*
+	 * This should always be a reference if the argument is indeed
+	 * a class instance.
+	 */
+	assert(run_item_get_vc(run, rarg_i) == vc_ref);
+	run_cvt_value_item(run, rarg_i, &rarg_vi);
+	assert(rarg_vi->ic == ic_value);
+
+	if (rarg_vi->u.value->var->u.ref_v->vref == NULL) {
+		/* Nil reference is always okay. */
+		*res = rarg_vi;
+		return;
+	}
+
+	run_dereference(run, rarg_vi, &rarg_di);
+
+	/* Now we should have a variable address. */
+	assert(rarg_di->ic == ic_address);
+	assert(rarg_di->u.address->ac == ac_var);
+
+	arg_vref = rarg_di->u.address->u.var_a->vref;
+
+	proc_ar = run_get_current_proc_ar(run);
+	/* XXX Memoize to avoid recomputing. */
+	run_texpr(run->program, proc_ar->proc->outer_symbol->outer_csi,
+	    as_op->dtype, &dtype);
+
+	assert(arg_vref->vc == vc_object);
+	obj_csi_sym = arg_vref->u.object_v->class_sym;
+	obj_csi = symbol_to_csi(obj_csi_sym);
+	assert(obj_csi != NULL);
+
+	if (tdata_is_csi_derived_from_ti(obj_csi, dtype) != b_true) {
+		printf("Error: Run-time type conversion error. Object is "
+		    "of type '");
+		symbol_print_fqn(obj_csi_sym);
+		printf("' which is not derived from '");
+		tdata_item_print(dtype);
+		printf("'.\n");
+		exit(1);
+	}
+
+	*res = rarg_vi;
+}
+
+/** Create new CSI instance. */
+void run_new_csi_inst(run_t *run, stree_csi_t *csi, rdata_item_t **res)
+{
+	rdata_object_t *obj;
+	rdata_var_t *obj_var;
+
+	stree_symbol_t *csi_sym;
+	stree_csimbr_t *csimbr;
+
+	rdata_var_t *mbr_var;
+
+	list_node_t *node;
+
+	csi_sym = csi_to_symbol(csi);
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Create new instance of CSI '");
+	symbol_print_fqn(csi_sym);
+	printf("'.\n");
+#endif
+
+	/* Create the object. */
+	obj = rdata_object_new();
+	obj->class_sym = csi_sym;
+	intmap_init(&obj->fields);
+
+	obj_var = rdata_var_new(vc_object);
+	obj_var->u.object_v = obj;
+
+	/* Create object fields. */
+	node = list_first(&csi->members);
+	while (node != NULL) {
+		csimbr = list_node_data(node, stree_csimbr_t *);
+		if (csimbr->cc == csimbr_var) {
+			/* XXX Depends on member variable type. */
+			mbr_var = rdata_var_new(vc_int);
+			mbr_var->u.int_v = rdata_int_new();
+			bigint_init(&mbr_var->u.int_v->value, 0);
+
+			intmap_set(&obj->fields, csimbr->u.var->name->sid,
+			    mbr_var);
+		}
+
+		node = list_next(&csi->members, node);
+	}
+
+	/* Create reference to the new object. */
+	run_reference(run, obj_var, res);
+}
+
+/** Return boolean value of an item.
+ *
+ * Tries to interpret @a item as a boolean value. If it is not a boolean
+ * value, this generates an error.
+ */
+bool_t run_item_boolean_value(run_t *run, rdata_item_t *item)
+{
+	rdata_item_t *vitem;
+	rdata_var_t *var;
+
+	(void) run;
+	run_cvt_value_item(run, item, &vitem);
+
+	assert(vitem->ic == ic_value);
+	var = vitem->u.value->var;
+
+	assert(var->vc == vc_bool);
+	return var->u.bool_v->value;
+}
Index: uspace/app/sbi/src/run_expr.h
===================================================================
--- uspace/app/sbi/src/run_expr.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/run_expr.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef RUN_EXPR_H_
+#define RUN_EXPR_H_
+
+#include "mytypes.h"
+
+void run_expr(run_t *run, stree_expr_t *expr, rdata_item_t **res);
+
+void run_new_csi_inst(run_t *run, stree_csi_t *csi, rdata_item_t **res);
+bool_t run_item_boolean_value(run_t *run, rdata_item_t *item);
+
+
+#endif
Index: uspace/app/sbi/src/run_t.h
===================================================================
--- uspace/app/sbi/src/run_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/run_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef RUN_T_H_
+#define RUN_T_H_
+
+#include "intmap_t.h"
+#include "list_t.h"
+
+/** Block activation record
+ *
+ * One block AR is created for each block that we enter. A variable declaration
+ * statement inserts the variable here. Upon exiting the block we pop from the
+ * stack, thus all the variables declared in that block are forgotten.
+ */
+typedef struct run_block_ar {
+	/** Variables in this block */
+	intmap_t vars; /* of rdata_var_t */
+} run_block_ar_t;
+
+
+/** Procedure activation record
+ *
+ * A procedure can be a member function, a named property or an indexed
+ * property. A procedure activation record is created whenever a procedure
+ * is invoked.
+ */
+typedef struct run_proc_ar {
+	/** Object on which the procedure is being invoked or @c NULL. */
+	struct rdata_var *obj;
+
+	/** Procedure being invoked */
+	struct stree_proc *proc;
+
+	/** Block activation records */
+	list_t block_ar; /* of run_block_ar_t */
+
+	/** Procedure return value or @c NULL if not set. */
+	struct rdata_item *retval;
+} run_proc_ar_t;
+
+/** Bailout mode
+ *
+ * Determines whether control is bailing out of a statement, function, etc.
+ */
+typedef enum {
+	/** Normal execution */
+	bm_none,
+
+	/** Break from statement */
+	bm_stat,
+
+	/** Return from procedure */
+	bm_proc,
+
+	/** Exception */
+	bm_exc,
+
+	/** Unrecoverable runtime error */
+	bm_error
+} run_bailout_mode_t;
+
+/** Thread activation record
+ *
+ * We can walk the list of function ARs to get a function call backtrace.
+ */
+typedef struct run_thread_ar {
+	/** Function activation records */
+	list_t proc_ar; /* of run_proc_ar_t */
+
+	/** Bailout mode */
+	run_bailout_mode_t bo_mode;
+
+	/** Exception payload */
+	struct rdata_value *exc_payload;
+
+	/** @c b_true if a run-time error occured. */
+	bool_t error;
+} run_thread_ar_t;
+
+/** Runner state object */
+typedef struct run {
+	/** Code of the program being executed */
+	struct stree_program *program;
+
+	/** Thread-private state */
+	run_thread_ar_t *thread_ar;
+} run_t;
+
+#endif
Index: uspace/app/sbi/src/run_texpr.c
===================================================================
--- uspace/app/sbi/src/run_texpr.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/run_texpr.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,290 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Evaluates type expressions. */
+
+#include <assert.h>
+#include <stdlib.h>
+#include "list.h"
+#include "mytypes.h"
+#include "strtab.h"
+#include "symbol.h"
+#include "tdata.h"
+
+#include "run_texpr.h"
+
+static void run_taccess(stree_program_t *prog, stree_csi_t *ctx,
+    stree_taccess_t *taccess, tdata_item_t **res);
+static void run_tindex(stree_program_t *prog, stree_csi_t *ctx,
+    stree_tindex_t *tindex, tdata_item_t **res);
+static void run_tliteral(stree_program_t *prog, stree_csi_t *ctx,
+    stree_tliteral_t *tliteral, tdata_item_t **res);
+static void run_tnameref(stree_program_t *prog, stree_csi_t *ctx,
+    stree_tnameref_t *tnameref, tdata_item_t **res);
+static void run_tapply(stree_program_t *prog, stree_csi_t *ctx,
+    stree_tapply_t *tapply, tdata_item_t **res);
+
+void run_texpr(stree_program_t *prog, stree_csi_t *ctx, stree_texpr_t *texpr,
+    tdata_item_t **res)
+{
+	switch (texpr->tc) {
+	case tc_taccess:
+		run_taccess(prog, ctx, texpr->u.taccess, res);
+		break;
+	case tc_tindex:
+		run_tindex(prog, ctx, texpr->u.tindex, res);
+		break;
+	case tc_tliteral:
+		run_tliteral(prog, ctx, texpr->u.tliteral, res);
+		break;
+	case tc_tnameref:
+		run_tnameref(prog, ctx, texpr->u.tnameref, res);
+		break;
+	case tc_tapply:
+		run_tapply(prog, ctx, texpr->u.tapply, res);
+		break;
+	}
+}
+
+static void run_taccess(stree_program_t *prog, stree_csi_t *ctx,
+    stree_taccess_t *taccess, tdata_item_t **res)
+{
+	stree_symbol_t *sym;
+	tdata_item_t *targ_i;
+	tdata_item_t *titem;
+	tdata_object_t *tobject;
+	stree_csi_t *base_csi;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Evaluating type access operation.\n");
+#endif
+	/* Evaluate base type. */
+	run_texpr(prog, ctx, taccess->arg, &targ_i);
+
+	if (targ_i->tic == tic_ignore) {
+		*res = tdata_item_new(tic_ignore);
+		return;
+	}
+
+	if (targ_i->tic != tic_tobject) {
+		printf("Error: Using '.' with type which is not an object.\n");
+		*res = tdata_item_new(tic_ignore);
+		return;
+	}
+
+	/* Get base CSI. */
+	base_csi = targ_i->u.tobject->csi;
+
+	sym = symbol_lookup_in_csi(prog, base_csi, taccess->member_name);
+	if (sym == NULL) {
+		printf("Error: CSI '");
+		symbol_print_fqn(csi_to_symbol(base_csi));
+		printf("' has no member named '%s'.\n",
+		    strtab_get_str(taccess->member_name->sid));
+		*res = tdata_item_new(tic_ignore);
+		return;
+	}
+
+	if (sym->sc != sc_csi) {
+		printf("Error: Symbol '");
+		symbol_print_fqn(sym);
+		printf("' is not a CSI.\n");
+		*res = tdata_item_new(tic_ignore);
+		return;
+	}
+
+	/* Construct type item. */
+	titem = tdata_item_new(tic_tobject);
+	tobject = tdata_object_new();
+	titem->u.tobject = tobject;
+
+	tobject->static_ref = b_false;
+	tobject->csi = sym->u.csi;
+
+	*res = titem;
+}
+
+static void run_tindex(stree_program_t *prog, stree_csi_t *ctx,
+    stree_tindex_t *tindex, tdata_item_t **res)
+{
+	tdata_item_t *base_ti;
+	tdata_item_t *titem;
+	tdata_array_t *tarray;
+	stree_expr_t *arg_expr;
+	list_node_t *arg_node;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Evaluating type index operation.\n");
+#endif
+	/* Evaluate base type. */
+	run_texpr(prog, ctx, tindex->base_type, &base_ti);
+
+	if (base_ti->tic == tic_ignore) {
+		*res = tdata_item_new(tic_ignore);
+		return;
+	}
+
+	/* Construct type item. */
+	titem = tdata_item_new(tic_tarray);
+	tarray = tdata_array_new();
+	titem->u.tarray = tarray;
+
+	tarray->base_ti = base_ti;
+	tarray->rank = tindex->n_args;
+
+	/* Copy extents. */
+	list_init(&tarray->extents);
+	arg_node = list_first(&tindex->args);
+
+	while (arg_node != NULL) {
+		arg_expr = list_node_data(arg_node, stree_expr_t *);
+		list_append(&tarray->extents, arg_expr);
+		arg_node = list_next(&tindex->args, arg_node);
+	}
+
+	*res = titem;
+}
+
+static void run_tliteral(stree_program_t *prog, stree_csi_t *ctx,
+    stree_tliteral_t *tliteral, tdata_item_t **res)
+{
+	tdata_item_t *titem;
+	tdata_primitive_t *tprimitive;
+	tprimitive_class_t tpc;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Evaluating type literal.\n");
+#endif
+	(void) prog;
+	(void) ctx;
+	(void) tliteral;
+
+	switch (tliteral->tlc) {
+	case tlc_bool: tpc = tpc_bool; break;
+	case tlc_char: tpc = tpc_char; break;
+	case tlc_int: tpc = tpc_int; break;
+	case tlc_string: tpc = tpc_string; break;
+	case tlc_resource: tpc = tpc_resource; break;
+	}
+
+	/* Construct type item. */
+	titem = tdata_item_new(tic_tprimitive);
+	tprimitive = tdata_primitive_new(tpc);
+	titem->u.tprimitive = tprimitive;
+
+	*res = titem;
+}
+
+static void run_tnameref(stree_program_t *prog, stree_csi_t *ctx,
+    stree_tnameref_t *tnameref, tdata_item_t **res)
+{
+	stree_symbol_t *sym;
+	tdata_item_t *titem;
+	tdata_object_t *tobject;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Evaluating type name reference.\n");
+#endif
+	sym = symbol_lookup_in_csi(prog, ctx, tnameref->name);
+	if (sym == NULL) {
+		printf("Error: Symbol '%s' not found.\n",
+		    strtab_get_str(tnameref->name->sid));
+		*res = tdata_item_new(tic_ignore);
+		return;
+	}
+
+	if (sym->sc != sc_csi) {
+		printf("Error: Symbol '");
+		symbol_print_fqn(sym);
+		printf("' is not a CSI.\n");
+		*res = tdata_item_new(tic_ignore);
+		return;
+	}
+
+	/* Construct type item. */
+	titem = tdata_item_new(tic_tobject);
+	tobject = tdata_object_new();
+	titem->u.tobject = tobject;
+
+	tobject->static_ref = b_false;
+	tobject->csi = sym->u.csi;
+
+	*res = titem;
+}
+
+static void run_tapply(stree_program_t *prog, stree_csi_t *ctx,
+    stree_tapply_t *tapply, tdata_item_t **res)
+{
+	tdata_item_t *base_ti;
+	tdata_item_t *arg_ti;
+	tdata_item_t *titem;
+	tdata_object_t *tobject;
+
+	list_node_t *arg_n;
+	stree_texpr_t *arg;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Evaluating type apply operation.\n");
+#endif
+	/* Construct type item. */
+	titem = tdata_item_new(tic_tobject);
+	tobject = tdata_object_new();
+	titem->u.tobject = tobject;
+
+	/* Evaluate base (generic) type. */
+	run_texpr(prog, ctx, tapply->gtype, &base_ti);
+
+	if (base_ti->tic != tic_tobject) {
+		printf("Error: Base type of generic application is not "
+		    "a CSI.\n");
+		*res = tdata_item_new(tic_ignore);
+		return;
+	}
+
+	tobject->static_ref = b_false;
+	tobject->csi = base_ti->u.tobject->csi;
+	list_init(&tobject->targs);
+
+	/* Evaluate type arguments. */
+	arg_n = list_first(&tapply->targs);
+	while (arg_n != NULL) {
+		arg = list_node_data(arg_n, stree_texpr_t *);
+		run_texpr(prog, ctx, arg, &arg_ti);
+
+		if (arg_ti->tic == tic_ignore) {
+			*res = tdata_item_new(tic_ignore);
+			return;
+		}
+
+		list_append(&tobject->targs, arg_ti);
+
+		arg_n = list_next(&tapply->targs, arg_n);
+	}
+
+	*res = titem;
+}
Index: uspace/app/sbi/src/run_texpr.h
===================================================================
--- uspace/app/sbi/src/run_texpr.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/run_texpr.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef RUN_TEXPR_H_
+#define RUN_TEXPR_H_
+
+#include "mytypes.h"
+
+void run_texpr(stree_program_t *prog, stree_csi_t *ctx, stree_texpr_t *texpr,
+    tdata_item_t **res);
+
+#endif
Index: uspace/app/sbi/src/stree.c
===================================================================
--- uspace/app/sbi/src/stree.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/stree.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,674 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Stree (syntax tree) intermediate representation. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "list.h"
+#include "mytypes.h"
+
+#include "stree.h"
+
+stree_module_t *stree_module_new(void)
+{
+	stree_module_t *module;
+
+	module = calloc(1, sizeof(stree_module_t));
+	if (module == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	list_init(&module->members);
+	return module;
+}
+
+stree_modm_t *stree_modm_new(modm_class_t mc)
+{
+	stree_modm_t *modm;
+
+	modm = calloc(1, sizeof(stree_modm_t));
+	if (modm == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	modm->mc = mc;
+	return modm;
+}
+
+stree_csi_t *stree_csi_new(csi_class_t cc)
+{
+	stree_csi_t *csi;
+
+	csi = calloc(1, sizeof(stree_csi_t));
+	if (csi == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	csi->cc = cc;
+	csi->ancr_state = ws_unvisited;
+	csi->name = NULL;
+	csi->base_csi_ref = NULL;
+	list_init(&csi->members);
+	return csi;
+}
+
+stree_csimbr_t *stree_csimbr_new(csimbr_class_t cc)
+{
+	stree_csimbr_t *csimbr;
+
+	csimbr = calloc(1, sizeof(stree_csimbr_t));
+	if (csimbr == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	csimbr->cc = cc;
+	return csimbr;
+}
+
+stree_fun_t *stree_fun_new(void)
+{
+	stree_fun_t *fun;
+
+	fun = calloc(1, sizeof(stree_fun_t));
+	if (fun == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return fun;
+}
+
+stree_var_t *stree_var_new(void)
+{
+	stree_var_t *var;
+
+	var = calloc(1, sizeof(stree_var_t));
+	if (var == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return var;
+}
+
+stree_prop_t *stree_prop_new(void)
+{
+	stree_prop_t *prop;
+
+	prop = calloc(1, sizeof(stree_prop_t));
+	if (prop == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return prop;
+}
+
+stree_symbol_attr_t *stree_symbol_attr_new(symbol_attr_class_t sac)
+{
+	stree_symbol_attr_t *symbol_attr;
+
+	symbol_attr = calloc(1, sizeof(stree_symbol_attr_t));
+	if (symbol_attr == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	symbol_attr->sac = sac;
+	return symbol_attr;
+}
+
+stree_proc_t *stree_proc_new(void)
+{
+	stree_proc_t *proc;
+
+	proc = calloc(1, sizeof(stree_proc_t));
+	if (proc == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return proc;
+}
+
+stree_proc_arg_t *stree_proc_arg_new(void)
+{
+	stree_proc_arg_t *proc_arg;
+
+	proc_arg = calloc(1, sizeof(stree_proc_arg_t));
+	if (proc_arg == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return proc_arg;
+}
+
+stree_arg_attr_t *stree_arg_attr_new(arg_attr_class_t aac)
+{
+	stree_arg_attr_t *arg_attr;
+
+	arg_attr = calloc(1, sizeof(stree_arg_attr_t));
+	if (arg_attr == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	arg_attr->aac = aac;
+	return arg_attr;
+}
+
+stree_stat_t *stree_stat_new(stat_class_t sc)
+{
+	stree_stat_t *stat;
+
+	stat = calloc(1, sizeof(stree_stat_t));
+	if (stat == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	stat->sc = sc;
+	return stat;
+}
+
+stree_vdecl_t *stree_vdecl_new(void)
+{
+	stree_vdecl_t *vdecl_s;
+
+	vdecl_s = calloc(1, sizeof(stree_vdecl_t));
+	if (vdecl_s == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return vdecl_s;
+}
+
+stree_if_t *stree_if_new(void)
+{
+	stree_if_t *if_s;
+
+	if_s = calloc(1, sizeof(stree_if_t));
+	if (if_s == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return if_s;
+}
+
+stree_while_t *stree_while_new(void)
+{
+	stree_while_t *while_s;
+
+	while_s = calloc(1, sizeof(stree_while_t));
+	if (while_s == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return while_s;
+}
+
+stree_for_t *stree_for_new(void)
+{
+	stree_for_t *for_s;
+
+	for_s = calloc(1, sizeof(stree_for_t));
+	if (for_s == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return for_s;
+}
+
+stree_raise_t *stree_raise_new(void)
+{
+	stree_raise_t *raise_s;
+
+	raise_s = calloc(1, sizeof(stree_raise_t));
+	if (raise_s == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return raise_s;
+}
+
+stree_return_t *stree_return_new(void)
+{
+	stree_return_t *return_s;
+
+	return_s = calloc(1, sizeof(stree_return_t));
+	if (return_s == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return return_s;
+}
+
+stree_wef_t *stree_wef_new(void)
+{
+	stree_wef_t *wef_s;
+
+	wef_s = calloc(1, sizeof(stree_wef_t));
+	if (wef_s == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return wef_s;
+}
+
+stree_exps_t *stree_exps_new(void)
+{
+	stree_exps_t *exp_s;
+
+	exp_s = calloc(1, sizeof(stree_exps_t));
+	if (exp_s == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return exp_s;
+}
+
+stree_except_t *stree_except_new(void)
+{
+	stree_except_t *except_c;
+
+	except_c = calloc(1, sizeof(stree_except_t));
+	if (except_c == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return except_c;
+}
+
+stree_block_t *stree_block_new(void)
+{
+	stree_block_t *block;
+
+	block = calloc(1, sizeof(stree_block_t));
+	if (block == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return block;
+}
+
+stree_expr_t *stree_expr_new(expr_class_t ec)
+{
+	stree_expr_t *expr;
+
+	expr = calloc(1, sizeof(stree_expr_t));
+	if (expr == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	expr->ec = ec;
+	return expr;
+}
+
+stree_assign_t *stree_assign_new(assign_class_t ac)
+{
+	stree_assign_t *assign;
+
+	assign = calloc(1, sizeof(stree_assign_t));
+	if (assign == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	assign->ac = ac;
+	return assign;
+}
+
+stree_binop_t *stree_binop_new(binop_class_t bc)
+{
+	stree_binop_t *binop;
+
+	binop = calloc(1, sizeof(stree_binop_t));
+	if (binop == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	binop->bc = bc;
+	return binop;
+}
+
+stree_unop_t *stree_unop_new(unop_class_t uc)
+{
+	stree_unop_t *unop;
+
+	unop = calloc(1, sizeof(stree_unop_t));
+	if (unop == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	unop->uc = uc;
+	return unop;
+}
+
+stree_new_t *stree_new_new(void)
+{
+	stree_new_t *new_op;
+
+	new_op = calloc(1, sizeof(stree_new_t));
+	if (new_op == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return new_op;
+}
+
+stree_access_t *stree_access_new(void)
+{
+	stree_access_t *access;
+
+	access = calloc(1, sizeof(stree_access_t));
+	if (access == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return access;
+}
+
+stree_call_t *stree_call_new(void)
+{
+	stree_call_t *call;
+
+	call = calloc(1, sizeof(stree_call_t));
+	if (call == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return call;
+}
+
+stree_index_t *stree_index_new(void)
+{
+	stree_index_t *index;
+
+	index = calloc(1, sizeof(stree_index_t));
+	if (index == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return index;
+}
+
+stree_as_t *stree_as_new(void)
+{
+	stree_as_t *as_expr;
+
+	as_expr = calloc(1, sizeof(stree_as_t));
+	if (as_expr == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return as_expr;
+}
+
+stree_nameref_t *stree_nameref_new(void)
+{
+	stree_nameref_t *nameref;
+
+	nameref = calloc(1, sizeof(stree_nameref_t));
+	if (nameref == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return nameref;
+}
+
+stree_ident_t *stree_ident_new(void)
+{
+	stree_ident_t *ident;
+
+	ident = calloc(1, sizeof(stree_ident_t));
+	if (ident == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return ident;
+}
+
+stree_literal_t *stree_literal_new(literal_class_t ltc)
+{
+	stree_literal_t *literal;
+
+	literal = calloc(1, sizeof(stree_literal_t));
+	if (literal == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	literal->ltc = ltc;
+	return literal;
+}
+
+stree_self_ref_t *stree_self_ref_new(void)
+{
+	stree_self_ref_t *self_ref;
+
+	self_ref = calloc(1, sizeof(stree_self_ref_t));
+	if (self_ref == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return self_ref;
+}
+
+stree_texpr_t *stree_texpr_new(texpr_class_t tc)
+{
+	stree_texpr_t *texpr;
+
+	texpr = calloc(1, sizeof(stree_texpr_t));
+	if (texpr == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	texpr->tc = tc;
+	return texpr;
+}
+
+stree_taccess_t *stree_taccess_new(void)
+{
+	stree_taccess_t *taccess;
+
+	taccess = calloc(1, sizeof(stree_taccess_t));
+	if (taccess == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return taccess;
+}
+
+stree_tapply_t *stree_tapply_new(void)
+{
+	stree_tapply_t *tapply;
+
+	tapply = calloc(1, sizeof(stree_tapply_t));
+	if (tapply == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return tapply;
+}
+
+stree_tindex_t *stree_tindex_new(void)
+{
+	stree_tindex_t *tindex;
+
+	tindex = calloc(1, sizeof(stree_tindex_t));
+	if (tindex == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return tindex;
+}
+
+stree_tliteral_t *stree_tliteral_new(tliteral_class_t tlc)
+{
+	stree_tliteral_t *tliteral;
+
+	tliteral = calloc(1, sizeof(stree_tliteral_t));
+	if (tliteral == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	tliteral->tlc = tlc;
+	return tliteral;
+}
+
+stree_tnameref_t *stree_tnameref_new(void)
+{
+	stree_tnameref_t *tnameref;
+
+	tnameref = calloc(1, sizeof(stree_tnameref_t));
+	if (tnameref == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return tnameref;
+}
+
+stree_symbol_t *stree_symbol_new(symbol_class_t sc)
+{
+	stree_symbol_t *symbol;
+
+	symbol = calloc(1, sizeof(stree_symbol_t));
+	if (symbol == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	symbol->sc = sc;
+	return symbol;
+}
+
+stree_program_t *stree_program_new(void)
+{
+	stree_program_t *program;
+
+	program = calloc(1, sizeof(stree_program_t));
+	if (program == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return program;
+}
+
+/** Determine if @a symbol has attribute of class @a sac. */
+bool_t stree_symbol_has_attr(stree_symbol_t *symbol, symbol_attr_class_t sac)
+{
+	list_node_t *node;
+	stree_symbol_attr_t *attr;
+
+	node = list_first(&symbol->attr);
+	while (node != NULL) {
+		attr = list_node_data(node, stree_symbol_attr_t *);
+		if (attr->sac == sac)
+			return b_true;
+
+		node = list_next(&symbol->attr, node);
+	}
+
+	return b_false;
+}
+
+/** Determine if argument @a arg has attribute of class @a aac. */
+bool_t stree_arg_has_attr(stree_proc_arg_t *arg, arg_attr_class_t aac)
+{
+	list_node_t *node;
+	stree_arg_attr_t *attr;
+
+	node = list_first(&arg->attr);
+	while (node != NULL) {
+		attr = list_node_data(node, stree_arg_attr_t *);
+		if (attr->aac == aac)
+			return b_true;
+
+		node = list_next(&arg->attr, node);
+	}
+
+	return b_false;
+}
+
+/** Determine wheter @a a is derived (transitively) from @a b.
+ *
+ * @param a	Derived CSI.
+ * @param b	Base CSI.
+ * @return	@c b_true if @a a is equal to or directly or indirectly
+ *		derived from @a b.
+ */
+bool_t stree_is_csi_derived_from_csi(stree_csi_t *a, stree_csi_t *b)
+{
+	stree_csi_t *csi;
+
+	csi = a;
+	while (csi != NULL) {
+		if (csi == b)
+			return b_true;
+
+		csi = csi->base_csi;
+	}
+
+	/* We went all the way to the root and did not find b. */
+	return b_false;
+}
Index: uspace/app/sbi/src/stree.h
===================================================================
--- uspace/app/sbi/src/stree.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/stree.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef STREE_H_
+#define STREE_H_
+
+#include "mytypes.h"
+
+stree_module_t *stree_module_new(void);
+stree_modm_t *stree_modm_new(modm_class_t mc);
+stree_csi_t *stree_csi_new(csi_class_t cc);
+stree_csimbr_t *stree_csimbr_new(csimbr_class_t cc);
+stree_fun_t *stree_fun_new(void);
+stree_var_t *stree_var_new(void);
+stree_prop_t *stree_prop_new(void);
+
+stree_symbol_attr_t *stree_symbol_attr_new(symbol_attr_class_t sac);
+
+stree_proc_t *stree_proc_new(void);
+stree_proc_arg_t *stree_proc_arg_new(void);
+stree_arg_attr_t *stree_arg_attr_new(arg_attr_class_t aac);
+
+stree_stat_t *stree_stat_new(stat_class_t sc);
+stree_vdecl_t *stree_vdecl_new(void);
+stree_if_t *stree_if_new(void);
+stree_while_t *stree_while_new(void);
+stree_for_t *stree_for_new(void);
+stree_raise_t *stree_raise_new(void);
+stree_return_t *stree_return_new(void);
+stree_wef_t *stree_wef_new(void);
+stree_exps_t *stree_exps_new(void);
+
+stree_except_t *stree_except_new(void);
+stree_block_t *stree_block_new(void);
+
+stree_expr_t *stree_expr_new(expr_class_t ec);
+stree_assign_t *stree_assign_new(assign_class_t ac);
+stree_binop_t *stree_binop_new(binop_class_t bc);
+stree_unop_t *stree_unop_new(unop_class_t uc);
+stree_new_t *stree_new_new(void);
+stree_access_t *stree_access_new(void);
+stree_call_t *stree_call_new(void);
+stree_index_t *stree_index_new(void);
+stree_as_t *stree_as_new(void);
+stree_nameref_t *stree_nameref_new(void);
+
+stree_ident_t *stree_ident_new(void);
+stree_literal_t *stree_literal_new(literal_class_t ltc);
+stree_self_ref_t *stree_self_ref_new(void);
+
+stree_texpr_t *stree_texpr_new(texpr_class_t tc);
+stree_taccess_t *stree_taccess_new(void);
+stree_tapply_t *stree_tapply_new(void);
+stree_tindex_t *stree_tindex_new(void);
+stree_tliteral_t *stree_tliteral_new(tliteral_class_t tlc);
+stree_tnameref_t *stree_tnameref_new(void);
+
+stree_symbol_t *stree_symbol_new(symbol_class_t sc);
+stree_program_t *stree_program_new(void);
+
+bool_t stree_symbol_has_attr(stree_symbol_t *symbol, symbol_attr_class_t sac);
+bool_t stree_arg_has_attr(stree_proc_arg_t *arg, arg_attr_class_t aac);
+bool_t stree_is_csi_derived_from_csi(stree_csi_t *a, stree_csi_t *b);
+
+#endif
Index: uspace/app/sbi/src/stree_t.h
===================================================================
--- uspace/app/sbi/src/stree_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/stree_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,610 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef STREE_T_H_
+#define STREE_T_H_
+
+#include "bigint_t.h"
+#include "list_t.h"
+#include "builtin_t.h"
+
+/*
+ * Arithmetic expressions
+ */
+
+struct stree_expr;
+
+/** Identifier */
+typedef struct {
+	int sid;
+} stree_ident_t;
+
+/** Name reference */
+typedef struct {
+	stree_ident_t *name;
+} stree_nameref_t;
+
+/** Reference to currently active object. */
+typedef struct {
+} stree_self_ref_t;
+
+/** Boolean literal */
+typedef struct {
+	bool_t value;
+} stree_lit_bool_t;
+
+/** Character literal */
+typedef struct {
+	bigint_t value;
+} stree_lit_char_t;
+
+/** Integer literal */
+typedef struct {
+	bigint_t value;
+} stree_lit_int_t;
+
+/** Reference literal (there is only one: @c nil). */
+typedef struct {
+} stree_lit_ref_t;
+
+/** String literal */
+typedef struct {
+	char *value;
+} stree_lit_string_t;
+
+typedef enum {
+	ltc_bool,
+	ltc_char,
+	ltc_int,
+	ltc_ref,
+	ltc_string
+} literal_class_t;
+
+/** Literal */
+typedef struct {
+	literal_class_t ltc;
+	union {
+		stree_lit_bool_t lit_bool;
+		stree_lit_char_t lit_char;
+		stree_lit_int_t lit_int;
+		stree_lit_ref_t lit_ref;
+		stree_lit_string_t lit_string;
+	} u;
+} stree_literal_t;
+
+/** Binary operation class */
+typedef enum {
+	bo_equal,
+	bo_notequal,
+	bo_lt,
+	bo_gt,
+	bo_lt_equal,
+	bo_gt_equal,
+	bo_plus,
+	bo_minus,
+	bo_mult
+} binop_class_t;
+
+/** Unary operation class */
+typedef enum {
+	uo_plus,
+	uo_minus,
+} unop_class_t;
+
+/** Binary operation */
+typedef struct {
+	/** Binary operation class */
+	binop_class_t bc;
+
+	/** Arguments */
+	struct stree_expr *arg1, *arg2;
+} stree_binop_t;
+
+/** Unary operation */
+typedef struct {
+	/** Operation class */
+	unop_class_t uc;
+
+	/** Argument */
+	struct stree_expr *arg;
+} stree_unop_t;
+
+/** New operation */
+typedef struct {
+	/** Type of object to construct. */
+	struct stree_texpr *texpr;
+} stree_new_t;
+
+/** Member access operation */
+typedef struct {
+	/** Argument */
+	struct stree_expr *arg;
+	/** Name of member being accessed. */
+	stree_ident_t *member_name;
+} stree_access_t;
+
+/** Function call operation */
+typedef struct {
+	/** Function */
+	struct stree_expr *fun;
+
+	/** Arguments */
+	list_t args; /* of stree_expr_t */
+} stree_call_t;
+
+typedef enum {
+	ac_set,
+	ac_increase
+} assign_class_t;
+
+/** Assignment */
+typedef struct {
+	assign_class_t ac;
+	struct stree_expr *dest, *src;
+} stree_assign_t;
+
+/** Indexing operation */
+typedef struct {
+	/** Base */
+	struct stree_expr *base;
+
+	/** Arguments (indices) */
+	list_t args; /* of stree_expr_t */
+} stree_index_t;
+
+/** @c as conversion operation */
+typedef struct {
+	/** Expression to convert */
+	struct stree_expr *arg;
+	/** Destination type of conversion. */
+	struct stree_texpr *dtype;
+} stree_as_t;
+
+/** Arithmetic expression class */
+typedef enum {
+	ec_nameref,
+	ec_literal,
+	ec_self_ref,
+	ec_binop,
+	ec_unop,
+	ec_new,
+	ec_access,
+	ec_call,
+	ec_assign,
+	ec_index,
+	ec_as
+} expr_class_t;
+
+/** Arithmetic expression */
+typedef struct stree_expr {
+	expr_class_t ec;
+
+	struct tdata_item *titem;
+
+	union {
+		stree_nameref_t *nameref;
+		stree_literal_t *literal;
+		stree_self_ref_t *self_ref;
+		stree_binop_t *binop;
+		stree_unop_t *unop;
+		stree_new_t *new_op;
+		stree_access_t *access;
+		stree_call_t *call;
+		stree_index_t *index;
+		stree_assign_t *assign;
+		stree_as_t *as_op;
+	} u;
+} stree_expr_t;
+
+/*
+ * Type expressions
+ */
+
+struct stree_texpr;
+
+/** Type literal class */
+typedef enum {
+	tlc_bool,
+	tlc_char,
+	tlc_int,
+	tlc_resource,
+	tlc_string
+} tliteral_class_t;
+
+/** Type literal */
+typedef struct {
+	tliteral_class_t tlc;
+} stree_tliteral_t;
+
+/** Type name reference */
+typedef struct {
+	stree_ident_t *name;
+} stree_tnameref_t;
+
+/** Type member access operation */
+typedef struct {
+	/** Argument */
+	struct stree_texpr *arg;
+	/** Name of member being accessed. */
+	stree_ident_t *member_name;
+} stree_taccess_t;
+
+/** Type application operation */
+typedef struct {
+	/* Base type */
+	struct stree_texpr *gtype;
+
+	/** (Formal) type arguments */
+	list_t targs; /* of stree_texpr_t */
+} stree_tapply_t;
+
+/** Type index operation */
+typedef struct {
+	/** Base type */
+	struct stree_texpr *base_type;
+
+	/**
+	 * Number of arguments (rank). Needed when only rank is specified
+	 * and @c args are not used.
+	 */
+	int n_args;
+
+	/** Arguments (extents) */
+	list_t args; /* of stree_expr_t */
+} stree_tindex_t;
+
+/** Type expression class */
+typedef enum {
+	tc_tliteral,
+	tc_tnameref,
+	tc_taccess,
+	tc_tapply,
+	tc_tindex
+} texpr_class_t;
+
+/** Arithmetic expression */
+typedef struct stree_texpr {
+	texpr_class_t tc;
+
+	union {
+		stree_tliteral_t *tliteral;
+		stree_tnameref_t *tnameref;
+		stree_taccess_t *taccess;
+		stree_tapply_t *tapply;
+		stree_tindex_t *tindex;
+	} u;
+} stree_texpr_t;
+
+/*
+ * Statements, class members and module members.
+ */
+
+/** Statement block */
+typedef struct stree_block {
+	/** List of statements in the block */
+	list_t stats; /* of stree_stat_t */
+} stree_block_t;
+
+/** Variable declaration */
+typedef struct {
+	stree_ident_t *name;
+	stree_texpr_t *type;
+} stree_vdecl_t;
+
+/** @c except clause */
+typedef struct {
+	stree_ident_t *evar;
+	stree_texpr_t *etype;
+	stree_block_t *block;
+} stree_except_t;
+
+/** If statement */
+typedef struct {
+	stree_expr_t *cond;
+	stree_block_t *if_block;
+	stree_block_t *else_block;
+} stree_if_t;
+
+/** While statement */
+typedef struct {
+	stree_expr_t *cond;
+	stree_block_t *body;
+} stree_while_t;
+
+/** For statement */
+typedef struct {
+	stree_block_t *body;
+} stree_for_t;
+
+/** Raise statement */
+typedef struct {
+	stree_expr_t *expr;
+} stree_raise_t;
+
+/** Return statement */
+typedef struct {
+	stree_expr_t *expr;
+} stree_return_t;
+
+/** Expression statement */
+typedef struct {
+	stree_expr_t *expr;
+} stree_exps_t;
+
+/** With-try-except-finally statement (WEF) */
+typedef struct {
+	stree_block_t *with_block;
+	list_t except_clauses; /* of stree_except_t */
+	stree_block_t *finally_block;
+} stree_wef_t;
+
+/** Statement class */
+typedef enum {
+	st_vdecl,
+	st_if,
+	st_while,
+	st_for,
+	st_raise,
+	st_return,
+	st_exps,
+	st_wef
+} stat_class_t;
+
+/** Statement */
+typedef struct {
+	stat_class_t sc;
+
+	union {
+		stree_vdecl_t *vdecl_s;
+		stree_if_t *if_s;
+		stree_while_t *while_s;
+		stree_for_t *for_s;
+		stree_raise_t *raise_s;
+		stree_return_t *return_s;
+		stree_exps_t *exp_s;
+		stree_wef_t *wef_s;
+	} u;
+} stree_stat_t;
+
+/** Argument attribute class */
+typedef enum {
+	/** Packed argument (for variadic functions) */
+	aac_packed
+} arg_attr_class_t;
+
+/** Argument atribute */
+typedef struct {
+	arg_attr_class_t aac;
+} stree_arg_attr_t;
+
+/** Formal function parameter */
+typedef struct {
+	/* Argument name */
+	stree_ident_t *name;
+
+	/* Argument type */
+	stree_texpr_t *type;
+
+	/* Attributes */
+	list_t attr; /* of stree_arg_attr_t */
+} stree_proc_arg_t;
+
+/** Procedure
+ *
+ * Procedure is the common term for a getter, setter or function body.
+ * A procedure can be invoked. However, the arguments are specified by
+ * the containing symbol.
+ */
+typedef struct stree_proc {
+	/** Symbol (function or property) containing the procedure */
+	struct stree_symbol *outer_symbol;
+
+	/** Main block for regular procedures */
+	stree_block_t *body;
+
+	/** Builtin handler for builtin procedures */
+	builtin_proc_t bi_handler;
+} stree_proc_t;
+
+/** Member function declaration */
+typedef struct stree_fun {
+	/** Function name */
+	stree_ident_t *name;
+
+	/** Symbol */
+	struct stree_symbol *symbol;
+
+	/** Formal parameters */
+	list_t args; /* of stree_proc_arg_t */
+
+	/** Variadic argument or @c NULL if none. */
+	stree_proc_arg_t *varg;
+
+	/** Return type */
+	stree_texpr_t *rtype;
+
+	/** Function implementation */
+	stree_proc_t *proc;
+} stree_fun_t;
+
+/** Member variable declaration */
+typedef struct stree_var {
+	stree_ident_t *name;
+	struct stree_symbol *symbol;
+	stree_texpr_t *type;
+} stree_var_t;
+
+/** Member property declaration */
+typedef struct stree_prop {
+	stree_ident_t *name;
+	struct stree_symbol *symbol;
+	stree_texpr_t *type;
+
+	stree_proc_t *getter;
+
+	stree_proc_t *setter;
+	stree_proc_arg_t *setter_arg;
+
+	/** Formal parameters (for indexed properties) */
+	list_t args; /* of stree_proc_arg_t */
+
+	/** Variadic argument or @c NULL if none. */
+	stree_proc_arg_t *varg;
+} stree_prop_t;
+
+/**
+ * Fake identifiers used with symbols that do not really have one.
+ * (Mostly for error messages.)
+ */
+#define INDEXER_IDENT "$indexer"
+
+typedef enum {
+	csimbr_csi,
+	csimbr_fun,
+	csimbr_var,
+	csimbr_prop
+} csimbr_class_t;
+
+/** Class, struct or interface member */
+typedef struct {
+	csimbr_class_t cc;
+
+	union {
+		struct stree_csi *csi;
+		stree_fun_t *fun;
+		stree_var_t *var;
+		stree_prop_t *prop;
+	} u;
+} stree_csimbr_t;
+
+typedef enum {
+	csi_class,
+	csi_struct,
+	csi_interface
+} csi_class_t;
+
+/** Class, struct or interface declaration */
+typedef struct stree_csi {
+	/** Which of class, struct or interface */
+	csi_class_t cc;
+
+	/** Name of this CSI */
+	stree_ident_t *name;
+
+	/** List of type argument names */
+	list_t targ_names; /* of stree_ident_t */
+
+	/** Symbol for this CSI */
+	struct stree_symbol *symbol;
+
+	/** Type expression referencing base CSI. */
+	stree_texpr_t *base_csi_ref;
+
+	/** Base CSI. Only available when ancr_state == ws_visited. */
+	struct stree_csi *base_csi;
+
+	/** Node state for ancr walks. */
+	walk_state_t ancr_state;
+
+	/** List of CSI members */
+	list_t members; /* of stree_csimbr_t */
+} stree_csi_t;
+
+typedef enum {
+	/* Class, struct or interface declaration */
+	mc_csi
+} modm_class_t;
+
+/** Module member */
+typedef struct {
+	modm_class_t mc;
+	union {
+		stree_csi_t *csi;
+	} u;
+} stree_modm_t;
+
+/** Module */
+typedef struct stree_module {
+	/** List of module members */
+	list_t members; /* of stree_modm_t */
+} stree_module_t;
+
+/** Symbol attribute class */
+typedef enum {
+	/** Builtin symbol (interpreter hook) */
+	sac_builtin
+} symbol_attr_class_t;
+
+/** Symbol atribute */
+typedef struct {
+	symbol_attr_class_t sac;
+} stree_symbol_attr_t;
+
+
+typedef enum {
+	sc_csi,
+	sc_fun,
+	sc_var,
+	sc_prop
+} symbol_class_t;
+
+/** Symbol
+ *
+ * A symbol is a common superclass of different program elements that
+ * allow us to refer to them, print their fully qualified names, etc.
+ */
+typedef struct stree_symbol {
+	symbol_class_t sc;
+
+	union {
+		struct stree_csi *csi;
+		stree_fun_t *fun;
+		stree_var_t *var;
+		stree_prop_t *prop;
+	} u;
+
+	/** Containing CSI (for all symbols) */
+	stree_csi_t *outer_csi;
+
+	/** Containing block (for block-level symbols) */
+	stree_block_t *outer_block;
+
+	/** Symbol attributes. */
+	list_t attr; /* of stree_symbol_attr_t */
+} stree_symbol_t;
+
+/** Program */
+typedef struct stree_program {
+	/** The one and only module in the program */
+	stree_module_t *module;
+
+	/** Builtin symbols binding. */
+	struct builtin *builtin;
+} stree_program_t;
+
+#endif
Index: uspace/app/sbi/src/strtab.c
===================================================================
--- uspace/app/sbi/src/strtab.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/strtab.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file String table.
+ *
+ * Converts strings to more compact SID (string ID, integer) and back.
+ * The string table is not an object as there will never be a need for
+ * more than one.
+ */
+
+#include <stdlib.h>
+#include "mytypes.h"
+#include "os/os.h"
+#include "list.h"
+
+#include "strtab.h"
+
+static list_t str_list;
+
+void strtab_init(void)
+{
+	list_init(&str_list);
+}
+
+sid_t strtab_get_sid(const char *str)
+{
+	list_node_t *node;
+	sid_t sid;
+
+	sid = 0;
+	node = list_first(&str_list);
+
+	while (node != NULL) {
+		++sid;
+		if (os_str_cmp(str, list_node_data(node, char *)) == 0)
+			return sid;
+
+		node = list_next(&str_list, node);
+	}
+
+	++sid;
+	list_append(&str_list, os_str_dup(str));
+
+	return sid;
+}
+
+char *strtab_get_str(sid_t sid)
+{
+	list_node_t *node;
+	sid_t cnt;
+
+	node = list_first(&str_list);
+	cnt = 1;
+	while (node != NULL && cnt < sid) {
+		node = list_next(&str_list, node);
+		cnt += 1;
+	}
+
+	if (node == NULL) {
+		printf("Internal error: Invalid SID %d", sid);
+		abort();
+	}
+
+	return list_node_data(node, char *);
+}
Index: uspace/app/sbi/src/strtab.h
===================================================================
--- uspace/app/sbi/src/strtab.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/strtab.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef STRTAB_H_
+#define STRTAB_H_
+
+#include "mytypes.h"
+
+void strtab_init(void);
+sid_t strtab_get_sid(const char *str);
+char *strtab_get_str(sid_t sid);
+
+#endif
Index: uspace/app/sbi/src/strtab_t.h
===================================================================
--- uspace/app/sbi/src/strtab_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/strtab_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef STRTAB_T_H_
+#define STRTAB_T_H_
+
+/** String ID */
+typedef int sid_t;
+
+#endif
Index: uspace/app/sbi/src/stype.c
===================================================================
--- uspace/app/sbi/src/stype.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/stype.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,740 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/**
+ * @file Implements a walk on the program that computes and checks static
+ * types. 'Types' the program.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "debug.h"
+#include "intmap.h"
+#include "list.h"
+#include "mytypes.h"
+#include "run_texpr.h"
+#include "stree.h"
+#include "strtab.h"
+#include "stype_expr.h"
+#include "symbol.h"
+#include "tdata.h"
+
+#include "stype.h"
+
+static void stype_csi(stype_t *stype, stree_csi_t *csi);
+static void stype_fun(stype_t *stype, stree_fun_t *fun);
+static void stype_var(stype_t *stype, stree_var_t *var);
+static void stype_prop(stype_t *stype, stree_prop_t *prop);
+
+static void stype_block(stype_t *stype, stree_block_t *block);
+
+static void stype_vdecl(stype_t *stype, stree_vdecl_t *vdecl_s);
+static void stype_if(stype_t *stype, stree_if_t *if_s);
+static void stype_while(stype_t *stype, stree_while_t *while_s);
+static void stype_for(stype_t *stype, stree_for_t *for_s);
+static void stype_raise(stype_t *stype, stree_raise_t *raise_s);
+static void stype_return(stype_t *stype, stree_return_t *return_s);
+static void stype_exps(stype_t *stype, stree_exps_t *exp_s, bool_t want_value);
+static void stype_wef(stype_t *stype, stree_wef_t *wef_s);
+
+/** Type module */
+void stype_module(stype_t *stype, stree_module_t *module)
+{
+	list_node_t *mbr_n;
+	stree_modm_t *mbr;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type module.\n");
+#endif
+	stype->current_csi = NULL;
+	stype->proc_vr = NULL;
+
+	mbr_n = list_first(&module->members);
+	while (mbr_n != NULL) {
+		mbr = list_node_data(mbr_n, stree_modm_t *);
+		assert(mbr->mc == mc_csi);
+
+		stype_csi(stype, mbr->u.csi);
+
+		mbr_n = list_next(&module->members, mbr_n);
+	}
+}
+
+/** Type CSI */
+static void stype_csi(stype_t *stype, stree_csi_t *csi)
+{
+	list_node_t *csimbr_n;
+	stree_csimbr_t *csimbr;
+	stree_csi_t *prev_ctx;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type CSI '");
+	symbol_print_fqn(csi_to_symbol(csi));
+	printf("'.\n");
+#endif
+	prev_ctx = stype->current_csi;
+	stype->current_csi = csi;
+
+	csimbr_n = list_first(&csi->members);
+	while (csimbr_n != NULL) {
+		csimbr = list_node_data(csimbr_n, stree_csimbr_t *);
+
+		switch (csimbr->cc) {
+		case csimbr_csi: stype_csi(stype, csimbr->u.csi); break;
+		case csimbr_fun: stype_fun(stype, csimbr->u.fun); break;
+		case csimbr_var: stype_var(stype, csimbr->u.var); break;
+		case csimbr_prop: stype_prop(stype, csimbr->u.prop); break;
+		}
+
+		csimbr_n = list_next(&csi->members, csimbr_n);
+	}
+
+	stype->current_csi = prev_ctx;
+}
+
+/** Type function */
+static void stype_fun(stype_t *stype, stree_fun_t *fun)
+{
+	list_node_t *arg_n;
+	stree_proc_arg_t *arg;
+	stree_symbol_t *fun_sym;
+	tdata_item_t *titem;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type function '");
+	symbol_print_fqn(fun_to_symbol(fun));
+	printf("'.\n");
+#endif
+	fun_sym = fun_to_symbol(fun);
+
+	/*
+	 * Type formal arguments.
+	 * XXX Save the results.
+	 */
+	arg_n = list_first(&fun->args);
+	while (arg_n != NULL) {
+		arg = list_node_data(arg_n, stree_proc_arg_t *);
+
+		/* XXX Because of overloaded builtin WriteLine. */
+		if (arg->type == NULL) {
+			arg_n = list_next(&fun->args, arg_n);
+			continue;
+		}
+
+		run_texpr(stype->program, fun_sym->outer_csi, arg->type,
+		    &titem);
+
+		arg_n = list_next(&fun->args, arg_n);
+	}
+
+	/* Variadic argument */
+	if (fun->varg != NULL) {
+		/* Check type and verify it is an array. */
+		run_texpr(stype->program, fun_sym->outer_csi, fun->varg->type,
+		    &titem);
+
+		if (titem->tic != tic_tarray && titem->tic != tic_ignore) {
+			printf("Error: Packed argument is not an array.\n");
+			stype_note_error(stype);
+		}
+	}
+
+	/*
+	 * Type function body.
+	 */
+
+	/* Builtin functions do not have a body. */
+	if (fun->proc->body == NULL)
+		return;
+
+	stype->proc_vr = stype_proc_vr_new();
+	stype->proc_vr->proc = fun->proc;
+	list_init(&stype->proc_vr->block_vr);
+
+	stype_block(stype, fun->proc->body);
+
+	free(stype->proc_vr);
+	stype->proc_vr = NULL;
+}
+
+/** Type member variable */
+static void stype_var(stype_t *stype, stree_var_t *var)
+{
+	tdata_item_t *titem;
+
+	(void) stype;
+	(void) var;
+
+	run_texpr(stype->program, stype->current_csi, var->type,
+	    &titem);
+	if (titem->tic == tic_ignore) {
+		/* An error occured. */
+		stype_note_error(stype);
+		return;
+	}
+}
+
+/** Type property */
+static void stype_prop(stype_t *stype, stree_prop_t *prop)
+{
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type property '");
+	symbol_print_fqn(prop_to_symbol(prop));
+	printf("'.\n");
+#endif
+	stype->proc_vr = stype_proc_vr_new();
+	list_init(&stype->proc_vr->block_vr);
+
+	if (prop->getter != NULL) {
+		stype->proc_vr->proc = prop->getter;
+		stype_block(stype, prop->getter->body);
+	}
+
+	if (prop->setter != NULL) {
+		stype->proc_vr->proc = prop->setter;
+		stype_block(stype, prop->setter->body);
+	}
+
+	free(stype->proc_vr);
+	stype->proc_vr = NULL;
+}
+
+/** Type statement block */
+static void stype_block(stype_t *stype, stree_block_t *block)
+{
+	stree_stat_t *stat;
+	list_node_t *stat_n;
+	stype_block_vr_t *block_vr;
+	list_node_t *bvr_n;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type block.\n");
+#endif
+
+	/* Create block visit record. */
+	block_vr = stype_block_vr_new();
+	intmap_init(&block_vr->vdecls);
+
+	/* Add block visit record to the stack. */
+	list_append(&stype->proc_vr->block_vr, block_vr);
+
+	stat_n = list_first(&block->stats);
+	while (stat_n != NULL) {
+		stat = list_node_data(stat_n, stree_stat_t *);
+		stype_stat(stype, stat, b_false);
+
+		stat_n = list_next(&block->stats, stat_n);
+	}
+
+	/* Remove block visit record from the stack, */
+	bvr_n = list_last(&stype->proc_vr->block_vr);
+	assert(list_node_data(bvr_n, stype_block_vr_t *) == block_vr);
+	list_remove(&stype->proc_vr->block_vr, bvr_n);
+}
+
+/** Type statement
+ *
+ * Types a statement. If @a want_value is @c b_true, then warning about
+ * ignored expression value will be supressed for this statement (but not
+ * for nested statemens). This is used in interactive mode.
+ *
+ * @param stype		Static typer object.
+ * @param stat		Statement to type.
+ * @param want_value	@c b_true to allow ignoring expression value.
+ */
+void stype_stat(stype_t *stype, stree_stat_t *stat, bool_t want_value)
+{
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type statement.\n");
+#endif
+	switch (stat->sc) {
+	case st_vdecl: stype_vdecl(stype, stat->u.vdecl_s); break;
+	case st_if: stype_if(stype, stat->u.if_s); break;
+	case st_while: stype_while(stype, stat->u.while_s); break;
+	case st_for: stype_for(stype, stat->u.for_s); break;
+	case st_raise: stype_raise(stype, stat->u.raise_s); break;
+	case st_return: stype_return(stype, stat->u.return_s); break;
+	case st_exps: stype_exps(stype, stat->u.exp_s, want_value); break;
+	case st_wef: stype_wef(stype, stat->u.wef_s); break;
+	}
+}
+
+/** Type local variable declaration */
+static void stype_vdecl(stype_t *stype, stree_vdecl_t *vdecl_s)
+{
+	stype_block_vr_t *block_vr;
+	stree_vdecl_t *old_vdecl;
+	tdata_item_t *titem;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type variable declaration statement.\n");
+#endif
+	block_vr = stype_get_current_block_vr(stype);
+	old_vdecl = (stree_vdecl_t *) intmap_get(&block_vr->vdecls,
+	    vdecl_s->name->sid);
+
+	if (old_vdecl != NULL) {
+		printf("Error: Duplicate variable declaration '%s'.\n",
+		    strtab_get_str(vdecl_s->name->sid));
+		stype_note_error(stype);
+	}
+
+	run_texpr(stype->program, stype->current_csi, vdecl_s->type,
+	    &titem);
+	if (titem->tic == tic_ignore) {
+		/* An error occured. */
+		stype_note_error(stype);
+		return;
+	}
+
+	intmap_set(&block_vr->vdecls, vdecl_s->name->sid, vdecl_s);
+}
+
+/** Type @c if statement */
+static void stype_if(stype_t *stype, stree_if_t *if_s)
+{
+	stree_expr_t *ccond;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type 'if' statement.\n");
+#endif
+	/* Convert condition to boolean type. */
+	stype_expr(stype, if_s->cond);
+	ccond = stype_convert(stype, if_s->cond, stype_boolean_titem(stype));
+
+	/* Patch code with augmented expression. */
+	if_s->cond = ccond;
+
+	/* Type the @c if block */
+	stype_block(stype, if_s->if_block);
+
+	/* Type the @c else block */
+	if (if_s->else_block != NULL)
+		stype_block(stype, if_s->else_block);
+}
+
+/** Type @c while statement */
+static void stype_while(stype_t *stype, stree_while_t *while_s)
+{
+	stree_expr_t *ccond;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type 'while' statement.\n");
+#endif
+	/* Convert condition to boolean type. */
+	stype_expr(stype, while_s->cond);
+	ccond = stype_convert(stype, while_s->cond,
+	    stype_boolean_titem(stype));
+
+	/* Patch code with augmented expression. */
+	while_s->cond = ccond;
+
+	/* Type the body of the loop */
+	stype_block(stype, while_s->body);
+}
+
+/** Type @c for statement */
+static void stype_for(stype_t *stype, stree_for_t *for_s)
+{
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type 'for' statement.\n");
+#endif
+	stype_block(stype, for_s->body);
+}
+
+/** Type @c raise statement */
+static void stype_raise(stype_t *stype, stree_raise_t *raise_s)
+{
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type 'raise' statement.\n");
+#endif
+	stype_expr(stype, raise_s->expr);
+}
+
+/** Type @c return statement */
+static void stype_return(stype_t *stype, stree_return_t *return_s)
+{
+	stree_symbol_t *outer_sym;
+	stree_fun_t *fun;
+	stree_prop_t *prop;
+
+	stree_expr_t *cexpr;
+	tdata_item_t *dtype;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type 'return' statement.\n");
+#endif
+	stype_expr(stype, return_s->expr);
+
+	/* Determine the type we need to return. */
+
+	outer_sym = stype->proc_vr->proc->outer_symbol;
+	switch (outer_sym->sc) {
+	case sc_fun:
+		fun = symbol_to_fun(outer_sym);
+		assert(fun != NULL);
+
+		/* XXX Memoize to avoid recomputing. */
+		run_texpr(stype->program, outer_sym->outer_csi, fun->rtype,
+		    &dtype);
+		break;
+	case sc_prop:
+		prop = symbol_to_prop(outer_sym);
+		assert(prop != NULL);
+
+		if (stype->proc_vr->proc != prop->getter) {
+			printf("Error: Return statement in "
+			    "setter.\n");
+			stype_note_error(stype);
+		}
+
+		/* XXX Memoize to avoid recomputing. */
+		run_texpr(stype->program, outer_sym->outer_csi, prop->type,
+		    &dtype);
+		break;
+	default:
+		assert(b_false);
+	}
+
+	/* Convert to the return type. */
+	cexpr = stype_convert(stype, return_s->expr, dtype);
+
+	/* Patch code with the augmented expression. */
+	return_s->expr = cexpr;
+}
+
+/** Type expression statement */
+static void stype_exps(stype_t *stype, stree_exps_t *exp_s, bool_t want_value)
+{
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type expression statement.\n");
+#endif
+	stype_expr(stype, exp_s->expr);
+
+	if (want_value == b_false && exp_s->expr->titem != NULL)
+		printf("Warning: Expression value ignored.\n");
+}
+
+/** Type With-Except-Finally statement */
+static void stype_wef(stype_t *stype, stree_wef_t *wef_s)
+{
+	list_node_t *ec_n;
+	stree_except_t *ec;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type WEF statement.\n");
+#endif
+	/* Type the @c with block. */
+	if (wef_s->with_block != NULL)
+		stype_block(stype, wef_s->with_block);
+
+	/* Type the @c except clauses. */
+	ec_n = list_first(&wef_s->except_clauses);
+	while (ec_n != NULL) {
+		ec = list_node_data(ec_n, stree_except_t *);
+		stype_block(stype, ec->block);
+
+		ec_n = list_next(&wef_s->except_clauses, ec_n);
+	}
+
+	/* Type the @c finally block. */
+	if (wef_s->finally_block != NULL)
+		stype_block(stype, wef_s->finally_block);
+}
+
+/** Convert expression of one type to another type.
+ *
+ * If the type of expression @a expr is not compatible with @a dtype
+ * (i.e. there does not exist an implicit conversion from @a expr->type to
+ * @a dtype), this function will produce an error (Cannot convert A to B).
+ *
+ * Otherwise it will either return the expression unmodified (if there is
+ * no action to take at run time) or it will return a new expression
+ * while clobbering the old one. Typically this would just attach the
+ * expression as a subtree of the conversion.
+ *
+ * Note: No conversion that would require modifying @a expr is implemented
+ * yet.
+ */
+stree_expr_t *stype_convert(stype_t *stype, stree_expr_t *expr,
+    tdata_item_t *dest)
+{
+	tdata_item_t *src;
+
+	(void) stype;
+	src = expr->titem;
+
+	if (dest == NULL) {
+		printf("Error: Conversion destination is not valid.\n");
+		stype_note_error(stype);
+		return expr;
+	}
+
+	if (src == NULL) {
+		printf("Error: Conversion source is not valid.\n");
+		stype_note_error(stype);
+		return expr;
+	}
+
+	if (dest->tic == tic_ignore || src->tic == tic_ignore)
+		return expr;
+
+	/*
+	 * Special case: Nil to object.
+	 */
+	if (src->tic == tic_tprimitive && src->u.tprimitive->tpc == tpc_nil) {
+		if (dest->tic == tic_tobject)
+			return expr;
+	}
+
+	if (src->tic != dest->tic)
+		goto failure;
+
+	switch (src->tic) {
+	case tic_tprimitive:
+		/* Check if both have the same tprimitive class. */
+		if (src->u.tprimitive->tpc != dest->u.tprimitive->tpc)
+			goto failure;
+		break;
+	case tic_tobject:
+		/* Check if @c src is derived from @c dest. */
+		if (stree_is_csi_derived_from_csi(src->u.tobject->csi,
+		    dest->u.tobject->csi) != b_true) {
+			goto failure;
+		}
+		break;
+	case tic_tarray:
+		/* Compare rank and base type. */
+		if (src->u.tarray->rank != dest->u.tarray->rank)
+			goto failure;
+
+		/* XXX Should we convert each element? */
+		if (tdata_item_equal(src->u.tarray->base_ti,
+		    dest->u.tarray->base_ti) != b_true)
+			goto failure;
+		break;
+	case tic_tfun:
+		printf("Error: Unimplemented: Converting '");
+		tdata_item_print(src);
+		printf("' to '");
+		tdata_item_print(dest);
+		printf("'.\n");
+		stype_note_error(stype);
+		break;
+	case tic_ignore:
+		assert(b_false);
+	}
+
+	return expr;
+
+failure:
+	printf("Error: Cannot convert ");
+	tdata_item_print(src);
+	printf(" to ");
+	tdata_item_print(dest);
+	printf(".\n");
+
+	stype_note_error(stype);
+	return expr;
+}
+
+/** Return a boolean type item */
+tdata_item_t *stype_boolean_titem(stype_t *stype)
+{
+	tdata_item_t *titem;
+	tdata_primitive_t *tprimitive;
+
+	(void) stype;
+
+	titem = tdata_item_new(tic_tprimitive);
+	tprimitive = tdata_primitive_new(tpc_bool);
+	titem->u.tprimitive = tprimitive;
+
+	return titem;
+}
+
+/** Find a local variable in the current function. */
+stree_vdecl_t *stype_local_vars_lookup(stype_t *stype, sid_t name)
+{
+	stype_proc_vr_t *proc_vr;
+	stype_block_vr_t *block_vr;
+	stree_vdecl_t *vdecl;
+	list_node_t *node;
+
+	proc_vr = stype->proc_vr;
+	node = list_last(&proc_vr->block_vr);
+
+	/* Walk through all block visit records. */
+	while (node != NULL) {
+		block_vr = list_node_data(node, stype_block_vr_t *);
+		vdecl = intmap_get(&block_vr->vdecls, name);
+		if (vdecl != NULL)
+			return vdecl;
+
+		node = list_prev(&proc_vr->block_vr, node);
+	}
+
+	/* No match */
+	return NULL;
+}
+
+/** Find argument of the current procedure. */
+stree_proc_arg_t *stype_proc_args_lookup(stype_t *stype, sid_t name)
+{
+	stype_proc_vr_t *proc_vr;
+
+	stree_symbol_t *outer_sym;
+	stree_fun_t *fun;
+	stree_prop_t *prop;
+
+	list_t *args;
+	list_node_t *arg_node;
+	stree_proc_arg_t *varg;
+	stree_proc_arg_t *arg;
+	stree_proc_arg_t *setter_arg;
+
+	proc_vr = stype->proc_vr;
+	outer_sym = proc_vr->proc->outer_symbol;
+
+	setter_arg = NULL;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Look for argument named '%s'.\n", strtab_get_str(name));
+#endif
+
+	switch (outer_sym->sc) {
+	case sc_fun:
+		fun = symbol_to_fun(outer_sym);
+		assert(fun != NULL);
+		args = &fun->args;
+		varg = fun->varg;
+		break;
+	case sc_prop:
+		prop = symbol_to_prop(outer_sym);
+		assert(prop != NULL);
+		args = &prop->args;
+		varg = prop->varg;
+
+		/* If we are in a setter, look also at setter argument. */
+		if (prop->setter == proc_vr->proc)
+			setter_arg = prop->setter_arg;
+		break;
+	default:
+		assert(b_false);
+	}
+
+	arg_node = list_first(args);
+	while (arg_node != NULL) {
+		arg = list_node_data(arg_node, stree_proc_arg_t *);
+		if (arg->name->sid == name) {
+			/* Match */
+#ifdef DEBUG_TYPE_TRACE
+			printf("Found argument.\n");
+#endif
+			return arg;
+		}
+
+		arg_node = list_next(args, arg_node);
+	}
+
+	/* Variadic argument */
+	if (varg != NULL && varg->name->sid == name) {
+#ifdef DEBUG_TYPE_TRACE
+		printf("Found variadic argument.\n");
+#endif
+		return varg;
+}
+
+	/* Setter argument */
+	if (setter_arg != NULL && setter_arg->name->sid == name) {
+#ifdef DEBUG_TYPE_TRACE
+		printf("Found setter argument.\n");
+#endif
+		return setter_arg;
+
+	}
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Not found.\n");
+#endif
+	/* No match */
+	return NULL;
+}
+
+/** Note a static typing error that has been immediately recovered. */
+void stype_note_error(stype_t *stype)
+{
+	stype->error = b_true;
+}
+
+/** Construct a special type item for recovery. */
+tdata_item_t *stype_recovery_titem(stype_t *stype)
+{
+	tdata_item_t *titem;
+
+	(void) stype;
+
+	titem = tdata_item_new(tic_ignore);
+	return titem;
+}
+
+/** Get current block visit record. */
+stype_block_vr_t *stype_get_current_block_vr(stype_t *stype)
+{
+	list_node_t *node;
+
+	node = list_last(&stype->proc_vr->block_vr);
+	return list_node_data(node, stype_block_vr_t *);
+}
+
+stype_proc_vr_t *stype_proc_vr_new(void)
+{
+	stype_proc_vr_t *proc_vr;
+
+	proc_vr = calloc(1, sizeof(stype_proc_vr_t));
+	if (proc_vr == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return proc_vr;
+}
+
+stype_block_vr_t *stype_block_vr_new(void)
+{
+	stype_block_vr_t *block_vr;
+
+	block_vr = calloc(1, sizeof(stype_block_vr_t));
+	if (block_vr == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return block_vr;
+}
Index: uspace/app/sbi/src/stype.h
===================================================================
--- uspace/app/sbi/src/stype.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/stype.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef STYPE_H_
+#define STYPE_H_
+
+#include "mytypes.h"
+
+void stype_module(stype_t *stype, stree_module_t *module);
+void stype_stat(stype_t *stype, stree_stat_t *stat, bool_t want_value);
+
+void stype_note_error(stype_t *stype);
+tdata_item_t *stype_recovery_titem(stype_t *stype);
+
+stree_expr_t *stype_convert(stype_t *stype, stree_expr_t *expr,
+    tdata_item_t *dest);
+
+tdata_item_t *stype_boolean_titem(stype_t *stype);
+
+stree_vdecl_t *stype_local_vars_lookup(stype_t *stype, sid_t name);
+stree_proc_arg_t *stype_proc_args_lookup(stype_t *stype, sid_t name);
+stype_block_vr_t *stype_get_current_block_vr(stype_t *stype);
+
+stype_proc_vr_t *stype_proc_vr_new(void);
+stype_block_vr_t *stype_block_vr_new(void);
+
+#endif
Index: uspace/app/sbi/src/stype_expr.c
===================================================================
--- uspace/app/sbi/src/stype_expr.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/stype_expr.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1101 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Type expressions. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "debug.h"
+#include "list.h"
+#include "mytypes.h"
+#include "run_texpr.h"
+#include "stree.h"
+#include "strtab.h"
+#include "stype.h"
+#include "symbol.h"
+#include "tdata.h"
+
+#include "stype_expr.h"
+
+static void stype_nameref(stype_t *stype, stree_nameref_t *nameref,
+    tdata_item_t **rtitem);
+static void stype_literal(stype_t *stype, stree_literal_t *literal,
+    tdata_item_t **rtitem);
+static void stype_self_ref(stype_t *stype, stree_self_ref_t *self_ref,
+    tdata_item_t **rtitem);
+
+static void stype_binop(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem);
+
+static void stype_binop_tprimitive(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem);
+static void stype_binop_bool(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem);
+static void stype_binop_char(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem);
+static void stype_binop_int(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem);
+static void stype_binop_nil(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem);
+static void stype_binop_string(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem);
+static void stype_binop_resource(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem);
+
+static void stype_binop_tobject(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem);
+
+static void stype_unop(stype_t *stype, stree_unop_t *unop,
+    tdata_item_t **rtitem);
+static void stype_unop_tprimitive(stype_t *stype, stree_unop_t *unop,
+    tdata_item_t *ta, tdata_item_t **rtitem);
+static void stype_new(stype_t *stype, stree_new_t *new,
+    tdata_item_t **rtitem);
+
+static void stype_access(stype_t *stype, stree_access_t *access,
+    tdata_item_t **rtitem);
+static void stype_access_tprimitive(stype_t *stype, stree_access_t *access,
+    tdata_item_t *arg_ti, tdata_item_t **rtitem);
+static void stype_access_tobject(stype_t *stype, stree_access_t *access,
+    tdata_item_t *arg_ti, tdata_item_t **rtitem);
+static void stype_access_tarray(stype_t *stype, stree_access_t *access,
+    tdata_item_t *arg_ti, tdata_item_t **rtitem);
+
+static void stype_call(stype_t *stype, stree_call_t *call,
+    tdata_item_t **rtitem);
+
+static void stype_index(stype_t *stype, stree_index_t *index,
+    tdata_item_t **rtitem);
+static void stype_index_tprimitive(stype_t *stype, stree_index_t *index,
+    tdata_item_t *base_ti, tdata_item_t **rtitem);
+static void stype_index_tobject(stype_t *stype, stree_index_t *index,
+    tdata_item_t *base_ti, tdata_item_t **rtitem);
+static void stype_index_tarray(stype_t *stype, stree_index_t *index,
+    tdata_item_t *base_ti, tdata_item_t **rtitem);
+
+static void stype_assign(stype_t *stype, stree_assign_t *assign,
+    tdata_item_t **rtitem);
+static void stype_as(stype_t *stype, stree_as_t *as_op, tdata_item_t **rtitem);
+
+
+/** Type expression. */
+void stype_expr(stype_t *stype, stree_expr_t *expr)
+{
+	tdata_item_t *et;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type expression.\n");
+#endif
+	/* Silence warning. */
+	et = NULL;
+
+	switch (expr->ec) {
+	case ec_nameref: stype_nameref(stype, expr->u.nameref, &et); break;
+	case ec_literal: stype_literal(stype, expr->u.literal, &et); break;
+	case ec_self_ref: stype_self_ref(stype, expr->u.self_ref, &et); break;
+	case ec_binop: stype_binop(stype, expr->u.binop, &et); break;
+	case ec_unop: stype_unop(stype, expr->u.unop, &et); break;
+	case ec_new: stype_new(stype, expr->u.new_op, &et); break;
+	case ec_access: stype_access(stype, expr->u.access, &et); break;
+	case ec_call: stype_call(stype, expr->u.call, &et); break;
+	case ec_index: stype_index(stype, expr->u.index, &et); break;
+	case ec_assign: stype_assign(stype, expr->u.assign, &et); break;
+	case ec_as: stype_as(stype, expr->u.as_op, &et); break;
+	}
+
+	expr->titem = et;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Expression type is '");
+	tdata_item_print(et);
+	printf("'.\n");
+#endif
+}
+
+/** Type name reference. */
+static void stype_nameref(stype_t *stype, stree_nameref_t *nameref,
+    tdata_item_t **rtitem)
+{
+	stree_symbol_t *sym;
+	stree_vdecl_t *vdecl;
+	stree_proc_arg_t *proc_arg;
+	tdata_item_t *titem;
+	tdata_object_t *tobject;
+	stree_csi_t *csi;
+	stree_fun_t *fun;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Evaluate type of name reference '%s'.\n",
+	    strtab_get_str(nameref->name->sid));
+#endif
+	/*
+	 * Look for a local variable declaration.
+	 */
+
+	vdecl = stype_local_vars_lookup(stype, nameref->name->sid);
+	if (vdecl != NULL) {
+		/* Found a local variable declaration. */
+#ifdef DEBUG_RUN_TRACE
+		printf("Found local variable declaration.\n");
+#endif
+		run_texpr(stype->program, stype->current_csi, vdecl->type,
+		    &titem);
+		*rtitem = titem;
+		return;
+	}
+
+	/*
+	 * Look for a procedure argument.
+	 */
+
+	proc_arg = stype_proc_args_lookup(stype, nameref->name->sid);
+	if (proc_arg != NULL) {
+		/* Found a procedure argument. */
+#ifdef DEBUG_RUN_TRACE
+		printf("Found procedure argument.\n");
+#endif
+		run_texpr(stype->program, stype->current_csi, proc_arg->type,
+		    &titem);
+		*rtitem = titem;
+		return;
+	}
+
+	/*
+	 * Look for a class-wide or global symbol.
+	 */
+
+	sym = symbol_lookup_in_csi(stype->program, stype->current_csi,
+	    nameref->name);
+
+	if (sym == NULL) {
+		/* Not found. */
+		if (stype->current_csi != NULL) {
+			printf("Error: Symbol '%s' not found in '",
+			    strtab_get_str(nameref->name->sid));
+			symbol_print_fqn(csi_to_symbol(stype->current_csi));
+			printf("'.\n");
+		} else {
+			printf("Error: Symbol '%s' not found.\n",
+			    strtab_get_str(nameref->name->sid));
+		}
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+	switch (sym->sc) {
+	case sc_var:
+		run_texpr(stype->program, stype->current_csi,
+		    sym->u.var->type, &titem);
+		break;
+	case sc_prop:
+		run_texpr(stype->program, stype->current_csi,
+		    sym->u.prop->type, &titem);
+		break;
+	case sc_csi:
+		csi = symbol_to_csi(sym);
+		assert(csi != NULL);
+
+		titem = tdata_item_new(tic_tobject);
+		tobject = tdata_object_new();
+		titem->u.tobject = tobject;
+
+		/* This is a static CSI reference. */
+		tobject->static_ref = b_true;
+		tobject->csi = csi;
+		break;
+	case sc_fun:
+		fun = symbol_to_fun(sym);
+		assert(fun != NULL);
+
+		titem = tdata_item_new(tic_tfun);
+		titem->u.tfun = tdata_fun_new();
+		titem->u.tfun->fun = fun;
+		break;
+	}
+
+	*rtitem = titem;
+}
+
+/** Type a literal. */
+static void stype_literal(stype_t *stype, stree_literal_t *literal,
+    tdata_item_t **rtitem)
+{
+	tdata_item_t *titem;
+	tdata_primitive_t *tprimitive;
+	tprimitive_class_t tpc;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Evaluate type of literal.\n");
+#endif
+	(void) stype;
+
+	switch (literal->ltc) {
+	case ltc_bool: tpc = tpc_bool; break;
+	case ltc_char: tpc = tpc_char; break;
+	case ltc_int: tpc = tpc_int; break;
+	case ltc_ref: tpc = tpc_nil; break;
+	case ltc_string: tpc = tpc_string; break;
+	}
+
+	titem = tdata_item_new(tic_tprimitive);
+	tprimitive = tdata_primitive_new(tpc);
+	titem->u.tprimitive = tprimitive;
+
+	*rtitem = titem;
+}
+
+/** Type a self reference. */
+static void stype_self_ref(stype_t *stype, stree_self_ref_t *self_ref,
+    tdata_item_t **rtitem)
+{
+#ifdef DEBUG_TYPE_TRACE
+	printf("Evaluate type of self reference.\n");
+#endif
+	(void) stype;
+	(void) self_ref;
+
+	*rtitem = NULL;
+}
+
+/** Type a binary operation. */
+static void stype_binop(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem)
+{
+	bool_t equal;
+	tdata_item_t *titem1, *titem2;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Evaluate type of binary operation.\n");
+#endif
+	stype_expr(stype, binop->arg1);
+	stype_expr(stype, binop->arg2);
+
+	titem1 = binop->arg1->titem;
+	titem2 = binop->arg2->titem;
+
+	if (titem1 == NULL || titem2 == NULL) {
+		printf("Error: Binary operand has no value.\n");
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+	if (titem1->tic == tic_ignore || titem2->tic == tic_ignore) {
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+	equal = tdata_item_equal(titem1, titem2);
+	if (equal != b_true) {
+		printf("Error: Binary operation arguments "
+		    "have different types ('");
+		tdata_item_print(titem1);
+		printf("' and '");
+		tdata_item_print(titem2);
+		printf("').\n");
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+	switch (titem1->tic) {
+	case tic_tprimitive:
+		stype_binop_tprimitive(stype, binop, titem1, titem2, rtitem);
+		break;
+	case tic_tobject:
+		stype_binop_tobject(stype, binop, titem1, titem2, rtitem);
+		break;
+	default:
+		printf("Error: Binary operation on value which is not of a "
+		    "supported type (found '");
+		tdata_item_print(titem1);
+		printf("').\n");
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		break;
+	}
+
+}
+
+/** Type a binary operation with arguments of primitive type. */
+static void stype_binop_tprimitive(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem)
+{
+	assert(ta->tic == tic_tprimitive);
+	assert(tb->tic == tic_tprimitive);
+
+	switch (ta->u.tprimitive->tpc) {
+	case tpc_bool:
+		stype_binop_bool(stype, binop, rtitem);
+		break;
+	case tpc_char:
+		stype_binop_char(stype, binop, rtitem);
+		break;
+	case tpc_int:
+		stype_binop_int(stype, binop, rtitem);
+		break;
+	case tpc_nil:
+		stype_binop_nil(stype, binop, rtitem);
+		break;
+	case tpc_string:
+		stype_binop_string(stype, binop, rtitem);
+		break;
+	case tpc_resource:
+		stype_binop_resource(stype, binop, rtitem);
+		break;
+	}
+}
+
+/** Type a binary operation with bool arguments. */
+static void stype_binop_bool(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem)
+{
+	tprimitive_class_t rtpc;
+	tdata_item_t *res_ti;
+
+	switch (binop->bc) {
+	case bo_equal:
+	case bo_notequal:
+	case bo_lt:
+	case bo_gt:
+	case bo_lt_equal:
+	case bo_gt_equal:
+		/* Comparison -> boolean type */
+		rtpc = tpc_bool;
+		break;
+	case bo_plus:
+	case bo_minus:
+	case bo_mult:
+		/* Arithmetic -> error */
+		printf("Error: Binary operation (%d) on booleans.\n",
+		    binop->bc);
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+	res_ti = tdata_item_new(tic_tprimitive);
+	res_ti->u.tprimitive = tdata_primitive_new(rtpc);
+
+	*rtitem = res_ti;
+}
+
+/** Type a binary operation with char arguments. */
+static void stype_binop_char(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem)
+{
+	tprimitive_class_t rtpc;
+	tdata_item_t *res_ti;
+
+	(void) stype;
+
+	switch (binop->bc) {
+	case bo_equal:
+	case bo_notequal:
+	case bo_lt:
+	case bo_gt:
+	case bo_lt_equal:
+	case bo_gt_equal:
+		/* Comparison -> boolean type */
+		rtpc = tpc_bool;
+		break;
+	case bo_plus:
+	case bo_minus:
+	case bo_mult:
+		/* Arithmetic -> error */
+		printf("Error: Binary operation (%d) on characters.\n",
+		    binop->bc);
+		stype_note_error(stype);
+		rtpc = tpc_char;
+		break;
+	}
+
+	res_ti = tdata_item_new(tic_tprimitive);
+	res_ti->u.tprimitive = tdata_primitive_new(rtpc);
+
+	*rtitem = res_ti;
+}
+
+/** Type a binary operation with int arguments. */
+static void stype_binop_int(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem)
+{
+	tprimitive_class_t rtpc;
+	tdata_item_t *res_ti;
+
+	(void) stype;
+
+	switch (binop->bc) {
+	case bo_equal:
+	case bo_notequal:
+	case bo_lt:
+	case bo_gt:
+	case bo_lt_equal:
+	case bo_gt_equal:
+		/* Comparison -> boolean type */
+		rtpc = tpc_bool;
+		break;
+	case bo_plus:
+	case bo_minus:
+	case bo_mult:
+		/* Arithmetic -> int type */
+		rtpc = tpc_int;
+		break;
+	}
+
+	res_ti = tdata_item_new(tic_tprimitive);
+	res_ti->u.tprimitive = tdata_primitive_new(rtpc);
+
+	*rtitem = res_ti;
+}
+
+/** Type a binary operation with nil arguments. */
+static void stype_binop_nil(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem)
+{
+	(void) binop;
+
+	printf("Unimplemented; Binary operation on nil.\n");
+	stype_note_error(stype);
+	*rtitem = stype_recovery_titem(stype);
+}
+
+/** Type a binary operation with string arguments. */
+static void stype_binop_string(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem)
+{
+	tprimitive_class_t rtpc;
+	tdata_item_t *res_ti;
+
+	if (binop->bc != bo_plus) {
+		printf("Unimplemented: Binary operation(%d) "
+		    "on strings.\n", binop->bc);
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+	rtpc = tpc_string;
+
+	res_ti = tdata_item_new(tic_tprimitive);
+	res_ti->u.tprimitive = tdata_primitive_new(rtpc);
+
+	*rtitem = res_ti;
+}
+
+/** Type a binary operation with resource arguments. */
+static void stype_binop_resource(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t **rtitem)
+{
+	tprimitive_class_t rtpc;
+	tdata_item_t *res_ti;
+
+	(void) binop;
+
+	printf("Error: Cannot apply operator to resource type.\n");
+	stype_note_error(stype);
+	rtpc = tpc_resource;
+
+	res_ti = tdata_item_new(tic_tprimitive);
+	res_ti->u.tprimitive = tdata_primitive_new(rtpc);
+
+	*rtitem = res_ti;
+}
+
+/** Type a binary operation with arguments of an object type. */
+static void stype_binop_tobject(stype_t *stype, stree_binop_t *binop,
+    tdata_item_t *ta, tdata_item_t *tb, tdata_item_t **rtitem)
+{
+	tdata_item_t *res_ti;
+
+	(void) stype;
+
+	assert(ta->tic == tic_tobject || (ta->tic == tic_tprimitive &&
+	    ta->u.tprimitive->tpc == tpc_nil));
+	assert(tb->tic == tic_tobject || (tb->tic == tic_tprimitive &&
+	    tb->u.tprimitive->tpc == tpc_nil));
+
+	switch (binop->bc) {
+	case bo_equal:
+	case bo_notequal:
+		/* Comparing objects -> boolean type */
+		res_ti = stype_boolean_titem(stype);
+		break;
+	default:
+		printf("Error: Binary operation (%d) on objects.\n",
+		    binop->bc);
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+	*rtitem = res_ti;
+}
+
+
+/** Type a unary operation. */
+static void stype_unop(stype_t *stype, stree_unop_t *unop,
+    tdata_item_t **rtitem)
+{
+	tdata_item_t *titem;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Evaluate type of unary operation.\n");
+#endif
+	stype_expr(stype, unop->arg);
+
+	titem = unop->arg->titem;
+
+	if (titem->tic == tic_ignore) {
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+	switch (titem->tic) {
+	case tic_tprimitive:
+		stype_unop_tprimitive(stype, unop, titem, rtitem);
+		break;
+	default:
+		printf("Error: Unary operation on value which is not of a "
+		    "supported type (found '");
+		tdata_item_print(titem);
+		printf("').\n");
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		break;
+	}
+}
+
+/** Type a binary operation arguments of primitive type. */
+static void stype_unop_tprimitive(stype_t *stype, stree_unop_t *unop,
+    tdata_item_t *ta, tdata_item_t **rtitem)
+{
+	tprimitive_class_t rtpc;
+	tdata_item_t *res_ti;
+
+	(void) stype;
+	(void) unop;
+
+	assert(ta->tic == tic_tprimitive);
+
+	switch (ta->u.tprimitive->tpc) {
+	case tpc_bool:
+		rtpc = tpc_bool;
+		break;
+	case tpc_int:
+		rtpc = tpc_int;
+		break;
+	default:
+		printf("Error: Unary operator applied on unsupported "
+		    "primitive type %d.\n", ta->u.tprimitive->tpc);
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+	res_ti = tdata_item_new(tic_tprimitive);
+	res_ti->u.tprimitive = tdata_primitive_new(rtpc);
+
+	*rtitem = res_ti;
+}
+
+/** Type a @c new operation. */
+static void stype_new(stype_t *stype, stree_new_t *new_op,
+    tdata_item_t **rtitem)
+{
+#ifdef DEBUG_TYPE_TRACE
+	printf("Evaluate type of 'new' operation.\n");
+#endif
+	/*
+	 * Type of @c new expression is exactly the type supplied as parameter
+	 * to the @c new operator.
+	 */
+	run_texpr(stype->program, stype->current_csi, new_op->texpr, rtitem);
+
+	if ((*rtitem)->tic == tic_ignore) {
+		/* An error occured when evaluating the type expression. */
+		stype_note_error(stype);
+	}
+}
+
+/** Type a field access operation */
+static void stype_access(stype_t *stype, stree_access_t *access,
+    tdata_item_t **rtitem)
+{
+	tdata_item_t *arg_ti;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Evaluate type of access operation.\n");
+#endif
+	stype_expr(stype, access->arg);
+	arg_ti = access->arg->titem;
+
+	if (arg_ti == NULL) {
+		printf("Error: Argument of access has no value.\n");
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+	switch (arg_ti->tic) {
+	case tic_tprimitive:
+		stype_access_tprimitive(stype, access, arg_ti, rtitem);
+		break;
+	case tic_tobject:
+		stype_access_tobject(stype, access, arg_ti, rtitem);
+		break;
+	case tic_tarray:
+		stype_access_tarray(stype, access, arg_ti, rtitem);
+		break;
+	case tic_tfun:
+		printf("Error: Using '.' operator on a function.\n");
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		break;
+	case tic_ignore:
+		*rtitem = stype_recovery_titem(stype);
+		break;
+	}
+}
+
+/** Type a primitive type access operation. */
+static void stype_access_tprimitive(stype_t *stype, stree_access_t *access,
+    tdata_item_t *arg_ti, tdata_item_t **rtitem)
+{
+	(void) stype;
+	(void) access;
+	(void) rtitem;
+
+	printf("Error: Unimplemented: Accessing primitive type '");
+	tdata_item_print(arg_ti);
+	printf("'.\n");
+	stype_note_error(stype);
+	*rtitem = stype_recovery_titem(stype);
+}
+
+/** Type an object access operation. */
+static void stype_access_tobject(stype_t *stype, stree_access_t *access,
+    tdata_item_t *arg_ti, tdata_item_t **rtitem)
+{
+	stree_symbol_t *member_sym;
+	stree_var_t *var;
+	stree_fun_t *fun;
+	stree_prop_t *prop;
+	tdata_object_t *tobject;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Type a CSI access operation.\n");
+#endif
+	assert(arg_ti->tic == tic_tobject);
+	tobject = arg_ti->u.tobject;
+
+	/* Look for a member with the specified name. */
+	member_sym = symbol_search_csi(stype->program, tobject->csi,
+	    access->member_name);
+
+	if (member_sym == NULL) {
+		/* No such member found. */
+		printf("Error: CSI '");
+		symbol_print_fqn(csi_to_symbol(tobject->csi));
+		printf("' has no member named '%s'.\n",
+		    strtab_get_str(access->member_name->sid));
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Found member '%s'.\n",
+	    strtab_get_str(access->member_name->sid));
+#endif
+
+	switch (member_sym->sc) {
+	case sc_csi:
+		printf("Error: Accessing object member which is nested "
+		    "CSI.\n");
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		break;
+	case sc_fun:
+		fun = symbol_to_fun(member_sym);
+		assert(fun != NULL);
+		*rtitem = tdata_item_new(tic_tfun);
+		(*rtitem)->u.tfun = tdata_fun_new();
+		(*rtitem)->u.tfun->fun = fun;
+		break;
+	case sc_var:
+		var = symbol_to_var(member_sym);
+		assert(var != NULL);
+		/* XXX Memoize to avoid recomputing every time. */
+		run_texpr(stype->program, member_sym->outer_csi,
+		    var->type, rtitem);
+		break;
+	case sc_prop:
+		prop = symbol_to_prop(member_sym);
+		assert(prop != NULL);
+		/* XXX Memoize to avoid recomputing every time. */
+		run_texpr(stype->program, member_sym->outer_csi,
+		    prop->type, rtitem);
+		break;
+	}
+}
+
+/** Type an array access operation. */
+static void stype_access_tarray(stype_t *stype, stree_access_t *access,
+    tdata_item_t *arg_ti, tdata_item_t **rtitem)
+{
+	(void) stype;
+	(void) access;
+	(void) rtitem;
+
+	printf("Error: Unimplemented: Accessing array type '");
+	tdata_item_print(arg_ti);
+	printf("'.\n");
+	stype_note_error(stype);
+	*rtitem = stype_recovery_titem(stype);
+}
+
+/** Type a call operation. */
+static void stype_call(stype_t *stype, stree_call_t *call,
+    tdata_item_t **rtitem)
+{
+	list_node_t *farg_n;
+	stree_proc_arg_t *farg;
+	tdata_item_t *farg_ti;
+	tdata_item_t *varg_ti;
+
+	list_node_t *arg_n;
+	stree_expr_t *arg;
+	stree_expr_t *carg;
+
+	tdata_item_t *fun_ti;
+	stree_fun_t *fun;
+	stree_symbol_t *fun_sym;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Evaluate type of call operation.\n");
+#endif
+	/* Type the function */
+	stype_expr(stype, call->fun);
+
+	/* Check type item class */
+
+	fun_ti = call->fun->titem;
+	switch (fun_ti->tic) {
+	case tic_tfun:
+		/* The expected case */
+		break;
+	case tic_ignore:
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	default:
+		printf("Error: Calling something which is not a function ");
+		printf("(found '");
+		tdata_item_print(fun_ti);
+		printf("').\n");
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+	fun = fun_ti->u.tfun->fun;
+	fun_sym = fun_to_symbol(fun);
+
+	/* Type and check the arguments. */
+	farg_n = list_first(&fun->args);
+	arg_n = list_first(&call->args);
+	while (farg_n != NULL && arg_n != NULL) {
+		farg = list_node_data(farg_n, stree_proc_arg_t *);
+		arg = list_node_data(arg_n, stree_expr_t *);
+		stype_expr(stype, arg);
+
+		/* XXX Because of overloaded bultin WriteLine */
+		if (farg->type == NULL) {
+			/* Skip the check */
+			farg_n = list_next(&fun->args, farg_n);
+			arg_n = list_next(&call->args, arg_n);
+			continue;
+		}
+
+		/* XXX Memoize to avoid recomputing every time. */
+		run_texpr(stype->program, fun_sym->outer_csi, farg->type,
+		    &farg_ti);
+
+		/* Convert expression to type of formal argument. */
+		carg = stype_convert(stype, arg, farg_ti);
+
+		/* Patch code with augmented expression. */
+		list_node_setdata(arg_n, carg);
+
+		farg_n = list_next(&fun->args, farg_n);
+		arg_n = list_next(&call->args, arg_n);
+	}
+
+	/* Type and check variadic arguments. */
+	if (fun->varg != NULL) {
+		/* XXX Memoize to avoid recomputing every time. */
+		run_texpr(stype->program, fun_sym->outer_csi, fun->varg->type,
+		    &farg_ti);
+
+		/* Get array element type */
+		assert(farg_ti->tic == tic_tarray);
+		varg_ti = farg_ti->u.tarray->base_ti;
+
+		while (arg_n != NULL) {
+			arg = list_node_data(arg_n, stree_expr_t *);
+			stype_expr(stype, arg);
+
+			/* Convert expression to type of formal argument. */
+			carg = stype_convert(stype, arg, varg_ti);
+
+			/* Patch code with augmented expression. */
+			list_node_setdata(arg_n, carg);
+
+			arg_n = list_next(&call->args, arg_n);
+		}
+	}
+
+	if (farg_n != NULL) {
+		printf("Error: Too few arguments to function '");
+		symbol_print_fqn(fun_to_symbol(fun));
+		printf("'.\n");
+		stype_note_error(stype);
+	}
+
+	if (arg_n != NULL) {
+		printf("Error: Too many arguments to function '");
+		symbol_print_fqn(fun_to_symbol(fun));
+		printf("'.\n");
+		stype_note_error(stype);
+	}
+
+	if (fun->rtype != NULL) {
+		/* XXX Memoize to avoid recomputing every time. */
+		run_texpr(stype->program, fun_sym->outer_csi, fun->rtype,
+		    rtitem);
+	} else {
+		*rtitem = NULL;
+	}
+}
+
+/** Type an indexing operation. */
+static void stype_index(stype_t *stype, stree_index_t *index,
+    tdata_item_t **rtitem)
+{
+	tdata_item_t *base_ti;
+	list_node_t *arg_n;
+	stree_expr_t *arg;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Evaluate type of index operation.\n");
+#endif
+	stype_expr(stype, index->base);
+	base_ti = index->base->titem;
+
+	/* Type the arguments (indices). */
+	arg_n = list_first(&index->args);
+	while (arg_n != NULL) {
+		arg = list_node_data(arg_n, stree_expr_t *);
+		stype_expr(stype, arg);
+
+		arg_n = list_next(&index->args, arg_n);
+	}
+
+	switch (base_ti->tic) {
+	case tic_tprimitive:
+		stype_index_tprimitive(stype, index, base_ti, rtitem);
+		break;
+	case tic_tobject:
+		stype_index_tobject(stype, index, base_ti, rtitem);
+		break;
+	case tic_tarray:
+		stype_index_tarray(stype, index, base_ti, rtitem);
+		break;
+	case tic_tfun:
+		printf("Error: Indexing a function.\n");
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		break;
+	case tic_ignore:
+		*rtitem = stype_recovery_titem(stype);
+		break;
+	}
+}
+
+/** Type a primitive indexing operation. */
+static void stype_index_tprimitive(stype_t *stype, stree_index_t *index,
+    tdata_item_t *base_ti, tdata_item_t **rtitem)
+{
+	tdata_primitive_t *tprimitive;
+	tdata_item_t *titem;
+
+	(void) stype;
+	(void) index;
+
+	assert(base_ti->tic == tic_tprimitive);
+	tprimitive = base_ti->u.tprimitive;
+
+	if (tprimitive->tpc == tpc_string) {
+		titem = tdata_item_new(tic_tprimitive);
+		titem->u.tprimitive = tdata_primitive_new(tpc_char);
+		*rtitem = titem;
+		return;
+	}
+
+	printf("Error: Indexing primitive type '");
+	tdata_item_print(base_ti);
+	printf("'.\n");
+	stype_note_error(stype);
+	*rtitem = stype_recovery_titem(stype);
+}
+
+/** Type an object indexing operation. */
+static void stype_index_tobject(stype_t *stype, stree_index_t *index,
+    tdata_item_t *base_ti, tdata_item_t **rtitem)
+{
+	tdata_object_t *tobject;
+	stree_symbol_t *idx_sym;
+	stree_prop_t *idx;
+	stree_ident_t *idx_ident;
+
+	(void) index;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Indexing object type '");
+	tdata_item_print(base_ti);
+	printf("'.\n");
+#endif
+
+	assert(base_ti->tic == tic_tobject);
+	tobject = base_ti->u.tobject;
+
+	/* Find indexer symbol. */
+	idx_ident = stree_ident_new();
+	idx_ident->sid = strtab_get_sid(INDEXER_IDENT);
+	idx_sym = symbol_search_csi(stype->program, tobject->csi, idx_ident);
+
+	if (idx_sym == NULL) {
+		printf("Error: Indexing object of type '");
+		tdata_item_print(base_ti);
+		printf("' which does not have an indexer.\n");
+		stype_note_error(stype);
+		*rtitem = stype_recovery_titem(stype);
+		return;
+	}
+
+	idx = symbol_to_prop(idx_sym);
+	assert(idx != NULL);
+
+	/* XXX Memoize to avoid recomputing every time. */
+	run_texpr(stype->program, idx_sym->outer_csi, idx->type, rtitem);
+}
+
+/** Type an array indexing operation. */
+static void stype_index_tarray(stype_t *stype, stree_index_t *index,
+    tdata_item_t *base_ti, tdata_item_t **rtitem)
+{
+	list_node_t *arg_n;
+	stree_expr_t *arg;
+	int arg_count;
+
+	(void) stype;
+	assert(base_ti->tic == tic_tarray);
+
+	/*
+	 * Check that type of all indices is @c int and that the number of
+	 * indices matches array rank.
+	 */
+	arg_count = 0;
+	arg_n = list_first(&index->args);
+	while (arg_n != NULL) {
+		++arg_count;
+
+		arg = list_node_data(arg_n, stree_expr_t *);
+		if (arg->titem->tic != tic_tprimitive ||
+		    arg->titem->u.tprimitive->tpc != tpc_int) {
+
+			printf("Error: Array index is not an integer.\n");
+			stype_note_error(stype);
+		}
+
+		arg_n = list_next(&index->args, arg_n);
+	}
+
+	if (arg_count != base_ti->u.tarray->rank) {
+		printf("Error: Using %d indices with array of rank %d.\n",
+		    arg_count, base_ti->u.tarray->rank);
+		stype_note_error(stype);
+	}
+
+	*rtitem = base_ti->u.tarray->base_ti;
+}
+
+/** Type an assignment. */
+static void stype_assign(stype_t *stype, stree_assign_t *assign,
+    tdata_item_t **rtitem)
+{
+	stree_expr_t *csrc;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Evaluate type of assignment.\n");
+#endif
+	stype_expr(stype, assign->dest);
+	stype_expr(stype, assign->src);
+
+	csrc = stype_convert(stype, assign->src, assign->dest->titem);
+
+	/* Patch code with the augmented expression. */
+	assign->src = csrc;
+	*rtitem = NULL;
+}
+
+/** Type @c as conversion. */
+static void stype_as(stype_t *stype, stree_as_t *as_op, tdata_item_t **rtitem)
+{
+	tdata_item_t *titem;
+
+#ifdef DEBUG_TYPE_TRACE
+	printf("Evaluate type of @c as conversion.\n");
+#endif
+	stype_expr(stype, as_op->arg);
+	run_texpr(stype->program, stype->current_csi, as_op->dtype, &titem);
+
+	/* Check that target type is derived from argument type. */
+	if (tdata_is_ti_derived_from_ti(titem, as_op->arg->titem) != b_true) {
+		printf("Error: Target of 'as' operator '");
+		tdata_item_print(titem);
+		printf("' is not derived from '");
+		tdata_item_print(as_op->arg->titem);
+		printf("'.\n");
+		stype_note_error(stype);
+	}
+
+	*rtitem = titem;
+}
Index: uspace/app/sbi/src/stype_expr.h
===================================================================
--- uspace/app/sbi/src/stype_expr.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/stype_expr.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef STYPE_EXPR_H_
+#define STYPE_EXPR_H_
+
+#include "mytypes.h"
+
+void stype_expr(stype_t *stype, stree_expr_t *expr);
+
+#endif
Index: uspace/app/sbi/src/stype_t.h
===================================================================
--- uspace/app/sbi/src/stype_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/stype_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef STYPE_T_H_
+#define STYPE_T_H_
+
+/** Block visit record
+ *
+ * One block VR is created for each block that we enter. A variable declaration
+ * statement inserts the variable declaration here. Upon leaving the block we
+ * pop from the stack, thus all the variable declarations from that block
+ * are forgotten.
+ */
+typedef struct run_block_vr {
+	/** Variable declarations in this block */
+	intmap_t vdecls; /* of stree_vdecl_t */
+} stype_block_vr_t;
+
+/** Procedure visit record
+ *
+ * A procedure can be a member function or a property getter or setter. A
+ * procedure visit record is created whenever @c stype (the static typing
+ * pass) enters a procedure.
+ */
+typedef struct run_proc_vr {
+	/** Definition of function or property being invoked */
+	struct stree_proc *proc;
+
+	/** Block activation records */
+	list_t block_vr; /* of run_block_ar_t */
+} stype_proc_vr_t;
+
+/** Static typer state object */
+typedef struct stype {
+	/** Code of the program being typed */
+	struct stree_program *program;
+
+	/**
+	 * CSI context in which we are currently typing. We keep an implicit
+	 * stack of these (in instances of local variable
+	 * @c stype_csi::prev_ctx.)
+	 */
+	struct stree_csi *current_csi;
+
+	/** Procedure VR for the current procedure. */
+	stype_proc_vr_t *proc_vr;
+
+	/** @c b_true if an error occured. */
+	bool_t error;
+} stype_t;
+
+#endif
Index: uspace/app/sbi/src/symbol.c
===================================================================
--- uspace/app/sbi/src/symbol.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/symbol.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,353 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Symbols. */
+
+#include <stdlib.h>
+#include <assert.h>
+#include "list.h"
+#include "mytypes.h"
+#include "strtab.h"
+#include "stree.h"
+
+#include "symbol.h"
+
+static stree_symbol_t *symbol_search_global(stree_program_t *prog,
+    stree_ident_t *name);
+static stree_symbol_t *symbol_find_epoint_rec(stree_program_t *prog,
+    stree_ident_t *name, stree_csi_t *csi);
+static stree_ident_t *symbol_get_ident(stree_symbol_t *symbol);
+
+/** Lookup symbol in CSI using a type expression. */
+stree_symbol_t *symbol_xlookup_in_csi(stree_program_t *prog,
+    stree_csi_t *scope, stree_texpr_t *texpr)
+{
+	stree_symbol_t *a, *b;
+	stree_csi_t *a_csi;
+
+	switch (texpr->tc) {
+	case tc_tnameref:
+		return symbol_lookup_in_csi(prog, scope, texpr->u.tnameref->name);
+	case tc_taccess:
+		a = symbol_xlookup_in_csi(prog, scope, texpr->u.taccess->arg);
+		a_csi = symbol_to_csi(a);
+		if (a_csi == NULL) {
+			printf("Error: Symbol is not CSI.\n");
+			exit(1);
+		}
+		b = symbol_search_csi(prog, a_csi, texpr->u.taccess->member_name);
+		if (b == NULL) {
+			printf("Error: CSI '%s' not found\n", strtab_get_str(texpr->u.taccess->member_name->sid));
+			exit(1);
+		}
+		return b;
+	case tc_tapply:
+		return symbol_xlookup_in_csi(prog, scope,
+		    texpr->u.tapply->gtype);
+	default:
+		assert(b_false);
+	}
+}
+
+/** Lookup symbol reference in CSI.
+ *
+ * @param prog	Program to look in.
+ * @param scope CSI in @a prog which is the base for references.
+ * @param name	Identifier of the symbol.
+ *
+ * @return	Symbol or @c NULL if symbol not found.
+ */
+stree_symbol_t *symbol_lookup_in_csi(stree_program_t *prog, stree_csi_t *scope,
+	stree_ident_t *name)
+{
+	stree_symbol_t *symbol;
+
+	/* This CSI node should have been processed. */
+	assert(scope == NULL || scope->ancr_state == ws_visited);
+
+	symbol = NULL;
+	while (scope != NULL && symbol == NULL) {
+		symbol = symbol_search_csi(prog, scope, name);
+		scope = csi_to_symbol(scope)->outer_csi;
+	}
+
+	if (symbol == NULL)
+		symbol = symbol_search_global(prog, name);
+
+	return symbol;
+}
+
+/** Look for symbol strictly in CSI.
+ *
+ * Look for symbol in definition of a CSI and its ancestors. (But not
+ * in lexically enclosing CSI.)
+ */
+stree_symbol_t *symbol_search_csi(stree_program_t *prog,
+    stree_csi_t *scope, stree_ident_t *name)
+{
+	list_node_t *node;
+	stree_csimbr_t *csimbr;
+	stree_symbol_t *symbol;
+	stree_ident_t *mbr_name;
+	stree_symbol_t *base_csi_sym;
+	stree_csi_t *base_csi;
+
+	(void) prog;
+
+	/* Look in new members in this class. */
+
+	node = list_first(&scope->members);
+	while (node != NULL) {
+		csimbr = list_node_data(node, stree_csimbr_t *);
+		switch (csimbr->cc) {
+		case csimbr_csi: mbr_name = csimbr->u.csi->name; break;
+		case csimbr_fun: mbr_name = csimbr->u.fun->name; break;
+		case csimbr_var: mbr_name = csimbr->u.var->name; break;
+		case csimbr_prop: mbr_name = csimbr->u.prop->name; break;
+		default: assert(b_false);
+		}
+
+		if (name->sid == mbr_name->sid) {
+			/* Match */
+			switch (csimbr->cc) {
+			case csimbr_csi:
+				symbol = csi_to_symbol(csimbr->u.csi);
+				break;
+			case csimbr_fun:
+				symbol = fun_to_symbol(csimbr->u.fun);
+				break;
+			case csimbr_var:
+				symbol = var_to_symbol(csimbr->u.var);
+				break;
+			case csimbr_prop:
+				symbol = prop_to_symbol(csimbr->u.prop);
+				break;
+			default:
+				assert(b_false);
+			}
+			return symbol;
+		}
+		node = list_next(&scope->members, node);
+	}
+
+	/* Try inherited members. */
+	if (scope->base_csi_ref != NULL) {
+		base_csi_sym = symbol_xlookup_in_csi(prog,
+		    csi_to_symbol(scope)->outer_csi, scope->base_csi_ref);
+		base_csi = symbol_to_csi(base_csi_sym);
+		assert(base_csi != NULL);
+
+		return symbol_search_csi(prog, base_csi, name);
+	}
+
+	/* No match */
+	return NULL;
+}
+
+static stree_symbol_t *symbol_search_global(stree_program_t *prog,
+    stree_ident_t *name)
+{
+	list_node_t *node;
+	stree_modm_t *modm;
+	stree_symbol_t *symbol;
+
+	node = list_first(&prog->module->members);
+	while (node != NULL) {
+		modm = list_node_data(node, stree_modm_t *);
+		if (name->sid == modm->u.csi->name->sid) {
+			/* Match */
+			switch (modm->mc) {
+			case mc_csi:
+				symbol = csi_to_symbol(modm->u.csi);
+				break;
+			default:
+				assert(b_false);
+			}
+			return symbol;
+		}
+		node = list_next(&prog->module->members, node);
+	}
+
+	return NULL;
+}
+
+/** Find entry point. */
+stree_symbol_t *symbol_find_epoint(stree_program_t *prog, stree_ident_t *name)
+{
+	list_node_t *node;
+	stree_modm_t *modm;
+	stree_symbol_t *entry, *etmp;
+
+	entry = NULL;
+
+	node = list_first(&prog->module->members);
+	while (node != NULL) {
+		modm = list_node_data(node, stree_modm_t *);
+		if (modm->mc == mc_csi) {
+			etmp = symbol_find_epoint_rec(prog, name, modm->u.csi);
+			if (etmp != NULL) {
+				if (entry != NULL) {
+					printf("Error: Duplicate entry point.\n");
+					exit(1);
+				}
+				entry = etmp;
+			}
+		}
+	    	node = list_next(&prog->module->members, node);
+	}
+
+	return entry;
+}
+
+static stree_symbol_t *symbol_find_epoint_rec(stree_program_t *prog,
+    stree_ident_t *name, stree_csi_t *csi)
+{
+	list_node_t *node;
+	stree_csimbr_t *csimbr;
+	stree_symbol_t *entry, *etmp;
+
+	entry = NULL;
+
+	node = list_first(&csi->members);
+	while (node != NULL) {
+		csimbr = list_node_data(node, stree_csimbr_t *);
+
+		switch (csimbr->cc) {
+		case csimbr_csi:
+			etmp = symbol_find_epoint_rec(prog, name, csimbr->u.csi);
+			if (etmp != NULL) {
+				if (entry != NULL) {
+					printf("Error: Duplicate entry point.\n");
+					exit(1);
+				}
+				entry = etmp;
+			}
+			break;
+		case csimbr_fun:
+			if (csimbr->u.fun->name->sid == name->sid) {
+				if (entry != NULL) {
+					printf("Error: Duplicate entry point.\n");
+					exit(1);
+				}
+				entry = fun_to_symbol(csimbr->u.fun);
+			}
+		default:
+			break;
+		}
+
+	    	node = list_next(&csi->members, node);
+	}
+
+	return entry;
+}
+
+stree_csi_t *symbol_to_csi(stree_symbol_t *symbol)
+{
+	if (symbol->sc != sc_csi)
+		return NULL;
+
+	return symbol->u.csi;
+}
+
+stree_symbol_t *csi_to_symbol(stree_csi_t *csi)
+{
+	assert(csi->symbol);
+	return csi->symbol;
+}
+
+stree_fun_t *symbol_to_fun(stree_symbol_t *symbol)
+{
+	if (symbol->sc != sc_fun)
+		return NULL;
+
+	return symbol->u.fun;
+}
+
+stree_symbol_t *fun_to_symbol(stree_fun_t *fun)
+{
+	assert(fun->symbol);
+	return fun->symbol;
+}
+
+stree_var_t *symbol_to_var(stree_symbol_t *symbol)
+{
+	if (symbol->sc != sc_var)
+		return NULL;
+
+	return symbol->u.var;
+}
+
+stree_symbol_t *var_to_symbol(stree_var_t *var)
+{
+	assert(var->symbol);
+	return var->symbol;
+}
+
+stree_prop_t *symbol_to_prop(stree_symbol_t *symbol)
+{
+	if (symbol->sc != sc_prop)
+		return NULL;
+
+	return symbol->u.prop;
+}
+
+stree_symbol_t *prop_to_symbol(stree_prop_t *prop)
+{
+	assert(prop->symbol);
+	return prop->symbol;
+}
+
+/** Print fully qualified name of symbol. */
+void symbol_print_fqn(stree_symbol_t *symbol)
+{
+	stree_ident_t *name;
+	stree_symbol_t *outer_sym;
+
+	if (symbol->outer_csi != NULL) {
+		outer_sym = csi_to_symbol(symbol->outer_csi);
+		symbol_print_fqn(outer_sym);
+		printf(".");
+	}
+
+	name = symbol_get_ident(symbol);
+	printf("%s", strtab_get_str(name->sid));
+}
+
+static stree_ident_t *symbol_get_ident(stree_symbol_t *symbol)
+{
+	stree_ident_t *ident;
+
+	switch (symbol->sc) {
+	case sc_csi: ident = symbol->u.csi->name; break;
+	case sc_fun: ident = symbol->u.fun->name; break;
+	case sc_var: ident = symbol->u.var->name; break;
+	case sc_prop: ident = symbol->u.prop->name; break;
+	}
+
+	return ident;
+}
Index: uspace/app/sbi/src/symbol.h
===================================================================
--- uspace/app/sbi/src/symbol.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/symbol.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef SYMBOL_H_
+#define SYMBOL_H_
+
+#include "mytypes.h"
+
+stree_symbol_t *symbol_xlookup_in_csi(stree_program_t *prog,
+    stree_csi_t *scope, stree_texpr_t *texpr);
+stree_symbol_t *symbol_lookup_in_csi(stree_program_t *prog, stree_csi_t *scope,
+    stree_ident_t *name);
+stree_symbol_t *symbol_search_csi(stree_program_t *prog, stree_csi_t *scope,
+    stree_ident_t *name);
+stree_symbol_t *symbol_find_epoint(stree_program_t *prog, stree_ident_t *name);
+
+stree_csi_t *symbol_to_csi(stree_symbol_t *symbol);
+stree_symbol_t *csi_to_symbol(stree_csi_t *csi);
+stree_fun_t *symbol_to_fun(stree_symbol_t *symbol);
+stree_symbol_t *fun_to_symbol(stree_fun_t *fun);
+stree_var_t *symbol_to_var(stree_symbol_t *symbol);
+stree_symbol_t *var_to_symbol(stree_var_t *var);
+stree_prop_t *symbol_to_prop(stree_symbol_t *symbol);
+stree_symbol_t *prop_to_symbol(stree_prop_t *prop);
+
+void symbol_print_fqn(stree_symbol_t *symbol);
+
+#endif
Index: uspace/app/sbi/src/tdata.c
===================================================================
--- uspace/app/sbi/src/tdata.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/tdata.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Run-time data representation. */
+
+#include <stdlib.h>
+#include <assert.h>
+#include "list.h"
+#include "mytypes.h"
+#include "stree.h"
+#include "symbol.h"
+
+#include "tdata.h"
+
+static void tdata_tprimitive_print(tdata_primitive_t *tprimitive);
+static void tdata_tobject_print(tdata_object_t *tobject);
+static void tdata_tarray_print(tdata_array_t *tarray);
+static void tdata_tfun_print(tdata_fun_t *tfun);
+
+/** Determine if CSI @a a is derived from CSI described by type item @a tb. */
+bool_t tdata_is_csi_derived_from_ti(stree_csi_t *a, tdata_item_t *tb)
+{
+	bool_t res;
+
+	switch (tb->tic) {
+	case tic_tobject:
+		res = stree_is_csi_derived_from_csi(a, tb->u.tobject->csi);
+		break;
+	default:
+		printf("Error: Base type is not a CSI.\n");
+		exit(1);
+	}
+
+	return res;
+}
+
+/**
+ * Determine if CSI described by type item @a a is derived from CSI described
+ * by type item @a tb.
+ */
+bool_t tdata_is_ti_derived_from_ti(tdata_item_t *ta, tdata_item_t *tb)
+{
+	bool_t res;
+
+	switch (ta->tic) {
+	case tic_tobject:
+		res = tdata_is_csi_derived_from_ti(ta->u.tobject->csi, tb);
+		break;
+	default:
+		printf("Error: Derived type is not a CSI.\n");
+		exit(1);
+	}
+
+	return res;
+}
+
+/** Determine if two type items are equal (i.e. describe the same type). */
+bool_t tdata_item_equal(tdata_item_t *a, tdata_item_t *b)
+{
+	/*
+	 * Special case: Nil vs. object
+	 *
+	 * XXX Type of @c Nil should probably be @c object to avoid this
+	 * madness.
+	 */
+	if (a->tic == tic_tprimitive && a->u.tprimitive->tpc == tpc_nil) {
+		if (b->tic == tic_tobject)
+			return b_true;
+	} else if (b->tic == tic_tprimitive && b->u.tprimitive->tpc == tpc_nil) {
+		if (a->tic == tic_tobject)
+			return b_true;
+	}
+
+	if (a->tic != b->tic)
+		return b_false;
+
+	switch (a->tic) {
+	case tic_tprimitive:
+		/* Check if both have the same tprimitive class. */
+		return (a->u.tprimitive->tpc == b->u.tprimitive->tpc);
+	case tic_tobject:
+		/* Check if both use the same CSI definition. */
+		return (a->u.tobject->csi == b->u.tobject->csi);
+	case tic_tarray:
+		/* Compare rank and base type. */
+		if (a->u.tarray->rank != b->u.tarray->rank)
+			return b_false;
+
+		return tdata_item_equal(a->u.tarray->base_ti,
+		    b->u.tarray->base_ti);
+	default:
+		printf("Warning: Unimplemented: Compare types '");
+		tdata_item_print(a);
+		printf("' and '");
+		tdata_item_print(b);
+		printf("'.\n");
+		return b_true;
+	}
+}
+
+/** Print type item. */
+void tdata_item_print(tdata_item_t *titem)
+{
+	if (titem == NULL) {
+		printf("none");
+		return;
+	}
+
+	switch (titem->tic) {
+	case tic_tprimitive:
+		tdata_tprimitive_print(titem->u.tprimitive);
+		break;
+	case tic_tobject:
+		tdata_tobject_print(titem->u.tobject);
+		break;
+	case tic_tarray:
+		tdata_tarray_print(titem->u.tarray);
+		break;
+	case tic_tfun:
+		tdata_tfun_print(titem->u.tfun);
+		break;
+	case tic_ignore:
+		printf("ignore");
+		break;
+	}
+}
+
+static void tdata_tprimitive_print(tdata_primitive_t *tprimitive)
+{
+	switch (tprimitive->tpc) {
+	case tpc_bool: printf("bool"); break;
+	case tpc_char: printf("char"); break;
+	case tpc_int: printf("int"); break;
+	case tpc_nil: printf("nil"); break;
+	case tpc_string: printf("string"); break;
+	case tpc_resource: printf("resource"); break;
+	}
+}
+
+static void tdata_tobject_print(tdata_object_t *tobject)
+{
+	stree_symbol_t *csi_sym;
+	list_node_t *arg_n;
+	tdata_item_t *arg;
+
+	csi_sym = csi_to_symbol(tobject->csi);
+	assert(csi_sym != NULL);
+	symbol_print_fqn(csi_sym);
+
+	arg_n = list_first(&tobject->targs);
+	while (arg_n != NULL) {
+		arg = list_node_data(arg_n, tdata_item_t *);
+		putchar('/');
+		tdata_item_print(arg);
+		arg_n = list_next(&tobject->targs, arg_n);
+	}
+}
+
+static void tdata_tarray_print(tdata_array_t *tarray)
+{
+	int i;
+
+	tdata_item_print(tarray->base_ti);
+
+	printf("[");
+	for (i = 0; i < tarray->rank - 1; ++i)
+		printf(",");
+	printf("]");
+}
+
+static void tdata_tfun_print(tdata_fun_t *tfun)
+{
+	(void) tfun;
+	printf("unimplemented(fun)");
+}
+
+tdata_item_t *tdata_item_new(titem_class_t tic)
+{
+	tdata_item_t *titem;
+
+	titem = calloc(1, sizeof(tdata_item_t));
+	if (titem == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	titem->tic = tic;
+	return titem;
+}
+
+tdata_array_t *tdata_array_new(void)
+{
+	tdata_array_t *tarray;
+
+	tarray = calloc(1, sizeof(tdata_array_t));
+	if (tarray == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return tarray;
+}
+
+tdata_object_t *tdata_object_new(void)
+{
+	tdata_object_t *tobject;
+
+	tobject = calloc(1, sizeof(tdata_object_t));
+	if (tobject == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return tobject;
+}
+
+tdata_primitive_t *tdata_primitive_new(tprimitive_class_t tpc)
+{
+	tdata_primitive_t *tprimitive;
+
+	tprimitive = calloc(1, sizeof(tdata_primitive_t));
+	if (tprimitive == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	tprimitive->tpc = tpc;
+	return tprimitive;
+}
+
+tdata_fun_t *tdata_fun_new(void)
+{
+	tdata_fun_t *tfun;
+
+	tfun = calloc(1, sizeof(tdata_fun_t));
+	if (tfun == NULL) {
+		printf("Memory allocation failed.\n");
+		exit(1);
+	}
+
+	return tfun;
+}
Index: uspace/app/sbi/src/tdata.h
===================================================================
--- uspace/app/sbi/src/tdata.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/tdata.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#ifndef TDATA_H_
+#define TDATA_H_
+
+#include "mytypes.h"
+
+tdata_item_t *tdata_item_new(titem_class_t tic);
+tdata_array_t *tdata_array_new(void);
+tdata_object_t *tdata_object_new(void);
+tdata_primitive_t *tdata_primitive_new(tprimitive_class_t tpc);
+tdata_fun_t *tdata_fun_new(void);
+
+bool_t tdata_is_csi_derived_from_ti(stree_csi_t *a, tdata_item_t *tb);
+bool_t tdata_is_ti_derived_from_ti(tdata_item_t *ta, tdata_item_t *tb);
+bool_t tdata_item_equal(tdata_item_t *a, tdata_item_t *b);
+void tdata_item_print(tdata_item_t *titem);
+
+#endif
Index: uspace/app/sbi/src/tdata_t.h
===================================================================
--- uspace/app/sbi/src/tdata_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/app/sbi/src/tdata_t.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+/** @file Static type system representation. */
+
+#ifndef TDATA_T_H_
+#define TDATA_T_H_
+
+/** Class of primitive type. */
+typedef enum {
+	/** Boolean type */
+	tpc_bool,
+	/** Character type */
+	tpc_char,
+	/** Integer type */
+	tpc_int,
+	/** Special type for nil reference */
+	tpc_nil,
+	/** String type */
+	tpc_string,
+	/** Resource type */
+	tpc_resource
+} tprimitive_class_t;
+
+/** Primitive type. */
+typedef struct {
+	/** Class of primitive type */
+	tprimitive_class_t tpc;
+} tdata_primitive_t;
+
+/** Object type. */
+typedef struct {
+	/** @c true if expression is a static CSI reference */
+	bool_t static_ref;
+
+	/** CSI definition */
+	struct stree_csi *csi;
+
+	/** (Real) type arguments */
+	list_t targs; /* of tdata_item_t */
+} tdata_object_t;
+
+/** Array type. */
+typedef struct {
+	/** Base type item */
+	struct tdata_item *base_ti;
+
+	/** Rank */
+	int rank;
+
+	/** Extents */
+	list_t extents; /* of stree_expr_t */
+} tdata_array_t;
+
+/** Functional type. */
+typedef struct {
+	/**
+	 * Function definition. We'll leave expansion to the call operation.
+	 */
+	struct stree_fun *fun;
+} tdata_fun_t;
+
+typedef enum {
+	/** Primitive type item */
+	tic_tprimitive,
+	/** Object type item */
+	tic_tobject,
+	/** Array type item */
+	tic_tarray,
+	/** Function type item */
+	tic_tfun,
+	/** Special error-recovery type item */
+	tic_ignore
+} titem_class_t;
+
+/** Type item, the result of evaluating a type expression. */
+typedef struct tdata_item {
+	titem_class_t tic;
+
+	union {
+		tdata_primitive_t *tprimitive;
+		tdata_object_t *tobject;
+		tdata_array_t *tarray;
+		tdata_fun_t *tfun;
+	} u;
+} tdata_item_t;
+
+#endif
Index: uspace/app/trace/syscalls.c
===================================================================
--- uspace/app/trace/syscalls.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/app/trace/syscalls.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -75,6 +75,9 @@
     [SYS_PREEMPT_CONTROL] = { "preempt_control",	1,	V_ERRNO },
 
-    [SYS_SYSINFO_VALID] = { "sysinfo_valid",		2,	V_HASH },
-    [SYS_SYSINFO_VALUE] = { "sysinfo_value",		2,	V_HASH },
+    [SYS_SYSINFO_GET_TAG] = { "sysinfo_get_tag",		2,	V_INTEGER },
+    [SYS_SYSINFO_GET_VALUE] = { "sysinfo_get_value",		3,	V_ERRNO },
+    [SYS_SYSINFO_GET_DATA_SIZE] = { "sysinfo_get_data_size",	3,	V_ERRNO },
+    [SYS_SYSINFO_GET_DATA] = { "sysinfo_get_data",		4,	V_ERRNO },
+
     [SYS_DEBUG_ENABLE_CONSOLE] = { "debug_enable_console", 0,	V_ERRNO },
     [SYS_IPC_CONNECT_KBOX] = { "ipc_connect_kbox",	1,	V_ERRNO }
Index: uspace/dist/src/sysel/demos/arith.sy
===================================================================
--- uspace/dist/src/sysel/demos/arith.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/demos/arith.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,101 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+class ArithmeticDemo is
+	fun Main() is
+		-- Test addition, multiplication and precedence.
+		Builtin.WriteLine("2*2 + 2*2 =");
+		Builtin.WriteLine(2*2 + 2*2);
+		Builtin.WriteLine("(expected: 8)");
+
+		-- Test subtraction, multiplication and precedence.
+		Builtin.WriteLine("1111 - 1 - 10 - 10*10 - 10*10*10 =");
+		Builtin.WriteLine(1111 - 1 - 10 - 10*10 - 10*10*10);
+		Builtin.WriteLine("(expected: 0)");
+
+		-- Test parenthesized sub-expressions.
+		Builtin.WriteLine("10 * (1 - 1) =");
+		Builtin.WriteLine(10 * (1 - 1));
+		Builtin.WriteLine("(expected: 0)");
+
+		-- Test unary plus and minus.
+		Builtin.WriteLine("(+1) - (-1) - (+(+1)) + (+(-1)) = ");
+		Builtin.WriteLine((+1) - (-1) - (+(+1)) + (+(-1)));
+		Builtin.WriteLine("(expected: 0)");
+
+		-- Test signed multiplication.
+		Builtin.WriteLine("+1 * +1 = ");
+		Builtin.WriteLine(+1 * +1);
+		Builtin.WriteLine("(expected: 1)");
+		Builtin.WriteLine("-1 * -1 = ");
+		Builtin.WriteLine(-1 * -1);
+		Builtin.WriteLine("(expected: 1)");
+		Builtin.WriteLine("+1 * -1 = ");
+		Builtin.WriteLine(+1 * -1);
+		Builtin.WriteLine("(expected: -1)");
+		Builtin.WriteLine("-1 * +1 = ");
+		Builtin.WriteLine(-1 * +1);
+		Builtin.WriteLine("(expected: -1)");
+
+		-- Test multiplication with large result.
+		Builtin.WriteLine("1000000 * 1000000 * 1000000 * 1000000 =");
+		Builtin.WriteLine(1000000 * 1000000 * 1000000 * 1000000);
+		Builtin.WriteLine("(expected: 1000000000000000000000000)");
+
+		-- Test large literals.
+		Builtin.WriteLine("1000000000000000000000000 =");
+		Builtin.WriteLine(1000000000000000000000000);
+		Builtin.WriteLine("(expected: 1000000000000000000000000)");
+
+		-- Test large factorials.
+		var n : int;
+
+		Builtin.WriteLine("Factorials:");
+		n = 1;
+		while n <= 40 do
+			Builtin.WriteLine(Factorial(n));
+			n = n + 1;
+		end
+	end
+
+	-- Return factorial of n.
+	fun Factorial(n : int) : int is
+		var i : int;
+		var val : int;
+
+		i = 1;
+		val = 1;
+
+		while i <= n do
+			val = val * i;
+			i = i + 1;
+		end
+
+		return val;
+	end
+end
Index: uspace/dist/src/sysel/demos/array.sy
===================================================================
--- uspace/dist/src/sysel/demos/array.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/demos/array.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,46 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+class ArrayDemo is
+	fun Main() is
+		var a : int[,];
+		var i : int;
+
+		a = new int[3, 2];
+
+		a[0, 0] = 1;
+		a[1, 0] = 2;
+		a[2, 0] = 3;
+
+		i = 0;
+		while i < 3 do
+			Builtin.WriteLine(a[i, 0]);
+			i = i + 1;
+		end
+	end
+end
Index: uspace/dist/src/sysel/demos/count.sy
===================================================================
--- uspace/dist/src/sysel/demos/count.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/demos/count.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,44 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+class CountDemo is
+	fun Count(a : int; b : int) is
+		var i : int;
+
+		i = a;
+		while i < b do
+			Builtin.WriteLine(i);
+			i = i + 1;
+		end
+
+	end
+
+	fun Main() is
+		Count(0, 10);
+	end
+end
Index: uspace/dist/src/sysel/demos/except.sy
===================================================================
--- uspace/dist/src/sysel/demos/except.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/demos/except.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,53 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+class ExceptionDemo is
+	fun foo() is
+	        Builtin.WriteLine("Entered foo().");
+		raise new BaseException();
+	end
+
+	fun Main() is
+		do
+			foo();
+			foo();
+		except e : DerivedException do
+			Builtin.WriteLine("Caught derived exception.");
+		except e : BaseException do
+			Builtin.WriteLine("Caught base exception.");
+		finally do
+			Builtin.WriteLine("Finally.");
+		end
+	end
+end
+
+class BaseException is
+end
+
+class DerivedException : BaseException is
+end
Index: uspace/dist/src/sysel/demos/hello.sy
===================================================================
--- uspace/dist/src/sysel/demos/hello.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/demos/hello.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,33 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+class HelloWorld is
+	fun Main() is
+		Builtin.WriteLine("Hello world!");
+	end
+end
Index: uspace/dist/src/sysel/demos/hexec.sy
===================================================================
--- uspace/dist/src/sysel/demos/hexec.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/demos/hexec.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,34 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+class HelenOSExecDemo is
+	fun Main() is
+		Task.Exec("/app/tester");
+		Task.Exec("/app/tester", "print1");
+	end
+end
Index: uspace/dist/src/sysel/demos/htxtfile.sy
===================================================================
--- uspace/dist/src/sysel/demos/htxtfile.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/demos/htxtfile.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,54 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+class TextFileDemo is
+	fun Main() is
+		var name : string;
+		var line : string;
+
+		var in_file : TextFile;
+		var out_file : TextFile;
+
+		name = "/readme";
+
+		in_file = new TextFile();
+		in_file.OpenRead(name);
+
+		out_file = new TextFile();
+		out_file.OpenWrite("/out.txt");
+
+		while in_file.EOF != 1 do
+			line = in_file.ReadLine();
+			Builtin.WriteLine(name + ": " + line);
+			out_file.WriteLine(name + ": " + line);
+		end
+
+		in_file.Close();
+		out_file.Close();
+	end
+end
Index: uspace/dist/src/sysel/demos/inherit.sy
===================================================================
--- uspace/dist/src/sysel/demos/inherit.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/demos/inherit.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,69 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+class A is
+	fun Foo() is
+		Builtin.WriteLine("A.Foo()");
+	end
+end
+
+class B : A is
+	fun Foo() is
+		Builtin.WriteLine("B.Foo()");
+	end
+end
+
+class C : A is
+end
+
+class InheritanceDemo is
+	fun Main() is
+		var a : A;
+		var c : C;
+
+		-- Construct and assign object.
+		a = new A();
+		a.Foo();
+
+		-- Implicit conversion to base type.
+		a = new B();
+		a.Foo();
+
+		a = new C();
+		a.Foo();
+
+		-- Test 'as' operator for conversion to derived type.
+		c = a as C;
+
+		-- Test grandfather class.
+		var d : Object;
+		d = a;
+		d = new B();
+		d = c;
+	end
+end
Index: uspace/dist/src/sysel/demos/list.sy
===================================================================
--- uspace/dist/src/sysel/demos/list.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/demos/list.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,52 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+-- Using the List class from the library.
+class ListDemo is
+	fun Main() is
+		var list : List;
+		var i : Int;
+
+		list = new List();
+		list.Init();
+
+		-- We need autoboxing or generics to get rid of this mess.
+		i = new Int(); i.Value = 5; list.Append(i);
+		i = new Int(); i.Value = 6; list.Append(i);
+		i = new Int(); i.Value = 7; list.Append(i);
+		i = new Int(); i.Value = 8; list.Append(i);
+
+		var n : ListNode;
+
+		n = list.First;
+		while n != nil do
+			Builtin.WriteLine((n.value as Int).Value);
+			n = n.Next;
+		end
+	end
+end
Index: uspace/dist/src/sysel/demos/property.sy
===================================================================
--- uspace/dist/src/sysel/demos/property.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/demos/property.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,138 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+class Foo is
+	var x : int;
+
+	-- Example of a named property
+	prop X : int is
+		get is
+			Builtin.WriteLine("Getting value of X which is");
+			Builtin.WriteLine(x);
+			return x;
+		end
+
+		set value is
+			Builtin.WriteLine("Setting value of X to");
+			Builtin.WriteLine(value);
+			x = value;
+		end
+	end
+
+	-- Backing store for indexed properties
+	var iprops : int[];
+
+	-- Example of an indexed property set (i.e. an indexer)
+	prop self[index : int] : int is
+		get is
+			Builtin.WriteLine("Getting property with index ");
+			Builtin.WriteLine(index);
+			Builtin.WriteLine("which is");
+			Builtin.WriteLine(iprops[index]);
+
+			return iprops[index];
+		end
+
+		set value is
+			Builtin.WriteLine("Setting property with index ");
+			Builtin.WriteLine(index);
+			Builtin.WriteLine("to");
+			Builtin.WriteLine(value);
+
+			iprops[index] = value;
+		end
+	end
+
+	--
+	-- Class-type property. This is used for demonstrating property
+	-- field access. This case is still quite easy. It does not require
+	-- read-modify-write. Since class is a reference type, access
+	-- operator will read the value and dereference it, thereby
+	-- getting somewhere else (so the value will not be modified and
+	-- need not be written back).
+	--
+
+	var bprop : Bar;
+
+	prop B : Bar is
+		get is
+			Builtin.WriteLine("Getting B");
+			return bprop;
+		end
+		set value is
+			Builtin.WriteLine("Setting B");
+			bprop = value;
+		end
+	end
+
+end
+
+class Bar is
+	var i : int;
+end
+
+class PropertyDemo is
+	fun Main() is
+		var a : Foo;
+		var i : int;
+
+		a = new Foo();
+
+		-- Get value of named property.
+		a.X = 1;
+
+		-- Set value of named property.
+		i = a.X;
+
+		Builtin.WriteLine("Main(): Got ");
+		Builtin.WriteLine(i);
+
+		a.iprops = new int[5];
+
+		-- Set value of indexed property.
+		a[1] = 2;
+
+		-- Get value of indexed property.
+		i = a[1];
+
+		Builtin.WriteLine("Main(): Got ");
+		Builtin.WriteLine(i);
+
+		-- Property field access
+		var b : Bar;
+
+		b = new Bar();
+
+		b.i = 42;
+		a.bprop = b;
+
+		Builtin.WriteLine(a.bprop.i);
+		a.bprop.i = 2;
+		Builtin.WriteLine(a.bprop.i);
+	end
+end
Index: uspace/dist/src/sysel/demos/string.sy
===================================================================
--- uspace/dist/src/sysel/demos/string.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/demos/string.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,42 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+class StringDemo is
+	fun Main() is
+		-- Concatenate some strings.
+		Builtin.WriteLine("One-" + "two-" + "three!");
+
+		-- Extract characters from a string.
+		var i : int;
+		i = 0;
+		while i < 5 do
+			Builtin.WriteLine("ABCDE"[i]);
+			i = i + 1;
+		end
+	end
+end
Index: uspace/dist/src/sysel/demos/varargs.sy
===================================================================
--- uspace/dist/src/sysel/demos/varargs.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/demos/varargs.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,58 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+class VariadicArgumentsDemo is
+	--- Variadic function example.
+	--
+	-- A variadic function is declared by marking its last argument
+	-- with the attribute 'packed'.
+	--
+	fun Print(args : string[], packed) is
+		var i : int;
+		var error : int;
+
+		error = 0;
+		i = 0;
+		while error == 0 do
+			-- This is definitely the wrong way to determine
+			-- array bounds, but until a better one is
+			-- implemented...
+			do
+				Builtin.WriteLine(args[i]);
+			except e : Error.OutOfBounds do
+				error = 1;
+			end
+
+			i = i + 1;
+		end
+	end
+
+	fun Main() is
+		Print("One", "Two", "Three", "Four", "Five");
+	end
+end
Index: uspace/dist/src/sysel/lib/arith.sy
===================================================================
--- uspace/dist/src/sysel/lib/arith.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/lib/arith.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,45 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+class Arith is
+	-- Return factorial of n.
+	fun Factorial(n : int) : int is
+		var i : int;
+		var val : int;
+
+		i = 1;
+		val = 1;
+
+		while i <= n do
+			val = val * i;
+			i = i + 1;
+		end
+
+		return val;
+	end
+end
Index: uspace/dist/src/sysel/lib/boxed.sy
===================================================================
--- uspace/dist/src/sysel/lib/boxed.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/lib/boxed.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,47 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+--
+-- Declarations for boxed variants of primitive types.
+--
+
+class Bool is
+	var Value : bool;
+end
+
+class Char is
+	var Value : char;
+end
+
+class Int is
+	var Value : int;
+end
+
+class String is
+	var Value : string;
+end
Index: uspace/dist/src/sysel/lib/libflist
===================================================================
--- uspace/dist/src/sysel/lib/libflist	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/lib/libflist	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,3 @@
+arith.sy
+boxed.sy
+list.sy
Index: uspace/dist/src/sysel/lib/list.sy
===================================================================
--- uspace/dist/src/sysel/lib/list.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/dist/src/sysel/lib/list.sy	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,121 @@
+--
+-- Copyright (c) 2010 Jiri Svoboda
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions
+-- are met:
+--
+-- o Redistributions of source code must retain the above copyright
+--   notice, this list of conditions and the following disclaimer.
+-- o 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.
+-- o 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.
+--
+
+-- Doubly-linked non-generic list.
+class List is
+	var head : ListNode;
+
+	-- Initialize list.
+	fun Init() is
+		head = new ListNode();
+		head.prev = head;
+		head.next = head;
+	end
+
+	-- Append new entry at the end of the list.
+	fun Append(data : Object) is
+		var n : ListNode;
+		var ntl : ListNode;
+
+		ntl = head.prev;
+
+		n = new ListNode();
+		n.value = data;
+
+		n.prev = ntl;
+		n.next = head;
+		n.head = head;
+
+		ntl.next = n;
+		head.prev = n;
+	end
+
+	-- Return first node in the list or @c nil if there is none.
+	prop First : ListNode is
+		get is
+		    return get_first();
+		end
+	end
+
+	-- Return first node in the list or @c nil if there is none.
+	fun get_first() : ListNode is
+		if head.next == head then
+			return nil;
+		else
+			return head.next;
+		end
+	end
+end
+
+class ListNode is
+	var value : Object;
+
+	var prev : ListNode;
+	var next : ListNode;
+	var head : ListNode;
+
+	-- Value stored in this node.
+	prop Value : Object is
+		get is
+			return value;
+		end
+	end
+
+	-- Previous node in list.
+	prop Prev : ListNode is
+		get is
+			return get_prev();
+		end
+	end
+
+	-- Next node in list.
+	prop Next : ListNode is
+		get is
+			return get_next();
+		end
+	end
+
+	-- Get next node.
+	fun get_next() : ListNode is
+		if next != head then
+			return next;
+		else
+			return nil;
+		end
+	end
+
+	-- Get previous node.
+	fun get_prev() : ListNode is
+		if prev != head then
+			return next;
+		else
+			return nil;
+		end
+	end
+
+end
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -35,11 +35,14 @@
 INCLUDE_LIBARCH = include/libarch
 
-PRE_DEPEND = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH)
+COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
+COMMON_HEADER = $(ROOT_PATH)/common.h
+COMMON_HEADER_ARCH = arch/$(UARCH)/include/common.h
+
+CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
+
+PRE_DEPEND = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH)
 EXTRA_OUTPUT = $(LINKER_SCRIPT)
-EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(LINKER_SCRIPT)
+EXTRA_CLEAN = $(INCLUDE_KERNEL) $(INCLUDE_ARCH) $(INCLUDE_LIBARCH) $(COMMON_HEADER_ARCH) $(LINKER_SCRIPT)
 LIBRARY = libc
-
-COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
-CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
 
 -include $(COMMON_MAKEFILE)
@@ -58,4 +61,5 @@
 	generic/mem.c \
 	generic/str.c \
+	generic/str_error.c \
 	generic/fibril.c \
 	generic/fibril_synch.c \
@@ -91,4 +95,5 @@
 	generic/vfs/canonify.c \
 	generic/stacktrace.c \
+	generic/arg_parse.c \
 	generic/ps.c \
 	generic/cpuinfo.c \
@@ -116,2 +121,5 @@
 $(LINKER_SCRIPT): $(LINKER_SCRIPT).in
 	$(GCC) $(DEFS) $(CFLAGS) -DLIBC_PATH=$(CURDIR) -E -x c $< | grep -v "^\#" > $@
+
+$(COMMON_HEADER_ARCH): $(COMMON_HEADER)
+	ln -sfn ../../../$< $@
Index: uspace/lib/c/arch/abs32le/include/types.h
===================================================================
--- uspace/lib/c/arch/abs32le/include/types.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/arch/abs32le/include/types.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -38,15 +38,7 @@
 #define __32_BITS__
 
-typedef unsigned int sysarg_t;
+#include <libarch/common.h>
 
-typedef char int8_t;
-typedef short int int16_t;
-typedef int int32_t;
-typedef long long int int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long long int uint64_t;
+typedef uint32_t sysarg_t;
 
 typedef int32_t ssize_t;
Index: uspace/lib/c/arch/amd64/include/types.h
===================================================================
--- uspace/lib/c/arch/amd64/include/types.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/arch/amd64/include/types.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -38,15 +38,7 @@
 #define __64_BITS__
 
-typedef unsigned long long sysarg_t;
+#include <libarch/common.h>
 
-typedef signed char int8_t;
-typedef short int int16_t;
-typedef int int32_t;
-typedef long long int int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long long int uint64_t;
+typedef uint64_t sysarg_t;
 
 typedef int64_t ssize_t;
Index: uspace/lib/c/arch/arm32/include/types.h
===================================================================
--- uspace/lib/c/arch/arm32/include/types.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/arch/arm32/include/types.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -27,8 +27,8 @@
  */
 
-/** @addtogroup libcarm32	
+/** @addtogroup libcarm32
  * @{
  */
-/** @file 
+/** @file
  *  @brief Definitions of basic types like #uintptr_t.
  */
@@ -39,15 +39,7 @@
 #define __32_BITS__
 
-typedef unsigned int sysarg_t;
+#include <libarch/common.h>
 
-typedef char int8_t;
-typedef short int int16_t;
-typedef long int int32_t;
-typedef long long int int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned long int uint32_t;
-typedef unsigned long long int uint64_t;
+typedef uint32_t sysarg_t;
 
 typedef int32_t ssize_t;
Index: uspace/lib/c/arch/ia32/include/types.h
===================================================================
--- uspace/lib/c/arch/ia32/include/types.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/arch/ia32/include/types.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -38,15 +38,7 @@
 #define __32_BITS__
 
-typedef unsigned int sysarg_t;
+#include <libarch/common.h>
 
-typedef char int8_t;
-typedef short int int16_t;
-typedef int int32_t;
-typedef long long int int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long long int uint64_t;
+typedef uint32_t sysarg_t;
 
 typedef int32_t ssize_t;
Index: uspace/lib/c/arch/ia64/include/types.h
===================================================================
--- uspace/lib/c/arch/ia64/include/types.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/arch/ia64/include/types.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -38,15 +38,10 @@
 #define __64_BITS__
 
-typedef unsigned long sysarg_t;
+#include <libarch/common.h>
 
-typedef char int8_t;
-typedef short int int16_t;
-typedef int int32_t;
-typedef long int int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long int uint64_t;
+typedef struct {
+	uint64_t lo;
+	int64_t hi;
+} int128_t;
 
 typedef struct {
@@ -54,4 +49,6 @@
 	uint64_t hi;
 } uint128_t;
+
+typedef uint64_t sysarg_t;
 
 typedef int64_t ssize_t;
Index: uspace/lib/c/arch/ia64/src/ddi.c
===================================================================
--- uspace/lib/c/arch/ia64/src/ddi.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/arch/ia64/src/ddi.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -2,12 +2,13 @@
 #include <sysinfo.h>
 
-uint64_t ia64_iospace_address=0;
-
+uint64_t ia64_iospace_address = 0;
 
 uint64_t get_ia64_iospace_address(void)
 {
-
-	return sysinfo_value("ia64_iospace.address.virtual");
-
+	sysarg_t addr;
+	if (sysinfo_get_value("ia64_iospace.address.virtual", &addr) != 0)
+		addr = 0;
+	
+	return addr;
 }
 
Index: uspace/lib/c/arch/mips32/include/types.h
===================================================================
--- uspace/lib/c/arch/mips32/include/types.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/arch/mips32/include/types.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -39,15 +39,7 @@
 #define __32_BITS__
 
-typedef unsigned int sysarg_t;
+#include <libarch/common.h>
 
-typedef char int8_t;
-typedef short int int16_t;
-typedef long int int32_t;
-typedef long long int int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned long int uint32_t;
-typedef unsigned long long int uint64_t;
+typedef uint32_t sysarg_t;
 
 typedef int32_t ssize_t;
Index: uspace/lib/c/arch/ppc32/include/types.h
===================================================================
--- uspace/lib/c/arch/ppc32/include/types.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/arch/ppc32/include/types.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -38,15 +38,7 @@
 #define __32_BITS__
 
-typedef unsigned int sysarg_t;
+#include <libarch/common.h>
 
-typedef char int8_t;
-typedef short int int16_t;
-typedef int int32_t;
-typedef long long int int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long long int uint64_t;
+typedef uint32_t sysarg_t;
 
 typedef int32_t ssize_t;
Index: uspace/lib/c/arch/sparc64/include/types.h
===================================================================
--- uspace/lib/c/arch/sparc64/include/types.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/arch/sparc64/include/types.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -38,15 +38,7 @@
 #define __64_BITS__
 
-typedef unsigned long sysarg_t;
+#include <libarch/common.h>
 
-typedef signed char int8_t;
-typedef short int int16_t;
-typedef int int32_t;
-typedef long int int64_t;
-
-typedef unsigned char uint8_t;
-typedef unsigned short int uint16_t;
-typedef unsigned int uint32_t;
-typedef unsigned long int uint64_t;
+typedef uint64_t sysarg_t;
 
 typedef int64_t ssize_t;
Index: uspace/lib/c/generic/adt/hash_table.c
===================================================================
--- uspace/lib/c/generic/adt/hash_table.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/generic/adt/hash_table.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -42,20 +42,19 @@
 #include <malloc.h>
 #include <assert.h>
-#include <stdio.h>
 #include <str.h>
 
 /** Create chained hash table.
  *
- * @param h		Hash table structure. Will be initialized by this call.
- * @param m		Number of hash table buckets.
- * @param max_keys	Maximal number of keys needed to identify an item.
- * @param op		Hash table operations structure.
- * @return		True on success
+ * @param h        Hash table structure. Will be initialized by this call.
+ * @param m        Number of hash table buckets.
+ * @param max_keys Maximal number of keys needed to identify an item.
+ * @param op       Hash table operations structure.
+ *
+ * @return True on success
+ *
  */
 int hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys,
     hash_table_operations_t *op)
 {
-	hash_count_t i;
-
 	assert(h);
 	assert(op && op->hash && op->compare);
@@ -63,10 +62,10 @@
 	
 	h->entry = malloc(m * sizeof(link_t));
-	if (!h->entry) {
-		printf("cannot allocate memory for hash table\n");
+	if (!h->entry)
 		return false;
-	}
+	
 	memset((void *) h->entry, 0,  m * sizeof(link_t));
 	
+	hash_count_t i;
 	for (i = 0; i < m; i++)
 		list_initialize(&h->entry[i]);
@@ -75,4 +74,5 @@
 	h->max_keys = max_keys;
 	h->op = op;
+	
 	return true;
 }
@@ -80,5 +80,6 @@
 /** Destroy a hash table instance.
  *
- * @param h		Hash table to be destroyed.
+ * @param h Hash table to be destroyed.
+ *
  */
 void hash_table_destroy(hash_table_t *h)
@@ -86,4 +87,5 @@
 	assert(h);
 	assert(h->entry);
+	
 	free(h->entry);
 }
@@ -91,16 +93,14 @@
 /** Insert item into a hash table.
  *
- * @param h		Hash table.
- * @param key		Array of all keys necessary to compute hash index.
- * @param item		Item to be inserted into the hash table.
+ * @param h    Hash table.
+ * @param key  Array of all keys necessary to compute hash index.
+ * @param item Item to be inserted into the hash table.
  */
 void hash_table_insert(hash_table_t *h, unsigned long key[], link_t *item)
 {
-	hash_index_t chain;
-
 	assert(item);
 	assert(h && h->op && h->op->hash && h->op->compare);
-
-	chain = h->op->hash(key);
+	
+	hash_index_t chain = h->op->hash(key);
 	assert(chain < h->entries);
 	
@@ -110,19 +110,18 @@
 /** Search hash table for an item matching keys.
  *
- * @param h		Hash table.
- * @param key		Array of all keys needed to compute hash index.
- *
- * @return		Matching item on success, NULL if there is no such item.
+ * @param h   Hash table.
+ * @param key Array of all keys needed to compute hash index.
+ *
+ * @return Matching item on success, NULL if there is no such item.
+ *
  */
 link_t *hash_table_find(hash_table_t *h, unsigned long key[])
 {
+	assert(h && h->op && h->op->hash && h->op->compare);
+	
+	hash_index_t chain = h->op->hash(key);
+	assert(chain < h->entries);
+	
 	link_t *cur;
-	hash_index_t chain;
-
-	assert(h && h->op && h->op->hash && h->op->compare);
-
-	chain = h->op->hash(key);
-	assert(chain < h->entries);
-	
 	for (cur = h->entry[chain].next; cur != &h->entry[chain];
 	    cur = cur->next) {
@@ -142,25 +141,24 @@
  * For each removed item, h->remove_callback() is called.
  *
- * @param h		Hash table.
- * @param key		Array of keys that will be compared against items of
- * 			the hash table.
- * @param keys		Number of keys in the 'key' array.
+ * @param h    Hash table.
+ * @param key  Array of keys that will be compared against items of
+ *             the hash table.
+ * @param keys Number of keys in the 'key' array.
+ *
  */
 void hash_table_remove(hash_table_t *h, unsigned long key[], hash_count_t keys)
 {
-	hash_index_t chain;
-	link_t *cur;
-
 	assert(h && h->op && h->op->hash && h->op->compare &&
 	    h->op->remove_callback);
 	assert(keys <= h->max_keys);
 	
+	link_t *cur;
+	
 	if (keys == h->max_keys) {
-
 		/*
 		 * All keys are known, hash_table_find() can be used to find the
 		 * entry.
 		 */
-	
+		
 		cur = hash_table_find(h, key);
 		if (cur) {
@@ -168,4 +166,5 @@
 			h->op->remove_callback(cur);
 		}
+		
 		return;
 	}
@@ -175,4 +174,5 @@
 	 * Any partially matching entries are to be removed.
 	 */
+	hash_index_t chain;
 	for (chain = 0; chain < h->entries; chain++) {
 		for (cur = h->entry[chain].next; cur != &h->entry[chain];
@@ -195,14 +195,14 @@
 /** Apply fucntion to all items in hash table.
  *
- * @param h		Hash table.
- * @param f		Function to be applied.
- * @param arg		Argument to be passed to the function.
- */
-void
-hash_table_apply(hash_table_t *h, void (*f)(link_t *, void *), void *arg)
+ * @param h   Hash table.
+ * @param f   Function to be applied.
+ * @param arg Argument to be passed to the function.
+ *
+ */
+void hash_table_apply(hash_table_t *h, void (*f)(link_t *, void *), void *arg)
 {
 	hash_index_t bucket;
 	link_t *cur;
-
+	
 	for (bucket = 0; bucket < h->entries; bucket++) {
 		for (cur = h->entry[bucket].next; cur != &h->entry[bucket];
Index: uspace/lib/c/generic/arg_parse.c
===================================================================
--- uspace/lib/c/generic/arg_parse.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/c/generic/arg_parse.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,141 @@
+/*
+ * 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.
+ */
+
+/** @file
+ * Command-line arguments parsing functions
+ */
+
+#include <arg_parse.h>
+#include <errno.h>
+#include <str.h>
+
+/** Parse the next argument as an integer.
+ *
+ * The actual argument is pointed by the index.
+ * Parse the offseted argument value if the offset is set
+ * or the next one if not.
+ *
+ * @param[in]     argc   The total number of arguments.
+ * @param[in]     argv   The arguments.
+ * @param[in,out] index  The actual argument index. The index is incremented
+ *                       by the number of processed arguments.
+ * @param[out]    value  The parsed argument value.
+ * @param[in]     offset The value offset in the actual argument. If not set,
+ *                       the next argument is parsed instead.
+ *
+ * @return EOK on success.
+ * @return ENOENT if the argument is missing.
+ * @return EINVAL if the argument is in wrong format.
+ *
+ */
+int arg_parse_int(int argc, char *argv[], int *index, int *value,
+    int offset)
+{
+	char *rest;
+	
+	if (offset)
+		*value = strtol(argv[*index] + offset, &rest, 10);
+	else if ((*index) + 1 < argc) {
+		(*index)++;
+		*value = strtol(argv[*index], &rest, 10);
+	} else
+		return ENOENT;
+	
+	if ((rest) && (*rest))
+		return EINVAL;
+	
+	return EOK;
+}
+
+/** Parse the next named argument as an integral number.
+ *
+ * The actual argument is pointed by the index.
+ * Parse the offseted actual argument if the offset is set or the next
+ * one if not. Translate the argument using the parse_value function.
+ * Increment the actual index by the number of processed arguments.
+ *
+ * @param[in]     argc        The total number of arguments.
+ * @param[in]     argv        The arguments.
+ * @param[in,out] index       The actual argument index. The index is
+ *                            incremented by the number of processed arguments.
+ * @param[out]    value       The parsed argument value.
+ * @param[in]     offset      The value offset in the actual argument. If not
+ *                            set, the next argument is parsed instead.
+ * @param[in]     parse_value The translation function to parse the named value.
+ *
+ * @return EOK on success.
+ * @return ENOENT if the argument is missing.
+ * @return EINVAL if the argument name has not been found.
+ *
+ */
+int arg_parse_name_int(int argc, char *argv[], int *index, int *value,
+    int offset, arg_parser parser)
+{
+	char *arg;
+	
+	int ret = arg_parse_string(argc, argv, index, &arg, offset);
+	if (ret != EOK)
+		return ret;
+	
+	return parser(arg, value);
+}
+
+/** Parse the next argument as a character string.
+ *
+ * The actual argument is pointed by the index.
+ * Parse the offseted actual argument value if the offset is set or the next
+ * one if not. Increment the actual index by the number of processed arguments.
+ *
+ * @param[in]     argc   The total number of arguments.
+ * @param[in]     argv   The arguments.
+ * @param[in,out] index  The actual argument index. The index is
+ *                       incremented by the number of processed arguments.
+ * @param[out]    value  The parsed argument value.
+ * @param[in]     offset The value offset in the actual argument. If not set,
+ *                       the next argument is parsed instead.
+ *
+ * @return EOK on success.
+ * @return ENOENT if the parameter is missing.
+ *
+ */
+int arg_parse_string(int argc, char **argv, int *index, char **value,
+    int offset)
+{
+	if (offset)
+		*value = argv[*index] + offset;
+	else if ((*index) + 1 < argc) {
+		(*index)++;
+		*value = argv[*index];
+	} else
+		return ENOENT;
+	
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/async.c
===================================================================
--- uspace/lib/c/generic/async.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/generic/async.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -746,5 +746,5 @@
 	if (!hash_table_create(&conn_hash_table, CONN_HASH_TABLE_CHAINS, 1,
 	    &conn_hash_table_ops)) {
-		printf("%s: cannot create hash table\n", "async");
+		printf("%s: Cannot create async hash table\n", "libc");
 		return ENOMEM;
 	}
Index: uspace/lib/c/generic/fibril.c
===================================================================
--- uspace/lib/c/generic/fibril.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/generic/fibril.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -48,10 +48,11 @@
 
 #ifndef FIBRIL_INITIAL_STACK_PAGES_NO
-#define FIBRIL_INITIAL_STACK_PAGES_NO	1
+	#define FIBRIL_INITIAL_STACK_PAGES_NO  1
 #endif
 
 /**
- * This futex serializes access to ready_list, serialized_list and manager_list.
- */ 
+ * This futex serializes access to ready_list,
+ * serialized_list and manager_list.
+ */
 static atomic_t fibril_futex = FUTEX_INITIALIZER;
 
@@ -60,47 +61,15 @@
 static LIST_INITIALIZE(manager_list);
 
-static void fibril_main(void);
-
 /** Number of threads that are executing a manager fibril. */
 static int threads_in_manager;
-/** Number of threads that are executing a manager fibril and are serialized. */
-static int serialized_threads;	/* Protected by async_futex */
+
+/**
+ * Number of threads that are executing a manager fibril
+ * and are serialized. Protected by async_futex.
+ */
+static int serialized_threads;
+
 /** Fibril-local count of serialization. If > 0, we must not preempt */
 static fibril_local int serialization_count;
-
-/** Setup fibril information into TCB structure */
-fibril_t *fibril_setup(void)
-{
-	fibril_t *f;
-	tcb_t *tcb;
-
-	tcb = __make_tls();
-	if (!tcb)
-		return NULL;
-
-	f = malloc(sizeof(fibril_t));
-	if (!f) {
-		__free_tls(tcb);
-		return NULL;
-	}
-
-	tcb->fibril_data = f;
-	f->tcb = tcb;
-
-	f->func = NULL;
-	f->arg = NULL;
-	f->stack = NULL;
-	f->clean_after_me = NULL;
-	f->retval = 0;
-	f->flags = 0;
-
-	return f;
-}
-
-void fibril_teardown(fibril_t *f)
-{
-	__free_tls(f->tcb);
-	free(f);
-}
 
 /** Function that spans the whole life-cycle of a fibril.
@@ -109,14 +78,49 @@
  * the fibril logic is called.  After its return, the return value is saved.
  * The fibril then switches to another fibril, which cleans up after it.
- */
-void fibril_main(void)
-{
-	fibril_t *f = __tcb_get()->fibril_data;
-
+ *
+ */
+static void fibril_main(void)
+{
+	fibril_t *fibril = __tcb_get()->fibril_data;
+	
 	/* Call the implementing function. */
-	f->retval = f->func(f->arg);
-
+	fibril->retval = fibril->func(fibril->arg);
+	
 	fibril_switch(FIBRIL_FROM_DEAD);
-	/* not reached */
+	/* Not reached */
+}
+
+/** Setup fibril information into TCB structure
+ *
+ */
+fibril_t *fibril_setup(void)
+{
+	tcb_t *tcb = __make_tls();
+	if (!tcb)
+		return NULL;
+	
+	fibril_t *fibril = malloc(sizeof(fibril_t));
+	if (!fibril) {
+		__free_tls(tcb);
+		return NULL;
+	}
+	
+	tcb->fibril_data = fibril;
+	fibril->tcb = tcb;
+	
+	fibril->func = NULL;
+	fibril->arg = NULL;
+	fibril->stack = NULL;
+	fibril->clean_after_me = NULL;
+	fibril->retval = 0;
+	fibril->flags = 0;
+	
+	return fibril;
+}
+
+void fibril_teardown(fibril_t *fibril)
+{
+	__free_tls(fibril->tcb);
+	free(fibril);
 }
 
@@ -126,9 +130,11 @@
  * held.
  *
- * @param stype		Switch type. One of FIBRIL_PREEMPT, FIBRIL_TO_MANAGER,
- * 			FIBRIL_FROM_MANAGER, FIBRIL_FROM_DEAD. The parameter
- * 			describes the circumstances of the switch.
- * @return		Return 0 if there is no ready fibril,
- * 			return 1 otherwise.
+ * @param stype Switch type. One of FIBRIL_PREEMPT, FIBRIL_TO_MANAGER,
+ *              FIBRIL_FROM_MANAGER, FIBRIL_FROM_DEAD. The parameter
+ *              describes the circumstances of the switch.
+ *
+ * @return 0 if there is no ready fibril,
+ * @return 1 otherwise.
+ *
  */
 int fibril_switch(fibril_switch_type_t stype)
@@ -246,48 +252,52 @@
 /** Create a new fibril.
  *
- * @param func		Implementing function of the new fibril.
- * @param arg		Argument to pass to func.
- *
- * @return		Return 0 on failure or TLS of the new fibril.
+ * @param func Implementing function of the new fibril.
+ * @param arg Argument to pass to func.
+ *
+ * @return 0 on failure or TLS of the new fibril.
+ *
  */
 fid_t fibril_create(int (*func)(void *), void *arg)
 {
-	fibril_t *f;
-
-	f = fibril_setup();
-	if (!f) 
+	fibril_t *fibril;
+	
+	fibril = fibril_setup();
+	if (fibril == NULL)
 		return 0;
-	f->stack = (char *) malloc(FIBRIL_INITIAL_STACK_PAGES_NO *
-	    getpagesize());
-	if (!f->stack) {
-		fibril_teardown(f);
+	
+	fibril->stack =
+	    (char *) malloc(FIBRIL_INITIAL_STACK_PAGES_NO * getpagesize());
+	if (!fibril->stack) {
+		fibril_teardown(fibril);
 		return 0;
 	}
 	
-	f->func = func;
-	f->arg = arg;
-
-	context_save(&f->ctx);
-	context_set(&f->ctx, FADDR(fibril_main), f->stack,
-	    FIBRIL_INITIAL_STACK_PAGES_NO * getpagesize(), f->tcb);
-
-	return (fid_t) f;
+	fibril->func = func;
+	fibril->arg = arg;
+	
+	context_save(&fibril->ctx);
+	context_set(&fibril->ctx, FADDR(fibril_main), fibril->stack,
+	    FIBRIL_INITIAL_STACK_PAGES_NO * getpagesize(), fibril->tcb);
+
+	return (fid_t) fibril;
 }
 
 /** Add a fibril to the ready list.
  *
- * @param fid		Pointer to the fibril structure of the fibril to be
- *			added.
+ * @param fid Pointer to the fibril structure of the fibril to be
+ *            added.
+ *
  */
 void fibril_add_ready(fid_t fid)
 {
-	fibril_t *f;
-
-	f = (fibril_t *) fid;
+	fibril_t *fibril = (fibril_t *) fid;
+	
 	futex_down(&fibril_futex);
-	if ((f->flags & FIBRIL_SERIALIZED))
-		list_append(&f->link, &serialized_list);
+	
+	if ((fibril->flags & FIBRIL_SERIALIZED))
+		list_append(&fibril->link, &serialized_list);
 	else
-		list_append(&f->link, &ready_list);
+		list_append(&fibril->link, &ready_list);
+	
 	futex_up(&fibril_futex);
 }
@@ -295,15 +305,14 @@
 /** Add a fibril to the manager list.
  *
- * @param fid		Pointer to the fibril structure of the fibril to be
- *			added.
+ * @param fid Pointer to the fibril structure of the fibril to be
+ *            added.
+ *
  */
 void fibril_add_manager(fid_t fid)
 {
-	fibril_t *f;
-
-	f = (fibril_t *) fid;
-
+	fibril_t *fibril = (fibril_t *) fid;
+	
 	futex_down(&fibril_futex);
-	list_append(&f->link, &manager_list);
+	list_append(&fibril->link, &manager_list);
 	futex_up(&fibril_futex);
 }
@@ -313,9 +322,8 @@
 {
 	futex_down(&fibril_futex);
-	if (list_empty(&manager_list)) {
-		futex_up(&fibril_futex);
-		return;
-	}
-	list_remove(manager_list.next);
+	
+	if (!list_empty(&manager_list))
+		list_remove(manager_list.next);
+	
 	futex_up(&fibril_futex);
 }
Index: uspace/lib/c/generic/futex.c
===================================================================
--- uspace/lib/c/generic/futex.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/generic/futex.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -31,5 +31,5 @@
  */
 /** @file
- */ 
+ */
 
 #include <futex.h>
@@ -40,6 +40,7 @@
 /** Initialize futex counter.
  *
- * @param futex		Futex.
- * @param val		Initialization value.
+ * @param futex Futex.
+ * @param val   Initialization value.
+ *
  */
 void futex_initialize(futex_t *futex, int val)
@@ -50,7 +51,9 @@
 /** Try to down the futex.
  *
- * @param futex		Futex.
- * @return		Non-zero if the futex was acquired.
- * @return		Zero if the futex was not acquired.
+ * @param futex Futex.
+ *
+ * @return Non-zero if the futex was acquired.
+ * @return Zero if the futex was not acquired.
+ *
  */
 int futex_trydown(futex_t *futex)
@@ -61,8 +64,10 @@
 /** Down the futex.
  *
- * @param futex		Futex.
- * @return		ENOENT if there is no such virtual address.
- * @return		Zero in the uncontended case. 
- * @return		Otherwise one of ESYNCH_OK_ATOMIC or ESYNCH_OK_BLOCKED.
+ * @param futex Futex.
+ *
+ * @return ENOENT if there is no such virtual address.
+ * @return Zero in the uncontended case.
+ * @return Otherwise one of ESYNCH_OK_ATOMIC or ESYNCH_OK_BLOCKED.
+ *
  */
 int futex_down(futex_t *futex)
@@ -70,5 +75,5 @@
 	if ((atomic_signed_t) atomic_predec(futex) < 0)
 		return __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->count);
-
+	
 	return 0;
 }
@@ -76,7 +81,9 @@
 /** Up the futex.
  *
- * @param futex		Futex.
- * @return		ENOENT if there is no such virtual address.
- * @return		Zero in the uncontended case.
+ * @param futex Futex.
+ *
+ * @return ENOENT if there is no such virtual address.
+ * @return Zero in the uncontended case.
+ *
  */
 int futex_up(futex_t *futex)
@@ -84,5 +91,5 @@
 	if ((atomic_signed_t) atomic_postinc(futex) < 0)
 		return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->count);
-		
+	
 	return 0;
 }
Index: uspace/lib/c/generic/libc.c
===================================================================
--- uspace/lib/c/generic/libc.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/generic/libc.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -62,6 +62,5 @@
 void __main(void *pcb_ptr)
 {
-	int retval;
-
+	/* Initialize user task run-time environment */
 	__heap_init();
 	__async_init();
@@ -75,4 +74,6 @@
 	char **argv;
 	
+	/* Get command line arguments and initialize
+	   standard input and output */
 	if (__pcb == NULL) {
 		argc = 0;
@@ -86,12 +87,12 @@
 	}
 	
-	retval = main(argc, argv);
-
-	__stdio_done();
-	(void) task_retval(retval);
+	/* Run main() and set task return value
+	   according the result */
+	(void) task_retval(main(argc, argv));
 }
 
 void __exit(void)
 {
+	__stdio_done();
 	fibril_teardown(__tcb_get()->fibril_data);
 	_exit(0);
Index: uspace/lib/c/generic/malloc.c
===================================================================
--- uspace/lib/c/generic/malloc.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/generic/malloc.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -43,4 +43,5 @@
 #include <bitops.h>
 #include <mem.h>
+#include <futex.h>
 #include <adt/gcdlcm.h>
 
@@ -75,5 +76,4 @@
 #define NET_SIZE(size)  ((size) - STRUCT_OVERHEAD)
 
-
 /** Header of a heap block
  *
@@ -104,4 +104,7 @@
 extern char _heap;
 
+/** Futex for thread-safe heap manipulation */
+static futex_t malloc_futex = FUTEX_INITIALIZER;
+
 /** Address of heap start */
 static void *heap_start = 0;
@@ -119,4 +122,5 @@
  *
  * Fills in the structures related to a heap block.
+ * Should be called only inside the critical section.
  *
  * @param addr Address of the block.
@@ -144,4 +148,5 @@
  * Verifies that the structures related to a heap block still contain
  * the magic constants. This helps detect heap corruption early on.
+ * Should be called only inside the critical section.
  *
  * @param addr Address of the block.
@@ -161,4 +166,11 @@
 }
 
+/** Increase the heap area size
+ *
+ * Should be called only inside the critical section.
+ *
+ * @param size Number of bytes to grow the heap by.
+ *
+ */
 static bool grow_heap(size_t size)
 {
@@ -189,4 +201,11 @@
 }
 
+/** Decrease the heap area
+ *
+ * Should be called only inside the critical section.
+ *
+ * @param size Number of bytes to shrink the heap by.
+ *
+ */
 static void shrink_heap(void)
 {
@@ -196,5 +215,5 @@
 /** Initialize the heap allocator
  *
- * Finds how much physical memory we have and creates
+ * Find how much physical memory we have and create
  * the heap management structures that mark the whole
  * physical memory as a single free block.
@@ -203,4 +222,6 @@
 void __heap_init(void)
 {
+	futex_down(&malloc_futex);
+	
 	if (as_area_create((void *) &_heap, PAGE_SIZE,
 	    AS_AREA_WRITE | AS_AREA_READ)) {
@@ -213,15 +234,35 @@
 		block_init(heap_start, heap_end - heap_start, true);
 	}
-}
-
+	
+	futex_up(&malloc_futex);
+}
+
+/** Get maximum heap address
+ *
+ */
 uintptr_t get_max_heap_addr(void)
 {
+	futex_down(&malloc_futex);
+	
 	if (max_heap_size == (size_t) -1)
 		max_heap_size =
 		    max((size_t) (heap_end - heap_start), MAX_HEAP_SIZE);
 	
-	return ((uintptr_t) heap_start + max_heap_size);
-}
-
+	uintptr_t max_heap_addr = (uintptr_t) heap_start + max_heap_size;
+	
+	futex_up(&malloc_futex);
+	
+	return max_heap_addr;
+}
+
+/** Split heap block and mark it as used.
+ *
+ * Should be called only inside the critical section.
+ *
+ * @param cur  Heap block to split.
+ * @param size Number of bytes to split and mark from the beginning
+ *             of the block.
+ *
+ */
 static void split_mark(heap_block_head_t *cur, const size_t size)
 {
@@ -243,4 +284,6 @@
 
 /** Allocate a memory block
+ *
+ * Should be called only inside the critical section.
  *
  * @param size  The size of the block to allocate.
@@ -356,4 +399,12 @@
 }
 
+/** Allocate memory by number of elements
+ *
+ * @param nmemb Number of members to allocate.
+ * @param size  Size of one member in bytes.
+ *
+ * @return Allocated memory or NULL.
+ *
+ */
 void *calloc(const size_t nmemb, const size_t size)
 {
@@ -361,14 +412,33 @@
 	if (block == NULL)
 		return NULL;
-
+	
 	memset(block, 0, nmemb * size);
 	return block;
 }
 
+/** Allocate memory
+ *
+ * @param size Number of bytes to allocate.
+ *
+ * @return Allocated memory or NULL.
+ *
+ */
 void *malloc(const size_t size)
 {
-	return malloc_internal(size, BASE_ALIGN);
-}
-
+	futex_down(&malloc_futex);
+	void *block = malloc_internal(size, BASE_ALIGN);
+	futex_up(&malloc_futex);
+	
+	return block;
+}
+
+/** Allocate memory with specified alignment
+ *
+ * @param align Alignment in byes.
+ * @param size  Number of bytes to allocate.
+ *
+ * @return Allocated memory or NULL.
+ *
+ */
 void *memalign(const size_t align, const size_t size)
 {
@@ -379,11 +449,25 @@
 	    1 << (fnzb(max(sizeof(void *), align) - 1) + 1);
 	
-	return malloc_internal(size, palign);
-}
-
+	futex_down(&malloc_futex);
+	void *block = malloc_internal(size, palign);
+	futex_up(&malloc_futex);
+	
+	return block;
+}
+
+/** Reallocate memory block
+ *
+ * @param addr Already allocated memory or NULL.
+ * @param size New size of the memory block.
+ *
+ * @return Reallocated memory or NULL.
+ *
+ */
 void *realloc(const void *addr, const size_t size)
 {
 	if (addr == NULL)
 		return malloc(size);
+	
+	futex_down(&malloc_futex);
 	
 	/* Calculate the position of the header. */
@@ -398,4 +482,5 @@
 	
 	void *ptr = NULL;
+	bool reloc = false;
 	size_t real_size = GROSS_SIZE(ALIGN_UP(size, BASE_ALIGN));
 	size_t orig_size = head->size;
@@ -415,5 +500,7 @@
 	} else {
 		/* Look at the next block. If it is free and the size is
-		   sufficient then merge the two. */
+		   sufficient then merge the two. Otherwise just allocate
+		   a new block, copy the original data into it and
+		   free the original block. */
 		heap_block_head_t *next_head =
 		    (heap_block_head_t *) (((void *) head) + head->size);
@@ -427,10 +514,15 @@
 			
 			ptr = ((void *) head) + sizeof(heap_block_head_t);
-		} else {
-			ptr = malloc(size);
-			if (ptr != NULL) {
-				memcpy(ptr, addr, NET_SIZE(orig_size));
-				free(addr);
-			}
+		} else
+			reloc = true;
+	}
+	
+	futex_up(&malloc_futex);
+	
+	if (reloc) {
+		ptr = malloc(size);
+		if (ptr != NULL) {
+			memcpy(ptr, addr, NET_SIZE(orig_size));
+			free(addr);
 		}
 	}
@@ -442,7 +534,10 @@
  *
  * @param addr The address of the block.
+ *
  */
 void free(const void *addr)
 {
+	futex_down(&malloc_futex);
+	
 	/* Calculate the position of the header. */
 	heap_block_head_t *head
@@ -483,4 +578,6 @@
 	
 	shrink_heap();
+	
+	futex_up(&malloc_futex);
 }
 
Index: uspace/lib/c/generic/str.c
===================================================================
--- uspace/lib/c/generic/str.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/generic/str.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -471,5 +471,5 @@
  * null-terminated and containing only complete characters.
  *
- * @param dest   Destination buffer.
+ * @param dest  Destination buffer.
  * @param count Size of the destination buffer (must be > 0).
  * @param src   Source string.
@@ -477,19 +477,16 @@
 void str_cpy(char *dest, size_t size, const char *src)
 {
-	wchar_t ch;
-	size_t src_off;
-	size_t dest_off;
-
 	/* There must be space for a null terminator in the buffer. */
 	assert(size > 0);
 	
-	src_off = 0;
-	dest_off = 0;
-
+	size_t src_off = 0;
+	size_t dest_off = 0;
+	
+	wchar_t ch;
 	while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
 		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
 			break;
 	}
-
+	
 	dest[dest_off] = '\0';
 }
@@ -505,26 +502,23 @@
  * have to be null-terminated.
  *
- * @param dest   Destination buffer.
+ * @param dest  Destination buffer.
  * @param count Size of the destination buffer (must be > 0).
  * @param src   Source string.
- * @param n	Maximum number of bytes to read from @a src.
+ * @param n     Maximum number of bytes to read from @a src.
  */
 void str_ncpy(char *dest, size_t size, const char *src, size_t n)
 {
-	wchar_t ch;
-	size_t src_off;
-	size_t dest_off;
-
 	/* There must be space for a null terminator in the buffer. */
 	assert(size > 0);
 	
-	src_off = 0;
-	dest_off = 0;
-
+	size_t src_off = 0;
+	size_t dest_off = 0;
+	
+	wchar_t ch;
 	while ((ch = str_decode(src, &src_off, n)) != 0) {
 		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
 			break;
 	}
-
+	
 	dest[dest_off] = '\0';
 }
@@ -896,28 +890,62 @@
 }
 
+/** Duplicate string.
+ *
+ * Allocate a new string and copy characters from the source
+ * string into it. The duplicate string is allocated via sleeping
+ * malloc(), thus this function can sleep in no memory conditions.
+ *
+ * The allocation cannot fail and the return value is always
+ * a valid pointer. The duplicate string is always a well-formed
+ * null-terminated UTF-8 string, but it can differ from the source
+ * string on the byte level.
+ *
+ * @param src Source string.
+ *
+ * @return Duplicate string.
+ *
+ */
 char *str_dup(const char *src)
 {
-	size_t size = str_size(src);
-	void *dest = malloc(size + 1);
-	
+	size_t size = str_size(src) + 1;
+	char *dest = (char *) malloc(size);
 	if (dest == NULL)
 		return (char *) NULL;
 	
-	return (char *) memcpy(dest, src, size + 1);
-}
-
-char *str_ndup(const char *src, size_t max_size)
+	str_cpy(dest, size, src);
+	return dest;
+}
+
+/** Duplicate string with size limit.
+ *
+ * Allocate a new string and copy up to @max_size bytes from the source
+ * string into it. The duplicate string is allocated via sleeping
+ * malloc(), thus this function can sleep in no memory conditions.
+ * No more than @max_size + 1 bytes is allocated, but if the size
+ * occupied by the source string is smaller than @max_size + 1,
+ * less is allocated.
+ *
+ * The allocation cannot fail and the return value is always
+ * a valid pointer. The duplicate string is always a well-formed
+ * null-terminated UTF-8 string, but it can differ from the source
+ * string on the byte level.
+ *
+ * @param src Source string.
+ * @param n   Maximum number of bytes to duplicate.
+ *
+ * @return Duplicate string.
+ *
+ */
+char *str_ndup(const char *src, size_t n)
 {
 	size_t size = str_size(src);
-	if (size > max_size)
-		size = max_size;
+	if (size > n)
+		size = n;
 	
 	char *dest = (char *) malloc(size + 1);
-	
 	if (dest == NULL)
 		return (char *) NULL;
 	
-	memcpy(dest, src, size);
-	dest[size] = 0;
+	str_ncpy(dest, size + 1, src, size);
 	return dest;
 }
Index: uspace/lib/c/generic/str_error.c
===================================================================
--- uspace/lib/c/generic/str_error.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/c/generic/str_error.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2010 Martin Decky
+ * 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
+ */
+
+#include <str_error.h>
+#include <stdio.h>
+#include <fibril.h>
+
+#define MIN_ERRNO  -17
+#define NOERR_LEN  64
+
+static const char* err_desc[] = {
+	"No error",
+	"No such entry",
+	"Not enought memory",
+	"Limit exceeded", 
+	"Connection refused",
+	"Forward error",
+	"Permission denied",
+	"Answerbox closed connection",
+	"Other party error",
+	"Entry already exists",
+	"Bad memory pointer",
+	"Not supported",
+	"Address not available",
+	"Timeout expired",
+	"Invalid value",
+	"Resource is busy",
+	"Result does not fits its size",
+	"Operation was interrupted"
+};
+
+static fibril_local char noerr[NOERR_LEN];
+
+const char *str_error(const int errno)
+{
+	if ((errno <= 0) && (errno >= MIN_ERRNO))
+		return err_desc[-errno];
+	
+	snprintf(noerr, NOERR_LEN, "Unkown error code %d", errno);
+	return noerr;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/sysinfo.c
===================================================================
--- uspace/lib/c/generic/sysinfo.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/generic/sysinfo.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -31,14 +31,52 @@
  */
 /** @file
- */ 
+ */
 
 #include <libc.h>
 #include <sysinfo.h>
 #include <str.h>
+#include <errno.h>
+#include <malloc.h>
+#include <bool.h>
 
-sysarg_t sysinfo_value(const char *name)
+sysinfo_item_tag_t sysinfo_get_tag(const char *path)
 {
-	return __SYSCALL2(SYS_SYSINFO_VALUE, (sysarg_t) name,
-	    (sysarg_t) str_size(name));
+	return (sysinfo_item_tag_t) __SYSCALL2(SYS_SYSINFO_GET_TAG,
+	    (sysarg_t) path, (sysarg_t) str_size(path));
+}
+
+int sysinfo_get_value(const char *path, sysarg_t *value)
+{
+	return (int) __SYSCALL3(SYS_SYSINFO_GET_VALUE, (sysarg_t) path,
+	    (sysarg_t) str_size(path), (sysarg_t) value);
+}
+
+static int sysinfo_get_data_size(const char *path, size_t *size)
+{
+	return (int) __SYSCALL3(SYS_SYSINFO_GET_DATA_SIZE, (sysarg_t) path,
+	    (sysarg_t) str_size(path), (sysarg_t) size);
+}
+
+extern void *sysinfo_get_data(const char *path, size_t *size)
+{
+	while (true) {
+		int ret = sysinfo_get_data_size(path, size);
+		if (ret != EOK)
+			return NULL;
+		
+		void *data = malloc(*size);
+		if (data == NULL)
+			return NULL;
+		
+		ret = __SYSCALL4(SYS_SYSINFO_GET_DATA, (sysarg_t) path,
+		    (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size);
+		if (ret == EOK)
+			return data;
+		
+		if (ret != ENOMEM)
+			return NULL;
+		
+		free(data);
+	}
 }
 
Index: uspace/lib/c/generic/task.c
===================================================================
--- uspace/lib/c/generic/task.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/generic/task.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -70,16 +70,21 @@
  * loader API.
  *
- * @param path pathname of the binary to execute
- * @param argv command-line arguments
+ * @param path Pathname of the binary to execute.
+ * @param argv Command-line arguments.
+ * @param err  If not NULL, the error value is stored here.
  *
  * @return ID of the newly created task or zero on error.
  *
  */
-task_id_t task_spawn(const char *path, const char *const args[])
+task_id_t task_spawn(const char *path, const char *const args[], int *err)
 {
 	/* Connect to a program loader. */
 	loader_t *ldr = loader_connect();
-	if (ldr == NULL)
+	if (ldr == NULL) {
+		if (err != NULL)
+			*err = EREFUSED;
+		
 		return 0;
+	}
 	
 	/* Get task ID. */
@@ -143,4 +148,8 @@
 	/* Success */
 	free(ldr);
+	
+	if (err != NULL)
+		*err = EOK;
+	
 	return task_id;
 	
@@ -149,4 +158,7 @@
 	loader_abort(ldr);
 	free(ldr);
+	
+	if (err != NULL)
+		*err = rc;
 	
 	return 0;
Index: uspace/lib/c/include/arg_parse.h
===================================================================
--- uspace/lib/c/include/arg_parse.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/c/include/arg_parse.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,47 @@
+/*
+ * 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
+ */
+
+#ifndef LIBC_ARG_PARSE_H_
+#define LIBC_ARG_PARSE_H_
+
+typedef int (*arg_parser)(const char *, int *);
+
+extern int arg_parse_int(int, char **, int *, int *, int);
+extern int arg_parse_name_int(int, char **, int *, int *, int, arg_parser);
+extern int arg_parse_string(int, char **, int *, char **, int);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/errno.h
===================================================================
--- uspace/lib/c/include/errno.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/include/errno.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -43,5 +43,5 @@
 #define errno _errno
 
-#define EMFILE        (-17)
+#define EMFILE        (-18)
 #define ENAMETOOLONG  (-256)
 #define EISDIR        (-257)
Index: uspace/lib/c/include/futex.h
===================================================================
--- uspace/lib/c/include/futex.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/include/futex.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -39,5 +39,5 @@
 #include <sys/types.h>
 
-#define FUTEX_INITIALIZER     {1}
+#define FUTEX_INITIALIZER  {1}
 
 typedef atomic_t futex_t;
Index: uspace/lib/c/include/str_error.h
===================================================================
--- uspace/lib/c/include/str_error.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/c/include/str_error.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2010 Martin Decky
+ * 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
+ */
+
+#ifndef LIBC_STRERROR_H_
+#define LIBC_STRERROR_H_
+
+const char *str_error(const int);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/sysinfo.h
===================================================================
--- uspace/lib/c/include/sysinfo.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/include/sysinfo.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -31,5 +31,5 @@
  */
 /** @file
- */ 
+ */
 
 #ifndef LIBC_SYSINFO_H_
@@ -37,8 +37,14 @@
 
 #include <libc.h>
-#include <sysinfo.h>
-#include <str.h>
 
-sysarg_t sysinfo_value(const char *name);
+typedef enum {
+	SYSINFO_VAL_UNDEFINED = 0,
+	SYSINFO_VAL_VAL = 1,
+	SYSINFO_VAL_DATA = 2
+} sysinfo_item_tag_t;
+
+extern sysinfo_item_tag_t sysinfo_get_tag(const char *);
+extern int sysinfo_get_value(const char *, sysarg_t *);
+extern void *sysinfo_get_data(const char *, size_t *);
 
 #endif
Index: uspace/lib/c/include/task.h
===================================================================
--- uspace/lib/c/include/task.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/include/task.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -46,9 +46,8 @@
 
 extern task_id_t task_get_id(void);
-extern int task_set_name(const char *name);
-extern task_id_t task_spawn(const char *path, const char *const argv[]);
-extern int task_wait(task_id_t id, task_exit_t *texit, int *retval);
-extern int task_retval(int val);
-
+extern int task_set_name(const char *);
+extern task_id_t task_spawn(const char *, const char *const[], int *);
+extern int task_wait(task_id_t id, task_exit_t *, int *);
+extern int task_retval(int);
 
 #endif
Index: uspace/lib/c/include/vfs/vfs.h
===================================================================
--- uspace/lib/c/include/vfs/vfs.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/lib/c/include/vfs/vfs.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -43,5 +43,5 @@
 /**
  * This type is a libc version of the VFS triplet.
- * It uniquelly identifies a file system node within a file system instance.
+ * It uniquely identifies a file system node within a file system instance.
  */
 typedef struct {
Index: uspace/lib/clui/Makefile
===================================================================
--- uspace/lib/clui/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/clui/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,35 @@
+#
+# Copyright (c) 2010 Jiri Svoboda
+# 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.
+#
+
+USPACE_PREFIX = ../..
+LIBRARY = libclui
+
+SOURCES = \
+	tinput.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/clui/tinput.c
===================================================================
--- uspace/lib/clui/tinput.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/clui/tinput.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,710 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <str.h>
+#include <io/console.h>
+#include <io/keycode.h>
+#include <io/style.h>
+#include <io/color.h>
+#include <vfs/vfs.h>
+#include <clipboard.h>
+#include <macros.h>
+#include <errno.h>
+#include <assert.h>
+#include <bool.h>
+
+#include "tinput.h"
+
+/** Seek direction */
+typedef enum {
+	seek_backward = -1,
+	seek_forward = 1
+} seek_dir_t;
+
+static void tinput_init(tinput_t *ti);
+static void tinput_insert_string(tinput_t *ti, const char *str);
+static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb);
+static bool tinput_sel_active(tinput_t *ti);
+static void tinput_sel_all(tinput_t *ti);
+static void tinput_sel_delete(tinput_t *ti);
+static void tinput_key_ctrl(tinput_t *ti, console_event_t *ev);
+static void tinput_key_shift(tinput_t *ti, console_event_t *ev);
+static void tinput_key_ctrl_shift(tinput_t *ti, console_event_t *ev);
+static void tinput_key_unmod(tinput_t *ti, console_event_t *ev);
+static void tinput_pre_seek(tinput_t *ti, bool shift_held);
+static void tinput_post_seek(tinput_t *ti, bool shift_held);
+
+/** Create a new text input field. */
+tinput_t *tinput_new(void)
+{
+	tinput_t *ti;
+
+	ti = malloc(sizeof(tinput_t));
+	if (ti == NULL)
+		return NULL;
+
+	tinput_init(ti);
+	return ti;
+}
+
+/** Destroy text input field. */
+void tinput_destroy(tinput_t *ti)
+{
+	free(ti);
+}
+
+static void tinput_display_tail(tinput_t *ti, int start, int pad)
+{
+	static wchar_t dbuf[INPUT_MAX_SIZE + 1];
+	int sa, sb;
+	int i, p;
+
+	tinput_sel_get_bounds(ti, &sa, &sb);
+
+	console_goto(fphone(stdout), (ti->col0 + start) % ti->con_cols,
+	    ti->row0 + (ti->col0 + start) / ti->con_cols);
+	console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
+
+	p = start;
+	if (p < sa) {
+		memcpy(dbuf, ti->buffer + p, (sa - p) * sizeof(wchar_t));
+		dbuf[sa - p] = '\0';
+		printf("%ls", dbuf);
+		p = sa;
+	}
+
+	if (p < sb) {
+		fflush(stdout);
+		console_set_color(fphone(stdout), COLOR_BLACK, COLOR_RED, 0);
+		memcpy(dbuf, ti->buffer + p,
+		    (sb - p) * sizeof(wchar_t));
+		dbuf[sb - p] = '\0';
+		printf("%ls", dbuf);
+		p = sb;
+	}
+
+	fflush(stdout);
+	console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
+
+	if (p < ti->nc) {
+		memcpy(dbuf, ti->buffer + p,
+		    (ti->nc - p) * sizeof(wchar_t));
+		dbuf[ti->nc - p] = '\0';
+		printf("%ls", dbuf);
+	}
+
+	for (i = 0; i < pad; ++i)
+		putchar(' ');
+	fflush(stdout);
+}
+
+static char *tinput_get_str(tinput_t *ti)
+{
+	return wstr_to_astr(ti->buffer);
+}
+
+static void tinput_position_caret(tinput_t *ti)
+{
+	console_goto(fphone(stdout), (ti->col0 + ti->pos) % ti->con_cols,
+	    ti->row0 + (ti->col0 + ti->pos) / ti->con_cols);
+}
+
+/** Update row0 in case the screen could have scrolled. */
+static void tinput_update_origin(tinput_t *ti)
+{
+	int width, rows;
+
+	width = ti->col0 + ti->nc;
+	rows = (width / ti->con_cols) + 1;
+
+	/* Update row0 if the screen scrolled. */
+	if (ti->row0 + rows > ti->con_rows)
+		ti->row0 = ti->con_rows - rows;	
+}
+
+static void tinput_insert_char(tinput_t *ti, wchar_t c)
+{
+	int i;
+	int new_width, new_height;
+
+	if (ti->nc == INPUT_MAX_SIZE)
+		return;
+
+	new_width = ti->col0 + ti->nc + 1;
+	if (new_width % ti->con_cols == 0) {
+		/* Advancing to new line. */
+		new_height = (new_width / ti->con_cols) + 1;
+		if (new_height >= ti->con_rows)
+			return; /* Disallow text longer than 1 page for now. */
+	}
+
+	for (i = ti->nc; i > ti->pos; --i)
+		ti->buffer[i] = ti->buffer[i - 1];
+
+	ti->buffer[ti->pos] = c;
+	ti->pos += 1;
+	ti->nc += 1;
+	ti->buffer[ti->nc] = '\0';
+	ti->sel_start = ti->pos;
+
+	tinput_display_tail(ti, ti->pos - 1, 0);
+	tinput_update_origin(ti);
+	tinput_position_caret(ti);
+}
+
+static void tinput_insert_string(tinput_t *ti, const char *str)
+{
+	int i;
+	int new_width, new_height;
+	int ilen;
+	wchar_t c;
+	size_t off;
+
+	ilen = min((ssize_t) str_length(str), INPUT_MAX_SIZE - ti->nc);
+	if (ilen == 0)
+		return;
+
+	new_width = ti->col0 + ti->nc + ilen;
+	new_height = (new_width / ti->con_cols) + 1;
+	if (new_height >= ti->con_rows)
+		return; /* Disallow text longer than 1 page for now. */
+
+	for (i = ti->nc - 1; i >= ti->pos; --i)
+		ti->buffer[i + ilen] = ti->buffer[i];
+
+	off = 0; i = 0;
+	while (i < ilen) {
+		c = str_decode(str, &off, STR_NO_LIMIT);
+		if (c == '\0')
+			break;
+
+		/* Filter out non-printable chars. */
+		if (c < 32)
+			c = 32;
+
+		ti->buffer[ti->pos + i] = c;
+		++i;
+	}
+
+	ti->pos += ilen;
+	ti->nc += ilen;
+	ti->buffer[ti->nc] = '\0';
+	ti->sel_start = ti->pos;
+
+	tinput_display_tail(ti, ti->pos - ilen, 0);
+	tinput_update_origin(ti);
+	tinput_position_caret(ti);
+}
+
+static void tinput_backspace(tinput_t *ti)
+{
+	int i;
+
+	if (tinput_sel_active(ti)) {
+		tinput_sel_delete(ti);
+		return;
+	}
+
+	if (ti->pos == 0)
+		return;
+
+	for (i = ti->pos; i < ti->nc; ++i)
+		ti->buffer[i - 1] = ti->buffer[i];
+	ti->pos -= 1;
+	ti->nc -= 1;
+	ti->buffer[ti->nc] = '\0';
+	ti->sel_start = ti->pos;
+
+	tinput_display_tail(ti, ti->pos, 1);
+	tinput_position_caret(ti);
+}
+
+static void tinput_delete(tinput_t *ti)
+{
+	if (tinput_sel_active(ti)) {
+		tinput_sel_delete(ti);
+		return;
+	}
+
+	if (ti->pos == ti->nc)
+		return;
+
+	ti->pos += 1;
+	ti->sel_start = ti->pos;
+
+	tinput_backspace(ti);
+}
+
+static void tinput_seek_cell(tinput_t *ti, seek_dir_t dir, bool shift_held)
+{
+	tinput_pre_seek(ti, shift_held);
+
+	if (dir == seek_forward) {
+		if (ti->pos < ti->nc)
+			ti->pos += 1;
+	} else {
+		if (ti->pos > 0)
+			ti->pos -= 1;
+	}
+
+	tinput_post_seek(ti, shift_held);
+}
+
+static void tinput_seek_word(tinput_t *ti, seek_dir_t dir, bool shift_held)
+{
+	tinput_pre_seek(ti, shift_held);
+
+	if (dir == seek_forward) {
+		if (ti->pos == ti->nc)
+			return;
+
+		while (1) {
+			ti->pos += 1;
+
+			if (ti->pos == ti->nc)
+				break;
+
+			if (ti->buffer[ti->pos - 1] == ' ' &&
+			    ti->buffer[ti->pos] != ' ')
+				break;
+		}
+	} else {
+		if (ti->pos == 0)
+			return;
+
+		while (1) {
+			ti->pos -= 1;
+
+			if (ti->pos == 0)
+				break;
+
+			if (ti->buffer[ti->pos - 1] == ' ' &&
+			    ti->buffer[ti->pos] != ' ')
+				break;
+		}
+
+	}
+
+	tinput_post_seek(ti, shift_held);
+}
+
+static void tinput_seek_vertical(tinput_t *ti, seek_dir_t dir, bool shift_held)
+{
+	tinput_pre_seek(ti, shift_held);
+
+	if (dir == seek_forward) {
+		if (ti->pos + ti->con_cols <= ti->nc)
+			ti->pos = ti->pos + ti->con_cols;
+	} else {
+		if (ti->pos - ti->con_cols >= 0)
+			ti->pos = ti->pos - ti->con_cols;
+	}
+
+	tinput_post_seek(ti, shift_held);
+}
+
+static void tinput_seek_max(tinput_t *ti, seek_dir_t dir, bool shift_held)
+{
+	tinput_pre_seek(ti, shift_held);
+
+	if (dir == seek_backward)
+		ti->pos = 0;
+	else
+		ti->pos = ti->nc;
+
+	tinput_post_seek(ti, shift_held);
+}
+
+static void tinput_pre_seek(tinput_t *ti, bool shift_held)
+{
+	if (tinput_sel_active(ti) && !shift_held) {
+		/* Unselect and redraw. */
+		ti->sel_start = ti->pos;
+		tinput_display_tail(ti, 0, 0);
+		tinput_position_caret(ti);
+	}
+}
+
+static void tinput_post_seek(tinput_t *ti, bool shift_held)
+{
+	if (shift_held) {
+		/* Selecting text. Need redraw. */
+		tinput_display_tail(ti, 0, 0);
+	} else {
+		/* Shift not held. Keep selection empty. */
+		ti->sel_start = ti->pos;
+	}
+	tinput_position_caret(ti);
+}
+
+static void tinput_history_insert(tinput_t *ti, char *str)
+{
+	int i;
+
+	if (ti->hnum < HISTORY_LEN) {
+		ti->hnum += 1;
+	} else {
+		if (ti->history[HISTORY_LEN] != NULL)
+			free(ti->history[HISTORY_LEN]);
+	}
+
+	for (i = ti->hnum; i > 1; --i)
+		ti->history[i] = ti->history[i - 1];
+
+	ti->history[1] = str_dup(str);
+
+	if (ti->history[0] != NULL) {
+		free(ti->history[0]);
+		ti->history[0] = NULL;
+	}
+}
+
+static void tinput_set_str(tinput_t *ti, char *str)
+{
+	str_to_wstr(ti->buffer, INPUT_MAX_SIZE, str);
+	ti->nc = wstr_length(ti->buffer);
+	ti->pos = ti->nc;
+	ti->sel_start = ti->pos;
+}
+
+static void tinput_sel_get_bounds(tinput_t *ti, int *sa, int *sb)
+{
+	if (ti->sel_start < ti->pos) {
+		*sa = ti->sel_start;
+		*sb = ti->pos;
+	} else {
+		*sa = ti->pos;
+		*sb = ti->sel_start;
+	}
+}
+
+static bool tinput_sel_active(tinput_t *ti)
+{
+	return ti->sel_start != ti->pos;
+}
+
+static void tinput_sel_all(tinput_t *ti)
+{
+	ti->sel_start = 0;
+	ti->pos = ti->nc;
+	tinput_display_tail(ti, 0, 0);
+	tinput_position_caret(ti);
+}
+
+static void tinput_sel_delete(tinput_t *ti)
+{
+	int sa, sb;
+
+	tinput_sel_get_bounds(ti, &sa, &sb);
+	if (sa == sb)
+		return;
+
+	memmove(ti->buffer + sa, ti->buffer + sb,
+	    (ti->nc - sb) * sizeof(wchar_t));
+	ti->pos = ti->sel_start = sa;
+	ti->nc -= (sb - sa);
+	ti->buffer[ti->nc] = '\0';
+
+	tinput_display_tail(ti, sa, sb - sa);
+	tinput_position_caret(ti);
+}
+
+static void tinput_sel_copy_to_cb(tinput_t *ti)
+{
+	int sa, sb;
+	char *str;
+
+	tinput_sel_get_bounds(ti, &sa, &sb);
+
+	if (sb < ti->nc) {
+		wchar_t tmp_c = ti->buffer[sb];
+		ti->buffer[sb] = '\0';
+		str = wstr_to_astr(ti->buffer + sa);
+		ti->buffer[sb] = tmp_c;
+	} else
+		str = wstr_to_astr(ti->buffer + sa);
+	
+	if (str == NULL)
+		goto error;
+
+	if (clipboard_put_str(str) != EOK)
+		goto error;
+
+	free(str);
+	return;
+error:
+	return;
+	/* TODO: Give the user some warning. */
+}
+
+static void tinput_paste_from_cb(tinput_t *ti)
+{
+	char *str;
+	int rc;
+
+	rc = clipboard_get_str(&str);
+	if (rc != EOK || str == NULL)
+		return; /* TODO: Give the user some warning. */
+
+	tinput_insert_string(ti, str);
+	free(str);
+}
+
+static void tinput_history_seek(tinput_t *ti, int offs)
+{
+	int pad;
+
+	if (ti->hpos + offs < 0 || ti->hpos + offs > ti->hnum)
+		return;
+
+	if (ti->history[ti->hpos] != NULL) {
+		free(ti->history[ti->hpos]);
+		ti->history[ti->hpos] = NULL;
+	}
+
+	ti->history[ti->hpos] = tinput_get_str(ti);
+	ti->hpos += offs;
+
+	pad = ti->nc - str_length(ti->history[ti->hpos]);
+	if (pad < 0) pad = 0;
+
+	tinput_set_str(ti, ti->history[ti->hpos]);
+	tinput_display_tail(ti, 0, pad);
+	tinput_update_origin(ti);
+	tinput_position_caret(ti);
+}
+
+/** Initialize text input field.
+ *
+ * Must be called before using the field. It clears the history.
+ */
+static void tinput_init(tinput_t *ti)
+{
+	ti->hnum = 0;
+	ti->hpos = 0;
+	ti->history[0] = NULL;
+}
+
+/** Read in one line of input.
+ *
+ * @param ti	Text input.
+ * @param dstr	Place to save pointer to new string.
+ * @return	EOK on success, ENOENT if user requested abort, EIO
+ *		if communication with console failed.
+ */
+int tinput_read(tinput_t *ti, char **dstr)
+{
+	console_event_t ev;
+	char *str;
+
+	fflush(stdout);
+
+	if (console_get_size(fphone(stdin), &ti->con_cols, &ti->con_rows) != EOK)
+		return EIO;
+	if (console_get_pos(fphone(stdin), &ti->col0, &ti->row0) != EOK)
+		return EIO;
+
+	ti->pos = ti->sel_start = 0;
+	ti->nc = 0;
+	ti->buffer[0] = '\0';
+	ti->done = false;
+	ti->exit_clui = false;
+
+	while (!ti->done) {
+		fflush(stdout);
+		if (!console_get_event(fphone(stdin), &ev))
+			return EIO;
+
+		if (ev.type != KEY_PRESS)
+			continue;
+
+		if ((ev.mods & KM_CTRL) != 0 &&
+		    (ev.mods & (KM_ALT | KM_SHIFT)) == 0) {
+			tinput_key_ctrl(ti, &ev);
+		}
+
+		if ((ev.mods & KM_SHIFT) != 0 &&
+		    (ev.mods & (KM_CTRL | KM_ALT)) == 0) {
+			tinput_key_shift(ti, &ev);
+		}
+
+		if ((ev.mods & KM_CTRL) != 0 &&
+		    (ev.mods & KM_SHIFT) != 0 &&
+		    (ev.mods & KM_ALT) == 0) {
+			tinput_key_ctrl_shift(ti, &ev);
+		}
+
+		if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {
+			tinput_key_unmod(ti, &ev);
+		}
+
+		if (ev.c >= ' ') {
+			tinput_sel_delete(ti);
+			tinput_insert_char(ti, ev.c);
+		}
+	}
+
+	if (ti->exit_clui)
+		return ENOENT;
+
+	ti->pos = ti->nc;
+	tinput_position_caret(ti);
+	putchar('\n');
+
+	str = tinput_get_str(ti);
+	if (str_cmp(str, "") != 0)
+		tinput_history_insert(ti, str);
+
+	ti->hpos = 0;
+
+	*dstr = str;
+	return EOK;
+}
+
+static void tinput_key_ctrl(tinput_t *ti, console_event_t *ev)
+{
+	switch (ev->key) {
+	case KC_LEFT:
+		tinput_seek_word(ti, seek_backward, false);
+		break;
+	case KC_RIGHT:
+		tinput_seek_word(ti, seek_forward, false);
+		break;
+	case KC_UP:
+		tinput_seek_vertical(ti, seek_backward, false);
+		break;
+	case KC_DOWN:
+		tinput_seek_vertical(ti, seek_forward, false);
+		break;
+	case KC_X:
+		tinput_sel_copy_to_cb(ti);
+		tinput_sel_delete(ti);
+		break;
+	case KC_C:
+		tinput_sel_copy_to_cb(ti);
+		break;
+	case KC_V:
+		tinput_sel_delete(ti);
+		tinput_paste_from_cb(ti);
+		break;
+	case KC_A:
+		tinput_sel_all(ti);
+		break;
+	case KC_Q:
+		/* Signal libary client to quit interactive loop. */
+		ti->done = true;
+		ti->exit_clui = true;
+		break;
+	default:
+		break;
+	}
+}
+
+static void tinput_key_ctrl_shift(tinput_t *ti, console_event_t *ev)
+{
+	switch (ev->key) {
+	case KC_LEFT:
+		tinput_seek_word(ti, seek_backward, true);
+		break;
+	case KC_RIGHT:
+		tinput_seek_word(ti, seek_forward, true);
+		break;
+	case KC_UP:
+		tinput_seek_vertical(ti, seek_backward, true);
+		break;
+	case KC_DOWN:
+		tinput_seek_vertical(ti, seek_forward, true);
+		break;
+	default:
+		break;
+	}
+}
+
+static void tinput_key_shift(tinput_t *ti, console_event_t *ev)
+{
+	switch (ev->key) {
+	case KC_LEFT:
+		tinput_seek_cell(ti, seek_backward, true);
+		break;
+	case KC_RIGHT:
+		tinput_seek_cell(ti, seek_forward, true);
+		break;
+	case KC_UP:
+		tinput_seek_vertical(ti, seek_backward, true);
+		break;
+	case KC_DOWN:
+		tinput_seek_vertical(ti, seek_forward, true);
+		break;
+	case KC_HOME:
+		tinput_seek_max(ti, seek_backward, true);
+		break;
+	case KC_END:
+		tinput_seek_max(ti, seek_forward, true);
+		break;
+	default:
+		break;
+	}
+}
+
+static void tinput_key_unmod(tinput_t *ti, console_event_t *ev)
+{
+	switch (ev->key) {
+	case KC_ENTER:
+	case KC_NENTER:
+		ti->done = true;
+		break;
+	case KC_BACKSPACE:
+		tinput_backspace(ti);
+		break;
+	case KC_DELETE:
+		tinput_delete(ti);
+		break;
+	case KC_LEFT:
+		tinput_seek_cell(ti, seek_backward, false);
+		break;
+	case KC_RIGHT:
+		tinput_seek_cell(ti, seek_forward, false);
+		break;
+	case KC_HOME:
+		tinput_seek_max(ti, seek_backward, false);
+		break;
+	case KC_END:
+		tinput_seek_max(ti, seek_forward, false);
+		break;
+	case KC_UP:
+		tinput_history_seek(ti, +1);
+		break;
+	case KC_DOWN:
+		tinput_history_seek(ti, -1);
+		break;
+	default:
+		break;
+	}
+}
Index: uspace/lib/clui/tinput.h
===================================================================
--- uspace/lib/clui/tinput.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/clui/tinput.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2010 Jiri Svoboda
+ * 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 libclui
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#ifndef LIBCLUI_TINPUT_H_
+#define LIBCLUI_TINPUT_H_
+
+#define HISTORY_LEN 10
+#define INPUT_MAX_SIZE 1024
+
+/** Text input field (command line).
+ *
+ * Applications should treat this structure as opaque.
+ */
+typedef struct {
+	/** Buffer holding text currently being edited */
+	wchar_t buffer[INPUT_MAX_SIZE + 1];
+	/** Screen coordinates of the top-left corner of the text field */
+	int col0, row0;
+	/** Screen dimensions */
+	int con_cols, con_rows;
+	/** Number of characters in @c buffer */
+	int nc;
+	/** Caret position within buffer */
+	int pos;
+	/** Selection mark position within buffer */
+	int sel_start;
+
+	/** History (dynamically allocated strings) */
+	char *history[1 + HISTORY_LEN];
+	/** Number of entries in @c history, not counting [0] */
+	int hnum;
+	/** Current position in history */
+	int hpos;
+	/** @c true if finished with this line (return to caller) */
+	bool done;
+	/** @c true if user requested to abort interactive loop */
+	bool exit_clui;
+} tinput_t;
+
+extern tinput_t *tinput_new(void);
+extern void tinput_destroy(tinput_t *ti);
+extern int tinput_read(tinput_t *ti, char **str);
+
+#endif
+
+/** @}
+ */
+
Index: uspace/lib/net/Makefile
===================================================================
--- uspace/lib/net/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,50 @@
+#
+# Copyright (c) 2005 Martin Decky
+# Copyright (c) 2007 Jakub Jermar
+# 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.
+#
+
+USPACE_PREFIX = ../..
+EXTRA_CFLAGS = -Iinclude -I$(LIBSOCKET_PREFIX)/include
+LIBRARY = libnet
+
+SOURCES = \
+	generic/net_remote.c \
+	generic/net_checksum.c \
+	generic/packet_remote.c \
+	adt/module_map.c \
+	netif/netif_local.c \
+	netif/netif_remote.c \
+	netif/netif_nil_bundle.c \
+	nil/nil_remote.c \
+	il/ip_remote.c \
+	il/ip_client.c \
+	il/arp_remote.c \
+	tl/icmp_remote.c \
+	tl/icmp_client.c \
+	tl/tl_common.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/net/adt/module_map.c
===================================================================
--- uspace/lib/net/adt/module_map.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/adt/module_map.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -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 net
+ *  @{
+ */
+
+/** @file
+ *  Character string to module map implementation.
+ */
+
+#include <malloc.h>
+#include <task.h>
+#include <unistd.h>
+
+#include <ipc/services.h>
+
+#include <net_err.h>
+#include <net_modules.h>
+
+#include <adt/generic_char_map.h>
+#include <adt/module_map.h>
+
+GENERIC_CHAR_MAP_IMPLEMENT(modules, module_t)
+
+int add_module(module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id, connect_module_t connect_module){
+	ERROR_DECLARE;
+
+	module_ref tmp_module;
+
+	tmp_module = (module_ref) malloc(sizeof(module_t));
+	if(! tmp_module){
+		return ENOMEM;
+	}
+	tmp_module->task_id = task_id;
+	tmp_module->phone = 0;
+	tmp_module->usage = 0;
+	tmp_module->name = name;
+	tmp_module->filename = filename;
+	tmp_module->service = service;
+	tmp_module->connect_module = connect_module;
+	if(ERROR_OCCURRED(modules_add(modules, tmp_module->name, 0, tmp_module))){
+		free(tmp_module);
+		return ERROR_CODE;
+	}
+	if(module){
+		*module = tmp_module;
+	}
+	return EOK;
+}
+
+module_ref get_running_module(modules_ref modules, char * name){
+	module_ref module;
+
+	module = modules_find(modules, name, 0);
+	if(! module){
+		return NULL;
+	}
+	if(! module->task_id){
+		module->task_id = spawn(module->filename);
+		if(! module->task_id){
+			return NULL;
+		}
+	}
+	if(! module->phone){
+		module->phone = module->connect_module(module->service);
+	}
+	return module;
+}
+
+task_id_t spawn(const char *fname)
+{
+	const char *argv[2];
+	task_id_t res;
+	
+	argv[0] = fname;
+	argv[1] = NULL;
+	res = task_spawn(fname, argv, NULL);
+	
+	return res;
+}
+
+/** @}
+ */
Index: uspace/lib/net/generic/net_checksum.c
===================================================================
--- uspace/lib/net/generic/net_checksum.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/generic/net_checksum.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,171 @@
+/*
+ * 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
+ *  General CRC and checksum computation implementation.
+ */
+
+#include <sys/types.h>
+
+#include <net_checksum.h>
+
+/** Big-endian encoding CRC divider.
+ */
+#define CRC_DIVIDER_BE	0x04C11DB7
+
+/** Little-endian encoding CRC divider.
+ */
+#define CRC_DIVIDER_LE	0xEDB88320
+
+uint16_t compact_checksum(uint32_t sum){
+	// shorten to the 16 bits
+	while(sum >> 16){
+		sum = (sum &0xFFFF) + (sum >> 16);
+	}
+
+	return (uint16_t) sum;
+}
+
+uint32_t compute_checksum(uint32_t seed, uint8_t * data, size_t length){
+	size_t index;
+
+	// sum all the 16 bit fields
+	for(index = 0; index + 1 < length; index += 2){
+		seed += (data[index] << 8) + data[index + 1];
+	}
+
+	// last odd byte with zero padding
+	if(index + 1 == length){
+		seed += data[index] << 8;
+	}
+
+	return seed;
+}
+
+uint32_t compute_crc32_be(uint32_t seed, uint8_t * data, size_t length){
+	size_t index;
+
+	// process full bytes
+	while(length >= 8){
+		// add the data
+		seed ^= (*data) << 24;
+		// for each added bit
+		for(index = 0; index < 8; ++ index){
+			// if the first bit is set
+			if(seed &0x80000000){
+				// shift and divide the checksum
+				seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE);
+			}else{
+				// shift otherwise
+				seed <<= 1;
+			}
+		}
+		// move to the next byte
+		++ data;
+		length -= 8;
+	}
+
+	// process the odd bits
+	if(length > 0){
+		// add the data with zero padding
+		seed ^= ((*data) &(0xFF << (8 - length))) << 24;
+		// for each added bit
+		for(index = 0; index < length; ++ index){
+			// if the first bit is set
+			if(seed &0x80000000){
+				// shift and divide the checksum
+				seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE);
+			}else{
+				// shift otherwise
+				seed <<= 1;
+			}
+		}
+	}
+
+	return seed;
+}
+
+uint32_t compute_crc32_le(uint32_t seed, uint8_t * data, size_t length){
+	size_t index;
+
+	// process full bytes
+	while(length >= 8){
+		// add the data
+		seed ^= (*data);
+		// for each added bit
+		for(index = 0; index < 8; ++ index){
+			// if the last bit is set
+			if(seed &1){
+				// shift and divide the checksum
+				seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE);
+			}else{
+				// shift otherwise
+				seed >>= 1;
+			}
+		}
+		// move to the next byte
+		++ data;
+		length -= 8;
+	}
+
+	// process the odd bits
+	if(length > 0){
+		// add the data with zero padding
+		seed ^= (*data) >> (8 - length);
+		for(index = 0; index < length; ++ index){
+			// if the last bit is set
+			if(seed &1){
+				// shift and divide the checksum
+				seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE);
+			}else{
+				// shift otherwise
+				seed >>= 1;
+			}
+		}
+	}
+
+	return seed;
+}
+
+uint16_t flip_checksum(uint16_t checksum){
+	// flip, zero is returned as 0xFFFF (not flipped)
+	checksum = ~ checksum;
+	return checksum ? checksum : IP_CHECKSUM_ZERO;
+}
+
+uint16_t ip_checksum(uint8_t * data, size_t length){
+	// compute, compact and flip the data checksum
+	return flip_checksum(compact_checksum(compute_checksum(0, data, length)));
+}
+
+/** @}
+ */
Index: uspace/lib/net/generic/net_remote.c
===================================================================
--- uspace/lib/net/generic/net_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/generic/net_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,71 @@
+/*
+ * 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 interface implementation for remote modules.
+ *  @see net_interface.h
+ */
+
+#include <ipc/services.h>
+
+#include <malloc.h>
+
+#include <net_messages.h>
+#include <net_modules.h>
+#include <net_device.h>
+#include <net_interface.h>
+#include <adt/measured_strings.h>
+#include <net_net_messages.h>
+
+int net_connect_module(services_t service){
+	return connect_to_service(SERVICE_NETWORKING);
+}
+
+void net_free_settings(measured_string_ref settings, char * data){
+	if(settings){
+		free(settings);
+	}
+	if(data){
+		free(data);
+	}
+}
+
+int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){
+	return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, 0, 0, * configuration, count, configuration, data);
+}
+
+int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){
+	return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, device_id, 0, * configuration, count, configuration, data);
+}
+
+/** @}
+ */
Index: uspace/lib/net/generic/packet_remote.c
===================================================================
--- uspace/lib/net/generic/packet_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/generic/packet_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,156 @@
+/*
+ * 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 interface implementation for remote modules.
+ *  @see packet_client.h
+ */
+
+#include <async.h>
+#include <errno.h>
+#include <ipc/ipc.h>
+#include <sys/mman.h>
+
+#include <net_err.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_remote.h>
+
+/** Obtain the packet from the packet server as the shared memory block.
+ *
+ * Create the local packet mapping as well.
+ *
+ * @param[in]  phone     The packet server module phone.
+ * @param[out] packet    The packet reference pointer to store the received
+ *                       packet reference.
+ * @param[in]  packet_id The packet identifier.
+ * @param[in]  size      The packet total size in bytes.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for the pm_add() function.
+ * @return Other error codes as defined for the async_share_in_start() function.
+ *
+ */
+static int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size){
+	ERROR_DECLARE;
+	
+	ipc_call_t answer;
+	aid_t message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
+	*packet = (packet_t) as_get_mappable_page(size);
+	if (ERROR_OCCURRED(async_share_in_start_0_0(phone, *packet, size))
+	    || ERROR_OCCURRED(pm_add(*packet))) {
+		munmap(*packet, size);
+		async_wait_for(message, NULL);
+		return ERROR_CODE;
+	}
+	
+	ipcarg_t result;
+	async_wait_for(message, &result);
+	
+	return result;
+}
+
+int packet_translate_remote(int phone, packet_ref packet, packet_id_t packet_id)
+{
+	ERROR_DECLARE;
+	
+	if (!packet)
+		return EINVAL;
+	
+	*packet = pm_find(packet_id);
+	if (!(*packet)) {
+		ipcarg_t size;
+		
+		ERROR_PROPAGATE(async_req_1_1(phone, NET_PACKET_GET_SIZE, packet_id, &size));
+		ERROR_PROPAGATE(packet_return(phone, packet, packet_id, size));
+	}
+	if ((** packet).next) {
+		packet_t next;
+		
+		return packet_translate_remote(phone, &next, (** packet).next);
+	}
+	
+	return EOK;
+}
+
+packet_t packet_get_4_remote(int phone, size_t max_content, size_t addr_len,
+    size_t max_prefix, size_t max_suffix)
+{
+	ERROR_DECLARE;
+	
+	ipcarg_t packet_id;
+	ipcarg_t size;
+	
+	if (ERROR_OCCURRED(async_req_4_2(phone, NET_PACKET_CREATE_4, max_content,
+	    addr_len, max_prefix, max_suffix, &packet_id, &size)))
+		return NULL;
+	
+	
+	packet_t packet = pm_find(packet_id);
+	if (!packet) {
+		if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size)))
+			return NULL;
+	}
+	
+	return packet;
+}
+
+packet_t packet_get_1_remote(int phone, size_t content)
+{
+	ERROR_DECLARE;
+	
+	ipcarg_t packet_id;
+	ipcarg_t size;
+	
+	if (ERROR_OCCURRED(async_req_1_2(phone, NET_PACKET_CREATE_1, content,
+	    &packet_id, &size)))
+		return NULL;
+	
+	packet_t packet = pm_find(packet_id);
+	if (!packet) {
+		if (ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size)))
+			return NULL;
+	}
+	
+	return packet;
+}
+
+void pq_release_remote(int phone, packet_id_t packet_id)
+{
+	async_msg_1(phone, NET_PACKET_RELEASE, packet_id);
+}
+
+/** @}
+ */
Index: uspace/lib/net/il/arp_remote.c
===================================================================
--- uspace/lib/net/il/arp_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/il/arp_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,94 @@
+/*
+ * 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 arp
+ *  @{
+ */
+
+/** @file
+ *  ARP interface implementation for remote modules.
+ *  @see arp_interface.h
+ */
+
+#include <async.h>
+#include <errno.h>
+#include <ipc/ipc.h>
+#include <ipc/services.h>
+
+#include <net_messages.h>
+#include <net_modules.h>
+#include <net_device.h>
+#include <arp_interface.h>
+#include <adt/measured_strings.h>
+#include <arp_messages.h>
+
+int arp_connect_module(services_t service){
+	if(service != SERVICE_ARP){
+		return EINVAL;
+	}
+	return connect_to_service(SERVICE_ARP);
+}
+
+int arp_clean_cache_req(int arp_phone){
+	return (int) async_req_0_0(arp_phone, NET_ARP_CLEAN_CACHE);
+}
+
+int arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address){
+	aid_t message_id;
+	ipcarg_t result;
+
+	message_id = async_send_2(arp_phone, NET_ARP_CLEAR_ADDRESS, (ipcarg_t) device_id, protocol, NULL);
+	measured_strings_send(arp_phone, address, 1);
+	async_wait_for(message_id, &result);
+	return (int) result;
+}
+
+int arp_clear_device_req(int arp_phone, device_id_t device_id){
+	return (int) async_req_1_0(arp_phone, NET_ARP_CLEAR_DEVICE, (ipcarg_t) device_id);
+}
+
+int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){
+	aid_t message_id;
+	ipcarg_t result;
+
+	message_id = async_send_3(arp_phone, NET_ARP_DEVICE, (ipcarg_t) device_id, protocol, netif, NULL);
+	measured_strings_send(arp_phone, address, 1);
+	async_wait_for(message_id, &result);
+	return (int) result;
+}
+
+task_id_t arp_task_get_id(void){
+	return 0;
+}
+
+int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data){
+	return generic_translate_req(arp_phone, NET_ARP_TRANSLATE, device_id, protocol, address, 1, translation, data);
+}
+
+/** @}
+ */
Index: uspace/lib/net/il/ip_client.c
===================================================================
--- uspace/lib/net/il/ip_client.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/il/ip_client.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,184 @@
+/*
+ * 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 ip
+ *  @{
+ */
+
+/** @file
+ *  IP client interface implementation.
+ *  @see ip_client.h
+ */
+
+#include <errno.h>
+#include <sys/types.h>
+
+#include <ip_client.h>
+#include <socket_errno.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+#include <ip_header.h>
+
+size_t ip_client_header_length(packet_t packet){
+	ip_header_ref header;
+
+	header = (ip_header_ref) packet_get_data(packet);
+	if((! header)
+		|| (packet_get_data_length(packet) < sizeof(ip_header_t))){
+		return 0;
+	}
+	return IP_HEADER_LENGTH(header);
+}
+
+int ip_client_get_pseudo_header(ip_protocol_t protocol, struct sockaddr * src, socklen_t srclen, struct sockaddr * dest, socklen_t destlen, size_t data_length, void **header, size_t * headerlen){
+	ipv4_pseudo_header_ref header_in;
+	struct sockaddr_in * address_in;
+
+	if(!(header && headerlen)){
+		return EBADMEM;
+	}
+	if(!(src && dest && (srclen > 0) && ((size_t) srclen >= sizeof(struct sockaddr)) && (srclen == destlen) && (src->sa_family == dest->sa_family))){
+		return EINVAL;
+	}
+
+	switch(src->sa_family){
+		case AF_INET:
+			if(srclen != sizeof(struct sockaddr_in)){
+				return EINVAL;
+			}
+			*headerlen = sizeof(*header_in);
+			header_in = (ipv4_pseudo_header_ref) malloc(*headerlen);
+			if(! header_in){
+				return ENOMEM;
+			}
+			bzero(header_in, * headerlen);
+			address_in = (struct sockaddr_in *) dest;
+			header_in->destination_address = address_in->sin_addr.s_addr;
+			address_in = (struct sockaddr_in *) src;
+			header_in->source_address = address_in->sin_addr.s_addr;
+			header_in->protocol = protocol;
+			header_in->data_length = htons(data_length);
+			*header = header_in;
+			return EOK;
+		// TODO IPv6
+/*		case AF_INET6:
+			if(addrlen != sizeof(struct sockaddr_in6)){
+				return EINVAL;
+			}
+			address_in6 = (struct sockaddr_in6 *) addr;
+			return EOK;
+*/		default:
+			return EAFNOSUPPORT;
+	}
+}
+
+int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length){
+	ip_header_ref header;
+	uint8_t * data;
+	size_t padding;
+
+	// compute the padding if IP options are set
+	// multiple of 4 bytes
+	padding =  ipopt_length % 4;
+	if(padding){
+		padding = 4 - padding;
+		ipopt_length += padding;
+	}
+
+	// prefix the header
+	data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding);
+	if(! data){
+		return ENOMEM;
+	}
+
+	// add the padding
+	while(padding --){
+		data[sizeof(ip_header_t) + padding] = IPOPT_NOOP;
+	}
+
+	// set the header
+	header = (ip_header_ref) data;
+	header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + ipopt_length);
+	header->ttl = (ttl ? ttl : IPDEFTTL); //(((ttl) <= MAXTTL) ? ttl : MAXTTL) : IPDEFTTL;
+	header->tos = tos;
+	header->protocol = protocol;
+
+	if(dont_fragment){
+		header->flags = IPFLAG_DONT_FRAGMENT;
+	}
+	return EOK;
+}
+
+int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length){
+	ip_header_ref header;
+
+	header = (ip_header_ref) packet_get_data(packet);
+	if((! header)
+		|| (packet_get_data_length(packet) < sizeof(ip_header_t))){
+		return ENOMEM;
+	}
+
+	if(protocol){
+		*protocol = header->protocol;
+	}
+	if(ttl){
+		*ttl = header->ttl;
+	}
+	if(tos){
+		*tos = header->tos;
+	}
+	if(dont_fragment){
+		*dont_fragment = header->flags &IPFLAG_DONT_FRAGMENT;
+	}
+	if(ipopt_length){
+		*ipopt_length = IP_HEADER_LENGTH(header) - sizeof(ip_header_t);
+		return sizeof(ip_header_t);
+	}else{
+		return IP_HEADER_LENGTH(header);
+	}
+}
+
+int ip_client_set_pseudo_header_data_length(void *header, size_t headerlen, size_t data_length){
+	ipv4_pseudo_header_ref header_in;
+
+	if(! header){
+		return EBADMEM;
+	}
+
+	if(headerlen == sizeof(ipv4_pseudo_header_t)){
+		header_in = (ipv4_pseudo_header_ref) header;
+		header_in->data_length = htons(data_length);
+		return EOK;
+	// TODO IPv6
+	}else{
+		return EINVAL;
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/net/il/ip_remote.c
===================================================================
--- uspace/lib/net/il/ip_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/il/ip_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,238 @@
+/*
+ * 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 ip
+ * @{
+ */
+
+/** @file
+ *
+ * IP interface implementation for remote modules.
+ *
+ * @see ip_interface.h
+ * @see il_interface.h
+ *
+ */
+
+#include <ipc/services.h>
+
+#include <net_messages.h>
+#include <net_modules.h>
+#include <net_device.h>
+#include <inet.h>
+#include <ip_interface.h>
+#include <packet/packet_client.h>
+#include <il_messages.h>
+#include <ip_messages.h>
+#include <ip_remote.h>
+
+/** Add a route to the device routing table.
+ *
+ * The target network is routed using this device.
+ *
+ * @param[in] ip_phone  The IP module phone used for (semi)remote calls.
+ * @param[in] device_id The device identifier.
+ * @param[in] address   The target network address.
+ * @param[in] netmask   The target network mask.
+ * @param[in] gateway   The target network gateway. Not used if zero.
+ *
+ */
+int ip_add_route_req_remote(int ip_phone, device_id_t device_id,
+    in_addr_t address, in_addr_t netmask, in_addr_t gateway)
+{
+	return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE,
+	    (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr,
+	    (ipcarg_t) address.s_addr, (ipcarg_t) netmask.s_addr);
+}
+
+int ip_bind_service(services_t service, int protocol, services_t me,
+    async_client_conn_t receiver, tl_received_msg_t tl_received_msg)
+{
+	return (int) bind_service(service, (ipcarg_t) protocol, me, service,
+	    receiver);
+}
+
+int ip_connect_module(services_t service)
+{
+	return connect_to_service(SERVICE_IP);
+}
+
+/** Register the new device.
+ *
+ * Register itself as the ip packet receiver.
+ * If the device uses ARP registers also the new ARP device.
+ *
+ * @param[in] ip_phone  The IP module phone used for (semi)remote calls.
+ * @param[in] device_id The new device identifier.
+ * @param[in] netif     The underlying device network interface layer service.
+ *
+ * @return EOK on success.
+ * @return ENOMEM if there is not enough memory left.
+ * @return EINVAL if the device configuration is invalid.
+ * @return ENOTSUP if the device uses IPv6.
+ * @return ENOTSUP if the device uses DHCP.
+ * @return Other error codes as defined for the net_get_device_conf_req()
+ *         function.
+ * @return Other error codes as defined for the arp_device_req() function.
+ *
+ */
+int ip_device_req_remote(int ip_phone, device_id_t device_id,
+    services_t service)
+{
+	return generic_device_req_remote(ip_phone, NET_IL_DEVICE, device_id, 0,
+	    service);
+}
+
+/** Return the device identifier and the IP pseudo header based on the destination address.
+ *
+ * @param[in]  ip_phone    The IP module phone used for (semi)remote calls.
+ * @param[in]  protocol    The transport protocol.
+ * @param[in]  destination The destination address.
+ * @param[in]  addrlen     The destination address length.
+ * @param[out] device_id   The device identifier.
+ * @param[out] header      The constructed IP pseudo header.
+ * @param[out] headerlen   The IP pseudo header length.
+ *
+ */
+int ip_get_route_req_remote(int ip_phone, ip_protocol_t protocol,
+    const struct sockaddr *destination, socklen_t addrlen,
+    device_id_t *device_id, void **header, size_t *headerlen)
+{
+	if ((!destination) || (addrlen == 0))
+		return EINVAL;
+	
+	if ((!device_id) || (header) || (headerlen))
+		return EBADMEM;
+	
+	*header = NULL;
+	
+	ipc_call_t answer;
+	aid_t message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE,
+	    (ipcarg_t) protocol, &answer);
+	
+	if ((async_data_write_start(ip_phone, destination, addrlen) == EOK)
+	    && (async_data_read_start(ip_phone, headerlen, sizeof(*headerlen)) == EOK)
+	    && (*headerlen > 0)) {
+		*header = malloc(*headerlen);
+		if (*header) {
+			if (async_data_read_start(ip_phone, *header, *headerlen) != EOK)
+				free(*header);
+		}
+	}
+	
+	ipcarg_t result;
+	async_wait_for(message_id, &result);
+	
+	if ((result != EOK) && (*header))
+		free(*header);
+	else
+		*device_id = IPC_GET_DEVICE(&answer);
+	
+	return (int) result;
+}
+
+/** Return the device packet dimension for sending.
+ *
+ * @param[in]  ip_phone         The IP module phone used for (semi)remote calls.
+ * @param[in]  device_id        The device identifier.
+ * @param[out] packet_dimension The packet dimension.
+ *
+ * @return EOK on success.
+ * @return ENOENT if there is no such device.
+ * @return Other error codes as defined for the
+ *         generic_packet_size_req_remote() function.
+ *
+ */
+int ip_packet_size_req_remote(int ip_phone, device_id_t device_id,
+    packet_dimension_ref packet_dimension)
+{
+	return generic_packet_size_req_remote(ip_phone, NET_IL_PACKET_SPACE, device_id,
+	    packet_dimension);
+}
+
+/** Notify the IP module about the received error notification packet.
+ *
+ * @param[in] ip_phone  The IP module phone used for (semi)remote calls.
+ * @param[in] device_id The device identifier.
+ * @param[in] packet    The received packet or the received packet queue.
+ * @param[in] target    The target internetwork module service to be
+ *                      delivered to.
+ * @param[in] error     The packet error reporting service. Prefixes the
+ *                      received packet.
+ *
+ * @return EOK on success.
+ *
+ */
+int ip_received_error_msg_remote(int ip_phone, device_id_t device_id,
+    packet_t packet, services_t target, services_t error)
+{
+	return generic_received_msg_remote(ip_phone, NET_IP_RECEIVED_ERROR,
+	    device_id, packet_get_id(packet), target, error);
+}
+
+/** Send the packet queue.
+ *
+ * The packets may get fragmented if needed.
+ *
+ * @param[in] ip_phone  The IP module phone used for (semi)remote calls.
+ * @param[in] device_id The device identifier.
+ * @param[in] packet    The packet fragments as a packet queue. All the
+ *                      packets have to have the same destination address.
+ * @param[in] sender    The sending module service.
+ * @param[in] error     The packet error reporting service. Prefixes the
+ *                      received packet.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for the generic_send_msg() function.
+ *
+ */
+int ip_send_msg_remote(int ip_phone, device_id_t device_id, packet_t packet,
+    services_t sender, services_t error)
+{
+	return generic_send_msg_remote(ip_phone, NET_IL_SEND, device_id,
+	    packet_get_id(packet), sender, error);
+}
+
+/** Set the default gateway.
+ *
+ * This gateway is used if no other route is found.
+ *
+ * @param[in] ip_phone  The IP module phone used for (semi)remote calls.
+ * @param[in] device_id The device identifier.
+ * @param[in] gateway   The default gateway.
+ *
+ */
+int ip_set_gateway_req_remote(int ip_phone, device_id_t device_id,
+    in_addr_t gateway)
+{
+	return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY,
+	    (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr);
+}
+
+/** @}
+ */
Index: uspace/lib/net/include/adt/module_map.h
===================================================================
--- uspace/lib/net/include/adt/module_map.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/adt/module_map.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -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 net
+ *  @{
+ */
+
+/** @file
+ *  Character string to module map.
+ */
+
+#ifndef __NET_MODULES_MAP_H__
+#define __NET_MODULES_MAP_H__
+
+#include <task.h>
+
+#include <ipc/services.h>
+
+#include <net_modules.h>
+
+#include <adt/generic_char_map.h>
+
+/** Type definition of the module structure.
+ *  @see module_struct
+ */
+typedef struct module_struct	module_t;
+
+/** Type definition of the module structure pointer.
+ *  @see module_struct
+ */
+typedef module_t *				module_ref;
+
+/** Module map.
+ *  Sorted by module names.
+ *  @see generic_char_map.h
+ */
+GENERIC_CHAR_MAP_DECLARE(modules, module_t)
+
+/** Module structure.
+ */
+struct	module_struct{
+	/** Module task identifier if running.
+	 */
+	task_id_t task_id;
+	/** Module service identifier.
+	 */
+	services_t service;
+	/** Module phone if running and connected.
+	 */
+	int phone;
+	/** Usage counter.
+	 */
+	int usage;
+	/** Module name.
+	 */
+	const char * name;
+	/** Module full path filename.
+	 */
+	const char * filename;
+	/** Connecting function.
+	 */
+	connect_module_t * connect_module;
+};
+
+/** Adds module to the module map.
+ *  @param[out] module The module structure added.
+ *  @param[in] modules The module map.
+ *  @param[in] name The module name.
+ *  @param[in] filename The full path filename.
+ *  @param[in] service The module service.
+ *  @param[in] task_id The module current task identifier. Zero (0) means not running.
+ *  @param[in] connect_module The module connecting function.
+ *  @returns EOK on success.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+int add_module(module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id, connect_module_t * connect_module);
+
+/** Searches and returns the specified module.
+ *  If the module is not running, the module filaname is spawned.
+ *  If the module is not connected, the connect_function is called.
+ *  @param[in] modules The module map.
+ *  @param[in] name The module name.
+ *  @returns The running module found. It does not have to be connected.
+ *  @returns NULL if there is no such module.
+ */
+module_ref get_running_module(modules_ref modules, char * name);
+
+/** Starts the given module.
+ *  @param[in] fname The module full or relative path filename.
+ *  @returns The new module task identifier on success.
+ *  @returns 0 if there is no such module.
+ */
+task_id_t spawn(const char * fname);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/arp_interface.h
===================================================================
--- uspace/lib/net/include/arp_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/arp_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,121 @@
+/*
+ * 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 arp
+ *  @{
+ */
+
+#ifndef __NET_ARP_INTERFACE_H__
+#define __NET_ARP_INTERFACE_H__
+
+#include <adt/measured_strings.h>
+#include <net_device.h>
+
+/** @name ARP module interface
+ *  This interface is used by other modules.
+ */
+/*@{*/
+
+/** Registers the new device and the requesting protocol service.
+ *  Connects to the network interface layer service.
+ *  Determines the device broadcast address, its address lengths and packet size.
+ *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
+ *  @param[in] device_id The new device identifier.
+ *  @param[in] protocol The requesting protocol service.
+ *  @param[in] netif The underlying device network interface layer service.
+ *  @param[in] address The local requesting protocol address of the device.
+ *  @returns EOK on success.
+ *  @returns EEXIST if the device is already used.
+ *  @returns ENOMEM if there is not enough memory left.
+ *  @returns ENOENT if the network interface service is not known.
+ *  @returns EREFUSED if the network interface service is not responding.
+ *  @returns Other error codes as defined for the nil_packet_get_size() function.
+ *  @returns Other error codes as defined for the nil_get_addr() function.
+ *  @returns Other error codes as defined for the nil_get_broadcast_addr() function.
+ */
+extern int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address);
+
+/** Translates the given protocol address to the network interface address.
+ *  Broadcasts the ARP request if the mapping is not found.
+ *  Allocates and returns the needed memory block as the data parameter.
+ *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
+ *  @param[in] device_id The device identifier.
+ *  @param[in] protocol The requesting protocol service.
+ *  @param[in] address The local requesting protocol address.
+ *  @param[out] translation The translation of the local protocol address.
+ *  @param[out] data The allocated raw translation data container.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the address parameter is NULL.
+ *  @returns EBADMEM if the translation or the data parameters are NULL.
+ *  @returns ENOENT if the mapping is not found.
+ */
+extern int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data);
+
+/** Clears the device cache.
+ *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
+ *  @param[in] device_id The device identifier.
+ *  @returns EOK on success.
+ *  @returns ENOENT if the device is not found.
+ */
+extern int arp_clear_device_req(int arp_phone, device_id_t device_id);
+
+/** Clears the given protocol address from the cache.
+ *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
+ *  @param[in] device_id The device identifier.
+ *  @param[in] protocol The requesting protocol service.
+ *  @param[in] address The protocol address to be cleared.
+ *  @returns EOK on success.
+ *  @returns ENOENT if the mapping is not found.
+ */
+extern int arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address);
+
+/** Cleans the cache.
+ *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
+ *  @returns EOK on success.
+ */
+extern int arp_clean_cache_req(int arp_phone);
+
+/** Connects to the ARP module.
+ *  @param service The ARP module service. Ignored parameter.
+ *  @returns The ARP module phone on success.
+ *  @returns 0 if called by the bundle module.
+ */
+extern int arp_connect_module(services_t service);
+
+/** Returns the ARP task identifier.
+ *  @returns The current task identifier if called by the bundle module.
+ *  @returns 0 if called by the remote module.
+ */
+extern task_id_t arp_task_get_id(void);
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/arp_messages.h
===================================================================
--- uspace/lib/net/include/arp_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/arp_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,85 @@
+/*
+ * 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 arp
+ *  @{
+ */
+
+/** @file
+ *  ARP module messages.
+ *  @see arp_interface.h
+ */
+
+#ifndef __NET_ARP_MESSAGES__
+#define __NET_ARP_MESSAGES__
+
+#include <ipc/ipc.h>
+
+#include <net_messages.h>
+
+/** ARP module messages.
+ */
+typedef enum{
+	/** Clean cache message.
+	 *  @see arp_clean_cache()
+	 */
+	NET_ARP_CLEAN_CACHE = NET_ARP_FIRST,
+	/** Clear address cache message.
+	 *  @see arp_clear_address_msg()
+	 */
+	NET_ARP_CLEAR_ADDRESS,
+	/** Clear device cache message.
+	 *  @see arp_clear_device_req()
+	 */
+	NET_ARP_CLEAR_DEVICE,
+	/** New device message.
+	 *  @see arp_device_req()
+	 */
+	NET_ARP_DEVICE,
+	/** Address translation message.
+	 *  @see arp_translate_req()
+	 */
+	NET_ARP_TRANSLATE
+} arp_messages;
+
+/** @name ARP specific message parameters definitions
+ */
+/*@{*/
+
+/** Returns the protocol service message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define ARP_GET_NETIF(call) \
+	({services_t service = (services_t) IPC_GET_ARG2(*call); service;})
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/ethernet_lsap.h
===================================================================
--- uspace/lib/net/include/ethernet_lsap.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/ethernet_lsap.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,137 @@
+/*
+ * 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 eth
+ *  @{
+ */
+
+/** @file
+ *  Link service access point identifiers.
+ */
+
+#ifndef __NET_ETHERNET_LSAP_H__
+#define __NET_ETHERNET_LSAP_H__
+
+#include <sys/types.h>
+
+/** Ethernet LSAP type definition.
+ */
+typedef uint8_t	eth_lsap_t;
+
+/** @name Ethernet LSAP values definitions
+ */
+/*@{*/
+
+/** Null LSAP LSAP identifier.
+ */
+#define ETH_LSAP_NULL	0x00
+/** Individual LLC Sublayer Management Function LSAP identifier.
+ */
+#define ETH_LSAP_ISLMF	0x02
+/** Group LLC Sublayer Management Function LSAP identifier.
+ */
+#define ETH_LSAP_GSLMI	0x03
+/** IBM SNA Path Control (individual) LSAP identifier.
+ */
+#define ETH_LSAP_ISNA	0x04
+/** IBM SNA Path Control (group) LSAP identifier.
+ */
+#define ETH_LSAP_GSNA	0x05
+/** ARPANET Internet Protocol (IP) LSAP identifier.
+ */
+#define ETH_LSAP_IP	0x06
+/** SNA LSAP identifier.
+ */
+#define ETH_LSAP_SNA	0x08
+/** SNA LSAP identifier.
+ */
+#define ETH_LSAP_SNA2	0x0C
+/** PROWAY (IEC955) Network Management &Initialization LSAP identifier.
+ */
+#define ETH_LSAP_PROWAY_NMI	0x0E
+/** Texas Instruments LSAP identifier.
+ */
+#define ETH_LSAP_TI	0x18
+/** IEEE 802.1 Bridge Spanning Tree Protocol LSAP identifier.
+ */
+#define ETH_LSAP_BRIDGE	0x42
+/** EIA RS-511 Manufacturing Message Service LSAP identifier.
+ */
+#define ETH_LSAP_EIS	0x4E
+/** ISO 8208 (X.25 over IEEE 802.2 Type 2 LLC) LSAP identifier.
+ */
+#define ETH_LSAP_ISO8208	0x7E
+/** Xerox Network Systems (XNS) LSAP identifier.
+ */
+#define ETH_LSAP_XNS	0x80
+/** Nestar LSAP identifier.
+ */
+#define ETH_LSAP_NESTAR	0x86
+/** PROWAY (IEC 955) Active Station List Maintenance LSAP identifier.
+ */
+#define ETH_LSAP_PROWAY_ASLM	0x8E
+/** ARPANET Address Resolution Protocol (ARP) LSAP identifier.
+ */
+#define ETH_LSAP_ARP	0x98
+/** Banyan VINES LSAP identifier.
+ */
+#define ETH_LSAP_VINES	0xBC
+/** SubNetwork Access Protocol (SNAP) LSAP identifier.
+ */
+#define ETH_LSAP_SNAP	0xAA
+/** Novell NetWare LSAP identifier.
+ */
+#define ETH_LSAP_NETWARE	0xE0
+/** IBM NetBIOS LSAP identifier.
+ */
+#define ETH_LSAP_NETBIOS	0xF0
+/** IBM LAN Management (individual) LSAP identifier.
+ */
+#define ETH_LSAP_ILAN	0xF4
+/** IBM LAN Management (group) LSAP identifier.
+ */
+#define ETH_LSAP_GLAN	0xF5
+/** IBM Remote Program Load (RPL) LSAP identifier.
+ */
+#define ETH_LSAP_RPL	0xF8
+/** Ungermann-Bass LSAP identifier.
+ */
+#define ETH_LSAP_UB	0xFA
+/** ISO Network Layer Protocol LSAP identifier.
+ */
+#define ETH_LSAP_ISONLP	0xFE
+/** Global LSAP LSAP identifier.
+ */
+#define ETH_LSAP_GLSAP	0xFF
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/ethernet_protocols.h
===================================================================
--- uspace/lib/net/include/ethernet_protocols.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/ethernet_protocols.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1012 @@
+/*
+ * 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 eth
+ *  @{
+ */
+
+/** @file
+ *  Ethernet protocol numbers according to the on-line IANA - Ethernet numbers - <http://www.iana.org/assignments/ethernet-numbers>, cited January 17 2009.
+ */
+
+#ifndef __NET_ETHERNET_PROTOCOLS_H__
+#define __NET_ETHERNET_PROTOCOLS_H__
+
+#include <sys/types.h>
+
+/** Ethernet protocol type definition.
+ */
+typedef uint16_t	eth_type_t;
+
+/** @name Ethernet protocols definitions
+ */
+/*@{*/
+
+/** Ethernet minimal protocol number.
+ *  According to the IEEE 802.3 specification.
+ */
+#define ETH_MIN_PROTO	0x0600 /*1536*/
+
+/** Ethernet loopback packet protocol type.
+ */
+#define ETH_P_LOOP		0x0060
+
+/** XEROX PUP (see 0A00) ethernet protocol type.
+ */
+#define ETH_P_PUP		0x0200
+
+/** PUP Addr Trans (see 0A01) ethernet protocol type.
+ */
+#define ETH_P_PUPAT		0x0201
+
+/** Nixdorf ethernet protocol type.
+ */
+#define ETH_P_Nixdorf		0x0400
+
+/** XEROX NS IDP ethernet protocol type.
+ */
+#define ETH_P_XEROX_NS_IDP		0x0600
+
+/** DLOG ethernet protocol type.
+ */
+#define ETH_P_DLOG		0x0660
+
+/** DLOG ethernet protocol type.
+ */
+#define ETH_P_DLOG2		0x0661
+
+/** Internet IP (IPv4) ethernet protocol type.
+ */
+#define ETH_P_IP		0x0800
+
+/** X.75 Internet ethernet protocol type.
+ */
+#define ETH_P_X_75		0x0801
+
+/** NBS Internet ethernet protocol type.
+ */
+#define ETH_P_NBS		0x0802
+
+/** ECMA Internet ethernet protocol type.
+ */
+#define ETH_P_ECMA		0x0803
+
+/** Chaosnet ethernet protocol type.
+ */
+#define ETH_P_Chaosnet		0x0804
+
+/** X.25 Level 3 ethernet protocol type.
+ */
+#define ETH_P_X25		0x0805
+
+/** ARP ethernet protocol type.
+ */
+#define ETH_P_ARP		0x0806
+
+/** XNS Compatability ethernet protocol type.
+ */
+#define ETH_P_XNS_Compatability		0x0807
+
+/** Frame Relay ARP ethernet protocol type.
+ */
+#define ETH_P_Frame_Relay_ARP		0x0808
+
+/** Symbolics Private ethernet protocol type.
+ */
+#define ETH_P_Symbolics_Private		0x081C
+
+/** Xyplex ethernet protocol type.
+ */
+#define ETH_P_Xyplex_MIN		0x0888
+
+/** Xyplex ethernet protocol type.
+ */
+#define ETH_P_Xyplex_MAX		0x088A
+
+/** Ungermann-Bass net debugr ethernet protocol type.
+ */
+#define ETH_P_Ungermann_Bass_net_debugr		0x0900
+
+/** Xerox IEEE802.3 PUP ethernet protocol type.
+ */
+#define ETH_P_IEEEPUP		0x0A00
+
+/** PUP Addr Trans ethernet protocol type.
+ */
+#define ETH_P_IEEEPUPAT		0x0A01
+
+/** Banyan VINES ethernet protocol type.
+ */
+#define ETH_P_Banyan_VINES		0x0BAD
+
+/** VINES Loopback ethernet protocol type.
+ */
+#define ETH_P_VINES_Loopback		0x0BAE
+
+/** VINES Echo ethernet protocol type.
+ */
+#define ETH_P_VINES_Echo		0x0BAF
+
+/** Berkeley Trailer nego ethernet protocol type.
+ */
+#define ETH_P_Berkeley_Trailer_nego		0x1000
+
+/** Berkeley Trailer encap/IP ethernet protocol type.
+ */
+#define ETH_P_Berkeley_Trailer_encapIP_MIN		0x1001
+
+/** Berkeley Trailer encap/IP ethernet protocol type.
+ */
+#define ETH_P_Berkeley_Trailer_encapIP_MAX		0x100F
+
+/** Valid Systems ethernet protocol type.
+ */
+#define ETH_P_Valid_Systems		0x1600
+
+/** PCS Basic Block Protocol ethernet protocol type.
+ */
+#define ETH_P_PCS_Basic_Block_Protocol		0x4242
+
+/** BBN Simnet ethernet protocol type.
+ */
+#define ETH_P_BBN_Simnet		0x5208
+
+/** DEC Unassigned (Exp.) ethernet protocol type.
+ */
+#define ETH_P_DEC		0x6000
+
+/** DEC MOP Dump/Load ethernet protocol type.
+ */
+#define ETH_P_DNA_DL		0x6001
+
+/** DEC MOP Remote Console ethernet protocol type.
+ */
+#define ETH_P_DNA_RC		0x6002
+
+/** DEC DECNET Phase IV Route ethernet protocol type.
+ */
+#define ETH_P_DNA_RT		0x6003
+
+/** DEC LAT ethernet protocol type.
+ */
+#define ETH_P_LAT		0x6004
+
+/** DEC Diagnostic Protocol ethernet protocol type.
+ */
+#define ETH_P_DIAG		0x6005
+
+/** DEC Customer Protocol ethernet protocol type.
+ */
+#define ETH_P_CUST		0x6006
+
+/** DEC LAVC, SCA ethernet protocol type.
+ */
+#define ETH_P_SCA		0x6007
+
+/** DEC Unassigned ethernet protocol type.
+ */
+#define ETH_P_DEC_Unassigned_MIN		0x6008
+
+/** DEC Unassigned ethernet protocol type.
+ */
+#define ETH_P_DEC_Unassigned_MAX		0x6009
+
+/** Com Corporation ethernet protocol type.
+ */
+#define ETH_P_Com_Corporation_MIN		0x6010
+
+/** Com Corporation ethernet protocol type.
+ */
+#define ETH_P_Com_Corporation_MAX		0x6014
+
+/** Trans Ether Bridging ethernet protocol type.
+ */
+#define ETH_P_Trans_Ether_Bridging		0x6558
+
+/** Raw Frame Relay ethernet protocol type.
+ */
+#define ETH_P_Raw_Frame_Relay		0x6559
+
+/** Ungermann-Bass download ethernet protocol type.
+ */
+#define ETH_P_Ungermann_Bass_download		0x7000
+
+/** Ungermann-Bass dia/loop ethernet protocol type.
+ */
+#define ETH_P_Ungermann_Bass_dialoop		0x7002
+
+/** LRT ethernet protocol type.
+ */
+#define ETH_P_LRT_MIN		0x7020
+
+/** LRT ethernet protocol type.
+ */
+#define ETH_P_LRT_MAX		0x7029
+
+/** Proteon ethernet protocol type.
+ */
+#define ETH_P_Proteon		0x7030
+
+/** Cabletron ethernet protocol type.
+ */
+#define ETH_P_Cabletron		0x7034
+
+/** Cronus VLN ethernet protocol type.
+ */
+#define ETH_P_Cronus_VLN		0x8003
+
+/** Cronus Direct ethernet protocol type.
+ */
+#define ETH_P_Cronus_Direct		0x8004
+
+/** HP Probe ethernet protocol type.
+ */
+#define ETH_P_HP_Probe		0x8005
+
+/** Nestar ethernet protocol type.
+ */
+#define ETH_P_Nestar		0x8006
+
+/** AT&T ethernet protocol type.
+ */
+#define ETH_P_AT_T		0x8008
+
+/** Excelan ethernet protocol type.
+ */
+#define ETH_P_Excelan		0x8010
+
+/** SGI diagnostics ethernet protocol type.
+ */
+#define ETH_P_SGI_diagnostics		0x8013
+
+/** SGI network games ethernet protocol type.
+ */
+#define ETH_P_SGI_network_games		0x8014
+
+/** SGI reserved ethernet protocol type.
+ */
+#define ETH_P_SGI_reserved		0x8015
+
+/** SGI bounce server ethernet protocol type.
+ */
+#define ETH_P_SGI_bounce_server		0x8016
+
+/** Apollo Domain ethernet protocol type.
+ */
+#define ETH_P_Apollo_Domain		0x8019
+
+/** Tymshare ethernet protocol type.
+ */
+#define ETH_P_Tymshare		0x802E
+
+/** Tigan, Inc. ethernet protocol type.
+ */
+#define ETH_P_Tigan		0x802F
+
+/** Reverse ARP ethernet protocol type.
+ */
+#define ETH_P_RARP		0x8035
+
+/** Aeonic Systems ethernet protocol type.
+ */
+#define ETH_P_Aeonic_Systems		0x8036
+
+/** DEC LANBridge ethernet protocol type.
+ */
+#define ETH_P_DEC_LANBridge		0x8038
+
+/** DEC Unassigned ethernet protocol type.
+ */
+#define ETH_P_DEC_Unassigned_MIN1		0x8039
+
+/** DEC Unassigned ethernet protocol type.
+ */
+#define ETH_P_DEC_Unassigned_MAX2		0x803C
+
+/** DEC Ethernet Encryption ethernet protocol type.
+ */
+#define ETH_P_DEC_Ethernet_Encryption		0x803D
+
+/** DEC Unassigned ethernet protocol type.
+ */
+#define ETH_P_DEC_Unassigned		0x803E
+
+/** DEC LAN Traffic Monitor ethernet protocol type.
+ */
+#define ETH_P_DEC_LAN_Traffic_Monitor		0x803F
+
+/** DEC Unassigned ethernet protocol type.
+ */
+#define ETH_P_DEC_Unassigned_MIN3		0x8040
+
+/** DEC Unassigned ethernet protocol type.
+ */
+#define ETH_P_DEC_Unassigned_MAX3		0x8042
+
+/** Planning Research Corp. ethernet protocol type.
+ */
+#define ETH_P_Planning_Research_Corp		0x8044
+
+/** AT&T ethernet protocol type.
+ */
+#define ETH_P_AT_T2		0x8046
+
+/** AT&T ethernet protocol type.
+ */
+#define ETH_P_AT_T3		0x8047
+
+/** ExperData ethernet protocol type.
+ */
+#define ETH_P_ExperData		0x8049
+
+/** Stanford V Kernel exp. ethernet protocol type.
+ */
+#define ETH_P_Stanford_V_Kernel_exp		0x805B
+
+/** Stanford V Kernel prod. ethernet protocol type.
+ */
+#define ETH_P_Stanford_V_Kernel_prod		0x805C
+
+/** Evans &Sutherland ethernet protocol type.
+ */
+#define ETH_P_Evans_Sutherland		0x805D
+
+/** Little Machines ethernet protocol type.
+ */
+#define ETH_P_Little_Machines		0x8060
+
+/** Counterpoint Computers ethernet protocol type.
+ */
+#define ETH_P_Counterpoint_Computers		0x8062
+
+/** Univ. of Mass. @ Amherst ethernet protocol type.
+ */
+#define ETH_P_Univ_of_Mass		0x8065
+
+/** Univ. of Mass. @ Amherst ethernet protocol type.
+ */
+#define ETH_P_Univ_of_Mass2		0x8066
+
+/** Veeco Integrated Auto. ethernet protocol type.
+ */
+#define ETH_P_Veeco_Integrated_Auto		0x8067
+
+/** General Dynamics ethernet protocol type.
+ */
+#define ETH_P_General_Dynamics		0x8068
+
+/** AT&T ethernet protocol type.
+ */
+#define ETH_P_AT_T4		0x8069
+
+/** Autophon ethernet protocol type.
+ */
+#define ETH_P_Autophon		0x806A
+
+/** ComDesign ethernet protocol type.
+ */
+#define ETH_P_ComDesign		0x806C
+
+/** Computgraphic Corp. ethernet protocol type.
+ */
+#define ETH_P_Computgraphic_Corp		0x806D
+
+/** Landmark Graphics Corp. ethernet protocol type.
+ */
+#define ETH_P_Landmark_Graphics_Corp_MIN		0x806E
+
+/** Landmark Graphics Corp. ethernet protocol type.
+ */
+#define ETH_P_Landmark_Graphics_Corp_MAX		0x8077
+
+/** Matra ethernet protocol type.
+ */
+#define ETH_P_Matra		0x807A
+
+/** Dansk Data Elektronik ethernet protocol type.
+ */
+#define ETH_P_Dansk_Data_Elektronik		0x807B
+
+/** Merit Internodal ethernet protocol type.
+ */
+#define ETH_P_Merit_Internodal		0x807C
+
+/** Vitalink Communications ethernet protocol type.
+ */
+#define ETH_P_Vitalink_Communications_MIN		0x807D
+
+/** Vitalink Communications ethernet protocol type.
+ */
+#define ETH_P_Vitalink_Communications_MAX		0x807F
+
+/** Vitalink TransLAN III ethernet protocol type.
+ */
+#define ETH_P_Vitalink_TransLAN_III		0x8080
+
+/** Counterpoint Computers ethernet protocol type.
+ */
+#define ETH_P_Counterpoint_Computers_MIN		0x8081
+
+/** Counterpoint Computers ethernet protocol type.
+ */
+#define ETH_P_Counterpoint_Computers_MAX		0x8083
+
+/** Appletalk ethernet protocol type.
+ */
+#define ETH_P_ATALK		0x809B
+
+/** Datability ethernet protocol type.
+ */
+#define ETH_P_Datability_MIN		0x809C
+
+/** Datability ethernet protocol type.
+ */
+#define ETH_P_Datability_MAX		0x809E
+
+/** Spider Systems Ltd. ethernet protocol type.
+ */
+#define ETH_P_Spider_Systems_Ltd		0x809F
+
+/** Nixdorf Computers ethernet protocol type.
+ */
+#define ETH_P_Nixdorf_Computers		0x80A3
+
+/** Siemens Gammasonics Inc. ethernet protocol type.
+ */
+#define ETH_P_Siemens_Gammasonics_Inc_MIN		0x80A4
+
+/** Siemens Gammasonics Inc. ethernet protocol type.
+ */
+#define ETH_P_Siemens_Gammasonics_Inc_MAX		0x80B3
+
+/** DCA Data Exchange Cluster ethernet protocol type.
+ */
+#define ETH_P_DCA_Data_Exchange_Cluster_MIN		0x80C0
+
+/** DCA Data Exchange Cluster ethernet protocol type.
+ */
+#define ETH_P_DCA_Data_Exchange_Cluster_MAX		0x80C3
+
+/** Banyan Systems ethernet protocol type.
+ */
+#define ETH_P_Banyan_Systems		0x80C4
+
+/** Banyan Systems ethernet protocol type.
+ */
+#define ETH_P_Banyan_Systems2		0x80C5
+
+/** Pacer Software ethernet protocol type.
+ */
+#define ETH_P_Pacer_Software		0x80C6
+
+/** Applitek Corporation ethernet protocol type.
+ */
+#define ETH_P_Applitek_Corporation		0x80C7
+
+/** Intergraph Corporation ethernet protocol type.
+ */
+#define ETH_P_Intergraph_Corporation_MIN		0x80C8
+
+/** Intergraph Corporation ethernet protocol type.
+ */
+#define ETH_P_Intergraph_Corporation_MAX		0x80CC
+
+/** Harris Corporation ethernet protocol type.
+ */
+#define ETH_P_Harris_Corporation_MIN		0x80CD
+
+/** Harris Corporation ethernet protocol type.
+ */
+#define ETH_P_Harris_Corporation_MAX		0x80CE
+
+/** Taylor Instrument ethernet protocol type.
+ */
+#define ETH_P_Taylor_Instrument_MIN		0x80CF
+
+/** Taylor Instrument ethernet protocol type.
+ */
+#define ETH_P_Taylor_Instrument_MAX		0x80D2
+
+/** Rosemount Corporation ethernet protocol type.
+ */
+#define ETH_P_Rosemount_Corporation_MIN		0x80D3
+
+/** Rosemount Corporation ethernet protocol type.
+ */
+#define ETH_P_Rosemount_Corporation_MAX		0x80D4
+
+/** IBM SNA Service on Ether ethernet protocol type.
+ */
+#define ETH_P_IBM_SNA_Service_on_Ether		0x80D5
+
+/** Varian Associates ethernet protocol type.
+ */
+#define ETH_P_Varian_Associates		0x80DD
+
+/** Integrated Solutions TRFS ethernet protocol type.
+ */
+#define ETH_P_Integrated_Solutions_TRFS_MIN		0x80DE
+
+/** Integrated Solutions TRFS ethernet protocol type.
+ */
+#define ETH_P_Integrated_Solutions_TRFS_MAX		0x80DF
+
+/** Allen-Bradley ethernet protocol type.
+ */
+#define ETH_P_Allen_Bradley_MIN		0x80E0
+
+/** Allen-Bradley ethernet protocol type.
+ */
+#define ETH_P_Allen_Bradley_MAX		0x80E3
+
+/** Datability ethernet protocol type.
+ */
+#define ETH_P_Datability_MIN2		0x80E4
+
+/** Datability ethernet protocol type.
+ */
+#define ETH_P_Datability_MAX2		0x80F0
+
+/** Retix ethernet protocol type.
+ */
+#define ETH_P_Retix		0x80F2
+
+/** AppleTalk AARP (Kinetics) ethernet protocol type.
+ */
+#define ETH_P_AARP		0x80F3
+
+/** Kinetics ethernet protocol type.
+ */
+#define ETH_P_Kinetics_MIN		0x80F4
+
+/** Kinetics ethernet protocol type.
+ */
+#define ETH_P_Kinetics_MAX		0x80F5
+
+/** Apollo Computer ethernet protocol type.
+ */
+#define ETH_P_Apollo_Computer		0x80F7
+
+/** Wellfleet Communications ethernet protocol type.
+ */
+#define ETH_P_Wellfleet_Communications		0x80FF
+
+/** IEEE 802.1Q VLAN-tagged frames (initially Wellfleet) ethernet protocol type.
+ */
+#define ETH_P_8021Q		0x8100
+
+/** Wellfleet Communications ethernet protocol type.
+ */
+#define ETH_P_Wellfleet_Communications_MIN		0x8101
+
+/** Wellfleet Communications ethernet protocol type.
+ */
+#define ETH_P_Wellfleet_Communications_MAX		0x8103
+
+/** Symbolics Private ethernet protocol type.
+ */
+#define ETH_P_Symbolics_Private_MIN		0x8107
+
+/** Symbolics Private ethernet protocol type.
+ */
+#define ETH_P_Symbolics_Private_MAX		0x8109
+
+/** Hayes Microcomputers ethernet protocol type.
+ */
+#define ETH_P_Hayes_Microcomputers		0x8130
+
+/** VG Laboratory Systems ethernet protocol type.
+ */
+#define ETH_P_VG_Laboratory_Systems		0x8131
+
+/** Bridge Communications ethernet protocol type.
+ */
+#define ETH_P_Bridge_Communications_MIN		0x8132
+
+/** Bridge Communications ethernet protocol type.
+ */
+#define ETH_P_Bridge_Communications_MAX		0x8136
+
+/** Novell, Inc. ethernet protocol type.
+ */
+#define ETH_P_Novell_Inc_MIN		0x8137
+
+/** Novell, Inc. ethernet protocol type.
+ */
+#define ETH_P_Novell_Inc_MAX		0x8138
+
+/** KTI ethernet protocol type.
+ */
+#define ETH_P_KTI_MIN		0x8139
+
+/** KTI ethernet protocol type.
+ */
+#define ETH_P_KTI_MAX		0x813D
+
+/** Logicraft ethernet protocol type.
+ */
+#define ETH_P_Logicraft		0x8148
+
+/** Network Computing Devices ethernet protocol type.
+ */
+#define ETH_P_Network_Computing_Devices		0x8149
+
+/** Alpha Micro ethernet protocol type.
+ */
+#define ETH_P_Alpha_Micro		0x814A
+
+/** SNMP ethernet protocol type.
+ */
+#define ETH_P_SNMP		0x814C
+
+/** BIIN ethernet protocol type.
+ */
+#define ETH_P_BIIN		0x814D
+
+/** BIIN ethernet protocol type.
+ */
+#define ETH_P_BIIN2		0x814E
+
+/** Technically Elite Concept ethernet protocol type.
+ */
+#define ETH_P_Technically_Elite_Concept		0x814F
+
+/** Rational Corp ethernet protocol type.
+ */
+#define ETH_P_Rational_Corp		0x8150
+
+/** Qualcomm ethernet protocol type.
+ */
+#define ETH_P_Qualcomm_MIN		0x8151
+
+/** Qualcomm ethernet protocol type.
+ */
+#define ETH_P_Qualcomm_MAX		0x8153
+
+/** Computer Protocol Pty Ltd ethernet protocol type.
+ */
+#define ETH_P_Computer_Protocol_Pty_Ltd_MIN		0x815C
+
+/** Computer Protocol Pty Ltd ethernet protocol type.
+ */
+#define ETH_P_Computer_Protocol_Pty_Ltd_MAX		0x815E
+
+/** Charles River Data System ethernet protocol type.
+ */
+#define ETH_P_Charles_River_Data_System_MIN		0x8164
+
+/** Charles River Data System ethernet protocol type.
+ */
+#define ETH_P_Charles_River_Data_System_MAX		0x8166
+
+/** XTP ethernet protocol type.
+ */
+#define ETH_P_XTP		0x817D
+
+/** SGI/Time Warner prop. ethernet protocol type.
+ */
+#define ETH_P_SGITime_Warner_prop		0x817E
+
+/** HIPPI-FP encapsulation ethernet protocol type.
+ */
+#define ETH_P_HIPPI_FP_encapsulation		0x8180
+
+/** STP, HIPPI-ST ethernet protocol type.
+ */
+#define ETH_P_STP_HIPPI_ST		0x8181
+
+/** Reserved for HIPPI-6400 ethernet protocol type.
+ */
+#define ETH_P_Reserved_for_HIPPI_6400		0x8182
+
+/** Reserved for HIPPI-6400 ethernet protocol type.
+ */
+#define ETH_P_Reserved_for_HIPPI_64002		0x8183
+
+/** Silicon Graphics prop. ethernet protocol type.
+ */
+#define ETH_P_Silicon_Graphics_prop_MIN		0x8184
+
+/** Silicon Graphics prop. ethernet protocol type.
+ */
+#define ETH_P_Silicon_Graphics_prop_MAX		0x818C
+
+/** Motorola Computer ethernet protocol type.
+ */
+#define ETH_P_Motorola_Computer		0x818D
+
+/** Qualcomm ethernet protocol type.
+ */
+#define ETH_P_Qualcomm_MIN2		0x819A
+
+/** Qualcomm ethernet protocol type.
+ */
+#define ETH_P_Qualcomm_MAX2		0x81A3
+
+/** ARAI Bunkichi ethernet protocol type.
+ */
+#define ETH_P_ARAI_Bunkichi		0x81A4
+
+/** RAD Network Devices ethernet protocol type.
+ */
+#define ETH_P_RAD_Network_Devices_MIN		0x81A5
+
+/** RAD Network Devices ethernet protocol type.
+ */
+#define ETH_P_RAD_Network_Devices_MAX		0x81AE
+
+/** Xyplex ethernet protocol type.
+ */
+#define ETH_P_Xyplex_MIN2		0x81B7
+
+/** Xyplex ethernet protocol type.
+ */
+#define ETH_P_Xyplex_MAX2		0x81B9
+
+/** Apricot Computers ethernet protocol type.
+ */
+#define ETH_P_Apricot_Computers_MIN		0x81CC
+
+/** Apricot Computers ethernet protocol type.
+ */
+#define ETH_P_Apricot_Computers_MAX		0x81D5
+
+/** Artisoft ethernet protocol type.
+ */
+#define ETH_P_Artisoft_MIN		0x81D6
+
+/** Artisoft ethernet protocol type.
+ */
+#define ETH_P_Artisoft_MAX		0x81DD
+
+/** Polygon ethernet protocol type.
+ */
+#define ETH_P_Polygon_MIN		0x81E6
+
+/** Polygon ethernet protocol type.
+ */
+#define ETH_P_Polygon_MAX		0x81EF
+
+/** Comsat Labs ethernet protocol type.
+ */
+#define ETH_P_Comsat_Labs_MIN		0x81F0
+
+/** Comsat Labs ethernet protocol type.
+ */
+#define ETH_P_Comsat_Labs_MAX		0x81F2
+
+/** SAIC ethernet protocol type.
+ */
+#define ETH_P_SAIC_MIN		0x81F3
+
+/** SAIC ethernet protocol type.
+ */
+#define ETH_P_SAIC_MAX		0x81F5
+
+/** VG Analytical ethernet protocol type.
+ */
+#define ETH_P_VG_Analytical_MIN		0x81F6
+
+/** VG Analytical ethernet protocol type.
+ */
+#define ETH_P_VG_Analytical_MAX		0x81F8
+
+/** Quantum Software ethernet protocol type.
+ */
+#define ETH_P_Quantum_Software_MIN		0x8203
+
+/** Quantum Software ethernet protocol type.
+ */
+#define ETH_P_Quantum_Software_MAX		0x8205
+
+/** Ascom Banking Systems ethernet protocol type.
+ */
+#define ETH_P_Ascom_Banking_Systems_MIN		0x8221
+
+/** Ascom Banking Systems ethernet protocol type.
+ */
+#define ETH_P_Ascom_Banking_Systems_MAX		0x8222
+
+/** Advanced Encryption Syste ethernet protocol type.
+ */
+#define ETH_P_Advanced_Encryption_Syste_MIN		0x823E
+
+/** Advanced Encryption Syste ethernet protocol type.
+ */
+#define ETH_P_Advanced_Encryption_Syste_MAX		0x8240
+
+/** Athena Programming ethernet protocol type.
+ */
+#define ETH_P_Athena_Programming_MIN		0x827F
+
+/** Athena Programming ethernet protocol type.
+ */
+#define ETH_P_Athena_Programming_MAX		0x8282
+
+/** Charles River Data System ethernet protocol type.
+ */
+#define ETH_P_Charles_River_Data_System_MIN2		0x8263
+
+/** Charles River Data System ethernet protocol type.
+ */
+#define ETH_P_Charles_River_Data_System_MAX2		0x826A
+
+/** Inst Ind Info Tech ethernet protocol type.
+ */
+#define ETH_P_Inst_Ind_Info_Tech_MIN		0x829A
+
+/** Inst Ind Info Tech ethernet protocol type.
+ */
+#define ETH_P_Inst_Ind_Info_Tech_MAX		0x829B
+
+/** Taurus Controls ethernet protocol type.
+ */
+#define ETH_P_Taurus_Controls_MIN		0x829C
+
+/** Taurus Controls ethernet protocol type.
+ */
+#define ETH_P_Taurus_Controls_MAX		0x82AB
+
+/** Walker Richer &Quinn ethernet protocol type.
+ */
+#define ETH_P_Walker_Richer_Quinn_MIN		0x82AC
+
+/** Walker Richer &Quinn ethernet protocol type.
+ */
+#define ETH_P_Walker_Richer_Quinn_MAX		0x8693
+
+/** Idea Courier ethernet protocol type.
+ */
+#define ETH_P_Idea_Courier_MIN		0x8694
+
+/** Idea Courier ethernet protocol type.
+ */
+#define ETH_P_Idea_Courier_MAX		0x869D
+
+/** Computer Network Tech ethernet protocol type.
+ */
+#define ETH_P_Computer_Network_Tech_MIN		0x869E
+
+/** Computer Network Tech ethernet protocol type.
+ */
+#define ETH_P_Computer_Network_Tech_MAX		0x86A1
+
+/** Gateway Communications ethernet protocol type.
+ */
+#define ETH_P_Gateway_Communications_MIN		0x86A3
+
+/** Gateway Communications ethernet protocol type.
+ */
+#define ETH_P_Gateway_Communications_MAX		0x86AC
+
+/** SECTRA ethernet protocol type.
+ */
+#define ETH_P_SECTRA		0x86DB
+
+/** Delta Controls ethernet protocol type.
+ */
+#define ETH_P_Delta_Controls		0x86DE
+
+/** IPv6 ethernet protocol type.
+ */
+#define ETH_P_IPV6		0x86DD
+
+/** ATOMIC ethernet protocol type.
+ */
+#define ETH_P_ATOMIC		0x86DF
+
+/** Landis &Gyr Powers ethernet protocol type.
+ */
+#define ETH_P_Landis_Gyr_Powers_MIN		0x86E0
+
+/** Landis &Gyr Powers ethernet protocol type.
+ */
+#define ETH_P_Landis_Gyr_Powers_MAX		0x86EF
+
+/** Motorola ethernet protocol type.
+ */
+#define ETH_P_Motorola_MIN		0x8700
+
+/** Motorola ethernet protocol type.
+ */
+#define ETH_P_Motorola_MAX		0x8710
+
+/** TCP/IP Compression ethernet protocol type.
+ */
+#define ETH_P_TCPIP_Compression		0x876B
+
+/** IP Autonomous Systems ethernet protocol type.
+ */
+#define ETH_P_IP_Autonomous_Systems		0x876C
+
+/** Secure Data ethernet protocol type.
+ */
+#define ETH_P_Secure_Data		0x876D
+
+/** PPP ethernet protocol type.
+ */
+#define ETH_P_PPP		0x880B
+
+/** MPLS ethernet protocol type.
+ */
+#define ETH_P_MPLS_UC		0x8847
+
+/** MPLS with upstream-assigned label ethernet protocol type.
+ */
+#define ETH_P_MPLS_MC		0x8848
+
+/** Invisible Software ethernet protocol type.
+ */
+#define ETH_P_Invisible_Software_MIN		0x8A96
+
+/** Invisible Software ethernet protocol type.
+ */
+#define ETH_P_Invisible_Software_MAX		0x8A97
+
+/** PPPoE Discovery Stage ethernet protocol type.
+ */
+#define ETH_P_PPP_DISC		0x8863
+
+/** PPPoE Session Stage ethernet protocol type.
+ */
+#define ETH_P_PPP_SES		0x8864
+
+/** Loopback ethernet protocol type.
+ */
+#define ETH_P_Loopback		0x9000
+
+/** Com(Bridge) XNS Sys Mgmt ethernet protocol type.
+ */
+#define ETH_P_Com_XNS_Sys_Mgmt		0x9001
+
+/** Com(Bridge) TCP-IP Sys ethernet protocol type.
+ */
+#define ETH_P_Com_TCP_IP_Sys		0x9002
+
+/** Com(Bridge) loop detect ethernet protocol type.
+ */
+#define ETH_P_Com_loop_detect		0x9003
+
+/** BBN VITAL-LanBridge cache ethernet protocol type.
+ */
+#define ETH_P_BBN_VITAL_LanBridge_cache		0xFF00
+
+/** ISC Bunker Ramo ethernet protocol type.
+ */
+#define ETH_P_ISC_Bunker_Ramo_MIN		0xFF00
+
+/** ISC Bunker Ramo ethernet protocol type.
+ */
+#define ETH_P_ISC_Bunker_Ramo_MAX		0xFF0F
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/icmp_client.h
===================================================================
--- uspace/lib/net/include/icmp_client.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/icmp_client.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,63 @@
+/*
+ * 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 icmp
+ *  @{
+ */
+
+/** @file
+ *  ICMP client interface.
+ */
+
+#ifndef __NET_ICMP_CLIENT_H__
+#define __NET_ICMP_CLIENT_H__
+
+#include <icmp_codes.h>
+#include <packet/packet.h>
+
+/** Processes the received packet prefixed with an ICMP header.
+ *  @param[in] packet The received packet.
+ *  @param[out] type The ICMP header type.
+ *  @param[out] code The ICMP header code.
+ *  @param[out] pointer The ICMP header pointer.
+ *  @param[out] mtu The ICMP header MTU.
+ *  @returns The ICMP header length.
+ *  @returns Zero (0) if the packet contains no data.
+ */
+extern int icmp_client_process_packet(packet_t packet, icmp_type_t * type, icmp_code_t * code, icmp_param_t * pointer, icmp_param_t * mtu);
+
+/** Returns the ICMP header length.
+ *  @param[in] packet The packet.
+ *  @returns The ICMP header length in bytes.
+ */
+extern size_t icmp_client_header_length(packet_t packet);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/icmp_header.h
===================================================================
--- uspace/lib/net/include/icmp_header.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/icmp_header.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,133 @@
+/*
+ * 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 icmp
+ *  @{
+ */
+
+/** @file
+ *  ICMP header definition.
+ *  Based on the RFC~792.
+ */
+
+#ifndef __NET_ICMP_HEADER_H__
+#define __NET_ICMP_HEADER_H__
+
+#include <sys/types.h>
+
+#include <in.h>
+#include <icmp_codes.h>
+
+/** ICMP header size in bytes.
+ */
+#define ICMP_HEADER_SIZE			sizeof(icmp_header_t)
+
+/** Type definition of the echo specific data.
+ *  @see icmp_echo
+ */
+typedef struct icmp_echo	icmp_echo_t;
+
+/** Type definition of the echo specific data pointer.
+ *  @see icmp_echo
+ */
+typedef icmp_echo_t *		icmp_echo_ref;
+
+/** Echo specific data.
+ */
+struct icmp_echo{
+	/** Message idintifier.
+	 */
+	icmp_param_t identifier;
+	/** Message sequence number.
+	 */
+	icmp_param_t sequence_number;
+} __attribute__ ((packed));
+
+/** Type definition of the internet control message header.
+ *  @see icmp_header
+ */
+typedef struct icmp_header	icmp_header_t;
+
+/** Type definition of the internet control message header pointer.
+ *  @see icmp_header
+ */
+typedef icmp_header_t *		icmp_header_ref;
+
+/** Internet control message header.
+ */
+struct icmp_header{
+	/** The type of the message.
+	 */
+	uint8_t type;
+	/** The error code for the datagram reported by the ICMP message.
+	 *  The interpretation is dependent on the message type.
+	 */
+	uint8_t code;
+	/** The checksum is the 16-bit ones's complement of the one's complement sum of the ICMP message starting with the ICMP Type.
+     *  For computing the checksum, the checksum field should be zero.
+	 *  If the checksum does not match the contents, the datagram is discarded.
+	 */
+	uint16_t checksum;
+	/** Message specific data.
+	 */
+	union{
+		/** Echo specific data.
+		 */
+		icmp_echo_t  echo;
+		/** Proposed gateway value.
+		 */
+		in_addr_t gateway;
+		/** Fragmentation needed specific data.
+		 */
+		struct{
+			/** Reserved field.
+			 *  Must be zero.
+			 */
+			icmp_param_t reserved;
+			/** Proposed MTU.
+			 */
+			icmp_param_t mtu;
+		} frag;
+		/** Parameter problem specific data.
+		 */
+		struct{
+			/** Problem pointer.
+			 */
+			icmp_param_t pointer;
+			/** Reserved field.
+			 *  Must be zero.
+			 */
+			icmp_param_t reserved;
+		} param;
+	} un;
+} __attribute__ ((packed));
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/icmp_interface.h
===================================================================
--- uspace/lib/net/include/icmp_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/icmp_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,106 @@
+/*
+ * 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 icmp
+ *  @{
+ */
+
+#ifndef __NET_ICMP_INTERFACE_H__
+#define __NET_ICMP_INTERFACE_H__
+
+#include <sys/types.h>
+
+#include <net_device.h>
+#include <adt/measured_strings.h>
+#include <packet/packet.h>
+#include <inet.h>
+#include <ip_codes.h>
+#include <socket_codes.h>
+#include <icmp_codes.h>
+#include <icmp_common.h>
+
+/** @name ICMP module interface
+ *  This interface is used by other modules.
+ */
+/*@{*/
+
+/** Sends the Destination Unreachable error notification packet.
+ *  Beginning of the packet is sent as the notification packet data.
+ *  The source and the destination addresses should be set in the original packet.
+ *  @param[in] icmp_phone The ICMP module phone used for (semi)remote calls.
+ *  @param[in] code The error specific code.
+ *  @param[in] mtu The error MTU value.
+ *  @param[in] packet The original packet.
+ *  @returns EOK on success.
+ *  @returns EPERM if the ICMP error notifications are disabled.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int icmp_destination_unreachable_msg(int icmp_phone, icmp_code_t code, icmp_param_t mtu, packet_t packet);
+
+/** Sends the Source Quench error notification packet.
+ *  Beginning of the packet is sent as the notification packet data.
+ *  The source and the destination addresses should be set in the original packet.
+ *  @param[in] icmp_phone The ICMP module phone used for (semi)remote calls.
+ *  @param[in] packet The original packet.
+ *  @returns EOK on success.
+ *  @returns EPERM if the ICMP error notifications are disabled.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int icmp_source_quench_msg(int icmp_phone, packet_t packet);
+
+/** Sends the Time Exceeded error notification packet.
+ *  Beginning of the packet is sent as the notification packet data.
+ *  The source and the destination addresses should be set in the original packet.
+ *  @param[in] icmp_phone The ICMP module phone used for (semi)remote calls.
+ *  @param[in] code The error specific code.
+ *  @param[in] packet The original packet.
+ *  @returns EOK on success.
+ *  @returns EPERM if the ICMP error notifications are disabled.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int icmp_time_exceeded_msg(int icmp_phone, icmp_code_t code, packet_t packet);
+
+/** Sends the Parameter Problem error notification packet.
+ *  Beginning of the packet is sent as the notification packet data.
+ *  The source and the destination addresses should be set in the original packet.
+ *  @param[in] icmp_phone The ICMP module phone used for (semi)remote calls.
+ *  @param[in] code The error specific code.
+ *  @param[in] pointer The problematic parameter offset.
+ *  @param[in] packet The original packet.
+ *  @returns EOK on success.
+ *  @returns EPERM if the ICMP error notifications are disabled.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int icmp_parameter_problem_msg(int icmp_phone, icmp_code_t code, icmp_param_t pointer, packet_t packet);
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/il_interface.h
===================================================================
--- uspace/lib/net/include/il_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/il_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,118 @@
+/*
+ * 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_il
+ *  @{
+ */
+
+/** @file
+ * Internetwork layer module interface for the underlying network interface layer.
+ * This interface is always called by the remote modules.
+ */
+
+#ifndef __NET_IL_INTERFACE_H__
+#define __NET_IL_INTERFACE_H__
+
+#include <async.h>
+
+#include <ipc/services.h>
+
+#include <net_messages.h>
+#include <net_device.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+#include <il_messages.h>
+
+/** @name Internetwork layer module interface
+ * This interface is used by other modules.
+ */
+/*@{*/
+
+/** Notify the internetwork layer modules about the device state change.
+ *
+ * @param[in] il_phone  The internetwork layer module phone used for
+ *                      (semi)remote calls.
+ * @param[in] device_id The device identifier.
+ * @param[in] state     The new device state.
+ * @param[in] target    The target internetwork module service to be
+ *                      delivered to.
+ *
+ * @return EOK on success.
+ *
+ */
+static inline int il_device_state_msg(int il_phone, device_id_t device_id,
+    device_state_t state, services_t target)
+{
+	return generic_device_state_msg_remote(il_phone, NET_IL_DEVICE_STATE,
+	    device_id, state, target);
+}
+
+/** Notify the internetwork layer modules about the received packet/s.
+ *
+ * @param[in] il_phone  The internetwork layer module phone used for
+ *                      (semi)remote calls.
+ * @param[in] device_id The device identifier.
+ * @param[in] packet    The received packet or the received packet queue.
+ * @param[in] target    The target internetwork module service to be
+ *                      delivered to.
+ *
+ * @return EOK on success.
+ *
+ */
+inline static int il_received_msg(int il_phone, device_id_t device_id,
+    packet_t packet, services_t target)
+{
+	return generic_received_msg_remote(il_phone, NET_IL_RECEIVED, device_id,
+	    packet_get_id(packet), target, 0);
+}
+
+/** Notify the internetwork layer modules about the mtu change.
+ *
+ * @param[in] il_phone  The internetwork layer module phone used for
+ *                      (semi)remote calls.
+ * @param[in] device_id The device identifier.
+ * @param[in] mtu       The new mtu value.
+ * @param[in] target    The target internetwork module service to be
+ *                      delivered to.
+ *
+ * @return EOK on success.
+ *
+ */
+inline static int il_mtu_changed_msg(int il_phone, device_id_t device_id,
+    size_t mtu, services_t target)
+{
+	return generic_device_state_msg_remote(il_phone, NET_IL_MTU_CHANGED,
+	    device_id, (int) mtu, target);
+}
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/il_local.h
===================================================================
--- uspace/lib/net/include/il_local.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/il_local.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2010 Martin Decky
+ * 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 il_local
+ *  @{
+ */
+
+#ifndef __IL_LOCAL_H__
+#define __IL_LOCAL_H__
+
+#include <ipc/ipc.h>
+#include <async.h>
+
+extern int il_module_message_standalone(ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, int *answer_count);
+extern int il_module_start_standalone(async_client_conn_t client_connection);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/il_messages.h
===================================================================
--- uspace/lib/net/include/il_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/il_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -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 net_il
+ * @{
+ */
+
+/** @file
+ * Internetwork layer modules messages.
+ * @see il_interface.h
+ * @see ip_interface.h
+ */
+
+#ifndef __NET_IL_MESSAGES_H__
+#define __NET_IL_MESSAGES_H__
+
+#include <ipc/ipc.h>
+
+/** Internet layer modules messages.
+ */
+typedef enum {
+	/** New device message.
+	 *  @see ip_device_req()
+	 */
+	NET_IL_DEVICE = NET_IL_FIRST,
+	/** Device state changed message.
+	 *  @see il_device_state_msg()
+	 */
+	NET_IL_DEVICE_STATE,
+	/** Device MTU changed message.
+	 *  @see il_mtu_changed_msg()
+	 */
+	NET_IL_MTU_CHANGED,
+	/** Packet size message.
+	 *  @see il_packet_size_req()
+	 */
+	NET_IL_PACKET_SPACE,
+	/** Packet received message.
+	 *  @see il_received_msg()
+	 */
+	NET_IL_RECEIVED,
+	/** Packet send message.
+	 *  @see il_send_msg()
+	 */
+	NET_IL_SEND
+} il_messages;
+
+/** @name Internetwork layer specific message parameters definitions
+ *
+ */
+/*@{*/
+
+/** Return the protocol number message parameter.
+ * @param[in] call The message call structure.
+ *
+ */
+#define IL_GET_PROTO(call)  (int) IPC_GET_ARG1(*call)
+
+/** Return the registering service message parameter.
+ * @param[in] call The message call structure.
+ *
+ */
+#define IL_GET_SERVICE(call)  (services_t) IPC_GET_ARG2(*call)
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/ip_client.h
===================================================================
--- uspace/lib/net/include/ip_client.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/ip_client.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,116 @@
+/*
+ * 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 ip
+ *  @{
+ */
+
+/** @file
+ *  IP client interface.
+ */
+
+#ifndef __NET_IP_CLIENT_H__
+#define __NET_IP_CLIENT_H__
+
+#include <sys/types.h>
+
+#include <packet/packet.h>
+#include <ip_codes.h>
+#include <ip_interface.h>
+#include <socket_codes.h>
+
+/** Prepares the packet to be transfered via IP.
+ *  The IP header is prefixed.
+ *  @param[in,out] packet The packet to be prepared.
+ *  @param[in] protocol The transport protocol.
+ *  @param[in] ttl The time to live counter. The IPDEFTTL is set if zero (0).
+ *  @param[in] tos The type of service.
+ *  @param[in] dont_fragment The value indicating whether fragmentation is disabled.
+ *  @param[in] ipopt_length The prefixed IP options length in bytes.
+ *  @returns EOK on success.
+ *  @returns ENOMEM if there is not enough memory left in the packet.
+ */
+extern int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length);
+
+/** Processes the received IP packet.
+ *  Fills set header fields.
+ *  Returns the prefixed IP header length.
+ *  @param[in] packet The received packet.
+ *  @param[out] protocol The transport protocol. May be NULL if not desired.
+ *  @param[out] ttl The time to live counter. May be NULL if not desired.
+ *  @param[out] tos The type of service. May be NULL if not desired.
+ *  @param[out] dont_fragment The value indicating whether the fragmentation is disabled. May be NULL if not desired.
+ *  @param[out] ipopt_length The IP options length in bytes. May be NULL if not desired.
+ *  @returns The prefixed IP header length in bytes on success.
+ *  @returns ENOMEM if the packet is too short to contain the IP header.
+ */
+extern int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length);
+
+/** Returns the IP header length.
+ *  @param[in] packet The packet.
+ *  @returns The IP header length in bytes.
+ *  @returns Zero (0) if there is no IP header.
+ */
+extern size_t ip_client_header_length(packet_t packet);
+
+/** Updates the IPv4 pseudo header data length field.
+ *  @param[in,out] header The IPv4 pseudo header to be updated.
+ *  @param[in] headerlen The length of the IP pseudo header in bytes.
+ *  @param[in] data_length The data length to be set.
+ *  @returns EOK on success.
+ *  @returns EBADMEM if the header parameter is NULL.
+ *  @returns EINVAL if the headerlen parameter is not IPv4 pseudo header length.
+ */
+extern int ip_client_set_pseudo_header_data_length(void *header, size_t headerlen, size_t data_length);
+
+/** Constructs the IPv4 pseudo header.
+ *  @param[in] protocol The transport protocol.
+ *  @param[in] src The source address.
+ *  @param[in] srclen The source address length.
+ *  @param[in] dest The destination address.
+ *  @param[in] destlen The destination address length.
+ *  @param[in] data_length The data length to be set.
+ *  @param[out] header The constructed IPv4 pseudo header.
+ *  @param[out] headerlen The length of the IP pseudo header in bytes.
+ *  @returns EOK on success.
+ *  @returns EBADMEM if the header and/or the headerlen parameter is NULL.
+ *  @returns EINVAL if the source address and/or the destination address parameter is NULL.
+ *  @returns EINVAL if the source address length is less than struct sockaddr length.
+ *  @returns EINVAL if the source address length differs from the destination address length.
+ *  @returns EINVAL if the source address family differs from the destination family.
+ *  @returns EAFNOSUPPORT if the address family is not supported.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int ip_client_get_pseudo_header(ip_protocol_t protocol, struct sockaddr * src, socklen_t srclen, struct sockaddr * dest, socklen_t destlen, size_t data_length, void **header, size_t * headerlen);
+
+// TODO ipopt manipulation
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/ip_header.h
===================================================================
--- uspace/lib/net/include/ip_header.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/ip_header.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,282 @@
+/*
+ * 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 ip
+ *  @{
+ */
+
+/** @file
+ *  IP header and options definitions.
+ *  Based on the RFC~791.
+ */
+
+#ifndef __NET_IP_HEADER_H__
+#define __NET_IP_HEADER_H__
+
+#include <byteorder.h>
+#include <sys/types.h>
+
+/** Returns the fragment offest high bits.
+ *  @param[in] length The prefixed data total length.
+ */
+#define IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length) ((((length) / 8u) &0x1F00) >> 8)
+
+/** Returns the fragment offest low bits.
+ *  @param[in] length The prefixed data total length.
+ */
+#define IP_COMPUTE_FRAGMENT_OFFSET_LOW(length) (((length) / 8u) &0xFF)
+
+/** Returns the IP header length.
+ *  @param[in] length The IP header length in bytes.
+ */
+#define IP_COMPUTE_HEADER_LENGTH(length)		((uint8_t) ((length) / 4u))
+
+/** Returns the fragment offest.
+ *  @param[in] header The IP packet header.
+ */
+#define IP_FRAGMENT_OFFSET(header) ((((header)->fragment_offset_high << 8) + (header)->fragment_offset_low) * 8u)
+
+/** Returns the IP packet header checksum.
+ *  @param[in] header The IP packet header.
+ */
+#define IP_HEADER_CHECKSUM(header)	(htons(ip_checksum((uint8_t *)(header), IP_HEADER_LENGTH(header))))
+
+/** Returns the actual IP packet data length.
+ *  @param[in] header The IP packet header.
+ */
+#define IP_HEADER_DATA_LENGTH(header)	(IP_TOTAL_LENGTH(header) - IP_HEADER_LENGTH(header))
+
+/** Returns the actual IP header length in bytes.
+ *  @param[in] header The IP packet header.
+ */
+#define IP_HEADER_LENGTH(header)		((header)->header_length * 4u)
+
+/** Returns the actual IP packet total length.
+ *  @param[in] header The IP packet header.
+ */
+#define IP_TOTAL_LENGTH(header)		ntohs((header)->total_length)
+
+/** @name IP flags definitions
+ */
+/*@{*/
+
+/** Fragment flag field shift.
+ */
+#define IPFLAG_FRAGMENT_SHIFT		1
+
+/** Fragmented flag field shift.
+ */
+#define IPFLAG_FRAGMENTED_SHIFT		0
+
+/** Don't fragment flag value.
+ *  Permits the packet fragmentation.
+ */
+#define IPFLAG_DONT_FRAGMENT		(0x1 << IPFLAG_FRAGMENT_SHIFT)
+
+/** Last fragment flag value.
+ *  Indicates the last packet fragment.
+ */
+#define IPFLAG_LAST_FRAGMENT		(0x0 << IPFLAG_FRAGMENTED_SHIFT)
+
+/** May fragment flag value.
+ *  Allows the packet fragmentation.
+ */
+#define IPFLAG_MAY_FRAGMENT			(0x0 << IPFLAG_FRAGMENT_SHIFT)
+
+/** More fragments flag value.
+ *  Indicates that more packet fragments follow.
+ */
+#define IPFLAG_MORE_FRAGMENTS		(0x1 << IPFLAG_FRAGMENTED_SHIFT)
+
+/*@}*/
+
+/** Type definition of the internet header.
+ *  @see ip_header
+ */
+typedef struct ip_header	ip_header_t;
+
+/** Type definition of the internet header pointer.
+ *  @see ip_header
+ */
+typedef ip_header_t *		ip_header_ref;
+
+/** Type definition of the internet option header.
+ *  @see ip_header
+ */
+typedef struct ip_option	ip_option_t;
+
+/** Type definition of the internet option header pointer.
+ *  @see ip_header
+ */
+typedef ip_option_t *		ip_option_ref;
+
+/** Type definition of the internet version 4 pseudo header.
+ *  @see ipv4_pseudo_header
+ */
+typedef struct ipv4_pseudo_header	ipv4_pseudo_header_t;
+
+/** Type definition of the internet version 4 pseudo header pointer.
+ *  @see ipv4_pseudo_header
+ */
+typedef ipv4_pseudo_header_t *		ipv4_pseudo_header_ref;
+
+/** Internet header.
+ *  The variable options should be included after the header itself and indicated by the increased header length value.
+ */
+struct ip_header{
+#ifdef ARCH_IS_BIG_ENDIAN
+	/** The Version field indicates the format of the internet header.
+	 */
+	uint8_t version:4;
+	/** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
+	 *  Note that the minimum value for a~correct header is~5.
+	 */
+	uint8_t header_length:4;
+#else
+	/** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
+	 *  Note that the minimum value for a~correct header is~5.
+	 */
+	uint8_t header_length:4;
+	/** The Version field indicates the format of the internet header.
+	 */
+	uint8_t version:4;
+#endif
+	/** The Type of Service provides an indication of the abstract parameters of the quality of service desired.
+	 *  These parameters are to be used to guide the selection of the actual service parameters when transmitting a~datagram through a~particular network.
+	 *  Several networks offer service precedence, which somehow treats high precedence traffic as more important than other traffic (generally by accepting only traffic above a~certain precedence at time of high load).
+	 *  The major choice is a~three way tradeoff between low-delay, high-reliability, and high-throughput.
+	 */
+	uint8_t tos;
+	/** Total Length is the length of the datagram, measured in octets, including internet header and data.
+	 *  This field allows the length of a~datagram to be up to 65,535~octets.
+	 */
+	uint16_t total_length;
+	/** An identifying value assigned by the sender to aid in assembling the fragments of a~datagram.
+	 */
+	uint16_t identification;
+#ifdef ARCH_IS_BIG_ENDIAN
+	/** Various control flags.
+	 */
+	uint8_t flags:3;
+	/** This field indicates where in the datagram this fragment belongs.
+	 *  High bits.
+	 */
+	uint8_t fragment_offset_high:5;
+#else
+	/** This field indicates where in the datagram this fragment belongs.
+	 *  High bits.
+	 */
+	uint8_t fragment_offset_high:5;
+	/** Various control flags.
+	 */
+	uint8_t flags:3;
+#endif
+	/** This field indicates where in the datagram this fragment belongs.
+	 *  Low bits.
+	 */
+	uint8_t fragment_offset_low;
+	/** This field indicates the maximum time the datagram is allowed to remain in the internet system.
+	 *  If this field contains the value zero, then the datagram must be destroyed.
+	 *  This field is modified in internet header processing.
+	 *  The time is measured in units of seconds, but since every module that processes a~datagram must decrease the TTL by at least one even if it process the datagram in less than a~second, the TTL must be thought of only as an upper bound on the time a~datagram may exist.
+	 *  The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime.
+	 */
+	uint8_t ttl;
+	/** This field indicates the next level protocol used in the data portion of the internet datagram.
+	 */
+	uint8_t protocol;
+	/** A checksum of the header only.
+	 *  Since some header fields change (e.g., time to live), this is recomputed and verified at each point that the internet header is processed.
+	 *  The checksum algorithm is: The checksum field is the 16~bit one's complement of the one's complement sum of all 16~bit words in the header.
+	 *  For purposes of computing the checksum, the value of the checksum field is zero.
+	 */
+	uint16_t header_checksum;
+	/** The source address.
+	 */
+	uint32_t source_address;
+	/** The destination address.
+	 */
+	uint32_t destination_address;
+} __attribute__ ((packed));
+
+/** Internet option header.
+ *  Only type field is always valid.
+ *  Other fields' validity depends on the option type.
+ */
+struct ip_option{
+	/** A single octet of option-type.
+	 */
+	uint8_t type;
+	/** An option length octet.
+	 */
+	uint8_t length;
+	/** A~pointer.
+	 */
+	uint8_t pointer;
+#ifdef ARCH_IS_BIG_ENDIAN
+	/** The number of IP modules that cannot register timestamps due to lack of space.
+	 */
+	uint8_t overflow:4;
+	/** Various internet timestamp control flags.
+	 */
+	uint8_t flags:4;
+#else
+	/** Various internet timestamp control flags.
+	 */
+	uint8_t flags:4;
+	/** The number of IP modules that cannot register timestamps due to lack of space.
+	 */
+	uint8_t overflow:4;
+#endif
+} __attribute__ ((packed));
+
+/** Internet version 4 pseudo header.
+ */
+struct ipv4_pseudo_header{
+	/** The source address.
+	 */
+	uint32_t source_address;
+	/** The destination address.
+	 */
+	uint32_t destination_address;
+	/** Reserved byte.
+	 *  Must be zero.
+	 */
+	uint8_t reserved;
+	/** This field indicates the next level protocol used in the data portion of the internet datagram.
+	 */
+	uint8_t protocol;
+	/** Data length is the length of the datagram, measured in octets.
+	 */
+	uint16_t data_length;
+} __attribute__ ((packed));
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/ip_interface.h
===================================================================
--- uspace/lib/net/include/ip_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/ip_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,111 @@
+/*
+ * 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 ip
+ *  @{
+ */
+
+#ifndef __NET_IP_INTERFACE_H__
+#define __NET_IP_INTERFACE_H__
+
+#include <async.h>
+#include <ipc/services.h>
+
+#include <net_device.h>
+#include <packet/packet.h>
+
+#include <in.h>
+#include <ip_codes.h>
+#include <socket_codes.h>
+
+#ifdef CONFIG_IL_TL_BUNDLE
+
+#include <ip_local.h>
+
+#define ip_received_error_msg  ip_received_error_msg_local
+#define ip_set_gateway_req     ip_set_gateway_req_local
+#define ip_packet_size_req     ip_packet_size_req_local
+#define ip_device_req          ip_device_req_local
+#define ip_add_route_req       ip_add_route_req_local
+#define ip_send_msg            ip_send_msg_local
+#define ip_get_route_req       ip_get_route_req_local
+
+#else
+
+#include <ip_remote.h>
+
+#define ip_received_error_msg  ip_received_error_msg_remote
+#define ip_set_gateway_req     ip_set_gateway_req_remote
+#define ip_packet_size_req     ip_packet_size_req_remote
+#define ip_device_req          ip_device_req_remote
+#define ip_add_route_req       ip_add_route_req_remote
+#define ip_send_msg            ip_send_msg_remote
+#define ip_get_route_req       ip_get_route_req_remote
+
+#endif
+
+/** @name IP module interface
+ *  This interface is used by other modules.
+ */
+/*@{*/
+
+/** The transport layer notification function type definition.
+ *  Notifies the transport layer modules about the received packet/s.
+ *  @param[in] device_id The device identifier.
+ *  @param[in] packet The received packet or the received packet queue.
+ *  @param[in] receiver The receiving module service.
+ *  @param[in] error The packet error reporting service. Prefixes the received packet.
+ *  @returns EOK on success.
+ */
+typedef int	(*tl_received_msg_t)(device_id_t device_id, packet_t packet, services_t receiver, services_t error);
+
+/** Creates bidirectional connection with the ip module service and registers the message receiver.
+ *  @param[in] service The IP module service.
+ *  @param[in] protocol The transport layer protocol.
+ *  @param[in] me The requesting module service.
+ *  @param[in] receiver The message receiver. Used for remote connection.
+ *  @param[in] tl_received_msg The message processing function. Used if bundled together.
+ *  @returns The phone of the needed service.
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for the bind_service() function.
+ */
+extern int ip_bind_service(services_t service, int protocol, services_t me, async_client_conn_t receiver, tl_received_msg_t tl_received_msg);
+
+/** Connects to the IP module.
+ *  @param service The IP module service. Ignored parameter.
+ *  @returns The IP module phone on success.
+ *  @returns 0 if called by the bundle module.
+ */
+extern int ip_connect_module(services_t service);
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/ip_local.h
===================================================================
--- uspace/lib/net/include/ip_local.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/ip_local.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,61 @@
+/*
+ * 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 ip
+ * @{
+ */
+
+#ifndef __NET_IP_LOCAL_H__
+#define __NET_IP_LOCAL_H__
+
+#include <async.h>
+#include <ipc/services.h>
+
+#include <ip_codes.h>
+#include <inet.h>
+#include <in.h>
+#include <socket.h>
+
+extern int ip_received_error_msg_local(int, device_id_t, packet_t, services_t,
+    services_t);
+extern int ip_set_gateway_req_local(int, device_id_t, in_addr_t);
+extern int ip_packet_size_req_local(int, device_id_t, packet_dimension_ref);
+extern int ip_received_error_msg_local(int, device_id_t, packet_t, services_t,
+    services_t);
+extern int ip_device_req_local(int, device_id_t, services_t);
+extern int ip_add_route_req_local(int, device_id_t, in_addr_t, in_addr_t,
+    in_addr_t);
+extern int ip_send_msg_local(int, device_id_t, packet_t, services_t,
+    services_t);
+extern int ip_get_route_req_local(int, ip_protocol_t, const struct sockaddr *,
+    socklen_t, device_id_t *, void **, size_t *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/ip_messages.h
===================================================================
--- uspace/lib/net/include/ip_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/ip_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,106 @@
+/*
+ * 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 ip
+ *  @{
+ */
+
+/** @file
+ *  IP module messages.
+ *  @see ip_interface.h
+ */
+
+#ifndef __NET_IP_MESSAGES_H__
+#define __NET_IP_MESSAGES_H__
+
+#include <ipc/ipc.h>
+
+#include <in.h>
+#include <ip_codes.h>
+
+/** IP module messages.
+ */
+typedef enum{
+	/** Adds the routing entry.
+	 *  @see ip_add_route()
+	 */
+	NET_IP_ADD_ROUTE = NET_IP_FIRST,
+	/** Gets the actual route information.
+	 *  @see ip_get_route()
+	 */
+	NET_IP_GET_ROUTE,
+	/** Processes the received error notification.
+	 *  @see ip_received_error_msg()
+	 */
+	NET_IP_RECEIVED_ERROR,
+	/** Sets the default gateway.
+	 *  @see ip_set_default_gateway()
+	 */
+	NET_IP_SET_GATEWAY
+} ip_messages;
+
+/** @name IP specific message parameters definitions
+ */
+/*@{*/
+
+/** Returns the address message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define IP_GET_ADDRESS(call) \
+	({in_addr_t addr; addr.s_addr = IPC_GET_ARG3(*call); addr;})
+
+/** Returns the gateway message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define IP_GET_GATEWAY(call) \
+	({in_addr_t addr; addr.s_addr = IPC_GET_ARG2(*call); addr;})
+
+/** Sets the header length in the message answer.
+ *  @param[out] answer The message answer structure.
+ */
+#define IP_SET_HEADERLEN(answer, value) \
+	{ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG2(*answer, argument);}
+
+/** Returns the network mask message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define IP_GET_NETMASK(call) \
+	({in_addr_t addr; addr.s_addr = IPC_GET_ARG4(*call); addr;})
+
+/** Returns the protocol message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define IP_GET_PROTOCOL(call) \
+	({ip_protocol_t protocol = (ip_protocol_t) IPC_GET_ARG1(*call); protocol;})
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/ip_remote.h
===================================================================
--- uspace/lib/net/include/ip_remote.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/ip_remote.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,59 @@
+/*
+ * 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 ip
+ * @{
+ */
+
+#ifndef __NET_IP_REMOTE_H__
+#define __NET_IP_REMOTE_H__
+
+#include <async.h>
+#include <ipc/services.h>
+
+#include <ip_codes.h>
+#include <inet.h>
+#include <in.h>
+#include <socket.h>
+
+extern int ip_set_gateway_req_remote(int, device_id_t, in_addr_t);
+extern int ip_packet_size_req_remote(int, device_id_t, packet_dimension_ref);
+extern int ip_received_error_msg_remote(int, device_id_t, packet_t, services_t,
+    services_t);
+extern int ip_device_req_remote(int, device_id_t, services_t);
+extern int ip_add_route_req_remote(int, device_id_t, in_addr_t, in_addr_t,
+    in_addr_t);
+extern int ip_send_msg_remote(int, device_id_t, packet_t, services_t,
+    services_t);
+extern int ip_get_route_req_remote(int, ip_protocol_t, const struct sockaddr *,
+    socklen_t, device_id_t *, void **, size_t *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/net_checksum.h
===================================================================
--- uspace/lib/net/include/net_checksum.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/net_checksum.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,113 @@
+/*
+ * 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
+ *  General CRC and checksum computation.
+ */
+
+#ifndef __NET_CHECKSUM_H__
+#define __NET_CHECKSUM_H__
+
+#include <byteorder.h>
+
+#include <sys/types.h>
+
+/** IP checksum value for computed zero checksum.
+ *  Zero is returned as 0xFFFF (not flipped)
+ */
+#define IP_CHECKSUM_ZERO			0xFFFFu
+
+/**	Computes CRC32 value.
+ *  @param[in] seed Initial value. Often used as 0 or ~0.
+ *  @param[in] data Pointer to the beginning of data to process.
+ *  @param[in] length Length of the data in bits.
+ *  @returns The computed CRC32 of the length bits of the data.
+ */
+#ifdef ARCH_IS_BIG_ENDIAN
+	#define compute_crc32(seed, data, length)	compute_crc32_be(seed, (uint8_t *) data, length)
+#else
+	#define compute_crc32(seed, data, length)	compute_crc32_le(seed, (uint8_t *) data, length)
+#endif
+
+/**	Computes CRC32 value in the little-endian environment.
+ *  @param[in] seed Initial value. Often used as 0 or ~0.
+ *  @param[in] data Pointer to the beginning of data to process.
+ *  @param[in] length Length of the data in bits.
+ *  @returns The computed CRC32 of the length bits of the data.
+ */
+extern uint32_t compute_crc32_le(uint32_t seed, uint8_t * data, size_t length);
+
+/**	Computes CRC32 value in the big-endian environment.
+ *  @param[in] seed Initial value. Often used as 0 or ~0.
+ *  @param[in] data Pointer to the beginning of data to process.
+ *  @param[in] length Length of the data in bits.
+ *  @returns The computed CRC32 of the length bits of the data.
+ */
+extern uint32_t compute_crc32_be(uint32_t seed, uint8_t * data, size_t length);
+
+/** Computes sum of the 2 byte fields.
+ *  Padds one zero (0) byte if odd.
+ *  @param[in] seed Initial value. Often used as 0 or ~0.
+ *  @param[in] data Pointer to the beginning of data to process.
+ *  @param[in] length Length of the data in bytes.
+ *  @returns The computed checksum of the length bytes of the data.
+ */
+extern uint32_t compute_checksum(uint32_t seed, uint8_t * data, size_t length);
+
+/** Compacts the computed checksum to the 16 bit number adding the carries.
+ *  @param[in] sum Computed checksum.
+ *  @returns Compacted computed checksum to the 16 bits.
+ */
+extern uint16_t compact_checksum(uint32_t sum);
+
+/** Returns or flips the checksum if zero.
+ *  @param[in] checksum The computed checksum.
+ *  @returns The internet protocol header checksum.
+ *  @returns 0xFFFF if the computed checksum is zero.
+ */
+extern uint16_t flip_checksum(uint16_t checksum);
+
+/** Computes the ip header checksum.
+ *  To compute the checksum of a new packet, the checksum header field must be zero.
+ *  To check the checksum of a received packet, the checksum may be left set.
+ *  The zero (0) value will be returned in this case if valid.
+ *  @param[in] data The header data.
+ *  @param[in] length The header length in bytes.
+ *  @returns The internet protocol header checksum.
+ *  @returns 0xFFFF if the computed checksum is zero.
+ */
+extern uint16_t ip_checksum(uint8_t * data, size_t length);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/net_hardware.h
===================================================================
--- uspace/lib/net/include/net_hardware.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/net_hardware.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,195 @@
+/*
+ * 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_nil
+ *  @{
+ */
+
+/** @file
+ *  Hardware types according to the on-line IANA - Address Resolution Protocol (ARP) Parameters - <http://www.iana.org/assignments/arp-parameters/arp-parameters.xml>, cited January 14 2009.
+ */
+
+#ifndef __NET_HW_TYPES_H__
+#define __NET_HW_TYPES_H__
+
+#include <sys/types.h>
+
+/** Network interface layer type type definition.
+ */
+typedef uint8_t	hw_type_t;
+
+/** @name Network interface layer types definitions
+ */
+/*@{*/
+
+/** Ethernet (10Mb) hardware type.
+ */
+#define HW_ETHER		1
+
+/** Experimental Ethernet (3Mb) hardware type.
+ */
+#define HW_EETHER		2
+
+/** Amateur Radio AX.25 hardware type.
+ */
+#define HW_AX25		3
+
+/** Proteon ProNET Token Ring hardware type.
+ */
+#define HW_PRONET		4
+
+/** Chaos hardware type.
+ */
+#define HW_CHAOS		5
+
+/** IEEE 802 Networks hardware type.
+ */
+#define HW_IEEE802		6
+
+/** ARCNET hardware type.
+ */
+#define HW_ARCNET		7
+
+/** Hyperchannel hardware type.
+ */
+#define HW_Hyperchannel		8
+
+/** Lanstar hardware type.
+ */
+#define HW_Lanstar		9
+
+/** Autonet Short Address hardware type.
+ */
+#define HW_ASA		10
+
+/** LocalTalk hardware type.
+ */
+#define HW_LocalTalk		11
+
+/** LocalNet (IBM PCNet or SYTEK LocalNET) hardware type.
+ */
+#define HW_LocalNet		12
+
+/** Ultra link hardware type.
+ */
+#define HW_Ultra_link		13
+
+/** SMDS hardware type.
+ */
+#define HW_SMDS		14
+
+/** Frame Relay DLCI hardware type.
+ */
+#define HW_DLCI		15
+
+/** Asynchronous Transmission Mode (ATM) hardware type.
+ */
+#define HW_ATM		16
+
+/** HDLC hardware type.
+ */
+#define HW_HDLC		17
+
+/** Fibre Channel hardware type.
+ */
+#define HW_Fibre_Channel		18
+
+/** Asynchronous Transmission Mode (ATM) hardware type.
+ */
+#define HW_ATM2		19
+
+/** Serial Line hardware type.
+ */
+#define HW_Serial_Line		20
+
+/** Asynchronous Transmission Mode (ATM) hardware type.
+ */
+#define HW_ATM3		21
+
+/** MIL-STD-188-220 hardware type.
+ */
+#define HW_MIL_STD_188_220		22
+
+/** Metricom hardware type.
+ */
+#define HW_METRICOM		23
+
+/** IEEE 1394.1995 hardware type.
+ */
+#define HW_IEEE1394		24
+
+/** MAPOS hardware type.
+ */
+#define HW_MAPOS		25
+
+/** Twinaxial hardware type.
+ */
+#define HW_Twinaxial		26
+
+/** EUI-64 hardware type.
+ */
+#define HW_EUI64		27
+
+/** HIPARP hardware type.
+ */
+#define HW_HIPARP		28
+
+/** IP and ARP over ISO 7816-3 hardware type.
+ */
+#define HW_ISO_7816_3		29
+
+/** ARPSec hardware type.
+ */
+#define HW_ARPSec		30
+
+/** IPsec tunnel hardware type.
+ */
+#define HW_IPsec_tunnel		31
+
+/** InfiniBand (TM) hardware type.
+ */
+#define HW_INFINIBAND		32
+
+/** TIA-102 Project 25 Common Air Interface (CAI) hardware type.
+ */
+#define HW_CAI		33
+
+/** Wiegand Interface hardware type.
+ */
+#define HW_Wiegand		34
+
+/** Pure IP hardware type.
+ */
+#define HW_Pure_IP		35
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/net_interface.h
===================================================================
--- uspace/lib/net/include/net_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/net_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,96 @@
+/*
+ * 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 __NET_NET_INTERFACE_H__
+#define __NET_NET_INTERFACE_H__
+
+#include <ipc/services.h>
+
+#include <net_device.h>
+#include <adt/measured_strings.h>
+
+/** @name Networking module interface
+ *  This interface is used by other modules.
+ */
+/*@{*/
+
+/** Returns the device specific configuration.
+ *  Returns the global configuration if the device specific is not found.
+ *  The configuration names are read and the appropriate settings are set instead.
+ *  Call net_free_settings() function to release the returned configuration.
+ *  @param[in] net_phone The networking module phone.
+ *  @param[in] device_id The device identifier.
+ *  @param[in,out] configuration The requested device configuration. The names are read and the appropriate settings are set instead.
+ *  @param[in] count The configuration entries count.
+ *  @param[in,out] data The configuration and settings data.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the configuration is NULL.
+ *  @returns EINVAL if the count is zero (0).
+ *  @returns Other error codes as defined for the generic_translate_req() function.
+ */
+extern int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data);
+
+/** Returns the global configuration.
+ *  The configuration names are read and the appropriate settings are set instead.
+ *  Call net_free_settings() function to release the returned configuration.
+ *  @param[in] net_phone The networking module phone.
+ *  @param[in,out] configuration The requested configuration. The names are read and the appropriate settings are set instead.
+ *  @param[in] count The configuration entries count.
+ *  @param[in,out] data The configuration and settings data.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the configuration is NULL.
+ *  @returns EINVAL if the count is zero (0).
+ *  @returns Other error codes as defined for the generic_translate_req() function.
+ */
+extern int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data);
+
+/** Frees the received settings.
+ *  @param[in] settings The received settings.
+ *  @param[in] data The received settings data.
+ *  @see net_get_device_conf_req()
+ *  @see net_get_conf_req()
+ */
+extern void net_free_settings(measured_string_ref settings, char * data);
+
+/** Connects to the networking module.
+ *  @param service The networking module service. Ignored parameter.
+ *  @returns The networking module phone on success.
+ *  @returns 0 if called by the bundle module.
+ */
+extern int net_connect_module(services_t service);
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/net_net_messages.h
===================================================================
--- uspace/lib/net/include/net_net_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/net_net_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,64 @@
+/*
+ * 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 subsystem central module messages.
+ *  @see net_interface.h
+ */
+
+#ifndef __NET_NET_MESSAGES_H__
+#define __NET_NET_MESSAGES_H__
+
+#include <ipc/ipc.h>
+
+#include <net_messages.h>
+
+/** Networking subsystem central module messages.
+ */
+typedef enum{
+	/** Returns the general configuration
+	 *  @see net_get_conf_req()
+	 */
+	NET_NET_GET_CONF = NET_FIRST,
+	/** Returns the device specific configuration
+	 *  @see net_get_device_conf_req()
+	 */
+	NET_NET_GET_DEVICE_CONF,
+	/** Starts the networking stack.
+	 */
+	NET_NET_STARTUP,
+} net_messages;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/netif_interface.h
===================================================================
--- uspace/lib/net/include/netif_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/netif_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,72 @@
+/*
+ * 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 netif
+ * @{
+ */
+
+#ifndef __NET_NETIF_INTERFACE_H__
+#define __NET_NETIF_INTERFACE_H__
+
+#ifdef CONFIG_NETIF_NIL_BUNDLE
+
+#include <netif_local.h>
+#include <netif_nil_bundle.h>
+#include <packet/packet_server.h>
+
+#define netif_module_message    netif_nil_module_message
+#define netif_module_start      netif_nil_module_start
+#define netif_get_addr_req      netif_get_addr_req_local
+#define netif_probe_req         netif_probe_req_local
+#define netif_send_msg          netif_send_msg_local
+#define netif_start_req         netif_start_req_local
+#define netif_stop_req          netif_stop_req_local
+#define netif_stats_req         netif_stats_req_local
+#define netif_bind_service      netif_bind_service_local
+
+#else /* CONFIG_NETIF_NIL_BUNDLE */
+
+#include <netif_remote.h>
+#include <packet/packet_client.h>
+
+#define netif_module_message    netif_module_message_standalone
+#define netif_module_start      netif_module_start_standalone
+#define netif_get_addr_req      netif_get_addr_req_remote
+#define netif_probe_req         netif_probe_req_remote
+#define netif_send_msg          netif_send_msg_remote
+#define netif_start_req         netif_start_req_remote
+#define netif_stop_req          netif_stop_req_remote
+#define netif_stats_req         netif_stats_req_remote
+#define netif_bind_service      netif_bind_service_remote
+
+#endif /* CONFIG_NETIF_NIL_BUNDLE */
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/netif_local.h
===================================================================
--- uspace/lib/net/include/netif_local.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/netif_local.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,227 @@
+/*
+ * 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 netif
+ * @{
+ */
+
+/** @file
+ * Network interface module skeleton.
+ * The skeleton has to be part of each network interface module.
+ * The skeleton can be also part of the module bundled with the network interface layer.
+ */
+
+#ifndef __NET_NETIF_LOCAL_H__
+#define __NET_NETIF_LOCAL_H__
+
+#include <async.h>
+#include <fibril_synch.h>
+#include <ipc/ipc.h>
+#include <ipc/services.h>
+
+#include <adt/measured_strings.h>
+#include <net_err.h>
+#include <net_device.h>
+#include <packet/packet.h>
+
+/** Network interface device specific data.
+ *
+ */
+typedef struct {
+	device_id_t device_id;  /**< Device identifier. */
+	int nil_phone;          /**< Receiving network interface layer phone. */
+	device_state_t state;   /**< Actual device state. */
+	void *specific;         /**< Driver specific data. */
+} netif_device_t;
+
+/** Device map.
+ *
+ * Maps device identifiers to the network interface device specific data.
+ * @see device.h
+ *
+ */
+DEVICE_MAP_DECLARE(netif_device_map, netif_device_t);
+
+/** Network interface module skeleton global data.
+ *
+ */
+typedef struct {
+	int net_phone;                  /**< Networking module phone. */
+	netif_device_map_t device_map;  /**< Device map. */
+	fibril_rwlock_t lock;           /**< Safety lock. */
+} netif_globals_t;
+
+extern netif_globals_t netif_globals;
+
+/** Initialize the specific module.
+ *
+ * This function has to be implemented in user code.
+ *
+ */
+extern int netif_initialize(void);
+
+/** Probe the existence of the device.
+ *
+ * This has to be implemented in user code.
+ *
+ * @param[in] device_id The device identifier.
+ * @param[in] irq       The device interrupt number.
+ * @param[in] io        The device input/output address.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for the find_device() function.
+ * @return Other error codes as defined for the specific module message
+ *         implementation.
+ *
+ */
+extern int netif_probe_message(device_id_t device_id, int irq, uintptr_t io);
+
+/** Send the packet queue.
+ *
+ * This has to be implemented in user code.
+ *
+ * @param[in] device_id The device identifier.
+ * @param[in] packet    The packet queue.
+ * @param[in] sender    The sending module service.
+ *
+ * @return EOK on success.
+ * @return EFORWARD if the device is not active (in the NETIF_ACTIVE state).
+ * @return Other error codes as defined for the find_device() function.
+ * @return Other error codes as defined for the specific module message
+ *         implementation.
+ *
+ */
+extern int netif_send_message(device_id_t device_id, packet_t packet,
+    services_t sender);
+
+/** Start the device.
+ *
+ * This has to be implemented in user code.
+ *
+ * @param[in] device The device structure.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for the find_device() function.
+ * @return Other error codes as defined for the specific module message
+ *         implementation.
+ *
+ */
+extern int netif_start_message(netif_device_t *device);
+
+/** Stop the device.
+ *
+ * This has to be implemented in user code.
+ *
+ * @param[in] device The device structure.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for the find_device() function.
+ * @return Other error codes as defined for the specific module message
+ *         implementation.
+ *
+ */
+extern int netif_stop_message(netif_device_t *device);
+
+/** Return the device local hardware address.
+ *
+ * This has to be implemented in user code.
+ *
+ * @param[in]  device_id The device identifier.
+ * @param[out] address   The device local hardware address.
+ *
+ * @return EOK on success.
+ * @return EBADMEM if the address parameter is NULL.
+ * @return ENOENT if there no such device.
+ * @return Other error codes as defined for the find_device() function.
+ * @return Other error codes as defined for the specific module message
+ *         implementation.
+ *
+ */
+extern int netif_get_addr_message(device_id_t device_id,
+    measured_string_ref address);
+
+/** Process the netif driver specific message.
+ *
+ * This function is called for uncommon messages received by the netif
+ * skeleton. This has to be implemented in user code.
+ *
+ * @param[in]  callid       The message identifier.
+ * @param[in]  call         The message parameters.
+ * @param[out] answer       The message answer parameters.
+ * @param[out] answer_count The last parameter for the actual answer in
+ *                          the answer parameter.
+ *
+ * @return EOK on success.
+ * @return ENOTSUP if the message is not known.
+ * @return Other error codes as defined for the specific module message
+ *         implementation.
+ *
+ */
+extern int netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, int *answer_count);
+
+/** Return the device usage statistics.
+ *
+ * This has to be implemented in user code.
+ *
+ * @param[in]  device_id The device identifier.
+ * @param[out] stats     The device usage statistics.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for the find_device() function.
+ * @return Other error codes as defined for the specific module message
+ *         implementation.
+ *
+ */
+extern int netif_get_device_stats(device_id_t device_id,
+    device_stats_ref stats);
+
+extern int netif_get_addr_req_local(int, device_id_t, measured_string_ref *,
+    char **);
+extern int netif_probe_req_local(int, device_id_t, int, int);
+extern int netif_send_msg_local(int, device_id_t, packet_t, services_t);
+extern int netif_start_req_local(int, device_id_t);
+extern int netif_stop_req_local(int, device_id_t);
+extern int netif_stats_req_local(int, device_id_t, device_stats_ref);
+extern int netif_bind_service_local(services_t, device_id_t, services_t,
+    async_client_conn_t);
+
+extern int find_device(device_id_t, netif_device_t **);
+extern void null_device_stats(device_stats_ref);
+extern void netif_pq_release(packet_id_t);
+extern packet_t netif_packet_get_1(size_t);
+extern int netif_init_module(async_client_conn_t);
+
+extern int netif_module_message_standalone(const char *, ipc_callid_t,
+    ipc_call_t *, ipc_call_t *, int *);
+extern int netif_module_start_standalone(async_client_conn_t);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/netif_messages.h
===================================================================
--- uspace/lib/net/include/netif_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/netif_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,94 @@
+/*
+ * 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 netif
+ * @{
+ */
+
+/** @file
+ * Network interface common module messages.
+ */
+
+#ifndef __NET_NETIF_MESSAGES_H__
+#define __NET_NETIF_MESSAGES_H__
+
+#include <ipc/ipc.h>
+
+#include <net_messages.h>
+
+/** Network interface common module messages.
+ */
+typedef enum {
+	/** Probe device message.
+	 *  @see netif_probe_req()
+	 */
+	NET_NETIF_PROBE = NET_NETIF_FIRST,
+	/** Send packet message.
+	 *  @see netif_send_msg()
+	 */
+	NET_NETIF_SEND,
+	/** Start device message.
+	 *  @see netif_start_req()
+	 */
+	NET_NETIF_START,
+	/** Get device usage statistics message.
+	 *  @see netif_stats_req()
+	 */
+	NET_NETIF_STATS,
+	/** Stop device message.
+	 *  @see netif_stop_req()
+	 */
+	NET_NETIF_STOP,
+	/** Get device address message.
+	 *  @see netif_get_addr_req()
+	 */
+	NET_NETIF_GET_ADDR,
+} netif_messages;
+
+/** @name Network interface specific message parameters definitions
+ */
+/*@{*/
+
+/** Return the interrupt number message parameter.
+ * @param[in] call The message call structure.
+ */
+#define NETIF_GET_IRQ(call) \
+	({int irq = (int) IPC_GET_ARG2(*call); irq;})
+
+/** Return the input/output address message parameter.
+ * @param[in] call The message call structure.
+ */
+#define NETIF_GET_IO(call) \
+	({int io = (int) IPC_GET_ARG3(*call); io;})
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/netif_nil_bundle.h
===================================================================
--- uspace/lib/net/include/netif_nil_bundle.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/netif_nil_bundle.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2010 Martin Decky
+ * 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 netif_standalone
+ *  @{
+ */
+
+#ifndef __NETIF_NIL_BUNDLE_H__
+#define __NETIF_NIL_BUNDLE_H__
+
+#include <ipc/ipc.h>
+#include <async.h>
+
+extern int netif_nil_module_message(const char *, ipc_callid_t, ipc_call_t *,
+    ipc_call_t *, int *);
+extern int netif_nil_module_start(async_client_conn_t);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/netif_remote.h
===================================================================
--- uspace/lib/net/include/netif_remote.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/netif_remote.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,53 @@
+/*
+ * 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 netif
+ * @{
+ */
+
+#ifndef __NET_NETIF_REMOTE_H__
+#define __NET_NETIF_REMOTE_H__
+
+#include <async.h>
+#include <fibril_synch.h>
+#include <ipc/ipc.h>
+
+extern int netif_get_addr_req_remote(int, device_id_t, measured_string_ref *,
+    char **);
+extern int netif_probe_req_remote(int, device_id_t, int, int);
+extern int netif_send_msg_remote(int, device_id_t, packet_t, services_t);
+extern int netif_start_req_remote(int, device_id_t);
+extern int netif_stop_req_remote(int, device_id_t);
+extern int netif_stats_req_remote(int, device_id_t, device_stats_ref);
+extern int netif_bind_service_remote(services_t, device_id_t, services_t,
+    async_client_conn_t);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/nil_interface.h
===================================================================
--- uspace/lib/net/include/nil_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/nil_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,91 @@
+/*
+ * 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_nil
+ *  @{
+ */
+
+#ifndef __NET_NIL_INTERFACE_H__
+#define __NET_NIL_INTERFACE_H__
+
+#include <async.h>
+#include <errno.h>
+
+#include <ipc/ipc.h>
+
+#include <net_messages.h>
+#include <adt/measured_strings.h>
+#include <packet/packet.h>
+#include <nil_messages.h>
+#include <net_device.h>
+
+#define nil_bind_service(service, device_id, me, receiver) \
+	bind_service(service, device_id, me, 0, receiver)
+
+#define nil_packet_size_req(nil_phone, device_id, packet_dimension) \
+	generic_packet_size_req_remote(nil_phone, NET_NIL_PACKET_SPACE, device_id, \
+	    packet_dimension)
+
+#define nil_get_addr_req(nil_phone, device_id, address, data) \
+	generic_get_addr_req(nil_phone, NET_NIL_ADDR, device_id, address, data)
+
+#define nil_get_broadcast_addr_req(nil_phone, device_id, address, data) \
+	generic_get_addr_req(nil_phone, NET_NIL_BROADCAST_ADDR, device_id, \
+	    address, data)
+
+#define nil_send_msg(nil_phone, device_id, packet, sender) \
+	generic_send_msg_remote(nil_phone, NET_NIL_SEND, device_id, \
+	    packet_get_id(packet), sender, 0)
+
+#define nil_device_req(nil_phone, device_id, mtu, netif_service) \
+	generic_device_req_remote(nil_phone, NET_NIL_DEVICE, device_id, mtu, \
+	    netif_service)
+
+
+#ifdef CONFIG_NETIF_NIL_BUNDLE
+
+#include <nil_local.h>
+#include <packet/packet_server.h>
+
+#define nil_device_state_msg  nil_device_state_msg_local
+#define nil_received_msg      nil_received_msg_local
+
+#else /* CONFIG_NETIF_NIL_BUNDLE */
+
+#include <nil_remote.h>
+#include <packet/packet_server.h>
+
+#define nil_device_state_msg  nil_device_state_msg_remote
+#define nil_received_msg      nil_received_msg_remote
+
+#endif /* CONFIG_NETIF_NIL_BUNDLE */
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/nil_local.h
===================================================================
--- uspace/lib/net/include/nil_local.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/nil_local.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,86 @@
+/*
+ * 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_nil
+ *  @{
+ */
+
+/** @file
+ * Network interface layer modules common skeleton.
+ * All network interface layer modules have to implement this interface.
+ */
+
+#ifndef __NET_NIL_LOCAL_H__
+#define __NET_NIL_LOCAL_H__
+
+#include <ipc/ipc.h>
+
+/** Module initialization.
+ *
+ * Is called by the module_start() function.
+ *
+ * @param[in] net_phone The networking moduel phone.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for each specific module initialize function.
+ *
+ */
+extern int nil_initialize(int);
+
+extern int nil_device_state_msg_local(int, device_id_t, int);
+extern int nil_received_msg_local(int, device_id_t, packet_t, services_t);
+
+/** Message processing function.
+ *
+ * @param[in]  name         Module name.
+ * @param[in]  callid       The message identifier.
+ * @param[in]  call         The message parameters.
+ * @param[out] answer       The message answer parameters.
+ * @param[out] answer_count The last parameter for the actual answer
+ *                          in the answer parameter.
+ *
+ * @return EOK on success.
+ * @return ENOTSUP if the message is not known.
+ * @return Other error codes as defined for each specific
+ *         module message function.
+ *
+ * @see nil_interface.h
+ * @see IS_NET_NIL_MESSAGE()
+ *
+ */
+extern int nil_message_standalone(const char *, ipc_callid_t, ipc_call_t *, ipc_call_t *,
+    int *);
+
+extern int nil_module_message_standalone(const char *, ipc_callid_t,
+    ipc_call_t *, ipc_call_t *, int *);
+extern int nil_module_start_standalone(async_client_conn_t);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/nil_messages.h
===================================================================
--- uspace/lib/net/include/nil_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/nil_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,91 @@
+/*
+ * 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_nil
+ * @{
+ */
+
+/** @file
+ * Network interface layer module messages.
+ */
+
+#ifndef __NET_NIL_MESSAGES_H__
+#define __NET_NIL_MESSAGES_H__
+
+#include <ipc/ipc.h>
+
+#include <net_messages.h>
+
+/** Network interface layer module messages.
+ */
+typedef enum {
+	/** New device or update MTU message.
+	 *  @see nil_device_req()
+	 */
+	NET_NIL_DEVICE = NET_NIL_FIRST,
+	/** New device state message.
+	 *  @see nil_device_state_msg()
+	 */
+	NET_NIL_DEVICE_STATE,
+	/** Received packet queue message.
+	 *  @see nil_received_msg()
+	 */
+	NET_NIL_RECEIVED,
+	/** Send packet queue message.
+	 *  @see nil_send_msg()
+	 */
+	NET_NIL_SEND,
+	/** Packet size message.
+	 *  @see nil_packet_size_req()
+	 */
+	NET_NIL_PACKET_SPACE,
+	/** Device local hardware address message.
+	 *  @see nil_get_addr()
+	 */
+	NET_NIL_ADDR,
+	/** Device broadcast hardware address message.
+	 *  @see nil_get_broadcast_addr()
+	 */
+	NET_NIL_BROADCAST_ADDR,
+} nil_messages;
+
+/** @name Network interface layer specific message parameters definitions
+ */
+/*@{*/
+
+/** Return the protocol service message parameter.
+ */
+#define NIL_GET_PROTO(call) \
+	({services_t service = (services_t) IPC_GET_ARG2(*call); service;})
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/nil_remote.h
===================================================================
--- uspace/lib/net/include/nil_remote.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/nil_remote.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,46 @@
+/*
+ * 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 netif
+ * @{
+ */
+
+#ifndef __NET_NIL_REMOTE_H__
+#define __NET_NIL_REMOTE_H__
+
+#include <async.h>
+#include <fibril_synch.h>
+#include <ipc/ipc.h>
+
+extern int nil_device_state_msg_remote(int, device_id_t, int);
+extern int nil_received_msg_remote(int, device_id_t, packet_t, services_t);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/packet_remote.h
===================================================================
--- uspace/lib/net/include/packet_remote.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/packet_remote.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,46 @@
+/*
+ * 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
+ * @{
+ */
+
+#ifndef __NET_PACKET_REMOTE_H__
+#define __NET_PACKET_REMOTE_H__
+
+#include <packet/packet.h>
+
+extern int packet_translate_remote(int, packet_ref, packet_id_t);
+extern packet_t packet_get_4_remote(int, size_t, size_t, size_t, size_t);
+extern packet_t packet_get_1_remote(int, size_t);
+extern void pq_release_remote(int, packet_id_t);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/protocol_map.h
===================================================================
--- uspace/lib/net/include/protocol_map.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/protocol_map.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,142 @@
+/*
+ * 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_nil
+ *  @{
+ */
+
+/** @file
+ *  Internetwork layer services - network interface layer service type translation.
+ */
+
+#ifndef __NET_PROTOCOL_MAP_H__
+#define __NET_PROTOCOL_MAP_H__
+
+#include <ipc/services.h>
+
+#include <ethernet_lsap.h>
+#include <ethernet_protocols.h>
+#include <net_hardware.h>
+
+/** Maps the internetwork layer service to the network interface layer type.
+ *  @param[in] nil Network interface layer service.
+ *  @param[in] il Internetwork layer service.
+ *  @returns Network interface layer type of the internetworking layer service.
+ *  @returns 0 if mapping is not found.
+ */
+static inline eth_type_t protocol_map(services_t nil, services_t il){
+	switch(nil){
+		case SERVICE_ETHERNET:
+		case SERVICE_DP8390:
+			switch(il){
+				case SERVICE_IP:
+					return ETH_P_IP;
+				case SERVICE_ARP:
+					return ETH_P_ARP;
+				default:
+					return 0;
+			}
+		default:
+			return 0;
+	}
+}
+
+/** Maps the network interface layer type to the internetwork layer service.
+ *  @param[in] nil Network interface layer service.
+ *  @param[in] protocol Network interface layer type.
+ *  @returns Internetwork layer service of the network interface layer type.
+ *  @returns 0 if mapping is not found.
+ */
+static inline services_t protocol_unmap(services_t nil, int protocol){
+	switch(nil){
+		case SERVICE_ETHERNET:
+		case SERVICE_DP8390:
+			switch(protocol){
+				case ETH_P_IP:
+					return SERVICE_IP;
+				case ETH_P_ARP:
+					return SERVICE_ARP;
+				default:
+					return 0;
+			}
+		default:
+			return 0;
+	}
+}
+
+/** Maps the link service access point identifier to the Ethernet protocol identifier.
+ *  @param[in] lsap Link service access point identifier.
+ *  @returns Ethernet protocol identifier of the link service access point identifier.
+ *  @returns ETH_LSAP_NULL if mapping is not found.
+ */
+static inline eth_type_t lsap_map(eth_lsap_t lsap){
+	switch(lsap){
+		case ETH_LSAP_IP:
+			return ETH_P_IP;
+		case ETH_LSAP_ARP:
+			return ETH_P_ARP;
+		default:
+			return ETH_LSAP_NULL;
+	}
+}
+
+/** Maps the Ethernet protocol identifier to the link service access point identifier.
+ *  @param[in] ethertype Ethernet protocol identifier.
+ *  @returns Link service access point identifier.
+ *  @returns 0 if mapping is not found.
+ */
+static inline eth_lsap_t lsap_unmap(eth_type_t ethertype){
+	switch(ethertype){
+		case ETH_P_IP:
+			return ETH_LSAP_IP;
+		case ETH_P_ARP:
+			return ETH_LSAP_ARP;
+		default:
+			return 0;
+	}
+}
+
+/** Maps the network interface layer services to the hardware types.
+ *  @param[in] nil The network interface service.
+ *  @returns The hardware type of the network interface service.
+ *  @returns 0 if mapping is not found.
+ */
+static inline hw_type_t hardware_map(services_t nil){
+	switch(nil){
+		case SERVICE_ETHERNET:
+		case SERVICE_DP8390:
+			return HW_ETHER;
+		default:
+			return 0;
+	}
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/tl_common.h
===================================================================
--- uspace/lib/net/include/tl_common.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/tl_common.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2008 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_tl
+ *  @{
+ */
+
+/** @file
+ *  Transport layer common functions.
+ */
+
+#ifndef __NET_TL_COMMON_H__
+#define __NET_TL_COMMON_H__
+
+#include <packet/packet.h>
+#include <net_device.h>
+#include <inet.h>
+#include <socket_codes.h>
+
+/** Device packet dimensions.
+ *  Maps devices to the packet dimensions.
+ *  @see device.h
+ */
+DEVICE_MAP_DECLARE(packet_dimensions, packet_dimension_t);
+
+extern int tl_get_ip_packet_dimension(int, packet_dimensions_ref,
+    device_id_t, packet_dimension_ref *);
+
+/** Gets the address port.
+ *  Supports AF_INET and AF_INET6 address families.
+ *  @param[in,out] addr The address to be updated.
+ *  @param[in] addrlen The address length.
+ *  @param[out] port The set port.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the address length does not match the address family.
+ *  @returns EAFNOSUPPORT if the address family is not supported.
+ */
+extern int tl_get_address_port(const struct sockaddr * addr, int addrlen, uint16_t * port);
+
+/** Updates IP device packet dimensions cache.
+ *  @param[in,out] packet_dimensions The packet dimensions cache.
+ *  @param[in] device_id The device identifier.
+ *  @param[in] content The new maximum content size.
+ *  @returns EOK on success.
+ *  @returns ENOENT if the packet dimension is not cached.
+ */
+extern int tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, device_id_t device_id, size_t content);
+
+/** Sets the address port.
+ *  Supports AF_INET and AF_INET6 address families.
+ *  @param[in,out] addr The address to be updated.
+ *  @param[in] addrlen The address length.
+ *  @param[in] port The port to be set.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the address length does not match the address family.
+ *  @returns EAFNOSUPPORT if the address family is not supported.
+ */
+extern int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port);
+
+/** Prepares the packet for ICMP error notification.
+ *  Keeps the first packet and releases all the others.
+ *  Releases all the packets on error.
+ *  @param[in] packet_phone The packet server module phone.
+ *  @param[in] icmp_phone The ICMP module phone.
+ *  @param[in] packet The packet to be send.
+ *  @param[in] error The packet error reporting service. Prefixes the received packet.
+ *  @returns EOK on success.
+ *  @returns ENOENT if no packet may be sent.
+ */
+extern int tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, services_t error);
+
+/** Receives data from the socket into a packet.
+ *  @param[in] packet_phone The packet server module phone.
+ *  @param[out] packet The new created packet.
+ *  @param[in] prefix Reserved packet data prefix length.
+ *  @param[in] dimension The packet dimension.
+ *  @param[in] addr The destination address.
+ *  @param[in] addrlen The address length.
+ *  @returns Number of bytes received.
+ *  @returns EINVAL if the client does not send data.
+ *  @returns ENOMEM if there is not enough memory left.
+ *  @returns Other error codes as defined for the async_data_read_finalize() function.
+ */
+extern int tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix, const packet_dimension_ref dimension, const struct sockaddr * addr, socklen_t addrlen);
+
+#endif
+
+/** @}
+ */
+
Index: uspace/lib/net/include/tl_interface.h
===================================================================
--- uspace/lib/net/include/tl_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/tl_interface.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,82 @@
+/*
+ * 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_tl
+ *  @{
+ */
+
+/** @file
+ * Transport layer module interface for the underlying internetwork layer.
+ */
+
+#ifndef __NET_TL_INTERFACE_H__
+#define __NET_TL_INTERFACE_H__
+
+#include <async.h>
+#include <ipc/services.h>
+
+#include <net_messages.h>
+#include <net_device.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+#include <tl_messages.h>
+
+/** @name Transport layer module interface
+ * This interface is used by other modules.
+ */
+/*@{*/
+
+/** Notify the remote transport layer modules about the received packet/s.
+ *
+ * @param[in] tl_phone  The transport layer module phone used for remote calls.
+ * @param[in] device_id The device identifier.
+ * @param[in] packet    The received packet or the received packet queue.
+ *                      The packet queue is used to carry a fragmented
+ *                      datagram. The first packet contains the headers,
+ *                      the others contain only data.
+ * @param[in] target    The target transport layer module service to be
+ *                      delivered to.
+ * @param[in] error     The packet error reporting service. Prefixes the
+ *                      received packet.
+ *
+ * @return EOK on success.
+ *
+ */
+inline static int tl_received_msg(int tl_phone, device_id_t device_id,
+    packet_t packet, services_t target, services_t error)
+{
+	return generic_received_msg_remote(tl_phone, NET_TL_RECEIVED, device_id,
+	    packet_get_id(packet), target, error);
+}
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/tl_local.h
===================================================================
--- uspace/lib/net/include/tl_local.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/tl_local.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2010 Martin Decky
+ * 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 tl_local
+ *  @{
+ */
+
+#ifndef __TL_LOCAL_H__
+#define __TL_LOCAL_H__
+
+#include <ipc/ipc.h>
+#include <async.h>
+
+extern int tl_module_message_standalone(ipc_callid_t, ipc_call_t *,
+    ipc_call_t *, int *);
+extern int tl_module_start_standalone(async_client_conn_t);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/include/tl_messages.h
===================================================================
--- uspace/lib/net/include/tl_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/include/tl_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,57 @@
+/*
+ * 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_tl
+ *  @{
+ */
+
+/** @file
+ *  Transport layer modules messages.
+ *  @see tl_interface.h
+ */
+
+#ifndef __NET_TL_MESSAGES_H__
+#define __NET_TL_MESSAGES_H__
+
+#include <ipc/ipc.h>
+
+#include <net_messages.h>
+
+/** Transport layer modules messages.
+ */
+typedef enum{
+	/** Packet received message.
+	 *  @see tl_received_msg()
+	 */
+	NET_TL_RECEIVED = NET_TL_FIRST
+} tl_messages;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/net/netif/netif_local.c
===================================================================
--- uspace/lib/net/netif/netif_local.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/netif/netif_local.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,468 @@
+/*
+ * 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 netif
+ * @{
+ */
+
+/** @file
+ * Network interface module skeleton implementation.
+ * @see netif.h
+ */
+
+#include <async.h>
+#include <mem.h>
+#include <fibril_synch.h>
+#include <stdio.h>
+#include <ipc/ipc.h>
+#include <ipc/services.h>
+
+#include <net_err.h>
+#include <net_messages.h>
+#include <net_modules.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+#include <packet/packet_server.h>
+#include <packet_remote.h>
+#include <adt/measured_strings.h>
+#include <net_device.h>
+#include <nil_interface.h>
+#include <netif_local.h>
+#include <netif_messages.h>
+#include <netif_interface.h>
+
+DEVICE_MAP_IMPLEMENT(netif_device_map, netif_device_t);
+
+/** Network interface global data.
+ */
+netif_globals_t netif_globals;
+
+/** Probe the existence of the device.
+ *
+ * @param[in] netif_phone The network interface phone.
+ * @param[in] device_id   The device identifier.
+ * @param[in] irq         The device interrupt number.
+ * @param[in] io          The device input/output address.
+ *
+ * @return EOK on success.
+ * @return Other errro codes as defined for the netif_probe_message().
+ *
+ */
+int netif_probe_req_local(int netif_phone, device_id_t device_id, int irq, int io)
+{
+	fibril_rwlock_write_lock(&netif_globals.lock);
+	int result = netif_probe_message(device_id, irq, io);
+	fibril_rwlock_write_unlock(&netif_globals.lock);
+	
+	return result;
+}
+
+/** Send the packet queue.
+ *
+ * @param[in] netif_phone The network interface phone.
+ * @param[in] device_id   The device identifier.
+ * @param[in] packet      The packet queue.
+ * @param[in] sender      The sending module service.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for the generic_send_msg() function.
+ *
+ */
+int netif_send_msg_local(int netif_phone, device_id_t device_id,
+    packet_t packet, services_t sender)
+{
+	fibril_rwlock_write_lock(&netif_globals.lock);
+	int result = netif_send_message(device_id, packet, sender);
+	fibril_rwlock_write_unlock(&netif_globals.lock);
+	
+	return result;
+}
+
+/** Start the device.
+ *
+ * @param[in] netif_phone The network interface phone.
+ * @param[in] device_id   The device identifier.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for the find_device() function.
+ * @return Other error codes as defined for the netif_start_message() function.
+ *
+ */
+int netif_start_req_local(int netif_phone, device_id_t device_id)
+{
+	ERROR_DECLARE;
+	
+	fibril_rwlock_write_lock(&netif_globals.lock);
+	
+	netif_device_t *device;
+	if (ERROR_OCCURRED(find_device(device_id, &device))) {
+		fibril_rwlock_write_unlock(&netif_globals.lock);
+		return ERROR_CODE;
+	}
+	
+	int result = netif_start_message(device);
+	if (result > NETIF_NULL) {
+		int phone = device->nil_phone;
+		fibril_rwlock_write_unlock(&netif_globals.lock);
+		nil_device_state_msg(phone, device_id, result);
+		return EOK;
+	}
+	
+	fibril_rwlock_write_unlock(&netif_globals.lock);
+	
+	return result;
+}
+
+/** Stop the device.
+ *
+ * @param[in] netif_phone The network interface phone.
+ * @param[in] device_id   The device identifier.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for the find_device() function.
+ * @return Other error codes as defined for the netif_stop_message() function.
+ *
+ */
+int netif_stop_req_local(int netif_phone, device_id_t device_id)
+{
+	ERROR_DECLARE;
+	
+	fibril_rwlock_write_lock(&netif_globals.lock);
+	
+	netif_device_t *device;
+	if (ERROR_OCCURRED(find_device(device_id, &device))) {
+		fibril_rwlock_write_unlock(&netif_globals.lock);
+		return ERROR_CODE;
+	}
+	
+	int result = netif_stop_message(device);
+	if (result > NETIF_NULL) {
+		int phone = device->nil_phone;
+		fibril_rwlock_write_unlock(&netif_globals.lock);
+		nil_device_state_msg(phone, device_id, result);
+		return EOK;
+	}
+	
+	fibril_rwlock_write_unlock(&netif_globals.lock);
+	
+	return result;
+}
+
+/** Return the device usage statistics.
+ *
+ * @param[in]  netif_phone The network interface phone.
+ * @param[in]  device_id   The device identifier.
+ * @param[out] stats       The device usage statistics.
+ *
+ * @return EOK on success.
+ *
+ */
+int netif_stats_req_local(int netif_phone, device_id_t device_id,
+    device_stats_ref stats)
+{
+	fibril_rwlock_read_lock(&netif_globals.lock);
+	int res = netif_get_device_stats(device_id, stats);
+	fibril_rwlock_read_unlock(&netif_globals.lock);
+	
+	return res;
+}
+
+/** Return the device local hardware address.
+ *
+ * @param[in]  netif_phone The network interface phone.
+ * @param[in]  device_id   The device identifier.
+ * @param[out] address     The device local hardware address.
+ * @param[out] data        The address data.
+ *
+ * @return EOK on success.
+ * @return EBADMEM if the address parameter is NULL.
+ * @return ENOENT if there no such device.
+ * @return Other error codes as defined for the netif_get_addr_message()
+ *         function.
+ *
+ */
+int netif_get_addr_req_local(int netif_phone, device_id_t device_id,
+    measured_string_ref *address, char **data)
+{
+	ERROR_DECLARE;
+	
+	if ((!address) || (!data))
+		return EBADMEM;
+	
+	fibril_rwlock_read_lock(&netif_globals.lock);
+	
+	measured_string_t translation;
+	if (!ERROR_OCCURRED(netif_get_addr_message(device_id, &translation))) {
+		*address = measured_string_copy(&translation);
+		ERROR_CODE = (*address) ? EOK : ENOMEM;
+	}
+	
+	fibril_rwlock_read_unlock(&netif_globals.lock);
+	
+	*data = (**address).value;
+	
+	return ERROR_CODE;
+}
+
+/** Create bidirectional connection with the network interface module and registers the message receiver.
+ *
+ * @param[in] service   The network interface module service.
+ * @param[in] device_id The device identifier.
+ * @param[in] me        The requesting module service.
+ * @param[in] receiver  The message receiver.
+ *
+ * @return The phone of the needed service.
+ * @return EOK on success.
+ * @return Other error codes as defined for the bind_service() function.
+ *
+ */
+int netif_bind_service_local(services_t service, device_id_t device_id,
+    services_t me, async_client_conn_t receiver)
+{
+	return EOK;
+}
+
+/** Find the device specific data.
+ *
+ * @param[in]  device_id The device identifier.
+ * @param[out] device    The device specific data.
+ *
+ * @return EOK on success.
+ * @return ENOENT if device is not found.
+ * @return EPERM if the device is not initialized.
+ *
+ */
+int find_device(device_id_t device_id, netif_device_t **device)
+{
+	if (!device)
+		return EBADMEM;
+	
+	*device = netif_device_map_find(&netif_globals.device_map, device_id);
+	if (*device == NULL)
+		return ENOENT;
+	
+	if ((*device)->state == NETIF_NULL)
+		return EPERM;
+	
+	return EOK;
+}
+
+/** Clear the usage statistics.
+ *
+ * @param[in] stats The usage statistics.
+ *
+ */
+void null_device_stats(device_stats_ref stats)
+{
+	bzero(stats, sizeof(device_stats_t));
+}
+
+/** Initialize the netif module.
+ *
+ *  @param[in] client_connection The client connection functio to be
+ *                               registered.
+ *
+ *  @return EOK on success.
+ *  @return Other error codes as defined for each specific module
+ *          message function.
+ *
+ */
+int netif_init_module(async_client_conn_t client_connection)
+{
+	ERROR_DECLARE;
+	
+	async_set_client_connection(client_connection);
+	
+	netif_globals.net_phone = connect_to_service(SERVICE_NETWORKING);
+	netif_device_map_initialize(&netif_globals.device_map);
+	
+	ERROR_PROPAGATE(pm_init());
+	
+	fibril_rwlock_initialize(&netif_globals.lock);
+	if (ERROR_OCCURRED(netif_initialize())) {
+		pm_destroy();
+		return ERROR_CODE;
+	}
+	
+	return EOK;
+}
+
+/** Release the given packet.
+ *
+ * Prepared for future optimization.
+ *
+ * @param[in] packet_id The packet identifier.
+ *
+ */
+void netif_pq_release(packet_id_t packet_id)
+{
+	pq_release_remote(netif_globals.net_phone, packet_id);
+}
+
+/** Allocate new packet to handle the given content size.
+ *
+ * @param[in] content The minimum content size.
+ *
+ * @return The allocated packet.
+ * @return NULL if there is an error.
+ *
+ */
+packet_t netif_packet_get_1(size_t content)
+{
+	return packet_get_1_remote(netif_globals.net_phone, content);
+}
+
+/** Register the device notification receiver, the network interface layer module.
+ *
+ * @param[in] name      Module name.
+ * @param[in] device_id The device identifier.
+ * @param[in] phone     The network interface layer module phone.
+ *
+ * @return EOK on success.
+ * @return ENOENT if there is no such device.
+ * @return ELIMIT if there is another module registered.
+ *
+ */
+static int register_message(const char *name, device_id_t device_id, int phone)
+{
+	ERROR_DECLARE;
+	
+	netif_device_t *device;
+	ERROR_PROPAGATE(find_device(device_id, &device));
+	if(device->nil_phone > 0)
+		return ELIMIT;
+	
+	device->nil_phone = phone;
+	printf("%s: Receiver of device %d registered (phone: %d)\n",
+	    name, device->device_id, device->nil_phone);
+	return EOK;
+}
+
+/** Process the netif module messages.
+ *
+ * @param[in]  name         Module name.
+ * @param[in]  callid       The message identifier.
+ * @param[in]  call         The message parameters.
+ * @param[out] answer       The message answer parameters.
+ * @param[out] answer_count The last parameter for the actual answer
+ *                          in the answer parameter.
+ *
+ * @return EOK on success.
+ * @return ENOTSUP if the message is not known.
+ * @return Other error codes as defined for each specific module message function.
+ *
+ * @see IS_NET_NETIF_MESSAGE()
+ *
+ */
+int netif_module_message_standalone(const char *name, ipc_callid_t callid,
+    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
+{
+	ERROR_DECLARE;
+	
+	size_t length;
+	device_stats_t stats;
+	packet_t packet;
+	measured_string_t address;
+	
+	*answer_count = 0;
+	switch (IPC_GET_METHOD(*call)) {
+		case IPC_M_PHONE_HUNGUP:
+			return EOK;
+		case NET_NETIF_PROBE:
+			return netif_probe_req_local(0, IPC_GET_DEVICE(call),
+			    NETIF_GET_IRQ(call), NETIF_GET_IO(call));
+		case IPC_M_CONNECT_TO_ME:
+			fibril_rwlock_write_lock(&netif_globals.lock);
+			ERROR_CODE = register_message(name, IPC_GET_DEVICE(call),
+			    IPC_GET_PHONE(call));
+			fibril_rwlock_write_unlock(&netif_globals.lock);
+			return ERROR_CODE;
+		case NET_NETIF_SEND:
+			ERROR_PROPAGATE(packet_translate_remote(netif_globals.net_phone,
+			    &packet, IPC_GET_PACKET(call)));
+			return netif_send_msg_local(0, IPC_GET_DEVICE(call), packet,
+			    IPC_GET_SENDER(call));
+		case NET_NETIF_START:
+			return netif_start_req_local(0, IPC_GET_DEVICE(call));
+		case NET_NETIF_STATS:
+			fibril_rwlock_read_lock(&netif_globals.lock);
+			if (!ERROR_OCCURRED(async_data_read_receive(&callid, &length))) {
+				if (length < sizeof(device_stats_t))
+					ERROR_CODE = EOVERFLOW;
+				else {
+					if (!ERROR_OCCURRED(netif_get_device_stats(
+					    IPC_GET_DEVICE(call), &stats)))
+						ERROR_CODE = async_data_read_finalize(callid, &stats,
+						    sizeof(device_stats_t));
+				}
+			}
+			fibril_rwlock_read_unlock(&netif_globals.lock);
+			return ERROR_CODE;
+		case NET_NETIF_STOP:
+			return netif_stop_req_local(0, IPC_GET_DEVICE(call));
+		case NET_NETIF_GET_ADDR:
+			fibril_rwlock_read_lock(&netif_globals.lock);
+			if (!ERROR_OCCURRED(netif_get_addr_message(IPC_GET_DEVICE(call),
+			    &address)))
+				ERROR_CODE = measured_strings_reply(&address, 1);
+			fibril_rwlock_read_unlock(&netif_globals.lock);
+			return ERROR_CODE;
+	}
+	
+	return netif_specific_message(callid, call, answer, answer_count);
+}
+
+/** Start the network interface module.
+ *
+ * Initialize the client connection serving function, initialize
+ * the module, registers the module service and start the async
+ * manager, processing IPC messages in an infinite loop.
+ *
+ * @param[in] client_connection The client connection processing
+ *                              function. The module skeleton propagates
+ *                              its own one.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for each specific module message
+ *         function.
+ *
+ */
+int netif_module_start_standalone(async_client_conn_t client_connection)
+{
+	ERROR_DECLARE;
+	
+	ERROR_PROPAGATE(netif_init_module(client_connection));
+	
+	async_manager();
+	
+	pm_destroy();
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/net/netif/netif_nil_bundle.c
===================================================================
--- uspace/lib/net/netif/netif_nil_bundle.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/netif/netif_nil_bundle.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,105 @@
+/*
+ * 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 netif
+ *  @{
+ */
+
+/** @file
+ *  Wrapper for the bundled network interface and network interface layer module.
+ *  Distributes messages and initializes both module parts.
+ */
+
+#include <async.h>
+#include <ipc/ipc.h>
+
+#include <net_messages.h>
+#include <packet/packet.h>
+#include <netif_nil_bundle.h>
+#include <netif_local.h>
+#include <nil_local.h>
+
+/** Distribute the messages between the module parts.
+ *
+ * @param[in]  name         Module name.
+ * @param[in]  callid       The message identifier.
+ * @param[in]  call         The message parameters.
+ * @param[out] answer       The message answer parameters.
+ * @param[out] answer_count The last parameter for the actual
+ *                          answer in the answer parameter.
+ *
+ * @return EOK on success.
+ * @return ENOTSUP if the message is not known.
+ * @return Other error codes as defined for each specific module message function.
+ *
+ */
+int netif_nil_module_message(const char *name, ipc_callid_t callid,
+    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
+{
+	if ((IS_NET_NIL_MESSAGE(call))
+	    || (IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME))
+		return nil_message_standalone(name, callid, call, answer,
+		    answer_count);
+	else
+		return netif_module_message_standalone(name, callid, call, answer,
+		    answer_count);
+}
+
+/** Start the bundle network interface module.
+ *
+ * Initialize the client connection serving function, initialize
+ * both module parts, register the module service and start the
+ * async manager, processing IPC messages in an infinite loop.
+ *
+ * @param[in] client_connection The client connection processing
+ *                              function. The module skeleton propagates
+ *                              its own one.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for each specific module message
+ *         function.
+ *
+ */
+int netif_nil_module_start(async_client_conn_t client_connection)
+{
+	ERROR_DECLARE;
+	
+	ERROR_PROPAGATE(netif_init_module(client_connection));
+	if (ERROR_OCCURRED(nil_initialize(netif_globals.net_phone))) {
+		pm_destroy();
+		return ERROR_CODE;
+	}
+	
+	async_manager();
+	
+	pm_destroy();
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/net/netif/netif_remote.c
===================================================================
--- uspace/lib/net/netif/netif_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/netif/netif_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,99 @@
+/*
+ * 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 netif
+ * @{
+ */
+
+/** @file
+ * Network interface module interface implementation for remote modules.
+ */
+
+#include <ipc/services.h>
+
+#include <net_modules.h>
+#include <adt/measured_strings.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+#include <net_device.h>
+#include <netif_remote.h>
+#include <netif_messages.h>
+
+int netif_get_addr_req_remote(int netif_phone, device_id_t device_id,
+    measured_string_ref *address, char **data)
+{
+	return generic_get_addr_req(netif_phone, NET_NETIF_GET_ADDR, device_id,
+	    address, data);
+}
+
+int netif_probe_req_remote(int netif_phone, device_id_t device_id, int irq, int io)
+{
+	return async_req_3_0(netif_phone, NET_NETIF_PROBE, device_id, irq, io);
+}
+
+int netif_send_msg_remote(int netif_phone, device_id_t device_id, packet_t packet,
+    services_t sender)
+{
+	return generic_send_msg_remote(netif_phone, NET_NETIF_SEND, device_id,
+	    packet_get_id(packet), sender, 0);
+}
+
+int netif_start_req_remote(int netif_phone, device_id_t device_id)
+{
+	return async_req_1_0(netif_phone, NET_NETIF_START, device_id);
+}
+
+int netif_stop_req_remote(int netif_phone, device_id_t device_id)
+{
+	return async_req_1_0(netif_phone, NET_NETIF_STOP, device_id);
+}
+
+int netif_stats_req_remote(int netif_phone, device_id_t device_id,
+    device_stats_ref stats)
+{
+	if (!stats)
+		return EBADMEM;
+	
+	aid_t message_id = async_send_1(netif_phone, NET_NETIF_STATS,
+	    (ipcarg_t) device_id, NULL);
+	async_data_read_start(netif_phone, stats, sizeof(*stats));
+	
+	ipcarg_t result;
+	async_wait_for(message_id, &result);
+	
+	return (int) result;
+}
+
+int netif_bind_service_remote(services_t service, device_id_t device_id, services_t me,
+    async_client_conn_t receiver)
+{
+	return bind_service(service, device_id, me, 0, receiver);
+}
+
+/** @}
+ */
Index: uspace/lib/net/nil/nil_remote.c
===================================================================
--- uspace/lib/net/nil/nil_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/nil/nil_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,86 @@
+/*
+ * 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_nil
+ * @{
+ */
+
+/** @file
+ * Network interface layer interface implementation for remote modules.
+ * @see nil_interface.h
+ */
+
+#include <net_messages.h>
+#include <net_device.h>
+#include <nil_interface.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+#include <nil_messages.h>
+#include <nil_remote.h>
+
+/** Notify the network interface layer about the device state change.
+ *
+ * @param[in] nil_phone The network interface layer phone.
+ * @param[in] device_id The device identifier.
+ * @param[in] state     The new device state.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for each specific module device
+ *         state function.
+ *
+ */
+int nil_device_state_msg_remote(int nil_phone, device_id_t device_id, int state)
+{
+	return generic_device_state_msg_remote(nil_phone, NET_NIL_DEVICE_STATE,
+	    device_id, state, 0);
+}
+
+/** Pass the packet queue to the network interface layer.
+ *
+ * Process and redistribute the received packet queue to the registered
+ * upper layers.
+ *
+ * @param[in] nil_phone The network interface layer phone.
+ * @param[in] device_id The source device identifier.
+ * @param[in] packet    The received packet or the received packet queue.
+ * @param     target    The target service. Ignored parameter.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for each specific module
+ *         received function.
+ *
+ */
+int nil_received_msg_remote(int nil_phone, device_id_t device_id,
+    packet_t packet, services_t target)
+{
+	return generic_received_msg_remote(nil_phone, NET_NIL_RECEIVED, device_id,
+	    packet_get_id(packet), target, 0);
+}
+
+/** @}
+ */
Index: uspace/lib/net/tl/icmp_client.c
===================================================================
--- uspace/lib/net/tl/icmp_client.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/tl/icmp_client.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,86 @@
+/*
+ * 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 icmp
+ *  @{
+ */
+
+/** @file
+ *  ICMP client interface implementation.
+ *  @see icmp_client.h
+ */
+
+#ifdef CONFIG_DEBUG
+	#include <stdio.h>
+#endif
+
+#include <errno.h>
+#include <sys/types.h>
+
+#include <icmp_codes.h>
+#include <icmp_client.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+#include <icmp_header.h>
+
+int icmp_client_process_packet(packet_t packet, icmp_type_t * type, icmp_code_t * code, icmp_param_t * pointer, icmp_param_t * mtu){
+	icmp_header_ref header;
+
+	header = (icmp_header_ref) packet_get_data(packet);
+	if((! header)
+		|| (packet_get_data_length(packet) < sizeof(icmp_header_t))){
+		return 0;
+	}
+	if(type){
+		*type = header->type;
+	}
+	if(code){
+		*code = header->code;
+	}
+	if(pointer){
+		*pointer = header->un.param.pointer;
+	}
+	if(mtu){
+		*mtu = header->un.frag.mtu;
+	}
+	// remove debug dump
+#ifdef CONFIG_DEBUG
+	printf("ICMP error %d (%d) in packet %d\n", header->type, header->code, packet_get_id(packet));
+#endif
+	return sizeof(icmp_header_t);
+}
+
+size_t icmp_client_header_length(packet_t packet){
+	if(packet_get_data_length(packet) < sizeof(icmp_header_t)){
+		return 0;
+	}
+	return sizeof(icmp_header_t);
+}
+
+/** @}
+ */
Index: uspace/lib/net/tl/icmp_remote.c
===================================================================
--- uspace/lib/net/tl/icmp_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/tl/icmp_remote.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,71 @@
+/*
+ * 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 icmp
+ *  @{
+ */
+
+/** @file
+ *  ICMP interface implementation for remote modules.
+ *  @see icmp_interface.h
+ */
+
+#include <async.h>
+#include <errno.h>
+#include <ipc/ipc.h>
+#include <ipc/services.h>
+#include <sys/types.h>
+
+#include <net_messages.h>
+#include <net_modules.h>
+#include <icmp_interface.h>
+#include <packet/packet_client.h>
+#include <icmp_messages.h>
+
+int icmp_destination_unreachable_msg(int icmp_phone, icmp_code_t code, icmp_param_t mtu, packet_t packet){
+	async_msg_3(icmp_phone, NET_ICMP_DEST_UNREACH, (ipcarg_t) code, (ipcarg_t) packet_get_id(packet), (ipcarg_t) mtu);
+	return EOK;
+}
+
+int icmp_source_quench_msg(int icmp_phone, packet_t packet){
+	async_msg_2(icmp_phone, NET_ICMP_SOURCE_QUENCH, 0, (ipcarg_t) packet_get_id(packet));
+	return EOK;
+}
+
+int icmp_time_exceeded_msg(int icmp_phone, icmp_code_t code, packet_t packet){
+	async_msg_2(icmp_phone, NET_ICMP_TIME_EXCEEDED, (ipcarg_t) code, (ipcarg_t) packet_get_id(packet));
+	return EOK;
+}
+
+int icmp_parameter_problem_msg(int icmp_phone, icmp_code_t code, icmp_param_t pointer, packet_t packet){
+	async_msg_3(icmp_phone, NET_ICMP_PARAMETERPROB, (ipcarg_t) code, (ipcarg_t) packet_get_id(packet), (ipcarg_t) pointer);
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/net/tl/tl_common.c
===================================================================
--- uspace/lib/net/tl/tl_common.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/net/tl/tl_common.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,250 @@
+/*
+ * Copyright (c) 2008 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_tl
+ *  @{
+ */
+
+/** @file
+ *  Transport layer common functions implementation.
+ *  @see tl_common.h
+ */
+
+#include <async.h>
+#include <ipc/services.h>
+
+#include <net_err.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+#include <packet_remote.h>
+#include <net_device.h>
+#include <icmp_interface.h>
+#include <in.h>
+#include <in6.h>
+#include <inet.h>
+#include <ip_local.h>
+#include <ip_remote.h>
+#include <socket_codes.h>
+#include <socket_errno.h>
+#include <ip_interface.h>
+#include <tl_interface.h>
+#include <tl_common.h>
+
+DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t);
+
+int tl_get_address_port(const struct sockaddr * addr, int addrlen, uint16_t * port){
+	const struct sockaddr_in * address_in;
+	const struct sockaddr_in6 * address_in6;
+
+	if((addrlen <= 0) || ((size_t) addrlen < sizeof(struct sockaddr))){
+		return EINVAL;
+	}
+	switch(addr->sa_family){
+		case AF_INET:
+			if(addrlen != sizeof(struct sockaddr_in)){
+				return EINVAL;
+			}
+			address_in = (struct sockaddr_in *) addr;
+			*port = ntohs(address_in->sin_port);
+			break;
+		case AF_INET6:
+			if(addrlen != sizeof(struct sockaddr_in6)){
+				return EINVAL;
+			}
+			address_in6 = (struct sockaddr_in6 *) addr;
+			*port = ntohs(address_in6->sin6_port);
+			break;
+		default:
+			return EAFNOSUPPORT;
+	}
+	return EOK;
+}
+
+/** Get IP packet dimensions.
+ *
+ * Try to search a cache and query the IP module if not found.
+ * The reply is cached then.
+ *
+ * @param[in]  ip_phone          The IP moduel phone for (semi)remote calls.
+ * @param[in]  packet_dimensions The packet dimensions cache.
+ * @param[in]  device_id         The device identifier.
+ * @param[out] packet_dimension  The IP packet dimensions.
+ *
+ * @return EOK on success.
+ * @return EBADMEM if the packet_dimension parameter is NULL.
+ * @return ENOMEM if there is not enough memory left.
+ * @return EINVAL if the packet_dimensions cache is not valid.
+ * @return Other codes as defined for the ip_packet_size_req() function.
+ *
+ */
+int tl_get_ip_packet_dimension(int ip_phone,
+    packet_dimensions_ref packet_dimensions, device_id_t device_id,
+    packet_dimension_ref *packet_dimension)
+{
+	ERROR_DECLARE;
+	
+	if (!packet_dimension)
+		return EBADMEM;
+	
+	*packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
+	if (!*packet_dimension) {
+		/* Ask for and remember them if not found */
+		*packet_dimension = malloc(sizeof(**packet_dimension));
+		if(!*packet_dimension)
+			return ENOMEM;
+		
+		if (ERROR_OCCURRED(ip_packet_size_req(ip_phone, device_id,
+		    *packet_dimension))) {
+			free(*packet_dimension);
+			return ERROR_CODE;
+		}
+		
+		ERROR_CODE = packet_dimensions_add(packet_dimensions, device_id,
+		    *packet_dimension);
+		if (ERROR_CODE < 0) {
+			free(*packet_dimension);
+			return ERROR_CODE;
+		}
+	}
+	
+	return EOK;
+}
+
+int tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, device_id_t device_id, size_t content){
+	packet_dimension_ref packet_dimension;
+
+	packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
+	if(! packet_dimension){
+		return ENOENT;
+	}
+	packet_dimension->content = content;
+	if(device_id != DEVICE_INVALID_ID){
+		packet_dimension = packet_dimensions_find(packet_dimensions, DEVICE_INVALID_ID);
+		if(packet_dimension){
+			if(packet_dimension->content >= content){
+				packet_dimension->content = content;
+			}else{
+				packet_dimensions_exclude(packet_dimensions, DEVICE_INVALID_ID);
+			}
+		}
+	}
+	return EOK;
+}
+
+int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port){
+	struct sockaddr_in * address_in;
+	struct sockaddr_in6 * address_in6;
+	size_t length;
+
+	if(addrlen < 0){
+		return EINVAL;
+	}
+	length = (size_t) addrlen;
+	if(length < sizeof(struct sockaddr)){
+		return EINVAL;
+	}
+	switch(addr->sa_family){
+		case AF_INET:
+			if(length != sizeof(struct sockaddr_in)){
+				return EINVAL;
+			}
+			address_in = (struct sockaddr_in *) addr;
+			address_in->sin_port = htons(port);
+			return EOK;
+		case AF_INET6:
+			if(length != sizeof(struct sockaddr_in6)){
+				return EINVAL;
+			}
+			address_in6 = (struct sockaddr_in6 *) addr;
+			address_in6->sin6_port = htons(port);
+			return EOK;
+		default:
+			return EAFNOSUPPORT;
+	}
+}
+
+int tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, services_t error){
+	packet_t next;
+	uint8_t * src;
+	int length;
+
+	// detach the first packet and release the others
+	next = pq_detach(packet);
+	if (next)
+		pq_release_remote(packet_phone, packet_get_id(next));
+	
+	length = packet_get_addr(packet, &src, NULL);
+	if((length > 0)
+		&& (! error)
+		&& (icmp_phone >= 0)
+	// set both addresses to the source one (avoids the source address deletion before setting the destination one)
+		&& (packet_set_addr(packet, src, src, (size_t) length) == EOK)){
+		return EOK;
+	}else{
+		pq_release_remote(packet_phone, packet_get_id(packet));
+	}
+	return ENOENT;
+}
+
+int tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix, const packet_dimension_ref dimension, const struct sockaddr * addr, socklen_t addrlen){
+	ERROR_DECLARE;
+
+	ipc_callid_t callid;
+	size_t length;
+	void * data;
+
+	if(! dimension){
+		return EINVAL;
+	}
+	// get the data length
+	if(! async_data_write_receive(&callid, &length)){
+		return EINVAL;
+	}
+	// get a new packet
+	*packet = packet_get_4_remote(packet_phone, length, dimension->addr_len, prefix + dimension->prefix, dimension->suffix);
+	if(! packet){
+		return ENOMEM;
+	}
+	// allocate space in the packet
+	data = packet_suffix(*packet, length);
+	if(! data){
+		pq_release_remote(packet_phone, packet_get_id(*packet));
+		return ENOMEM;
+	}
+	// read the data into the packet
+	if(ERROR_OCCURRED(async_data_write_finalize(callid, data, length))
+	// set the packet destination address
+		|| ERROR_OCCURRED(packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen))){
+		pq_release_remote(packet_phone, packet_get_id(*packet));
+		return ERROR_CODE;
+	}
+	return (int) length;
+}
+
+/** @}
+ */
Index: uspace/lib/socket/Makefile
===================================================================
--- uspace/lib/socket/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,49 @@
+#
+# Copyright (c) 2005 Martin Decky
+# Copyright (c) 2007 Jakub Jermar
+# 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.
+#
+
+USPACE_PREFIX = ../..
+EXTRA_CFLAGS = -Iinclude
+LIBRARY = libsocket
+
+SOURCES = \
+	generic/socket_client.c \
+	generic/socket_core.c \
+	generic/socket_parse.c \
+	generic/inet.c \
+	generic/net_modules.c \
+	generic/icmp_common.c \
+	generic/icmp_api.c \
+	packet/packet.c \
+	packet/packet_client.c \
+	packet/packet_server.c \
+	adt/dynamic_fifo.c \
+	adt/measured_strings.c \
+	adt/char_map.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/socket/adt/char_map.c
===================================================================
--- uspace/lib/socket/adt/char_map.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/adt/char_map.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,234 @@
+/*
+ * 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
+ *  Character string to integer map implementation.
+ *  @see char_map.h
+ */
+
+#include <errno.h>
+#include <malloc.h>
+#include <mem.h>
+#include <unistd.h>
+
+#include <adt/char_map.h>
+
+/** Internal magic value for a&nbsp;consistency check.
+ */
+#define CHAR_MAP_MAGIC_VALUE	0x12345611
+
+/** Adds the value with the key to the map.
+ *  Creates new nodes to map the key.
+ *  @param[in,out] map The character string to integer map.
+ *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
+ *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
+ *  @param[in] value The integral value to be stored for the key character string.
+ *  @returns EOK on success.
+ *  @returns ENOMEM if there is not enough memory left.
+ *  @returns EEXIST if the key character string is already used.
+ */
+int char_map_add_item(char_map_ref map, const char * identifier, size_t length, const int value);
+
+/** Returns the node assigned to the key from the map.
+ *  @param[in] map The character string to integer map.
+ *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
+ *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
+ *  @returns The node holding the integral value assigned to the key character string.
+ *  @returns NULL if the key is not assigned a&nbsp;node.
+ */
+char_map_ref char_map_find_node(const char_map_ref map, const char * identifier, const size_t length);
+
+/** Returns the value assigned to the map.
+ *  @param[in] map The character string to integer map.
+ *  @returns The integral value assigned to the map.
+ *  @returns CHAR_MAP_NULL if the map is not assigned a&nbsp;value.
+ */
+int char_map_get_value(const char_map_ref map);
+
+/** Checks if the map is valid.
+ *  @param[in] map The character string to integer map.
+ *  @returns TRUE if the map is valid.
+ *  @returns FALSE otherwise.
+ */
+int char_map_is_valid(const char_map_ref map);
+
+int char_map_add(char_map_ref map, const char * identifier, size_t length, const int value){
+	if(char_map_is_valid(map) && (identifier) && ((length) || (*identifier))){
+		int index;
+
+		for(index = 0; index < map->next; ++ index){
+			if(map->items[index]->c == * identifier){
+				++ identifier;
+				if((length > 1) || ((length == 0) && (*identifier))){
+					return char_map_add(map->items[index], identifier, length ? length - 1 : 0, value);
+				}else{
+					if(map->items[index]->value != CHAR_MAP_NULL){
+						return EEXISTS;
+					}
+					map->items[index]->value = value;
+					return EOK;
+				}
+			}
+		}
+		return char_map_add_item(map, identifier, length, value);
+	}
+	return EINVAL;
+}
+
+int char_map_add_item(char_map_ref map, const char * identifier, size_t length, const int value){
+	if(map->next == (map->size - 1)){
+		char_map_ref *tmp;
+
+		tmp = (char_map_ref *) realloc(map->items, sizeof(char_map_ref) * 2 * map->size);
+		if(! tmp){
+			return ENOMEM;
+		}
+		map->size *= 2;
+		map->items = tmp;
+	}
+	map->items[map->next] = (char_map_ref) malloc(sizeof(char_map_t));
+	if(! map->items[map->next]){
+		return ENOMEM;
+	}
+	if(char_map_initialize(map->items[map->next]) != EOK){
+		free(map->items[map->next]);
+		map->items[map->next] = NULL;
+		return ENOMEM;
+	}
+	map->items[map->next]->c = * identifier;
+	++ identifier;
+	++ map->next;
+	if((length > 1) || ((length == 0) && (*identifier))){
+		map->items[map->next - 1]->value = CHAR_MAP_NULL;
+		return char_map_add_item(map->items[map->next - 1], identifier, length ? length - 1 : 0, value);
+	}else{
+		map->items[map->next - 1]->value = value;
+	}
+	return EOK;
+}
+
+void char_map_destroy(char_map_ref map){
+	if(char_map_is_valid(map)){
+		int index;
+
+		map->magic = 0;
+		for(index = 0; index < map->next; ++ index){
+			char_map_destroy(map->items[index]);
+		}
+		free(map->items);
+		map->items = NULL;
+	}
+}
+
+int char_map_exclude(char_map_ref map, const char * identifier, size_t length){
+	char_map_ref node;
+
+	node = char_map_find_node(map, identifier, length);
+	if(node){
+		int value;
+
+		value = node->value;
+		node->value = CHAR_MAP_NULL;
+		return value;
+	}
+	return CHAR_MAP_NULL;
+}
+
+int char_map_find(const char_map_ref map, const char * identifier, size_t length){
+	char_map_ref node;
+
+	node = char_map_find_node(map, identifier, length);
+	return node ? node->value : CHAR_MAP_NULL;
+}
+
+char_map_ref char_map_find_node(const char_map_ref map, const char * identifier, size_t length){
+	if(! char_map_is_valid(map)){
+		return NULL;
+	}
+	if(length || (*identifier)){
+		int index;
+
+		for(index = 0; index < map->next; ++ index){
+			if(map->items[index]->c == * identifier){
+				++ identifier;
+				if(length == 1){
+					return map->items[index];
+				}
+				return char_map_find_node(map->items[index], identifier, length ? length - 1 : 0);
+			}
+		}
+		return NULL;
+	}
+	return map;
+}
+
+int char_map_get_value(const char_map_ref map){
+	return char_map_is_valid(map) ? map->value : CHAR_MAP_NULL;
+}
+
+int char_map_initialize(char_map_ref map){
+	if(! map){
+		return EINVAL;
+	}
+	map->c = '\0';
+	map->value = CHAR_MAP_NULL;
+	map->size = 2;
+	map->next = 0;
+	map->items = malloc(sizeof(char_map_ref) * map->size);
+	if(! map->items){
+		map->magic = 0;
+		return ENOMEM;
+	}
+	map->items[map->next] = NULL;
+	map->magic = CHAR_MAP_MAGIC_VALUE;
+	return EOK;
+}
+
+int char_map_is_valid(const char_map_ref map){
+	return map && (map->magic == CHAR_MAP_MAGIC_VALUE);
+}
+
+int char_map_update(char_map_ref map, const char * identifier, const size_t length, const int value){
+	char_map_ref node;
+
+//	if(! char_map_is_valid(map)) return EINVAL;
+	node = char_map_find_node(map, identifier, length);
+	if(node){
+		node->value = value;
+		return EOK;
+	}else{
+		return char_map_add(map, identifier, length, value);
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/socket/adt/dynamic_fifo.c
===================================================================
--- uspace/lib/socket/adt/dynamic_fifo.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/adt/dynamic_fifo.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,151 @@
+/*
+ * 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
+ *  Dynamic first in first out positive integer queue implementation.
+ */
+
+#include <errno.h>
+#include <malloc.h>
+#include <mem.h>
+
+#include <adt/dynamic_fifo.h>
+
+/** Internal magic value for a&nbsp;consistency check.
+ */
+#define DYN_FIFO_MAGIC_VALUE	0x58627659
+
+/** Returns the next queue index.
+ *  The queue field is circular.
+ *  @param[in] fifo The dynamic queue.
+ *  @param[in] index The actual index to be shifted.
+ */
+#define NEXT_INDEX(fifo, index)	(((index) + 1) % ((fifo)->size + 1))
+
+/** Checks if the queue is valid.
+ *  @param[in] fifo The dynamic queue.
+ *  @returns TRUE if the queue is valid.
+ *  @returns FALSE otherwise.
+ */
+static int dyn_fifo_is_valid(dyn_fifo_ref fifo){
+	return fifo && (fifo->magic_value == DYN_FIFO_MAGIC_VALUE);
+}
+
+int dyn_fifo_initialize(dyn_fifo_ref fifo, int size){
+	if(! fifo){
+		return EBADMEM;
+	}
+	if(size <= 0){
+		return EINVAL;
+	}
+	fifo->items = (int *) malloc(sizeof(int) * size + 1);
+	if(! fifo->items){
+		return ENOMEM;
+	}
+	fifo->size = size;
+	fifo->head = 0;
+	fifo->tail = 0;
+	fifo->magic_value = DYN_FIFO_MAGIC_VALUE;
+	return EOK;
+}
+
+int dyn_fifo_push(dyn_fifo_ref fifo, int value, int max_size){
+	int * new_items;
+
+	if(! dyn_fifo_is_valid(fifo)){
+		return EINVAL;
+	}
+	if(NEXT_INDEX(fifo, fifo->tail) == fifo->head){
+		if((max_size > 0) && ((fifo->size * 2) > max_size)){
+			if(fifo->size >= max_size){
+				return ENOMEM;
+			}
+		}else{
+			max_size = fifo->size * 2;
+		}
+		new_items = realloc(fifo->items, sizeof(int) * max_size + 1);
+		if(! new_items){
+			return ENOMEM;
+		}
+		fifo->items = new_items;
+		if(fifo->tail < fifo->head){
+			if(fifo->tail < max_size - fifo->size){
+				memcpy(fifo->items + fifo->size + 1, fifo->items, fifo->tail * sizeof(int));
+				fifo->tail += fifo->size + 1;
+			}else{
+				memcpy(fifo->items + fifo->size + 1, fifo->items, (max_size - fifo->size) * sizeof(int));
+				memcpy(fifo->items, fifo->items + max_size - fifo->size, fifo->tail - max_size + fifo->size);
+				fifo->tail -= max_size - fifo->size;
+			}
+		}
+		fifo->size = max_size;
+	}
+	fifo->items[fifo->tail] = value;
+	fifo->tail = NEXT_INDEX(fifo, fifo->tail);
+	return EOK;
+}
+
+int dyn_fifo_pop(dyn_fifo_ref fifo){
+	int value;
+
+	if(! dyn_fifo_is_valid(fifo)){
+		return EINVAL;
+	}
+	if(fifo->head == fifo->tail){
+		return ENOENT;
+	}
+	value = fifo->items[fifo->head];
+	fifo->head = NEXT_INDEX(fifo, fifo->head);
+	return value;
+}
+
+int dyn_fifo_value(dyn_fifo_ref fifo){
+	if(! dyn_fifo_is_valid(fifo)){
+		return EINVAL;
+	}
+	if(fifo->head == fifo->tail){
+		return ENOENT;
+	}
+	return fifo->items[fifo->head];
+}
+
+int dyn_fifo_destroy(dyn_fifo_ref fifo){
+	if(! dyn_fifo_is_valid(fifo)){
+		return EINVAL;
+	}
+	free(fifo->items);
+	fifo->magic_value = 0;
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/socket/adt/measured_strings.c
===================================================================
--- uspace/lib/socket/adt/measured_strings.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/adt/measured_strings.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,284 @@
+/*
+ * 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
+ *  Character string with measured length implementation.
+ *  @see measured_strings.h
+ */
+
+#include <errno.h>
+#include <malloc.h>
+#include <mem.h>
+#include <unistd.h>
+
+#include <ipc/ipc.h>
+
+#include <net_err.h>
+#include <net_modules.h>
+#include <adt/measured_strings.h>
+
+measured_string_ref measured_string_create_bulk(const char * string, size_t length){
+	measured_string_ref new;
+
+	if(length == 0){
+		while(string[length]){
+			++ length;
+		}
+	}
+	new = (measured_string_ref) malloc(sizeof(measured_string_t) + (sizeof(char) * (length + 1)));
+	if(! new){
+		return NULL;
+	}
+	new->length = length;
+	new->value = ((char *) new) + sizeof(measured_string_t);
+	// append terminating zero explicitly - to be safe
+	memcpy(new->value, string, new->length);
+	new->value[new->length] = '\0';
+	return new;
+}
+
+measured_string_ref measured_string_copy(measured_string_ref source){
+	measured_string_ref new;
+
+	if(! source){
+		return NULL;
+	}
+	new = (measured_string_ref) malloc(sizeof(measured_string_t));
+	if(new){
+		new->value = (char *) malloc(source->length + 1);
+		if(new->value){
+			new->length = source->length;
+			memcpy(new->value, source->value, new->length);
+			new->value[new->length] = '\0';
+			return new;
+		}else{
+			free(new);
+		}
+	}
+	return NULL;
+}
+
+int measured_strings_receive(measured_string_ref * strings, char ** data, size_t count){
+	ERROR_DECLARE;
+
+	size_t * lengths;
+	size_t index;
+	size_t length;
+	char * next;
+	ipc_callid_t callid;
+
+	if((! strings) || (! data) || (count <= 0)){
+		return EINVAL;
+	}
+	lengths = (size_t *) malloc(sizeof(size_t) * (count + 1));
+	if(! lengths){
+		return ENOMEM;
+	}
+	if((! async_data_write_receive(&callid, &length))
+		|| (length != sizeof(size_t) * (count + 1))){
+		free(lengths);
+		return EINVAL;
+	}
+	if(ERROR_OCCURRED(async_data_write_finalize(callid, lengths, sizeof(size_t) * (count + 1)))){
+		free(lengths);
+		return ERROR_CODE;
+	}
+	*data = malloc(lengths[count]);
+	if(!(*data)){
+		return ENOMEM;
+	}
+	(*data)[lengths[count] - 1] = '\0';
+	*strings = (measured_string_ref) malloc(sizeof(measured_string_t) * count);
+	if(!(*strings)){
+		free(lengths);
+		free(*data);
+		return ENOMEM;
+	}
+	next = * data;
+	for(index = 0; index < count; ++ index){
+		(*strings)[index].length = lengths[index];
+		if(lengths[index] > 0){
+			if((! async_data_write_receive(&callid, &length))
+				|| (length != lengths[index])){
+				free(*data);
+				free(*strings);
+				free(lengths);
+				return EINVAL;
+			}
+			ERROR_PROPAGATE(async_data_write_finalize(callid, next, lengths[index]));
+			(*strings)[index].value = next;
+			next += lengths[index];
+			*next = '\0';
+			++ next;
+		}else{
+			(*strings)[index].value = NULL;
+		}
+	}
+	free(lengths);
+	return EOK;
+}
+
+/** Computes the lengths of the measured strings in the given array.
+ *  @param[in] strings The measured strings array to be processed.
+ *  @param[in] count The measured strings array size.
+ *  @returns The computed sizes array.
+ *  @returns NULL if there is not enough memory left.
+ */
+static size_t * prepare_lengths(const measured_string_ref strings, size_t count){
+	size_t * lengths;
+	size_t index;
+	size_t length;
+
+	lengths = (size_t *) malloc(sizeof(size_t) * (count + 1));
+	if(! lengths){
+		return NULL;
+	}
+	length = 0;
+	for(index = 0; index < count; ++ index){
+		lengths[index] = strings[index].length;
+		length += lengths[index] + 1;
+	}
+	lengths[count] = length;
+	return lengths;
+}
+
+int measured_strings_reply(const measured_string_ref strings, size_t count){
+	ERROR_DECLARE;
+
+	size_t * lengths;
+	size_t index;
+	size_t length;
+	ipc_callid_t callid;
+
+	if((! strings) || (count <= 0)){
+		return EINVAL;
+	}
+	lengths = prepare_lengths(strings, count);
+	if(! lengths){
+		return ENOMEM;
+	}
+	if((! async_data_read_receive(&callid, &length))
+		|| (length != sizeof(size_t) * (count + 1))){
+		free(lengths);
+		return EINVAL;
+	}
+	if(ERROR_OCCURRED(async_data_read_finalize(callid, lengths, sizeof(size_t) * (count + 1)))){
+		free(lengths);
+		return ERROR_CODE;
+	}
+	free(lengths);
+	for(index = 0; index < count; ++ index){
+		if(strings[index].length > 0){
+			if((! async_data_read_receive(&callid, &length))
+				|| (length != strings[index].length)){
+				return EINVAL;
+			}
+			ERROR_PROPAGATE(async_data_read_finalize(callid, strings[index].value, strings[index].length));
+		}
+	}
+	return EOK;
+}
+
+int measured_strings_return(int phone, measured_string_ref * strings, char ** data, size_t count){
+	ERROR_DECLARE;
+
+	size_t * lengths;
+	size_t index;
+	char * next;
+
+	if((phone <= 0) || (! strings) || (! data) || (count <= 0)){
+		return EINVAL;
+	}
+	lengths = (size_t *) malloc(sizeof(size_t) * (count + 1));
+	if(! lengths){
+		return ENOMEM;
+	}
+	if(ERROR_OCCURRED(async_data_read_start(phone, lengths, sizeof(size_t) * (count + 1)))){
+		free(lengths);
+		return ERROR_CODE;
+	}
+	*data = malloc(lengths[count]);
+	if(!(*data)){
+		return ENOMEM;
+	}
+	*strings = (measured_string_ref) malloc(sizeof(measured_string_t) * count);
+	if(!(*strings)){
+		free(lengths);
+		free(*data);
+		return ENOMEM;
+	}
+	next = * data;
+	for(index = 0; index < count; ++ index){
+		(*strings)[index].length = lengths[index];
+		if(lengths[index] > 0){
+			ERROR_PROPAGATE(async_data_read_start(phone, next, lengths[index]));
+			(*strings)[index].value = next;
+			next += lengths[index];
+			*next = '\0';
+			++ next;
+		}else{
+			(*strings)[index].value = NULL;
+		}
+	}
+	free(lengths);
+	return EOK;
+}
+
+int measured_strings_send(int phone, const measured_string_ref strings, size_t count){
+	ERROR_DECLARE;
+
+	size_t * lengths;
+	size_t index;
+
+	if((phone <= 0) || (! strings) || (count <= 0)){
+		return EINVAL;
+	}
+	lengths = prepare_lengths(strings, count);
+	if(! lengths){
+		return ENOMEM;
+	}
+	if(ERROR_OCCURRED(async_data_write_start(phone, lengths, sizeof(size_t) * (count + 1)))){
+		free(lengths);
+		return ERROR_CODE;
+	}
+	free(lengths);
+	for(index = 0; index < count; ++ index){
+		if(strings[index].length > 0){
+			ERROR_PROPAGATE(async_data_write_start(phone, strings[index].value, strings[index].length));
+		}
+	}
+	return EOK;
+}
+
+/** @}
+ */
+
Index: uspace/lib/socket/generic/icmp_api.c
===================================================================
--- uspace/lib/socket/generic/icmp_api.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/generic/icmp_api.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,69 @@
+/*
+ * 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 icmp
+ *  @{
+ */
+
+/** @file
+ *  ICMP application interface implementation.
+ *  @see icmp_api.h
+ */
+
+#include <async.h>
+
+#include <ipc/ipc.h>
+#include <ipc/services.h>
+
+#include <sys/types.h>
+
+#include <net_modules.h>
+#include <icmp_api.h>
+#include <inet.h>
+#include <ip_codes.h>
+#include <socket_codes.h>
+#include <icmp_messages.h>
+
+int icmp_echo_msg(int icmp_phone, size_t size, mseconds_t timeout, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, const struct sockaddr * addr, socklen_t addrlen){
+	aid_t message_id;
+	ipcarg_t result;
+
+	if(addrlen <= 0){
+		return EINVAL;
+	}
+	message_id = async_send_5(icmp_phone, NET_ICMP_ECHO, size, timeout, ttl, tos, (ipcarg_t) dont_fragment, NULL);
+	// send the address
+	async_data_write_start(icmp_phone, addr, (size_t) addrlen);
+	// timeout version may cause inconsistency - there is also an inner timer
+	// return async_wait_timeout(message_id, &result, timeout);
+	async_wait_for(message_id, &result);
+	return (int) result;
+}
+
+/** @}
+ */
Index: uspace/lib/socket/generic/icmp_common.c
===================================================================
--- uspace/lib/socket/generic/icmp_common.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/generic/icmp_common.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,56 @@
+/*
+ * 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 icmp
+ *  @{
+ */
+
+/** @file
+ *  ICMP common interface implementation.
+ *  @see icmp_common.h
+ */
+
+#include <async.h>
+#include <ipc/services.h>
+
+#include <net_modules.h>
+#include <icmp_common.h>
+#include <icmp_messages.h>
+
+int icmp_connect_module(services_t service, suseconds_t timeout){
+	int phone;
+
+	phone = connect_to_service_timeout(SERVICE_ICMP, timeout);
+	if(phone >= 0){
+		async_req_0_0(phone, NET_ICMP_INIT);
+	}
+	return phone;
+}
+
+/** @}
+ */
Index: uspace/lib/socket/generic/inet.c
===================================================================
--- uspace/lib/socket/generic/inet.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/generic/inet.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,156 @@
+/*
+ * 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
+ *  Internet protocol address conversion functions implementation.
+ */
+
+#include <errno.h>
+#include <mem.h>
+#include <stdio.h>
+#include <str.h>
+
+#include <in.h>
+#include <in6.h>
+#include <inet.h>
+#include <socket_codes.h>
+
+int inet_ntop(uint16_t family, const uint8_t * data, char * address, size_t length){
+	if((! data) || (! address)){
+		return EINVAL;
+	}
+
+	switch(family){
+		case AF_INET:
+			// check the output buffer size
+			if(length < INET_ADDRSTRLEN){
+				return ENOMEM;
+			}
+			// fill the buffer with the IPv4 address
+			snprintf(address, length, "%hhu.%hhu.%hhu.%hhu", data[0], data[1], data[2], data[3]);
+			return EOK;
+		case AF_INET6:
+			// check the output buffer size
+			if(length < INET6_ADDRSTRLEN){
+				return ENOMEM;
+			}
+			// fill the buffer with the IPv6 address
+			snprintf(address, length, "%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15]);
+			return EOK;
+		default:
+			return ENOTSUP;
+	}
+}
+
+int inet_pton(uint16_t family, const char * address, uint8_t * data){
+	/** The base number of the values.
+	 */
+	int base;
+	/** The number of bytes per a section.
+	 */
+	size_t bytes;
+	/** The number of bytes of the address data.
+	 */
+	int count;
+
+	const char * next;
+	char * last;
+	int index;
+	size_t shift;
+	unsigned long value;
+
+	if(! data){
+		return EINVAL;
+	}
+
+	// set the processing parameters
+	switch(family){
+		case AF_INET:
+			count = 4;
+			base = 10;
+			bytes = 1;
+			break;
+		case AF_INET6:
+			count = 16;
+			base = 16;
+			bytes = 4;
+			break;
+		default:
+			return ENOTSUP;
+	}
+
+	// erase if no address
+	if(! address){
+		bzero(data, count);
+		return ENOENT;
+	}
+
+	// process the string from the beginning
+	next = address;
+	index = 0;
+	do{
+		// if the actual character is set
+		if(next && (*next)){
+
+			// if not on the first character
+			if(index){
+				// move to the next character
+				++ next;
+			}
+
+			// parse the actual integral value
+			value = strtoul(next, &last, base);
+			// remember the last problematic character
+			// should be either '.' or ':' but is ignored to be more generic
+			next = last;
+
+			// fill the address data byte by byte
+			shift = bytes - 1;
+			do{
+				// like little endian
+				data[index + shift] = value;
+				value >>= 8;
+			}while(shift --);
+
+			index += bytes;
+		}else{
+			// erase the rest of the address
+			bzero(data + index, count - index);
+			return EOK;
+		}
+	}while(index < count);
+
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/socket/generic/net_modules.c
===================================================================
--- uspace/lib/socket/generic/net_modules.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/generic/net_modules.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,228 @@
+/*
+ * 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
+ *  Generic module functions implementation.
+ */
+
+#include <async.h>
+#include <malloc.h>
+
+#include <ipc/ipc.h>
+#include <ipc/services.h>
+
+#include <sys/time.h>
+
+#include <net_err.h>
+#include <net_modules.h>
+
+/** The time between connect requests in microseconds.
+ */
+#define MODULE_WAIT_TIME	(10 * 1000)
+
+void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count){
+	// choose the most efficient answer function
+	if(answer || (! answer_count)){
+		switch(answer_count){
+			case 0:
+				ipc_answer_0(callid, (ipcarg_t) result);
+				break;
+			case 1:
+				ipc_answer_1(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer));
+				break;
+			case 2:
+				ipc_answer_2(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer));
+				break;
+			case 3:
+				ipc_answer_3(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer));
+				break;
+			case 4:
+				ipc_answer_4(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer));
+				break;
+			case 5:
+			default:
+				ipc_answer_5(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer), IPC_GET_ARG5(*answer));
+				break;
+		}
+	}
+}
+
+/** Create bidirectional connection with the needed module service and registers the message receiver.
+ *
+ * @param[in] need            The needed module service.
+ * @param[in] arg1            The first parameter.
+ * @param[in] arg2            The second parameter.
+ * @param[in] arg3            The third parameter.
+ * @param[in] client_receiver The message receiver.
+ *
+ * @return The phone of the needed service.
+ * @return Other error codes as defined for the ipc_connect_to_me() function.
+ *
+ */
+int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3,
+    async_client_conn_t client_receiver)
+{
+	return bind_service_timeout(need, arg1, arg2, arg3, client_receiver, 0);
+}
+
+/** Create bidirectional connection with the needed module service and registers the message receiver.
+ *
+ * @param[in] need            The needed module service.
+ * @param[in] arg1            The first parameter.
+ * @param[in] arg2            The second parameter.
+ * @param[in] arg3            The third parameter.
+ * @param[in] client_receiver The message receiver.
+ * @param[in] timeout         The connection timeout in microseconds.
+ *                            No timeout if set to zero (0).
+ *
+ * @return The phone of the needed service.
+ * @return ETIMEOUT if the connection timeouted.
+ * @return Other error codes as defined for the ipc_connect_to_me() function.
+ *
+ */
+int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2,
+    ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout)
+{
+	ERROR_DECLARE;
+	
+	/* Connect to the needed service */
+	int phone = connect_to_service_timeout(need, timeout);
+	if (phone >= 0) {
+		/* Request the bidirectional connection */
+		ipcarg_t phonehash;
+		if (ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3,
+		    &phonehash))) {
+			ipc_hangup(phone);
+			return ERROR_CODE;
+		}
+		async_new_connection(phonehash, 0, NULL, client_receiver);
+	}
+	
+	return phone;
+}
+
+int connect_to_service(services_t need){
+	return connect_to_service_timeout(need, 0);
+}
+
+int connect_to_service_timeout(services_t need, suseconds_t timeout){
+	int phone;
+
+	// if no timeout is set
+	if (timeout <= 0){
+		return async_connect_me_to_blocking(PHONE_NS, need, 0, 0);
+	}
+
+	while(true){
+		phone = async_connect_me_to(PHONE_NS, need, 0, 0);
+		if((phone >= 0) || (phone != ENOENT)){
+			return phone;
+		}
+
+		// end if no time is left
+		if(timeout <= 0){
+			return ETIMEOUT;
+		}
+
+		// wait the minimum of the module wait time and the timeout
+		usleep((timeout <= MODULE_WAIT_TIME) ? timeout : MODULE_WAIT_TIME);
+		timeout -= MODULE_WAIT_TIME;
+	}
+}
+
+int data_receive(void ** data, size_t * length){
+	ERROR_DECLARE;
+
+	ipc_callid_t callid;
+
+	if(!(data && length)){
+		return EBADMEM;
+	}
+
+	// fetch the request
+	if(! async_data_write_receive(&callid, length)){
+		return EINVAL;
+	}
+
+	// allocate the buffer
+	*data = malloc(*length);
+	if(!(*data)){
+		return ENOMEM;
+	}
+
+	// fetch the data
+	if(ERROR_OCCURRED(async_data_write_finalize(callid, * data, * length))){
+		free(data);
+		return ERROR_CODE;
+	}
+	return EOK;
+}
+
+int data_reply(void * data, size_t data_length){
+	size_t length;
+	ipc_callid_t callid;
+
+	// fetch the request
+	if(! async_data_read_receive(&callid, &length)){
+		return EINVAL;
+	}
+
+	// check the requested data size
+	if(length < data_length){
+		async_data_read_finalize(callid, data, length);
+		return EOVERFLOW;
+	}
+
+	// send the data
+	return async_data_read_finalize(callid, data, data_length);
+}
+
+void refresh_answer(ipc_call_t * answer, int * answer_count){
+
+	if(answer_count){
+		*answer_count = 0;
+	}
+
+	if(answer){
+		IPC_SET_RETVAL(*answer, 0);
+		// just to be precize
+		IPC_SET_METHOD(*answer, 0);
+		IPC_SET_ARG1(*answer, 0);
+		IPC_SET_ARG2(*answer, 0);
+		IPC_SET_ARG3(*answer, 0);
+		IPC_SET_ARG4(*answer, 0);
+		IPC_SET_ARG5(*answer, 0);
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/socket/generic/socket_client.c
===================================================================
--- uspace/lib/socket/generic/socket_client.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/generic/socket_client.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,882 @@
+/*
+ * 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 application program interface (API) implementation.
+ *  @see socket.h for more information.
+ *  This is a part of the network application library.
+ */
+
+#include <assert.h>
+#include <async.h>
+#include <fibril_synch.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#include <ipc/services.h>
+
+#include <net_err.h>
+#include <net_modules.h>
+#include <in.h>
+#include <socket.h>
+#include <socket_errno.h>
+#include <adt/dynamic_fifo.h>
+#include <adt/int_map.h>
+#include <socket_messages.h>
+
+/** Initial received packet queue size.
+ */
+#define SOCKET_INITIAL_RECEIVED_SIZE	4
+
+/** Maximum received packet queue size.
+ */
+#define SOCKET_MAX_RECEIVED_SIZE		0
+
+/** Initial waiting sockets queue size.
+ */
+#define SOCKET_INITIAL_ACCEPTED_SIZE	1
+
+/** Maximum waiting sockets queue size.
+ */
+#define SOCKET_MAX_ACCEPTED_SIZE		0
+
+/** Default timeout for connections in microseconds.
+ */
+#define SOCKET_CONNECT_TIMEOUT	(1 * 1000 * 1000)
+
+/** Maximum number of random attempts to find a new socket identifier before switching to the sequence.
+ */
+#define SOCKET_ID_TRIES					100
+
+/** Type definition of the socket specific data.
+ *  @see socket
+ */
+typedef struct socket	socket_t;
+
+/** Type definition of the socket specific data pointer.
+ *  @see socket
+ */
+typedef socket_t *	socket_ref;
+
+/** Socket specific data.
+ *  Each socket lock locks only its structure part and any number of them may be locked simultaneously.
+ */
+struct socket{
+	/** Socket identifier.
+	 */
+	int socket_id;
+	/** Parent module phone.
+	 */
+	int phone;
+	/** Parent module service.
+	 */
+	services_t service;
+	/** Underlying protocol header size.
+	 *  Sending and receiving optimalization.
+	 */
+	size_t header_size;
+	/** Packet data fragment size.
+	 *  Sending optimalization.
+	 */
+	size_t data_fragment_size;
+	/** Sending safety lock.
+	 *  Locks the header_size and data_fragment_size attributes.
+	 */
+	fibril_rwlock_t sending_lock;
+	/** Received packets queue.
+	 */
+	dyn_fifo_t received;
+	/** Received packets safety lock.
+	 *  Used for receiving and receive notifications.
+	 *  Locks the received attribute.
+	 */
+	fibril_mutex_t receive_lock;
+	/** Received packets signaling.
+	 *  Signaled upon receive notification.
+	 */
+	fibril_condvar_t receive_signal;
+	/** Waiting sockets queue.
+	 */
+	dyn_fifo_t accepted;
+	/** Waiting sockets safety lock.
+	 *  Used for accepting and accept notifications.
+	 *  Locks the accepted attribute.
+	 */
+	fibril_mutex_t accept_lock;
+	/** Waiting sockets signaling.
+	 *  Signaled upon accept notification.
+	 */
+	fibril_condvar_t accept_signal;
+	/** The number of blocked functions called.
+	 *  Used while waiting for the received packets or accepted sockets.
+	 */
+	int blocked;
+};
+
+/** Sockets map.
+ *  Maps socket identifiers to the socket specific data.
+ *  @see int_map.h
+ */
+INT_MAP_DECLARE(sockets, socket_t);
+
+/** Socket client library global data.
+ */
+static struct socket_client_globals {
+	/** TCP module phone.
+	 */
+	int tcp_phone;
+	/** UDP module phone.
+	 */
+	int udp_phone;
+//	/** The last socket identifier.
+//	 */
+//	int last_id;
+	/** Active sockets.
+	 */
+	sockets_ref sockets;
+	/** Safety lock.
+	 *  Write lock is used only for adding or removing sockets.
+	 *  When locked for writing, no other socket locks need to be locked.
+	 *  When locked for reading, any other socket locks may be locked.
+	 *  No socket lock may be locked if this lock is unlocked.
+	 */
+	fibril_rwlock_t lock;
+} socket_globals = {
+	.tcp_phone = -1,
+	.udp_phone = -1,
+//	.last_id = 0,
+	.sockets = NULL,
+	.lock = {
+		.readers = 0,
+		.writers = 0,
+		.waiters = {
+			.prev = &socket_globals.lock.waiters,
+			.next = &socket_globals.lock.waiters
+		}
+	}
+};
+
+INT_MAP_IMPLEMENT(sockets, socket_t);
+
+/** Returns the active sockets.
+ *  @returns The active sockets.
+ */
+static sockets_ref socket_get_sockets(void){
+	if(! socket_globals.sockets){
+		socket_globals.sockets = (sockets_ref) malloc(sizeof(sockets_t));
+		if(! socket_globals.sockets){
+			return NULL;
+		}
+		if(sockets_initialize(socket_globals.sockets) != EOK){
+			free(socket_globals.sockets);
+			socket_globals.sockets = NULL;
+		}
+		srand(task_get_id());
+	}
+	return socket_globals.sockets;
+}
+
+/** Default thread for new connections.
+ *  @param[in] iid The initial message identifier.
+ *  @param[in] icall The initial message call structure.
+ */
+static void socket_connection(ipc_callid_t iid, ipc_call_t * icall){
+	ERROR_DECLARE;
+
+	ipc_callid_t callid;
+	ipc_call_t call;
+	socket_ref socket;
+
+	while(true){
+
+		callid = async_get_call(&call);
+		switch(IPC_GET_METHOD(call)){
+			case NET_SOCKET_RECEIVED:
+			case NET_SOCKET_ACCEPTED:
+			case NET_SOCKET_DATA_FRAGMENT_SIZE:
+				fibril_rwlock_read_lock(&socket_globals.lock);
+				// find the socket
+				socket = sockets_find(socket_get_sockets(), SOCKET_GET_SOCKET_ID(call));
+				if(! socket){
+					ERROR_CODE = ENOTSOCK;
+				}else{
+					switch(IPC_GET_METHOD(call)){
+						case NET_SOCKET_RECEIVED:
+							fibril_mutex_lock(&socket->receive_lock);
+							// push the number of received packet fragments
+							if(! ERROR_OCCURRED(dyn_fifo_push(&socket->received, SOCKET_GET_DATA_FRAGMENTS(call), SOCKET_MAX_RECEIVED_SIZE))){
+								// signal the received packet
+								fibril_condvar_signal(&socket->receive_signal);
+							}
+							fibril_mutex_unlock(&socket->receive_lock);
+							break;
+						case NET_SOCKET_ACCEPTED:
+							// push the new socket identifier
+							fibril_mutex_lock(&socket->accept_lock);
+							if(! ERROR_OCCURRED(dyn_fifo_push(&socket->accepted, 1, SOCKET_MAX_ACCEPTED_SIZE))){
+								// signal the accepted socket
+								fibril_condvar_signal(&socket->accept_signal);
+							}
+							fibril_mutex_unlock(&socket->accept_lock);
+							break;
+						default:
+							ERROR_CODE = ENOTSUP;
+					}
+					if((SOCKET_GET_DATA_FRAGMENT_SIZE(call) > 0)
+						&& (SOCKET_GET_DATA_FRAGMENT_SIZE(call) != socket->data_fragment_size)){
+						fibril_rwlock_write_lock(&socket->sending_lock);
+						// set the data fragment size
+						socket->data_fragment_size = SOCKET_GET_DATA_FRAGMENT_SIZE(call);
+						fibril_rwlock_write_unlock(&socket->sending_lock);
+					}
+				}
+				fibril_rwlock_read_unlock(&socket_globals.lock);
+				break;
+			default:
+				ERROR_CODE = ENOTSUP;
+		}
+		ipc_answer_0(callid, (ipcarg_t) ERROR_CODE);
+	}
+}
+
+/** Returns the TCP module phone.
+ *  Connects to the TCP module if necessary.
+ *  @returns The TCP module phone.
+ *  @returns Other error codes as defined for the bind_service_timeout() function.
+ */
+static int socket_get_tcp_phone(void){
+	if(socket_globals.tcp_phone < 0){
+		socket_globals.tcp_phone = bind_service_timeout(SERVICE_TCP, 0, 0, SERVICE_TCP, socket_connection, SOCKET_CONNECT_TIMEOUT);
+	}
+	return socket_globals.tcp_phone;
+}
+
+/** Returns the UDP module phone.
+ *  Connects to the UDP module if necessary.
+ *  @returns The UDP module phone.
+ *  @returns Other error codes as defined for the bind_service_timeout() function.
+ */
+static int socket_get_udp_phone(void){
+	if(socket_globals.udp_phone < 0){
+		socket_globals.udp_phone = bind_service_timeout(SERVICE_UDP, 0, 0, SERVICE_UDP, socket_connection, SOCKET_CONNECT_TIMEOUT);
+	}
+	return socket_globals.udp_phone;
+}
+
+/** Tries to find a new free socket identifier.
+ *	@returns The new socket identifier.
+ *  @returns ELIMIT if there is no socket identifier available.
+ */
+static int socket_generate_new_id(void){
+	sockets_ref sockets;
+	int socket_id;
+	int count;
+
+	sockets = socket_get_sockets();
+	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(sockets_find(sockets, socket_id));
+//	last_id = socket_id
+	return socket_id;
+}
+
+/** Initializes a new socket specific data.
+ *  @param[in,out] socket The socket to be initialized.
+ *  @param[in] socket_id The new socket identifier.
+ *  @param[in] phone The parent module phone.
+ *  @param[in] service The parent module service.
+ */
+static void socket_initialize(socket_ref socket, int socket_id, int phone, services_t service){
+	socket->socket_id = socket_id;
+	socket->phone = phone;
+	socket->service = service;
+	dyn_fifo_initialize(&socket->received, SOCKET_INITIAL_RECEIVED_SIZE);
+	dyn_fifo_initialize(&socket->accepted, SOCKET_INITIAL_ACCEPTED_SIZE);
+	fibril_mutex_initialize(&socket->receive_lock);
+	fibril_condvar_initialize(&socket->receive_signal);
+	fibril_mutex_initialize(&socket->accept_lock);
+	fibril_condvar_initialize(&socket->accept_signal);
+	fibril_rwlock_initialize(&socket->sending_lock);
+}
+
+int socket(int domain, int type, int protocol){
+	ERROR_DECLARE;
+
+	socket_ref socket;
+	int phone;
+	int socket_id;
+	services_t service;
+	ipcarg_t fragment_size;
+	ipcarg_t header_size;
+
+	// find the appropriate service
+	switch(domain){
+		case PF_INET:
+			switch(type){
+				case SOCK_STREAM:
+					if(! protocol){
+						protocol = IPPROTO_TCP;
+					}
+					switch(protocol){
+						case IPPROTO_TCP:
+							phone = socket_get_tcp_phone();
+							service = SERVICE_TCP;
+							break;
+						default:
+							return EPROTONOSUPPORT;
+					}
+					break;
+				case SOCK_DGRAM:
+					if(! protocol){
+						protocol = IPPROTO_UDP;
+					}
+					switch(protocol){
+						case IPPROTO_UDP:
+							phone = socket_get_udp_phone();
+							service = SERVICE_UDP;
+							break;
+						default:
+							return EPROTONOSUPPORT;
+					}
+					break;
+				case SOCK_RAW:
+				default:
+					return ESOCKTNOSUPPORT;
+			}
+			break;
+		// TODO IPv6
+		default:
+			return EPFNOSUPPORT;
+	}
+	if(phone < 0){
+		return phone;
+	}
+	// create a new socket structure
+	socket = (socket_ref) malloc(sizeof(socket_t));
+	if(! socket){
+		return ENOMEM;
+	}
+	bzero(socket, sizeof(*socket));
+	fibril_rwlock_write_lock(&socket_globals.lock);
+	// request a new socket
+	socket_id = socket_generate_new_id();
+	if(socket_id <= 0){
+		fibril_rwlock_write_unlock(&socket_globals.lock);
+		free(socket);
+		return socket_id;
+	}
+	if(ERROR_OCCURRED((int) async_req_3_3(phone, NET_SOCKET, socket_id, 0, service, NULL, &fragment_size, &header_size))){
+		fibril_rwlock_write_unlock(&socket_globals.lock);
+		free(socket);
+		return ERROR_CODE;
+	}
+	socket->data_fragment_size = (size_t) fragment_size;
+	socket->header_size = (size_t) header_size;
+	// finish the new socket initialization
+	socket_initialize(socket, socket_id, phone, service);
+	// store the new socket
+	ERROR_CODE = sockets_add(socket_get_sockets(), socket_id, socket);
+	fibril_rwlock_write_unlock(&socket_globals.lock);
+	if(ERROR_CODE < 0){
+		dyn_fifo_destroy(&socket->received);
+		dyn_fifo_destroy(&socket->accepted);
+		free(socket);
+		async_msg_3(phone, NET_SOCKET_CLOSE, (ipcarg_t) socket_id, 0, service);
+		return ERROR_CODE;
+	}
+
+	return socket_id;
+}
+
+/** Sends message to the socket parent module with specified data.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[in] message The action message.
+ *  @param[in] arg2 The second message parameter.
+ *  @param[in] data The data to be sent.
+ *  @param[in] datalength The data length.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns EBADMEM if the data parameter is NULL.
+ *  @returns NO_DATA if the datalength parameter is zero (0).
+ *  @returns Other error codes as defined for the spcific message.
+ */
+static int socket_send_data(int socket_id, ipcarg_t message, ipcarg_t arg2, const void * data, size_t datalength){
+	socket_ref socket;
+	aid_t message_id;
+	ipcarg_t result;
+
+	if(! data){
+		return EBADMEM;
+	}
+	if(! datalength){
+		return NO_DATA;
+	}
+
+	fibril_rwlock_read_lock(&socket_globals.lock);
+	// find the socket
+	socket = sockets_find(socket_get_sockets(), socket_id);
+	if(! socket){
+		fibril_rwlock_read_unlock(&socket_globals.lock);
+		return ENOTSOCK;
+	}
+	// request the message
+	message_id = async_send_3(socket->phone, message, (ipcarg_t) socket->socket_id, arg2, socket->service, NULL);
+	// send the address
+	async_data_write_start(socket->phone, data, datalength);
+	fibril_rwlock_read_unlock(&socket_globals.lock);
+	async_wait_for(message_id, &result);
+	return (int) result;
+}
+
+int bind(int socket_id, const struct sockaddr * my_addr, socklen_t addrlen){
+	if(addrlen <= 0){
+		return EINVAL;
+	}
+	// send the address
+	return socket_send_data(socket_id, NET_SOCKET_BIND, 0, my_addr, (size_t) addrlen);
+}
+
+int listen(int socket_id, int backlog){
+	socket_ref socket;
+	int result;
+
+	if(backlog <= 0){
+		return EINVAL;
+	}
+	fibril_rwlock_read_lock(&socket_globals.lock);
+	// find the socket
+	socket = sockets_find(socket_get_sockets(), socket_id);
+	if(! socket){
+		fibril_rwlock_read_unlock(&socket_globals.lock);
+		return ENOTSOCK;
+	}
+	// request listen backlog change
+	result = (int) async_req_3_0(socket->phone, NET_SOCKET_LISTEN, (ipcarg_t) socket->socket_id, (ipcarg_t) backlog, socket->service);
+	fibril_rwlock_read_unlock(&socket_globals.lock);
+	return result;
+}
+
+int accept(int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen){
+	socket_ref socket;
+	socket_ref new_socket;
+	aid_t message_id;
+	ipcarg_t ipc_result;
+	int result;
+	ipc_call_t answer;
+
+	if((! cliaddr) || (! addrlen)){
+		return EBADMEM;
+	}
+
+	fibril_rwlock_write_lock(&socket_globals.lock);
+	// find the socket
+	socket = sockets_find(socket_get_sockets(), socket_id);
+	if(! socket){
+		fibril_rwlock_write_unlock(&socket_globals.lock);
+		return ENOTSOCK;
+	}
+	fibril_mutex_lock(&socket->accept_lock);
+	// wait for an accepted socket
+	++ socket->blocked;
+	while(dyn_fifo_value(&socket->accepted) <= 0){
+		fibril_rwlock_write_unlock(&socket_globals.lock);
+		fibril_condvar_wait(&socket->accept_signal, &socket->accept_lock);
+		// drop the accept lock to avoid deadlock
+		fibril_mutex_unlock(&socket->accept_lock);
+		fibril_rwlock_write_lock(&socket_globals.lock);
+		fibril_mutex_lock(&socket->accept_lock);
+	}
+	-- socket->blocked;
+
+	// create a new scoket
+	new_socket = (socket_ref) malloc(sizeof(socket_t));
+	if(! new_socket){
+		fibril_mutex_unlock(&socket->accept_lock);
+		fibril_rwlock_write_unlock(&socket_globals.lock);
+		return ENOMEM;
+	}
+	bzero(new_socket, sizeof(*new_socket));
+	socket_id = socket_generate_new_id();
+	if(socket_id <= 0){
+		fibril_mutex_unlock(&socket->accept_lock);
+		fibril_rwlock_write_unlock(&socket_globals.lock);
+		free(new_socket);
+		return socket_id;
+	}
+	socket_initialize(new_socket, socket_id, socket->phone, socket->service);
+	result = sockets_add(socket_get_sockets(), new_socket->socket_id, new_socket);
+	if(result < 0){
+		fibril_mutex_unlock(&socket->accept_lock);
+		fibril_rwlock_write_unlock(&socket_globals.lock);
+		free(new_socket);
+		return result;
+	}
+
+	// request accept
+	message_id = async_send_5(socket->phone, NET_SOCKET_ACCEPT, (ipcarg_t) socket->socket_id, 0, socket->service, 0, new_socket->socket_id, &answer);
+	// read address
+	ipc_data_read_start(socket->phone, cliaddr, * addrlen);
+	fibril_rwlock_write_unlock(&socket_globals.lock);
+	async_wait_for(message_id, &ipc_result);
+	result = (int) ipc_result;
+	if(result > 0){
+		if(result != socket_id){
+			result = EINVAL;
+		}
+		// dequeue the accepted socket if successful
+		dyn_fifo_pop(&socket->accepted);
+		// set address length
+		*addrlen = SOCKET_GET_ADDRESS_LENGTH(answer);
+		new_socket->data_fragment_size = SOCKET_GET_DATA_FRAGMENT_SIZE(answer);
+	}else if(result == ENOTSOCK){
+		// empty the queue if no accepted sockets
+		while(dyn_fifo_pop(&socket->accepted) > 0);
+	}
+	fibril_mutex_unlock(&socket->accept_lock);
+	return result;
+}
+
+int connect(int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen){
+	if(! serv_addr){
+		return EDESTADDRREQ;
+	}
+	if(! addrlen){
+		return EDESTADDRREQ;
+	}
+	// send the address
+	return socket_send_data(socket_id, NET_SOCKET_CONNECT, 0, serv_addr, addrlen);
+}
+
+/** Clears and destroys the socket.
+ *  @param[in] socket The socket to be destroyed.
+ */
+static void socket_destroy(socket_ref socket){
+	int accepted_id;
+
+	// destroy all accepted sockets
+	while((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0){
+		socket_destroy(sockets_find(socket_get_sockets(), accepted_id));
+	}
+	dyn_fifo_destroy(&socket->received);
+	dyn_fifo_destroy(&socket->accepted);
+	sockets_exclude(socket_get_sockets(), socket->socket_id);
+}
+
+int closesocket(int socket_id){
+	ERROR_DECLARE;
+
+	socket_ref socket;
+
+	fibril_rwlock_write_lock(&socket_globals.lock);
+	socket = sockets_find(socket_get_sockets(), socket_id);
+	if(! socket){
+		fibril_rwlock_write_unlock(&socket_globals.lock);
+		return ENOTSOCK;
+	}
+	if(socket->blocked){
+		fibril_rwlock_write_unlock(&socket_globals.lock);
+		return EINPROGRESS;
+	}
+	// request close
+	ERROR_PROPAGATE((int) async_req_3_0(socket->phone, NET_SOCKET_CLOSE, (ipcarg_t) socket->socket_id, 0, socket->service));
+	// free the socket structure
+	socket_destroy(socket);
+	fibril_rwlock_write_unlock(&socket_globals.lock);
+	return EOK;
+}
+
+/** Sends data via the socket to the remote address.
+ *  Binds the socket to a free port if not already connected/bound.
+ *  @param[in] message The action message.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[in] data The data to be sent.
+ *  @param[in] datalength The data length.
+ *  @param[in] flags Various send flags.
+ *  @param[in] toaddr The destination address. May be NULL for connected sockets.
+ *  @param[in] addrlen The address length. Used only if toaddr is not NULL.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns EBADMEM if the data or toaddr parameter is NULL.
+ *  @returns NO_DATA if the datalength or the addrlen parameter is zero (0).
+ *  @returns Other error codes as defined for the NET_SOCKET_SENDTO message.
+ */
+static int sendto_core(ipcarg_t message, int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen){
+	socket_ref socket;
+	aid_t message_id;
+	ipcarg_t result;
+	size_t fragments;
+	ipc_call_t answer;
+
+	if(! data){
+		return EBADMEM;
+	}
+	if(! datalength){
+		return NO_DATA;
+	}
+	fibril_rwlock_read_lock(&socket_globals.lock);
+	// find socket
+	socket = sockets_find(socket_get_sockets(), socket_id);
+	if(! socket){
+		fibril_rwlock_read_unlock(&socket_globals.lock);
+		return ENOTSOCK;
+	}
+	fibril_rwlock_read_lock(&socket->sending_lock);
+	// compute data fragment count
+	if(socket->data_fragment_size > 0){
+		fragments = (datalength + socket->header_size) / socket->data_fragment_size;
+		if((datalength + socket->header_size) % socket->data_fragment_size) ++ fragments;
+	}else{
+		fragments = 1;
+	}
+	// request send
+	message_id = async_send_5(socket->phone, message, (ipcarg_t) socket->socket_id, (fragments == 1 ? datalength : socket->data_fragment_size), socket->service, (ipcarg_t) flags, fragments, &answer);
+	// send the address if given
+	if((! toaddr) || (async_data_write_start(socket->phone, toaddr, addrlen) == EOK)){
+		if(fragments == 1){
+			// send all if only one fragment
+			async_data_write_start(socket->phone, data, datalength);
+		}else{
+			// send the first fragment
+			async_data_write_start(socket->phone, data, socket->data_fragment_size - socket->header_size);
+			data = ((const uint8_t *) data) + socket->data_fragment_size - socket->header_size;
+			// send the middle fragments
+			while((-- fragments) > 1){
+				async_data_write_start(socket->phone, data, socket->data_fragment_size);
+				data = ((const uint8_t *) data) + socket->data_fragment_size;
+			}
+			// send the last fragment
+			async_data_write_start(socket->phone, data, (datalength + socket->header_size) % socket->data_fragment_size);
+		}
+	}
+	async_wait_for(message_id, &result);
+	if((SOCKET_GET_DATA_FRAGMENT_SIZE(answer) > 0)
+		&& (SOCKET_GET_DATA_FRAGMENT_SIZE(answer) != socket->data_fragment_size)){
+		// set the data fragment size
+		socket->data_fragment_size = SOCKET_GET_DATA_FRAGMENT_SIZE(answer);
+	}
+	fibril_rwlock_read_unlock(&socket->sending_lock);
+	fibril_rwlock_read_unlock(&socket_globals.lock);
+	return (int) result;
+}
+
+int send(int socket_id, void * data, size_t datalength, int flags){
+	// without the address
+	return sendto_core(NET_SOCKET_SEND, socket_id, data, datalength, flags, NULL, 0);
+}
+
+int sendto(int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen){
+	if(! toaddr){
+		return EDESTADDRREQ;
+	}
+	if(! addrlen){
+		return EDESTADDRREQ;
+	}
+	// with the address
+	return sendto_core(NET_SOCKET_SENDTO, socket_id, data, datalength, flags, toaddr, addrlen);
+}
+
+/** Receives data via the socket.
+ *  @param[in] message The action message.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[out] data The data buffer to be filled.
+ *  @param[in] datalength The data length.
+ *  @param[in] flags Various receive flags.
+ *  @param[out] fromaddr The source address. May be NULL for connected sockets.
+ *  @param[in,out] addrlen The address length. The maximum address length is read. The actual address length is set. Used only if fromaddr is not NULL.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns EBADMEM if the data parameter is NULL.
+ *  @returns NO_DATA if the datalength or addrlen parameter is zero (0).
+ *  @returns Other error codes as defined for the spcific message.
+ */
+static int recvfrom_core(ipcarg_t message, int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen){
+	socket_ref socket;
+	aid_t message_id;
+	ipcarg_t ipc_result;
+	int result;
+	size_t fragments;
+	size_t * lengths;
+	size_t index;
+	ipc_call_t answer;
+
+	if(! data){
+		return EBADMEM;
+	}
+	if(! datalength){
+		return NO_DATA;
+	}
+	if(fromaddr && (! addrlen)){
+		return EINVAL;
+	}
+	fibril_rwlock_read_lock(&socket_globals.lock);
+	// find the socket
+	socket = sockets_find(socket_get_sockets(), socket_id);
+	if(! socket){
+		fibril_rwlock_read_unlock(&socket_globals.lock);
+		return ENOTSOCK;
+	}
+	fibril_mutex_lock(&socket->receive_lock);
+	// wait for a received packet
+	++ socket->blocked;
+	while((result = dyn_fifo_value(&socket->received)) <= 0){
+		fibril_rwlock_read_unlock(&socket_globals.lock);
+		fibril_condvar_wait(&socket->receive_signal, &socket->receive_lock);
+		// drop the receive lock to avoid deadlock
+		fibril_mutex_unlock(&socket->receive_lock);
+		fibril_rwlock_read_lock(&socket_globals.lock);
+		fibril_mutex_lock(&socket->receive_lock);
+	}
+	-- socket->blocked;
+	fragments = (size_t) result;
+	// prepare lengths if more fragments
+	if(fragments > 1){
+		lengths = (size_t *) malloc(sizeof(size_t) * fragments + sizeof(size_t));
+		if(! lengths){
+			fibril_mutex_unlock(&socket->receive_lock);
+			fibril_rwlock_read_unlock(&socket_globals.lock);
+			return ENOMEM;
+		}
+		// request packet data
+		message_id = async_send_4(socket->phone, message, (ipcarg_t) socket->socket_id, 0, socket->service, (ipcarg_t) flags, &answer);
+		// read the address if desired
+		if((! fromaddr) || (async_data_read_start(socket->phone, fromaddr, * addrlen) == EOK)){
+		// read the fragment lengths
+			if(async_data_read_start(socket->phone, lengths, sizeof(int) * (fragments + 1)) == EOK){
+				if(lengths[fragments] <= datalength){
+					// read all fragments if long enough
+					for(index = 0; index < fragments; ++ index){
+						async_data_read_start(socket->phone, data, lengths[index]);
+						data = ((uint8_t *) data) + lengths[index];
+					}
+				}
+			}
+		}
+		free(lengths);
+	}else{
+		// request packet data
+		message_id = async_send_4(socket->phone, message, (ipcarg_t) socket->socket_id, 0, socket->service, (ipcarg_t) flags, &answer);
+		// read the address if desired
+		if((! fromaddr) || (async_data_read_start(socket->phone, fromaddr, * addrlen) == EOK)){
+			// read all if only one fragment
+			async_data_read_start(socket->phone, data, datalength);
+		}
+	}
+	async_wait_for(message_id, &ipc_result);
+	result = (int) ipc_result;
+	// if successful
+	if(result == EOK){
+		// dequeue the received packet
+		dyn_fifo_pop(&socket->received);
+		// return read data length
+		result = SOCKET_GET_READ_DATA_LENGTH(answer);
+		// set address length
+		if(fromaddr && addrlen){
+			*addrlen = SOCKET_GET_ADDRESS_LENGTH(answer);
+		}
+	}
+	fibril_mutex_unlock(&socket->receive_lock);
+	fibril_rwlock_read_unlock(&socket_globals.lock);
+	return result;
+}
+
+int recv(int socket_id, void * data, size_t datalength, int flags){
+	// without the address
+	return recvfrom_core(NET_SOCKET_RECV, socket_id, data, datalength, flags, NULL, NULL);
+}
+
+int recvfrom(int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen){
+	if(! fromaddr){
+		return EBADMEM;
+	}
+	if(! addrlen){
+		return NO_DATA;
+	}
+	// with the address
+	return recvfrom_core(NET_SOCKET_RECVFROM, socket_id, data, datalength, flags, fromaddr, addrlen);
+}
+
+int getsockopt(int socket_id, int level, int optname, void * value, size_t * optlen){
+	socket_ref socket;
+	aid_t message_id;
+	ipcarg_t result;
+
+	if(!(value && optlen)){
+		return EBADMEM;
+	}
+	if(!(*optlen)){
+		return NO_DATA;
+	}
+	fibril_rwlock_read_lock(&socket_globals.lock);
+	// find the socket
+	socket = sockets_find(socket_get_sockets(), socket_id);
+	if(! socket){
+		fibril_rwlock_read_unlock(&socket_globals.lock);
+		return ENOTSOCK;
+	}
+	// request option value
+	message_id = async_send_3(socket->phone, NET_SOCKET_GETSOCKOPT, (ipcarg_t) socket->socket_id, (ipcarg_t) optname, socket->service, NULL);
+	// read the length
+	if(async_data_read_start(socket->phone, optlen, sizeof(*optlen)) == EOK){
+		// read the value
+		async_data_read_start(socket->phone, value, * optlen);
+	}
+	fibril_rwlock_read_unlock(&socket_globals.lock);
+	async_wait_for(message_id, &result);
+	return (int) result;
+}
+
+int setsockopt(int socket_id, int level, int optname, const void * value, size_t optlen){
+	// send the value
+	return socket_send_data(socket_id, NET_SOCKET_SETSOCKOPT, (ipcarg_t) optname, value, optlen);
+
+}
+
+/** @}
+ */
Index: uspace/lib/socket/generic/socket_core.c
===================================================================
--- uspace/lib/socket/generic/socket_core.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/generic/socket_core.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,476 @@
+/*
+ * 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 <limits.h>
+#include <stdlib.h>
+
+#include <net_err.h>
+#include <in.h>
+#include <inet.h>
+#include <socket_codes.h>
+#include <socket_errno.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/generic/socket_parse.c
===================================================================
--- uspace/lib/socket/generic/socket_parse.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/generic/socket_parse.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,122 @@
+/*
+ * 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
+ * Command-line argument parsing functions related to networking.
+ */
+
+#include <socket_parse.h>
+#include <arg_parse.h>
+#include <errno.h>
+#include <str.h>
+#include <socket.h>
+
+/** Translate the character string to the address family number.
+ *
+ * @param[in]  name The address family name.
+ * @param[out] af   The corresponding address family number
+ *                  or EAFNOSUPPORTED.
+ *
+ * @return EOK on success.
+ * @return ENOTSUP on unsupported address family.
+ *
+ */
+int socket_parse_address_family(const char *name, int *af)
+{
+	if (str_lcmp(name, "AF_INET", 7) == 0) {
+		*af = AF_INET;
+		return EOK;
+	}
+	
+	if (str_lcmp(name, "AF_INET6", 8) == 0) {
+		*af = AF_INET6;
+		return EOK;
+	}
+	
+	*af = EAFNOSUPPORT;
+	return ENOTSUP;
+}
+
+/** Translate the character string to the protocol family number.
+ *
+ * @param[in]  name The protocol family name.
+ * @param[out] pf   The corresponding protocol family number
+ *                  or EPFNOSUPPORTED.
+ *
+ * @return EOK on success.
+ * @return ENOTSUP on unsupported protocol family.
+ *
+ */
+int socket_parse_protocol_family(const char *name, int *pf)
+{
+	if (str_lcmp(name, "PF_INET", 7) == 0) {
+		*pf = PF_INET;
+		return EOK;
+	}
+	
+	if (str_lcmp(name, "PF_INET6", 8) == 0) {
+		*pf = PF_INET6;
+		return EOK;
+	}
+	
+	*pf = EPFNOSUPPORT;
+	return ENOTSUP;
+}
+
+/** Translate the character string to the socket type number.
+ *
+ * @param[in]  name  The socket type name.
+ * @param[out] sockt The corresponding socket type number
+ *                   or ESOCKTNOSUPPORT.
+ *
+ * @return EOK on success.
+ * @return ENOTSUP on unsupported socket type.
+ *
+ */
+int socket_parse_socket_type(const char *name, int *sockt)
+{
+	if (str_lcmp(name, "SOCK_DGRAM", 11) == 0) {
+		*sockt = SOCK_DGRAM;
+		return EOK;
+	}
+	
+	if (str_lcmp(name, "SOCK_STREAM", 12) == 0) {
+		*sockt = SOCK_STREAM;
+		return EOK;
+	}
+	
+	*sockt = ESOCKTNOSUPPORT;
+	return ENOTSUP;
+}
+
+/** @}
+ */
Index: uspace/lib/socket/include/adt/char_map.h
===================================================================
--- uspace/lib/socket/include/adt/char_map.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/adt/char_map.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,142 @@
+/*
+ * 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
+ *  Character string to integer map.
+ */
+
+#ifndef __CHAR_MAP_H__
+#define __CHAR_MAP_H__
+
+/** Invalid assigned value used also if an&nbsp;entry does not exist.
+ */
+#define CHAR_MAP_NULL	(-1)
+
+/** Type definition of the character string to integer map.
+ *  @see char_map
+ */
+typedef struct char_map	char_map_t;
+
+/** Type definition of the character string to integer map pointer.
+ *  @see char_map
+ */
+typedef char_map_t *	char_map_ref;
+
+/** Character string to integer map item.
+ *  This structure recursivelly contains itself as a&nbsp;character by character tree.
+ *  The actually mapped character string consists o fall the parent characters and the actual one.
+ */
+struct	char_map{
+	/** Actually mapped character.
+	 */
+	char c;
+	/** Stored integral value.
+	 */
+	int value;
+	/** Next character array size.
+	 */
+	int size;
+	/** First free position in the next character array.
+	 */
+	int next;
+	/** Next character array.
+	 */
+	char_map_ref * items;
+	/** Consistency check magic value.
+	 */
+	int magic;
+};
+
+/** Adds the value with the key to the map.
+ *  @param[in,out] map The character string to integer map.
+ *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
+ *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
+ *  @param[in] value The integral value to be stored for the key character string.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the map is not valid.
+ *  @returns EINVAL if the identifier parameter is NULL.
+ *  @returns EINVAL if the length parameter zero (0) and the identifier parameter is an empty character string (the first character is the terminating zero ('\\0') character.
+ *  @returns EEXIST if the key character string is already used.
+ *  @returns Other error codes as defined for the char_map_add_item() function.
+ */
+extern int char_map_add(char_map_ref map, const char * identifier, size_t length, const int value);
+
+/** Clears and destroys the map.
+ *  @param[in,out] map The character string to integer map.
+ */
+extern void char_map_destroy(char_map_ref map);
+
+/** Excludes the value assigned to the key from the map.
+ *  The entry is cleared from the map.
+ *  @param[in,out] map The character string to integer map.
+ *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
+ *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
+ *  @returns The integral value assigned to the key character string.
+ *  @returns CHAR_MAP_NULL if the key is not assigned a&nbsp;value.
+ */
+extern int char_map_exclude(char_map_ref map, const char * identifier, size_t length);
+
+/** Returns the value assigned to the key from the map.
+ *  @param[in] map The character string to integer map.
+ *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
+ *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
+ *  @returns The integral value assigned to the key character string.
+ *  @returns CHAR_MAP_NULL if the key is not assigned a&nbsp;value.
+ */
+extern int char_map_find(const char_map_ref map, const char * identifier, size_t length);
+
+/** Initializes the map.
+ *  @param[in,out] map The character string to integer map.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the map parameter is NULL.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int char_map_initialize(char_map_ref map);
+
+/** Adds or updates the value with the key to the map.
+ *  @param[in,out] map The character string to integer map.
+ *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
+ *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
+ *  @param[in] value The integral value to be stored for the key character string.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the map is not valid.
+ *  @returns EINVAL if the identifier parameter is NULL.
+ *  @returns EINVAL if the length parameter zero (0) and the identifier parameter is an empty character string (the first character is the terminating zero ('\\0) character.
+ *  @returns EEXIST if the key character string is already used.
+ *  @returns Other error codes as defined for the char_map_add_item() function.
+ */
+extern int char_map_update(char_map_ref map, const char * identifier, size_t length, const int value);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/adt/dynamic_fifo.h
===================================================================
--- uspace/lib/socket/include/adt/dynamic_fifo.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/adt/dynamic_fifo.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,119 @@
+/*
+ * 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
+ *  Dynamic first in first out positive integer queue.
+ *  Possitive integer values only.
+ */
+
+#ifndef __NET_DYNAMIC_FIFO_H__
+#define __NET_DYNAMIC_FIFO_H__
+
+/** Type definition of the dynamic fifo queue.
+ *  @see dyn_fifo
+ */
+typedef struct dyn_fifo	dyn_fifo_t;
+
+/** Type definition of the dynamic fifo queue pointer.
+ *  @see dyn_fifo
+ */
+typedef dyn_fifo_t *	dyn_fifo_ref;
+
+/** Dynamic first in first out positive integer queue.
+ *  Possitive integer values only.
+ *  The queue automatically resizes if needed.
+ */
+struct dyn_fifo{
+	/** Stored item field.
+	 */
+	int *	items;
+	/** Actual field size.
+	 */
+	int size;
+	/** First item in the queue index.
+	 */
+	int head;
+	/** Last item in the queue index.
+	 */
+	int tail;
+	/** Consistency check magic value.
+	 */
+	int magic_value;
+};
+
+/** Initializes the dynamic queue.
+ *  @param[in,out] fifo The dynamic queue.
+ *  @param[in] size The initial queue size.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the queue is not valid.
+ *  @returns EBADMEM if the fifo parameter is NULL.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int dyn_fifo_initialize(dyn_fifo_ref fifo, int size);
+
+/** Appends a new item to the queue end.
+ *  @param[in,out] fifo The dynamic queue.
+ *  @param[in] value The new item value. Should be positive.
+ *  @param[in] max_size The maximum queue size. The queue is not resized beyound this limit. May be zero or negative (<=0) to indicate no limit.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the queue is not valid.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
+extern int dyn_fifo_push(dyn_fifo_ref fifo, int value, int max_size);
+
+/** Returns and excludes the first item in the queue.
+ *  @param[in,out] fifo The dynamic queue.
+ *  @returns Value of the first item in the queue.
+ *  @returns EINVAL if the queue is not valid.
+ *  @returns ENOENT if the queue is empty.
+ */
+extern int dyn_fifo_pop(dyn_fifo_ref fifo);
+
+/** Returns and keeps the first item in the queue.
+ *  @param[in,out] fifo The dynamic queue.
+ *  @returns Value of the first item in the queue.
+ *  @returns EINVAL if the queue is not valid.
+ *  @returns ENOENT if the queue is empty.
+ */
+extern int dyn_fifo_value(dyn_fifo_ref fifo);
+
+/** Clears and destroys the queue.
+ *  @param[in,out] fifo The dynamic queue.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the queue is not valid.
+ */
+extern int dyn_fifo_destroy(dyn_fifo_ref fifo);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/adt/generic_char_map.h
===================================================================
--- uspace/lib/socket/include/adt/generic_char_map.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/adt/generic_char_map.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,161 @@
+/*
+ * 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
+ *  Character string to generic type map.
+ */
+
+#ifndef __GENERIC_CHAR_MAP_H__
+#define __GENERIC_CHAR_MAP_H__
+
+#include <errno.h>
+#include <unistd.h>
+
+#include <net_err.h>
+
+#include <adt/char_map.h>
+#include <adt/generic_field.h>
+
+/** Internal magic value for a&nbsp;map consistency check.
+ */
+#define GENERIC_CHAR_MAP_MAGIC_VALUE	0x12345622
+
+/** Character string to generic type map declaration.
+ *  @param[in] name Name of the map.
+ *  @param[in] type Inner object type.
+ */
+#define GENERIC_CHAR_MAP_DECLARE(name, type)									\
+																				\
+GENERIC_FIELD_DECLARE(name##_items, type)										\
+																				\
+typedef	struct name		name##_t;												\
+typedef	name##_t *		name##_ref;												\
+																				\
+struct	name{																	\
+	char_map_t names;														\
+	name##_items_t values;														\
+	int magic;														\
+};																				\
+																				\
+int name##_add(name##_ref map, const char * name, const size_t length, type * value);	\
+int name##_count(name##_ref map);												\
+void name##_destroy(name##_ref map);											\
+void name##_exclude(name##_ref map, const char * name, const size_t length);	\
+type * name##_find(name##_ref map, const char * name, const size_t length);		\
+int name##_initialize(name##_ref map);											\
+int name##_is_valid(name##_ref map);
+
+/** Character string to generic type map implementation.
+ *  Should follow declaration with the same parameters.
+ *  @param[in] name Name of the map.
+ *  @param[in] type Inner object type.
+ */
+#define GENERIC_CHAR_MAP_IMPLEMENT(name, type)									\
+																				\
+GENERIC_FIELD_IMPLEMENT(name##_items, type)										\
+																				\
+int name##_add(name##_ref map, const char * name, const size_t length, type * value){	\
+	ERROR_DECLARE;																\
+																				\
+	int index;																	\
+																				\
+	if(! name##_is_valid(map)){													\
+		return EINVAL;															\
+	}																			\
+	index = name##_items_add(&map->values, value);								\
+	if(index < 0){																\
+		return index;															\
+	}																			\
+	if(ERROR_OCCURRED(char_map_add(&map->names, name, length, index))){			\
+		name##_items_exclude_index(&map->values, index);						\
+		return ERROR_CODE;														\
+	}																			\
+	return EOK;																	\
+}																				\
+																				\
+int name##_count(name##_ref map){												\
+	return name##_is_valid(map) ? name##_items_count(&map->values) : -1;		\
+}																				\
+																				\
+void name##_destroy(name##_ref map){											\
+	if(name##_is_valid(map)){													\
+		char_map_destroy(&map->names);											\
+		name##_items_destroy(&map->values);										\
+	}																			\
+}																				\
+																				\
+void name##_exclude(name##_ref map, const char * name, const size_t length){	\
+	if(name##_is_valid(map)){													\
+		int index;																\
+																				\
+		index = char_map_exclude(&map->names, name, length);					\
+		if(index != CHAR_MAP_NULL){												\
+			name##_items_exclude_index(&map->values, index);					\
+		}																		\
+	}																			\
+}																				\
+																				\
+type * name##_find(name##_ref map, const char * name, const size_t length){		\
+	if(name##_is_valid(map)){													\
+		int index;																\
+																				\
+		index = char_map_find(&map->names, name, length);						\
+		if(index != CHAR_MAP_NULL){												\
+			return name##_items_get_index(&map->values, index);					\
+		}																		\
+	}																			\
+	return NULL;																\
+}																				\
+																				\
+int name##_initialize(name##_ref map){											\
+	ERROR_DECLARE;																\
+																				\
+	if(! map){																	\
+		return EINVAL;															\
+	}																			\
+	ERROR_PROPAGATE(char_map_initialize(&map->names));							\
+	if(ERROR_OCCURRED(name##_items_initialize(&map->values))){					\
+		char_map_destroy(&map->names);											\
+		return ERROR_CODE;														\
+	}																			\
+	map->magic = GENERIC_CHAR_MAP_MAGIC_VALUE;									\
+	return EOK;																	\
+}																				\
+																				\
+int name##_is_valid(name##_ref map){											\
+	return map && (map->magic == GENERIC_CHAR_MAP_MAGIC_VALUE);					\
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/adt/generic_field.h
===================================================================
--- uspace/lib/socket/include/adt/generic_field.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/adt/generic_field.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,160 @@
+/*
+ * 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
+ *  Generic type field.
+ */
+
+#ifndef __GENERIC_FIELD_H__
+#define __GENERIC_FIELD_H__
+
+#include <errno.h>
+#include <malloc.h>
+#include <mem.h>
+#include <unistd.h>
+
+/** Internal magic value for a&nbsp;field consistency check.
+ */
+#define GENERIC_FIELD_MAGIC_VALUE		0x55667788
+
+/** Generic type field declaration.
+ *  @param[in] name Name of the field.
+ *  @param[in] type Inner object type.
+ */
+#define GENERIC_FIELD_DECLARE(name, type)										\
+																				\
+typedef	struct name		name##_t;												\
+typedef	name##_t *		name##_ref;												\
+																				\
+struct	name{																	\
+	int size;																	\
+	int next;																	\
+	type **	items;																\
+	int magic;																	\
+};																				\
+																				\
+int name##_add(name##_ref field, type * value);									\
+int name##_count(name##_ref field);												\
+void name##_destroy(name##_ref field);											\
+void name##_exclude_index(name##_ref field, int index);							\
+type ** name##_get_field(name##_ref field);										\
+type * name##_get_index(name##_ref field, int index);							\
+int name##_initialize(name##_ref field);										\
+int name##_is_valid(name##_ref field);
+
+/** Generic type field implementation.
+ *  Should follow declaration with the same parameters.
+ *  @param[in] name Name of the field.
+ *  @param[in] type Inner object type.
+ */
+#define GENERIC_FIELD_IMPLEMENT(name, type)										\
+																				\
+int name##_add(name##_ref field, type * value){									\
+	if(name##_is_valid(field)){													\
+		if(field->next == (field->size - 1)){									\
+			type **	tmp;														\
+																				\
+			tmp = (type **) realloc(field->items, sizeof(type *) * 2 * field->size);	\
+			if(! tmp){															\
+				return ENOMEM;													\
+			}																	\
+			field->size *= 2;													\
+			field->items = tmp;													\
+		}																		\
+		field->items[field->next] = value;										\
+		++ field->next;															\
+		field->items[field->next] = NULL;										\
+		return field->next - 1;													\
+	}																			\
+	return EINVAL;																\
+}																				\
+																				\
+int name##_count(name##_ref field){												\
+	return name##_is_valid(field) ? field->next : -1;							\
+}																				\
+																				\
+void name##_destroy(name##_ref field){											\
+	if(name##_is_valid(field)){													\
+		int index;																\
+																				\
+		field->magic = 0;														\
+		for(index = 0; index < field->next; ++ index){							\
+			if(field->items[index]){											\
+				free(field->items[index]);										\
+			}																	\
+		}																		\
+		free(field->items);														\
+	}																			\
+}																				\
+																				\
+void name##_exclude_index(name##_ref field, int index){							\
+	if(name##_is_valid(field) && (index >= 0) && (index < field->next) && (field->items[index])){	\
+		free(field->items[index]);												\
+		field->items[index] = NULL;												\
+	}																			\
+}																				\
+																				\
+type * name##_get_index(name##_ref field, int index){							\
+	if(name##_is_valid(field) && (index >= 0) && (index < field->next) && (field->items[index])){	\
+		return field->items[index];												\
+	}																			\
+	return NULL;																\
+}																				\
+																				\
+type ** name##_get_field(name##_ref field){										\
+	return name##_is_valid(field) ? field->items : NULL;						\
+}																				\
+																				\
+int name##_initialize(name##_ref field){										\
+	if(! field){																\
+		return EINVAL;															\
+	}																			\
+	field->size = 2;															\
+	field->next = 0;															\
+	field->items = (type **) malloc(sizeof(type *) * field->size);				\
+	if(! field->items){															\
+		return ENOMEM;															\
+	}																			\
+	field->items[field->next] = NULL;											\
+	field->magic = GENERIC_FIELD_MAGIC_VALUE;									\
+	return EOK;																	\
+}																				\
+																				\
+int name##_is_valid(name##_ref field){											\
+	return field && (field->magic == GENERIC_FIELD_MAGIC_VALUE);				\
+}
+
+#endif
+
+/** @}
+ */
+
Index: uspace/lib/socket/include/adt/int_map.h
===================================================================
--- uspace/lib/socket/include/adt/int_map.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/adt/int_map.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,247 @@
+/*
+ * 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
+ *  Integer to generic type map.
+ */
+
+#ifndef __NET_INT_MAP_H__
+#define __NET_INT_MAP_H__
+
+#include <errno.h>
+#include <malloc.h>
+#include <mem.h>
+#include <unistd.h>
+
+/** Internal magic value for a&nbsp;map consistency check.
+ */
+#define INT_MAP_MAGIC_VALUE			0x11223344
+
+/** Internal magic value for an item consistency check.
+ */
+#define INT_MAP_ITEM_MAGIC_VALUE	0x55667788
+
+/** Integer to generic type map declaration.
+ *  @param[in] name Name of the map.
+ *  @param[in] type Inner object type.
+ */
+#define INT_MAP_DECLARE(name, type)												\
+																				\
+typedef	struct name			name##_t;											\
+typedef	name##_t *			name##_ref;											\
+typedef	struct name##_item	name##_item_t;										\
+typedef	name##_item_t *		name##_item_ref;									\
+																				\
+struct	name##_item{															\
+	int key;																\
+	type * value;																\
+	int magic;																\
+};																				\
+																				\
+struct	name{																	\
+	int size;														\
+	int next;														\
+	name##_item_ref items;														\
+	int magic;														\
+};																				\
+																				\
+int name##_add(name##_ref map, int key, type * value);							\
+void name##_clear(name##_ref map);												\
+int name##_count(name##_ref map);												\
+void name##_destroy(name##_ref map);											\
+void name##_exclude(name##_ref map, int key);									\
+void name##_exclude_index(name##_ref map, int index);							\
+type * name##_find(name##_ref map, int key);									\
+int name##_update(name##_ref map, int key, int new_key);						\
+type * name##_get_index(name##_ref map, int index);								\
+int name##_initialize(name##_ref map);											\
+int name##_is_valid(name##_ref map);											\
+void name##_item_destroy(name##_item_ref item);									\
+int name##_item_is_valid(name##_item_ref item);
+
+/** Integer to generic type map implementation.
+ *  Should follow declaration with the same parameters.
+ *  @param[in] name Name of the map.
+ *  @param[in] type Inner object type.
+ */
+#define INT_MAP_IMPLEMENT(name, type)											\
+																				\
+int name##_add(name##_ref map, int key, type * value){							\
+	if(name##_is_valid(map)){													\
+		if(map->next == (map->size - 1)){										\
+			name##_item_ref tmp;												\
+																				\
+			tmp = (name##_item_ref) realloc(map->items, sizeof(name##_item_t) * 2 * map->size);	\
+			if(! tmp){															\
+				return ENOMEM;													\
+			}																	\
+			map->size *= 2;														\
+			map->items = tmp;													\
+		}																		\
+		map->items[map->next].key = key;										\
+		map->items[map->next].value = value;									\
+		map->items[map->next].magic = INT_MAP_ITEM_MAGIC_VALUE;					\
+		++ map->next;															\
+		map->items[map->next].magic = 0;										\
+		return map->next - 1;													\
+	}																			\
+	return EINVAL;																\
+}																				\
+																				\
+void name##_clear(name##_ref map){												\
+	if(name##_is_valid(map)){													\
+		int index;																\
+																				\
+/*		map->magic = 0;*/														\
+		for(index = 0; index < map->next; ++ index){							\
+			if(name##_item_is_valid(&(map->items[index]))){						\
+				name##_item_destroy(&(map->items[index]));						\
+			}																	\
+		}																		\
+		map->next = 0;															\
+		map->items[map->next].magic = 0;										\
+/*		map->magic = INT_MAP_MAGIC_VALUE;*/										\
+	}																			\
+}																				\
+																				\
+int name##_count(name##_ref map){												\
+	return name##_is_valid(map) ? map->next : -1;								\
+}																				\
+																				\
+void name##_destroy(name##_ref map){											\
+	if(name##_is_valid(map)){													\
+		int index;																\
+																				\
+		map->magic = 0;															\
+		for(index = 0; index < map->next; ++ index){							\
+			if(name##_item_is_valid(&(map->items[index]))){						\
+				name##_item_destroy(&(map->items[index]));						\
+			}																	\
+		}																		\
+		free(map->items);														\
+	}																			\
+}																				\
+																				\
+void name##_exclude(name##_ref map, int key){									\
+	if(name##_is_valid(map)){													\
+		int index;																\
+																				\
+		for(index = 0; index < map->next; ++ index){							\
+			if(name##_item_is_valid(&(map->items[index])) && (map->items[index].key == key)){	\
+				name##_item_destroy(&(map->items[index]));						\
+			}																	\
+		}																		\
+	}																			\
+}																				\
+																				\
+void name##_exclude_index(name##_ref map, int index){							\
+	if(name##_is_valid(map) && (index >= 0) && (index < map->next) && name##_item_is_valid(&(map->items[index]))){	\
+		name##_item_destroy(&(map->items[index]));								\
+	}																			\
+}																				\
+																				\
+type * name##_find(name##_ref map, int key){									\
+	if(name##_is_valid(map)){													\
+		int index;																\
+																				\
+		for(index = 0; index < map->next; ++ index){							\
+			if(name##_item_is_valid(&(map->items[index])) && (map->items[index].key == key)){	\
+				return map->items[index].value;									\
+			}																	\
+		}																		\
+	}																			\
+	return NULL;																\
+}																				\
+																				\
+int name##_update(name##_ref map, int key, int new_key){						\
+	if(name##_is_valid(map)){													\
+		int index;																\
+																				\
+		for(index = 0; index < map->next; ++ index){							\
+			if(name##_item_is_valid(&(map->items[index]))){						\
+				if(map->items[index].key == new_key){							\
+					return EEXIST;												\
+				}else if(map->items[index].key == key){							\
+					map->items[index].key = new_key;							\
+					return EOK;													\
+				}																\
+			}																	\
+		}																		\
+	}																			\
+	return ENOENT;																\
+}																				\
+																				\
+type * name##_get_index(name##_ref map, int index){								\
+	if(name##_is_valid(map) && (index >= 0) && (index < map->next) && name##_item_is_valid(&(map->items[index]))){	\
+		return map->items[index].value;											\
+	}																			\
+	return NULL;																\
+}																				\
+																				\
+int name##_initialize(name##_ref map){											\
+	if(! map){																	\
+		return EINVAL;															\
+	}																			\
+	map->size = 2;																\
+	map->next = 0;																\
+	map->items = (name##_item_ref) malloc(sizeof(name##_item_t) * map->size);	\
+	if(! map->items){															\
+		return ENOMEM;															\
+	}																			\
+	map->items[map->next].magic = 0;											\
+	map->magic = INT_MAP_MAGIC_VALUE;											\
+	return EOK;																	\
+}																				\
+																				\
+int name##_is_valid(name##_ref map){											\
+	return map && (map->magic == INT_MAP_MAGIC_VALUE);							\
+}																				\
+																				\
+void name##_item_destroy(name##_item_ref item){									\
+	if(name##_item_is_valid(item)){												\
+		item->magic = 0;														\
+		if(item->value){														\
+			free(item->value);													\
+			item->value = NULL;													\
+		}																		\
+	}																			\
+}																				\
+																				\
+int name##_item_is_valid(name##_item_ref item){									\
+	return item && (item->magic == INT_MAP_ITEM_MAGIC_VALUE);					\
+}
+
+#endif
+
+/** @}
+ */
+
Index: uspace/lib/socket/include/adt/measured_strings.h
===================================================================
--- uspace/lib/socket/include/adt/measured_strings.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/adt/measured_strings.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,144 @@
+/*
+ * 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
+ *  Character string with measured length.
+ *  The structure has been designed for serialization of character strings between modules.
+ */
+
+#ifndef __MEASURED_STRINGS_H__
+#define __MEASURED_STRINGS_H__
+
+#include <sys/types.h>
+
+/** Type definition of the character string with measured length.
+ *  @see measured_string
+ */
+typedef struct measured_string	measured_string_t;
+
+/** Type definition of the character string with measured length pointer.
+ *  @see measured_string
+ */
+typedef measured_string_t *		measured_string_ref;
+
+/** Character string with measured length.
+ *  This structure has been designed for serialization of character strings between modules.
+ */
+struct	measured_string{
+	/** Character string data.
+	 */
+	char * value;
+	/** Character string length.
+	 */
+	size_t length;
+};
+
+/** Creates a&nbsp;new measured string bundled with a&nbsp;copy of the given string itself as one memory block.
+ *  If the measured string is being freed, whole memory block is freed.
+ *  The measured string should be used only as a&nbsp;constant.
+ *  @param[in] string The initial character string to be stored.
+ *  @param[in] length The length of the given string without the terminating zero ('/0') character. If the length is zero (0), the actual length is computed. The given length is used and appended with the terminating zero ('\\0') character otherwise.
+ *  @returns The new bundled character string with measured length.
+ *  @returns NULL if there is not enough memory left.
+ */
+extern measured_string_ref measured_string_create_bulk(const char * string, size_t length);
+
+/** Copies the given measured string with separated header and data parts.
+ *  @param[in] source The source measured string to be copied.
+ *  @returns The copy of the given measured string.
+ *  @returns NULL if the source parameter is NULL.
+ *  @returns NULL if there is not enough memory left.
+ */
+extern measured_string_ref measured_string_copy(measured_string_ref source);
+
+/** Receives a&nbsp;measured strings array from a&nbsp;calling module.
+ *  Creates the array and the data memory blocks.
+ *  This method should be used only while processing IPC messages as the array size has to be negotiated in advance.
+ *  @param[out] strings The received measured strings array.
+ *  @param[out] data The measured strings data. This memory block stores the actual character strings.
+ *  @param[in] count The size of the measured strings array.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the strings or data parameter is NULL.
+ *  @returns EINVAL if the count parameter is zero (0).
+ *  @returns EINVAL if the sent array differs in size.
+ *  @returns EINVAL if there is inconsistency in sent measured strings' lengths (should not occur).
+ *  @returns ENOMEM if there is not enough memory left.
+ *  @returns Other error codes as defined for the async_data_write_finalize() function.
+ */
+extern int measured_strings_receive(measured_string_ref * strings, char ** data, size_t count);
+
+/** Replies the given measured strings array to a&nbsp;calling module.
+ *  This method should be used only while processing IPC messages as the array size has to be negotiated in advance.
+ *  @param[in] strings The measured strings array to be transferred.
+ *  @param[in] count The measured strings array size.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the strings parameter is NULL.
+ *  @returns EINVAL if the count parameter is zero (0).
+ *  @returns EINVAL if the calling module does not accept the given array size.
+ *  @returns EINVAL if there is inconsistency in sent measured strings' lengths (should not occur).
+ *  @returns Other error codes as defined for the async_data_read_finalize() function.
+ */
+extern int measured_strings_reply(const measured_string_ref strings, size_t count);
+
+/** Receives a&nbsp;measured strings array from another module.
+ *  Creates the array and the data memory blocks.
+ *  This method should be used only following other IPC messages as the array size has to be negotiated in advance.
+ *  @param[in] phone The other module phone.
+ *  @param[out] strings The returned measured strings array.
+ *  @param[out] data The measured strings data. This memory block stores the actual character strings.
+ *  @param[in] count The size of the measured strings array.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the strings or data parameter is NULL.
+ *  @returns EINVAL if the phone or count parameter is not positive (<=0).
+ *  @returns EINVAL if the sent array differs in size.
+ *  @returns ENOMEM if there is not enough memory left.
+ *  @returns Other error codes as defined for the async_data_read_start() function.
+ */
+extern int measured_strings_return(int phone, measured_string_ref * strings, char ** data, size_t count);
+
+/** Sends the given measured strings array to another module.
+ *  This method should be used only following other IPC messages as the array size has to be negotiated in advance.
+ *  @param[in] phone The other module phone.
+ *  @param[in] strings The measured strings array to be transferred.
+ *  @param[in] count The measured strings array size.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the strings parameter is NULL.
+ *  @returns EINVAL if the phone or count parameter is not positive (<=0).
+ *  @returns Other error codes as defined for the async_data_write_start() function.
+ */
+extern int measured_strings_send(int phone, const measured_string_ref strings, size_t count);
+
+#endif
+
+/** @}
+ */
+
Index: uspace/lib/socket/include/icmp_api.h
===================================================================
--- uspace/lib/socket/include/icmp_api.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/icmp_api.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,85 @@
+/*
+ * 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 icmp
+ *  @{
+ */
+
+/** @file
+ *  ICMP module application interface.
+ */
+
+#ifndef __NET_ICMP_API_H__
+#define __NET_ICMP_API_H__
+
+#include <sys/types.h>
+
+#include <net_device.h>
+#include <adt/measured_strings.h>
+#include <packet/packet.h>
+#include <inet.h>
+#include <ip_codes.h>
+#include <socket_codes.h>
+#include <icmp_codes.h>
+#include <icmp_common.h>
+
+/** Miliseconds type definition.
+ */
+typedef size_t	mseconds_t;
+
+/** @name ICMP module application interface
+ *  This interface is used by other application modules.
+ */
+/*@{*/
+
+/** Requests an echo message.
+ *  Sends a packet with specified parameters to the target host and waits for the reply upto the given timeout.
+ *  Blocks the caller until the reply or the timeout occurres.
+ *  @param[in] icmp_phone The ICMP module phone used for (semi)remote calls.
+ *  @param[in] size The message data length in bytes.
+ *  @param[in] timeout The timeout in miliseconds.
+ *  @param[in] ttl The time to live.
+ *  @param[in] tos The type of service.
+ *  @param[in] dont_fragment The value indicating whether the datagram must not be fragmented. Is used as a MTU discovery.
+ *  @param[in] addr The target host address.
+ *  @param[in] addrlen The torget host address length.
+ *  @returns ICMP_ECHO on success.
+ *  @returns ETIMEOUT if the reply has not arrived before the timeout.
+ *  @returns ICMP type of the received error notification. 
+ *  @returns EINVAL if the addrlen parameter is less or equal to zero (<=0).
+ *  @returns ENOMEM if there is not enough memory left.
+ *  @returns EPARTY if there was an internal error.
+ */
+extern int icmp_echo_msg(int icmp_phone, size_t size, mseconds_t timeout, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, const struct sockaddr * addr, socklen_t addrlen);
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/icmp_codes.h
===================================================================
--- uspace/lib/socket/include/icmp_codes.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/icmp_codes.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,347 @@
+/*
+ * 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 icmp
+ *  @{
+ */
+
+/** @file
+ *  ICMP types and codes according to the on-line IANA - ICMP Type Numbers - <http://http://www.iana.org/assignments/icmp-parameters>, cited September 14 2009.
+ */
+
+#ifndef __NET_ICMP_CODES_H__
+#define __NET_ICMP_CODES_H__
+
+/** ICMP type type definition.
+ */
+typedef uint8_t	icmp_type_t;
+
+/** ICMP code type definition.
+ */
+typedef uint8_t	icmp_code_t;
+
+/** ICMP parameter type definition.
+ */
+typedef uint16_t	icmp_param_t;
+
+/** @name ICMP types definitions
+ */
+/*@{*/
+
+/** Echo Reply.
+ */
+#define ICMP_ECHOREPLY		0
+
+/** Destination Unreachable.
+ */
+#define ICMP_DEST_UNREACH	3
+
+/** Source Quench.
+ */
+#define ICMP_SOURCE_QUENCH	4
+
+/** Redirect.
+ */
+#define ICMP_REDIRECT		5
+
+/** Alternate Host Address.
+ */
+#define ICMP_ALTERNATE_ADDR	6
+
+/** Echo Request.
+ */
+#define ICMP_ECHO			8
+
+/** Router Advertisement.
+ */
+#define ICMP_ROUTER_ADV		9
+
+/** Router solicitation.
+ */
+#define ICMP_ROUTER_SOL		10
+
+/** Time Exceeded.
+ */
+#define ICMP_TIME_EXCEEDED	11
+
+/** Parameter Problem.
+ */
+#define ICMP_PARAMETERPROB	12
+
+/** Timestamp Request.
+ */
+#define ICMP_TIMESTAMP		13
+
+/** Timestamp Reply.
+ */
+#define ICMP_TIMESTAMPREPLY	14
+
+/** Information Request.
+ */
+#define ICMP_INFO_REQUEST	15
+
+/** Information Reply.
+ */
+#define ICMP_INFO_REPLY		16
+
+/** Address Mask Request.
+ */
+#define ICMP_ADDRESS		17
+
+/** Address Mask Reply.
+ */
+#define ICMP_ADDRESSREPLY	18
+
+/** Traceroute.
+ */
+#define ICMP_TRACEROUTE		30
+
+/** Datagram Conversion Error.
+ */
+#define ICMP_CONVERSION_ERROR	31
+
+/** Mobile Host Redirect.
+ */
+#define ICMP_REDIRECT_MOBILE	32
+
+/** IPv6 Where-Are-You.
+ */
+#define ICMP_IPV6_WHERE_ARE_YOU	33
+
+/** IPv6 I-Am-Here.
+ */
+#define ICMP_IPV6_I_AM_HERE	34
+
+/** Mobile Registration Request.
+ */
+#define ICMP_MOBILE_REQUEST	35
+
+/** Mobile Registration Reply.
+ */
+#define ICMP_MOBILE_REPLY	36
+
+/** Domain name request.
+ */
+#define ICMP_DN_REQUEST		37
+
+/** Domain name reply.
+ */
+#define ICMP_DN_REPLY		38
+
+/** SKIP.
+ */
+#define ICMP_SKIP			39
+
+/** Photuris.
+ */
+#define ICMP_PHOTURIS		40
+
+/*@}*/
+
+/** @name ICMP_DEST_UNREACH codes definitions
+ */
+/*@{*/
+
+/** Network Unreachable.
+ */
+#define ICMP_NET_UNREACH	0
+
+/** Host Unreachable.
+ */
+#define ICMP_HOST_UNREACH	1
+
+/** Protocol Unreachable.
+ */
+#define ICMP_PROT_UNREACH	2
+
+/** Port Unreachable.
+ */
+#define ICMP_PORT_UNREACH	3
+
+/** Fragmentation needed but the Do Not Fragment bit was set.
+ */
+#define ICMP_FRAG_NEEDED	4
+
+/** Source Route failed.
+ */
+#define ICMP_SR_FAILED		5
+
+/** Destination network unknown.
+ */
+#define ICMP_NET_UNKNOWN	6
+
+/** Destination host unknown.
+ */
+#define ICMP_HOST_UNKNOWN	7
+
+/** Source host isolated (obsolete).
+ */
+#define ICMP_HOST_ISOLATED	8
+
+/** Destination network administratively prohibited.
+ */
+#define ICMP_NET_ANO		9
+
+/** Destination host administratively prohibited.
+ */
+#define ICMP_HOST_ANO		10
+
+/** Network unreachable for this type of service.
+ */
+#define ICMP_NET_UNR_TOS	11
+
+/** Host unreachable for this type of service.
+ */
+#define ICMP_HOST_UNR_TOS	12
+
+/** Communication administratively prohibited by filtering.
+ */
+#define ICMP_PKT_FILTERED	13
+
+/** Host precedence violation.
+ */
+#define ICMP_PREC_VIOLATION	14
+
+/** Precedence cutoff in effect.
+ */
+#define ICMP_PREC_CUTOFF	15
+
+/*@}*/
+
+/** @name ICMP_REDIRECT codes definitions
+ */
+/*@{*/
+
+/** Network redirect (or subnet).
+ */
+#define ICMP_REDIR_NET		0
+
+/** Host redirect.
+ */
+#define ICMP_REDIR_HOST		1
+
+/** Network redirect for this type of service.
+ */
+#define ICMP_REDIR_NETTOS	2
+
+/** Host redirect for this type of service.
+ */
+#define ICMP_REDIR_HOSTTOS	3
+
+/*@}*/
+
+/** @name ICMP_ALTERNATE_ADDRESS codes definitions
+ */
+/*@{*/
+
+/** Alternate address for host.
+ */
+#define ICMP_ALTERNATE_HOST	0
+
+/*@}*/
+
+/** @name ICMP_ROUTER_ADV codes definitions
+ */
+/*@{*/
+
+/** Normal router advertisement.
+ */
+#define ICMP_ROUTER_NORMAL	0
+
+/** Does not route common traffic.
+ */
+#define ICMP_ROUTER_NO_NORMAL_TRAFFIC	16
+
+/*@}*/
+
+/** @name ICMP_TIME_EXCEEDED codes definitions
+ */
+/*@{*/
+
+/** Transit TTL exceeded.
+ */
+#define ICMP_EXC_TTL		0
+
+/** Reassembly TTL exceeded.
+ */
+#define ICMP_EXC_FRAGTIME	1
+
+/*@}*/
+
+/** @name ICMP_PARAMETERPROB codes definitions
+ */
+/*@{*/
+
+/** Pointer indicates the error.
+ */
+#define ICMP_PARAM_POINTER	0
+
+/** Missing required option.
+ */
+#define ICMP_PARAM_MISSING	1
+
+/** Bad length.
+ */
+#define ICMP_PARAM_LENGTH	2
+
+/*@}*/
+
+/** @name ICMP_PHOTURIS codes definitions
+ */
+/*@{*/
+
+/** Bad SPI.
+ */
+#define ICMP_PHOTURIS_BAD_SPI	0
+
+/** Authentication failed.
+ */
+#define ICMP_PHOTURIS_AUTHENTICATION	1
+
+/** Decompression failed.
+ */
+#define ICMP_PHOTURIS_DECOMPRESSION		2
+
+/** Decryption failed.
+ */
+#define ICMP_PHOTURIS_DECRYPTION	3
+
+/** Need authentication.
+ */
+#define ICMP_PHOTURIS_NEED_AUTHENTICATION	4
+
+/** Need authorization.
+ */
+#define ICMP_PHOTURIS_NEED_AUTHORIZATION	5
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/icmp_common.h
===================================================================
--- uspace/lib/socket/include/icmp_common.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/icmp_common.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,60 @@
+/*
+ * 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 icmp
+ *  @{
+ */
+
+/** @file
+ *  ICMP module common interface.
+ */
+
+#ifndef __NET_ICMP_COMMON_H__
+#define __NET_ICMP_COMMON_H__
+
+#include <ipc/services.h>
+
+#include <sys/time.h>
+
+/** Default timeout for incoming connections in microseconds.
+ */
+#define ICMP_CONNECT_TIMEOUT	(1 * 1000 * 1000)
+
+/** Connects to the ICMP module.
+ *  @param service The ICMP module service. Ignored parameter.
+ *  @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0).
+ *  @returns The ICMP module phone on success.
+ *  @returns The ICMP socket identifier if called by the bundle module.
+ *  @returns ETIMEOUT if the connection timeouted.
+ */
+extern int icmp_connect_module(services_t service, suseconds_t timeout);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/icmp_messages.h
===================================================================
--- uspace/lib/socket/include/icmp_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/icmp_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,132 @@
+/*
+ * 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 icmp
+ *  @{
+ */
+
+/** @file
+ *  ICMP module messages.
+ *  @see icmp_interface.h
+ */
+
+#ifndef __NET_ICMP_MESSAGES__
+#define __NET_ICMP_MESSAGES__
+
+#include <ipc/ipc.h>
+#include <sys/types.h>
+
+#include <icmp_codes.h>
+#include <net_messages.h>
+
+/** ICMP module messages.
+ */
+typedef enum{
+	/** Sends echo request.
+	 *  @see icmp_echo()
+	 */
+	NET_ICMP_ECHO = NET_ICMP_FIRST,
+	/** Sends destination unreachable error message.
+	 *  @see icmp_destination_unreachable_msg()
+	 */
+	NET_ICMP_DEST_UNREACH,
+	/** Sends source quench error message.
+	 *  @see icmp_source_quench_msg()
+	 */
+	NET_ICMP_SOURCE_QUENCH,
+	/** Sends time exceeded error message.
+	 *  @see icmp_time_exceeded_msg()
+	 */
+	NET_ICMP_TIME_EXCEEDED,
+	/** Sends parameter problem error message.
+	 *  @see icmp_parameter_problem_msg()
+	 */
+	NET_ICMP_PARAMETERPROB,
+	/** Initializes new connection.
+	 */
+	NET_ICMP_INIT
+} icmp_messages;
+
+/** @name ICMP specific message parameters definitions
+ */
+/*@{*/
+
+/** Returns the ICMP code message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define ICMP_GET_CODE(call) \
+	({icmp_code_t code = (icmp_code_t) IPC_GET_ARG1(*call); code;})
+
+/** Returns the ICMP link MTU message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define ICMP_GET_MTU(call) \
+	({icmp_param_t mtu = (icmp_param_t) IPC_GET_ARG3(*call); mtu;})
+
+/** Returns the pointer message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define ICMP_GET_POINTER(call) \
+	({icmp_param_t pointer = (icmp_param_t) IPC_GET_ARG3(*call); pointer;})
+
+/** Returns the size message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define ICMP_GET_SIZE(call) \
+	({size_t size = (size_t) IPC_GET_ARG1(call); size;})
+
+/** Returns the timeout message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define ICMP_GET_TIMEOUT(call) \
+	(({suseconds_t timeout = (suseconds_t) IPC_GET_ARG2(call); timeout;}))
+
+/** Returns the time to live message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define ICMP_GET_TTL(call) \
+	({ip_ttl_t ttl = (ip_ttl_t) IPC_GET_ARG3(call); ttl;})
+
+/** Returns the type of service message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define ICMP_GET_TOS(call) \
+	({ip_tos_t tos = (ip_tos_t) IPC_GET_ARG4(call); tos;})
+
+/** Returns the dont fragment message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define ICMP_GET_DONT_FRAGMENT(call) \
+	({int dont_fragment = (int) IPC_GET_ARG5(call); dont_fragment;})
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/in.h
===================================================================
--- uspace/lib/socket/include/in.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/in.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,89 @@
+/*
+ * 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
+ *  INET family common definitions.
+ */
+
+#ifndef __NET_IN_H__
+#define __NET_IN_H__
+
+#include <sys/types.h>
+
+#include <ip_protocols.h>
+#include <inet.h>
+
+/** INET string address maximum length.
+ */
+#define INET_ADDRSTRLEN		(4 * 3 + 3 + 1)
+
+/** Type definition of the INET address.
+ *  @see in_addr
+ */
+typedef struct in_addr		in_addr_t;
+
+/** Type definition of the INET socket address.
+ *  @see sockaddr_in
+ */
+typedef struct sockaddr_in	sockaddr_in_t;
+
+/** INET address.
+ */
+struct in_addr{
+	/** 4 byte IP address.
+	 */
+	uint32_t s_addr;
+};
+
+/** INET socket address.
+ *  @see sockaddr
+ */
+struct sockaddr_in{
+	/** Address family.
+	 *  Should be AF_INET.
+	 */
+	uint16_t sin_family;
+	/** Port number.
+	 */
+	uint16_t sin_port;
+	/** Internet address.
+	 */
+	struct in_addr sin_addr;
+	/** Padding to meet the sockaddr size.
+	 */
+	uint8_t sin_zero[8];
+};
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/in6.h
===================================================================
--- uspace/lib/socket/include/in6.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/in6.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,92 @@
+/*
+ * 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
+ *  INET6 family common definitions.
+ */
+
+#ifndef __NET_IN6_H__
+#define __NET_IN6_H__
+
+#include <sys/types.h>
+
+#include <ip_protocols.h>
+#include <inet.h>
+
+/** INET6 string address maximum length.
+ */
+#define INET6_ADDRSTRLEN	(8 * 4 + 7 + 1)
+
+/** Type definition of the INET6 address.
+ *  @see in6_addr
+ */
+typedef struct in6_addr	in6_addr_t;
+
+/** Type definition of the INET6 socket address.
+ *  @see sockaddr_in6
+ */
+typedef struct sockaddr_in6	sockaddr_in6_t;
+
+/** INET6 address.
+ */
+struct in6_addr{
+	/** 16 byte IPv6 address.
+	 */
+	unsigned char s6_addr[16];
+};
+
+/** INET6 socket address.
+ *  @see sockaddr
+ */
+struct sockaddr_in6{
+	/** Address family.
+	 *  Should be AF_INET6.
+	 */
+	uint16_t sin6_family;
+	/** Port number.
+	 */
+	uint16_t sin6_port;
+	/** IPv6 flow information.
+	 */
+	uint32_t sin6_flowinfo;
+	/** IPv6 address.
+	 */
+	struct in6_addr sin6_addr;
+	/** Scope identifier.
+	 */
+	uint32_t sin6_scope_id;
+};
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/inet.h
===================================================================
--- uspace/lib/socket/include/inet.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/inet.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,115 @@
+/*
+ * 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
+ *  Internet common definitions.
+ */
+
+#ifndef __NET_INET_H__
+#define __NET_INET_H__
+
+#include <sys/types.h>
+
+#include <net_byteorder.h>
+
+/** Type definition of the socket address.
+ *  @see sockaddr
+ */
+typedef struct sockaddr		sockaddr_t;
+
+/** Type definition of the address information.
+ *  @see addrinfo
+ */
+typedef struct addrinfo		addrinfo_t;
+
+/** Prints the address into the character buffer.
+ *  @param[in] family The address family.
+ *  @param[in] data The address data.
+ *  @param[out] address The character buffer to be filled.
+ *  @param[in] length The buffer length.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the data or address parameter is NULL.
+ *  @returns ENOMEM if the character buffer is not long enough.
+ *  @returns ENOTSUP if the address family is not supported.
+ */
+extern int inet_ntop(uint16_t family, const uint8_t * data, char * address, size_t length);
+
+/** Parses the character string into the address.
+ *  If the string is shorter than the full address, zero bytes are added.
+ *  @param[in] family The address family.
+ *  @param[in] address The character buffer to be parsed.
+ *  @param[out] data The address data to be filled.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the data parameter is NULL.
+ *  @returns ENOENT if the address parameter is NULL.
+ *  @returns ENOTSUP if the address family is not supported.
+ */
+extern int inet_pton(uint16_t family, const char * address, uint8_t * data);
+
+/** Socket address.
+ */
+struct sockaddr{
+	/** Address family.
+	 *  @see socket.h
+	 */
+	uint16_t sa_family;
+	/** 14 byte protocol address.
+	 */
+	uint8_t sa_data[14];
+};
+
+// TODO define address information
+// /** Address information.
+// * \todo
+// */
+//struct addrinfo{
+//	int				ai_flags;		// AI_PASSIVE, AI_CANONNAME, etc.
+//	uint16_t		ai_family;		// AF_INET, AF_INET6, AF_UNSPEC
+//	int				ai_socktype;	// SOCK_STREAM, SOCK_DGRAM
+//	int				ai_protocol;	// use 0 for "any"
+//	size_t			ai_addrlen;		// size of ai_addr in bytes
+//	struct sockaddr *	ai_addr;	// struct sockaddr_in or _in6
+//	char *			ai_canonname;	// full canonical hostname
+//	struct addrinfo *	ai_next;	// linked list, next node
+//};
+
+/*int getaddrinfo(const char *node, // e.g. "www.example.com" or IP
+const char *service, // e.g. "http" or port number
+const struct addrinfo *hints,
+struct addrinfo **res);
+getnameinfo
+*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/ip_codes.h
===================================================================
--- uspace/lib/socket/include/ip_codes.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/ip_codes.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,374 @@
+/*
+ * 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 ip
+ *  @{
+ */
+
+/** @file
+ *  IP codes and definitions.
+ */
+
+#ifndef __NET_IP_CODES_H__
+#define __NET_IP_CODES_H__
+
+#include <sys/types.h>
+
+/** IP time to live counter type definition.
+ */
+typedef uint8_t	ip_ttl_t;
+
+/** IP type of service type definition.
+ */
+typedef uint8_t	ip_tos_t;
+
+/** IP transport protocol type definition.
+ */
+typedef uint8_t	ip_protocol_t;
+
+/** Default IPVERSION.
+ */
+#define IPVERSION	4
+
+/** Maximum time to live counter.
+ */
+#define MAXTTL		255
+
+/** Default time to live counter.
+ */
+#define IPDEFTTL	64
+
+/** @name IP type of service definitions
+ */
+/*@{*/
+
+/** IP TOS mask.
+ */
+#define IPTOS_TOS_MASK				0x1E
+
+/** Precedence shift.
+ */
+#define IPTOS_PRECEDENCE_SHIFT		5
+
+/** Delay shift.
+ */
+#define IPTOS_DELAY_SHIFT			4
+
+/** Throughput shift.
+ */
+#define IPTOS_THROUGHPUT_SHIFT		3
+
+/** Reliability shift.
+ */
+#define IPTOS_RELIABILITY_SHIFT		2
+
+/** Cost shift.
+ */
+#define IPTOS_COST_SHIFT			1
+
+/** Normal delay.
+ */
+#define IPTOS_NORMALDELAY			(0x0 << IPTOS_DELAY_SHIFT)
+
+/** Low delay.
+ */
+#define IPTOS_LOWDELAY				(0x1 << IPTOS_DELAY_SHIFT)
+
+/** Normal throughput.
+ */
+#define IPTOS_NORMALTHROUGHPUT		(0x0 << IPTOS_THROUGHPUT_SHIFT)
+
+/** Throughput.
+ */
+#define IPTOS_THROUGHPUT			(0x1 << IPTOS_THROUGHPUT_SHIFT)
+
+/** Normal reliability.
+ */
+#define IPTOS_NORMALRELIABILITY		(0x0 << IPTOS_RELIABILITY_SHIFT)
+
+/** Reliability.
+ */
+#define IPTOS_RELIABILITY			(0x1 << IPTOS_RELIABILITY_SHIFT)
+
+/** Normal cost.
+ */
+#define IPTOS_NORMALCOST			(0x0 << IPTOS_COST_SHIFT)
+
+/** Minimum cost.
+ */
+#define IPTOS_MICNCOST				(0x1 << IPTOS_COST_SHIFT)
+
+/*@}*/
+
+/** @name IP TOS precedence definitions
+ */
+/*@{*/
+
+
+/** Precedence mask.
+ */
+#define IPTOS_PREC_MASK				0xE0
+
+/** Routine precedence.
+ */
+#define IPTOS_PREC_ROUTINE			(0x0 << IPTOS_PRECEDENCE_SHIFT)
+
+/** Priority precedence.
+ */
+#define IPTOS_PREC_PRIORITY			(0x1 << IPTOS_PRECEDENCE_SHIFT)
+
+/** Immediate precedence.
+ */
+#define IPTOS_PREC_IMMEDIATE		(0x2 << IPTOS_PRECEDENCE_SHIFT)
+
+/** Flash precedence.
+ */
+#define IPTOS_PREC_FLASH			(0x3 << IPTOS_PRECEDENCE_SHIFT)
+
+/** Flash override precedence.
+ */
+#define IPTOS_PREC_FLASHOVERRIDE	(0x4 << IPTOS_PRECEDENCE_SHIFT)
+
+/** Critical precedence.
+ */
+#define IPTOS_PREC_CRITIC_ECP		(0x5 << IPTOS_PRECEDENCE_SHIFT)
+
+/** Inter-network control precedence.
+ */
+#define IPTOS_PREC_INTERNETCONTROL	(0x6 << IPTOS_PRECEDENCE_SHIFT)
+
+/** Network control precedence.
+ */
+#define IPTOS_PREC_NETCONTROL		(0x7 << IPTOS_PRECEDENCE_SHIFT)
+
+/*@}*/
+
+/** @name IP options definitions
+ */
+/*@{*/
+
+/** Copy shift.
+ */
+#define IPOPT_COPY_SHIFT			7
+
+/** Class shift.
+ */
+#define IPOPT_CLASS_SHIFT			5
+
+/** Number shift.
+ */
+#define IPOPT_NUMBER_SHIFT			0
+
+/** Class mask.
+ */
+#define IPOPT_CLASS_MASK			0x60
+
+/** Number mask.
+ */
+#define IPOPT_NUMBER_MASK			0x1F
+
+/** Copy flag.
+ */
+#define IPOPT_COPY					(1 << IPOPT_COPY_SHIFT)
+
+/** Returns IP option type.
+ *  @param[in] copy The value indication whether the IP option should be copied.
+ *  @param[in] class The IP option class.
+ *  @param[in] number The IP option number.
+ */
+#define IPOPT_TYPE(copy, class, number)	(((copy) &IPOPT_COPY) | ((class) &IPOPT_CLASS_MASK) | ((number << IPOPT_NUMBER_SHIFT) &IPOPT_NUMBER_MASK))
+
+/** Returns a value indicating whether the IP option should be copied.
+ *  @param[in] o The IP option.
+ */
+#define	IPOPT_COPIED(o)			((o) &IPOPT_COPY)
+
+/** Returns an IP option class.
+ *  @param[in] o The IP option.
+ */
+#define	IPOPT_CLASS(o)			((o) &IPOPT_CLASS_MASK)
+
+/** Returns an IP option number.
+ *  @param[in] o The IP option.
+ */
+#define	IPOPT_NUMBER(o)			((o) &IPOPT_NUMBER_MASK)
+
+/*@}*/
+
+/** @name IP option class definitions
+ */
+/*@{*/
+
+/** Control class.
+ */
+#define	IPOPT_CONTROL				(0 << IPOPT_CLASS_SHIFT)
+
+/** Reserved class 1.
+ */
+#define	IPOPT_RESERVED1				(1 << IPOPT_CLASS_SHIFT)
+
+/** Measurement class.
+ */
+#define	IPOPT_MEASUREMENT			(2 << IPOPT_CLASS_SHIFT)
+
+/** Reserved class 2.
+ */
+#define	IPOPT_RESERVED2				(3 << IPOPT_CLASS_SHIFT)
+
+/*@}*/
+
+/** @name IP option type definitions
+ */
+/*@{*/
+
+/** End of list.
+ */
+//#define IPOPT_END_OF_LIST			0x0
+#define IPOPT_END					IPOPT_TYPE(0, IPOPT_CONTROL, 0)
+
+/** No operation.
+ */
+//#define IPOPT_NO_OPERATION		0x1
+#define IPOPT_NOOP					IPOPT_TYPE(0, IPOPT_CONTROL, 1)
+
+/** Security.
+ */
+//#define IPOPT_SECURITY			0x82
+#define IPOPT_SEC					IPOPT_TYPE(IPOPT_COPY, IPOPT_CONTROL, 2)
+
+/** Loose source.
+ */
+//#define IPOPT_LOOSE_SOURCE		0x83
+#define IPOPT_LSRR					IPOPT_TYPE(IPOPT_COPY, IPOPT_CONTROL, 3)
+
+/** Strict route.
+ */
+//#define IPOPT_STRICT_SOURCE		0x89
+#define IPOPT_SSRR					IPOPT_TYPE(IPOPT_COPY, IPOPT_CONTROL, 9)
+
+/** Record route.
+ */
+//#define IPOPT_RECORD_ROUTE		0x07
+#define IPOPT_RR					IPOPT_TYPE(IPOPT_COPY, IPOPT_CONTROL, 7)
+
+/** Stream identifier.
+ */
+//#define IPOPT_STREAM_IDENTIFIER	0x88
+#define IPOPT_SID					IPOPT_TYPE(IPOPT_COPY, IPOPT_CONTROL, 8)
+
+/** Stream identifier length.
+ */
+#define IPOPT_SID_LENGTH			4
+
+/** Internet timestamp.
+ */
+//#define IPOPT_INTERNET_TIMESTAMP	0x44
+#define IPOPT_TIMESTAMP				IPOPT_TYPE(IPOPT_COPY, IPOPT_MEASUREMENT, 4)
+
+/** Commercial IP security option.
+ */
+#define IPOPT_CIPSO					IPOPT_TYPE(IPOPT_COPY, IPOPT_CONTROL, 5)
+
+/** No operation variant.
+ */
+#define IPOPT_NOP IPOPT_NOOP
+
+/** End of list variant.
+ */
+#define IPOPT_EOL IPOPT_END
+
+/** Timestamp variant.
+ */
+#define IPOPT_TS  IPOPT_TIMESTAMP
+
+/*@}*/
+
+/** @name IP security option definitions
+ */
+/*@{*/
+
+/** Security length.
+ */
+#define IPOPT_SEC_LENGTH			11
+
+/** Unclasified.
+ */
+#define IPOPT_SEC_UNCLASIFIED		0x0
+
+/** Confidential.
+ */
+#define IPOPT_SEC_CONFIDENTIAL		0xF035
+
+/** EFTO.
+ */
+#define IPOPT_SEC_EFTO				0x789A
+
+/** MMMM.
+ */
+#define IPOPT_SEC_MMMM				0xBC4D
+
+/** PROG.
+ */
+#define IPOPT_SEC_PROG				0x5E26
+
+/** Restricted.
+ */
+#define IPOPT_SEC_RESTRICTED		0xAF13
+
+/** Secret.
+ */
+#define IPOPT_SEC_SECRET			0xD788
+
+/** Top secret.
+ */
+#define IPOPT_SEC_TOP_SECRET		0x6BC5
+
+/*@}*/
+
+/** @name IP timestamp option definitions
+ */
+/*@{*/
+
+/** Tiemstamp only.
+ */
+#define	IPOPT_TS_TSONLY		0
+
+/** Timestamps and addresses.
+ */
+#define	IPOPT_TS_TSANDADDR	1
+
+/** Specified modules only.
+ */
+#define	IPOPT_TS_PRESPEC	3
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/ip_protocols.h
===================================================================
--- uspace/lib/socket/include/ip_protocols.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/ip_protocols.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,619 @@
+/*
+ * 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 ip
+ *  @{
+ */
+
+/** @file
+ *  Internet protocol numbers according to the on-line IANA - Assigned Protocol numbers - <http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml>, cited January 14 2009.
+ */
+
+#ifndef __NET_IPPROTOCOLS_H__
+#define __NET_IPPROTOCOLS_H__
+
+/** @name IP protocols definitions
+ */
+/*@{*/
+
+/** IPv6 Hop-by-Hop Option internet protocol number.
+ */
+#define IPPROTO_HOPOPT		0
+
+/** Internet Control Message internet protocol number.
+ */
+#define IPPROTO_ICMP		1
+
+/** Internet Group Management internet protocol number.
+ */
+#define IPPROTO_IGMP		2
+
+/** Gateway-to-Gateway internet protocol number.
+ */
+#define IPPROTO_GGP		3
+
+/** IP in IP (encapsulation) internet protocol number.
+ */
+#define IPPROTO_IP		4
+
+/** Stream internet protocol number.
+ */
+#define IPPROTO_ST		5
+
+/** Transmission Control internet protocol number.
+ */
+#define IPPROTO_TCP		6
+
+/** CBT internet protocol number.
+ */
+#define IPPROTO_CBT		7
+
+/** Exterior Gateway Protocol internet protocol number.
+ */
+#define IPPROTO_EGP		8
+
+/** any private interior gateway             
+(used by Cisco for their IGRP) internet protocol number.
+ */
+#define IPPROTO_IGP		9
+
+/** BBN RCC Monitoring internet protocol number.
+ */
+#define IPPROTO_BBN_RCC_MON		10
+
+/** Network Voice Protocol internet protocol number.
+ */
+#define IPPROTO_NVP_II		11
+
+/** PUP internet protocol number.
+ */
+#define IPPROTO_PUP		12
+
+/** ARGUS internet protocol number.
+ */
+#define IPPROTO_ARGUS		13
+
+/** EMCON internet protocol number.
+ */
+#define IPPROTO_EMCON		14
+
+/** Cross Net Debugger internet protocol number.
+ */
+#define IPPROTO_XNET		15
+
+/** Chaos internet protocol number.
+ */
+#define IPPROTO_CHAOS		16
+
+/** User Datagram internet protocol number.
+ */
+#define IPPROTO_UDP		17
+
+/** Multiplexing internet protocol number.
+ */
+#define IPPROTO_MUX		18
+
+/** DCN Measurement Subsystems internet protocol number.
+ */
+#define IPPROTO_DCN_MEAS		19
+
+/** Host Monitoring internet protocol number.
+ */
+#define IPPROTO_HMP		20
+
+/** Packet Radio Measurement internet protocol number.
+ */
+#define IPPROTO_PRM		21
+
+/** XEROX NS IDP internet protocol number.
+ */
+#define IPPROTO_XNS_IDP		22
+
+/** Trunk-1 internet protocol number.
+ */
+#define IPPROTO_TRUNK_1		23
+
+/** Trunk-2 internet protocol number.
+ */
+#define IPPROTO_TRUNK_2		24
+
+/** Leaf-1 internet protocol number.
+ */
+#define IPPROTO_LEAF_1		25
+
+/** Leaf-2 internet protocol number.
+ */
+#define IPPROTO_LEAF_2		26
+
+/** Reliable Data Protocol internet protocol number.
+ */
+#define IPPROTO_RDP		27
+
+/** Internet Reliable Transaction internet protocol number.
+ */
+#define IPPROTO_IRTP		28
+
+/** ISO Transport Protocol Class 4 internet protocol number.
+ */
+#define IPPROTO_ISO_TP4		29
+
+/** Bulk Data Transfer Protocol internet protocol number.
+ */
+#define IPPROTO_NETBLT		30
+
+/** MFE Network Services Protocol internet protocol number.
+ */
+#define IPPROTO_MFE_NSP		31
+
+/** MERIT Internodal Protocol internet protocol number.
+ */
+#define IPPROTO_MERIT_INP		32
+
+/** Datagram Congestion Control Protocol internet protocol number.
+ */
+#define IPPROTO_DCCP		33
+
+/** Third Party Connect Protocol internet protocol number.
+ */
+#define IPPROTO_3PC		34
+
+/** Inter-Domain Policy Routing Protocol internet protocol number.
+ */
+#define IPPROTO_IDPR		35
+
+/** XTP internet protocol number.
+ */
+#define IPPROTO_XTP		36
+
+/** Datagram Delivery Protocol internet protocol number.
+ */
+#define IPPROTO_DDP		37
+
+/** IDPR Control Message Transport Proto internet protocol number.
+ */
+#define IPPROTO_IDPR_CMTP		38
+
+/** TP++ Transport Protocol internet protocol number.
+ */
+#define IPPROTO_TP		39
+
+/** IL Transport Protocol internet protocol number.
+ */
+#define IPPROTO_IL		40
+
+/** Ipv6 internet protocol number.
+ */
+#define IPPROTO_IPV6		41
+
+/** Source Demand Routing Protocol internet protocol number.
+ */
+#define IPPROTO_SDRP		42
+
+/** Routing Header for IPv6 internet protocol number.
+ */
+#define IPPROTO_IPv6_Route		43
+
+/** Fragment Header for IPv6 internet protocol number.
+ */
+#define IPPROTO_IPv6_Frag		44
+
+/** Inter-Domain Routing Protocol internet protocol number.
+ */
+#define IPPROTO_IDRP		45
+
+/** Reservation Protocol internet protocol number.
+ */
+#define IPPROTO_RSVP		46
+
+/** General Routing Encapsulation internet protocol number.
+ */
+#define IPPROTO_GRE		47
+
+/** Dynamic Source Routing Protocol internet protocol number.
+ */
+#define IPPROTO_DSR		48
+
+/** BNA internet protocol number.
+ */
+#define IPPROTO_BNA		49
+
+/** Encap Security Payload internet protocol number.
+ */
+#define IPPROTO_ESP		50
+
+/** Authentication Header internet protocol number.
+ */
+#define IPPROTO_AH		51
+
+/** Integrated Net Layer Security  TUBA internet protocol number.
+ */
+#define IPPROTO_I_NLSP		52
+
+/** IP with Encryption internet protocol number.
+ */
+#define IPPROTO_SWIPE		53
+
+/** NBMA Address Resolution Protocol internet protocol number.
+ */
+#define IPPROTO_NARP		54
+
+/** IP Mobility internet protocol number.
+ */
+#define IPPROTO_MOBILE		55
+
+/** Transport Layer Security Protocol        
+using Kryptonet key management internet protocol number.
+ */
+#define IPPROTO_TLSP		56
+
+/** SKIP internet protocol number.
+ */
+#define IPPROTO_SKIP		57
+
+/** ICMP for IPv6 internet protocol number.
+ */
+#define IPPROTO_IPv6_ICMP		58
+
+/** No Next Header for IPv6 internet protocol number.
+ */
+#define IPPROTO_IPv6_NoNxt		59
+
+/** Destination Options for IPv6 internet protocol number.
+ */
+#define IPPROTO_IPv6_Opts		60
+
+/** Any host internal protocol internet protocol number.
+ */
+#define IPPROTO_AHIP		61
+
+/** CFTP internet protocol number.
+ */
+#define IPPROTO_CFTP		62
+
+/** Any local network internet protocol number.
+ */
+#define IPPROTO_ALN		63
+
+/** SATNET and Backroom EXPAK internet protocol number.
+ */
+#define IPPROTO_SAT_EXPAK		64
+
+/** Kryptolan internet protocol number.
+ */
+#define IPPROTO_KRYPTOLAN		65
+
+/** MIT Remote Virtual Disk Protocol internet protocol number.
+ */
+#define IPPROTO_RVD		66
+
+/** Internet Pluribus Packet Core internet protocol number.
+ */
+#define IPPROTO_IPPC		67
+
+/** Any distributed file system internet protocol number.
+ */
+#define IPPROTO_ADFS		68
+
+/** SATNET Monitoring internet protocol number.
+ */
+#define IPPROTO_SAT_MON		69
+
+/** VISA Protocol internet protocol number.
+ */
+#define IPPROTO_VISA		70
+
+/** Internet Packet Core Utility internet protocol number.
+ */
+#define IPPROTO_IPCV		71
+
+/** Computer Protocol Network Executive internet protocol number.
+ */
+#define IPPROTO_CPNX		72
+
+/** Computer Protocol Heart Beat internet protocol number.
+ */
+#define IPPROTO_CPHB		73
+
+/** Wang Span Network internet protocol number.
+ */
+#define IPPROTO_WSN		74
+
+/** Packet Video Protocol internet protocol number.
+ */
+#define IPPROTO_PVP		75
+
+/** Backroom SATNET Monitoring internet protocol number.
+ */
+#define IPPROTO_BR_SAT_MON		76
+
+/** SUN ND IPPROTOCOL_Temporary internet protocol number.
+ */
+#define IPPROTO_SUN_ND		77
+
+/** WIDEBAND Monitoring internet protocol number.
+ */
+#define IPPROTO_WB_MON		78
+
+/** WIDEBAND EXPAK internet protocol number.
+ */
+#define IPPROTO_WB_EXPAK		79
+
+/** ISO Internet Protocol internet protocol number.
+ */
+#define IPPROTO_ISO_IP		80
+
+/** VMTP internet protocol number.
+ */
+#define IPPROTO_VMTP		81
+
+/** SECURE-VMTP internet protocol number.
+ */
+#define IPPROTO_SECURE_VMTP		82
+
+/** VINES internet protocol number.
+ */
+#define IPPROTO_VINES		83
+
+/** TTP internet protocol number.
+ */
+#define IPPROTO_TTP		84
+
+/** NSFNET-IGP internet protocol number.
+ */
+#define IPPROTO_NSFNET_IGP		85
+
+/** Dissimilar Gateway Protocol internet protocol number.
+ */
+#define IPPROTO_DGP		86
+
+/** TCF internet protocol number.
+ */
+#define IPPROTO_TCF		87
+
+/** EIGRP internet protocol number.
+ */
+#define IPPROTO_EIGRP		88
+
+/** OSPFIGP internet protocol number.
+ */
+#define IPPROTO_OSPFIGP		89
+
+/** Sprite RPC Protocol internet protocol number.
+ */
+#define IPPROTO_Sprite_RPC		90
+
+/** Locus Address Resolution Protocol internet protocol number.
+ */
+#define IPPROTO_LARP		91
+
+/** Multicast Transport Protocol internet protocol number.
+ */
+#define IPPROTO_MTP		92
+
+/** AX.25 Frames internet protocol number.
+ */
+#define IPPROTO_AX25		93
+
+/** IP-within-IP Encapsulation Protocol internet protocol number.
+ */
+#define IPPROTO_IPIP		94
+
+/** Mobile Internetworking Control Pro. internet protocol number.
+ */
+#define IPPROTO_MICP		95
+
+/** Semaphore Communications Sec. Pro. internet protocol number.
+ */
+#define IPPROTO_SCC_SP		96
+
+/** Ethernet-within-IP Encapsulation internet protocol number.
+ */
+#define IPPROTO_ETHERIP		97
+
+/** Encapsulation Header internet protocol number.
+ */
+#define IPPROTO_ENCAP		98
+
+/** Any private encryption scheme internet protocol number.
+ */
+#define IPPROTO_APES		99
+
+/** GMTP internet protocol number.
+ */
+#define IPPROTO_GMTP		100
+
+/** Ipsilon Flow Management Protocol internet protocol number.
+ */
+#define IPPROTO_IFMP		101
+
+/** PNNI over IP internet protocol number.
+ */
+#define IPPROTO_PNNI		102
+
+/** Protocol Independent Multicast internet protocol number.
+ */
+#define IPPROTO_PIM		103
+
+/** ARIS internet protocol number.
+ */
+#define IPPROTO_ARIS		104
+
+/** SCPS internet protocol number.
+ */
+#define IPPROTO_SCPS		105
+
+/** QNX internet protocol number.
+ */
+#define IPPROTO_QNX		106
+
+/** Active Networks internet protocol number.
+ */
+#define IPPROTO_AN		107
+
+/** IP Payload Compression Protocol internet protocol number.
+ */
+#define IPPROTO_IPComp		108
+
+/** Sitara Networks Protocol internet protocol number.
+ */
+#define IPPROTO_SNP		109
+
+/** Compaq Peer Protocol internet protocol number.
+ */
+#define IPPROTO_Compaq_Peer		110
+
+/** IPX in IP internet protocol number.
+ */
+#define IPPROTO_IPX_in_IP		111
+
+/** Virtual Router Redundancy Protocol internet protocol number.
+ */
+#define IPPROTO_VRRP		112
+
+/** PGM Reliable Transport Protocol internet protocol number.
+ */
+#define IPPROTO_PGM		113
+
+/** Any 0-hop protocol internet protocol number.
+ */
+#define IPPROTO_A0HP		114
+
+/** Layer Two Tunneling Protocol internet protocol number.
+ */
+#define IPPROTO_L2TP		115
+
+/** D-II Data Exchange (DDX) internet protocol number.
+ */
+#define IPPROTO_DDX		116
+
+/** Interactive Agent Transfer Protocol internet protocol number.
+ */
+#define IPPROTO_IATP		117
+
+/** Schedule Transfer Protocol internet protocol number.
+ */
+#define IPPROTO_STP		118
+
+/** SpectraLink Radio Protocol internet protocol number.
+ */
+#define IPPROTO_SRP		119
+
+/** UTI internet protocol number.
+ */
+#define IPPROTO_UTI		120
+
+/** Simple Message Protocol internet protocol number.
+ */
+#define IPPROTO_SMP		121
+
+/** SM internet protocol number.
+ */
+#define IPPROTO_SM		122
+
+/** Performance Transparency Protocol internet protocol number.
+ */
+#define IPPROTO_PTP		123
+
+/** ISIS over IPv4 internet protocol number.
+ */
+#define IPPROTO_ISIS		124
+
+/** FIRE internet protocol number.
+ */
+#define IPPROTO_FIRE		125
+
+/** Combat Radio Transport Protocol internet protocol number.
+ */
+#define IPPROTO_CRTP		126
+
+/** Combat Radio User Datagram internet protocol number.
+ */
+#define IPPROTO_CRUDP		127
+
+/** SSCOPMCE internet protocol number.
+ */
+#define IPPROTO_SSCOPMCE		128
+
+/** IPLT internet protocol number.
+ */
+#define IPPROTO_IPLT		129
+
+/** Secure Packet Shield internet protocol number.
+ */
+#define IPPROTO_SPS		130
+
+/** Private IP Encapsulation within IP internet protocol number.
+ */
+#define IPPROTO_PIPE		131
+
+/** Stream Control Transmission Protocol internet protocol number.
+ */
+#define IPPROTO_SCTP		132
+
+/** Fibre Channel internet protocol number.
+ */
+#define IPPROTO_FC		133
+
+/** RSVP-E2E-IGNORE internet protocol number.
+ */
+#define IPPROTO_RSVP_E2E_IGNORE		134
+
+/** Mobility Header internet protocol number.
+ */
+#define IPPROTO_MH		135
+
+/** UDPLite internet protocol number.
+ */
+#define IPPROTO_UDPLITE		136
+
+/** MPLS-in-IP internet protocol number.
+ */
+#define IPPROTO_MPLS_in_IP		137
+
+/** MANET Protocols internet protocol number.
+ */
+#define IPPROTO_manet		138
+
+/** Host Identity Protocol internet protocol number.
+ */
+#define IPPROTO_HIP		139
+
+/** Raw internet protocol number.
+ */
+#define IPPROTO_RAW		255
+
+/** Maximum internet protocol number.
+ */
+#define IPPROTO_MAX		(IPPROTO_RAW + 1)
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/net_byteorder.h
===================================================================
--- uspace/lib/socket/include/net_byteorder.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/net_byteorder.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,71 @@
+/*
+ * 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
+ *  Host - network byte order manipulation functions.
+ */
+
+#ifndef __NET_BYTEORDER_H__
+#define __NET_BYTEORDER_H__
+
+#include <byteorder.h>
+#include <sys/types.h>
+
+
+/** Converts the given short number (16 bit) from the host byte order to the network byte order (big endian).
+ *  @param[in] number The number in the host byte order to be converted.
+ *  @returns The number in the network byte order.
+ */
+#define htons(number)		host2uint16_t_be(number)
+
+/** Converts the given long number (32 bit) from the host byte order to the network byte order (big endian).
+ *  @param[in] number The number in the host byte order to be converted.
+ *  @returns The number in the network byte order.
+ */
+#define htonl(number)		host2uint32_t_be(number)
+
+/** Converts the given short number (16 bit) from the network byte order (big endian) to the host byte order.
+ *  @param[in] number The number in the network byte order to be converted.
+ *  @returns The number in the host byte order.
+ */
+#define ntohs(number) 	uint16_t_be2host(number)
+
+/** Converts the given long number (32 bit) from the network byte order (big endian) to the host byte order.
+ *  @param[in] number The number in the network byte order to be converted.
+ *  @returns The number in the host byte order.
+ */
+#define ntohl(number)		uint32_t_be2host(number)
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/net_device.h
===================================================================
--- uspace/lib/socket/include/net_device.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/net_device.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,173 @@
+/*
+ * 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 netif
+ *  @{
+ */
+
+/** @file
+ *  Device identifier, state and usage statistics.
+ */
+
+#ifndef __NET_DEVICE_ID_TYPE_H__
+#define __NET_DEVICE_ID_TYPE_H__
+
+#include <adt/int_map.h>
+
+/** Device identifier to generic type map declaration.
+ */
+#define DEVICE_MAP_DECLARE		INT_MAP_DECLARE
+
+/** Device identifier to generic type map implementation.
+ */
+#define DEVICE_MAP_IMPLEMENT	INT_MAP_IMPLEMENT
+
+/** Invalid device identifier.
+ */
+#define DEVICE_INVALID_ID		(-1)
+
+/** Device identifier type.
+ */
+typedef int	device_id_t;
+
+/** Device state type.
+ */
+typedef enum device_state	device_state_t;
+
+/** Type definition of the device usage statistics.
+ *  @see device_stats
+ */
+typedef struct device_stats	device_stats_t;
+
+/** Type definition of the device usage statistics pointer.
+ *  @see device_stats
+ */
+typedef device_stats_t *	device_stats_ref;
+
+/** Device state.
+ */
+enum	device_state{
+	/** Device not present or not initialized.
+	 */
+	NETIF_NULL = 0,
+	/** Device present and stopped.
+	 */
+	NETIF_STOPPED,
+	/** Device present and active.
+	 */
+	NETIF_ACTIVE,
+	/** Device present but unable to transmit.
+	 */
+	NETIF_CARRIER_LOST
+};
+
+/** Device usage statistics.
+ */
+struct	device_stats{
+	/** Total packets received.
+	 */
+	unsigned long receive_packets;
+	/** Total packets transmitted.
+	 */
+	unsigned long send_packets;
+	/** Total bytes received.
+	 */
+	unsigned long receive_bytes;
+	/** Total bytes transmitted.
+	 */
+	unsigned long send_bytes;
+	/** Bad packets received counter.
+	 */
+	unsigned long receive_errors;
+	/** Packet transmition problems counter.
+	 */
+	unsigned long send_errors;
+	/** No space in buffers counter.
+	 */
+	unsigned long receive_dropped;
+	/** No space available counter.
+	 */
+	unsigned long send_dropped;
+	/** Total multicast packets received.
+	 */
+	unsigned long multicast;
+	/** The number of collisions due to congestion on the medium.
+	 */
+	unsigned long collisions;
+
+	/* detailed receive_errors: */
+	/** Received packet length error counter.
+	 */
+	unsigned long receive_length_errors;
+	/** Receiver buffer overflow counter.
+	 */
+	unsigned long receive_over_errors;
+	/** Received packet with crc error counter.
+	 */
+	unsigned long receive_crc_errors;
+	/** Received frame alignment error counter.
+	 */
+	unsigned long receive_frame_errors;
+	/** Receiver fifo overrun counter.
+	 */
+	unsigned long receive_fifo_errors;
+	/** Receiver missed packet counter.
+	 */
+	unsigned long receive_missed_errors;
+
+	/* detailed send_errors */
+	/** Transmitter aborted counter.
+	 */
+	unsigned long send_aborted_errors;
+	/** Transmitter carrier errors counter.
+	 */
+	unsigned long send_carrier_errors;
+	/** Transmitter fifo overrun counter.
+	 */
+	unsigned long send_fifo_errors;
+	/** Transmitter carrier errors counter.
+	 */
+	unsigned long send_heartbeat_errors;
+	/** Transmitter window errors counter.
+	 */
+	unsigned long send_window_errors;
+
+	/* for cslip etc */
+	/** Total compressed packets received.
+	 */
+	unsigned long receive_compressed;
+	/** Total compressed packet transmitted.
+	 */
+	unsigned long send_compressed;
+};
+
+#endif
+
+/** @}
+ */
+
Index: uspace/lib/socket/include/net_err.h
===================================================================
--- uspace/lib/socket/include/net_err.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/net_err.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,99 @@
+/*
+ * 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
+ * Common error processing codes and routines.
+ */
+
+#ifndef __NET_ERR_H__
+#define __NET_ERR_H__
+
+#include <errno.h>
+
+#ifdef CONFIG_DEBUG
+	#include <stdio.h>
+	#include <str_error.h>
+#endif
+
+/** An actual stored error code.
+ *
+ */
+#define ERROR_CODE  error_check_return_value
+
+/** An error processing routines declaration.
+ *
+ * This has to be declared in the block where the error processing
+ * is desired.
+ *
+ */
+#define ERROR_DECLARE  int ERROR_CODE
+
+/** Store the value as an error code and checks if an error occurred.
+ *
+ * @param[in] value The value to be checked. May be a function call.
+ * @return False if the value indicates success (EOK).
+ * @return True otherwise.
+ *
+ */
+#ifdef CONFIG_DEBUG
+
+#define ERROR_OCCURRED(value) \
+	(((ERROR_CODE = (value)) != EOK) \
+	&& ({ \
+		fprintf(stderr, "libsocket error at %s:%d (%s)\n", \
+		__FILE__, __LINE__, str_error(ERROR_CODE)); \
+		1; \
+	}))
+
+#else
+
+#define ERROR_OCCURRED(value)  ((ERROR_CODE = (value)) != EOK)
+
+#endif
+
+/** Error propagation
+ *
+ * Check if an error occurred and immediately exit the actual
+ * function returning the error code.
+ *
+ * @param[in] value The value to be checked. May be a function call.
+ *
+ */
+
+#define ERROR_PROPAGATE(value) \
+	if (ERROR_OCCURRED(value)) \
+		return ERROR_CODE
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/net_messages.h
===================================================================
--- uspace/lib/socket/include/net_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/net_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,670 @@
+/*
+ * 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 common message definitions.
+ */
+
+#ifndef __NET_MESSAGES_H__
+#define __NET_MESSAGES_H__
+
+#include <async.h>
+
+#include <ipc/ipc.h>
+#include <ipc/services.h>
+
+#include <net_device.h>
+#include <adt/measured_strings.h>
+#include <packet/packet.h>
+
+/** Returns a value indicating whether the value is in the interval.
+ *  @param[in] item The value to be checked.
+ *  @param[in] first_inclusive The first value in the interval inclusive.
+ *  @param[in] last_exclusive The first value after the interval.
+ */
+#define IS_IN_INTERVAL(item, first_inclusive, last_exclusive)	(((item) >= (first_inclusive)) && ((item) < (last_exclusive)))
+
+/** @name Networking message counts
+ */
+/*@{*/
+
+/** The number of ARP messages.
+ */
+#define NET_ARP_COUNT		5
+
+/** The number of Ethernet messages.
+ */
+#define NET_ETH_COUNT		0
+
+/** The number of ICMP messages.
+ */
+#define NET_ICMP_COUNT		6
+
+/** The number of inter-network messages.
+ */
+#define NET_IL_COUNT		6
+
+/** The number of IP messages.
+ */
+#define NET_IP_COUNT		4
+
+/** The number of general networking messages.
+ */
+#define NET_NET_COUNT		3
+
+/** The number of network interface driver messages.
+ */
+#define NET_NETIF_COUNT		6
+
+/** The number of network interface layer messages.
+ */
+#define NET_NIL_COUNT		7
+
+/** The number of packet management system messages.
+ */
+#define NET_PACKET_COUNT	5
+
+/** The number of socket messages.
+ */
+#define NET_SOCKET_COUNT	14
+
+/** The number of TCP messages.
+ */
+#define NET_TCP_COUNT		0
+
+/** The number of transport layer messages.
+ */
+#define NET_TL_COUNT		1
+
+/** The number of UDP messages.
+ */
+#define NET_UDP_COUNT		0
+
+/*@}*/
+
+/** @name Networking message intervals
+ */
+/*@{*/
+
+/** The first networking message.
+ */
+#define NET_FIRST			2000
+
+/** The first network interface layer message.
+ */
+#define NET_NETIF_FIRST		NET_FIRST
+
+/** The last network interface layer message.
+ */
+#define NET_NETIF_LAST		(NET_NETIF_FIRST + NET_NETIF_COUNT)
+
+/** The first general networking message.
+ */
+#define NET_NET_FIRST		(NET_NETIF_LAST + 0)
+
+/** The last general networking message.
+ */
+#define NET_NET_LAST		(NET_NET_FIRST + NET_NET_COUNT)
+
+/** The first network interface layer message.
+ */
+#define NET_NIL_FIRST		(NET_NET_LAST + 0)
+
+/** The last network interface layer message.
+ */
+#define NET_NIL_LAST		(NET_NIL_FIRST + NET_NIL_COUNT)
+
+/** The first Ethernet message.
+ */
+#define NET_ETH_FIRST		(NET_NIL_LAST + 0)
+
+/** The last Ethernet message.
+ */
+#define NET_ETH_LAST		(NET_ETH_FIRST + NET_ETH_COUNT)
+
+/** The first inter-network message.
+ */
+#define NET_IL_FIRST		(NET_ETH_LAST + 0)
+
+/** The last inter-network message.
+ */
+#define NET_IL_LAST			(NET_IL_FIRST + NET_IL_COUNT)
+
+/** The first IP message.
+ */
+#define NET_IP_FIRST		(NET_IL_LAST + 0)
+
+/** The last IP message.
+ */
+#define NET_IP_LAST			(NET_IP_FIRST + NET_IP_COUNT)
+
+/** The first ARP message.
+ */
+#define NET_ARP_FIRST		(NET_IP_LAST + 0)
+
+/** The last ARP message.
+ */
+#define NET_ARP_LAST		(NET_ARP_FIRST + NET_ARP_COUNT)
+
+/** The first ICMP message.
+ */
+#define NET_ICMP_FIRST		(NET_ARP_LAST + 0)
+
+/** The last ICMP message.
+ */
+#define NET_ICMP_LAST		(NET_ICMP_FIRST + NET_ICMP_COUNT)
+
+/** The first ICMP message.
+ */
+#define NET_TL_FIRST		(NET_ICMP_LAST + 0)
+
+/** The last ICMP message.
+ */
+#define NET_TL_LAST			(NET_TL_FIRST + NET_TL_COUNT)
+
+/** The first UDP message.
+ */
+#define NET_UDP_FIRST		(NET_TL_LAST + 0)
+
+/** The last UDP message.
+ */
+#define NET_UDP_LAST		(NET_UDP_FIRST + NET_UDP_COUNT)
+
+/** The first TCP message.
+ */
+#define NET_TCP_FIRST		(NET_UDP_LAST + 0)
+
+/** The last TCP message.
+ */
+#define NET_TCP_LAST		(NET_TCP_FIRST + NET_TCP_COUNT)
+
+/** The first socket message.
+ */
+#define NET_SOCKET_FIRST	(NET_TCP_LAST + 0)
+
+/** The last socket message.
+ */
+#define NET_SOCKET_LAST		(NET_SOCKET_FIRST + NET_SOCKET_COUNT)
+
+/** The first packet management system message.
+ */
+#define NET_PACKET_FIRST	(NET_SOCKET_LAST + 0)
+
+/** The last packet management system message.
+ */
+#define NET_PACKET_LAST		(NET_PACKET_FIRST + NET_PACKET_COUNT)
+
+/** The last networking message.
+ */
+#define NET_LAST			NET_PACKET_LAST
+
+/** The number of networking messages.
+ */
+#define NET_COUNT			(NET_LAST - NET_FIRST)
+
+/** Returns a value indicating whether the IPC call is a generic networking message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_FIRST, NET_LAST)
+
+/** Returns a value indicating whether the IPC call is an ARP message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_ARP_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_ARP_FIRST, NET_ARP_LAST)
+
+/** Returns a value indicating whether the IPC call is an Ethernet message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_ETH_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_ETH_FIRST, NET_ETH_LAST)
+
+/** Returns a value indicating whether the IPC call is an ICMP message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_ICMP_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_ICMP_FIRST, NET_ICMP_LAST)
+
+/** Returns a value indicating whether the IPC call is an inter-network layer message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_IL_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_IL_FIRST, NET_IL_LAST)
+
+/** Returns a value indicating whether the IPC call is an IP message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_IP_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_IP_FIRST, NET_IP_LAST)
+
+/** Returns a value indicating whether the IPC call is a generic networking message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_NET_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_NET_FIRST, NET_NET_LAST)
+
+/** Returns a value indicating whether the IPC call is a network interface layer message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_NIL_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_NIL_FIRST, NET_NIL_LAST)
+
+/** Returns a value indicating whether the IPC call is a packet manaagement system message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_PACKET_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_PACKET_FIRST, NET_PACKET_LAST)
+
+/** Returns a value indicating whether the IPC call is a socket message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_SOCKET_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_SOCKET_FIRST, NET_SOCKET_LAST)
+
+/** Returns a value indicating whether the IPC call is a TCP message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_TCP_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_TCP_FIRST, NET_TCP_LAST)
+
+/** Returns a value indicating whether the IPC call is a transport layer message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_TL_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_TL_FIRST, NET_TL_LAST)
+
+/** Returns a value indicating whether the IPC call is a UDP message.
+ *  @param[in] call The IPC call to be checked.
+ */
+#define IS_NET_UDP_MESSAGE(call) \
+	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_UDP_FIRST, NET_UDP_LAST)
+
+/*@}*/
+
+/** @name Networking specific message arguments definitions
+ */
+/*@{*/
+
+/** @name First arguments
+ */
+/*@{*/
+
+/** Returns the device identifier message argument.
+ *  @param[in] call The message call structure.
+ */
+#define IPC_GET_DEVICE(call) \
+	({device_id_t device_id = (device_id_t) IPC_GET_ARG1(*call); device_id;})
+
+/*@;})*/
+
+/** @name Second arguments
+ */
+/*@({*/
+
+/** Returns the packet identifier message argument.
+ *  @param[in] call The message call structure.
+ */
+#define IPC_GET_PACKET(call) \
+	({packet_id_t packet_id = (packet_id_t) IPC_GET_ARG2(*call); packet_id;})
+
+/** Returns the count message argument.
+ *  @param[in] call The message call structure.
+ */
+#define IPC_GET_COUNT(call) \
+	({size_t size = (size_t) IPC_GET_ARG2(*call); size;})
+
+/** Returns the device state message argument.
+ *  @param[in] call The message call structure.
+ */
+#define IPC_GET_STATE(call) \
+	({device_state_t device_state = (device_state_t) IPC_GET_ARG2(*call); device_state;})
+
+/** Returns the maximum transmission unit message argument.
+ *  @param[in] call The message call structure.
+ */
+#define IPC_GET_MTU(call) \
+	({size_t size = (size_t) IPC_GET_ARG2(*call); size;})
+
+/*@;})*/
+
+/** @name Third arguments
+ */
+/*@({*/
+
+/** Returns the device driver service message argument.
+ *  @param[in] call The message call structure.
+ */
+ #define IPC_GET_SERVICE(call) \
+	({services_t service = (services_t) IPC_GET_ARG3(*call); service;})
+
+/** Returns the target service message argument.
+ *  @param[in] call The message call structure.
+ */
+#define IPC_GET_TARGET(call) \
+	({services_t service = (services_t) IPC_GET_ARG3(*call); service;})
+
+/** Returns the sender service message argument.
+ *  @param[in] call The message call structure.
+ */
+#define IPC_GET_SENDER(call) \
+	({services_t service = (services_t) IPC_GET_ARG3(*call); service;})
+
+/*@;})*/
+
+/** @name Fourth arguments
+ */
+/*@({*/
+
+/** Returns the error service message argument.
+ *  @param[in] call The message call structure.
+ */
+#define IPC_GET_ERROR(call) \
+	({services_t service = (services_t) IPC_GET_ARG4(*call); service;})
+
+/*@;})*/
+
+/** @name Fifth arguments
+ */
+/*@({*/
+
+/** Returns the phone message argument.
+ *  @param[in] call The message call structure.
+ */
+#define IPC_GET_PHONE(call) \
+	({int phone = (int) IPC_GET_ARG5(*call); phone;})
+
+/*@}*/
+
+/** @name First answers
+ */
+/*@{*/
+
+/** Sets the device identifier in the message answer.
+ *  @param[out] answer The message answer structure.
+ */
+#define IPC_SET_DEVICE(answer, value) \
+	{ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG1(*answer, argument);}
+
+/** Sets the minimum address length in the message answer.
+ *  @param[out] answer The message answer structure.
+ */
+#define IPC_SET_ADDR(answer, value) \
+	{ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG1(*answer, argument);}
+
+/*@}*/
+
+/** @name Second answers
+ */
+/*@{*/
+
+/** Sets the minimum prefix size in the message answer.
+ *  @param[out] answer The message answer structure.
+ */
+#define IPC_SET_PREFIX(answer, value) \
+	{ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG2(*answer, argument);}
+
+/*@}*/
+
+/** @name Third answers
+ */
+/*@{*/
+
+/** Sets the maximum content size in the message answer.
+ *  @param[out] answer The message answer structure.
+ */
+#define IPC_SET_CONTENT(answer, value) \
+	{ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG3(*answer, argument);}
+
+/*@}*/
+
+/** @name Fourth answers
+ */
+/*@{*/
+
+/** Sets the minimum suffix size in the message answer.
+ *  @param[out] answer The message answer structure.
+ */
+#define IPC_SET_SUFFIX(answer, value) \
+	{ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG4(*answer, argument);}
+
+/*@}*/
+
+/*@}*/
+
+/** Notify the module about the device state change.
+ *
+ * @param[in] phone     The service module phone.
+ * @param[in] message   The service specific message.
+ * @param[in] device_id The device identifier.
+ * @param[in] state     The new device state.
+ * @param[in] target    The target module service.
+ *
+ * @return EOK on success.
+ *
+ */
+static inline int generic_device_state_msg_remote(int phone, int message,
+    device_id_t device_id, int state, services_t target)
+{
+	async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id,
+	    (ipcarg_t) state, target);
+	
+	return EOK;
+}
+
+/** Notify a module about the device.
+ *
+ * @param[in] phone     The service module phone.
+ * @param[in] message   The service specific message.
+ * @param[in] device_id The device identifier.
+ * @param[in] arg2      The second argument of the message.
+ * @param[in] service   The device module service.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for the specific service message.
+ *
+ */
+static inline int generic_device_req_remote(int phone, int message,
+    device_id_t device_id, int arg2, services_t service)
+{
+	return (int) async_req_3_0(phone, (ipcarg_t) message, (ipcarg_t) device_id,
+	    (ipcarg_t) arg2, (ipcarg_t) service);
+}
+
+/** Returns the address.
+ *  @param[in] phone The service module phone.
+ *  @param[in] message The service specific message.
+ *  @param[in] device_id The device identifier.
+ *  @param[out] address The desired address.
+ *  @param[out] data The address data container.
+ *  @returns EOK on success.
+ *  @returns EBADMEM if the address parameter and/or the data parameter is NULL.
+ *  @returns Other error codes as defined for the specific service message.
+ */
+static inline int generic_get_addr_req(int phone, int message, device_id_t device_id, measured_string_ref * address, char ** data){
+	aid_t message_id;
+	ipcarg_t result;
+	int string;
+
+	if(!(address && data)){
+		return EBADMEM;
+	}
+
+	// request the address
+	message_id = async_send_1(phone, (ipcarg_t) message, (ipcarg_t) device_id, NULL);
+	string = measured_strings_return(phone, address, data, 1);
+	async_wait_for(message_id, &result);
+
+	// if not successful
+	if((string == EOK) && (result != EOK)){
+		// clear the data
+		free(*address);
+		free(*data);
+	}
+	return (int) result;
+}
+
+/** Return the device packet dimension for sending.
+ *
+ * @param[in]  phone            The service module phone.
+ * @param[in]  message          The service specific message.
+ * @param[in]  device_id        The device identifier.
+ * @param[out] packet_dimension The packet dimension.
+ *
+ * @return EOK on success.
+ * @return EBADMEM if the packet_dimension parameter is NULL.
+ * @return Other error codes as defined for the specific service message.
+ *
+ */
+static inline int generic_packet_size_req_remote(int phone, int message,
+    device_id_t device_id, packet_dimension_ref packet_dimension)
+{
+	if (!packet_dimension)
+		return EBADMEM;
+	
+	ipcarg_t addr_len;
+	ipcarg_t prefix;
+	ipcarg_t content;
+	ipcarg_t suffix;
+	
+	ipcarg_t result = async_req_1_4(phone, (ipcarg_t) message,
+	    (ipcarg_t) device_id, &addr_len, &prefix, &content, &suffix);
+	
+	packet_dimension->prefix = (size_t) prefix;
+	packet_dimension->content = (size_t) content;
+	packet_dimension->suffix = (size_t) suffix;
+	packet_dimension->addr_len = (size_t) addr_len;
+	
+	return (int) result;
+}
+
+/** Pass the packet queue to the module.
+ *
+ * @param[in] phone     The service module phone.
+ * @param[in] message   The service specific message.
+ * @param[in] device_id The device identifier.
+ * @param[in] packet_id The received packet or the received packet queue
+ *                      identifier.
+ * @param[in] target    The target module service.
+ * @param[in] error     The error module service.
+ *
+ * @return EOK on success.
+ *
+ */
+static inline int generic_received_msg_remote(int phone, int message,
+    device_id_t device_id, packet_id_t packet_id, services_t target,
+    services_t error)
+{
+	if (error)
+		async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id,
+		    (ipcarg_t) packet_id, (ipcarg_t) target, (ipcarg_t) error);
+	else
+		async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id,
+		    (ipcarg_t) packet_id, (ipcarg_t) target);
+	
+	return EOK;
+}
+
+/** Send the packet queue.
+ *
+ * @param[in] phone     The service module phone.
+ * @param[in] message   The service specific message.
+ * @param[in] device_id The device identifier.
+ * @param[in] packet_id The packet or the packet queue identifier.
+ * @param[in] sender    The sending module service.
+ * @param[in] error     The error module service.
+ *
+ * @return EOK on success.
+ *
+ */
+static inline int generic_send_msg_remote(int phone, int message,
+    device_id_t device_id, packet_id_t packet_id, services_t sender,
+    services_t error)
+{
+	if (error)
+		async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id,
+		    (ipcarg_t) packet_id, (ipcarg_t) sender, (ipcarg_t) error);
+	else
+		async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id,
+		    (ipcarg_t) packet_id, (ipcarg_t) sender);
+	
+	return EOK;
+}
+
+/** Translates the given strings.
+ *  Allocates and returns the needed memory block as the data parameter.
+ *  @param[in] phone The service module phone.
+ *  @param[in] message The service specific message.
+ *  @param[in] device_id The device identifier.
+ *  @param[in] service The module service.
+ *  @param[in] configuration The key strings.
+ *  @param[in] count The number of configuration keys.
+ *  @param[out] translation The translated values.
+ *  @param[out] data The translation data container.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the configuration parameter is NULL.
+ *  @returns EINVAL if the count parameter is zero (0).
+ *  @returns EBADMEM if the translation or the data parameters are NULL.
+ *  @returns Other error codes as defined for the specific service message.
+ */
+static inline int generic_translate_req(int phone, int message, device_id_t device_id, services_t service, measured_string_ref configuration, size_t count, measured_string_ref * translation, char ** data){
+	aid_t message_id;
+	ipcarg_t result;
+	int string;
+
+	if(!(configuration && (count > 0))){
+		return EINVAL;
+	}
+	if(!(translation && data)){
+		return EBADMEM;
+	}
+
+	// request the translation
+	message_id = async_send_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) count, (ipcarg_t) service, NULL);
+	measured_strings_send(phone, configuration, count);
+	string = measured_strings_return(phone, translation, data, count);
+	async_wait_for(message_id, &result);
+
+	// if not successful
+	if((string == EOK) && (result != EOK)){
+		// clear the data
+		free(*translation);
+		free(*data);
+	}
+
+	return (int) result;
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/net_modules.h
===================================================================
--- uspace/lib/socket/include/net_modules.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/net_modules.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,125 @@
+/*
+ * 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
+ *  Generic module functions.
+ */
+
+#ifndef __NET_MODULES_H__
+#define __NET_MODULES_H__
+ 
+#include <async.h>
+
+#include <ipc/ipc.h>
+#include <ipc/services.h>
+
+#include <sys/time.h>
+
+/** Converts the data length between different types.
+ *	@param[in] type_from The source type.
+ *  @param[in] type_to The destination type.
+ *  @param[in] count The number units of the source type size.
+ */
+#define CONVERT_SIZE(type_from, type_to, count)	((sizeof(type_from) / sizeof(type_to)) * (count))
+
+/** Registers the module service at the name server.
+ *  @param[in] me The module service.
+ *  @param[out] phonehash The created phone hash.
+ */
+#define REGISTER_ME(me, phonehash)	ipc_connect_to_me(PHONE_NS, (me), 0, 0, (phonehash))
+
+/** Connect to the needed module function type definition.
+ *  @param[in] need The needed module service.
+ *  @returns The phone of the needed service.
+ */
+typedef int connect_module_t(services_t need);
+
+/** Answers the call.
+ *  @param[in] callid The call identifier.
+ *  @param[in] result The message processing result.
+ *  @param[in] answer The message processing answer.
+ *  @param[in] answer_count The number of answer parameters.
+ */
+extern void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count);
+
+extern int bind_service(services_t, ipcarg_t, ipcarg_t, ipcarg_t,
+    async_client_conn_t);
+extern int bind_service_timeout(services_t, ipcarg_t, ipcarg_t, ipcarg_t,
+    async_client_conn_t, suseconds_t);
+
+/** Connects to the needed module.
+ *  @param[in] need The needed module service.
+ *  @returns The phone of the needed service.
+ */
+extern int connect_to_service(services_t need);
+
+/** Connects to the needed module.
+ *  @param[in] need The needed module service.
+ *  @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0).
+ *  @returns The phone of the needed service.
+ *  @returns ETIMEOUT if the connection timeouted.
+ */
+extern int connect_to_service_timeout(services_t need, suseconds_t timeout);
+
+/** Receives data from the other party.
+ *  The received data buffer is allocated and returned.
+ *  @param[out] data The data buffer to be filled.
+ *  @param[out] length The buffer length.
+ *  @returns EOK on success.
+ *  @returns EBADMEM if the data or the length parameter is NULL.
+ *  @returns EINVAL if the client does not send data.
+ *  @returns ENOMEM if there is not enough memory left.
+ *  @returns Other error codes as defined for the async_data_write_finalize() function.
+ */
+extern int data_receive(void ** data, size_t * length);
+
+/** Replies the data to the other party.
+ *  @param[in] data The data buffer to be sent.
+ *  @param[in] data_length The buffer length.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the client does not expect the data.
+ *  @returns EOVERFLOW if the client does not expect all the data. Only partial data are transfered.
+ *  @returns Other error codes as defined for the async_data_read_finalize() function.
+ */
+extern int data_reply(void * data, size_t data_length);
+
+/** Refreshes answer structure and parameters count.
+ *  Erases all attributes.
+ *  @param[in,out] answer The message processing answer structure.
+ *  @param[in,out] answer_count The number of answer parameters.
+ */
+extern void refresh_answer(ipc_call_t * answer, int * answer_count);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/netdb.h
===================================================================
--- uspace/lib/socket/include/netdb.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/netdb.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -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/socket/include/packet/packet.h
===================================================================
--- uspace/lib/socket/include/packet/packet.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/packet/packet.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -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 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/packet/packet_client.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -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 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/packet/packet_header.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -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: uspace/lib/socket/include/packet/packet_messages.h
===================================================================
--- uspace/lib/socket/include/packet/packet_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/packet/packet_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,96 @@
+/*
+ * 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 <net_messages.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/packet/packet_server.h
===================================================================
--- uspace/lib/socket/include/packet/packet_server.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/packet/packet_server.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ *  The hosting module has to be compiled with both the packet.c and the packet_server.c source files.
+ *  To function correctly, initialization of the packet map by the pm_init() function has to happen at the first place.
+ *  Then the packet messages have to be processed by the packet_server_message() function.
+ *  The packet map should be released by the pm_destroy() function during the module termination.
+ *  @see IS_NET_PACKET_MESSAGE()
+ */
+
+#ifndef __NET_PACKET_SERVER_H__
+#define __NET_PACKET_SERVER_H__
+
+#include <ipc/ipc.h>
+
+/** Processes the packet server message.
+ *  @param[in] callid The message identifier.
+ *  @param[in] call The message parameters.
+ *  @param[out] answer The message answer parameters.
+ *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
+ *  @returns EOK on success.
+ *  @returns ENOMEM if there is not enough memory left.
+ *  @returns ENOENT if there is no such packet as in the packet message parameter..
+ *  @returns ENOTSUP if the message is not known.
+ *  @returns Other error codes as defined for the packet_release_wrapper() function.
+ */
+extern int packet_server_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/socket.h
===================================================================
--- uspace/lib/socket/include/socket.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/socket.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,214 @@
+/*
+ * 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 application program interface (API).
+ *  This is a part of the network application library.
+ *  Based on the BSD socket interface.
+ */
+
+#ifndef __NET_SOCKET_H__
+#define __NET_SOCKET_H__
+
+#include <net_byteorder.h>
+#include <in.h>
+#include <in6.h>
+#include <inet.h>
+#include <socket_codes.h>
+#include <socket_errno.h>
+
+/** @name Socket application programming interface
+ */
+/*@{*/
+
+/** Creates a new socket.
+ *  @param[in] domain The socket protocol family.
+ *  @param[in] type Socket type.
+ *  @param[in] protocol Socket protocol.
+ *  @returns The socket identifier on success.
+ *  @returns EPFNOTSUPPORT if the protocol family is not supported.
+ *  @returns ESOCKNOTSUPPORT if the socket type is not supported.
+ *  @returns EPROTONOSUPPORT if the protocol is not supported.
+ *  @returns ENOMEM if there is not enough memory left.
+ *  @returns ELIMIT if there was not a free socket identifier found this time.
+ *  @returns Other error codes as defined for the NET_SOCKET message.
+ *  @returns Other error codes as defined for the bind_service_timeout() function.
+ */
+extern int socket(int domain, int type, int protocol);
+
+/** Binds the socket to a port address.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[in] my_addr The port address.
+ *  @param[in] addrlen The address length.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns EBADMEM if the my_addr parameter is NULL.
+ *  @returns NO_DATA if the addlen parameter is zero (0).
+ *  @returns Other error codes as defined for the NET_SOCKET_BIND message.
+ */
+extern int bind(int socket_id, const struct sockaddr * my_addr, socklen_t addrlen);
+
+/** Sets the number of connections waiting to be accepted.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[in] backlog The maximum number of waiting sockets to be accepted.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the backlog parameter is not positive (<=0).
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns Other error codes as defined for the NET_SOCKET_LISTEN message.
+ */
+extern int listen(int socket_id, int backlog);
+
+/** Accepts waiting socket.
+ *  Blocks until such a socket exists.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[out] cliaddr The remote client address.
+ *  @param[in] addrlen The address length.
+ *  @returns EOK on success.
+ *  @returns EBADMEM if the cliaddr or addrlen parameter is NULL.
+ *  @returns EINVAL if the backlog parameter is not positive (<=0).
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns Other error codes as defined for the NET_SOCKET_ACCEPT message.
+ */
+extern int accept(int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen);
+
+/** Connects socket to the remote server.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[in] serv_addr The remote server address.
+ *  @param[in] addrlen The address length.
+ *  @returns EOK on success.
+ *  @returns EBADMEM if the serv_addr parameter is NULL.
+ *  @returns NO_DATA if the addlen parameter is zero (0).
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns Other error codes as defined for the NET_SOCKET_CONNECT message.
+ */
+extern int connect(int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen);
+
+/** Closes the socket.
+ *  @param[in] socket_id Socket identifier.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns EINPROGRESS if there is another blocking function in progress.
+ *  @returns Other error codes as defined for the NET_SOCKET_CLOSE message.
+ */
+extern int closesocket(int socket_id);
+
+/** Sends data via the socket.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[in] data The data to be sent.
+ *  @param[in] datalength The data length.
+ *  @param[in] flags Various send flags.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns EBADMEM if the data parameter is NULL.
+ *  @returns NO_DATA if the datalength parameter is zero (0).
+ *  @returns Other error codes as defined for the NET_SOCKET_SEND message.
+ */
+extern int send(int socket_id, void * data, size_t datalength, int flags);
+
+/** Sends data via the socket to the remote address.
+ *  Binds the socket to a free port if not already connected/bound.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[in] data The data to be sent.
+ *  @param[in] datalength The data length.
+ *  @param[in] flags Various send flags.
+ *  @param[in] toaddr The destination address.
+ *  @param[in] addrlen The address length.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns EBADMEM if the data or toaddr parameter is NULL.
+ *  @returns NO_DATA if the datalength or the addrlen parameter is zero (0).
+ *  @returns Other error codes as defined for the NET_SOCKET_SENDTO message.
+ */
+extern int sendto(int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen);
+
+/** Receives data via the socket.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[out] data The data buffer to be filled.
+ *  @param[in] datalength The data length.
+ *  @param[in] flags Various receive flags.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns EBADMEM if the data parameter is NULL.
+ *  @returns NO_DATA if the datalength parameter is zero (0).
+ *  @returns Other error codes as defined for the NET_SOCKET_RECV message.
+ */
+extern int recv(int socket_id, void * data, size_t datalength, int flags);
+
+/** Receives data via the socket.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[out] data The data buffer to be filled.
+ *  @param[in] datalength The data length.
+ *  @param[in] flags Various receive flags.
+ *  @param[out] fromaddr The source address.
+ *  @param[in,out] addrlen The address length. The maximum address length is read. The actual address length is set.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns EBADMEM if the data or fromaddr parameter is NULL.
+ *  @returns NO_DATA if the datalength or addrlen parameter is zero (0).
+ *  @returns Other error codes as defined for the NET_SOCKET_RECVFROM message.
+ */
+extern int recvfrom(int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen);
+
+/** Gets socket option.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[in] level The socket options level.
+ *  @param[in] optname The socket option to be get.
+ *  @param[out] value The value buffer to be filled.
+ *  @param[in,out] optlen The value buffer length. The maximum length is read. The actual length is set.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns EBADMEM if the value or optlen parameter is NULL.
+ *  @returns NO_DATA if the optlen parameter is zero (0).
+ *  @returns Other error codes as defined for the NET_SOCKET_GETSOCKOPT message.
+ */
+extern int getsockopt(int socket_id, int level, int optname, void * value, size_t * optlen);
+
+/** Sets socket option.
+ *  @param[in] socket_id Socket identifier.
+ *  @param[in] level The socket options level.
+ *  @param[in] optname The socket option to be set.
+ *  @param[in] value The value to be set.
+ *  @param[in] optlen The value length.
+ *  @returns EOK on success.
+ *  @returns ENOTSOCK if the socket is not found.
+ *  @returns EBADMEM if the value parameter is NULL.
+ *  @returns NO_DATA if the optlen parameter is zero (0).
+ *  @returns Other error codes as defined for the NET_SOCKET_SETSOCKOPT message.
+ */
+extern int setsockopt(int socket_id, int level, int optname, const void * value, size_t optlen);
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/socket_codes.h
===================================================================
--- uspace/lib/socket/include/socket_codes.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/socket_codes.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,460 @@
+/*
+ * 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 codes and definitions.
+ *  This is a part of the network application library.
+ */
+
+#ifndef __NET_SOCKET_CODES_H__
+#define __NET_SOCKET_CODES_H__
+
+#include <sys/types.h>
+
+/** @name Address families definitions
+ */
+/*@{*/
+
+/** Unspecified address family.
+ */
+#define AF_UNSPEC	0
+
+/** Unix domain sockets address family.
+ */
+#define AF_UNIXL	1
+
+/** POSIX name for AF_UNIX address family.
+ */
+#define AF_LOCAL	1
+
+/** Internet IP Protocol address family.
+ */
+#define AF_INET		2
+
+/** Amateur Radio AX.25 address family.
+ */
+#define AF_AX25		3
+
+/** Novell IPX address family.
+ */
+#define AF_IPX		4
+
+/** AppleTalk DDP address family.
+ */
+#define AF_APPLETALK	5
+
+/** Amateur Radio NET/ROM address family.
+ */
+#define AF_NETROM	6
+
+/** Multiprotocol bridge address family.
+ */
+#define AF_BRIDGE	7
+
+/** ATM PVCs address family.
+ */
+#define AF_ATMPVC	8
+
+/** Reserved for X.25 project address family.
+ */
+#define AF_X25		9
+
+/** IP version 6 address family.
+ */
+#define AF_INET6	10
+
+/** Amateur Radio X.25 PLP address family.
+ */
+#define AF_ROSE		11
+
+/** Reserved for DECnet project address family.
+ */
+#define AF_DECnet	12
+
+/** Reserved for 802.2LLC project address family.
+ */
+#define AF_NETBEUI	13
+
+/** Security callback pseudo AF address family.
+ */
+#define AF_SECURITY	14
+
+/** PF_KEY key management API address family.
+ */
+#define AF_KEY		15
+
+/** Alias to emulate 4.4BSD address family.
+ */
+#define AF_NETLINK	16
+
+/** Packet family address family.
+ */
+#define AF_PACKET	17
+
+/** Ash address family.
+ */
+#define AF_ASH		18
+
+/** Acorn Econet address family.
+ */
+#define AF_ECONET	19
+
+/** ATM SVCs address family.
+ */
+#define AF_ATMSVC	20
+
+/** Linux SNA Project (nutters!) address family.
+ */
+#define AF_SNA		22
+
+/** IRDA sockets address family.
+ */
+#define AF_IRDA		23
+
+/** PPPoX sockets address family.
+ */
+#define AF_PPPOX	24
+
+/** Wanpipe API Sockets address family.
+ */
+#define AF_WANPIPE	25
+
+/** Linux LLC address family.
+ */
+#define AF_LLC		26
+
+/** Controller Area Network address family.
+ */
+#define AF_CAN		29
+
+/** TIPC sockets address family.
+ */
+#define AF_TIPC		30
+
+/** Bluetooth sockets address family.
+ */
+#define AF_BLUETOOTH	31
+
+/** IUCV sockets address family.
+ */
+#define AF_IUCV		32
+
+/** RxRPC sockets address family.
+ */
+#define AF_RXRPC	33
+
+/** Maximum address family.
+ */
+#define AF_MAX		34
+
+/*@}*/
+
+/** @name Protocol families definitions
+ *  Same as address families.
+ */
+/*@{*/
+
+/** Unspecified protocol family.
+ */
+#define PF_UNSPEC	AF_UNSPEC
+
+/** Unix domain sockets protocol family.
+ */
+#define PF_UNIXL	AF_UNIXL
+
+/** POSIX name for AF_UNIX protocol family.
+ */
+#define PF_LOCAL	AF_LOCAL
+
+/** Internet IP Protocol protocol family.
+ */
+#define PF_INET		AF_INET
+
+/** Amateur Radio AX.25 protocol family.
+ */
+#define PF_AX25		AF_AX25
+
+/** Novell IPX protocol family.
+ */
+#define PF_IPX		AF_IPX
+
+/** AppleTalk DDP protocol family.
+ */
+#define PF_APPLETALK	AF_APPLETALK
+
+/** Amateur Radio NET/ROM protocol family.
+ */
+#define PF_NETROM	AF_NETROM
+
+/** Multiprotocol bridge protocol family.
+ */
+#define PF_BRIDGE	AF_BRIDGE
+
+/** ATM PVCs protocol family.
+ */
+#define PF_ATMPVC	AF_ATMPVC
+
+/** Reserved for X.25 project protocol family.
+ */
+#define PF_X25		AF_X25
+
+/** IP version 6 protocol family.
+ */
+#define PF_INET6	AF_INET6
+
+/** Amateur Radio X.25 PLP protocol family.
+ */
+#define PF_ROSE		AF_ROSE
+
+/** Reserved for DECnet project protocol family.
+ */
+#define PF_DECnet	AF_DECnet
+
+/** Reserved for 802.2LLC project protocol family.
+ */
+#define PF_NETBEUI	AF_NETBEUI
+
+/** Security callback pseudo AF protocol family.
+ */
+#define PF_SECURITY	AF_SECURITY
+
+/** PF_KEY key management API protocol family.
+ */
+#define PF_KEY		AF_KEY
+
+/** Alias to emulate 4.4BSD protocol family.
+ */
+#define PF_NETLINK	AF_NETLINK
+
+/** Packet family protocol family.
+ */
+#define PF_PACKET	AF_PACKET
+
+/** Ash protocol family.
+ */
+#define PF_ASH		AF_ASH
+
+/** Acorn Econet protocol family.
+ */
+#define PF_ECONET	AF_ECONET
+
+/** ATM SVCs protocol family.
+ */
+#define PF_ATMSVC	AF_ATMSVC
+
+/** Linux SNA Project (nutters!) protocol family.
+ */
+#define PF_SNA		AF_SNA
+
+/** IRDA sockets protocol family.
+ */
+#define PF_IRDA		AF_IRDA
+
+/** PPPoX sockets protocol family.
+ */
+#define PF_PPPOX	AF_PPPOX
+
+/** Wanpipe API Sockets protocol family.
+ */
+#define PF_WANPIPE	AF_WANPIPE
+
+/** Linux LLC protocol family.
+ */
+#define PF_LLC		AF_LLC
+
+/** Controller Area Network protocol family.
+ */
+#define PF_CAN		AF_CAN
+
+/** TIPC sockets protocol family.
+ */
+#define PF_TIPC		AF_TIPC
+
+/** Bluetooth sockets protocol family.
+ */
+#define PF_BLUETOOTH	AF_BLUETOOTH
+
+/** IUCV sockets protocol family.
+ */
+#define PF_IUCV		AF_IUCV
+
+/** RxRPC sockets protocol family.
+ */
+#define PF_RXRPC	AF_RXRPC
+
+/** Maximum protocol family.
+ */
+#define PF_MAX		AF_MAX
+
+/*@}*/
+
+/** @name Socket option levels definitions
+ *  Thanks to BSD these must match IPPROTO_xxx
+ */
+/*@{*/
+
+/** IP socket option level.
+ */
+#define SOL_IP		0
+
+/** ICMP socket option level.
+ */
+#define SOL_ICMP	1
+
+/** TCP socket option level.
+ */
+#define SOL_TCP		6
+
+/** UDP socket option level.
+ */
+#define SOL_UDP		17
+
+/** IPV socket option level.
+ */
+#define SOL_IPV6	41
+
+/** ICMPV socket option level.
+ */
+#define SOL_ICMPV6	58
+
+/** SCTP socket option level.
+ */
+#define SOL_SCTP	132
+
+/** UDP-Lite (RFC 3828) socket option level.
+ */
+#define SOL_UDPLITE	136
+
+/** RAW socket option level.
+ */
+#define SOL_RAW		255
+
+/** IPX socket option level.
+ */
+#define SOL_IPX		256
+
+/** AX socket option level.
+ */
+#define SOL_AX25	257
+
+/** ATALK socket option level.
+ */
+#define SOL_ATALK	258
+
+/** NETROM socket option level.
+ */
+#define SOL_NETROM	259
+
+/** ROSE socket option level.
+ */
+#define SOL_ROSE	260
+
+/** DECNET socket option level.
+ */
+#define SOL_DECNET	261
+
+/** X25 socket option level.
+ */
+#define	SOL_X25		262
+
+/** PACKET socket option level.
+ */
+#define SOL_PACKET	263
+
+/** ATM layer (cell level) socket option level.
+ */
+#define SOL_ATM		264
+
+/** ATM Adaption Layer (packet level) socket option level.
+ */
+#define SOL_AAL		265
+
+/** IRDA socket option level.
+ */
+#define SOL_IRDA	266
+
+/** NETBEUI socket option level.
+ */
+#define SOL_NETBEUI	267
+
+/** LLC socket option level.
+ */
+#define SOL_LLC		268
+
+/** DCCP socket option level.
+ */
+#define SOL_DCCP	269
+
+/** NETLINK socket option level.
+ */
+#define SOL_NETLINK	270
+
+/** TIPC socket option level.
+ */
+#define SOL_TIPC	271
+
+/** RXRPC socket option level.
+ */
+#define SOL_RXRPC	272
+
+/** PPPOL socket option level.
+ */
+#define SOL_PPPOL2TP	273
+
+/** BLUETOOTH socket option level.
+ */
+#define SOL_BLUETOOTH	274
+
+/*@}*/
+
+/** Socket types.
+ */
+typedef enum sock_type{
+	/** Stream (connection oriented) socket.
+	 */
+	SOCK_STREAM = 1,
+	/** Datagram (connectionless oriented) socket.
+	 */
+	SOCK_DGRAM = 2,
+	/** Raw socket.
+	 */
+	SOCK_RAW = 3
+} sock_type_t;
+
+/** Type definition of the socket length.
+ */
+typedef int32_t	socklen_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/socket_core.h
===================================================================
--- uspace/lib/socket/include/socket_core.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/socket_core.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -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 <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/include/socket_errno.h
===================================================================
--- uspace/lib/socket/include/socket_errno.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/socket_errno.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,136 @@
+/*
+ * 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
+ *  Socket error codes.
+ *  Based on BSD.
+ */
+
+#ifndef __NET_SOCKET_ERR_H__
+#define __NET_SOCKET_ERR_H__
+
+#include <errno.h>
+
+/** @name Socket error codes definitions
+ */
+/*@{*/
+
+////#define EINTR			(-10004)
+////#define EBADF			(-10009)
+//#define EACCES			(-10013)
+//#define EFAULT			(-10014)
+////#define EINVAL			(-10022)
+////#define EMFILE			(-10024)
+//#define EWOULDBLOCK		(-10035)
+
+/** An API function is called while another blocking function is in progress.
+ */
+#define EINPROGRESS		(-10036)
+
+//#define EALREADY		(-10037)
+
+/** The socket identifier is not valid.
+ */
+#define ENOTSOCK		(-10038)
+
+/** The destination address required.
+ */
+#define EDESTADDRREQ	(-10039)
+
+//#define EMSGSIZE		(-10040)
+//#define EPROTOTYPE		(-10041)
+//#define ENOPROTOOPT		(-10042)
+
+/** Protocol is not supported.
+ */
+#define EPROTONOSUPPORT	(-10043)
+
+/** Socket type is not supported.
+ */
+#define ESOCKTNOSUPPORT	(-10044)
+
+//#define EOPNOTSUPP		(-10045)
+
+/** Protocol family is not supported.
+ */
+#define EPFNOSUPPORT	(-10046)
+
+/** Address family is not supported.
+ */
+#define EAFNOSUPPORT	(-10047)
+
+/** Address is already in use.
+ */
+#define EADDRINUSE		(-10048)
+
+//#define EADDRNOTAVAIL	(-10049)
+/* May be reported at any time if the implementation detects an underlying failure.
+ */
+//#define ENETDOWN		(-10050)
+//#define ENETUNREACH		(-10051)
+//#define ENETRESET		(-10052)
+//#define ECONNABORTED	(-10053)
+//#define ECONNRESET		(-10054)
+//#define ENOBUFS			(-10055)
+//#define EISCONN			(-10056)
+
+/** The socket is not connected or bound.
+ */
+#define ENOTCONN		(-10057)
+
+//#define ESHUTDOWN		(-10058)
+//#define ETOOMANYREFS	(-10059)
+//#define ETIMEDOUT		(-10060)
+//#define ECONNREFUSED	(-10061)
+//#define ELOOP			(-10062)
+////#define ENAMETOOLONG	(-10063)
+//#define EHOSTDOWN		(-10064)
+//#define EHOSTUNREACH	(-10065)
+//#define HOST_NOT_FOUND	(-11001)
+
+/** The requested operation was not performed.
+ *  Try again later.
+ */
+#define TRY_AGAIN		(-11002)
+
+//#define NO_RECOVERY		(-11003)
+
+/** No data.
+ */
+#define NO_DATA			(-11004)
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/socket_messages.h
===================================================================
--- uspace/lib/socket/include/socket_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/socket_messages.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,215 @@
+/*
+ * 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 messages.
+ *  @see socket.h
+ */
+
+
+#ifndef __NET_SOCKET_MESSAGES_H__
+#define __NET_SOCKET_MESSAGES_H__
+
+#include <ipc/ipc.h>
+
+#include <net_messages.h>
+#include <socket_codes.h>
+
+/** Socket client messages.
+ */
+typedef enum{
+	/** Creates a new socket.
+	 *  @see socket()
+	 */
+	NET_SOCKET = NET_SOCKET_FIRST,
+	/** Binds the socket.
+	 *  @see bind()
+	 */
+	NET_SOCKET_BIND,
+	/** Creates a new socket.
+	 *  @see socket()
+	 */
+	NET_SOCKET_LISTEN,
+	/** Accepts an incomming connection.
+	 *  @see accept()
+	 */
+	NET_SOCKET_ACCEPT,
+	/** Connects the socket.
+	 *  @see connect()
+	 */
+	NET_SOCKET_CONNECT,
+	/** Closes the socket.
+	 *  @see closesocket()
+	 */
+	NET_SOCKET_CLOSE,
+	/** Sends data via the stream socket.
+	 *  @see send()
+	 */
+	NET_SOCKET_SEND,
+	/** Sends data via the datagram socket.
+	 *  @see sendto()
+	 */
+	NET_SOCKET_SENDTO,
+	/** Receives data from the stream socket.
+	 *  @see socket()
+	 */
+	NET_SOCKET_RECV,
+	/** Receives data from the datagram socket.
+	 *  @see socket()
+	 */
+	NET_SOCKET_RECVFROM,
+	/** Gets the socket option.
+	 *  @see getsockopt()
+	 */
+	NET_SOCKET_GETSOCKOPT,
+	/** Sets the socket option.
+	 *  @see setsockopt()
+	 */
+	NET_SOCKET_SETSOCKOPT,
+	/** New socket for acceptence notification message.
+	 */
+	NET_SOCKET_ACCEPTED,
+	/** New data received notification message.
+	 */
+	NET_SOCKET_RECEIVED,
+	/** New socket data fragment size notification message.
+	 */
+	NET_SOCKET_DATA_FRAGMENT_SIZE
+} socket_messages;
+
+/** @name Socket specific message parameters definitions
+ */
+/*@{*/
+
+/** Sets the socket identifier in the message answer.
+ *  @param[out] answer The message answer structure.
+ */
+#define SOCKET_SET_SOCKET_ID(answer, value) \
+	{ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG1(answer, argument);}
+
+/** Returns the socket identifier message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define SOCKET_GET_SOCKET_ID(call) \
+	({int socket_id = (int) IPC_GET_ARG1(call); socket_id;})
+
+/** Sets the read data length in the message answer.
+ *  @param[out] answer The message answer structure.
+ */
+#define SOCKET_SET_READ_DATA_LENGTH(answer, value) \
+	{ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG1(answer, argument);}
+
+/** Returns the read data length message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define SOCKET_GET_READ_DATA_LENGTH(call) \
+	({int data_length = (int) IPC_GET_ARG1(call); data_length;})
+
+/** Returns the backlog message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define SOCKET_GET_BACKLOG(call) \
+	({int backlog = (int) IPC_GET_ARG2(call); backlog;})
+
+/** Returns the option level message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define SOCKET_GET_OPT_LEVEL(call) \
+	({int opt_level = (int) IPC_GET_ARG2(call); opt_level;})
+
+/** Returns the data fragment size message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define SOCKET_GET_DATA_FRAGMENT_SIZE(call) \
+	({size_t size = (size_t) IPC_GET_ARG2(call); size;})
+
+/** Sets the data fragment size in the message answer.
+ *  @param[out] answer The message answer structure.
+ */
+#define SOCKET_SET_DATA_FRAGMENT_SIZE(answer, value) \
+	{ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG2(answer, argument);}
+
+/** Sets the address length in the message answer.
+ *  @param[out] answer The message answer structure.
+ */
+#define SOCKET_SET_ADDRESS_LENGTH(answer, value) \
+	{ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG3(answer, argument);}
+
+/** Returns the address length message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define SOCKET_GET_ADDRESS_LENGTH(call) \
+	({socklen_t address_length = (socklen_t) IPC_GET_ARG3(call); address_length;})
+
+/** Sets the header size in the message answer.
+ *  @param[out] answer The message answer structure.
+ */
+#define SOCKET_SET_HEADER_SIZE(answer, value) \
+	\
+	{ipcarg_t argument = (ipcarg_t) (value); IPC_SET_ARG3(answer, argument);}
+
+/** Returns the header size message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define SOCKET_GET_HEADER_SIZE(call) \
+	({size_t size = (size_t) IPC_GET_ARG3(call); size;})
+
+/** Returns the flags message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define SOCKET_GET_FLAGS(call) \
+	({int flags = (int) IPC_GET_ARG4(call); flags;})
+
+/** Returns the option name message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define SOCKET_GET_OPT_NAME(call) \
+	({int opt_name = (int) IPC_GET_ARG4(call); opt_name;})
+
+/** Returns the data fragments message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define SOCKET_GET_DATA_FRAGMENTS(call) \
+	({int fragments = (int) IPC_GET_ARG5(call); fragments;})
+
+/** Returns the new socket identifier message parameter.
+ *  @param[in] call The message call structure.
+ */
+#define SOCKET_GET_NEW_SOCKET_ID(call) \
+	({int socket_id = (int) IPC_GET_ARG5(call); socket_id;})
+
+/*@}*/
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/socket/include/socket_parse.h
===================================================================
--- uspace/lib/socket/include/socket_parse.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/socket_parse.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,42 @@
+/*
+ * 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
+ * Command-line argument parsing functions related to networking.
+ */
+
+extern int socket_parse_address_family(const char *, int *);
+extern int socket_parse_protocol_family(const char *, int *);
+extern int socket_parse_socket_type(const char *, int *);
+
+/** @}
+ */
Index: uspace/lib/socket/include/tcp_codes.h
===================================================================
--- uspace/lib/socket/include/tcp_codes.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/include/tcp_codes.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -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/lib/socket/packet/packet.c
===================================================================
--- uspace/lib/socket/packet/packet.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/packet/packet.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -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 <errno.h>
+#include <malloc.h>
+#include <mem.h>
+#include <fibril_synch.h>
+#include <unistd.h>
+
+#include <sys/mman.h>
+
+#include <net_err.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 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/packet/packet_client.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,186 @@
+/*
+ * 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;
+	uint8_t * dest;
+	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 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/lib/socket/packet/packet_server.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,342 @@
+/*
+ * 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 implementation.
+ */
+
+#include <align.h>
+#include <assert.h>
+#include <async.h>
+#include <errno.h>
+#include <fibril_synch.h>
+#include <unistd.h>
+
+#include <ipc/ipc.h>
+#include <sys/mman.h>
+
+#include <net_err.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>
+
+#define FREE_QUEUES_COUNT	7
+
+/** The default address length reserved for new packets.
+ */
+#define DEFAULT_ADDR_LEN	32
+
+/** The default prefix reserved for new packets.
+ */
+#define DEFAULT_PREFIX		64
+
+/** The default suffix reserved for new packets.
+ */
+#define DEFAULT_SUFFIX		64
+
+/** Packet server global data.
+ */
+static struct{
+	/** Safety lock.
+	 */
+	fibril_mutex_t lock;
+	/** Free packet queues.
+	 */
+	packet_t free[FREE_QUEUES_COUNT];
+	/** Packet length upper bounds of the free packet queues.
+	 *  The maximal lengths of packets in each queue in the ascending order.
+	 *  The last queue is not limited.
+	 */
+	size_t sizes[FREE_QUEUES_COUNT];
+	/** Total packets allocated.
+	 */
+	unsigned int count;
+} ps_globals = {
+	.lock = {
+		.counter = 1,
+		.waiters = {
+			.prev = &ps_globals.lock.waiters,
+			.next = &ps_globals.lock.waiters,
+		}
+	},
+	.free = {NULL, NULL, NULL, NULL, NULL, NULL, NULL},
+	.sizes = {PAGE_SIZE, PAGE_SIZE * 2, PAGE_SIZE * 4, PAGE_SIZE * 8, PAGE_SIZE * 16, PAGE_SIZE * 32, PAGE_SIZE * 64},
+	.count = 0
+};
+
+int packet_translate_local(int phone, packet_ref packet, packet_id_t packet_id)
+{
+	if (!packet)
+		return EINVAL;
+	
+	*packet = pm_find(packet_id);
+	return (*packet) ? EOK : ENOENT;
+}
+
+/** Clears and initializes the packet according to the given dimensions.
+ *  @param[in] packet The packet to be initialized.
+ *  @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.
+ */
+static void packet_init(packet_t packet, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix){
+	// clear the packet content
+	bzero(((void *) packet) + sizeof(struct packet), packet->length - sizeof(struct packet));
+	// clear the packet header
+	packet->order = 0;
+	packet->metric = 0;
+	packet->previous = 0;
+	packet->next = 0;
+	packet->addr_len = 0;
+	packet->src_addr = sizeof(struct packet);
+	packet->dest_addr = packet->src_addr + addr_len;
+	packet->max_prefix = max_prefix;
+	packet->max_content = max_content;
+	packet->data_start = packet->dest_addr + addr_len + packet->max_prefix;
+	packet->data_end = packet->data_start;
+}
+
+/** Creates a&nbsp;new packet of dimensions at least as given.
+ *  Should be used only when the global data are locked.
+ *  @param[in] length The total length of the packet, including the header, the addresses and the data of the packet.
+ *  @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 of dimensions at least as given.
+ *  @returns NULL if there is not enough memory left.
+ */
+static packet_t packet_create(size_t length, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix){
+	ERROR_DECLARE;
+
+	packet_t packet;
+
+	// already locked
+	packet = (packet_t) mmap(NULL, length, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
+	if(packet == MAP_FAILED){
+		return NULL;
+	}
+	++ ps_globals.count;
+	packet->packet_id = ps_globals.count;
+	packet->length = length;
+	packet_init(packet, addr_len, max_prefix, max_content, max_suffix);
+	packet->magic_value = PACKET_MAGIC_VALUE;
+	if(ERROR_OCCURRED(pm_add(packet))){
+		munmap(packet, packet->length);
+		return NULL;
+	}
+	return packet;
+}
+
+/** Return the packet of dimensions at least as given.
+ *
+ * Try to reuse free packets first.
+ * Create a new packet aligned to the memory page size if none available.
+ * Lock the global data during its processing.
+ *
+ * @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.
+ *
+ * @return The packet of dimensions at least as given.
+ * @return NULL if there is not enough memory left.
+ *
+ */
+static packet_t packet_get_local(size_t addr_len, size_t max_prefix,
+    size_t max_content, size_t max_suffix)
+{
+	size_t length = ALIGN_UP(sizeof(struct packet) + 2 * addr_len + max_prefix
+	    + max_content + max_suffix, PAGE_SIZE);
+	
+	fibril_mutex_lock(&ps_globals.lock);
+	
+	packet_t packet;
+	unsigned int index;
+	
+	for (index = 0; index < FREE_QUEUES_COUNT - 1; index++) {
+		if (length <= ps_globals.sizes[index]) {
+			packet = ps_globals.free[index];
+			
+			while (packet_is_valid(packet) && (packet->length < length))
+				packet = pm_find(packet->next);
+			
+			if (packet_is_valid(packet)) {
+				if (packet == ps_globals.free[index])
+					ps_globals.free[index] = pq_detach(packet);
+				else
+					pq_detach(packet);
+				
+				packet_init(packet, addr_len, max_prefix, max_content,
+				    max_suffix);
+				fibril_mutex_unlock(&ps_globals.lock);
+				
+				return packet;
+			}
+		}
+	}
+	
+	packet = packet_create(length, addr_len, max_prefix, max_content,
+	    max_suffix);
+	
+	fibril_mutex_unlock(&ps_globals.lock);
+	
+	return packet;
+}
+
+packet_t packet_get_4_local(int phone, size_t max_content, size_t addr_len,
+    size_t max_prefix, size_t max_suffix)
+{
+	return packet_get_local(addr_len, max_prefix, max_content, max_suffix);
+}
+
+packet_t packet_get_1_local(int phone, size_t content)
+{
+	return packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content,
+	    DEFAULT_SUFFIX);
+}
+
+/** Release the packet and returns it to the appropriate free packet queue.
+ *
+ *  Should be used only when the global data are locked.
+ *
+ *  @param[in] packet The packet to be released.
+ *
+ */
+static void packet_release(packet_t packet){
+	int index;
+	int result;
+
+	// remove debug dump
+//	printf("packet %d released\n", packet->packet_id);
+	for(index = 0; (index < FREE_QUEUES_COUNT - 1) && (packet->length > ps_globals.sizes[index]); ++ index);
+	result = pq_add(&ps_globals.free[index], packet, packet->length, packet->length);
+	assert(result == EOK);
+}
+
+/** Releases the packet queue.
+ *  @param[in] packet_id The first packet identifier.
+ *  @returns EOK on success.
+ *  @returns ENOENT if there is no such packet.
+ */
+static int packet_release_wrapper(packet_id_t packet_id){
+	packet_t packet;
+
+	packet = pm_find(packet_id);
+	if(! packet_is_valid(packet)){
+		return ENOENT;
+	}
+	fibril_mutex_lock(&ps_globals.lock);
+	pq_destroy(packet, packet_release);
+	fibril_mutex_unlock(&ps_globals.lock);
+	return EOK;
+}
+
+void pq_release_local(int phone, packet_id_t packet_id)
+{
+	(void) packet_release_wrapper(packet_id);
+}
+
+/** Shares the packet memory block.
+ *  @param[in] packet The packet to be shared.
+ *  @returns EOK on success.
+ *  @returns EINVAL if the packet is not valid.
+ *  @returns EINVAL if the calling module does not accept the memory.
+ *  @returns ENOMEM if the desired and actual sizes differ.
+ *  @returns Other error codes as defined for the async_share_in_finalize() function.
+ */
+static int packet_reply(const packet_t packet){
+	ipc_callid_t callid;
+	size_t size;
+
+	if(! packet_is_valid(packet)){
+		return EINVAL;
+	}
+	if(async_share_in_receive(&callid, &size) <= 0) return EINVAL;
+	if(size != packet->length){
+		return ENOMEM;
+	}
+	return async_share_in_finalize(callid, packet, PROTO_READ | PROTO_WRITE);
+}
+
+int packet_server_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+	packet_t packet;
+
+	*answer_count = 0;
+	switch(IPC_GET_METHOD(*call)){
+		case IPC_M_PHONE_HUNGUP:
+			return EOK;
+		case NET_PACKET_CREATE_1:
+			packet = packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, IPC_GET_CONTENT(call), DEFAULT_SUFFIX);
+			if(! packet){
+				return ENOMEM;
+			}
+			*answer_count = 2;
+			IPC_SET_ARG1(*answer, (ipcarg_t) packet->packet_id);
+			IPC_SET_ARG2(*answer, (ipcarg_t) packet->length);
+			return EOK;
+		case NET_PACKET_CREATE_4:
+			packet = packet_get_local(((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(call)) ? IPC_GET_ADDR_LEN(call) : DEFAULT_ADDR_LEN), DEFAULT_PREFIX + IPC_GET_PREFIX(call), IPC_GET_CONTENT(call), DEFAULT_SUFFIX + IPC_GET_SUFFIX(call));
+			if(! packet){
+				return ENOMEM;
+			}
+			*answer_count = 2;
+			IPC_SET_ARG1(*answer, (ipcarg_t) packet->packet_id);
+			IPC_SET_ARG2(*answer, (ipcarg_t) packet->length);
+			return EOK;
+		case NET_PACKET_GET:
+			packet = pm_find(IPC_GET_ID(call));
+			if(! packet_is_valid(packet)){
+				return ENOENT;
+			}
+			return packet_reply(packet);
+		case NET_PACKET_GET_SIZE:
+			packet = pm_find(IPC_GET_ID(call));
+			if(! packet_is_valid(packet)){
+				return ENOENT;
+			}
+			IPC_SET_ARG1(*answer, (ipcarg_t) packet->length);
+			*answer_count = 1;
+			return EOK;
+		case NET_PACKET_RELEASE:
+			return packet_release_wrapper(IPC_GET_ID(call));
+	}
+	return ENOTSUP;
+}
+
+/** @}
+ */
Index: uspace/srv/bd/rd/rd.c
===================================================================
--- uspace/srv/bd/rd/rd.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/bd/rd/rd.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -32,9 +32,9 @@
 /** @addtogroup rd
  * @{
- */ 
+ */
 
 /**
- * @file	rd.c
- * @brief	Initial RAM disk for HelenOS.
+ * @file rd.c
+ * @brief Initial RAM disk for HelenOS.
  */
 
@@ -61,4 +61,5 @@
 /** Pointer to the ramdisk's image */
 static void *rd_addr;
+
 /** Size of the ramdisk */
 static size_t rd_size;
@@ -70,16 +71,17 @@
 static int rd_write_blocks(uint64_t ba, size_t cnt, const void *buf);
 
-/**
- * This rwlock protects the ramdisk's data.
+/** This rwlock protects the ramdisk's data.
+ *
  * If we were to serve multiple requests (read + write or several writes)
- * concurrently (i.e. from two or more threads), each read and write needs to be
- * protected by this rwlock.
- */ 
+ * concurrently (i.e. from two or more threads), each read and write needs to
+ * be protected by this rwlock.
+ *
+ */
 fibril_rwlock_t rd_lock;
 
 /** Handle one connection to ramdisk.
  *
- * @param iid		Hash of the request that opened the connection.
- * @param icall		Call data of the request that opened the connection.
+ * @param iid   Hash of the request that opened the connection.
+ * @param icall Call data of the request that opened the connection.
  */
 static void rd_connection(ipc_callid_t iid, ipc_call_t *icall)
@@ -92,10 +94,10 @@
 	size_t cnt;
 	size_t comm_size;
-
+	
 	/*
 	 * Answer the first IPC_M_CONNECT_ME_TO call.
 	 */
 	ipc_answer_0(iid, EOK);
-
+	
 	/*
 	 * Now we wait for the client to send us its communication as_area.
@@ -108,5 +110,5 @@
 		} else {
 			ipc_answer_0(callid, EHANGUP);
-			return;		
+			return;
 		}
 	} else {
@@ -178,9 +180,9 @@
 		return ELIMIT;
 	}
-
+	
 	fibril_rwlock_read_lock(&rd_lock);
 	memcpy(buf, rd_addr + ba * block_size, block_size * cnt);
 	fibril_rwlock_read_unlock(&rd_lock);
-
+	
 	return EOK;
 }
@@ -193,9 +195,9 @@
 		return ELIMIT;
 	}
-
+	
 	fibril_rwlock_write_lock(&rd_lock);
 	memcpy(rd_addr + ba * block_size, buf, block_size * cnt);
 	fibril_rwlock_write_unlock(&rd_lock);
-
+	
 	return EOK;
 }
@@ -204,9 +206,14 @@
 static bool rd_init(void)
 {
-	rd_size = sysinfo_value("rd.size");
-	void *rd_ph_addr = (void *) sysinfo_value("rd.address.physical");
-	
-	if (rd_size == 0) {
-		printf(NAME ": No RAM disk found\n");
+	int ret = sysinfo_get_value("rd.size", &rd_size);
+	if ((ret != EOK) || (rd_size == 0)) {
+		printf("%s: No RAM disk found\n", NAME);
+		return false;
+	}
+	
+	sysarg_t rd_ph_addr;
+	ret = sysinfo_get_value("rd.address.physical", &rd_ph_addr);
+	if ((ret != EOK) || (rd_ph_addr == 0)) {
+		printf("%s: Invalid RAM disk physical address\n", NAME);
 		return false;
 	}
@@ -215,17 +222,17 @@
 	
 	int flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE;
-	int retval = physmem_map(rd_ph_addr, rd_addr,
+	int retval = physmem_map((void *) rd_ph_addr, rd_addr,
 	    ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
 	
 	if (retval < 0) {
-		printf(NAME ": Error mapping RAM disk\n");
-		return false;
-	}
-	
-	printf(NAME ": Found RAM disk at %p, %d bytes\n", rd_ph_addr, rd_size);
+		printf("%s: Error mapping RAM disk\n", NAME);
+		return false;
+	}
+	
+	printf("%s: Found RAM disk at %p, %d bytes\n", NAME, rd_ph_addr, rd_size);
 	
 	int rc = devmap_driver_register(NAME, rd_connection);
 	if (rc < 0) {
-		printf(NAME ": Unable to register driver (%d)\n", rc);
+		printf("%s: Unable to register driver (%d)\n", NAME, rc);
 		return false;
 	}
@@ -234,5 +241,5 @@
 	if (devmap_device_register("bd/initrd", &dev_handle) != EOK) {
 		devmap_hangup_phone(DEVMAP_DRIVER);
-		printf(NAME ": Unable to register device\n");
+		printf("%s: Unable to register device\n", NAME);
 		return false;
 	}
@@ -245,10 +252,10 @@
 int main(int argc, char **argv)
 {
-	printf(NAME ": HelenOS RAM disk server\n");
+	printf("%s: HelenOS RAM disk server\n", NAME);
 	
 	if (!rd_init())
 		return -1;
 	
-	printf(NAME ": Accepting connections\n");
+	printf("%s: Accepting connections\n", NAME);
 	async_manager();
 
Index: uspace/srv/devmap/devmap.c
===================================================================
--- uspace/srv/devmap/devmap.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/devmap/devmap.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -172,5 +172,11 @@
 		
 		*name = str_dup(fqdn);
-		if ((*name == NULL) || (str_cmp(*name, "") == 0)) {
+		if (*name == NULL) {
+			free(*ns_name);
+			return false;
+		}
+		
+		if (str_cmp(*name, "") == 0) {
+			free(*name);
 			free(*ns_name);
 			return false;
@@ -186,9 +192,15 @@
 	
 	*name = str_dup(fqdn + slash_after);
-	if ((*name == NULL) || (str_cmp(*name, "") == 0)) {
+	if (*name == NULL) {
 		free(*ns_name);
 		return false;
 	}
 	
+	if (str_cmp(*name, "") == 0) {
+		free(*name);
+		free(*ns_name);
+		return false;
+	}
+	
 	return true;
 }
@@ -202,11 +214,10 @@
 static devmap_namespace_t *devmap_namespace_find_name(const char *name)
 {
-	link_t *item = namespaces_list.next;
-	
-	while (item != &namespaces_list) {
-		devmap_namespace_t *namespace = list_get_instance(item, devmap_namespace_t, namespaces);
+	link_t *item;
+	for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
+		devmap_namespace_t *namespace =
+		    list_get_instance(item, devmap_namespace_t, namespaces);
 		if (str_cmp(namespace->name, name) == 0)
 			return namespace;
-		item = item->next;
 	}
 	
@@ -224,12 +235,10 @@
 static devmap_namespace_t *devmap_namespace_find_handle(dev_handle_t handle)
 {
-	link_t *item = namespaces_list.next;
-	
-	while (item != &namespaces_list) {
-		devmap_namespace_t *namespace = list_get_instance(item, devmap_namespace_t, namespaces);
+	link_t *item;
+	for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
+		devmap_namespace_t *namespace =
+		    list_get_instance(item, devmap_namespace_t, namespaces);
 		if (namespace->handle == handle)
 			return namespace;
-		
-		item = item->next;
 	}
 	
@@ -246,11 +255,11 @@
     const char *name)
 {
-	link_t *item = devices_list.next;
-	
-	while (item != &devices_list) {
-		devmap_device_t *device = list_get_instance(item, devmap_device_t, devices);
-		if ((str_cmp(device->namespace->name, ns_name) == 0) && (str_cmp(device->name, name) == 0))
+	link_t *item;
+	for (item = devices_list.next; item != &devices_list; item = item->next) {
+		devmap_device_t *device =
+		    list_get_instance(item, devmap_device_t, devices);
+		if ((str_cmp(device->namespace->name, ns_name) == 0)
+		    && (str_cmp(device->name, name) == 0))
 			return device;
-		item = item->next;
 	}
 	
@@ -268,12 +277,10 @@
 static devmap_device_t *devmap_device_find_handle(dev_handle_t handle)
 {
-	link_t *item = devices_list.next;
-	
-	while (item != &devices_list) {
-		devmap_device_t *device = list_get_instance(item, devmap_device_t, devices);
+	link_t *item;
+	for (item = devices_list.next; item != &devices_list; item = item->next) {
+		devmap_device_t *device =
+		    list_get_instance(item, devmap_device_t, devices);
 		if (device->handle == handle)
 			return device;
-		
-		item = item->next;
 	}
 	
@@ -367,5 +374,4 @@
 	list_remove(&(device->driver_devices));
 	
-	free(device->namespace);
 	free(device->name);
 	free(device);
@@ -386,6 +392,6 @@
 	}
 	
-	devmap_driver_t *driver = (devmap_driver_t *) malloc(sizeof(devmap_driver_t));
-	
+	devmap_driver_t *driver =
+	    (devmap_driver_t *) malloc(sizeof(devmap_driver_t));
 	if (driver == NULL) {
 		ipc_answer_0(iid, ENOMEM);
@@ -404,5 +410,25 @@
 	}
 	
-	/* Initialize mutex for list of devices owned by this driver */
+	/*
+	 * Create connection to the driver
+	 */
+	ipc_call_t call;
+	ipc_callid_t callid = async_get_call(&call);
+	
+	if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
+		free(driver->name);
+		free(driver);
+		ipc_answer_0(callid, ENOTSUP);
+		ipc_answer_0(iid, ENOTSUP);
+		return NULL;
+	}
+	
+	driver->phone = IPC_GET_ARG5(call);
+	ipc_answer_0(callid, EOK);
+	
+	/*
+	 * Initialize mutex for list of devices
+	 * owned by this driver
+	 */
 	fibril_mutex_initialize(&driver->devices_mutex);
 	
@@ -411,24 +437,4 @@
 	 */
 	list_initialize(&driver->devices);
-	
-	/*
-	 * Create connection to the driver
-	 */
-	ipc_call_t call;
-	ipc_callid_t callid = async_get_call(&call);
-	
-	if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
-		ipc_answer_0(callid, ENOTSUP);
-		
-		free(driver->name);
-		free(driver);
-		ipc_answer_0(iid, ENOTSUP);
-		return NULL;
-	}
-	
-	driver->phone = IPC_GET_ARG5(call);
-	
-	ipc_answer_0(callid, EOK);
-	
 	list_initialize(&(driver->drivers));
 	
@@ -436,5 +442,6 @@
 	
 	/* TODO:
-	 * check that no driver with name equal to driver->name is registered
+	 * Check that no driver with name equal to
+	 * driver->name is registered
 	 */
 	
@@ -482,5 +489,5 @@
 	fibril_mutex_unlock(&drivers_list_mutex);
 	
-	/* free name and driver */
+	/* Free name and driver */
 	if (driver->name != NULL)
 		free(driver->name);
@@ -503,5 +510,6 @@
 	
 	/* Create new device entry */
-	devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t));
+	devmap_device_t *device =
+	    (devmap_device_t *) malloc(sizeof(devmap_device_t));
 	if (device == NULL) {
 		ipc_answer_0(iid, ENOMEM);
@@ -533,6 +541,7 @@
 	devmap_namespace_t *namespace = devmap_namespace_create(ns_name);
 	free(ns_name);
-	if (!namespace) {
+	if (namespace == NULL) {
 		fibril_mutex_unlock(&devices_list_mutex);
+		free(device->name);
 		free(device);
 		ipc_answer_0(iid, ENOMEM);
@@ -545,8 +554,8 @@
 	/* Check that device is not already registered */
 	if (devmap_device_find_name(namespace->name, device->name) != NULL) {
-		printf(NAME ": Device '%s/%s' already registered\n", device->namespace, device->name);
+		printf("%s: Device '%s/%s' already registered\n", NAME,
+		    device->namespace, device->name);
 		devmap_namespace_destroy(namespace);
 		fibril_mutex_unlock(&devices_list_mutex);
-		free(device->namespace);
 		free(device->name);
 		free(device);
@@ -603,4 +612,5 @@
 	
 	if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) {
+		fibril_mutex_unlock(&devices_list_mutex);
 		ipc_answer_0(callid, ENOENT);
 		return;
@@ -668,7 +678,8 @@
 		return;
 	}
+	
+	ipc_answer_1(iid, EOK, dev->handle);
+	
 	fibril_mutex_unlock(&devices_list_mutex);
-	
-	ipc_answer_1(iid, EOK, dev->handle);
 	free(ns_name);
 	free(name);
@@ -719,7 +730,8 @@
 		return;
 	}
+	
+	ipc_answer_1(iid, EOK, namespace->handle);
+	
 	fibril_mutex_unlock(&devices_list_mutex);
-	
-	ipc_answer_1(iid, EOK, namespace->handle);
 	free(name);
 }
@@ -729,7 +741,9 @@
 	fibril_mutex_lock(&devices_list_mutex);
 	
-	devmap_namespace_t *namespace = devmap_namespace_find_handle(IPC_GET_ARG1(*icall));
+	devmap_namespace_t *namespace =
+	    devmap_namespace_find_handle(IPC_GET_ARG1(*icall));
 	if (namespace == NULL) {
-		devmap_device_t *dev = devmap_device_find_handle(IPC_GET_ARG1(*icall));
+		devmap_device_t *dev =
+		    devmap_device_find_handle(IPC_GET_ARG1(*icall));
 		if (dev == NULL)
 			ipc_answer_1(iid, EOK, DEV_HANDLE_NONE);
@@ -753,5 +767,6 @@
 	fibril_mutex_lock(&devices_list_mutex);
 	
-	devmap_namespace_t *namespace = devmap_namespace_find_handle(IPC_GET_ARG1(*icall));
+	devmap_namespace_t *namespace =
+	    devmap_namespace_find_handle(IPC_GET_ARG1(*icall));
 	if (namespace == NULL)
 		ipc_answer_0(iid, EEXISTS);
@@ -782,4 +797,5 @@
 	size_t count = size / sizeof(dev_desc_t);
 	if (count != list_count(&namespaces_list)) {
+		fibril_mutex_unlock(&devices_list_mutex);
 		ipc_answer_0(callid, EOVERFLOW);
 		ipc_answer_0(iid, EOVERFLOW);
@@ -789,4 +805,5 @@
 	dev_desc_t *desc = (dev_desc_t *) malloc(size);
 	if (desc == NULL) {
+		fibril_mutex_unlock(&devices_list_mutex);
 		ipc_answer_0(callid, ENOMEM);
 		ipc_answer_0(iid, ENOMEM);
@@ -794,14 +811,14 @@
 	}
 	
-	link_t *item = namespaces_list.next;
+	link_t *item;
 	size_t pos = 0;
-	while (item != &namespaces_list) {
-		devmap_namespace_t *namespace = list_get_instance(item, devmap_namespace_t, namespaces);
+	for (item = namespaces_list.next; item != &namespaces_list;
+	    item = item->next) {
+		devmap_namespace_t *namespace =
+		    list_get_instance(item, devmap_namespace_t, namespaces);
 		
 		desc[pos].handle = namespace->handle;
 		str_cpy(desc[pos].name, DEVMAP_NAME_MAXLEN, namespace->name);
 		pos++;
-		
-		item = item->next;
 	}
 	
@@ -835,5 +852,6 @@
 	fibril_mutex_lock(&devices_list_mutex);
 	
-	devmap_namespace_t *namespace = devmap_namespace_find_handle(IPC_GET_ARG1(*icall));
+	devmap_namespace_t *namespace =
+	    devmap_namespace_find_handle(IPC_GET_ARG1(*icall));
 	if (namespace == NULL) {
 		fibril_mutex_unlock(&devices_list_mutex);
@@ -845,4 +863,5 @@
 	size_t count = size / sizeof(dev_desc_t);
 	if (count != namespace->refcnt) {
+		fibril_mutex_unlock(&devices_list_mutex);
 		ipc_answer_0(callid, EOVERFLOW);
 		ipc_answer_0(iid, EOVERFLOW);
@@ -852,4 +871,5 @@
 	dev_desc_t *desc = (dev_desc_t *) malloc(size);
 	if (desc == NULL) {
+		fibril_mutex_unlock(&devices_list_mutex);
 		ipc_answer_0(callid, ENOMEM);
 		ipc_answer_0(iid, EREFUSED);
@@ -857,8 +877,9 @@
 	}
 	
-	link_t *item = devices_list.next;
+	link_t *item;
 	size_t pos = 0;
-	while (item != &devices_list) {
-		devmap_device_t *device = list_get_instance(item, devmap_device_t, devices);
+	for (item = devices_list.next; item != &devices_list; item = item->next) {
+		devmap_device_t *device =
+		    list_get_instance(item, devmap_device_t, devices);
 		
 		if (device->namespace == namespace) {
@@ -867,6 +888,4 @@
 			pos++;
 		}
-		
-		item = item->next;
 	}
 	
@@ -909,5 +928,6 @@
 	}
 	
-	devmap_device_t *device = (devmap_device_t *) malloc(sizeof(devmap_device_t));
+	devmap_device_t *device =
+	    (devmap_device_t *) malloc(sizeof(devmap_device_t));
 	if (device == NULL) {
 		fibril_mutex_unlock(&null_devices_mutex);
@@ -919,5 +939,5 @@
 	
 	devmap_namespace_t *namespace = devmap_namespace_create("null");
-	if (!namespace) {
+	if (namespace == NULL) {
 		fibril_mutex_lock(&devices_list_mutex);
 		fibril_mutex_unlock(&null_devices_mutex);
@@ -949,9 +969,14 @@
 static void devmap_null_destroy(ipc_callid_t iid, ipc_call_t *icall)
 {
+	ipcarg_t i = IPC_GET_ARG1(*icall);
+	if (i >= NULL_DEVICES) {
+		ipc_answer_0(iid, ELIMIT);
+		return;
+	}
+	
 	fibril_mutex_lock(&null_devices_mutex);
 	
-	ipcarg_t i = IPC_GET_ARG1(*icall);
-	
 	if (null_devices[i] == NULL) {
+		fibril_mutex_unlock(&null_devices_mutex);
 		ipc_answer_0(iid, ENOENT);
 		return;
@@ -965,5 +990,4 @@
 	
 	fibril_mutex_unlock(&null_devices_mutex);
-	
 	ipc_answer_0(iid, EOK);
 }
@@ -1121,8 +1145,8 @@
 int main(int argc, char *argv[])
 {
-	printf(NAME ": HelenOS Device Mapper\n");
+	printf("%s: HelenOS Device Mapper\n", NAME);
 	
 	if (!devmap_init()) {
-		printf(NAME ": Error while initializing service\n");
+		printf("%s: Error while initializing service\n", NAME);
 		return -1;
 	}
@@ -1136,5 +1160,5 @@
 		return -1;
 	
-	printf(NAME ": Accepting connections\n");
+	printf("%s: Accepting connections\n", NAME);
 	async_manager();
 	
Index: uspace/srv/hid/fb/Makefile
===================================================================
--- uspace/srv/hid/fb/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/fb/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -29,5 +29,13 @@
 
 USPACE_PREFIX = ../../..
+ROOT_PATH = $(USPACE_PREFIX)/..
+
+COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
+CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
+
 BINARY = fb
+
+-include $(COMMON_MAKEFILE)
+-include $(CONFIG_MAKEFILE)
 
 SOURCES = \
@@ -36,43 +44,50 @@
 
 ifneq ($(UARCH),ia64)
-	SOURCES += fb.c \
+	SOURCES += \
+		fb.c \
 		font-8x16.c
-	EXTRA_CFLAGS = -DFB_ENABLED
+	EXTRA_CFLAGS += -DFB_ENABLED
 endif
 
 ifeq ($(UARCH),ia32)
-	SOURCES += ega.c
-	EXTRA_CFLAGS = -DEGA_ENABLED
+	SOURCES += \
+		ega.c
+	EXTRA_CFLAGS += -DEGA_ENABLED
 endif
 
 ifeq ($(UARCH),ia64)
-	SOURCES += ega.c \
+	SOURCES +=
+		ega.c \
 		ski.c \
 		serial_console.c
-	EXTRA_CFLAGS = -DSKI_ENABLED -DEGA_ENABLED
+	EXTRA_CFLAGS += -DSKI_ENABLED -DEGA_ENABLED
 endif
 
 ifeq ($(UARCH),amd64)
-	SOURCES += ega.c
-	EXTRA_CFLAGS = -DEGA_ENABLED
+	SOURCES += \
+		ega.c
+	EXTRA_CFLAGS += -DEGA_ENABLED
 endif
 
 ifeq ($(UARCH),mips32)
-	SOURCES += msim.c \
+	SOURCES += \
+		msim.c \
 		serial_console.c
-	EXTRA_CFLAGS = -DMSIM_ENABLED
+	EXTRA_CFLAGS += -DMSIM_ENABLED
 endif
 
 ifeq ($(UARCH),sparc64)
-	ifeq ($(PROCESSOR), sun4v)
-		SOURCES += niagara.c \
+	ifeq ($(PROCESSOR),sun4v)
+		SOURCES += \
+			niagara.c \
 			serial_console.c
-		EXTRA_CFLAGS = -DNIAGARA_ENABLED
+		EXTRA_CFLAGS += -DNIAGARA_ENABLED
 	endif
-
-	ifeq ($(MACHINE), serengeti)
-		SOURCES += sgcn.c \
+	
+	ifeq ($(MACHINE),serengeti)
+		SOURCES += \
+			sgcn.c \
 			serial_console.c
-		EXTRA_CFLAGS = -DSGCN_ENABLED
+		EXTRA_CFLAGS += -DSGCN_ENABLED
 	endif
 endif
Index: uspace/srv/hid/fb/ega.c
===================================================================
--- uspace/srv/hid/fb/ega.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/fb/ega.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -415,21 +415,36 @@
 	void *ega_ph_addr;
 	size_t sz;
-
-	ega_ph_addr = (void *) sysinfo_value("fb.address.physical");
-	scr_width = sysinfo_value("fb.width");
-	scr_height = sysinfo_value("fb.height");
-
-	if (sysinfo_value("fb.blinking")) {
+	
+	sysarg_t paddr;
+	if (sysinfo_get_value("fb.address.physical", &paddr) != EOK)
+		return -1;
+	
+	sysarg_t width;
+	if (sysinfo_get_value("fb.width", &width) != EOK)
+		return -1;
+	
+	sysarg_t height;
+	if (sysinfo_get_value("fb.width", &height) != EOK)
+		return -1;
+	
+	sysarg_t blinking;
+	if (sysinfo_get_value("fb.blinking", &blinking) != EOK)
+		blinking = false;
+	
+	ega_ph_addr = (void *) paddr;
+	scr_width = width;
+	scr_height = height;
+	if (blinking) {
 		ega_normal_color &= 0x77;
 		ega_inverted_color &= 0x77;
 	}
-
+	
 	style = NORMAL_COLOR;
-
+	
 	iospace_enable(task_get_id(), (void *) EGA_IO_BASE, 2);
-
+	
 	sz = scr_width * scr_height * 2;
 	scr_addr = as_get_mappable_page(sz);
-
+	
 	if (physmem_map(ega_ph_addr, scr_addr, ALIGN_UP(sz, PAGE_SIZE) >>
 	    PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0)
Index: uspace/srv/hid/fb/fb.c
===================================================================
--- uspace/srv/hid/fb/fb.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/fb/fb.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -1756,21 +1756,38 @@
 	async_set_client_connection(fb_client_connection);
 	
-	void *fb_ph_addr = (void *) sysinfo_value("fb.address.physical");
-	unsigned int fb_offset = sysinfo_value("fb.offset");
-	unsigned int fb_width = sysinfo_value("fb.width");
-	unsigned int fb_height = sysinfo_value("fb.height");
-	unsigned int fb_scanline = sysinfo_value("fb.scanline");
-	unsigned int fb_visual = sysinfo_value("fb.visual");
-
-	unsigned int fbsize = fb_scanline * fb_height;
+	sysarg_t fb_ph_addr;
+	if (sysinfo_get_value("fb.address.physical", &fb_ph_addr) != EOK)
+		return -1;
+	
+	sysarg_t fb_offset;
+	if (sysinfo_get_value("fb.offset", &fb_offset) != EOK)
+		fb_offset = 0;
+	
+	sysarg_t fb_width;
+	if (sysinfo_get_value("fb.width", &fb_width) != EOK)
+		return -1;
+	
+	sysarg_t fb_height;
+	if (sysinfo_get_value("fb.height", &fb_height) != EOK)
+		return -1;
+	
+	sysarg_t fb_scanline;
+	if (sysinfo_get_value("fb.scanline", &fb_scanline) != EOK)
+		return -1;
+	
+	sysarg_t fb_visual;
+	if (sysinfo_get_value("fb.visual", &fb_visual) != EOK)
+		return -1;
+	
+	sysarg_t fbsize = fb_scanline * fb_height;
 	void *fb_addr = as_get_mappable_page(fbsize);
-
-	if (physmem_map(fb_ph_addr + fb_offset, fb_addr,
+	
+	if (physmem_map((void *) fb_ph_addr + fb_offset, fb_addr,
 	    ALIGN_UP(fbsize, PAGE_SIZE) >> PAGE_WIDTH, AS_AREA_READ | AS_AREA_WRITE) != 0)
 		return -1;
-
+	
 	if (screen_init(fb_addr, fb_width, fb_height, fb_scanline, fb_visual))
 		return 0;
-
+	
 	return -1;
 }
Index: uspace/srv/hid/fb/main.c
===================================================================
--- uspace/srv/hid/fb/main.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/fb/main.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -60,11 +60,20 @@
 int main(int argc, char *argv[])
 {
-	printf(NAME ": HelenOS Framebuffer service\n");
+	printf("%s: HelenOS Framebuffer service\n", NAME);
 	
-	ipcarg_t phonead;
 	bool initialized = false;
+	sysarg_t fb_present;
+	sysarg_t fb_kind;
+	
+	if (sysinfo_get_value("fb", &fb_present) != EOK)
+		fb_present = false;
+	
+	if (sysinfo_get_value("fb.kind", &fb_kind) != EOK) {
+		printf("%s: Unable to detect framebuffer configuration\n", NAME);
+		return -1;
+	}
 	
 #ifdef FB_ENABLED
-	if (sysinfo_value("fb.kind") == 1) {
+	if ((!initialized) && (fb_kind == 1)) {
 		if (fb_init() == 0)
 			initialized = true;
@@ -72,5 +81,5 @@
 #endif
 #ifdef EGA_ENABLED
-	if ((!initialized) && (sysinfo_value("fb.kind") == 2)) {
+	if ((!initialized) && (fb_kind == 2)) {
 		if (ega_init() == 0)
 			initialized = true;
@@ -78,5 +87,5 @@
 #endif
 #ifdef MSIM_ENABLED
-	if ((!initialized) && (sysinfo_value("fb.kind") == 3)) {
+	if ((!initialized) && (fb_kind == 3)) {
 		if (msim_init() == 0)
 			initialized = true;
@@ -84,5 +93,5 @@
 #endif
 #ifdef SGCN_ENABLED
-	if ((!initialized) && (sysinfo_value("fb.kind") == 4)) {
+	if ((!initialized) && (fb_kind == 4)) {
 		if (sgcn_init() == 0)
 			initialized = true;
@@ -90,5 +99,5 @@
 #endif
 #ifdef NIAGARA_ENABLED
-	if ((!initialized) && (sysinfo_value("fb.kind") == 5)) {
+	if ((!initialized) && (fb_kind == 5)) {
 		if (niagara_init() == 0)
 			initialized = true;
@@ -96,5 +105,5 @@
 #endif
 #ifdef SKI_ENABLED
-	if ((!initialized) && (sysinfo_value("fb") != true)) {
+	if ((!initialized) && (!fb_present)) {
 		if (ski_init() == 0)
 			initialized = true;
@@ -105,8 +114,9 @@
 		return -1;
 	
+	ipcarg_t phonead;
 	if (ipc_connect_to_me(PHONE_NS, SERVICE_VIDEO, 0, 0, &phonead) != 0) 
 		return -1;
 	
-	printf(NAME ": Accepting connections\n");
+	printf("%s: Accepting connections\n", NAME);
 	async_manager();
 	
Index: uspace/srv/hid/fb/msim.c
===================================================================
--- uspace/srv/hid/fb/msim.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/fb/msim.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -29,8 +29,8 @@
 
 /** @defgroup msimfb MSIM text console
- * @brief	HelenOS MSIM text console.
+ * @brief HelenOS MSIM text console.
  * @ingroup fbs
  * @{
- */ 
+ */
 /** @file
  */
@@ -41,4 +41,5 @@
 #include <as.h>
 #include <ddi.h>
+#include <errno.h>
 
 #include "serial_console.h"
@@ -57,8 +58,12 @@
 int msim_init(void)
 {
-	void *phys_addr = (void *) sysinfo_value("fb.address.physical");
+	sysarg_t phys_addr;
+	if (sysinfo_get_value("fb.address.physical", &phys_addr) != EOK)
+		return -1;
+	
 	virt_addr = (char *) as_get_mappable_page(1);
 	
-	if (physmem_map(phys_addr, virt_addr, 1, AS_AREA_READ | AS_AREA_WRITE) != 0)
+	if (physmem_map((void *) phys_addr, virt_addr, 1,
+	    AS_AREA_READ | AS_AREA_WRITE) != 0)
 		return -1;
 	
@@ -69,5 +74,4 @@
 }
 
-/** 
- * @}
+/** @}
  */
Index: uspace/srv/hid/fb/niagara.c
===================================================================
--- uspace/srv/hid/fb/niagara.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/fb/niagara.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -91,9 +91,12 @@
 int niagara_init(void)
 {
+	sysarg_t paddr;
+	if (sysinfo_get_value("niagara.outbuf.address", &paddr) != EOK)
+		return -1;
+	
 	output_buffer_addr = (uintptr_t) as_get_mappable_page(PAGE_SIZE);
-	int result = physmem_map(
-		(void *) sysinfo_value("niagara.outbuf.address"),
-		(void *) output_buffer_addr,
-		1, AS_AREA_READ | AS_AREA_WRITE);
+	int result = physmem_map((void *) paddr,
+	    (void *) output_buffer_addr, 1,
+	    AS_AREA_READ | AS_AREA_WRITE);
 
 	if (result != 0) {
Index: uspace/srv/hid/fb/sgcn.c
===================================================================
--- uspace/srv/hid/fb/sgcn.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/fb/sgcn.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -122,14 +122,22 @@
 int sgcn_init(void)
 {
-	sram_virt_addr = (uintptr_t) as_get_mappable_page(sysinfo_value("sram.area.size"));
+	sysarg_t sram_paddr;
+	if (sysinfo_get_value("sram.address.physical", &sram_paddr) != EOK)
+		return -1;
 	
-	if (physmem_map((void *) sysinfo_value("sram.address.physical"),
-	    (void *) sram_virt_addr, sysinfo_value("sram.area.size") / PAGE_SIZE,
-	    AS_AREA_READ | AS_AREA_WRITE) != 0)
+	sysarg_t sram_size;
+	if (sysinfo_get_value("sram.area.size", &sram_size) != EOK)
+		return -1;
+	
+	if (sysinfo_get_value("sram.buffer.offset", &sram_buffer_offset) != EOK)
+		sram_buffer_offset = 0;
+	
+	sram_virt_addr = (uintptr_t) as_get_mappable_page(sram_size);
+	
+	if (physmem_map((void *) sram_paddr, (void *) sram_virt_addr,
+	    sram_size / PAGE_SIZE, AS_AREA_READ | AS_AREA_WRITE) != 0)
 		return -1;
 	
 	serial_console_init(sgcn_putc, WIDTH, HEIGHT);
-	
-	sram_buffer_offset = sysinfo_value("sram.buffer.offset");
 	
 	async_set_client_connection(serial_client_connection);
Index: uspace/srv/hid/kbd/generic/kbd.c
===================================================================
--- uspace/srv/hid/kbd/generic/kbd.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/kbd/generic/kbd.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -212,9 +212,12 @@
 int main(int argc, char **argv)
 {
-	printf(NAME ": HelenOS Keyboard service\n");
-	
-	if (sysinfo_value("kbd.cir.fhc") == 1)
+	printf("%s: HelenOS Keyboard service\n", NAME);
+	
+	sysarg_t fhc;
+	sysarg_t obio;
+	
+	if ((sysinfo_get_value("kbd.cir.fhc", &fhc) == EOK) && (fhc))
 		cir_service = SERVICE_FHC;
-	else if (sysinfo_value("kbd.cir.obio") == 1)
+	else if ((sysinfo_get_value("kbd.cir.obio", &obio) == EOK) && (obio))
 		cir_service = SERVICE_OBIO;
 	
@@ -240,5 +243,5 @@
 	int rc = devmap_driver_register(NAME, client_connection);
 	if (rc < 0) {
-		printf(NAME ": Unable to register driver (%d)\n", rc);
+		printf("%s: Unable to register driver (%d)\n", NAME, rc);
 		return -1;
 	}
@@ -249,5 +252,5 @@
 	dev_handle_t dev_handle;
 	if (devmap_device_register(kbd, &dev_handle) != EOK) {
-		printf(NAME ": Unable to register device %s\n", kbd);
+		printf("%s: Unable to register device %s\n", NAME, kbd);
 		return -1;
 	}
Index: uspace/srv/hid/kbd/port/gxemul.c
===================================================================
--- uspace/srv/hid/kbd/port/gxemul.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/kbd/port/gxemul.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -41,4 +41,5 @@
 #include <kbd.h>
 #include <ddi.h>
+#include <errno.h>
 
 static irq_cmd_t gxemul_cmds[] = {
@@ -63,8 +64,15 @@
 int kbd_port_init(void)
 {
+	sysarg_t addr;
+	if (sysinfo_get_value("kbd.address.virtual", &addr) != EOK)
+		return -1;
+	
+	sysarg_t inr;
+	if (sysinfo_get_value("kbd.inr", &inr) != EOK)
+		return -1;
+	
 	async_set_interrupt_received(gxemul_irq_handler);
-	gxemul_cmds[0].addr = (void *) sysinfo_value("kbd.address.virtual");
-	ipc_register_irq(sysinfo_value("kbd.inr"), device_assign_devno(),
-	    0, &gxemul_kbd);
+	gxemul_cmds[0].addr = (void *) addr;
+	ipc_register_irq(inr, device_assign_devno(), 0, &gxemul_kbd);
 	return 0;
 }
Index: uspace/srv/hid/kbd/port/msim.c
===================================================================
--- uspace/srv/hid/kbd/port/msim.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/kbd/port/msim.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -30,7 +30,7 @@
  * @ingroup  kbd
  * @{
- */ 
+ */
 /** @file
- * @brief	Msim keyboard port driver.
+ * @brief Msim keyboard port driver.
  */
 
@@ -41,4 +41,5 @@
 #include <kbd.h>
 #include <ddi.h>
+#include <errno.h>
 
 irq_cmd_t msim_cmds[] = {
@@ -63,8 +64,16 @@
 int kbd_port_init(void)
 {
+	sysarg_t vaddr;
+	if (sysinfo_get_value("kbd.address.virtual", &vaddr) != EOK)
+		return -1;
+	
+	sysarg_t inr;
+	if (sysinfo_get_value("kbd.inr", &inr) != EOK)
+		return -1;
+	
+	msim_cmds[0].addr = (void *) vaddr;
 	async_set_interrupt_received(msim_irq_handler);
-	msim_cmds[0].addr = (void *) sysinfo_value("kbd.address.virtual");
-	ipc_register_irq(sysinfo_value("kbd.inr"), device_assign_devno(),
-	    0, &msim_kbd);
+	ipc_register_irq(inr, device_assign_devno(), 0, &msim_kbd);
+	
 	return 0;
 }
Index: uspace/srv/hid/kbd/port/niagara.c
===================================================================
--- uspace/srv/hid/kbd/port/niagara.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/kbd/port/niagara.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -44,6 +44,7 @@
 #include <thread.h>
 #include <bool.h>
+#include <errno.h>
 
-#define POLL_INTERVAL		10000
+#define POLL_INTERVAL  10000
 
 /**
@@ -57,5 +58,6 @@
  * kernel/arch/sparc64/src/drivers/niagara.c.
  */
-#define INPUT_BUFFER_SIZE	((PAGE_SIZE) - 2 * 8)
+#define INPUT_BUFFER_SIZE  ((PAGE_SIZE) - 2 * 8)
+
 typedef volatile struct {
 	uint64_t write_ptr;
@@ -79,24 +81,25 @@
 int kbd_port_init(void)
 {
+	sysarg_t paddr;
+	if (sysinfo_get_value("niagara.inbuf.address", &paddr) != EOK)
+		return -1;
+	
 	input_buffer_addr = (uintptr_t) as_get_mappable_page(PAGE_SIZE);
-	int result = physmem_map(
-		(void *) sysinfo_value("niagara.inbuf.address"),
-		(void *) input_buffer_addr,
-		1, AS_AREA_READ | AS_AREA_WRITE);
-
-	if (result != 0) {
+	int rc = physmem_map((void *) paddr, (void *) input_buffer_addr,
+	    1, AS_AREA_READ | AS_AREA_WRITE);
+	
+	if (rc != 0) {
 		printf("Niagara: uspace driver couldn't map physical memory: %d\n",
-			result);
-	}
-
-	input_buffer = (input_buffer_t) input_buffer_addr;
-
-	thread_id_t tid;
-	int rc;
-
-	rc = thread_create(niagara_thread_impl, NULL, "kbd_poll", &tid);
-	if (rc != 0) {
+		    rc);
 		return rc;
 	}
+	
+	input_buffer = (input_buffer_t) input_buffer_addr;
+	
+	thread_id_t tid;
+	rc = thread_create(niagara_thread_impl, NULL, "kbd_poll", &tid);
+	if (rc != 0)
+		return rc;
+	
 	return 0;
 }
Index: uspace/srv/hid/kbd/port/ns16550.c
===================================================================
--- uspace/srv/hid/kbd/port/ns16550.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/kbd/port/ns16550.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -30,7 +30,7 @@
  * @ingroup  kbd
  * @{
- */ 
+ */
 /** @file
- * @brief	NS16550 port driver.
+ * @brief NS16550 port driver.
  */
 
@@ -43,20 +43,21 @@
 #include <sun.h>
 #include <ddi.h>
+#include <errno.h>
 
 /* NS16550 registers */
-#define RBR_REG		0	/** Receiver Buffer Register. */
-#define IER_REG		1	/** Interrupt Enable Register. */
-#define IIR_REG		2	/** Interrupt Ident Register (read). */
-#define FCR_REG		2	/** FIFO control register (write). */
-#define LCR_REG		3	/** Line Control register. */
-#define MCR_REG		4	/** Modem Control Register. */
-#define LSR_REG		5	/** Line Status Register. */
+#define RBR_REG  0  /** Receiver Buffer Register. */
+#define IER_REG  1  /** Interrupt Enable Register. */
+#define IIR_REG  2  /** Interrupt Ident Register (read). */
+#define FCR_REG  2  /** FIFO control register (write). */
+#define LCR_REG  3  /** Line Control register. */
+#define MCR_REG  4  /** Modem Control Register. */
+#define LSR_REG  5  /** Line Status Register. */
 
-#define LSR_DATA_READY	0x01
+#define LSR_DATA_READY  0x01
 
 static irq_cmd_t ns16550_cmds[] = {
 	{
 		.cmd = CMD_PIO_READ_8,
-		.addr = (void *) 0,	/* will be patched in run-time */
+		.addr = (void *) 0,     /* Will be patched in run-time */
 		.dstarg = 1
 	},
@@ -74,5 +75,5 @@
 	{
 		.cmd = CMD_PIO_READ_8,
-		.addr = (void *) 0,	/* will be patched in run-time */
+		.addr = (void *) 0,     /* Will be patched in run-time */
 		.dstarg = 2
 	},
@@ -96,12 +97,20 @@
 	void *vaddr;
 
-	async_set_interrupt_received(ns16550_irq_handler);
-
-	ns16550_physical = sysinfo_value("kbd.address.physical");
-	ns16550_kernel = sysinfo_value("kbd.address.kernel");
+	if (sysinfo_get_value("kbd.address.physical", &ns16550_physical) != EOK)
+		return -1;
+	
+	if (sysinfo_get_value("kbd.address.kernel", &ns16550_kernel) != EOK)
+		return -1;
+	
+	sysarg_t inr;
+	if (sysinfo_get_value("kbd.inr", &inr) != EOK)
+		return -1;
+	
 	ns16550_kbd.cmds[0].addr = (void *) (ns16550_kernel + LSR_REG);
 	ns16550_kbd.cmds[3].addr = (void *) (ns16550_kernel + RBR_REG);
-	ipc_register_irq(sysinfo_value("kbd.inr"), device_assign_devno(),
-	    sysinfo_value("kbd.inr"), &ns16550_kbd);
+	
+	async_set_interrupt_received(ns16550_irq_handler);
+	ipc_register_irq(inr, device_assign_devno(), inr, &ns16550_kbd);
+	
 	return pio_enable((void *) ns16550_physical, 8, &vaddr);
 }
Index: uspace/srv/hid/kbd/port/pl050.c
===================================================================
--- uspace/srv/hid/kbd/port/pl050.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/kbd/port/pl050.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -83,12 +83,17 @@
 int kbd_port_init(void)
 {
-
-	pl050_kbd.cmds[0].addr = (void *) sysinfo_value("kbd.address.status");
-	pl050_kbd.cmds[3].addr = (void *) sysinfo_value("kbd.address.data");
-
+	if (sysinfo_get_value("kbd.address.status", &pl050_kbd.cmds[0].addr) != EOK)
+		return -1;
+	
+	if (sysinfo_get_value("kbd.address.data", &pl050_kbd.cmds[3].addr) != EOK)
+		return -1;
+	
+	sysarg_t inr;
+	if (sysinfo_get_value("kbd.inr", &inr) != EOK)
+		return -1;
+	
 	async_set_interrupt_received(pl050_irq_handler);
-
-	ipc_register_irq(sysinfo_value("kbd.inr"), device_assign_devno(), 0, &pl050_kbd);
-
+	ipc_register_irq(inr, device_assign_devno(), 0, &pl050_kbd);
+	
 	return 0;
 }
Index: uspace/srv/hid/kbd/port/sgcn.c
===================================================================
--- uspace/srv/hid/kbd/port/sgcn.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/kbd/port/sgcn.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -30,7 +30,7 @@
  * @ingroup  kbd
  * @{
- */ 
+ */
 /** @file
- * @brief	SGCN (Serengeti Console) keyboard port driver.
+ * @brief SGCN (Serengeti Console) keyboard port driver.
  */
 
@@ -44,10 +44,11 @@
 #include <thread.h>
 #include <bool.h>
+#include <errno.h>
 
-#define POLL_INTERVAL		10000
+#define POLL_INTERVAL  10000
 
 /**
  * SGCN buffer header. It is placed at the very beginning of the SGCN
- * buffer. 
+ * buffer.
  */
 typedef struct {
@@ -102,22 +103,28 @@
 int kbd_port_init(void)
 {
-	sram_virt_addr = (uintptr_t) as_get_mappable_page(sysinfo_value("sram.area.size"));
-	if (physmem_map((void *) sysinfo_value("sram.address.physical"),
-	    (void *) sram_virt_addr, sysinfo_value("sram.area.size") / PAGE_SIZE,
-	    AS_AREA_READ | AS_AREA_WRITE) != 0) {
+	sysarg_t sram_paddr;
+	if (sysinfo_get_value("sram.address.physical", &sram_paddr) != EOK)
+		return -1;
+	
+	sysarg_t sram_size;
+	if (sysinfo_get_value("sram.area.size", &sram_size) != EOK)
+		return -1;
+	
+	if (sysinfo_get_value("sram.buffer.offset", &sram_buffer_offset) != EOK)
+		sram_buffer_offset = 0;
+	
+	sram_virt_addr = (uintptr_t) as_get_mappable_page(sram_size);
+	
+	if (physmem_map((void *) sram_paddr, (void *) sram_virt_addr,
+	    sram_size / PAGE_SIZE, AS_AREA_READ | AS_AREA_WRITE) != 0) {
 		printf("SGCN: uspace driver could not map physical memory.");
 		return -1;
 	}
 	
-	sram_buffer_offset = sysinfo_value("sram.buffer.offset");
-
 	thread_id_t tid;
-	int rc;
-
-	rc = thread_create(sgcn_thread_impl, NULL, "kbd_poll", &tid);
-	if (rc != 0) {
+	int rc = thread_create(sgcn_thread_impl, NULL, "kbd_poll", &tid);
+	if (rc != 0)
 		return rc;
-	}
-
+	
 	return 0;
 }
Index: uspace/srv/hid/kbd/port/sun.c
===================================================================
--- uspace/srv/hid/kbd/port/sun.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/kbd/port/sun.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -39,4 +39,6 @@
 #include <sun.h>
 #include <sysinfo.h>
+#include <errno.h>
+#include <bool.h>
 
 /** Sun keyboard virtual port driver.
@@ -50,10 +52,18 @@
 int kbd_port_init(void)
 {
-	if (sysinfo_value("kbd.type.z8530")) {
+	sysarg_t z8530;
+	if (sysinfo_get_value("kbd.type.z8530", &z8530) != EOK)
+		z8530 = false;
+	
+	sysarg_t ns16550;
+	if (sysinfo_get_value("kbd.type.ns16550", &ns16550) != EOK)
+		ns16550 = false;
+	
+	if (z8530) {
 		if (z8530_port_init() == 0)
 			return 0;
 	}
 	
-	if (sysinfo_value("kbd.type.ns16550")) {
+	if (ns16550) {
 		if (ns16550_port_init() == 0)
 			return 0;
Index: uspace/srv/hid/kbd/port/z8530.c
===================================================================
--- uspace/srv/hid/kbd/port/z8530.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hid/kbd/port/z8530.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -30,7 +30,7 @@
  * @ingroup  kbd
  * @{
- */ 
+ */
 /** @file
- * @brief	Z8530 keyboard port driver.
+ * @brief Z8530 keyboard port driver.
  */
 
@@ -44,14 +44,15 @@
 #include <sys/types.h>
 #include <ddi.h>
+#include <errno.h>
 
-#define CHAN_A_STATUS	4
-#define CHAN_A_DATA	6
+#define CHAN_A_STATUS  4
+#define CHAN_A_DATA    6
 
-#define RR0_RCA	1
+#define RR0_RCA  1
 
 static irq_cmd_t z8530_cmds[] = {
 	{
 		.cmd = CMD_PIO_READ_8,
-		.addr = (void *) 0,	/* will be patched in run-time */
+		.addr = (void *) 0,     /* Will be patched in run-time */
 		.dstarg = 1
 	},
@@ -69,5 +70,5 @@
 	{
 		.cmd = CMD_PIO_READ_8,
-		.addr = (void *) 0,	/* will be patched in run-time */
+		.addr = (void *) 0,     /* Will be patched in run-time */
 		.dstarg = 2
 	},
@@ -86,11 +87,18 @@
 int z8530_port_init(void)
 {
+	sysarg_t kaddr;
+	if (sysinfo_get_value("kbd.address.kernel", &kaddr) != EOK)
+		return -1;
+	
+	sysarg_t inr;
+	if (sysinfo_get_value("kbd.inr", &inr) != EOK)
+		return -1;
+	
+	z8530_cmds[0].addr = (void *) kaddr + CHAN_A_STATUS;
+	z8530_cmds[3].addr = (void *) kaddr + CHAN_A_DATA;
+	
 	async_set_interrupt_received(z8530_irq_handler);
-	z8530_cmds[0].addr = (void *) sysinfo_value("kbd.address.kernel") +
-	    CHAN_A_STATUS;
-	z8530_cmds[3].addr = (void *) sysinfo_value("kbd.address.kernel") +
-	    CHAN_A_DATA;
-	ipc_register_irq(sysinfo_value("kbd.inr"), device_assign_devno(),
-	    sysinfo_value("kbd.inr"), &z8530_kbd);
+	ipc_register_irq(inr, device_assign_devno(), inr, &z8530_kbd);
+	
 	return 0;
 }
Index: uspace/srv/hw/bus/cuda_adb/cuda_adb.c
===================================================================
--- uspace/srv/hw/bus/cuda_adb/cuda_adb.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hw/bus/cuda_adb/cuda_adb.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -254,11 +254,14 @@
 static int cuda_init(void)
 {
+	if (sysinfo_get_value("cuda.address.physical", &(instance->cuda_physical)) != EOK)
+		return -1;
+	
+	if (sysinfo_get_value("cuda.address.kernel", &(instance->cuda_kernel)) != EOK)
+		return -1;
+	
 	void *vaddr;
-
-	instance->cuda_physical = sysinfo_value("cuda.address.physical");
-	instance->cuda_kernel = sysinfo_value("cuda.address.kernel");
-
 	if (pio_enable((void *) instance->cuda_physical, sizeof(cuda_t), &vaddr) != 0)
 		return -1;
+	
 	dev = vaddr;
 
Index: uspace/srv/hw/char/i8042/i8042.c
===================================================================
--- uspace/srv/hw/char/i8042/i8042.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hw/char/i8042/i8042.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -164,14 +164,27 @@
 static int i8042_init(void)
 {
+	if (sysinfo_get_value("i8042.address.physical", &i8042_physical) != EOK)
+		return -1;
+	
+	if (sysinfo_get_value("i8042.address.kernel", &i8042_kernel) != EOK)
+		return -1;
+	
 	void *vaddr;
-
-	i8042_physical = sysinfo_value("i8042.address.physical");
-	i8042_kernel = sysinfo_value("i8042.address.kernel");
 	if (pio_enable((void *) i8042_physical, sizeof(i8042_t), &vaddr) != 0)
 		return -1;
+	
 	i8042 = vaddr;
-
+	
+	sysarg_t inr_a;
+	sysarg_t inr_b;
+	
+	if (sysinfo_get_value("i8042.inr_a", &inr_a) != EOK)
+		return -1;
+	
+	if (sysinfo_get_value("i8042.inr_b", &inr_b) != EOK)
+		return -1;
+	
 	async_set_interrupt_received(i8042_irq_handler);
-
+	
 	/* Disable kbd and aux */
 	wait_ready();
@@ -186,8 +199,7 @@
 	i8042_kbd.cmds[0].addr = (void *) &((i8042_t *) i8042_kernel)->status;
 	i8042_kbd.cmds[3].addr = (void *) &((i8042_t *) i8042_kernel)->data;
-	ipc_register_irq(sysinfo_value("i8042.inr_a"), device_assign_devno(), 0, &i8042_kbd);
-	ipc_register_irq(sysinfo_value("i8042.inr_b"), device_assign_devno(), 0, &i8042_kbd);
-	printf("i8042: registered for interrupts %d and %d\n",
-	    sysinfo_value("i8042.inr_a"), sysinfo_value("i8042.inr_b"));
+	ipc_register_irq(inr_a, device_assign_devno(), 0, &i8042_kbd);
+	ipc_register_irq(inr_b, device_assign_devno(), 0, &i8042_kbd);
+	printf("%s: registered for interrupts %d and %d\n", NAME, inr_a, inr_b);
 
 	wait_ready();
Index: uspace/srv/hw/cir/fhc/fhc.c
===================================================================
--- uspace/srv/hw/cir/fhc/fhc.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hw/cir/fhc/fhc.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -109,14 +109,13 @@
 static bool fhc_init(void)
 {
-	ipcarg_t phonead;
+	sysarg_t paddr;
 
-	fhc_uart_size = sysinfo_value("fhc.uart.size");
-	fhc_uart_phys = (void *) sysinfo_value("fhc.uart.physical");
-	
-	if (!fhc_uart_size) {
+	if ((sysinfo_get_value("fhc.uart.physical", &paddr) != EOK)
+	    || (sysinfo_get_value("fhc.uart.size", &fhc_uart_size) != EOK)) {
 		printf(NAME ": no FHC UART registers found\n");
 		return false;
 	}
-
+	
+	fhc_uart_phys = (void *) paddr;
 	fhc_uart_virt = as_get_mappable_page(fhc_uart_size);
 	
@@ -132,6 +131,7 @@
 	printf(NAME ": FHC UART registers at %p, %d bytes\n", fhc_uart_phys,
 	    fhc_uart_size);
-
+	
 	async_set_client_connection(fhc_connection);
+	ipcarg_t phonead;
 	ipc_connect_to_me(PHONE_NS, SERVICE_FHC, 0, 0, &phonead);
 	
Index: uspace/srv/hw/cir/obio/obio.c
===================================================================
--- uspace/srv/hw/cir/obio/obio.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/hw/cir/obio/obio.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -112,13 +112,12 @@
 static bool obio_init(void)
 {
-	ipcarg_t phonead;
-
-	base_phys = (void *) sysinfo_value("obio.base.physical");
+	sysarg_t paddr;
 	
-	if (!base_phys) {
+	if (sysinfo_get_value("obio.base.physical", &paddr) != EOK) {
 		printf(NAME ": no OBIO registers found\n");
 		return false;
 	}
-
+	
+	base_phys = (void *) paddr;
 	base_virt = as_get_mappable_page(OBIO_SIZE);
 	
@@ -133,6 +132,7 @@
 	
 	printf(NAME ": OBIO registers with base at %p\n", base_phys);
-
+	
 	async_set_client_connection(obio_connection);
+	ipcarg_t phonead;
 	ipc_connect_to_me(PHONE_NS, SERVICE_OBIO, 0, 0, &phonead);
 	
Index: uspace/srv/hw/netif/dp8390/Makefile
===================================================================
--- uspace/srv/hw/netif/dp8390/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/hw/netif/dp8390/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,52 @@
+#
+# Copyright (c) 2005 Martin Decky
+# Copyright (c) 2007 Jakub Jermar
+# 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.
+#
+
+USPACE_PREFIX = ../../../..
+ROOT_PATH = $(USPACE_PREFIX)/..
+LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBSOCKET_PREFIX)/include
+
+COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
+CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
+
+-include $(COMMON_MAKEFILE)
+-include $(CONFIG_MAKEFILE)
+
+ifeq ($(CONFIG_NETIF_NIL_BUNDLE),y)
+	LIBS += $(USPACE_PREFIX)/srv/net/nil/eth/libeth.a
+endif
+
+BINARY = dp8390
+
+SOURCES = \
+	dp8390.c \
+	dp8390_module.c \
+	ne2000.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/hw/netif/dp8390/dp8390.c
===================================================================
--- uspace/srv/hw/netif/dp8390/dp8390.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/hw/netif/dp8390/dp8390.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,1672 @@
+/*
+ * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system 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.
+ * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+ * * Any deviations from these conditions require written permission from the copyright holder in advance
+ *
+ *
+ * Disclaimer
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``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 COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS 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.
+ *
+ * Changes:
+ *  2009 ported to HelenOS, Lukas Mejdrech
+ */
+
+/** @addtogroup dp8390
+ *  @{
+ */
+
+/** @file
+ *  DP8390 network interface core implementation.
+ */
+
+#include <assert.h>
+#include <errno.h>
+
+#include <net_byteorder.h>
+#include <netif_local.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+
+#include "dp8390_drv.h"
+#include "dp8390_port.h"
+
+/*
+ * dp8390.c
+ *
+ * Created:	before Dec 28, 1992 by Philip Homburg <philip@f-mnx.phicoh.com>
+ *
+ * Modified Mar 10 1994 by Philip Homburg
+ *	Become a generic dp8390 driver.
+ *
+ * Modified Dec 20 1996 by G. Falzoni <falzoni@marina.scn.de>
+ *	Added support for 3c503 boards.
+ */
+
+#include "local.h"
+#include "dp8390.h"
+
+/** Queues the outgoing packet.
+ *  @param[in] dep The network interface structure.
+ *  @param[in] packet The outgoing packet.
+ *  @returns EOK on success.
+ *  @returns EINVAL 
+ */
+int queue_packet(dpeth_t * dep, packet_t packet);
+
+/** Reads a memory block byte by byte.
+ *  @param[in] port The source address.
+ *  @param[out] buf The destination buffer.
+ *  @param[in] size The memory block size in bytes.
+ */
+static void outsb(port_t port, void * buf, size_t size);
+
+/** Reads a memory block word by word.
+ *  @param[in] port The source address.
+ *  @param[out] buf The destination buffer.
+ *  @param[in] size The memory block size in bytes.
+ */
+static void outsw(port_t port, void * buf, size_t size);
+
+//static u16_t eth_ign_proto;
+//static char *progname;
+
+/* Configuration */
+/*typedef struct dp_conf
+{
+	port_t dpc_port;
+	int dpc_irq;
+	phys_bytes dpc_mem;
+	char *dpc_envvar;
+} dp_conf_t;
+*/
+//dp_conf_t dp_conf[]=	/* Card addresses */
+//{
+	/* I/O port, IRQ,  Buffer address,  Env. var. */
+/*	{ 0x280,     3,    0xD0000,        "DPETH0"	},
+	{ 0x300,     5,    0xC8000,        "DPETH1"	},
+	{ 0x380,    10,    0xD8000,        "DPETH2"	},
+};
+*/
+/* Test if dp_conf has exactly DE_PORT_NR entries.  If not then you will see
+ * the error: "array size is negative".
+ */
+//extern int ___dummy[DE_PORT_NR == sizeof(dp_conf)/sizeof(dp_conf[0]) ? 1 : -1];
+
+/* Card inits configured out? */
+#if !ENABLE_WDETH
+#define wdeth_probe(dep)	(0)
+#endif
+#if !ENABLE_NE2000
+#define ne_probe(dep)		(0)
+#endif
+#if !ENABLE_3C503
+#define el2_probe(dep)		(0)
+#endif
+
+/* Some clones of the dp8390 and the PC emulator 'Bochs' require the CR_STA
+ * on writes to the CR register. Additional CR_STAs do not appear to hurt
+ * genuine dp8390s
+ */
+#define CR_EXTRA	CR_STA
+
+//#if ENABLE_PCI
+//_PROTOTYPE(static void pci_conf, (void)				);
+//#endif
+//_PROTOTYPE(static void do_vwrite, (message *mp, int from_int,
+//							int vectored)	);
+//_PROTOTYPE(static void do_vwrite_s, (message *mp, int from_int)	);
+//_PROTOTYPE(static void do_vread, (message *mp, int vectored)		);
+//_PROTOTYPE(static void do_vread_s, (message *mp)			);
+//_PROTOTYPE(static void do_init, (message *mp)				);
+//_PROTOTYPE(static void do_int, (dpeth_t *dep)				);
+//_PROTOTYPE(static void do_getstat, (message *mp)			);
+//_PROTOTYPE(static void do_getstat_s, (message *mp)			);
+//_PROTOTYPE(static void do_getname, (message *mp)			);
+//_PROTOTYPE(static void do_stop, (message *mp)				);
+_PROTOTYPE(static void dp_init, (dpeth_t *dep)				);
+//_PROTOTYPE(static void dp_confaddr, (dpeth_t *dep)			);
+_PROTOTYPE(static void dp_reinit, (dpeth_t *dep)			);
+_PROTOTYPE(static void dp_reset, (dpeth_t *dep)			);
+//_PROTOTYPE(static void dp_check_ints, (dpeth_t *dep)			);
+_PROTOTYPE(static void dp_recv, (dpeth_t *dep)				);
+_PROTOTYPE(static void dp_send, (dpeth_t *dep)				);
+//_PROTOTYPE(static void dp8390_stop, (void)				);
+_PROTOTYPE(static void dp_getblock, (dpeth_t *dep, int page,
+				size_t offset, size_t size, void *dst)	);
+_PROTOTYPE(static void dp_pio8_getblock, (dpeth_t *dep, int page,
+				size_t offset, size_t size, void *dst)	);
+_PROTOTYPE(static void dp_pio16_getblock, (dpeth_t *dep, int page,
+				size_t offset, size_t size, void *dst)	);
+_PROTOTYPE(static int dp_pkt2user, (dpeth_t *dep, int page,
+							int length) );
+//_PROTOTYPE(static int dp_pkt2user_s, (dpeth_t *dep, int page,
+//							int length)	);
+_PROTOTYPE(static void dp_user2nic, (dpeth_t *dep, iovec_dat_t *iovp, 
+		vir_bytes offset, int nic_addr, vir_bytes count) );
+//_PROTOTYPE(static void dp_user2nic_s, (dpeth_t *dep, iovec_dat_s_t *iovp, 
+//		vir_bytes offset, int nic_addr, vir_bytes count)	);
+_PROTOTYPE(static void dp_pio8_user2nic, (dpeth_t *dep,
+				iovec_dat_t *iovp, vir_bytes offset,
+				int nic_addr, vir_bytes count) );
+//_PROTOTYPE(static void dp_pio8_user2nic_s, (dpeth_t *dep,
+//				iovec_dat_s_t *iovp, vir_bytes offset,
+//				int nic_addr, vir_bytes count)		);
+_PROTOTYPE(static void dp_pio16_user2nic, (dpeth_t *dep,
+				iovec_dat_t *iovp, vir_bytes offset,
+				int nic_addr, vir_bytes count) );
+//_PROTOTYPE(static void dp_pio16_user2nic_s, (dpeth_t *dep,
+//				iovec_dat_s_t *iovp, vir_bytes offset,
+//				int nic_addr, vir_bytes count)		);
+_PROTOTYPE(static void dp_nic2user, (dpeth_t *dep, int nic_addr, 
+		iovec_dat_t *iovp, vir_bytes offset, vir_bytes count)	);
+//_PROTOTYPE(static void dp_nic2user_s, (dpeth_t *dep, int nic_addr, 
+//		iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count)	);
+_PROTOTYPE(static void dp_pio8_nic2user, (dpeth_t *dep, int nic_addr, 
+		iovec_dat_t *iovp, vir_bytes offset, vir_bytes count)	);
+//_PROTOTYPE(static void dp_pio8_nic2user_s, (dpeth_t *dep, int nic_addr, 
+//		iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count)	);
+_PROTOTYPE(static void dp_pio16_nic2user, (dpeth_t *dep, int nic_addr, 
+		iovec_dat_t *iovp, vir_bytes offset, vir_bytes count)	);
+//_PROTOTYPE(static void dp_pio16_nic2user_s, (dpeth_t *dep, int nic_addr, 
+//		iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count)	);
+_PROTOTYPE(static void dp_next_iovec, (iovec_dat_t *iovp)		);
+//_PROTOTYPE(static void dp_next_iovec_s, (iovec_dat_s_t *iovp)		);
+_PROTOTYPE(static void conf_hw, (dpeth_t *dep)				);
+//_PROTOTYPE(static void update_conf, (dpeth_t *dep, dp_conf_t *dcp)	);
+_PROTOTYPE(static void map_hw_buffer, (dpeth_t *dep)			);
+//_PROTOTYPE(static int calc_iovec_size, (iovec_dat_t *iovp)		);
+//_PROTOTYPE(static int calc_iovec_size_s, (iovec_dat_s_t *iovp)		);
+_PROTOTYPE(static void reply, (dpeth_t *dep, int err, int may_block)	);
+//_PROTOTYPE(static void mess_reply, (message *req, message *reply)	);
+_PROTOTYPE(static void get_userdata, (int user_proc,
+		vir_bytes user_addr, vir_bytes count, void *loc_addr)	);
+//_PROTOTYPE(static void get_userdata_s, (int user_proc,
+//		cp_grant_id_t grant, vir_bytes offset, vir_bytes count,
+//		void *loc_addr)	);
+//_PROTOTYPE(static void put_userdata, (int user_proc,
+//		vir_bytes user_addr, vir_bytes count, void *loc_addr)	);
+//_PROTOTYPE(static void put_userdata_s, (int user_proc,
+//		cp_grant_id_t grant, size_t count, void *loc_addr)	);
+_PROTOTYPE(static void insb, (port_t port, void *buf, size_t size)				);
+_PROTOTYPE(static void insw, (port_t port, void *buf, size_t size)				);
+//_PROTOTYPE(static void do_vir_insb, (port_t port, int proc,
+//					vir_bytes buf, size_t size)	);
+//_PROTOTYPE(static void do_vir_insw, (port_t port, int proc,
+//					vir_bytes buf, size_t size)	);
+//_PROTOTYPE(static void do_vir_outsb, (port_t port, int proc,
+//					vir_bytes buf, size_t size)	);
+//_PROTOTYPE(static void do_vir_outsw, (port_t port, int proc,
+//					vir_bytes buf, size_t size)	);
+
+int do_probe(dpeth_t * dep){
+	/* This is the default, try to (re)locate the device. */
+	conf_hw(dep);
+	if (dep->de_mode == DEM_DISABLED)
+	{
+		/* Probe failed, or the device is configured off. */
+		return EXDEV;//ENXIO;
+	}
+	if (dep->de_mode == DEM_ENABLED)
+		dp_init(dep);
+	return EOK;
+}
+
+/*===========================================================================*
+ *				dp8390_dump				     *
+ *===========================================================================*/
+void dp8390_dump(dpeth_t * dep)
+{
+//	dpeth_t *dep;
+	int /*i,*/ isr;
+
+//	printf("\n");
+//	for (i= 0, dep = &de_table[0]; i<DE_PORT_NR; i++, dep++)
+//	{
+#if XXX
+		if (dep->de_mode == DEM_DISABLED)
+			printf("dp8390 port %d is disabled\n", i);
+		else if (dep->de_mode == DEM_SINK)
+			printf("dp8390 port %d is in sink mode\n", i);
+#endif
+
+		if (dep->de_mode != DEM_ENABLED)
+//			continue;
+			return;
+
+//		printf("dp8390 statistics of port %d:\n", i);
+
+		printf("recvErr    :%8ld\t", dep->de_stat.ets_recvErr);
+		printf("sendErr    :%8ld\t", dep->de_stat.ets_sendErr);
+		printf("OVW        :%8ld\n", dep->de_stat.ets_OVW);
+
+		printf("CRCerr     :%8ld\t", dep->de_stat.ets_CRCerr);
+		printf("frameAll   :%8ld\t", dep->de_stat.ets_frameAll);
+		printf("missedP    :%8ld\n", dep->de_stat.ets_missedP);
+
+		printf("packetR    :%8ld\t", dep->de_stat.ets_packetR);
+		printf("packetT    :%8ld\t", dep->de_stat.ets_packetT);
+		printf("transDef   :%8ld\n", dep->de_stat.ets_transDef);
+
+		printf("collision  :%8ld\t", dep->de_stat.ets_collision);
+		printf("transAb    :%8ld\t", dep->de_stat.ets_transAb);
+		printf("carrSense  :%8ld\n", dep->de_stat.ets_carrSense);
+
+		printf("fifoUnder  :%8ld\t", dep->de_stat.ets_fifoUnder);
+		printf("fifoOver   :%8ld\t", dep->de_stat.ets_fifoOver);
+		printf("CDheartbeat:%8ld\n", dep->de_stat.ets_CDheartbeat);
+
+		printf("OWC        :%8ld\t", dep->de_stat.ets_OWC);
+
+		isr= inb_reg0(dep, DP_ISR);
+		printf("dp_isr = 0x%x + 0x%x, de_flags = 0x%x\n", isr,
+					inb_reg0(dep, DP_ISR), dep->de_flags);
+//	}
+}
+
+/*===========================================================================*
+ *				do_init					     *
+ *===========================================================================*/
+int do_init(dpeth_t * dep, int mode){
+	if (dep->de_mode == DEM_DISABLED)
+	{
+		// might call do_probe()
+		return EXDEV;
+	}
+
+	if (dep->de_mode == DEM_SINK)
+	{
+//		strncpy((char *) dep->de_address.ea_addr, "ZDP", 6);
+//		dep->de_address.ea_addr[5] = port;
+//		dp_confaddr(dep);
+//		reply_mess.m_type = DL_CONF_REPLY;
+//		reply_mess.m3_i1 = mp->DL_PORT;
+//		reply_mess.m3_i2 = DE_PORT_NR;
+//		*(ether_addr_t *) reply_mess.m3_ca1 = dep->de_address;
+//		mess_reply(mp, &reply_mess);
+//		return;
+		return EOK;
+	}
+	assert(dep->de_mode == DEM_ENABLED);
+	assert(dep->de_flags &DEF_ENABLED);
+
+	dep->de_flags &= ~(DEF_PROMISC | DEF_MULTI | DEF_BROAD);
+
+	if (mode &DL_PROMISC_REQ)
+		dep->de_flags |= DEF_PROMISC | DEF_MULTI | DEF_BROAD;
+	if (mode &DL_MULTI_REQ)
+		dep->de_flags |= DEF_MULTI;
+	if (mode &DL_BROAD_REQ)
+		dep->de_flags |= DEF_BROAD;
+
+//	dep->de_client = mp->m_source;
+	dp_reinit(dep);
+
+//	reply_mess.m_type = DL_CONF_REPLY;
+//	reply_mess.m3_i1 = mp->DL_PORT;
+//	reply_mess.m3_i2 = DE_PORT_NR;
+//	*(ether_addr_t *) reply_mess.m3_ca1 = dep->de_address;
+
+//	mess_reply(mp, &reply_mess);
+	return EOK;
+}
+
+/*===========================================================================*
+ *				do_stop					     *
+ *===========================================================================*/
+void do_stop(dpeth_t * dep){
+	if((dep->de_mode != DEM_SINK) && (dep->de_mode == DEM_ENABLED) && (dep->de_flags &DEF_ENABLED)){
+		outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
+		(dep->de_stopf)(dep);
+
+		dep->de_flags = DEF_EMPTY;
+	}
+}
+
+int queue_packet(dpeth_t * dep, packet_t packet){
+	packet_t tmp;
+
+	if(dep->packet_count >= MAX_PACKETS){
+		netif_pq_release(packet_get_id(packet));
+		return ELIMIT;
+	}
+
+	tmp = dep->packet_queue;
+	while(pq_next(tmp)){
+		tmp = pq_next(tmp);
+	}
+	if(pq_add(&tmp, packet, 0, 0) != EOK){
+		return EINVAL;
+	}
+	if(! dep->packet_count){
+		dep->packet_queue = packet;
+	}
+	++ dep->packet_count;
+	return EBUSY;
+}
+
+/*===========================================================================*
+ *			based on	do_vwrite				     *
+ *===========================================================================*/
+int do_pwrite(dpeth_t * dep, packet_t packet, int from_int)
+{
+//	int port, count, size;
+	int size;
+	int sendq_head;
+/*	dpeth_t *dep;
+
+	port = mp->DL_PORT;
+	count = mp->DL_COUNT;
+	if (port < 0 || port >= DE_PORT_NR)
+		panic("", "dp8390: illegal port", port);
+	dep= &de_table[port];
+	dep->de_client= mp->DL_PROC;
+*/
+	if (dep->de_mode == DEM_SINK)
+	{
+		assert(!from_int);
+//		dep->de_flags |= DEF_PACK_SEND;
+		reply(dep, OK, FALSE);
+//		return;
+		return EOK;
+	}
+	assert(dep->de_mode == DEM_ENABLED);
+	assert(dep->de_flags &DEF_ENABLED);
+	if(dep->packet_queue && (! from_int)){
+//	if (dep->de_flags &DEF_SEND_AVAIL){
+//		panic("", "dp8390: send already in progress", NO_NUM);
+		return queue_packet(dep, packet);
+	}
+
+	sendq_head= dep->de_sendq_head;
+//	if (dep->de_sendq[sendq_head].sq_filled)
+//	{
+//		if (from_int)
+//			panic("", "dp8390: should not be sending\n", NO_NUM);
+//		dep->de_sendmsg= *mp;
+//		dep->de_flags |= DEF_SEND_AVAIL;
+//		reply(dep, OK, FALSE);
+//		return;
+//		return queue_packet(dep, packet);
+//	}
+//	assert(!(dep->de_flags &DEF_PACK_SEND));
+
+/*	if (vectored)
+	{
+		get_userdata(mp->DL_PROC, (vir_bytes) mp->DL_ADDR,
+			(count > IOVEC_NR ? IOVEC_NR : count) *
+			sizeof(iovec_t), dep->de_write_iovec.iod_iovec);
+		dep->de_write_iovec.iod_iovec_s = count;
+		dep->de_write_iovec.iod_proc_nr = mp->DL_PROC;
+		dep->de_write_iovec.iod_iovec_addr = (vir_bytes) mp->DL_ADDR;
+
+		dep->de_tmp_iovec = dep->de_write_iovec;
+		size = calc_iovec_size(&dep->de_tmp_iovec);
+	}
+	else
+	{ 
+		dep->de_write_iovec.iod_iovec[0].iov_addr =
+			(vir_bytes) mp->DL_ADDR;
+		dep->de_write_iovec.iod_iovec[0].iov_size =
+			mp->DL_COUNT;
+		dep->de_write_iovec.iod_iovec_s = 1;
+		dep->de_write_iovec.iod_proc_nr = mp->DL_PROC;
+		dep->de_write_iovec.iod_iovec_addr = 0;
+		size= mp->DL_COUNT;
+	}
+*/
+	size = packet_get_data_length(packet);
+	dep->de_write_iovec.iod_iovec[0].iov_addr = (vir_bytes) packet_get_data(packet);
+	dep->de_write_iovec.iod_iovec[0].iov_size = size;
+	dep->de_write_iovec.iod_iovec_s = 1;
+	dep->de_write_iovec.iod_iovec_addr = NULL;
+
+	if (size < ETH_MIN_PACK_SIZE || size > ETH_MAX_PACK_SIZE_TAGGED)
+	{
+		panic("", "dp8390: invalid packet size", size);
+		return EINVAL;
+	}
+	(dep->de_user2nicf)(dep, &dep->de_write_iovec, 0,
+		dep->de_sendq[sendq_head].sq_sendpage * DP_PAGESIZE,
+		size);
+	dep->de_sendq[sendq_head].sq_filled= TRUE;
+	if (dep->de_sendq_tail == sendq_head)
+	{
+		outb_reg0(dep, DP_TPSR, dep->de_sendq[sendq_head].sq_sendpage);
+		outb_reg0(dep, DP_TBCR1, size >> 8);
+		outb_reg0(dep, DP_TBCR0, size &0xff);
+		outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA);/* there it goes.. */
+	}
+	else
+		dep->de_sendq[sendq_head].sq_size= size;
+	
+	if (++sendq_head == dep->de_sendq_nr)
+		sendq_head= 0;
+	assert(sendq_head < SENDQ_NR);
+	dep->de_sendq_head= sendq_head;
+
+//	dep->de_flags |= DEF_PACK_SEND;
+
+	/* If the interrupt handler called, don't send a reply. The reply
+	 * will be sent after all interrupts are handled. 
+	 */
+	if (from_int)
+		return EOK;
+	reply(dep, OK, FALSE);
+
+	assert(dep->de_mode == DEM_ENABLED);
+	assert(dep->de_flags &DEF_ENABLED);
+	return EOK;
+}
+
+/*===========================================================================*
+ *				dp_init					     *
+ *===========================================================================*/
+void dp_init(dep)
+dpeth_t *dep;
+{
+	int dp_rcr_reg;
+	int i;//, r;
+
+	/* General initialization */
+	dep->de_flags = DEF_EMPTY;
+	(*dep->de_initf)(dep);
+
+//	dp_confaddr(dep);
+
+	if (debug)
+	{
+		printf("%s: Ethernet address ", dep->de_name);
+		for (i= 0; i < 6; i++)
+			printf("%x%c", dep->de_address.ea_addr[i],
+							i < 5 ? ':' : '\n');
+	}
+
+	/* Map buffer */
+	map_hw_buffer(dep);
+
+	/* Initialization of the dp8390 following the mandatory procedure
+	 * in reference manual ("DP8390D/NS32490D NIC Network Interface
+	 * Controller", National Semiconductor, July 1995, Page 29).
+	 */
+	/* Step 1: */
+	outb_reg0(dep, DP_CR, CR_PS_P0 | CR_STP | CR_DM_ABORT);
+	/* Step 2: */
+	if (dep->de_16bit)
+		outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS);
+	else
+		outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES | DCR_BMS);
+	/* Step 3: */
+	outb_reg0(dep, DP_RBCR0, 0);
+	outb_reg0(dep, DP_RBCR1, 0);
+	/* Step 4: */
+	dp_rcr_reg = 0;
+	if (dep->de_flags &DEF_PROMISC)
+		dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM;
+	if (dep->de_flags &DEF_BROAD)
+		dp_rcr_reg |= RCR_AB;
+	if (dep->de_flags &DEF_MULTI)
+		dp_rcr_reg |= RCR_AM;
+	outb_reg0(dep, DP_RCR, dp_rcr_reg);
+	/* Step 5: */
+	outb_reg0(dep, DP_TCR, TCR_INTERNAL);
+	/* Step 6: */
+	outb_reg0(dep, DP_BNRY, dep->de_startpage);
+	outb_reg0(dep, DP_PSTART, dep->de_startpage);
+	outb_reg0(dep, DP_PSTOP, dep->de_stoppage);
+	/* Step 7: */
+	outb_reg0(dep, DP_ISR, 0xFF);
+	/* Step 8: */
+	outb_reg0(dep, DP_IMR, IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE |
+		IMR_OVWE | IMR_CNTE);
+	/* Step 9: */
+	outb_reg0(dep, DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP);
+
+	outb_reg1(dep, DP_PAR0, dep->de_address.ea_addr[0]);
+	outb_reg1(dep, DP_PAR1, dep->de_address.ea_addr[1]);
+	outb_reg1(dep, DP_PAR2, dep->de_address.ea_addr[2]);
+	outb_reg1(dep, DP_PAR3, dep->de_address.ea_addr[3]);
+	outb_reg1(dep, DP_PAR4, dep->de_address.ea_addr[4]);
+	outb_reg1(dep, DP_PAR5, dep->de_address.ea_addr[5]);
+
+	outb_reg1(dep, DP_MAR0, 0xff);
+	outb_reg1(dep, DP_MAR1, 0xff);
+	outb_reg1(dep, DP_MAR2, 0xff);
+	outb_reg1(dep, DP_MAR3, 0xff);
+	outb_reg1(dep, DP_MAR4, 0xff);
+	outb_reg1(dep, DP_MAR5, 0xff);
+	outb_reg1(dep, DP_MAR6, 0xff);
+	outb_reg1(dep, DP_MAR7, 0xff);
+
+	outb_reg1(dep, DP_CURR, dep->de_startpage + 1);
+	/* Step 10: */
+	outb_reg0(dep, DP_CR, CR_DM_ABORT | CR_STA);
+	/* Step 11: */
+	outb_reg0(dep, DP_TCR, TCR_NORMAL);
+
+	inb_reg0(dep, DP_CNTR0);		/* reset counters by reading */
+	inb_reg0(dep, DP_CNTR1);
+	inb_reg0(dep, DP_CNTR2);
+
+	/* Finish the initialization. */
+	dep->de_flags |= DEF_ENABLED;
+	for (i= 0; i<dep->de_sendq_nr; i++)
+		dep->de_sendq[i].sq_filled= 0;
+	dep->de_sendq_head= 0;
+	dep->de_sendq_tail= 0;
+	if (!dep->de_prog_IO)
+	{
+		dep->de_user2nicf= dp_user2nic;
+//		dep->de_user2nicf_s= dp_user2nic_s;
+		dep->de_nic2userf= dp_nic2user;
+//		dep->de_nic2userf_s= dp_nic2user_s;
+		dep->de_getblockf= dp_getblock;
+	}
+	else if (dep->de_16bit)
+	{
+		dep->de_user2nicf= dp_pio16_user2nic;
+//		dep->de_user2nicf_s= dp_pio16_user2nic_s;
+		dep->de_nic2userf= dp_pio16_nic2user;
+//		dep->de_nic2userf_s= dp_pio16_nic2user_s;
+		dep->de_getblockf= dp_pio16_getblock;
+	}
+	else
+	{
+		dep->de_user2nicf= dp_pio8_user2nic;
+//		dep->de_user2nicf_s= dp_pio8_user2nic_s;
+		dep->de_nic2userf= dp_pio8_nic2user;
+//		dep->de_nic2userf_s= dp_pio8_nic2user_s;
+		dep->de_getblockf= dp_pio8_getblock;
+	}
+
+	/* Set the interrupt handler and policy. Do not automatically 
+	 * reenable interrupts. Return the IRQ line number on interrupts.
+ 	 */
+/* 	dep->de_hook = dep->de_irq;
+	r= sys_irqsetpolicy(dep->de_irq, 0, &dep->de_hook);
+	if (r != OK)
+		panic("DP8390", "sys_irqsetpolicy failed", r);
+
+	r= sys_irqenable(&dep->de_hook);
+	if (r != OK)
+	{
+		panic("DP8390", "unable enable interrupts", r);
+	}
+*/
+}
+
+/*===========================================================================*
+ *				dp_reinit				     *
+ *===========================================================================*/
+static void dp_reinit(dep)
+dpeth_t *dep;
+{
+	int dp_rcr_reg;
+
+	outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA);
+
+	dp_rcr_reg = 0;
+	if (dep->de_flags &DEF_PROMISC)
+		dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM;
+	if (dep->de_flags &DEF_BROAD)
+		dp_rcr_reg |= RCR_AB;
+	if (dep->de_flags &DEF_MULTI)
+		dp_rcr_reg |= RCR_AM;
+	outb_reg0(dep, DP_RCR, dp_rcr_reg);
+}
+
+/*===========================================================================*
+ *				dp_reset				     *
+ *===========================================================================*/
+static void dp_reset(dep)
+dpeth_t *dep;
+{
+	int i;
+
+	/* Stop chip */
+	outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
+	outb_reg0(dep, DP_RBCR0, 0);
+	outb_reg0(dep, DP_RBCR1, 0);
+	for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) &ISR_RST) == 0); i++)
+		; /* Do nothing */
+	outb_reg0(dep, DP_TCR, TCR_1EXTERNAL|TCR_OFST);
+	outb_reg0(dep, DP_CR, CR_STA|CR_DM_ABORT);
+	outb_reg0(dep, DP_TCR, TCR_NORMAL);
+
+	/* Acknowledge the ISR_RDC (remote dma) interrupt. */
+	for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) &ISR_RDC) == 0); i++)
+		; /* Do nothing */
+	outb_reg0(dep, DP_ISR, inb_reg0(dep, DP_ISR) &~ISR_RDC);
+
+	/* Reset the transmit ring. If we were transmitting a packet, we
+	 * pretend that the packet is processed. Higher layers will
+	 * retransmit if the packet wasn't actually sent.
+	 */
+	dep->de_sendq_head= dep->de_sendq_tail= 0;
+	for (i= 0; i<dep->de_sendq_nr; i++)
+		dep->de_sendq[i].sq_filled= 0;
+	dp_send(dep);
+	dep->de_flags &= ~DEF_STOPPED;
+}
+
+/*===========================================================================*
+ *				dp_check_ints				     *
+ *===========================================================================*/
+void dp_check_ints(dep, isr)
+dpeth_t *dep;
+int isr;
+{
+	int /*isr,*/ tsr;
+	int size, sendq_tail;
+
+	if (!(dep->de_flags &DEF_ENABLED))
+		panic("", "dp8390: got premature interrupt", NO_NUM);
+
+	for(;;)
+	{
+//		isr = inb_reg0(dep, DP_ISR);
+		if (!isr)
+			break;
+		outb_reg0(dep, DP_ISR, isr);
+		if (isr &(ISR_PTX|ISR_TXE))
+		{
+			if (isr &ISR_TXE)
+			{
+#if DEBUG
+ {printf("%s: got send Error\n", dep->de_name);}
+#endif
+				dep->de_stat.ets_sendErr++;
+			}
+			else
+			{
+				tsr = inb_reg0(dep, DP_TSR);
+
+				if (tsr &TSR_PTX) dep->de_stat.ets_packetT++;
+#if 0	/* Reserved in later manuals, should be ignored */
+				if (!(tsr &TSR_DFR))
+				{
+					/* In most (all?) implementations of
+					 * the dp8390, this bit is set
+					 * when the packet is not deferred
+					 */
+					dep->de_stat.ets_transDef++;
+				}
+#endif
+				if (tsr &TSR_COL) dep->de_stat.ets_collision++;
+				if (tsr &TSR_ABT) dep->de_stat.ets_transAb++;
+				if (tsr &TSR_CRS) dep->de_stat.ets_carrSense++;
+				if (tsr &TSR_FU
+					&& ++dep->de_stat.ets_fifoUnder <= 10)
+				{
+					printf("%s: fifo underrun\n",
+						dep->de_name);
+				}
+				if (tsr &TSR_CDH
+					&& ++dep->de_stat.ets_CDheartbeat <= 10)
+				{
+					printf("%s: CD heart beat failure\n",
+						dep->de_name);
+				}
+				if (tsr &TSR_OWC) dep->de_stat.ets_OWC++;
+			}
+			sendq_tail= dep->de_sendq_tail;
+
+			if (!(dep->de_sendq[sendq_tail].sq_filled))
+			{
+				/* Software bug? */
+				assert(!debug);
+
+				/* Or hardware bug? */
+				printf(
+				"%s: transmit interrupt, but not sending\n",
+					dep->de_name);
+				continue;
+			}
+			dep->de_sendq[sendq_tail].sq_filled= 0;
+			if (++sendq_tail == dep->de_sendq_nr)
+				sendq_tail= 0;
+			dep->de_sendq_tail= sendq_tail;
+			if (dep->de_sendq[sendq_tail].sq_filled)
+			{
+				size= dep->de_sendq[sendq_tail].sq_size;
+				outb_reg0(dep, DP_TPSR,
+					dep->de_sendq[sendq_tail].sq_sendpage);
+				outb_reg0(dep, DP_TBCR1, size >> 8);
+				outb_reg0(dep, DP_TBCR0, size &0xff);
+				outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA);
+			}
+//			if (dep->de_flags &DEF_SEND_AVAIL)
+				dp_send(dep);
+		}
+
+		if (isr &ISR_PRX)
+		{
+			/* Only call dp_recv if there is a read request */
+//			if (dep->de_flags) &DEF_READING)
+				dp_recv(dep);
+		}
+		
+		if (isr &ISR_RXE) dep->de_stat.ets_recvErr++;
+		if (isr &ISR_CNT)
+		{
+			dep->de_stat.ets_CRCerr += inb_reg0(dep, DP_CNTR0);
+			dep->de_stat.ets_frameAll += inb_reg0(dep, DP_CNTR1);
+			dep->de_stat.ets_missedP += inb_reg0(dep, DP_CNTR2);
+		}
+		if (isr &ISR_OVW)
+		{
+			dep->de_stat.ets_OVW++;
+#if 0
+			{printW(); printf(
+				"%s: got overwrite warning\n", dep->de_name);}
+#endif
+/*			if (dep->de_flags &DEF_READING)
+			{
+				printf(
+"dp_check_ints: strange: overwrite warning and pending read request\n");
+				dp_recv(dep);
+			}
+*/		}
+		if (isr &ISR_RDC)
+		{
+			/* Nothing to do */
+		}
+		if (isr &ISR_RST)
+		{
+			/* this means we got an interrupt but the ethernet 
+			 * chip is shutdown. We set the flag DEF_STOPPED,
+			 * and continue processing arrived packets. When the
+			 * receive buffer is empty, we reset the dp8390.
+			 */
+#if 0
+			 {printW(); printf(
+				"%s: NIC stopped\n", dep->de_name);}
+#endif
+			dep->de_flags |= DEF_STOPPED;
+			break;
+		}
+		isr = inb_reg0(dep, DP_ISR);
+	}
+//	if ((dep->de_flags &(DEF_READING|DEF_STOPPED)) == 
+//						(DEF_READING|DEF_STOPPED))
+	if ((dep->de_flags &DEF_STOPPED) == DEF_STOPPED)
+	{
+		/* The chip is stopped, and all arrived packets are 
+		 * delivered.
+		 */
+		dp_reset(dep);
+	}
+}
+
+/*===========================================================================*
+ *				dp_recv					     *
+ *===========================================================================*/
+static void dp_recv(dep)
+dpeth_t *dep;
+{
+	dp_rcvhdr_t header;
+	//unsigned pageno, curr, next;
+	int pageno, curr, next;
+	vir_bytes length;
+	int packet_processed, r;
+	u16_t eth_type;
+
+	packet_processed = FALSE;
+	pageno = inb_reg0(dep, DP_BNRY) + 1;
+	if (pageno == dep->de_stoppage) pageno = dep->de_startpage;
+
+	do
+	{
+		outb_reg0(dep, DP_CR, CR_PS_P1 | CR_EXTRA);
+		curr = inb_reg1(dep, DP_CURR);
+		outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA);
+
+		if (curr == pageno) break;
+
+		(dep->de_getblockf)(dep, pageno, (size_t)0, sizeof(header),
+			&header);
+		(dep->de_getblockf)(dep, pageno, sizeof(header) +
+			2*sizeof(ether_addr_t), sizeof(eth_type), &eth_type);
+
+		length = (header.dr_rbcl | (header.dr_rbch << 8)) -
+			sizeof(dp_rcvhdr_t);
+		next = header.dr_next;
+		if (length < ETH_MIN_PACK_SIZE ||
+			length > ETH_MAX_PACK_SIZE_TAGGED)
+		{
+			printf("%s: packet with strange length arrived: %d\n",
+				dep->de_name, (int) length);
+			next= curr;
+		}
+		else if (next < dep->de_startpage || next >= dep->de_stoppage)
+		{
+			printf("%s: strange next page\n", dep->de_name);
+			next= curr;
+		}
+/*		else if (eth_type == eth_ign_proto)
+		{
+*/			/* Hack: ignore packets of a given protocol, useful
+			 * if you share a net with 80 computers sending
+			 * Amoeba FLIP broadcasts.  (Protocol 0x8146.)
+			 */
+/*			static int first= 1;
+			if (first)
+			{
+				first= 0;
+				printf("%s: dropping proto 0x%04x packets\n",
+					dep->de_name,
+					ntohs(eth_ign_proto));
+			}
+			dep->de_stat.ets_packetR++;
+		}
+*/		else if (header.dr_status &RSR_FO)
+		{
+			/* This is very serious, so we issue a warning and
+			 * reset the buffers */
+			printf("%s: fifo overrun, resetting receive buffer\n",
+				dep->de_name);
+			dep->de_stat.ets_fifoOver++;
+			next = curr;
+		}
+		else if ((header.dr_status &RSR_PRX) && 
+					   (dep->de_flags &DEF_ENABLED))
+		{
+//			if (dep->de_safecopy_read)
+//				r = dp_pkt2user_s(dep, pageno, length);
+//			else
+				r = dp_pkt2user(dep, pageno, length);
+			if (r != OK)
+				return;
+
+			packet_processed = TRUE;
+			dep->de_stat.ets_packetR++;
+		}
+		if (next == dep->de_startpage)
+			outb_reg0(dep, DP_BNRY, dep->de_stoppage - 1);
+		else
+			outb_reg0(dep, DP_BNRY, next - 1);
+
+		pageno = next;
+	}
+	while (!packet_processed);
+}
+
+/*===========================================================================*
+ *				dp_send					     *
+ *===========================================================================*/
+static void dp_send(dep)
+dpeth_t *dep;
+{
+	packet_t packet;
+
+//	if (!(dep->de_flags &DEF_SEND_AVAIL))
+//		return;
+
+	if(dep->packet_queue){
+		packet = dep->packet_queue;
+		dep->packet_queue = pq_detach(packet);
+		do_pwrite(dep, packet, TRUE);
+		netif_pq_release(packet_get_id(packet));
+		-- dep->packet_count;
+	}
+//	if(! dep->packet_queue){
+//		dep->de_flags &= ~DEF_SEND_AVAIL;
+//	}
+/*	switch(dep->de_sendmsg.m_type)
+	{
+	case DL_WRITE:	do_vwrite(&dep->de_sendmsg, TRUE, FALSE);	break;
+	case DL_WRITEV:	do_vwrite(&dep->de_sendmsg, TRUE, TRUE);	break;
+	case DL_WRITEV_S: do_vwrite_s(&dep->de_sendmsg, TRUE);	break;
+	default:
+		panic("", "dp8390: wrong type", dep->de_sendmsg.m_type);
+		break;
+	}
+*/
+}
+
+/*===========================================================================*
+ *				dp_getblock				     *
+ *===========================================================================*/
+static void dp_getblock(dep, page, offset, size, dst)
+dpeth_t *dep;
+int page;
+size_t offset;
+size_t size;
+void *dst;
+{
+//	int r;
+
+	offset = page * DP_PAGESIZE + offset;
+
+	memcpy(dst, dep->de_locmem + offset, size);
+}
+
+/*===========================================================================*
+ *				dp_pio8_getblock			     *
+ *===========================================================================*/
+static void dp_pio8_getblock(dep, page, offset, size, dst)
+dpeth_t *dep;
+int page;
+size_t offset;
+size_t size;
+void *dst;
+{
+	offset = page * DP_PAGESIZE + offset;
+	outb_reg0(dep, DP_RBCR0, size &0xFF);
+	outb_reg0(dep, DP_RBCR1, size >> 8);
+	outb_reg0(dep, DP_RSAR0, offset &0xFF);
+	outb_reg0(dep, DP_RSAR1, offset >> 8);
+	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
+
+	insb(dep->de_data_port, dst, size);
+}
+
+/*===========================================================================*
+ *				dp_pio16_getblock			     *
+ *===========================================================================*/
+static void dp_pio16_getblock(dep, page, offset, size, dst)
+dpeth_t *dep;
+int page;
+size_t offset;
+size_t size;
+void *dst;
+{
+	offset = page * DP_PAGESIZE + offset;
+	outb_reg0(dep, DP_RBCR0, size &0xFF);
+	outb_reg0(dep, DP_RBCR1, size >> 8);
+	outb_reg0(dep, DP_RSAR0, offset &0xFF);
+	outb_reg0(dep, DP_RSAR1, offset >> 8);
+	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
+
+	assert (!(size &1));
+	insw(dep->de_data_port, dst, size);
+}
+
+/*===========================================================================*
+ *				dp_pkt2user				     *
+ *===========================================================================*/
+static int dp_pkt2user(dep, page, length)
+dpeth_t *dep;
+int page, length;
+{
+	int last, count;
+	packet_t packet;
+
+//	if (!(dep->de_flags &DEF_READING))
+//		return EGENERIC;
+
+	packet = netif_packet_get_1(length);
+	if(! packet){
+		return ENOMEM;
+	}
+	dep->de_read_iovec.iod_iovec[0].iov_addr = (vir_bytes) packet_suffix(packet, length);
+	dep->de_read_iovec.iod_iovec[0].iov_size = length;
+	dep->de_read_iovec.iod_iovec_s = 1;
+	dep->de_read_iovec.iod_iovec_addr = NULL;
+
+	last = page + (length - 1) / DP_PAGESIZE;
+	if (last >= dep->de_stoppage)
+	{
+		count = (dep->de_stoppage - page) * DP_PAGESIZE -
+			sizeof(dp_rcvhdr_t);
+
+		/* Save read_iovec since we need it twice. */
+		dep->de_tmp_iovec = dep->de_read_iovec;
+		(dep->de_nic2userf)(dep, page * DP_PAGESIZE +
+			sizeof(dp_rcvhdr_t), &dep->de_tmp_iovec, 0, count);
+		(dep->de_nic2userf)(dep, dep->de_startpage * DP_PAGESIZE, 
+			&dep->de_read_iovec, count, length - count);
+	}
+	else
+	{
+		(dep->de_nic2userf)(dep, page * DP_PAGESIZE +
+			sizeof(dp_rcvhdr_t), &dep->de_read_iovec, 0, length);
+	}
+
+	dep->de_read_s = length;
+	dep->de_flags |= DEF_PACK_RECV;
+//	dep->de_flags &= ~DEF_READING;
+
+	if(dep->received_count >= MAX_PACKETS){
+		netif_pq_release(packet_get_id(packet));
+		return ELIMIT;
+	}else{
+		if(pq_add(&dep->received_queue, packet, 0, 0) == EOK){
+			++ dep->received_count;
+		}else{
+			netif_pq_release(packet_get_id(packet));
+		}
+	}
+	return OK;
+}
+
+/*===========================================================================*
+ *				dp_user2nic				     *
+ *===========================================================================*/
+static void dp_user2nic(dep, iovp, offset, nic_addr, count)
+dpeth_t *dep;
+iovec_dat_t *iovp;
+vir_bytes offset;
+int nic_addr;
+vir_bytes count;
+{
+	vir_bytes vir_hw;//, vir_user;
+	//int bytes, i, r;
+	int i, r;
+	vir_bytes bytes;
+
+	vir_hw = (vir_bytes)dep->de_locmem + nic_addr;
+
+	i= 0;
+	while (count > 0)
+	{
+		if (i >= IOVEC_NR)
+		{
+			dp_next_iovec(iovp);
+			i= 0;
+			continue;
+		}
+		assert(i < iovp->iod_iovec_s);
+		if (offset >= iovp->iod_iovec[i].iov_size)
+		{
+			offset -= iovp->iod_iovec[i].iov_size;
+			i++;
+			continue;
+		}
+		bytes = iovp->iod_iovec[i].iov_size - offset;
+		if (bytes > count)
+			bytes = count;
+
+		r= sys_vircopy(iovp->iod_proc_nr, D,
+			iovp->iod_iovec[i].iov_addr + offset,
+			SELF, D, vir_hw, bytes);
+		if (r != OK)
+			panic("DP8390", "dp_user2nic: sys_vircopy failed", r);
+
+		count -= bytes;
+		vir_hw += bytes;
+		offset += bytes;
+	}
+	assert(count == 0);
+}
+
+/*===========================================================================*
+ *				dp_pio8_user2nic			     *
+ *===========================================================================*/
+static void dp_pio8_user2nic(dep, iovp, offset, nic_addr, count)
+dpeth_t *dep;
+iovec_dat_t *iovp;
+vir_bytes offset;
+int nic_addr;
+vir_bytes count;
+{
+//	phys_bytes phys_user;
+	int i;
+	vir_bytes bytes;
+
+	outb_reg0(dep, DP_ISR, ISR_RDC);
+
+	outb_reg0(dep, DP_RBCR0, count &0xFF);
+	outb_reg0(dep, DP_RBCR1, count >> 8);
+	outb_reg0(dep, DP_RSAR0, nic_addr &0xFF);
+	outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
+	outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
+
+	i= 0;
+	while (count > 0)
+	{
+		if (i >= IOVEC_NR)
+		{
+			dp_next_iovec(iovp);
+			i= 0;
+			continue;
+		}
+		assert(i < iovp->iod_iovec_s);
+		if (offset >= iovp->iod_iovec[i].iov_size)
+		{
+			offset -= iovp->iod_iovec[i].iov_size;
+			i++;
+			continue;
+		}
+		bytes = iovp->iod_iovec[i].iov_size - offset;
+		if (bytes > count)
+			bytes = count;
+
+		do_vir_outsb(dep->de_data_port, iovp->iod_proc_nr,
+			iovp->iod_iovec[i].iov_addr + offset, bytes);
+		count -= bytes;
+		offset += bytes;
+	}
+	assert(count == 0);
+
+	for (i= 0; i<100; i++)
+	{
+		if (inb_reg0(dep, DP_ISR) &ISR_RDC)
+			break;
+	}
+	if (i == 100)
+	{
+		panic("", "dp8390: remote dma failed to complete", NO_NUM);
+	}
+}
+
+/*===========================================================================*
+ *				dp_pio16_user2nic			     *
+ *===========================================================================*/
+static void dp_pio16_user2nic(dep, iovp, offset, nic_addr, count)
+dpeth_t *dep;
+iovec_dat_t *iovp;
+vir_bytes offset;
+int nic_addr;
+vir_bytes count;
+{
+	vir_bytes vir_user;
+	vir_bytes ecount;
+	int i, r, user_proc;
+	vir_bytes bytes;
+	//u8_t two_bytes[2];
+	u16_t two_bytes;
+	int odd_byte;
+
+	ecount= (count+1) &~1;
+	odd_byte= 0;
+
+	outb_reg0(dep, DP_ISR, ISR_RDC);
+	outb_reg0(dep, DP_RBCR0, ecount &0xFF);
+	outb_reg0(dep, DP_RBCR1, ecount >> 8);
+	outb_reg0(dep, DP_RSAR0, nic_addr &0xFF);
+	outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
+	outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
+
+	i= 0;
+	while (count > 0)
+	{
+		if (i >= IOVEC_NR)
+		{
+			dp_next_iovec(iovp);
+			i= 0;
+			continue;
+		}
+		assert(i < iovp->iod_iovec_s);
+		if (offset >= iovp->iod_iovec[i].iov_size)
+		{
+			offset -= iovp->iod_iovec[i].iov_size;
+			i++;
+			continue;
+		}
+		bytes = iovp->iod_iovec[i].iov_size - offset;
+		if (bytes > count)
+			bytes = count;
+
+		user_proc= iovp->iod_proc_nr;
+		vir_user= iovp->iod_iovec[i].iov_addr + offset;
+		if (odd_byte)
+		{
+			r= sys_vircopy(user_proc, D, vir_user, 
+			//	SELF, D, (vir_bytes)&two_bytes[1], 1);
+				SELF, D, (vir_bytes)&(((u8_t *)&two_bytes)[1]), 1);
+			if (r != OK)
+			{
+				panic("DP8390",
+					"dp_pio16_user2nic: sys_vircopy failed",
+					r);
+			}
+			//outw(dep->de_data_port, *(u16_t *)two_bytes);
+			outw(dep->de_data_port, two_bytes);
+			count--;
+			offset++;
+			bytes--;
+			vir_user++;
+			odd_byte= 0;
+			if (!bytes)
+				continue;
+		}
+		ecount= bytes &~1;
+		if (ecount != 0)
+		{
+			do_vir_outsw(dep->de_data_port, user_proc, vir_user,
+				ecount);
+			count -= ecount;
+			offset += ecount;
+			bytes -= ecount;
+			vir_user += ecount;
+		}
+		if (bytes)
+		{
+			assert(bytes == 1);
+			r= sys_vircopy(user_proc, D, vir_user, 
+			//	SELF, D, (vir_bytes)&two_bytes[0], 1);
+				SELF, D, (vir_bytes)&(((u8_t *)&two_bytes)[0]), 1);
+			if (r != OK)
+			{
+				panic("DP8390",
+					"dp_pio16_user2nic: sys_vircopy failed",
+					r);
+			}
+			count--;
+			offset++;
+			bytes--;
+			vir_user++;
+			odd_byte= 1;
+		}
+	}
+	assert(count == 0);
+
+	if (odd_byte)
+		//outw(dep->de_data_port, *(u16_t *)two_bytes);
+		outw(dep->de_data_port, two_bytes);
+
+	for (i= 0; i<100; i++)
+	{
+		if (inb_reg0(dep, DP_ISR) &ISR_RDC)
+			break;
+	}
+	if (i == 100)
+	{
+		panic("", "dp8390: remote dma failed to complete", NO_NUM);
+	}
+}
+
+/*===========================================================================*
+ *				dp_nic2user				     *
+ *===========================================================================*/
+static void dp_nic2user(dep, nic_addr, iovp, offset, count)
+dpeth_t *dep;
+int nic_addr;
+iovec_dat_t *iovp;
+vir_bytes offset;
+vir_bytes count;
+{
+	vir_bytes vir_hw;//, vir_user;
+	vir_bytes bytes;
+	int i, r;
+
+	vir_hw = (vir_bytes)dep->de_locmem + nic_addr;
+
+	i= 0;
+	while (count > 0)
+	{
+		if (i >= IOVEC_NR)
+		{
+			dp_next_iovec(iovp);
+			i= 0;
+			continue;
+		}
+		assert(i < iovp->iod_iovec_s);
+		if (offset >= iovp->iod_iovec[i].iov_size)
+		{
+			offset -= iovp->iod_iovec[i].iov_size;
+			i++;
+			continue;
+		}
+		bytes = iovp->iod_iovec[i].iov_size - offset;
+		if (bytes > count)
+			bytes = count;
+
+		r= sys_vircopy(SELF, D, vir_hw,
+			iovp->iod_proc_nr, D,
+			iovp->iod_iovec[i].iov_addr + offset, bytes);
+		if (r != OK)
+			panic("DP8390", "dp_nic2user: sys_vircopy failed", r);
+
+		count -= bytes;
+		vir_hw += bytes;
+		offset += bytes;
+	}
+	assert(count == 0);
+}
+
+/*===========================================================================*
+ *				dp_pio8_nic2user			     *
+ *===========================================================================*/
+static void dp_pio8_nic2user(dep, nic_addr, iovp, offset, count)
+dpeth_t *dep;
+int nic_addr;
+iovec_dat_t *iovp;
+vir_bytes offset;
+vir_bytes count;
+{
+//	phys_bytes phys_user;
+	int i;
+	vir_bytes bytes;
+
+	outb_reg0(dep, DP_RBCR0, count &0xFF);
+	outb_reg0(dep, DP_RBCR1, count >> 8);
+	outb_reg0(dep, DP_RSAR0, nic_addr &0xFF);
+	outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
+	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
+
+	i= 0;
+	while (count > 0)
+	{
+		if (i >= IOVEC_NR)
+		{
+			dp_next_iovec(iovp);
+			i= 0;
+			continue;
+		}
+		assert(i < iovp->iod_iovec_s);
+		if (offset >= iovp->iod_iovec[i].iov_size)
+		{
+			offset -= iovp->iod_iovec[i].iov_size;
+			i++;
+			continue;
+		}
+		bytes = iovp->iod_iovec[i].iov_size - offset;
+		if (bytes > count)
+			bytes = count;
+
+		do_vir_insb(dep->de_data_port, iovp->iod_proc_nr,
+			iovp->iod_iovec[i].iov_addr + offset, bytes);
+		count -= bytes;
+		offset += bytes;
+	}
+	assert(count == 0);
+}
+
+/*===========================================================================*
+ *				dp_pio16_nic2user			     *
+ *===========================================================================*/
+static void dp_pio16_nic2user(dep, nic_addr, iovp, offset, count)
+dpeth_t *dep;
+int nic_addr;
+iovec_dat_t *iovp;
+vir_bytes offset;
+vir_bytes count;
+{
+	vir_bytes vir_user;
+	vir_bytes ecount;
+	int i, r, user_proc;
+	vir_bytes bytes;
+	//u8_t two_bytes[2];
+	u16_t two_bytes;
+	int odd_byte;
+
+	ecount= (count+1) &~1;
+	odd_byte= 0;
+
+	outb_reg0(dep, DP_RBCR0, ecount &0xFF);
+	outb_reg0(dep, DP_RBCR1, ecount >> 8);
+	outb_reg0(dep, DP_RSAR0, nic_addr &0xFF);
+	outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
+	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
+
+	i= 0;
+	while (count > 0)
+	{
+		if (i >= IOVEC_NR)
+		{
+			dp_next_iovec(iovp);
+			i= 0;
+			continue;
+		}
+		assert(i < iovp->iod_iovec_s);
+		if (offset >= iovp->iod_iovec[i].iov_size)
+		{
+			offset -= iovp->iod_iovec[i].iov_size;
+			i++;
+			continue;
+		}
+		bytes = iovp->iod_iovec[i].iov_size - offset;
+		if (bytes > count)
+			bytes = count;
+
+		user_proc= iovp->iod_proc_nr;
+		vir_user= iovp->iod_iovec[i].iov_addr + offset;
+		if (odd_byte)
+		{
+			//r= sys_vircopy(SELF, D, (vir_bytes)&two_bytes[1],
+			r= sys_vircopy(SELF, D, (vir_bytes)&(((u8_t *)&two_bytes)[1]),
+				user_proc, D, vir_user,  1);
+			if (r != OK)
+			{
+				panic("DP8390",
+					"dp_pio16_nic2user: sys_vircopy failed",
+					r);
+			}
+			count--;
+			offset++;
+			bytes--;
+			vir_user++;
+			odd_byte= 0;
+			if (!bytes)
+				continue;
+		}
+		ecount= bytes &~1;
+		if (ecount != 0)
+		{
+			do_vir_insw(dep->de_data_port, user_proc, vir_user,
+				ecount);
+			count -= ecount;
+			offset += ecount;
+			bytes -= ecount;
+			vir_user += ecount;
+		}
+		if (bytes)
+		{
+			assert(bytes == 1);
+			//*(u16_t *)two_bytes= inw(dep->de_data_port);
+			two_bytes= inw(dep->de_data_port);
+			//r= sys_vircopy(SELF, D, (vir_bytes)&two_bytes[0],
+			r= sys_vircopy(SELF, D, (vir_bytes)&(((u8_t *)&two_bytes)[0]),
+				user_proc, D, vir_user,  1);
+			if (r != OK)
+			{
+				panic("DP8390",
+					"dp_pio16_nic2user: sys_vircopy failed",
+					r);
+			}
+			count--;
+			offset++;
+			bytes--;
+			vir_user++;
+			odd_byte= 1;
+		}
+	}
+	assert(count == 0);
+}
+
+/*===========================================================================*
+ *				dp_next_iovec				     *
+ *===========================================================================*/
+static void dp_next_iovec(iovp)
+iovec_dat_t *iovp;
+{
+	assert(iovp->iod_iovec_s > IOVEC_NR);
+
+	iovp->iod_iovec_s -= IOVEC_NR;
+
+	iovp->iod_iovec_addr += IOVEC_NR * sizeof(iovec_t);
+
+	get_userdata(iovp->iod_proc_nr, iovp->iod_iovec_addr, 
+		(iovp->iod_iovec_s > IOVEC_NR ? IOVEC_NR : iovp->iod_iovec_s) *
+		sizeof(iovec_t), iovp->iod_iovec); 
+}
+
+/*===========================================================================*
+ *				conf_hw					     *
+ *===========================================================================*/
+static void conf_hw(dep)
+dpeth_t *dep;
+{
+//	static eth_stat_t empty_stat = {0, 0, 0, 0, 0, 0 	/* ,... */};
+
+//	int ifnr;
+//	dp_conf_t *dcp;
+
+//	dep->de_mode= DEM_DISABLED;	/* Superfluous */
+//	ifnr= dep-de_table;
+
+//	dcp= &dp_conf[ifnr];
+//	update_conf(dep, dcp);
+//	if (dep->de_mode != DEM_ENABLED)
+//		return;
+	if (!wdeth_probe(dep) && !ne_probe(dep) && !el2_probe(dep))
+	{
+		printf("%s: No ethernet card found at 0x%x\n", 
+			dep->de_name, dep->de_base_port);
+		dep->de_mode= DEM_DISABLED;
+		return;
+	}
+
+/* XXX */ if (dep->de_linmem == 0) dep->de_linmem= 0xFFFF0000;
+
+	dep->de_mode = DEM_ENABLED;
+
+	dep->de_flags = DEF_EMPTY;
+//	dep->de_stat = empty_stat;
+}
+
+/*===========================================================================*
+ *				map_hw_buffer				     *
+ *===========================================================================*/
+static void map_hw_buffer(dep)
+dpeth_t *dep;
+{
+//	int r;
+//	size_t o, size;
+//	char *buf, *abuf;
+
+	if (dep->de_prog_IO)
+	{
+#if 0
+		if(debug){
+			printf(
+			"map_hw_buffer: programmed I/O, no need to map buffer\n");
+		}
+#endif
+		dep->de_locmem = (char *)-dep->de_ramsize; /* trap errors */
+		return;
+	}else{
+		printf("map_hw_buffer: no buffer!\n");
+	}
+
+//	size = dep->de_ramsize + PAGE_SIZE;	/* Add PAGE_SIZE for
+//						 * alignment
+//						 */
+//	buf= malloc(size);
+//	if (buf == NULL)
+//		panic(__FILE__, "map_hw_buffer: cannot malloc size", size);
+//	o= PAGE_SIZE - ((vir_bytes)buf % PAGE_SIZE);
+//	abuf= buf + o;
+//	printf("buf at 0x%x, abuf at 0x%x\n", buf, abuf);
+
+//	r= sys_vm_map(SELF, 1 /* map */, (vir_bytes)abuf,
+//			dep->de_ramsize, (phys_bytes)dep->de_linmem);
+//	if (r != OK)
+//		panic(__FILE__, "map_hw_buffer: sys_vm_map failed", r);
+//	dep->de_locmem = abuf;
+}
+
+/*===========================================================================*
+ *				reply					     *
+ *===========================================================================*/
+static void reply(dep, err, may_block)
+dpeth_t *dep;
+int err;
+int may_block;
+{
+/*	message reply;
+	int status;
+	int r;
+
+	status = 0;
+	if (dep->de_flags &DEF_PACK_SEND)
+		status |= DL_PACK_SEND;
+	if (dep->de_flags &DEF_PACK_RECV)
+		status |= DL_PACK_RECV;
+
+	reply.m_type = DL_TASK_REPLY;
+	reply.DL_PORT = dep - de_table;
+	reply.DL_PROC = dep->de_client;
+	reply.DL_STAT = status | ((u32_t) err << 16);
+	reply.DL_COUNT = dep->de_read_s;
+	reply.DL_CLCK = 0;	*//* Don't know */
+/*	r= send(dep->de_client, &reply);
+
+	if (r == ELOCKED && may_block)
+	{
+#if 0
+		printf("send locked\n");
+#endif
+		return;
+	}
+
+	if (r < 0)
+		panic("", "dp8390: send failed:", r);
+	
+*/	dep->de_read_s = 0;
+//	dep->de_flags &= ~(DEF_PACK_SEND | DEF_PACK_RECV);
+}
+
+/*===========================================================================*
+ *				get_userdata				     *
+ *===========================================================================*/
+static void get_userdata(user_proc, user_addr, count, loc_addr)
+int user_proc;
+vir_bytes user_addr;
+vir_bytes count;
+void *loc_addr;
+{
+	int r;
+
+	r= sys_vircopy(user_proc, D, user_addr,
+		SELF, D, (vir_bytes)loc_addr, count);
+	if (r != OK)
+		panic("DP8390", "get_userdata: sys_vircopy failed", r);
+}
+
+static void insb(port_t port, void *buf, size_t size)
+{
+	size_t i;
+
+	for(i = 0; i < size; ++ i){
+		*((uint8_t *) buf + i) = inb(port);
+	}
+}
+
+static void insw(port_t port, void *buf, size_t size)
+{
+	size_t i;
+
+	for(i = 0; i * 2 < size; ++ i){
+		*((uint16_t *) buf + i) = inw(port);
+	}
+}
+
+static void outsb(port_t port, void *buf, size_t size)
+{
+	size_t i;
+
+	for(i = 0; i < size; ++ i){
+		outb(port, *((uint8_t *) buf + i));
+	}
+}
+
+static void outsw(port_t port, void *buf, size_t size)
+{
+	size_t i;
+
+	for(i = 0; i * 2 < size; ++ i){
+		outw(port, *((uint16_t *) buf + i));
+	}
+}
+
+/*
+ * $PchId: dp8390.c,v 1.25 2005/02/10 17:32:07 philip Exp $
+ */
+
+/** @}
+ */
Index: uspace/srv/hw/netif/dp8390/dp8390.h
===================================================================
--- uspace/srv/hw/netif/dp8390/dp8390.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/hw/netif/dp8390/dp8390.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,431 @@
+/*
+ * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system 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.
+ * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+ * * Any deviations from these conditions require written permission from the copyright holder in advance
+ *
+ *
+ * Disclaimer
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``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 COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS 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.
+ *
+ * Changes:
+ *  2009 ported to HelenOS, Lukas Mejdrech
+ */
+
+/** @addtogroup dp8390
+ *  @{
+ */
+
+/** @file
+ *  DP8390 network interface definitions.
+ */
+
+#ifndef __NET_NETIF_DP8390_H__
+#define __NET_NETIF_DP8390_H__
+
+#include <packet/packet.h>
+
+#include "dp8390_port.h"
+#include "local.h"
+
+/** Input/output size.
+ */
+#define DP8390_IO_SIZE	0x01f
+
+/*
+dp8390.h
+
+Created:	before Dec 28, 1992 by Philip Homburg
+*/
+
+/* National Semiconductor DP8390 Network Interface Controller. */
+
+				/* Page 0, for reading ------------- */
+#define	DP_CR		0x0	/* Read side of Command Register     */
+#define	DP_CLDA0	0x1	/* Current Local Dma Address 0       */
+#define	DP_CLDA1	0x2	/* Current Local Dma Address 1       */
+#define	DP_BNRY		0x3	/* Boundary Pointer                  */
+#define	DP_TSR		0x4	/* Transmit Status Register          */
+#define	DP_NCR		0x5	/* Number of Collisions Register     */
+#define	DP_FIFO		0x6	/* Fifo ??                           */
+#define	DP_ISR		0x7	/* Interrupt Status Register         */
+#define	DP_CRDA0	0x8	/* Current Remote Dma Address 0      */
+#define	DP_CRDA1	0x9	/* Current Remote Dma Address 1      */
+#define	DP_DUM1		0xA	/* unused                            */
+#define	DP_DUM2		0xB	/* unused                            */
+#define	DP_RSR		0xC	/* Receive Status Register           */
+#define	DP_CNTR0	0xD	/* Tally Counter 0                   */
+#define	DP_CNTR1	0xE	/* Tally Counter 1                   */
+#define	DP_CNTR2	0xF	/* Tally Counter 2                   */
+
+				/* Page 0, for writing ------------- */
+#define	DP_CR		0x0	/* Write side of Command Register    */
+#define	DP_PSTART	0x1	/* Page Start Register               */
+#define	DP_PSTOP	0x2	/* Page Stop Register                */
+#define	DP_BNRY		0x3	/* Boundary Pointer                  */
+#define	DP_TPSR		0x4	/* Transmit Page Start Register      */
+#define	DP_TBCR0	0x5	/* Transmit Byte Count Register 0    */
+#define	DP_TBCR1	0x6	/* Transmit Byte Count Register 1    */
+#define	DP_ISR		0x7	/* Interrupt Status Register         */
+#define	DP_RSAR0	0x8	/* Remote Start Address Register 0   */
+#define	DP_RSAR1	0x9	/* Remote Start Address Register 1   */
+#define	DP_RBCR0	0xA	/* Remote Byte Count Register 0      */
+#define	DP_RBCR1	0xB	/* Remote Byte Count Register 1      */
+#define	DP_RCR		0xC	/* Receive Configuration Register    */
+#define	DP_TCR		0xD	/* Transmit Configuration Register   */
+#define	DP_DCR		0xE	/* Data Configuration Register       */
+#define	DP_IMR		0xF	/* Interrupt Mask Register           */
+
+				/* Page 1, read/write -------------- */
+#define	DP_CR		0x0	/* Command Register                  */
+#define	DP_PAR0		0x1	/* Physical Address Register 0       */
+#define	DP_PAR1		0x2	/* Physical Address Register 1       */
+#define	DP_PAR2		0x3	/* Physical Address Register 2       */
+#define	DP_PAR3		0x4	/* Physical Address Register 3       */
+#define	DP_PAR4		0x5	/* Physical Address Register 4       */
+#define	DP_PAR5		0x6	/* Physical Address Register 5       */
+#define	DP_CURR		0x7	/* Current Page Register             */
+#define	DP_MAR0		0x8	/* Multicast Address Register 0      */
+#define	DP_MAR1		0x9	/* Multicast Address Register 1      */
+#define	DP_MAR2		0xA	/* Multicast Address Register 2      */
+#define	DP_MAR3		0xB	/* Multicast Address Register 3      */
+#define	DP_MAR4		0xC	/* Multicast Address Register 4      */
+#define	DP_MAR5		0xD	/* Multicast Address Register 5      */
+#define	DP_MAR6		0xE	/* Multicast Address Register 6      */
+#define	DP_MAR7		0xF	/* Multicast Address Register 7      */
+
+/* Bits in dp_cr */
+#define CR_STP		0x01	/* Stop: software reset              */
+#define CR_STA		0x02	/* Start: activate NIC               */
+#define CR_TXP		0x04	/* Transmit Packet                   */
+#define CR_DMA		0x38	/* Mask for DMA control              */
+#define CR_DM_NOP	0x00	/* DMA: No Operation                 */
+#define CR_DM_RR	0x08	/* DMA: Remote Read                  */
+#define CR_DM_RW	0x10	/* DMA: Remote Write                 */
+#define CR_DM_SP	0x18	/* DMA: Send Packet                  */
+#define CR_DM_ABORT	0x20	/* DMA: Abort Remote DMA Operation   */
+#define CR_PS		0xC0	/* Mask for Page Select              */
+#define CR_PS_P0	0x00	/* Register Page 0                   */
+#define CR_PS_P1	0x40	/* Register Page 1                   */
+#define CR_PS_P2	0x80	/* Register Page 2                   */
+#define CR_PS_T1	0xC0	/* Test Mode Register Map            */
+
+/* Bits in dp_isr */
+#define ISR_PRX		0x01	/* Packet Received with no errors    */
+#define ISR_PTX		0x02	/* Packet Transmitted with no errors */
+#define ISR_RXE		0x04	/* Receive Error                     */
+#define ISR_TXE		0x08	/* Transmit Error                    */
+#define ISR_OVW		0x10	/* Overwrite Warning                 */
+#define ISR_CNT		0x20	/* Counter Overflow                  */
+#define ISR_RDC		0x40	/* Remote DMA Complete               */
+#define ISR_RST		0x80	/* Reset Status                      */
+
+/* Bits in dp_imr */
+#define IMR_PRXE	0x01	/* Packet Received iEnable           */
+#define IMR_PTXE	0x02	/* Packet Transmitted iEnable        */
+#define IMR_RXEE	0x04	/* Receive Error iEnable             */
+#define IMR_TXEE	0x08	/* Transmit Error iEnable            */
+#define IMR_OVWE	0x10	/* Overwrite Warning iEnable         */
+#define IMR_CNTE	0x20	/* Counter Overflow iEnable          */
+#define IMR_RDCE	0x40	/* DMA Complete iEnable              */
+
+/* Bits in dp_dcr */
+#define DCR_WTS		0x01	/* Word Transfer Select              */
+#define DCR_BYTEWIDE	0x00	/* WTS: byte wide transfers          */
+#define DCR_WORDWIDE	0x01	/* WTS: word wide transfers          */
+#define DCR_BOS		0x02	/* Byte Order Select                 */
+#define DCR_LTLENDIAN	0x00	/* BOS: Little Endian                */
+#define DCR_BIGENDIAN	0x02	/* BOS: Big Endian                   */
+#define DCR_LAS		0x04	/* Long Address Select               */
+#define DCR_BMS		0x08	/* Burst Mode Select
+				 * Called Loopback Select (LS) in 
+				 * later manuals. Should be set.     */
+#define DCR_AR		0x10	/* Autoinitialize Remote             */
+#define DCR_FTS		0x60	/* Fifo Threshold Select             */
+#define DCR_2BYTES	0x00	/* 2 bytes                           */
+#define DCR_4BYTES	0x40	/* 4 bytes                           */
+#define DCR_8BYTES	0x20	/* 8 bytes                           */
+#define DCR_12BYTES	0x60	/* 12 bytes                          */
+
+/* Bits in dp_tcr */
+#define TCR_CRC		0x01	/* Inhibit CRC                       */
+#define TCR_ELC		0x06	/* Encoded Loopback Control          */
+#define TCR_NORMAL	0x00	/* ELC: Normal Operation             */
+#define TCR_INTERNAL	0x02	/* ELC: Internal Loopback            */
+#define TCR_0EXTERNAL	0x04	/* ELC: External Loopback LPBK=0     */
+#define TCR_1EXTERNAL	0x06	/* ELC: External Loopback LPBK=1     */
+#define TCR_ATD		0x08	/* Auto Transmit Disable             */
+#define TCR_OFST	0x10	/* Collision Offset Enable (be nice) */
+
+/* Bits in dp_tsr */
+#define TSR_PTX		0x01	/* Packet Transmitted (without error)*/
+#define TSR_DFR		0x02	/* Transmit Deferred, reserved in
+				 * later manuals.		     */
+#define TSR_COL		0x04	/* Transmit Collided                 */
+#define TSR_ABT		0x08	/* Transmit Aborted                  */
+#define TSR_CRS		0x10	/* Carrier Sense Lost                */
+#define TSR_FU		0x20	/* FIFO Underrun                     */
+#define TSR_CDH		0x40	/* CD Heartbeat                      */
+#define TSR_OWC		0x80	/* Out of Window Collision           */
+
+/* Bits in tp_rcr */
+#define RCR_SEP		0x01	/* Save Errored Packets              */
+#define RCR_AR		0x02	/* Accept Runt Packets               */
+#define RCR_AB		0x04	/* Accept Broadcast                  */
+#define RCR_AM		0x08	/* Accept Multicast                  */
+#define RCR_PRO		0x10	/* Physical Promiscuous              */
+#define RCR_MON		0x20	/* Monitor Mode                      */
+
+/* Bits in dp_rsr */
+#define RSR_PRX		0x01	/* Packet Received Intact            */
+#define RSR_CRC		0x02	/* CRC Error                         */
+#define RSR_FAE		0x04	/* Frame Alignment Error             */
+#define RSR_FO		0x08	/* FIFO Overrun                      */
+#define RSR_MPA		0x10	/* Missed Packet                     */
+#define RSR_PHY		0x20	/* Multicast Address Match           */
+#define RSR_DIS		0x40	/* Receiver Disabled                 */
+#define RSR_DFR		0x80	/* In later manuals: Deferring       */
+
+/** Type definition of the receive header.
+ */
+typedef struct dp_rcvhdr
+{
+	/** Copy of rsr.
+	 */
+	u8_t dr_status;
+	/** Pointer to next packet.
+	 */
+	u8_t dr_next;
+	/** Receive Byte Count Low.
+	 */
+	u8_t dr_rbcl;
+	/** Receive Byte Count High.
+	 */
+	u8_t dr_rbch;
+} dp_rcvhdr_t;
+
+/** Page size.
+ */
+#define DP_PAGESIZE	256
+
+/* Some macros to simplify accessing the dp8390 */
+/** Reads 1 byte from the zero page register.
+ *  @param[in] dep The network interface structure.
+ *  @param[in] reg The register offset.
+ *  @returns The read value.
+ */
+#define inb_reg0(dep, reg)		(inb(dep->de_dp8390_port+reg))
+
+/** Writes 1 byte zero page register.
+ *  @param[in] dep The network interface structure.
+ *  @param[in] reg The register offset.
+ *  @param[in] data The value to be written.
+ */
+#define outb_reg0(dep, reg, data)	(outb(dep->de_dp8390_port+reg, data))
+
+/** Reads 1 byte from the first page register.
+ *  @param[in] dep The network interface structure.
+ *  @param[in] reg The register offset.
+ *  @returns The read value.
+ */
+#define inb_reg1(dep, reg)		(inb(dep->de_dp8390_port+reg))
+
+/** Writes 1 byte first page register.
+ *  @param[in] dep The network interface structure.
+ *  @param[in] reg The register offset.
+ *  @param[in] data The value to be written.
+ */
+#define outb_reg1(dep, reg, data)	(outb(dep->de_dp8390_port+reg, data))
+
+/* Software interface to the dp8390 driver */
+
+struct dpeth;
+struct iovec_dat;
+//struct iovec_dat_s;
+_PROTOTYPE(typedef void (*dp_initf_t), (struct dpeth *dep)		);
+_PROTOTYPE(typedef void (*dp_stopf_t), (struct dpeth *dep)		);
+_PROTOTYPE(typedef void (*dp_user2nicf_t), (struct dpeth *dep,
+			struct iovec_dat *iovp, vir_bytes offset,
+			int nic_addr, vir_bytes count) );
+//_PROTOTYPE(typedef void (*dp_user2nicf_s_t), (struct dpeth *dep,
+//			struct iovec_dat_s *iovp, vir_bytes offset,
+//			int nic_addr, vir_bytes count)			);
+_PROTOTYPE(typedef void (*dp_nic2userf_t), (struct dpeth *dep,
+			int nic_addr, struct iovec_dat *iovp,
+			vir_bytes offset, vir_bytes count) );
+//_PROTOTYPE(typedef void (*dp_nic2userf_s_t), (struct dpeth *dep,
+//			int nic_addr, struct iovec_dat_s *iovp,
+//			vir_bytes offset, vir_bytes count)		);
+//#if 0
+//_PROTOTYPE(typedef void (*dp_getheaderf_t), (struct dpeth *dep,
+//			int page, struct dp_rcvhdr *h, u16_t *eth_type)	);
+//#endif
+_PROTOTYPE(typedef void (*dp_getblock_t), (struct dpeth *dep,
+		int page, size_t offset, size_t size, void *dst)	);
+
+/* iovectors are handled IOVEC_NR entries at a time. */
+//#define IOVEC_NR	16
+// no vectors allowed
+#define IOVEC_NR	1
+
+/*
+typedef int irq_hook_t;
+*/
+typedef struct iovec_dat
+{
+  iovec_t iod_iovec[IOVEC_NR];
+  int iod_iovec_s;
+  // no direct process access
+  int iod_proc_nr;
+  vir_bytes iod_iovec_addr;
+} iovec_dat_t;
+/*
+typedef struct iovec_dat_s
+{
+  iovec_s_t iod_iovec[IOVEC_NR];
+  int iod_iovec_s;
+  int iod_proc_nr;
+  cp_grant_id_t iod_grant;
+  vir_bytes iod_iovec_offset;
+} iovec_dat_s_t;
+*/
+#define SENDQ_NR	1	/* Maximum size of the send queue */
+#define SENDQ_PAGES	6	/* 6 * DP_PAGESIZE >= 1514 bytes */
+
+/** Maximum number of waiting packets to be sent or received.
+ */
+#define MAX_PACKETS	4
+
+typedef struct dpeth
+{
+	/** Outgoing packets queue.
+	 */
+	packet_t packet_queue;
+	/** Outgoing packets count.
+	 */
+	int packet_count;
+
+	/** Received packets queue.
+	 */
+	packet_t received_queue;
+	/** Received packets count.
+	 */
+	int received_count;
+
+	/* The de_base_port field is the starting point of the probe.
+	 * The conf routine also fills de_linmem and de_irq. If the probe
+	 * routine knows the irq and/or memory address because they are
+	 * hardwired in the board, the probe should modify these fields.
+	 * Futhermore, the probe routine should also fill in de_initf and
+	 * de_stopf fields with the appropriate function pointers and set
+	 * de_prog_IO iff programmed I/O is to be used.
+	 */
+	port_t de_base_port;
+	phys_bytes de_linmem;
+	char *de_locmem;
+	int de_irq;
+	int de_int_pending;
+//	irq_hook_t de_hook;
+	dp_initf_t de_initf; 
+	dp_stopf_t de_stopf; 
+	int de_prog_IO;
+	char de_name[sizeof("dp8390#n")];
+
+	/* The initf function fills the following fields. Only cards that do
+	 * programmed I/O fill in the de_pata_port field.
+	 * In addition, the init routine has to fill in the sendq data
+	 * structures.
+	 */
+	ether_addr_t de_address;
+	port_t de_dp8390_port;
+	port_t de_data_port;
+	int de_16bit;
+	long de_ramsize;
+	int de_offset_page;
+	int de_startpage;
+	int de_stoppage;
+
+	/* should be here - read even for ne2k isa init... */
+	char de_pci;			/* TRUE iff PCI device */
+
+#if ENABLE_PCI
+	/* PCI config */
+//	char de_pci;			/* TRUE iff PCI device */
+//	u8_t de_pcibus;	
+//	u8_t de_pcidev;	
+//	u8_t de_pcifunc;	
+#endif
+
+	/* Do it yourself send queue */
+	struct sendq
+	{
+		int sq_filled;		/* this buffer contains a packet */
+		int sq_size;		/* with this size */
+		int sq_sendpage;	/* starting page of the buffer */
+	} de_sendq[SENDQ_NR];
+	int de_sendq_nr;
+	int de_sendq_head;		/* Enqueue at the head */
+	int de_sendq_tail;		/* Dequeue at the tail */
+
+	/* Fields for internal use by the dp8390 driver. */
+	int de_flags;
+	int de_mode;
+	eth_stat_t de_stat;
+	iovec_dat_t de_read_iovec;
+//	iovec_dat_s_t de_read_iovec_s;
+//	int de_safecopy_read;
+	iovec_dat_t de_write_iovec;
+//	iovec_dat_s_t de_write_iovec_s;
+	iovec_dat_t de_tmp_iovec;
+//	iovec_dat_s_t de_tmp_iovec_s;
+	vir_bytes de_read_s;
+//	int de_client;
+//	message de_sendmsg;
+	dp_user2nicf_t de_user2nicf; 
+//	dp_user2nicf_s_t de_user2nicf_s; 
+	dp_nic2userf_t de_nic2userf;
+//	dp_nic2userf_s_t de_nic2userf_s; 
+	dp_getblock_t de_getblockf;
+} dpeth_t;
+
+#define DEI_DEFAULT	0x8000
+
+#define DEF_EMPTY	0x000
+#define DEF_PACK_SEND	0x001
+#define DEF_PACK_RECV	0x002
+#define DEF_SEND_AVAIL	0x004
+#define DEF_READING	0x010
+#define DEF_PROMISC	0x040
+#define DEF_MULTI	0x080
+#define DEF_BROAD	0x100
+#define DEF_ENABLED	0x200
+#define DEF_STOPPED	0x400
+
+#define DEM_DISABLED	0x0
+#define DEM_SINK	0x1
+#define DEM_ENABLED	0x2
+
+//#if !__minix_vmd
+#define debug		1	/* Standard Minix lacks debug variable */
+//#endif
+
+/*
+ * $PchId: dp8390.h,v 1.10 2005/02/10 17:26:06 philip Exp $
+ */
+
+#endif
+
+/** @}
+ */
Index: uspace/srv/hw/netif/dp8390/dp8390_drv.h
===================================================================
--- uspace/srv/hw/netif/dp8390/dp8390_drv.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/hw/netif/dp8390/dp8390_drv.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,84 @@
+/*
+ * 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 dp8390
+ *  @{
+ */
+
+/** @file
+ *  DP8390 network interface driver interface.
+ */
+
+#ifndef __NET_NETIF_DP8390_DRIVER_H__
+#define __NET_NETIF_DP8390_DRIVER_H__
+
+#include "dp8390.h"
+
+/** Initializes and/or starts the network interface.
+ *  @param[in,out] dep The network interface structure.
+ *  @param[in] mode The state mode.
+ *  @returns EOK on success.
+ *  @returns EXDEV if the network interface is disabled.
+ */
+int do_init(dpeth_t *dep, int mode);
+
+/** Stops the network interface.
+ *  @param[in,out] dep The network interface structure.
+ */
+void do_stop(dpeth_t *dep);
+
+/** Processes the interrupt.
+ *  @param[in,out] dep The network interface structure.
+ *  @param[in] isr The interrupt status register.
+ */
+void dp_check_ints(dpeth_t *dep, int isr);
+
+/** Probes and initializes the network interface.
+ *  @param[in,out] dep The network interface structure.
+ *  @returns EOK on success.
+ *  @returns EXDEV if the network interface was not recognized.
+ */
+int do_probe(dpeth_t * dep);
+
+/** Sends a packet.
+ *  @param[in,out] dep The network interface structure.
+ *  @param[in] packet The packet t be sent.
+ *  @param[in] from_int The value indicating whether the sending is initialized from the interrupt handler.
+ *  @returns 
+ */
+int do_pwrite(dpeth_t * dep, packet_t packet, int from_int);
+
+/** Prints out network interface information.
+ *  @param[in] dep The network interface structure.
+ */
+void dp8390_dump(dpeth_t * dep);
+
+#endif
+
+/** @}
+ */
Index: uspace/srv/hw/netif/dp8390/dp8390_module.c
===================================================================
--- uspace/srv/hw/netif/dp8390/dp8390_module.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/hw/netif/dp8390/dp8390_module.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,363 @@
+/*
+ * 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 dp8390
+ *  @{
+ */
+
+/** @file
+ *  DP8390 network interface implementation.
+ */
+
+#include <assert.h>
+#include <async.h>
+#include <ddi.h>
+#include <errno.h>
+#include <malloc.h>
+#include <ipc/ipc.h>
+#include <ipc/services.h>
+
+#include <net_err.h>
+#include <net_messages.h>
+#include <net_modules.h>
+#include <packet/packet_client.h>
+#include <adt/measured_strings.h>
+#include <net_device.h>
+#include <nil_interface.h>
+#include <netif_interface.h>
+#include <netif_local.h>
+
+#include "dp8390.h"
+#include "dp8390_drv.h"
+#include "dp8390_port.h"
+
+/** DP8390 module name.
+ */
+#define NAME  "dp8390"
+
+/** Returns the device from the interrupt call.
+ *  @param[in] call The interrupt call.
+ */
+#define IRQ_GET_DEVICE(call)			(device_id_t) IPC_GET_METHOD(*call)
+
+/** Returns the interrupt status register from the interrupt call.
+ *  @param[in] call The interrupt call.
+ */
+#define IPC_GET_ISR(call)				(int) IPC_GET_ARG2(*call)
+
+/** DP8390 kernel interrupt command sequence.
+ */
+static irq_cmd_t	dp8390_cmds[] = {
+	{	.cmd = CMD_PIO_READ_8,
+		.addr = NULL,
+		.dstarg = 2
+	},
+	{
+		.cmd = CMD_PREDICATE,
+		.value = 1,
+		.srcarg = 2
+	},
+	{
+		.cmd = CMD_ACCEPT
+	}
+};
+
+/** DP8390 kernel interrupt code.
+ */
+static irq_code_t	dp8390_code = {
+	sizeof(dp8390_cmds) / sizeof(irq_cmd_t),
+	dp8390_cmds
+};
+
+/** Handles the interrupt messages.
+ *  This is the interrupt handler callback function.
+ *  @param[in] iid The interrupt message identifier.
+ *  @param[in] call The interrupt message.
+ */
+static void irq_handler(ipc_callid_t iid, ipc_call_t * call)
+{
+	netif_device_t * device;
+	dpeth_t * dep;
+	packet_t received;
+	device_id_t device_id;
+	int phone;
+
+	device_id = IRQ_GET_DEVICE(call);
+	fibril_rwlock_write_lock(&netif_globals.lock);
+	if(find_device(device_id, &device) != EOK){
+		fibril_rwlock_write_unlock(&netif_globals.lock);
+		return;
+	}
+	dep = (dpeth_t *) device->specific;
+	if (dep->de_mode != DEM_ENABLED){
+		fibril_rwlock_write_unlock(&netif_globals.lock);
+		return;
+	}
+	assert(dep->de_flags &DEF_ENABLED);
+	dep->de_int_pending = 0;
+	dp_check_ints(dep, IPC_GET_ISR(call));
+	if(dep->received_queue){
+		received = dep->received_queue;
+		phone = device->nil_phone;
+		dep->received_queue = NULL;
+		dep->received_count = 0;
+		fibril_rwlock_write_unlock(&netif_globals.lock);
+		nil_received_msg(phone, device_id, received, NULL);
+	}else{
+		fibril_rwlock_write_unlock(&netif_globals.lock);
+	}
+	ipc_answer_0(iid, EOK);
+}
+
+/** Changes the network interface state.
+ *  @param[in,out] device The network interface.
+ *  @param[in] state The new state.
+ *  @returns The new state.
+ */
+static int change_state(netif_device_t * device, device_state_t state)
+{
+	if (device->state != state) {
+		device->state = state;
+		
+		printf("%s: State changed to %s\n", NAME,
+		    (state == NETIF_ACTIVE) ? "active" : "stopped");
+		
+		return state;
+	}
+	
+	return EOK;
+}
+
+int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+	return ENOTSUP;
+}
+
+int netif_get_device_stats(device_id_t device_id, device_stats_ref stats){
+	ERROR_DECLARE;
+
+	netif_device_t * device;
+	eth_stat_t * de_stat;
+
+	if(! stats){
+		return EBADMEM;
+	}
+	ERROR_PROPAGATE(find_device(device_id, &device));
+	de_stat = &((dpeth_t *) device->specific)->de_stat;
+	null_device_stats(stats);
+	stats->receive_errors = de_stat->ets_recvErr;
+	stats->send_errors = de_stat->ets_sendErr;
+	stats->receive_crc_errors = de_stat->ets_CRCerr;
+	stats->receive_frame_errors = de_stat->ets_frameAll;
+	stats->receive_missed_errors = de_stat->ets_missedP;
+	stats->receive_packets = de_stat->ets_packetR;
+	stats->send_packets = de_stat->ets_packetT;
+	stats->collisions = de_stat->ets_collision;
+	stats->send_aborted_errors = de_stat->ets_transAb;
+	stats->send_carrier_errors = de_stat->ets_carrSense;
+	stats->send_heartbeat_errors = de_stat->ets_CDheartbeat;
+	stats->send_window_errors = de_stat->ets_OWC;
+	return EOK;
+}
+
+int netif_get_addr_message(device_id_t device_id, measured_string_ref address){
+	ERROR_DECLARE;
+
+	netif_device_t * device;
+
+	if(! address){
+		return EBADMEM;
+	}
+	ERROR_PROPAGATE(find_device(device_id, &device));
+	address->value = (char *) (&((dpeth_t *) device->specific)->de_address);
+	address->length = CONVERT_SIZE(ether_addr_t, char, 1);
+	return EOK;
+}
+
+
+
+int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){
+	ERROR_DECLARE;
+
+	netif_device_t * device;
+	dpeth_t * dep;
+
+	device = (netif_device_t *) malloc(sizeof(netif_device_t));
+	if(! device){
+		return ENOMEM;
+	}
+	dep = (dpeth_t *) malloc(sizeof(dpeth_t));
+	if(! dep){
+		free(device);
+		return ENOMEM;
+	}
+	bzero(device, sizeof(netif_device_t));
+	bzero(dep, sizeof(dpeth_t));
+	device->device_id = device_id;
+	device->nil_phone = -1;
+	device->specific = (void *) dep;
+	device->state = NETIF_STOPPED;
+	dep->de_irq = irq;
+	dep->de_mode = DEM_DISABLED;
+	//TODO address?
+	if(ERROR_OCCURRED(pio_enable((void *) io, DP8390_IO_SIZE, (void **) &dep->de_base_port))
+		|| ERROR_OCCURRED(do_probe(dep))){
+		free(dep);
+		free(device);
+		return ERROR_CODE;
+	}
+	if(ERROR_OCCURRED(netif_device_map_add(&netif_globals.device_map, device->device_id, device))){
+		free(dep);
+		free(device);
+		return ERROR_CODE;
+	}
+	return EOK;
+}
+
+int netif_send_message(device_id_t device_id, packet_t packet, services_t sender){
+	ERROR_DECLARE;
+
+	netif_device_t * device;
+	dpeth_t * dep;
+	packet_t next;
+
+	ERROR_PROPAGATE(find_device(device_id, &device));
+	if(device->state != NETIF_ACTIVE){
+		netif_pq_release(packet_get_id(packet));
+		return EFORWARD;
+	}
+	dep = (dpeth_t *) device->specific;
+	// process packet queue
+	do{
+		next = pq_detach(packet);
+		if(do_pwrite(dep, packet, FALSE) != EBUSY){
+			netif_pq_release(packet_get_id(packet));
+		}
+		packet = next;
+	}while(packet);
+	return EOK;
+}
+
+int netif_start_message(netif_device_t * device){
+	ERROR_DECLARE;
+
+	dpeth_t * dep;
+
+	if(device->state != NETIF_ACTIVE){
+		dep = (dpeth_t *) device->specific;
+		dp8390_cmds[0].addr = (void *) (uintptr_t) (dep->de_dp8390_port + DP_ISR);
+		dp8390_cmds[2].addr = dp8390_cmds[0].addr;
+		ERROR_PROPAGATE(ipc_register_irq(dep->de_irq, device->device_id, device->device_id, &dp8390_code));
+		if(ERROR_OCCURRED(do_init(dep, DL_BROAD_REQ))){
+			ipc_unregister_irq(dep->de_irq, device->device_id);
+			return ERROR_CODE;
+		}
+		return change_state(device, NETIF_ACTIVE);
+	}
+	return EOK;
+}
+
+int netif_stop_message(netif_device_t * device){
+	dpeth_t * dep;
+
+	if(device->state != NETIF_STOPPED){
+		dep = (dpeth_t *) device->specific;
+		do_stop(dep);
+		ipc_unregister_irq(dep->de_irq, device->device_id);
+		return change_state(device, NETIF_STOPPED);
+	}
+	return EOK;
+}
+
+int netif_initialize(void){
+	ipcarg_t phonehash;
+
+	async_set_interrupt_received(irq_handler);
+
+	return REGISTER_ME(SERVICE_DP8390, &phonehash);
+}
+
+/** Default thread for new connections.
+ *
+ *  @param[in] iid The initial message identifier.
+ *  @param[in] icall The initial message call structure.
+ *
+ */
+static void netif_client_connection(ipc_callid_t iid, ipc_call_t * icall)
+{
+	/*
+	 * Accept the connection
+	 *  - Answer the first IPC_M_CONNECT_ME_TO call.
+	 */
+	ipc_answer_0(iid, EOK);
+	
+	while(true) {
+		ipc_call_t answer;
+		int answer_count;
+		
+		/* Clear the answer structure */
+		refresh_answer(&answer, &answer_count);
+		
+		/* Fetch the next message */
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		/* Process the message */
+		int res = netif_module_message(NAME, callid, &call, &answer,
+		    &answer_count);
+		
+		/* End if said to either by the message or the processing result */
+		if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
+			return;
+		
+		/* Answer the message */
+		answer_call(callid, res, &answer, answer_count);
+	}
+}
+
+/** Starts the module.
+ *
+ *  @param argc The count of the command line arguments. Ignored parameter.
+ *  @param argv The command line parameters. Ignored parameter.
+ *
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for each specific module start function.
+ *
+ */
+int main(int argc, char *argv[])
+{
+	ERROR_DECLARE;
+	
+	/* Start the module */
+	if (ERROR_OCCURRED(netif_module_start(netif_client_connection)))
+		return ERROR_CODE;
+	
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/srv/hw/netif/dp8390/dp8390_port.h
===================================================================
--- uspace/srv/hw/netif/dp8390/dp8390_port.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/hw/netif/dp8390/dp8390_port.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,274 @@
+/*
+ * 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 dp8390
+ *  @{
+ */
+
+/** @file
+ *  DP8390 network interface types and structures ports.
+ */
+
+#ifndef __NET_NETIF_DP8390_PORT_H__
+#define __NET_NETIF_DP8390_PORT_H__
+
+#include <errno.h>
+#include <mem.h>
+#include <stdio.h>
+#include <libarch/ddi.h>
+#include <sys/types.h>
+
+/** Macro for difining functions.
+ *  @param[in] function The function type and name definition.
+ *  @param[in] params The function parameters definition.
+ */
+#define _PROTOTYPE(function, params) function params
+
+/** Success error code.
+ */
+#define OK	EOK
+
+/** Type definition of the unsigned byte.
+ */
+typedef uint8_t u8_t;
+
+/** Type definition of the unsigned short.
+ */
+typedef uint16_t u16_t;
+
+/** Compares two memory blocks.
+ *  @param[in] first The first memory block.
+ *  @param[in] second The second memory block.
+ *  @param[in] size The blocks size in bytes.
+ *  @returns 0 if equeal.
+ *  @returns -1 if the first is greater than the second.
+ *  @returns 1 if the second is greater than the first.
+ */
+#define memcmp(first, second, size)	bcmp((char *) (first), (char *) (second), (size))
+
+/** Reads 1 byte.
+ *  @param[in] port The address to be read.
+ *  @returns The read value.
+ */
+#define inb(port)	pio_read_8((ioport8_t *) (port))
+
+/** Reads 1 word (2 bytes).
+ *  @param[in] port The address to be read.
+ *  @returns The read value.
+ */
+#define inw(port)	pio_read_16((ioport16_t *) (port))
+
+/** Writes 1 byte.
+ *  @param[in] port The address to be written.
+ *  @param[in] value The value to be written.
+ */
+#define outb(port, value)	pio_write_8((ioport8_t *) (port), (value))
+
+/** Writes 1 word (2 bytes).
+ *  @param[in] port The address to be written.
+ *  @param[in] value The value to be written.
+ */
+#define outw(port, value)	pio_write_16((ioport16_t *) (port), (value))
+
+/** Prints out the driver critical error.
+ *  Does not call the system panic().
+ */
+#define panic(...)	printf("%s%s%d", __VA_ARGS__)
+
+/** Copies a memory block.
+ *  @param proc The source process. Ignored parameter.
+ *  @param src_s Ignored parameter.
+ *  @param[in] src The source address.
+ *  @param me The current proces. Ignored parameter.
+ *  @param dst_s Ignored parameter.
+ *  @param[in] dst The destination address.
+ *  @param[in] bytes The block size in bytes.
+ *  @returns EOK.
+ */
+#define sys_vircopy(proc, src_s, src, me, dst_s, dst, bytes)	({memcpy((void *)(dst), (void *)(src), (bytes)); EOK;})
+
+/** Reads a memory block byte by byte.
+ *  @param[in] port The address to be written.
+ *  @param proc The source process. Ignored parameter.
+ *  @param[in] dst The destination address.
+ *  @param[in] bytes The block size in bytes.
+ */
+#define do_vir_insb(port, proc, dst, bytes)	insb((port), (void *)(dst), (bytes))
+
+/** Reads a memory block word by word (2 bytes).
+ *  @param[in] port The address to be written.
+ *  @param proc The source process. Ignored parameter.
+ *  @param[in] dst The destination address.
+ *  @param[in] bytes The block size in bytes.
+ */
+#define do_vir_insw(port, proc, dst, bytes)	insw((port), (void *)(dst), (bytes))
+
+/** Writes a memory block byte by byte.
+ *  @param[in] port The address to be written.
+ *  @param proc The source process. Ignored parameter.
+ *  @param[in] src The source address.
+ *  @param[in] bytes The block size in bytes.
+ */
+#define do_vir_outsb(port, proc, src, bytes)	outsb((port), (void *)(src), (bytes))
+
+/** Writes a memory block word by word (2 bytes).
+ *  @param[in] port The address to be written.
+ *  @param proc The source process. Ignored parameter.
+ *  @param[in] src The source address.
+ *  @param[in] bytes The block size in bytes.
+ */
+#define do_vir_outsw(port, proc, src, bytes)	outsw((port), (void *)(src), (bytes))
+
+/* com.h */
+/* Bits in 'DL_MODE' field of DL requests. */
+#  define DL_NOMODE		0x0
+#  define DL_PROMISC_REQ	0x2
+#  define DL_MULTI_REQ		0x4
+#  define DL_BROAD_REQ		0x8
+
+/* const.h */
+/** True value.
+ */
+#define TRUE               1	/* used for turning integers into Booleans */
+
+/** False value.
+ */
+#define FALSE              0	/* used for turning integers into Booleans */
+
+/** No number value.
+ */
+#define NO_NUM        0x8000	/* used as numerical argument to panic() */
+
+/* devio.h */
+//typedef u16_t port_t;
+/** Type definition of a port.
+ */
+typedef long port_t;
+
+/* dl_eth.h */
+/** Ethernet statistics.
+ */
+typedef struct eth_stat
+{
+	/** Number of receive errors.
+	 */
+	unsigned long ets_recvErr;
+	/** Number of send error.
+	 */
+	unsigned long ets_sendErr;
+	/** Number of buffer overwrite warnings.
+	 */
+	unsigned long ets_OVW;
+	/** Number of crc errors of read.
+	 */
+	unsigned long ets_CRCerr;
+	/** Number of frames not alligned (number of bits % 8 != 0).
+	 */
+	unsigned long ets_frameAll;
+	/** Number of packets missed due to slow processing.
+	 */
+	unsigned long ets_missedP;
+	/** Number of packets received.
+	 */
+	unsigned long ets_packetR;
+	/** Number of packets transmitted.
+	 */
+	unsigned long ets_packetT;
+	/** Number of transmission defered (Tx was busy).
+	 */
+	unsigned long ets_transDef;
+	/** Number of collissions.
+	 */
+	unsigned long ets_collision;
+	/** Number of Tx aborted due to excess collisions.
+	 */
+	unsigned long ets_transAb;
+	/** Number of carrier sense lost.
+	 */
+	unsigned long ets_carrSense;
+	/** Number of FIFO underruns (processor too busy).
+	 */
+	unsigned long ets_fifoUnder;
+	/** Number of FIFO overruns (processor too busy).
+	 */
+	unsigned long ets_fifoOver;
+	/** Number of times unable to transmit collision sig.
+	 */
+	unsigned long ets_CDheartbeat;
+	/** Number of times out of window collision.
+	 */
+	unsigned long ets_OWC;
+} eth_stat_t;
+
+/* errno.h */
+/** Generic error.
+ */
+#define EGENERIC     EINVAL
+
+/* ether.h */
+/** Minimum Ethernet packet size in bytes.
+ */
+#define ETH_MIN_PACK_SIZE		  60
+
+/** Maximum Ethernet packet size in bytes.
+ */
+#define ETH_MAX_PACK_SIZE_TAGGED	1518
+
+/** Ethernet address type definition.
+ */
+typedef struct ether_addr
+{
+	/** Address data.
+	 */
+	u8_t ea_addr[6];
+} ether_addr_t;
+
+/* type.h */
+/** Type definition of the physical addresses and lengths in bytes.
+ */
+typedef unsigned long phys_bytes;
+
+/** Type definition of the virtual addresses and lengths in bytes.
+ */
+typedef unsigned long vir_bytes;
+
+/** Type definition of the input/output vector.
+ */
+typedef struct {
+	/** Address of an I/O buffer.
+	 */
+	vir_bytes iov_addr;
+	/** Sizeof an I/O buffer.
+	 */
+	vir_bytes iov_size;
+} iovec_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/srv/hw/netif/dp8390/local.h
===================================================================
--- uspace/srv/hw/netif/dp8390/local.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/hw/netif/dp8390/local.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system 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.
+ * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+ * * Any deviations from these conditions require written permission from the copyright holder in advance
+ *
+ *
+ * Disclaimer
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``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 COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS 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.
+ *
+ * Changes:
+ *  2009 ported to HelenOS, Lukas Mejdrech
+ */
+
+/** @addtogroup dp8390
+ *  @{
+ */
+
+/** @file
+ *  Network interface probe functions.
+ */
+
+#ifndef __NET_NETIF_DP8390_CONFIG_H__
+#define __NET_NETIF_DP8390_CONFIG_H__
+
+#include "dp8390_port.h"
+
+/*
+local.h
+*/
+
+/** WDETH switch.
+ */
+#define ENABLE_WDETH 0
+
+/** NE2000 switch.
+ */
+#define ENABLE_NE2000 1
+
+/** 3C503 switch.
+ */
+#define ENABLE_3C503 0
+
+/** PCI support switch.
+ */
+#define ENABLE_PCI 0
+
+struct dpeth;
+
+/* 3c503.c */
+/* * Probes a 3C503 network interface.
+ *  @param[in] dep The network interface structure.
+ *  @returns 1 if the NE2000 network interface is present.
+ *  @returns 0 otherwise.
+ */
+//_PROTOTYPE(int el2_probe, (struct dpeth*dep)				);
+
+/* ne2000.c */
+/** Probes a NE2000 or NE1000 network interface.
+ *  @param[in] dep The network interface structure.
+ *  @returns 1 if the NE2000 network interface is present.
+ *  @returns 0 otherwise.
+ */
+int ne_probe(struct dpeth * dep);
+//_PROTOTYPE(int ne_probe, (struct dpeth *dep)				);
+//_PROTOTYPE(void ne_init, (struct dpeth *dep)				);
+
+/* rtl8029.c */
+/* * Probes a RTL8029 network interface.
+ *  @param[in] dep The network interface structure.
+ *  @returns 1 if the NE2000 network interface is present.
+ *  @returns 0 otherwise.
+ */
+//_PROTOTYPE(int rtl_probe, (struct dpeth *dep)				);
+
+/* wdeth.c */
+/* * Probes a WDETH network interface.
+ *  @param[in] dep The network interface structure.
+ *  @returns 1 if the NE2000 network interface is present.
+ *  @returns 0 otherwise.
+ */
+//_PROTOTYPE(int wdeth_probe, (struct dpeth*dep)				);
+
+#endif
+
+/** @}
+ */
Index: uspace/srv/hw/netif/dp8390/ne2000.c
===================================================================
--- uspace/srv/hw/netif/dp8390/ne2000.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/hw/netif/dp8390/ne2000.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,416 @@
+/*
+ * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system 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.
+ * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+ * * Any deviations from these conditions require written permission from the copyright holder in advance
+ *
+ *
+ * Disclaimer
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``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 COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS 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.
+ *
+ * Changes:
+ *  2009 ported to HelenOS, Lukas Mejdrech
+ */
+
+/** @addtogroup ne2k
+ *  @{
+ */
+
+/** @file
+ *  NE1000 and NE2000 network interface initialization and probe functions implementation.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include "dp8390_port.h"
+
+/*
+ne2000.c
+
+Driver for the ne2000 ethernet cards. This file contains only the ne2000
+specific code, the rest is in dp8390.c
+
+Created:	March 15, 1994 by Philip Homburg <philip@f-mnx.phicoh.com>
+*/
+
+//#include "../drivers.h"
+
+//#include <net/gen/ether.h>
+//#include <net/gen/eth_io.h>
+//#if __minix_vmd
+//#include "config.h"
+//#endif
+
+#include "local.h"
+#include "dp8390.h"
+#include "ne2000.h"
+
+#if ENABLE_NE2000
+
+/** Number of bytes to transfer.
+ */
+#define N 100
+
+//#define MILLIS_TO_TICKS(m)  (((m)*HZ/1000)+1)
+
+/** Sleeps for the defined millicesonds.
+ *  @param[in] millis The number of milliseconds to sleep.
+ */
+#define milli_delay(millis)	usleep((millis) * 1000)
+
+/** Type definition of the testing function.
+ */
+_PROTOTYPE(typedef int (*testf_t), (dpeth_t *dep, int pos, u8_t *pat)	);
+
+/** First data pattern.
+ */
+u8_t	pat0[]= {0x00, 0x00, 0x00, 0x00};
+
+/** Second data pattern.
+ */
+u8_t	pat1[]= {0xFF, 0xFF, 0xFF, 0xFF};
+
+/** Third data pattern.
+ */
+u8_t	pat2[]= {0xA5, 0x5A, 0x69, 0x96};
+
+/** Fourth data pattern.
+ */
+u8_t	pat3[]= {0x96, 0x69, 0x5A, 0xA5};
+
+/** Tests 8 bit NE2000 network interface.
+ *  @param[in,out] dep The network interface structure.
+ *  @param[in] pos The starting position.
+ *  @param[in] pat The data pattern to be written.
+ *  @returns True on success.
+ *  @returns FALSE otherwise.
+ */
+static int test_8(dpeth_t *dep, int pos, u8_t *pat);
+
+/** Tests 16 bit NE2000 network interface.
+ *  @param[in,out] dep The network interface structure.
+ *  @param[in] pos The starting position.
+ *  @param[in] pat The data pattern to be written.
+ *  @returns True on success.
+ *  @returns FALSE otherwise.
+ */
+static int test_16(dpeth_t *dep, int pos, u8_t *pat);
+
+/** Stops the NE2000 network interface.
+ *  @param[in,out] dep The network interface structure.
+ */
+static void ne_stop(dpeth_t *dep);
+//_PROTOTYPE(static void milli_delay, (unsigned long millis)		);
+
+/** Initializes the NE2000 network interface.
+ *  @param[in,out] dep The network interface structure.
+ */
+void ne_init(struct dpeth *dep);
+
+/*===========================================================================*
+ *				ne_probe				     *
+ *===========================================================================*/
+int ne_probe(dep)
+dpeth_t *dep;
+{
+	int byte;
+	int i;
+	int loc1, loc2;
+	testf_t f;
+
+	dep->de_dp8390_port= dep->de_base_port + NE_DP8390;
+
+	/* We probe for an ne1000 or an ne2000 by testing whether the
+	 * on board is reachable through the dp8390. Note that the
+	 * ne1000 is an 8bit card and has a memory region distict from
+	 * the 16bit ne2000
+	 */
+
+	for (dep->de_16bit= 0; dep->de_16bit < 2; dep->de_16bit++)
+	{
+		/* Reset the ethernet card */
+		byte= inb_ne(dep, NE_RESET);
+		milli_delay(2);
+		outb_ne(dep, NE_RESET, byte);
+		milli_delay(2);
+
+		/* Reset the dp8390 */
+		outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
+		for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) &ISR_RST) == 0); i++)
+			; /* Do nothing */
+
+		/* Check if the dp8390 is really there */
+		if ((inb_reg0(dep, DP_CR) &(CR_STP|CR_DM_ABORT)) !=
+			(CR_STP|CR_DM_ABORT))
+		{
+			return 0;
+		}
+
+		/* Disable the receiver and init TCR and DCR. */
+		outb_reg0(dep, DP_RCR, RCR_MON);
+		outb_reg0(dep, DP_TCR, TCR_NORMAL);
+		if (dep->de_16bit)
+		{
+			outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES |
+				DCR_BMS);
+		}
+		else
+		{
+			outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES |
+				DCR_BMS);
+		}
+
+		if (dep->de_16bit)
+		{
+			loc1= NE2000_START;
+			loc2= NE2000_START + NE2000_SIZE - 4;
+			f= test_16;
+		}
+		else
+		{
+			loc1= NE1000_START;
+			loc2= NE1000_START + NE1000_SIZE - 4;
+			f= test_8;
+		}
+		if (f(dep, loc1, pat0) && f(dep, loc1, pat1) && 
+			f(dep, loc1, pat2) && f(dep, loc1, pat3) && 
+			f(dep, loc2, pat0) && f(dep, loc2, pat1) && 
+			f(dep, loc2, pat2) && f(dep, loc2, pat3))
+		{
+			/* We don't need a memory segment */
+			dep->de_linmem= 0;
+			if (!dep->de_pci)
+				dep->de_initf= ne_init;
+			dep->de_stopf= ne_stop;
+			dep->de_prog_IO= 1;
+			return 1;
+		}
+	}
+	return 0;
+}
+
+/*===========================================================================*
+ *				ne_init					     *
+ *===========================================================================*/
+void ne_init(dep)
+dpeth_t *dep;
+{
+	int i;
+	int word, sendq_nr;
+
+	/* Setup a transfer to get the ethernet address. */
+	if (dep->de_16bit)
+		outb_reg0(dep, DP_RBCR0, 6*2);
+	else
+		outb_reg0(dep, DP_RBCR0, 6);
+	outb_reg0(dep, DP_RBCR1, 0);
+	outb_reg0(dep, DP_RSAR0, 0);
+	outb_reg0(dep, DP_RSAR1, 0);
+	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
+
+	for (i= 0; i<6; i++)
+	{
+		if (dep->de_16bit)
+		{
+			word= inw_ne(dep, NE_DATA);
+			dep->de_address.ea_addr[i]= word;
+		}
+		else
+		{
+			dep->de_address.ea_addr[i] = inb_ne(dep, NE_DATA);
+		}
+	}
+	dep->de_data_port= dep->de_base_port + NE_DATA;
+	if (dep->de_16bit)
+	{
+		dep->de_ramsize= NE2000_SIZE;
+		dep->de_offset_page= NE2000_START / DP_PAGESIZE;
+	}
+	else
+	{
+		dep->de_ramsize= NE1000_SIZE;
+		dep->de_offset_page= NE1000_START / DP_PAGESIZE;
+	}
+
+	/* Allocate one send buffer (1.5KB) per 8KB of on board memory. */
+	sendq_nr= dep->de_ramsize / 0x2000;
+	if (sendq_nr < 1)
+		sendq_nr= 1;
+	else if (sendq_nr > SENDQ_NR)
+		sendq_nr= SENDQ_NR;
+	dep->de_sendq_nr= sendq_nr;
+	for (i= 0; i<sendq_nr; i++)
+	{
+		dep->de_sendq[i].sq_sendpage= dep->de_offset_page +
+			i*SENDQ_PAGES;	
+	}
+
+	dep->de_startpage= dep->de_offset_page + i*SENDQ_PAGES;
+	dep->de_stoppage= dep->de_offset_page + dep->de_ramsize / DP_PAGESIZE;
+
+	/* Can't override the default IRQ. */
+	dep->de_irq &= ~DEI_DEFAULT;
+
+	if (!debug)
+	{
+		printf("%s: NE%d000 at %X:%d\n",
+			dep->de_name, dep->de_16bit ? 2 : 1,
+			dep->de_base_port, dep->de_irq);
+	}
+	else
+	{
+		printf("%s: Novell NE%d000 ethernet card at I/O address "
+			"0x%X, memory size 0x%X, irq %d\n",
+			dep->de_name, dep->de_16bit ? 2 : 1,
+			dep->de_base_port, dep->de_ramsize, dep->de_irq);
+	}
+}
+
+/*===========================================================================*
+ *				test_8					     *
+ *===========================================================================*/
+static int test_8(dep, pos, pat)
+dpeth_t *dep;
+int pos;
+u8_t *pat;
+{
+	u8_t buf[4];
+	int i;
+	int r;
+
+	outb_reg0(dep, DP_ISR, 0xFF);
+
+	/* Setup a transfer to put the pattern. */
+	outb_reg0(dep, DP_RBCR0, 4);
+	outb_reg0(dep, DP_RBCR1, 0);
+	outb_reg0(dep, DP_RSAR0, pos &0xFF);
+	outb_reg0(dep, DP_RSAR1, pos >> 8);
+	outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
+
+	for (i= 0; i<4; i++)
+		outb_ne(dep, NE_DATA, pat[i]);
+
+	for (i= 0; i<N; i++)
+	{
+		if (inb_reg0(dep, DP_ISR) &ISR_RDC)
+			break;
+	}
+	if (i == N)
+	{
+		if (debug)
+		{
+			printf("%s: NE1000 remote DMA test failed\n",
+				dep->de_name);
+		}
+		return 0;
+	}
+
+	outb_reg0(dep, DP_RBCR0, 4);
+	outb_reg0(dep, DP_RBCR1, 0);
+	outb_reg0(dep, DP_RSAR0, pos &0xFF);
+	outb_reg0(dep, DP_RSAR1, pos >> 8);
+	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
+
+	for (i= 0; i<4; i++)
+		buf[i]= inb_ne(dep, NE_DATA);
+
+	r= (memcmp(buf, pat, 4) == 0);
+	return r;
+}
+
+/*===========================================================================*
+ *				test_16					     *
+ *===========================================================================*/
+static int test_16(dep, pos, pat)
+dpeth_t *dep;
+int pos;
+u8_t *pat;
+{
+	u8_t buf[4];
+	int i;
+	int r;
+
+	outb_reg0(dep, DP_ISR, 0xFF);
+
+	/* Setup a transfer to put the pattern. */
+	outb_reg0(dep, DP_RBCR0, 4);
+	outb_reg0(dep, DP_RBCR1, 0);
+	outb_reg0(dep, DP_RSAR0, pos &0xFF);
+	outb_reg0(dep, DP_RSAR1, pos >> 8);
+	outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
+
+	for (i= 0; i<4; i += 2)
+	{
+		outw_ne(dep, NE_DATA, *(u16_t *)(pat+i));
+	}
+
+	for (i= 0; i<N; i++)
+	{
+		if (inb_reg0(dep, DP_ISR) &ISR_RDC)
+			break;
+	}
+	if (i == N)
+	{
+		if (debug)
+		{
+			printf("%s: NE2000 remote DMA test failed\n",
+				dep->de_name);
+		}
+		return 0;
+	}
+
+	outb_reg0(dep, DP_RBCR0, 4);
+	outb_reg0(dep, DP_RBCR1, 0);
+	outb_reg0(dep, DP_RSAR0, pos &0xFF);
+	outb_reg0(dep, DP_RSAR1, pos >> 8);
+	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
+
+	for (i= 0; i<4; i += 2)
+	{
+		*(u16_t *)(buf+i)= inw_ne(dep, NE_DATA);
+	}
+
+	r= (memcmp(buf, pat, 4) == 0);
+	return r;
+}
+
+/*===========================================================================*
+ *				ne_stop					     *
+ *===========================================================================*/
+static void ne_stop(dep)
+dpeth_t *dep;
+{
+	int byte;
+
+	/* Reset the ethernet card */
+	byte= inb_ne(dep, NE_RESET);
+	milli_delay(2);
+	outb_ne(dep, NE_RESET, byte);
+}
+/*
+static void milli_delay(unsigned long millis)
+{
+	tickdelay(MILLIS_TO_TICKS(millis));
+}
+*/
+#endif /* ENABLE_NE2000 */
+
+/*
+ * $PchId: ne2000.c,v 1.10 2004/08/03 12:03:00 philip Exp $
+ */
+
+/** @}
+ */
Index: uspace/srv/hw/netif/dp8390/ne2000.h
===================================================================
--- uspace/srv/hw/netif/dp8390/ne2000.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/hw/netif/dp8390/ne2000.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system 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.
+ * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+ * * Any deviations from these conditions require written permission from the copyright holder in advance
+ *
+ *
+ * Disclaimer
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``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 COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS 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.
+ *
+ * Changes:
+ *  2009 ported to HelenOS, Lukas Mejdrech
+ */
+
+/*
+ne2000.h
+
+Created:	March 15, 1994 by Philip Homburg <philip@f-mnx.phicoh.com>
+*/
+
+/** @addtogroup ne2k
+ *  @{
+ */
+
+/** @file
+ *  NE1000 and NE2000 network interface definitions.
+ */
+
+#ifndef __NET_NETIF_NE2000_H__
+#define __NET_NETIF_NE2000_H__
+
+#include <libarch/ddi.h>
+
+#include "dp8390_port.h"
+
+/** DP8390 register offset.
+ */
+#define NE_DP8390	0x00
+
+/** Data register.
+ */
+#define NE_DATA		0x10
+
+/** Reset register.
+ */
+#define NE_RESET	0x1F
+
+/** NE1000 data start.
+ */
+#define NE1000_START	0x2000
+
+/** NE1000 data size.
+ */
+#define NE1000_SIZE	0x2000
+
+/** NE2000 data start.
+ */
+#define NE2000_START	0x4000
+
+/** NE2000 data size.
+ */
+#define NE2000_SIZE	0x4000
+
+/** Reads 1 byte register.
+ *  @param[in] dep The network interface structure.
+ *  @param[in] reg The register offset.
+ *  @returns The read value.
+ */
+#define inb_ne(dep, reg)	(inb(dep->de_base_port+reg))
+
+/** Writes 1 byte register.
+ *  @param[in] dep The network interface structure.
+ *  @param[in] reg The register offset.
+ *  @param[in] data The value to be written.
+ */
+#define outb_ne(dep, reg, data)	(outb(dep->de_base_port+reg, data))
+
+/** Reads 1 word (2 bytes) register.
+ *  @param[in] dep The network interface structure.
+ *  @param[in] reg The register offset.
+ *  @returns The read value.
+ */
+#define inw_ne(dep, reg)	(inw(dep->de_base_port+reg))
+
+/** Writes 1 word (2 bytes) register.
+ *  @param[in] dep The network interface structure.
+ *  @param[in] reg The register offset.
+ *  @param[in] data The value to be written.
+ */
+#define outw_ne(dep, reg, data)	(outw(dep->de_base_port+reg, data))
+
+#endif /* __NET_NETIF_NE2000_H__ */
+
+/*
+ * $PchId: ne2000.h,v 1.4 2004/08/03 12:03:20 philip Exp $
+ */
+
+/** @}
+ */
Index: pace/srv/net/Doxyfile
===================================================================
--- uspace/srv/net/Doxyfile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,298 +1,0 @@
-# Doxyfile 1.5.6
-
-#---------------------------------------------------------------------------
-# Project related configuration options
-#---------------------------------------------------------------------------
-DOXYFILE_ENCODING      = UTF-8
-PROJECT_NAME           = "Networking and TCP/IP stack for HelenOS system"
-PROJECT_NUMBER         = ""
-OUTPUT_DIRECTORY       = doc/
-CREATE_SUBDIRS         = YES
-OUTPUT_LANGUAGE        = English
-BRIEF_MEMBER_DESC      = YES
-REPEAT_BRIEF           = YES
-ABBREVIATE_BRIEF       = "The $name class           " \
-                         "The $name widget           " \
-                         "The $name file           " \
-                         is \
-                         provides \
-                         specifies \
-                         contains \
-                         represents \
-                         a \
-                         an \
-                         the
-ALWAYS_DETAILED_SEC    = NO
-INLINE_INHERITED_MEMB  = NO
-FULL_PATH_NAMES        = YES
-STRIP_FROM_PATH        = .
-STRIP_FROM_INC_PATH    = 
-SHORT_NAMES            = YES
-JAVADOC_AUTOBRIEF      = YES
-QT_AUTOBRIEF           = NO
-MULTILINE_CPP_IS_BRIEF = NO
-DETAILS_AT_TOP         = NO
-INHERIT_DOCS           = YES
-SEPARATE_MEMBER_PAGES  = NO
-TAB_SIZE               = 2
-ALIASES                = 
-OPTIMIZE_OUTPUT_FOR_C  = YES
-OPTIMIZE_OUTPUT_JAVA   = NO
-OPTIMIZE_FOR_FORTRAN   = NO
-OPTIMIZE_OUTPUT_VHDL   = NO
-BUILTIN_STL_SUPPORT    = NO
-CPP_CLI_SUPPORT        = NO
-SIP_SUPPORT            = NO
-IDL_PROPERTY_SUPPORT   = YES
-DISTRIBUTE_GROUP_DOC   = NO
-SUBGROUPING            = YES
-TYPEDEF_HIDES_STRUCT   = NO
-#---------------------------------------------------------------------------
-# Build related configuration options
-#---------------------------------------------------------------------------
-EXTRACT_ALL            = YES
-EXTRACT_PRIVATE        = NO
-EXTRACT_STATIC         = YES
-EXTRACT_LOCAL_CLASSES  = YES
-EXTRACT_LOCAL_METHODS  = NO
-EXTRACT_ANON_NSPACES   = NO
-HIDE_UNDOC_MEMBERS     = YES
-HIDE_UNDOC_CLASSES     = YES
-HIDE_FRIEND_COMPOUNDS  = NO
-HIDE_IN_BODY_DOCS      = NO
-INTERNAL_DOCS          = NO
-CASE_SENSE_NAMES       = YES
-HIDE_SCOPE_NAMES       = NO
-SHOW_INCLUDE_FILES     = YES
-INLINE_INFO            = YES
-SORT_MEMBER_DOCS       = YES
-SORT_BRIEF_DOCS        = NO
-SORT_GROUP_NAMES       = NO
-SORT_BY_SCOPE_NAME     = NO
-GENERATE_TODOLIST      = YES
-GENERATE_TESTLIST      = YES
-GENERATE_BUGLIST       = YES
-GENERATE_DEPRECATEDLIST= YES
-ENABLED_SECTIONS       = 
-MAX_INITIALIZER_LINES  = 30
-SHOW_USED_FILES        = YES
-SHOW_DIRECTORIES       = YES
-SHOW_FILES             = YES
-SHOW_NAMESPACES        = YES
-FILE_VERSION_FILTER    = 
-#---------------------------------------------------------------------------
-# configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-QUIET                  = NO
-WARNINGS               = YES
-WARN_IF_UNDOCUMENTED   = YES
-WARN_IF_DOC_ERROR      = YES
-WARN_NO_PARAMDOC       = YES
-WARN_FORMAT            = "$file:$line: $text           "
-WARN_LOGFILE           = doc/doxygen_warnings.txt
-#---------------------------------------------------------------------------
-# configuration options related to the input files
-#---------------------------------------------------------------------------
-INPUT                  = ./ \
-                         ../../doc/doxygroups.h \
-                         ./documentation.txt
-INPUT_ENCODING         = UTF-8
-FILE_PATTERNS          = *.c \
-                         *.cc \
-                         *.cxx \
-                         *.cpp \
-                         *.c++ \
-                         *.d \
-                         *.java \
-                         *.ii \
-                         *.ixx \
-                         *.ipp \
-                         *.i++ \
-                         *.inl \
-                         *.h \
-                         *.hh \
-                         *.hxx \
-                         *.hpp \
-                         *.h++ \
-                         *.idl \
-                         *.odl \
-                         *.cs \
-                         *.php \
-                         *.php3 \
-                         *.inc \
-                         *.m \
-                         *.mm \
-                         *.dox \
-                         *.py \
-                         *.C \
-                         *.CC \
-                         *.C++ \
-                         *.II \
-                         *.I++ \
-                         *.H \
-                         *.HH \
-                         *.H++ \
-                         *.CS \
-                         *.PHP \
-                         *.PHP3 \
-                         *.M \
-                         *.MM \
-                         *.PY
-RECURSIVE              = YES
-EXCLUDE                = 
-EXCLUDE_SYMLINKS       = NO
-EXCLUDE_PATTERNS       = *.svn*
-EXCLUDE_SYMBOLS        = packed
-EXAMPLE_PATH           = 
-EXAMPLE_PATTERNS       = *
-EXAMPLE_RECURSIVE      = NO
-IMAGE_PATH             = 
-INPUT_FILTER           = 
-FILTER_PATTERNS        = 
-FILTER_SOURCE_FILES    = NO
-#---------------------------------------------------------------------------
-# configuration options related to source browsing
-#---------------------------------------------------------------------------
-SOURCE_BROWSER         = NO
-INLINE_SOURCES         = NO
-STRIP_CODE_COMMENTS    = YES
-REFERENCED_BY_RELATION = YES
-REFERENCES_RELATION    = YES
-REFERENCES_LINK_SOURCE = YES
-USE_HTAGS              = NO
-VERBATIM_HEADERS       = NO
-#---------------------------------------------------------------------------
-# configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-ALPHABETICAL_INDEX     = YES
-COLS_IN_ALPHA_INDEX    = 4
-IGNORE_PREFIX          = 
-#---------------------------------------------------------------------------
-# configuration options related to the HTML output
-#---------------------------------------------------------------------------
-GENERATE_HTML          = YES
-HTML_OUTPUT            = 
-HTML_FILE_EXTENSION    = .html
-HTML_HEADER            = 
-HTML_FOOTER            = 
-HTML_STYLESHEET        = 
-HTML_ALIGN_MEMBERS     = YES
-GENERATE_HTMLHELP      = NO
-GENERATE_DOCSET        = NO
-DOCSET_FEEDNAME        = "Doxygen generated docs"
-DOCSET_BUNDLE_ID       = org.doxygen.Project
-HTML_DYNAMIC_SECTIONS  = YES
-CHM_FILE               = 
-HHC_LOCATION           = 
-GENERATE_CHI           = NO
-CHM_INDEX_ENCODING     = 
-BINARY_TOC             = NO
-TOC_EXPAND             = NO
-DISABLE_INDEX          = NO
-ENUM_VALUES_PER_LINE   = 4
-GENERATE_TREEVIEW      = NO
-TREEVIEW_WIDTH         = 250
-FORMULA_FONTSIZE       = 10
-#---------------------------------------------------------------------------
-# configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-GENERATE_LATEX         = NO
-LATEX_OUTPUT           = latex
-LATEX_CMD_NAME         = latex
-MAKEINDEX_CMD_NAME     = makeindex
-COMPACT_LATEX          = NO
-PAPER_TYPE             = a4wide
-EXTRA_PACKAGES         = 
-LATEX_HEADER           = 
-PDF_HYPERLINKS         = NO
-USE_PDFLATEX           = NO
-LATEX_BATCHMODE        = NO
-LATEX_HIDE_INDICES     = NO
-#---------------------------------------------------------------------------
-# configuration options related to the RTF output
-#---------------------------------------------------------------------------
-GENERATE_RTF           = NO
-RTF_OUTPUT             = rtf
-COMPACT_RTF            = NO
-RTF_HYPERLINKS         = NO
-RTF_STYLESHEET_FILE    = 
-RTF_EXTENSIONS_FILE    = 
-#---------------------------------------------------------------------------
-# configuration options related to the man page output
-#---------------------------------------------------------------------------
-GENERATE_MAN           = NO
-MAN_OUTPUT             = man
-MAN_EXTENSION          = .3
-MAN_LINKS              = NO
-#---------------------------------------------------------------------------
-# configuration options related to the XML output
-#---------------------------------------------------------------------------
-GENERATE_XML           = NO
-XML_OUTPUT             = xml
-XML_SCHEMA             = 
-XML_DTD                = 
-XML_PROGRAMLISTING     = YES
-#---------------------------------------------------------------------------
-# configuration options for the AutoGen Definitions output
-#---------------------------------------------------------------------------
-GENERATE_AUTOGEN_DEF   = NO
-#---------------------------------------------------------------------------
-# configuration options related to the Perl module output
-#---------------------------------------------------------------------------
-GENERATE_PERLMOD       = NO
-PERLMOD_LATEX          = NO
-PERLMOD_PRETTY         = YES
-PERLMOD_MAKEVAR_PREFIX = 
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor   
-#---------------------------------------------------------------------------
-ENABLE_PREPROCESSING   = YES
-MACRO_EXPANSION        = NO
-EXPAND_ONLY_PREDEF     = NO
-SEARCH_INCLUDES        = YES
-INCLUDE_PATH           = 
-INCLUDE_FILE_PATTERNS  = 
-PREDEFINED             = 
-EXPAND_AS_DEFINED      = 
-SKIP_FUNCTION_MACROS   = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to external references   
-#---------------------------------------------------------------------------
-TAGFILES               = 
-GENERATE_TAGFILE       = 
-ALLEXTERNALS           = NO
-EXTERNAL_GROUPS        = YES
-PERL_PATH              = /usr/bin/perl
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool   
-#---------------------------------------------------------------------------
-CLASS_DIAGRAMS         = YES
-MSCGEN_PATH            = 
-HIDE_UNDOC_RELATIONS   = YES
-HAVE_DOT               = YES
-DOT_FONTNAME           = FreeSans
-DOT_FONTPATH           = 
-CLASS_GRAPH            = YES
-COLLABORATION_GRAPH    = YES
-GROUP_GRAPHS           = YES
-UML_LOOK               = YES
-TEMPLATE_RELATIONS     = NO
-INCLUDE_GRAPH          = YES
-INCLUDED_BY_GRAPH      = YES
-CALL_GRAPH             = YES
-CALLER_GRAPH           = YES
-GRAPHICAL_HIERARCHY    = YES
-DIRECTORY_GRAPH        = YES
-DOT_IMAGE_FORMAT       = png
-DOT_PATH               = 
-DOTFILE_DIRS           = 
-DOT_GRAPH_MAX_NODES    = 50
-MAX_DOT_GRAPH_DEPTH    = 1000
-DOT_TRANSPARENT        = NO
-DOT_MULTI_TARGETS      = YES
-GENERATE_LEGEND        = YES
-DOT_CLEANUP            = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to the search engine   
-#---------------------------------------------------------------------------
-SEARCHENGINE           = NO
Index: pace/srv/net/app/echo/Makefile
===================================================================
--- uspace/srv/net/app/echo/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,40 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# 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.
-#
-
-NET_BASE = ../..
-USPACE_PREFIX = ../../../..
-LIBS = $(NET_BASE)/socket/libsocket.a
-BINARY = echo
-
-SOURCES = \
-	echo.c \
-	$(NET_BASE)/app/parse.c \
-	$(NET_BASE)/app/print_error.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: pace/srv/net/app/echo/echo.c
===================================================================
--- uspace/srv/net/app/echo/echo.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,375 +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 echo
- *  @{
- */
-
-/** @file
- *  Echo application.
- *  Answers received packets.
- */
-
-#include <malloc.h>
-#include <stdio.h>
-#include <str.h>
-#include <task.h>
-
-#include "../../include/in.h"
-#include "../../include/in6.h"
-#include "../../include/inet.h"
-#include "../../include/socket.h"
-
-#include "../../err.h"
-
-#include "../parse.h"
-#include "../print_error.h"
-
-/** Echo module name.
- */
-#define NAME	"Echo"
-
-/** Prints the application help.
- */
-void echo_print_help(void);
-
-/** Module entry point.
- *  Reads command line parameters and starts listenning.
- *  @param[in] argc The number of command line parameters.
- *  @param[in] argv The command line parameters.
- *  @returns EOK on success.
- */
-int main(int argc, char * argv[]);
-
-void echo_print_help(void){
-	printf(
-		"Network Echo aplication\n" \
-		"Usage: echo [options]\n" \
-		"Where options are:\n" \
-		"-b backlog | --backlog=size\n" \
-		"\tThe size of the accepted sockets queue. Only for SOCK_STREAM. The default is 3.\n" \
-		"\n" \
-		"-c count | --count=count\n" \
-		"\tThe number of received messages to handle. A negative number means infinity. The default is infinity.\n" \
-		"\n" \
-		"-f protocol_family | --family=protocol_family\n" \
-		"\tThe listenning socket protocol family. Only the PF_INET and PF_INET6 are supported.\n"
-		"\n" \
-		"-h | --help\n" \
-		"\tShow this application help.\n"
-		"\n" \
-		"-p port_number | --port=port_number\n" \
-		"\tThe port number the application should listen at. The default is 7.\n" \
-		"\n" \
-		"-r reply_string | --reply=reply_string\n" \
-		"\tThe constant reply string. The default is the original data received.\n" \
-		"\n" \
-		"-s receive_size | --size=receive_size\n" \
-		"\tThe maximum receive data size the application should accept. The default is 1024 bytes.\n" \
-		"\n" \
-		"-t socket_type | --type=socket_type\n" \
-		"\tThe listenning socket type. Only the SOCK_DGRAM and the SOCK_STREAM are supported.\n" \
-		"\n" \
-		"-v | --verbose\n" \
-		"\tShow all output messages.\n"
-	);
-}
-
-int main(int argc, char * argv[]){
-	ERROR_DECLARE;
-
-	size_t size			= 1024;
-	int verbose			= 0;
-	char * reply		= NULL;
-	sock_type_t type	= SOCK_DGRAM;
-	int count			= -1;
-	int family			= PF_INET;
-	uint16_t port		= 7;
-	int backlog			= 3;
-
-	socklen_t max_length				= sizeof(struct sockaddr_in6);
-	uint8_t address_data[max_length];
-	struct sockaddr * address			= (struct sockaddr *) address_data;
-	struct sockaddr_in * address_in		= (struct sockaddr_in *) address;
-	struct sockaddr_in6 * address_in6	= (struct sockaddr_in6 *) address;
-	socklen_t addrlen;
-	char address_string[INET6_ADDRSTRLEN];
-	uint8_t * address_start;
-	int socket_id;
-	int listening_id;
-	char * data;
-	size_t length;
-	int index;
-	size_t reply_length;
-	int value;
-
-	// print the program label
-	printf("Task %d - ", task_get_id());
-	printf("%s\n", NAME);
-
-	// parse the command line arguments
-	for(index = 1; index < argc; ++ index){
-		if(argv[index][0] == '-'){
-			switch(argv[index][1]){
-				case 'b':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &backlog, "accepted sockets queue size", 0));
-					break;
-				case 'c':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "message count", 0));
-					break;
-				case 'f':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, parse_protocol_family));
-					break;
-				case 'h':
-					echo_print_help();
-					return EOK;
-					break;
-				case 'p':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 0));
-					port = (uint16_t) value;
-					break;
-				case 'r':
-					ERROR_PROPAGATE(parse_parameter_string(argc, argv, &index, &reply, "reply string", 0));
-					break;
-				case 's':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "receive size", 0));
-					size = (value >= 0) ? (size_t) value : 0;
-					break;
-				case 't':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, parse_socket_type));
-					type = (sock_type_t) value;
-					break;
-				case 'v':
-					verbose = 1;
-					break;
-				// long options with the double minus sign ('-')
-				case '-':
-					if(str_lcmp(argv[index] + 2, "backlog=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &backlog, "accepted sockets queue size", 8));
-					}else if(str_lcmp(argv[index] + 2, "count=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "message count", 8));
-					}else if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, parse_protocol_family));
-					}else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
-						echo_print_help();
-						return EOK;
-					}else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 7));
-						port = (uint16_t) value;
-					}else if(str_lcmp(argv[index] + 2, "reply=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_string(argc, argv, &index, &reply, "reply string", 8));
-					}else if(str_lcmp(argv[index] + 2, "size=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "receive size", 7));
-						size = (value >= 0) ? (size_t) value : 0;
-					}else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, parse_socket_type));
-						type = (sock_type_t) value;
-					}else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
-						verbose = 1;
-					}else{
-						print_unrecognized(index, argv[index] + 2);
-						echo_print_help();
-						return EINVAL;
-					}
-					break;
-				default:
-					print_unrecognized(index, argv[index] + 1);
-					echo_print_help();
-					return EINVAL;
-			}
-		}else{
-			print_unrecognized(index, argv[index]);
-			echo_print_help();
-			return EINVAL;
-		}
-	}
-
-	// check the buffer size
-	if(size <= 0){
-		fprintf(stderr, "Receive size too small (%d). Using 1024 bytes instead.\n", size);
-		size = 1024;
-	}
-	// size plus the terminating null (\0)
-	data = (char *) malloc(size + 1);
-	if(! data){
-		fprintf(stderr, "Failed to allocate receive buffer.\n");
-		return ENOMEM;
-	}
-
-	// set the reply size if set
-	reply_length = reply ? str_length(reply) : 0;
-
-	// prepare the address buffer
-	bzero(address_data, max_length);
-	switch(family){
-		case PF_INET:
-			address_in->sin_family = AF_INET;
-			address_in->sin_port = htons(port);
-			addrlen = sizeof(struct sockaddr_in);
-			break;
-		case PF_INET6:
-			address_in6->sin6_family = AF_INET6;
-			address_in6->sin6_port = htons(port);
-			addrlen = sizeof(struct sockaddr_in6);
-			break;
-		default:
-			fprintf(stderr, "Protocol family is not supported\n");
-			return EAFNOSUPPORT;
-	}
-
-	// get a listening socket
-	listening_id = socket(family, type, 0);
-	if(listening_id < 0){
-		socket_print_error(stderr, listening_id, "Socket create: ", "\n");
-		return listening_id;
-	}
-
-	// if the stream socket is used
-	if(type == SOCK_STREAM){
-		// check the backlog
-		if(backlog <= 0){
-			fprintf(stderr, "Accepted sockets queue size too small (%d). Using 3 instead.\n", size);
-			backlog = 3;
-		}
-		// set the backlog
-		if(ERROR_OCCURRED(listen(listening_id, backlog))){
-			socket_print_error(stderr, ERROR_CODE, "Socket listen: ", "\n");
-			return ERROR_CODE;
-		}
-	}
-
-	// bind the listenning socket
-	if(ERROR_OCCURRED(bind(listening_id, address, addrlen))){
-		socket_print_error(stderr, ERROR_CODE, "Socket bind: ", "\n");
-		return ERROR_CODE;
-	}
-
-	if(verbose){
-		printf("Socket %d listenning at %d\n", listening_id, port);
-	}
-
-	socket_id = listening_id;
-
-	// do count times
-	// or indefinitely if set to a negative value
-	while(count){
-
-		addrlen = max_length;
-		if(type == SOCK_STREAM){
-			// acceept a socket if the stream socket is used
-			socket_id = accept(listening_id, address, &addrlen);
-			if(socket_id <= 0){
-				socket_print_error(stderr, socket_id, "Socket accept: ", "\n");
-			}else{
-				if(verbose){
-					printf("Socket %d accepted\n", socket_id);
-				}
-			}
-		}
-
-		// if the datagram socket is used or the stream socked was accepted
-		if(socket_id > 0){
-
-			// receive an echo request
-			value = recvfrom(socket_id, data, size, 0, address, &addrlen);
-			if(value < 0){
-				socket_print_error(stderr, value, "Socket receive: ", "\n");
-			}else{
-				length = (size_t) value;
-				if(verbose){
-					// print the header
-
-					// get the source port and prepare the address buffer
-					address_start = NULL;
-					switch(address->sa_family){
-						case AF_INET:
-							port = ntohs(address_in->sin_port);
-							address_start = (uint8_t *) &address_in->sin_addr.s_addr;
-							break;
-						case AF_INET6:
-							port = ntohs(address_in6->sin6_port);
-							address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
-							break;
-						default:
-							fprintf(stderr, "Address family %d (0x%X) is not supported.\n", address->sa_family);
-					}
-					// parse the source address
-					if(address_start){
-						if(ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))){
-							fprintf(stderr, "Received address error %d\n", ERROR_CODE);
-						}else{
-							data[length] = '\0';
-							printf("Socket %d received %d bytes from %s:%d\n%s\n", socket_id, length, address_string, port, data);
-						}
-					}
-				}
-
-				// answer the request either with the static reply or the original data
-				if(ERROR_OCCURRED(sendto(socket_id, reply ? reply : data, reply ? reply_length : length, 0, address, addrlen))){
-					socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
-				}
-
-			}
-
-			// close the accepted stream socket
-			if(type == SOCK_STREAM){
-				if(ERROR_OCCURRED(closesocket(socket_id))){
-					socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n");
-				}
-			}
-
-		}
-
-		// decrease the count if positive
-		if(count > 0){
-			-- count;
-			if(verbose){
-				printf("Waiting for next %d packet(s)\n", count);
-			}
-		}
-	}
-
-	if(verbose){
-		printf("Closing the socket\n");
-	}
-
-	// close the listenning socket
-	if(ERROR_OCCURRED(closesocket(listening_id))){
-		socket_print_error(stderr, ERROR_CODE, "Close socket: ", "\n");
-		return ERROR_CODE;
-	}
-
-	if(verbose){
-		printf("Exiting\n");
-	}
-
-	return EOK;
-}
-
-/** @}
- */
Index: pace/srv/net/app/nettest.c
===================================================================
--- uspace/srv/net/app/nettest.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,202 +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 nettest
- *  @{
- */
-
-/** @file
- *  Networking test support functions implementation.
- */
-
-#include <stdio.h>
-
-#include "../include/socket.h"
-
-#include "../err.h"
-
-#include "nettest.h"
-#include "print_error.h"
-
-int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type){
-	int index;
-
-	if(verbose){
-		printf("Create\t");
-	}
-	fflush(stdout);
-	for(index = 0; index < sockets; ++ index){
-		socket_ids[index] = socket(family, type, 0);
-		if(socket_ids[index] < 0){
-			printf("Socket %d (%d) error:\n", index, socket_ids[index]);
-			socket_print_error(stderr, socket_ids[index], "Socket create: ", "\n");
-			return socket_ids[index];
-		}
-		if(verbose){
-			print_mark(index);
-		}
-	}
-	return EOK;
-}
-
-int sockets_close(int verbose, int * socket_ids, int sockets){
-	ERROR_DECLARE;
-
-	int index;
-
-	if(verbose){
-		printf("\tClose\t");
-	}
-	fflush(stdout);
-	for(index = 0; index < sockets; ++ index){
-		if(ERROR_OCCURRED(closesocket(socket_ids[index]))){
-			printf("Socket %d (%d) error:\n", index, socket_ids[index]);
-			socket_print_error(stderr, ERROR_CODE, "Socket close: ", "\n");
-			return ERROR_CODE;
-		}
-		if(verbose){
-			print_mark(index);
-		}
-	}
-	return EOK;
-}
-
-int sockets_connect(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen){
-	ERROR_DECLARE;
-
-	int index;
-
-	if(verbose){
-		printf("\tConnect\t");
-	}
-	fflush(stdout);
-	for(index = 0; index < sockets; ++ index){
-		if(ERROR_OCCURRED(connect(socket_ids[index], address, addrlen))){
-			socket_print_error(stderr, ERROR_CODE, "Socket connect: ", "\n");
-			return ERROR_CODE;
-		}
-		if(verbose){
-			print_mark(index);
-		}
-	}
-	return EOK;
-}
-
-int sockets_sendto(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages){
-	ERROR_DECLARE;
-
-	int index;
-	int message;
-
-	if(verbose){
-		printf("\tSendto\t");
-	}
-	fflush(stdout);
-	for(index = 0; index < sockets; ++ index){
-		for(message = 0; message < messages; ++ message){
-			if(ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, addrlen))){
-				printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
-				socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
-				return ERROR_CODE;
-			}
-		}
-		if(verbose){
-			print_mark(index);
-		}
-	}
-	return EOK;
-}
-
-int sockets_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){
-	int value;
-	int index;
-	int message;
-
-	if(verbose){
-		printf("\tRecvfrom\t");
-	}
-	fflush(stdout);
-	for(index = 0; index < sockets; ++ index){
-		for(message = 0; message < messages; ++ message){
-			value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
-			if(value < 0){
-				printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
-				socket_print_error(stderr, value, "Socket receive: ", "\n");
-				return value;
-			}
-		}
-		if(verbose){
-			print_mark(index);
-		}
-	}
-	return EOK;
-}
-
-int sockets_sendto_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){
-	ERROR_DECLARE;
-
-	int value;
-	int index;
-	int message;
-
-	if(verbose){
-		printf("\tSendto and recvfrom\t");
-	}
-	fflush(stdout);
-	for(index = 0; index < sockets; ++ index){
-		for(message = 0; message < messages; ++ message){
-			if(ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, * addrlen))){
-				printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
-				socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
-				return ERROR_CODE;
-			}
-			value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
-			if(value < 0){
-				printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
-				socket_print_error(stderr, value, "Socket receive: ", "\n");
-				return value;
-			}
-		}
-		if(verbose){
-			print_mark(index);
-		}
-	}
-	return EOK;
-}
-
-void print_mark(int index){
-	if((index + 1) % 10){
-		printf("*");
-	}else{
-		printf("|");
-	}
-	fflush(stdout);
-}
-
-/** @}
- */
Index: pace/srv/net/app/nettest.h
===================================================================
--- uspace/srv/net/app/nettest.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,126 +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 nettest
- *  @{
- */
-
-/** @file
- *  Networking test support functions.
- */
-
-#ifndef __NET_TEST__
-#define __NET_TEST__
-
-#include "../include/socket.h"
-
-/** Prints a mark.
- *  If the index is a multiple of ten, a different mark is printed.
- *  @param[in] index The index of the mark to be printed.
- */
-void print_mark(int index);
-
-/** Creates new sockets.
- *  @param[in] verbose A value indicating whether to print out verbose information.
- *  @param[out] socket_ids A field to store the socket identifiers.
- *  @param[in] sockets The number of sockets to create. Should be at most the size of the field.
- *  @param[in] family The socket address family.
- *  @param[in] type The socket type.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the socket() function.
- */
-int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type);
-
-/** Closes sockets.
- *  @param[in] verbose A value indicating whether to print out verbose information.
- *  @param[in] socket_ids A field of stored socket identifiers.
- *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the closesocket() function.
- */
-int sockets_close(int verbose, int * socket_ids, int sockets);
-
-/** Connects sockets.
- *  @param[in] verbose A value indicating whether to print out verbose information.
- *  @param[in] socket_ids A field of stored socket identifiers.
- *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
- *  @param[in] address The destination host address to connect to.
- *  @param[in] addrlen The length of the destination address in bytes.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the connect() function.
- */
-int sockets_connect(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen);
-
-/** Sends data via sockets.
- *  @param[in] verbose A value indicating whether to print out verbose information.
- *  @param[in] socket_ids A field of stored socket identifiers.
- *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
- *  @param[in] address The destination host address to send data to.
- *  @param[in] addrlen The length of the destination address in bytes.
- *  @param[in] data The data to be sent.
- *  @param[in] size The data size in bytes.
- *  @param[in] messages The number of datagrams per socket to be sent.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the sendto() function.
- */
-int sockets_sendto(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages);
-
-/** Receives data via sockets.
- *  @param[in] verbose A value indicating whether to print out verbose information.
- *  @param[in] socket_ids A field of stored socket identifiers.
- *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
- *  @param[in] address The source host address of received datagrams.
- *  @param[in,out] addrlen The maximum length of the source address in bytes. The actual size of the source address is set instead.
- *  @param[out] data The received data.
- *  @param[in] size The maximum data size in bytes.
- *  @param[in] messages The number of datagrams per socket to be received.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the recvfrom() function.
- */
-int sockets_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages);
-
-/** Sends and receives data via sockets.
- *  Each datagram is sent and a reply read consequently.
- *  The next datagram is sent after the reply is received.
- *  @param[in] verbose A value indicating whether to print out verbose information.
- *  @param[in] socket_ids A field of stored socket identifiers.
- *  @param[in] sockets The number of sockets in the field. Should be at most the size of the field.
- *  @param[in,out] address The destination host address to send data to. The source host address of received datagrams is set instead.
- *  @param[in] addrlen The length of the destination address in bytes.
- *  @param[in,out] data The data to be sent. The received data are set instead.
- *  @param[in] size The data size in bytes.
- *  @param[in] messages The number of datagrams per socket to be received.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the recvfrom() function.
- */
-int sockets_sendto_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/app/nettest1/Makefile
===================================================================
--- uspace/srv/net/app/nettest1/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,41 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# 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.
-#
-
-NET_BASE = ../..
-USPACE_PREFIX = ../../../..
-LIBS = $(NET_BASE)/socket/libsocket.a
-BINARY = nettest1
-
-SOURCES = \
-	nettest1.c \
-	$(NET_BASE)/app/nettest.c \
-	$(NET_BASE)/app/parse.c \
-	$(NET_BASE)/app/print_error.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: pace/srv/net/app/nettest1/nettest1.c
===================================================================
--- uspace/srv/net/app/nettest1/nettest1.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,425 +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 nettest
- *  @{
- */
-
-/** @file
- *  Networking test 1 application - sockets.
- */
-
-#include <malloc.h>
-#include <stdio.h>
-#include <str.h>
-#include <task.h>
-#include <time.h>
-
-#include "../../include/in.h"
-#include "../../include/in6.h"
-#include "../../include/inet.h"
-#include "../../include/socket.h"
-
-#include "../../err.h"
-
-#include "../nettest.h"
-#include "../parse.h"
-#include "../print_error.h"
-
-/** Echo module name.
- */
-#define NAME	"Nettest1"
-
-/** Packet data pattern.
- */
-#define NETTEST1_TEXT	"Networking test 1 - sockets"
-
-/** Module entry point.
- *  Starts testing.
- *  @param[in] argc The number of command line parameters.
- *  @param[in] argv The command line parameters.
- *  @returns EOK on success.
- */
-int main(int argc, char * argv[]);
-
-/** Prints the application help.
- */
-void nettest1_print_help(void);
-
-/** Refreshes the data.
- *  Fills the data block with the NETTEST1_TEXT pattern.
- *  @param[out] data The data block.
- *  @param[in] size The data block size in bytes.
- */
-void nettest1_refresh_data(char * data, size_t size);
-
-int main(int argc, char * argv[]){
-	ERROR_DECLARE;
-
-	size_t size			= 27;
-	int verbose			= 0;
-	sock_type_t type	= SOCK_DGRAM;
-	int sockets			= 10;
-	int messages		= 10;
-	int family			= PF_INET;
-	uint16_t port		= 7;
-
-	socklen_t max_length				= sizeof(struct sockaddr_in6);
-	uint8_t address_data[max_length];
-	struct sockaddr * address			= (struct sockaddr *) address_data;
-	struct sockaddr_in * address_in		= (struct sockaddr_in *) address;
-	struct sockaddr_in6 * address_in6	= (struct sockaddr_in6 *) address;
-	socklen_t addrlen;
-//	char address_string[INET6_ADDRSTRLEN];
-	uint8_t * address_start;
-
-	int * socket_ids;
-	char * data;
-	int value;
-	int index;
-	struct timeval time_before;
-	struct timeval time_after;
-
-	// print the program label
-	printf("Task %d - ", task_get_id());
-	printf("%s\n", NAME);
-
-	// parse the command line arguments
-	// stop before the last argument if it does not start with the minus sign ('-')
-	for(index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index){
-		// options should start with the minus sign ('-')
-		if(argv[index][0] == '-'){
-			switch(argv[index][1]){
-				// short options with only one letter
-				case 'f':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, parse_protocol_family));
-					break;
-				case 'h':
-					nettest1_print_help();
-					return EOK;
-					break;
-				case 'm':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 0));
-					break;
-				case 'n':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 0));
-					break;
-				case 'p':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 0));
-					port = (uint16_t) value;
-					break;
-				case 's':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 0));
-					size = (value >= 0) ? (size_t) value : 0;
-					break;
-				case 't':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, parse_socket_type));
-					type = (sock_type_t) value;
-					break;
-				case 'v':
-					verbose = 1;
-					break;
-				// long options with the double minus sign ('-')
-				case '-':
-					if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, parse_protocol_family));
-					}else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
-						nettest1_print_help();
-						return EOK;
-					}else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 8));
-					}else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 8));
-					}else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 7));
-						port = (uint16_t) value;
-					}else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, parse_socket_type));
-						type = (sock_type_t) value;
-					}else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
-						verbose = 1;
-					}else{
-						print_unrecognized(index, argv[index] + 2);
-						nettest1_print_help();
-						return EINVAL;
-					}
-					break;
-				default:
-					print_unrecognized(index, argv[index] + 1);
-					nettest1_print_help();
-					return EINVAL;
-			}
-		}else{
-			print_unrecognized(index, argv[index]);
-			nettest1_print_help();
-			return EINVAL;
-		}
-	}
-
-	// if not before the last argument containing the address
-	if(index >= argc){
-		printf("Command line error: missing address\n");
-		nettest1_print_help();
-		return EINVAL;
-	}
-
-	// prepare the address buffer
-	bzero(address_data, max_length);
-	switch(family){
-		case PF_INET:
-			address_in->sin_family = AF_INET;
-			address_in->sin_port = htons(port);
-			address_start = (uint8_t *) &address_in->sin_addr.s_addr;
-			addrlen = sizeof(struct sockaddr_in);
-			break;
-		case PF_INET6:
-			address_in6->sin6_family = AF_INET6;
-			address_in6->sin6_port = htons(port);
-			address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
-			addrlen = sizeof(struct sockaddr_in6);
-			break;
-		default:
-			fprintf(stderr, "Address family is not supported\n");
-			return EAFNOSUPPORT;
-	}
-
-	// parse the last argument which should contain the address
-	if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
-		fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
-		return ERROR_CODE;
-	}
-
-	// check the buffer size
-	if(size <= 0){
-		fprintf(stderr, "Data buffer size too small (%d). Using 1024 bytes instead.\n", size);
-		size = 1024;
-	}
-
-	// prepare the buffer
-	// size plus the terminating null (\0)
-	data = (char *) malloc(size + 1);
-	if(! data){
-		fprintf(stderr, "Failed to allocate data buffer.\n");
-		return ENOMEM;
-	}
-	nettest1_refresh_data(data, size);
-
-	// check the socket count
-	if(sockets <= 0){
-		fprintf(stderr, "Socket count too small (%d). Using 2 instead.\n", sockets);
-		sockets = 2;
-	}
-
-	// prepare the socket buffer
-	// count plus the terminating null (\0)
-	socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
-	if(! socket_ids){
-		fprintf(stderr, "Failed to allocate receive buffer.\n");
-		return ENOMEM;
-	}
-	socket_ids[sockets] = NULL;
-
-	if(verbose){
-		printf("Starting tests\n");
-	}
-
-	if(verbose){
-		printf("1 socket, 1 message\n");
-	}
-
-	if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
-		fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
-		return ERROR_CODE;
-	}
-
-	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
-	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
-	if(verbose){
-		printf("\tOK\n");
-	}
-
-	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
-	if(type == SOCK_STREAM){
-		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
-	}
-	ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, 1));
-	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
-	if(verbose){
-		printf("\tOK\n");
-	}
-
-	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
-	if(type == SOCK_STREAM){
-		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
-	}
-	ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, 1, address, addrlen, data, size, 1));
-	ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, 1));
-	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
-	if(verbose){
-		printf("\tOK\n");
-	}
-
-	if(verbose){
-		printf("1 socket, %d messages\n", messages);
-	}
-
-	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
-	if(type == SOCK_STREAM){
-		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
-	}
-	ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, messages));
-	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
-	if(verbose){
-		printf("\tOK\n");
-	}
-
-	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, 1, family, type));
-	if(type == SOCK_STREAM){
-		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, 1, address, addrlen));
-	}
-	ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, 1, address, addrlen, data, size, messages));
-	ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, 1, address, &addrlen, data, size, messages));
-	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, 1));
-	if(verbose){
-		printf("\tOK\n");
-	}
-
-	if(verbose){
-		printf("%d sockets, 1 message\n", sockets);
-	}
-
-	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
-	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
-	if(verbose){
-		printf("\tOK\n");
-	}
-
-	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
-	if(type == SOCK_STREAM){
-		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
-	}
-	ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, 1));
-	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
-	if(verbose){
-		printf("\tOK\n");
-	}
-
-	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
-	if(type == SOCK_STREAM){
-		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
-	}
-	ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, 1));
-	ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, 1));
-	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
-	if(verbose){
-		printf("\tOK\n");
-	}
-
-	if(verbose){
-		printf("%d sockets, %d messages\n", sockets, messages);
-	}
-
-	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
-	if(type == SOCK_STREAM){
-		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
-	}
-	ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
-	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
-	if(verbose){
-		printf("\tOK\n");
-	}
-
-	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
-	if(type == SOCK_STREAM){
-		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
-	}
-	ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages));
-	ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
-	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
-
-	if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
-		fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
-		return ERROR_CODE;
-	}
-
-	if(verbose){
-		printf("\tOK\n");
-	}
-
-	printf("Tested in %d microseconds\n", tv_sub(&time_after, &time_before));
-
-	if(verbose){
-		printf("Exiting\n");
-	}
-
-	return EOK;
-}
-
-void nettest1_print_help(void){
-	printf(
-		"Network Networking test 1 aplication - sockets\n" \
-		"Usage: echo [options] numeric_address\n" \
-		"Where options are:\n" \
-		"-f protocol_family | --family=protocol_family\n" \
-		"\tThe listenning socket protocol family. Only the PF_INET and PF_INET6 are supported.\n"
-		"\n" \
-		"-h | --help\n" \
-		"\tShow this application help.\n"
-		"\n" \
-		"-m count | --messages=count\n" \
-		"\tThe number of messages to send and receive per socket. The default is 10.\n" \
-		"\n" \
-		"-n sockets | --sockets=count\n" \
-		"\tThe number of sockets to use. The default is 10.\n" \
-		"\n" \
-		"-p port_number | --port=port_number\n" \
-		"\tThe port number the application should send messages to. The default is 7.\n" \
-		"\n" \
-		"-s packet_size | --size=packet_size\n" \
-		"\tThe packet data size the application sends. The default is 28 bytes.\n" \
-		"\n" \
-		"-v | --verbose\n" \
-		"\tShow all output messages.\n"
-	);
-}
-
-void nettest1_refresh_data(char * data, size_t size){
-	size_t length;
-
-	// fill the data
-	length = 0;
-	while(size > length + sizeof(NETTEST1_TEXT) - 1){
-		memcpy(data + length, NETTEST1_TEXT, sizeof(NETTEST1_TEXT) - 1);
-		length += sizeof(NETTEST1_TEXT) - 1;
-	}
-	memcpy(data + length, NETTEST1_TEXT, size - length);
-	data[size] = '\0';
-}
-
-/** @}
- */
Index: pace/srv/net/app/nettest2/Makefile
===================================================================
--- uspace/srv/net/app/nettest2/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,41 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# 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.
-#
-
-NET_BASE = ../..
-USPACE_PREFIX = ../../../..
-LIBS = $(NET_BASE)/socket/libsocket.a
-BINARY = nettest2
-
-SOURCES = \
-	nettest2.c \
-	$(NET_BASE)/app/nettest.c \
-	$(NET_BASE)/app/parse.c \
-	$(NET_BASE)/app/print_error.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: pace/srv/net/app/nettest2/nettest2.c
===================================================================
--- uspace/srv/net/app/nettest2/nettest2.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,348 +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 nettest
- *  @{
- */
-
-/** @file
- *  Networking test 2 application - transfer.
- */
-
-#include <malloc.h>
-#include <stdio.h>
-#include <str.h>
-#include <task.h>
-#include <time.h>
-
-#include "../../include/in.h"
-#include "../../include/in6.h"
-#include "../../include/inet.h"
-#include "../../include/socket.h"
-
-#include "../../err.h"
-
-#include "../nettest.h"
-#include "../parse.h"
-#include "../print_error.h"
-
-/** Echo module name.
- */
-#define NAME	"Nettest2"
-
-/** Packet data pattern.
- */
-#define NETTEST2_TEXT	"Networking test 2 - transfer"
-
-/** Module entry point.
- *  Starts testing.
- *  @param[in] argc The number of command line parameters.
- *  @param[in] argv The command line parameters.
- *  @returns EOK on success.
- */
-int main(int argc, char * argv[]);
-
-/** Prints the application help.
- */
-void nettest2_print_help(void);
-
-/** Refreshes the data.
- *  Fills the data block with the NETTEST1_TEXT pattern.
- *  @param[out] data The data block.
- *  @param[in] size The data block size in bytes.
- */
-void nettest2_refresh_data(char * data, size_t size);
-
-int main(int argc, char * argv[]){
-	ERROR_DECLARE;
-
-	size_t size			= 28;
-	int verbose			= 0;
-	sock_type_t type	= SOCK_DGRAM;
-	int sockets			= 10;
-	int messages		= 10;
-	int family			= PF_INET;
-	uint16_t port		= 7;
-
-	socklen_t max_length				= sizeof(struct sockaddr_in6);
-	uint8_t address_data[max_length];
-	struct sockaddr * address			= (struct sockaddr *) address_data;
-	struct sockaddr_in * address_in		= (struct sockaddr_in *) address;
-	struct sockaddr_in6 * address_in6	= (struct sockaddr_in6 *) address;
-	socklen_t addrlen;
-//	char address_string[INET6_ADDRSTRLEN];
-	uint8_t * address_start;
-
-	int * socket_ids;
-	char * data;
-	int value;
-	int index;
-	struct timeval time_before;
-	struct timeval time_after;
-
-	printf("Task %d - ", task_get_id());
-	printf("%s\n", NAME);
-
-	// parse the command line arguments
-	// stop before the last argument if it does not start with the minus sign ('-')
-	for(index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index){
-		// options should start with the minus sign ('-')
-		if(argv[index][0] == '-'){
-			switch(argv[index][1]){
-				// short options with only one letter
-				case 'f':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 0, parse_protocol_family));
-					break;
-				case 'h':
-					nettest2_print_help();
-					return EOK;
-					break;
-				case 'm':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 0));
-					break;
-				case 'n':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 0));
-					break;
-				case 'p':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 0));
-					port = (uint16_t) value;
-					break;
-				case 's':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 0));
-					size = (value >= 0) ? (size_t) value : 0;
-					break;
-				case 't':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 0, parse_socket_type));
-					type = (sock_type_t) value;
-					break;
-				case 'v':
-					verbose = 1;
-					break;
-				// long options with the double minus sign ('-')
-				case '-':
-					if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "protocol family", 9, parse_protocol_family));
-					}else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
-						nettest2_print_help();
-						return EOK;
-					}else if(str_lcmp(argv[index] + 2, "messages=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &messages, "message count", 8));
-					}else if(str_lcmp(argv[index] + 2, "sockets=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &sockets, "socket count", 8));
-					}else if(str_lcmp(argv[index] + 2, "port=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "port number", 7));
-						port = (uint16_t) value;
-					}else if(str_lcmp(argv[index] + 2, "type=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &value, "socket type", 7, parse_socket_type));
-						type = (sock_type_t) value;
-					}else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
-						verbose = 1;
-					}else{
-						print_unrecognized(index, argv[index] + 2);
-						nettest2_print_help();
-						return EINVAL;
-					}
-					break;
-				default:
-					print_unrecognized(index, argv[index] + 1);
-					nettest2_print_help();
-					return EINVAL;
-			}
-		}else{
-			print_unrecognized(index, argv[index]);
-			nettest2_print_help();
-			return EINVAL;
-		}
-	}
-
-	// if not before the last argument containing the address
-	if(index >= argc){
-		printf("Command line error: missing address\n");
-		nettest2_print_help();
-		return EINVAL;
-	}
-
-	// prepare the address buffer
-	bzero(address_data, max_length);
-	switch(family){
-		case PF_INET:
-			address_in->sin_family = AF_INET;
-			address_in->sin_port = htons(port);
-			address_start = (uint8_t *) &address_in->sin_addr.s_addr;
-			addrlen = sizeof(struct sockaddr_in);
-			break;
-		case PF_INET6:
-			address_in6->sin6_family = AF_INET6;
-			address_in6->sin6_port = htons(port);
-			address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
-			addrlen = sizeof(struct sockaddr_in6);
-			break;
-		default:
-			fprintf(stderr, "Address family is not supported\n");
-			return EAFNOSUPPORT;
-	}
-
-	// parse the last argument which should contain the address
-	if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
-		fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
-		return ERROR_CODE;
-	}
-
-	// check the buffer size
-	if(size <= 0){
-		fprintf(stderr, "Data buffer size too small (%d). Using 1024 bytes instead.\n", size);
-		size = 1024;
-	}
-
-	// prepare the buffer
-	// size plus terminating null (\0)
-	data = (char *) malloc(size + 1);
-	if(! data){
-		fprintf(stderr, "Failed to allocate data buffer.\n");
-		return ENOMEM;
-	}
-	nettest2_refresh_data(data, size);
-
-	// check the socket count
-	if(sockets <= 0){
-		fprintf(stderr, "Socket count too small (%d). Using 2 instead.\n", sockets);
-		sockets = 2;
-	}
-
-	// prepare the socket buffer
-	// count plus the terminating null (\0)
-	socket_ids = (int *) malloc(sizeof(int) * (sockets + 1));
-	if(! socket_ids){
-		fprintf(stderr, "Failed to allocate receive buffer.\n");
-		return ENOMEM;
-	}
-	socket_ids[sockets] = NULL;
-
-	if(verbose){
-		printf("Starting tests\n");
-	}
-
-	ERROR_PROPAGATE(sockets_create(verbose, socket_ids, sockets, family, type));
-
-	if(type == SOCK_STREAM){
-		ERROR_PROPAGATE(sockets_connect(verbose, socket_ids, sockets, address, addrlen));
-	}
-
-	if(verbose){
-		printf("\n");
-	}
-
-	if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
-		fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
-		return ERROR_CODE;
-	}
-
-	ERROR_PROPAGATE(sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
-
-	if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
-		fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
-		return ERROR_CODE;
-	}
-
-	if(verbose){
-		printf("\tOK\n");
-	}
-
-	printf("sendto + recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before));
-
-	if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
-		fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
-		return ERROR_CODE;
-	}
-
-	ERROR_PROPAGATE(sockets_sendto(verbose, socket_ids, sockets, address, addrlen, data, size, messages));
-	ERROR_PROPAGATE(sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, data, size, messages));
-
-	if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
-		fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
-		return ERROR_CODE;
-	}
-
-	if(verbose){
-		printf("\tOK\n");
-	}
-
-	printf("sendto, recvfrom tested in %d microseconds\n", tv_sub(&time_after, &time_before));
-
-	ERROR_PROPAGATE(sockets_close(verbose, socket_ids, sockets));
-
-	if(verbose){
-		printf("\nExiting\n");
-	}
-
-	return EOK;
-}
-
-void nettest2_print_help(void){
-	printf(
-		"Network Networking test 2 aplication - UDP transfer\n" \
-		"Usage: echo [options] numeric_address\n" \
-		"Where options are:\n" \
-		"-f protocol_family | --family=protocol_family\n" \
-		"\tThe listenning socket protocol family. Only the PF_INET and PF_INET6 are supported.\n"
-		"\n" \
-		"-h | --help\n" \
-		"\tShow this application help.\n"
-		"\n" \
-		"-m count | --messages=count\n" \
-		"\tThe number of messages to send and receive per socket. The default is 10.\n" \
-		"\n" \
-		"-n sockets | --sockets=count\n" \
-		"\tThe number of sockets to use. The default is 10.\n" \
-		"\n" \
-		"-p port_number | --port=port_number\n" \
-		"\tThe port number the application should send messages to. The default is 7.\n" \
-		"\n" \
-		"-s packet_size | --size=packet_size\n" \
-		"\tThe packet data size the application sends. The default is 29 bytes.\n" \
-		"\n" \
-		"-v | --verbose\n" \
-		"\tShow all output messages.\n"
-	);
-}
-
-void nettest2_refresh_data(char * data, size_t size){
-	size_t length;
-
-	// fill the data
-	length = 0;
-	while(size > length + sizeof(NETTEST2_TEXT) - 1){
-		memcpy(data + length, NETTEST2_TEXT, sizeof(NETTEST2_TEXT) - 1);
-		length += sizeof(NETTEST2_TEXT) - 1;
-	}
-	memcpy(data + length, NETTEST2_TEXT, size - length);
-	data[size] = '\0';
-}
-
-/** @}
- */
Index: pace/srv/net/app/parse.c
===================================================================
--- uspace/srv/net/app/parse.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,124 +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 net_app
- *  @{
- */
-
-/** @file
- *  Generic application parsing functions implementation.
- */
-
-#include <stdio.h>
-#include <str.h>
-
-#include "../include/socket.h"
-
-#include "../err.h"
-
-#include "parse.h"
-
-int parse_address_family(const char * name){
-	if(str_lcmp(name, "AF_INET", 7) == 0){
-		return AF_INET;
-	}else if(str_lcmp(name, "AF_INET6", 8) == 0){
-		return AF_INET6;
-	}
-	return EAFNOSUPPORT;
-}
-
-int parse_parameter_int(int argc, char ** argv, int * index, int * value, const char * name, int offset){
-	char * rest;
-
-	if(offset){
-		*value = strtol(argv[*index] + offset, &rest, 10);
-	}else if((*index) + 1 < argc){
-		++ (*index);
-		*value = strtol(argv[*index], &rest, 10);
-	}else{
-		fprintf(stderr, "Command line error: missing %s\n", name);
-		return EINVAL;
-	}
-	if(rest && (*rest)){
-		fprintf(stderr, "Command line error: %s unrecognized (%d: %s)\n", name, * index, argv[*index]);
-		return EINVAL;
-	}
-	return EOK;
-}
-
-int parse_parameter_name_int(int argc, char ** argv, int * index, int * value, const char * name, int offset, int (*parse_value)(const char * value)){
-	ERROR_DECLARE;
-
-	char * parameter;
-
-	ERROR_PROPAGATE(parse_parameter_string(argc, argv, index, &parameter, name, offset));
-	*value = (*parse_value)(parameter);
-	if((*value) == ENOENT){
-		fprintf(stderr, "Command line error: unrecognized %s value (%d: %s)\n", name, * index, parameter);
-		return ENOENT;
-	}
-	return EOK;
-}
-
-int parse_parameter_string(int argc, char ** argv, int * index, char ** value, const char * name, int offset){
-	if(offset){
-		*value = argv[*index] + offset;
-	}else if((*index) + 1 < argc){
-		++ (*index);
-		*value = argv[*index];
-	}else{
-		fprintf(stderr, "Command line error: missing %s\n", name);
-		return EINVAL;
-	}
-	return EOK;
-}
-
-int parse_protocol_family(const char * name){
-	if(str_lcmp(name, "PF_INET", 7) == 0){
-		return PF_INET;
-	}else if(str_lcmp(name, "PF_INET6", 8) == 0){
-		return PF_INET6;
-	}
-	return EPFNOSUPPORT;
-}
-
-int parse_socket_type(const char * name){
-	if(str_lcmp(name, "SOCK_DGRAM", 11) == 0){
-		return SOCK_DGRAM;
-	}else if(str_lcmp(name, "SOCK_STREAM", 12) == 0){
-		return SOCK_STREAM;
-	}
-	return ESOCKTNOSUPPORT;
-}
-
-void print_unrecognized(int index, const char * parameter){
-	fprintf(stderr, "Command line error: unrecognized argument (%d: %s)\n", index, parameter);
-}
-
-/** @}
- */
Index: pace/srv/net/app/parse.h
===================================================================
--- uspace/srv/net/app/parse.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,120 +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 net_app
- *  @{
- */
-
-/** @file
- *  Generic command line arguments parsing functions.
- */
-
-#ifndef __NET_APP_PARSE__
-#define __NET_APP_PARSE__
-
-#include "../include/socket.h"
-
-/** Translates the character string to the address family number.
- *  @param[in] name The address family name.
- *  @returns The corresponding address family number.
- *  @returns EAFNOSUPPORTED if the address family is not supported.
- */
-int parse_address_family(const char * name);
-
-/** Parses the next parameter as an integral number.
- *  The actual parameter is pointed by the index.
- *  Parses the offseted actual parameter value if the offset is set or the next one if not.
- *  @param[in] argc The total number of the parameters.
- *  @param[in] argv The parameters.
- *  @param[in,out] index The actual parameter index. The index is incremented by the number of processed parameters.
- *  @param[out] value The parsed parameter value.
- *  @param[in] name The parameter name to be printed on errors.
- *  @param[in] offset The value offset in the actual parameter. If not set, the next parameter is parsed instead.
- *  @returns EOK on success.
- *  @returns EINVAL if the parameter is missing.
- *  @returns EINVAL if the parameter is in wrong format.
- */
-int parse_parameter_int(int argc, char ** argv, int * index, int * value, const char * name, int offset);
-
-/** Parses the next named parameter as an integral number.
- *  The actual parameter is pointed by the index.
- *  Uses the offseted actual parameter if the offset is set or the next one if not.
- *  Translates the parameter using the parse_value function.
- *  Increments the actual index by the number of processed parameters.
- *  @param[in] argc The total number of the parameters.
- *  @param[in] argv The parameters.
- *  @param[in,out] index The actual parameter index. The index is incremented by the number of processed parameters.
- *  @param[out] value The parsed parameter value.
- *  @param[in] name The parameter name to be printed on errors.
- *  @param[in] offset The value offset in the actual parameter. If not set, the next parameter is parsed instead.
- *  @param[in] parse_value The translation function to parse the named value.
- *  @returns EOK on success.
- *  @returns EINVAL if the parameter is missing.
- *  @returns ENOENT if the parameter name has not been found.
- */
-int parse_parameter_name_int(int argc, char ** argv, int * index, int * value, const char * name, int offset, int (*parse_value)(const char * value));
-
-/** Parses the next parameter as a character string.
- *  The actual parameter is pointed by the index.
- *  Uses the offseted actual parameter value if the offset is set or the next one if not.
- *  Increments the actual index by the number of processed parameters.
- *  @param[in] argc The total number of the parameters.
- *  @param[in] argv The parameters.
- *  @param[in,out] index The actual parameter index. The index is incremented by the number of processed parameters.
- *  @param[out] value The parsed parameter value.
- *  @param[in] name The parameter name to be printed on errors.
- *  @param[in] offset The value offset in the actual parameter. If not set, the next parameter is parsed instead.
- *  @returns EOK on success.
- *  @returns EINVAL if the parameter is missing.
- */
-int parse_parameter_string(int argc, char ** argv, int * index, char ** value, const char * name, int offset);
-
-/** Translates the character string to the protocol family number.
- *  @param[in] name The protocol family name.
- *  @returns The corresponding protocol family number.
- *  @returns EPFNOSUPPORTED if the protocol family is not supported.
- */
-int parse_protocol_family(const char * name);
-
-/** Translates the character string to the socket type number.
- *  @param[in] name The socket type name.
- *  @returns The corresponding socket type number.
- *  @returns ESOCKNOSUPPORTED if the socket type is not supported.
- */
-int parse_socket_type(const char * name);
-
-/** Prints the parameter unrecognized message and the application help.
- *  @param[in] index The index of the parameter.
- *  @param[in] parameter The parameter name.
- */
-void print_unrecognized(int index, const char * parameter);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/app/ping/Makefile
===================================================================
--- uspace/srv/net/app/ping/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,44 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# 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.
-#
-
-NET_BASE = ../..
-USPACE_PREFIX = ../../../..
-LIBS = $(NET_BASE)/socket/libsocket.a
-BINARY = ping
-
-SOURCES = \
-	ping.c \
-	$(NET_BASE)/app/parse.c \
-	$(NET_BASE)/app/print_error.c \
-	$(NET_BASE)/inet.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/tl/icmp/icmp_api.c \
-	$(NET_BASE)/tl/icmp/icmp_common.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: pace/srv/net/app/ping/ping.c
===================================================================
--- uspace/srv/net/app/ping/ping.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,302 +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 ping
- *  @{
- */
-
-/** @file
- *  Ping application.
- */
-
-#include <stdio.h>
-#include <str.h>
-#include <task.h>
-#include <time.h>
-#include <ipc/ipc.h>
-#include <ipc/services.h>
-
-#include "../../include/icmp_api.h"
-#include "../../include/in.h"
-#include "../../include/in6.h"
-#include "../../include/inet.h"
-#include "../../include/ip_codes.h"
-#include "../../include/socket_errno.h"
-
-#include "../../err.h"
-
-#include "../parse.h"
-#include "../print_error.h"
-
-/** Echo module name.
- */
-#define NAME	"Ping"
-
-/** Module entry point.
- *  Reads command line parameters and pings.
- *  @param[in] argc The number of command line parameters.
- *  @param[in] argv The command line parameters.
- *  @returns EOK on success.
- */
-int main(int argc, char * argv[]);
-
-/** Prints the application help.
- */
-void ping_print_help(void);
-
-int main(int argc, char * argv[]){
-	ERROR_DECLARE;
-
-	size_t size			= 38;
-	int verbose			= 0;
-	int dont_fragment	= 0;
-	ip_ttl_t ttl		= 0;
-	ip_tos_t tos		= 0;
-	int count			= 3;
-	suseconds_t timeout	= 3000;
-	int family			= AF_INET;
-
-	socklen_t max_length				= sizeof(struct sockaddr_in6);
-	uint8_t address_data[max_length];
-	struct sockaddr * address			= (struct sockaddr *) address_data;
-	struct sockaddr_in * address_in		= (struct sockaddr_in *) address;
-	struct sockaddr_in6 * address_in6	= (struct sockaddr_in6 *) address;
-	socklen_t addrlen;
-	char address_string[INET6_ADDRSTRLEN];
-	uint8_t * address_start;
-	int icmp_phone;
-	struct timeval time_before;
-	struct timeval time_after;
-	int result;
-	int value;
-	int index;
-
-	// print the program label
-	printf("Task %d - ", task_get_id());
-	printf("%s\n", NAME);
-
-	// parse the command line arguments
-	// stop before the last argument if it does not start with the minus sign ('-')
-	for(index = 1; (index < argc - 1) || ((index == argc - 1) && (argv[index][0] == '-')); ++ index){
-		// options should start with the minus sign ('-')
-		if(argv[index][0] == '-'){
-			switch(argv[index][1]){
-				// short options with only one letter
-				case 'c':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "count", 0));
-					break;
-				case 'f':
-					ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "address family", 0, parse_address_family));
-					break;
-				case 'h':
-					ping_print_help();
-					return EOK;
-					break;
-				case 's':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 0));
-					size = (value >= 0) ? (size_t) value : 0;
-					break;
-				case 't':
-					ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "timeout", 0));
-					timeout = (value >= 0) ? (suseconds_t) value : 0;
-					break;
-				case 'v':
-					verbose = 1;
-					break;
-				// long options with the double minus sign ('-')
-				case '-':
-					if(str_lcmp(argv[index] + 2, "count=", 6) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &count, "received count", 8));
-					}else if(str_lcmp(argv[index] + 2, "dont_fragment", 13) == 0){
-						dont_fragment = 1;
-					}else if(str_lcmp(argv[index] + 2, "family=", 7) == 0){
-						ERROR_PROPAGATE(parse_parameter_name_int(argc, argv, &index, &family, "address family", 9, parse_address_family));
-					}else if(str_lcmp(argv[index] + 2, "help", 5) == 0){
-						ping_print_help();
-						return EOK;
-					}else if(str_lcmp(argv[index] + 2, "size=", 5) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "packet size", 7));
-						size = (value >= 0) ? (size_t) value : 0;
-					}else if(str_lcmp(argv[index] + 2, "timeout=", 8) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "timeout", 7));
-						timeout = (value >= 0) ? (suseconds_t) value : 0;
-					}else if(str_lcmp(argv[index] + 2, "tos=", 4) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "type of service", 7));
-						tos = (value >= 0) ? (ip_tos_t) value : 0;
-					}else if(str_lcmp(argv[index] + 2, "ttl=", 4) == 0){
-						ERROR_PROPAGATE(parse_parameter_int(argc, argv, &index, &value, "time to live", 7));
-						ttl = (value >= 0) ? (ip_ttl_t) value : 0;
-					}else if(str_lcmp(argv[index] + 2, "verbose", 8) == 0){
-						verbose = 1;
-					}else{
-						print_unrecognized(index, argv[index] + 2);
-						ping_print_help();
-						return EINVAL;
-					}
-					break;
-				default:
-					print_unrecognized(index, argv[index] + 1);
-					ping_print_help();
-					return EINVAL;
-			}
-		}else{
-			print_unrecognized(index, argv[index]);
-			ping_print_help();
-			return EINVAL;
-		}
-	}
-
-	// if not before the last argument containing the address
-	if(index >= argc){
-		printf("Command line error: missing address\n");
-		ping_print_help();
-		return EINVAL;
-	}
-
-	// prepare the address buffer
-	bzero(address_data, max_length);
-	switch(family){
-		case AF_INET:
-			address_in->sin_family = AF_INET;
-			address_start = (uint8_t *) &address_in->sin_addr.s_addr;
-			addrlen = sizeof(struct sockaddr_in);
-			break;
-		case AF_INET6:
-			address_in6->sin6_family = AF_INET6;
-			address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;
-			addrlen = sizeof(struct sockaddr_in6);
-			break;
-		default:
-			fprintf(stderr, "Address family is not supported\n");
-			return EAFNOSUPPORT;
-	}
-
-	// parse the last argument which should contain the address
-	if(ERROR_OCCURRED(inet_pton(family, argv[argc - 1], address_start))){
-		fprintf(stderr, "Address parse error %d\n", ERROR_CODE);
-		return ERROR_CODE;
-	}
-
-	// connect to the ICMP module
-	icmp_phone = icmp_connect_module(SERVICE_ICMP, ICMP_CONNECT_TIMEOUT);
-	if(icmp_phone < 0){
-		fprintf(stderr, "ICMP connect error %d\n", icmp_phone);
-		return icmp_phone;
-	}
-
-	// print the ping header
-	printf("PING %d bytes of data\n", size);
-	if(ERROR_OCCURRED(inet_ntop(address->sa_family, address_start, address_string, sizeof(address_string)))){
-		fprintf(stderr, "Address error %d\n", ERROR_CODE);
-	}else{
-		printf("Address %s:\n", address_string);
-	}
-
-	// do count times
-	while(count > 0){
-
-		// get the starting time
-		if(ERROR_OCCURRED(gettimeofday(&time_before, NULL))){
-			fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
-			// release the ICMP phone
-			ipc_hangup(icmp_phone);
-			return ERROR_CODE;
-		}
-
-		// request the ping
-		result = icmp_echo_msg(icmp_phone, size, timeout, ttl, tos, dont_fragment, address, addrlen);
-
-		// get the ending time
-		if(ERROR_OCCURRED(gettimeofday(&time_after, NULL))){
-			fprintf(stderr, "Get time of day error %d\n", ERROR_CODE);
-			// release the ICMP phone
-			ipc_hangup(icmp_phone);
-			return ERROR_CODE;
-		}
-
-		// print the result
-		switch(result){
-			case ICMP_ECHO:
-				printf("Ping round trip time %d miliseconds\n", tv_sub(&time_after, &time_before) / 1000);
-				break;
-			case ETIMEOUT:
-				printf("Timed out.\n");
-				break;
-			default:
-				print_error(stdout, result, NULL, "\n");
-		}
-		-- count;
-	}
-
-	if(verbose){
-		printf("Exiting\n");
-	}
-
-	// release the ICMP phone
-	ipc_hangup(icmp_phone);
-
-	return EOK;
-}
-
-void ping_print_help(void){
-	printf(
-		"Network Ping aplication\n" \
-		"Usage: ping [options] numeric_address\n" \
-		"Where options are:\n" \
-		"\n" \
-		"-c request_count | --count=request_count\n" \
-		"\tThe number of packets the application sends. The default is three (3).\n" \
-		"\n" \
-		"--dont_fragment\n" \
-		"\tDisable packet fragmentation.\n"
-		"\n" \
-		"-f address_family | --family=address_family\n" \
-		"\tThe given address family. Only the AF_INET and AF_INET6 are supported.\n"
-		"\n" \
-		"-h | --help\n" \
-		"\tShow this application help.\n"
-		"\n" \
-		"-s packet_size | --size=packet_size\n" \
-		"\tThe packet data size the application sends. The default is 38 bytes.\n" \
-		"\n" \
-		"-t timeout | --timeout=timeout\n" \
-		"\tThe number of miliseconds the application waits for a reply. The default is three thousands (3 000).\n" \
-		"\n" \
-		"--tos=tos\n" \
-		"\tThe type of service to be used.\n" \
-		"\n" \
-		"--ttl=ttl\n" \
-		"\tThe time to live to be used.\n" \
-		"\n" \
-		"-v | --verbose\n" \
-		"\tShow all output messages.\n"
-	);
-}
-
-/** @}
- */
Index: pace/srv/net/app/print_error.c
===================================================================
--- uspace/srv/net/app/print_error.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,150 +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 net_app
- *  @{
- */
-
-/** @file
- *  Generic application error printing functions implementation.
- */
-
-#include <stdio.h>
-
-#include "../include/icmp_codes.h"
-#include "../include/socket_errno.h"
-
-#include "print_error.h"
-
-void icmp_print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
-	if(output){
-		if(prefix){
-			fprintf(output, "%s", prefix);
-		}
-		switch(error_code){
-			case ICMP_DEST_UNREACH:
-				fprintf(output, "ICMP Destination Unreachable (%d) error", error_code);
-				break;
-			case ICMP_SOURCE_QUENCH:
-				fprintf(output, "ICMP Source Quench (%d) error", error_code);
-				break;
-			case ICMP_REDIRECT:
-				fprintf(output, "ICMP Redirect (%d) error", error_code);
-				break;
-			case ICMP_ALTERNATE_ADDR:
-				fprintf(output, "ICMP Alternate Host Address (%d) error", error_code);
-				break;
-			case ICMP_ROUTER_ADV:
-				fprintf(output, "ICMP Router Advertisement (%d) error", error_code);
-				break;
-			case ICMP_ROUTER_SOL:
-				fprintf(output, "ICMP Router Solicitation (%d) error", error_code);
-				break;
-			case ICMP_TIME_EXCEEDED:
-				fprintf(output, "ICMP Time Exceeded (%d) error", error_code);
-				break;
-			case ICMP_PARAMETERPROB:
-				fprintf(output, "ICMP Paramenter Problem (%d) error", error_code);
-				break;
-			case ICMP_CONVERSION_ERROR:
-				fprintf(output, "ICMP Datagram Conversion Error (%d) error", error_code);
-				break;
-			case ICMP_REDIRECT_MOBILE:
-				fprintf(output, "ICMP Mobile Host Redirect (%d) error", error_code);
-				break;
-			case ICMP_SKIP:
-				fprintf(output, "ICMP SKIP (%d) error", error_code);
-				break;
-			case ICMP_PHOTURIS:
-				fprintf(output, "ICMP Photuris (%d) error", error_code);
-				break;
-			default:
-				fprintf(output, "Other (%d) error", error_code);
-		}
-		if(suffix){
-			fprintf(output, "%s", suffix);
-		}
-	}
-}
-
-void print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
-	if(IS_ICMP_ERROR(error_code)){
-		icmp_print_error(output, error_code, prefix, suffix);
-	}else if(IS_SOCKET_ERROR(error_code)){
-		socket_print_error(output, error_code, prefix, suffix);
-	}
-}
-
-void socket_print_error(FILE * output, int error_code, const char * prefix, const char * suffix){
-	if(output){
-		if(prefix){
-			fprintf(output, "%s", prefix);
-		}
-		switch(error_code){
-			case ENOTSOCK:
-				fprintf(output, "Not a socket (%d) error", error_code);
-				break;
-			case EPROTONOSUPPORT:
-				fprintf(output, "Protocol not supported (%d) error", error_code);
-				break;
-			case ESOCKTNOSUPPORT:
-				fprintf(output, "Socket type not supported (%d) error", error_code);
-				break;
-			case EPFNOSUPPORT:
-				fprintf(output, "Protocol family not supported (%d) error", error_code);
-				break;
-			case EAFNOSUPPORT:
-				fprintf(output, "Address family not supported (%d) error", error_code);
-				break;
-			case EADDRINUSE:
-				fprintf(output, "Address already in use (%d) error", error_code);
-				break;
-			case ENOTCONN:
-				fprintf(output, "Socket not connected (%d) error", error_code);
-				break;
-			case NO_DATA:
-				fprintf(output, "No data (%d) error", error_code);
-				break;
-			case EINPROGRESS:
-				fprintf(output, "Another operation in progress (%d) error", error_code);
-				break;
-			case EDESTADDRREQ:
-				fprintf(output, "Destination address required (%d) error", error_code);
-			case TRY_AGAIN:
-				fprintf(output, "Try again (%d) error", error_code);
-			default:
-				fprintf(output, "Other (%d) error", error_code);
-		}
-		if(suffix){
-			fprintf(output, "%s", suffix);
-		}
-	}
-}
-
-/** @}
- */
Index: pace/srv/net/app/print_error.h
===================================================================
--- uspace/srv/net/app/print_error.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,80 +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 net_app
- *  @{
- */
-
-/** @file
- *  Generic application error printing functions.
- */
-
-#ifndef __NET_APP_PRINT__
-#define __NET_APP_PRINT__
-
-/** Returns whether the error code may be an ICMP error code.
- *  @param[in] error_code The error code.
- *  @returns A value indicating whether the error code may be an ICMP error code.
- */
-#define IS_ICMP_ERROR(error_code)		((error_code) > 0)
-
-/** Returns whether the error code may be socket error code.
- *  @param[in] error_code The error code.
- *  @returns A value indicating whether the error code may be a socket error code.
- */
-#define IS_SOCKET_ERROR(error_code)	((error_code) < 0)
-
-/** Prints the specific ICMP error description.
- *  @param[in] output The description output stream. May be NULL.
- *  @param[in] error_code The ICMP error code.
- *  @param[in] prefix The error description prefix. May be NULL.
- *  @param[in] suffix The error description suffix. May be NULL.
- */
-void icmp_print_error(FILE * output, int error_code, const char * prefix, const char * suffix);
-
-/** Prints the error description.
- *  Supports ICMP and socket error codes.
- *  @param[in] output The description output stream. May be NULL.
- *  @param[in] error_code The error code.
- *  @param[in] prefix The error description prefix. May be NULL.
- *  @param[in] suffix The error description suffix. May be NULL.
- */
-void print_error(FILE * output, int error_code, const char * prefix, const char * suffix);
-
-/** Prints the specific socket error description.
- *  @param[in] output The description output stream. May be NULL.
- *  @param[in] error_code The socket error code.
- *  @param[in] prefix The error description prefix. May be NULL.
- *  @param[in] suffix The error description suffix. May be NULL.
- */
-void socket_print_error(FILE * output, int error_code, const char * prefix, const char * suffix);
-
-#endif
-
-/** @}
- */
Index: uspace/srv/net/cfg/Makefile
===================================================================
--- uspace/srv/net/cfg/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/net/cfg/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,60 @@
+#
+# Copyright (c) 2010 Martin Decky
+# 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.
+#
+
+USPACE_PREFIX = ../../..
+ROOT_PATH = $(USPACE_PREFIX)/..
+
+COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
+CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
+
+-include $(COMMON_MAKEFILE)
+-include $(CONFIG_MAKEFILE)
+
+ifeq ($(CONFIG_NETIF_NIL_BUNDLE),y)
+	LO_SOURCE = lo.netif_nil_bundle
+	NE2K_SOURCE = ne2k.netif_nil_bundle
+else
+	LO_SOURCE = lo.netif_standalone
+	NE2K_SOURCE = ne2k.netif_standalone
+endif
+
+LO_TARGET = lo
+NE2K_TARGET = ne2k
+
+.PHONY: all clean
+
+all: $(LO_TARGET) $(NE2K_TARGET)
+
+clean:
+	rm -f $(LO_TARGET) $(NE2K_TARGET)
+
+$(LO_TARGET): $(LO_SOURCE)
+	cp $< $@
+
+$(NE2K_TARGET): $(NE2K_SOURCE)
+	cp $< $@
Index: uspace/srv/net/cfg/general
===================================================================
--- uspace/srv/net/cfg/general	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/net/cfg/general	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,12 @@
+# general configuration
+
+IPV=4
+IP_ROUTING=no
+
+MTU=1500
+
+ICMP_ERROR_REPORTING=yes
+ICMP_ECHO_REPLYING=yes
+
+UDP_CHECKSUM_COMPUTING=yes
+UDP_AUTOBINDING=yes
Index: uspace/srv/net/cfg/lo.netif_nil_bundle
===================================================================
--- uspace/srv/net/cfg/lo.netif_nil_bundle	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/net/cfg/lo.netif_nil_bundle	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,13 @@
+# loopback configuration
+
+NAME=lo
+
+NETIF=lo
+NIL=lo
+IL=ip
+
+IP_CONFIG=static
+IP_ADDR=127.0.0.1
+IP_NETMASK=255.0.0.0
+
+MTU=15535
Index: uspace/srv/net/cfg/lo.netif_standalone
===================================================================
--- uspace/srv/net/cfg/lo.netif_standalone	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/net/cfg/lo.netif_standalone	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,13 @@
+# loopback configuration
+
+NAME=lo
+
+NETIF=lo
+NIL=nildummy
+IL=ip
+
+IP_CONFIG=static
+IP_ADDR=127.0.0.1
+IP_NETMASK=255.0.0.0
+
+MTU=15535
Index: pace/srv/net/cfg/modular/general
===================================================================
--- uspace/srv/net/cfg/modular/general	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,12 +1,0 @@
-# general configuration
-
-IPV=4
-IP_ROUTING=no
-
-MTU=1500
-
-ICMP_ERROR_REPORTING=yes
-ICMP_ECHO_REPLYING=yes
-
-UDP_CHECKSUM_COMPUTING=yes
-UDP_AUTOBINDING=yes
Index: pace/srv/net/cfg/modular/lo
===================================================================
--- uspace/srv/net/cfg/modular/lo	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,13 +1,0 @@
-# loopback configuration
-
-NAME=lo
-
-NETIF=lo
-NIL=nildummy
-IL=ip
-
-IP_CONFIG=static
-IP_ADDR=127.0.0.1
-IP_NETMASK=255.0.0.0
-
-MTU=15535
Index: pace/srv/net/cfg/modular/ne2k
===================================================================
--- uspace/srv/net/cfg/modular/ne2k	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,25 +1,0 @@
-# DP8390 (NE2k) configuration
-
-NAME=ne2k
-
-NETIF=dp8390
-NIL=ethernet
-IL=ip
-
-# sysinfo_value("netif.dp8390.inr")
-IRQ=9
-IO=300
-
-# 8023_2_LSAP, 8023_2_SNAP
-ETH_MODE=DIX
-ETH_DUMMY=no
-
-IP_CONFIG=static
-IP_ADDR=10.0.2.15
-IP_ROUTING=yes
-IP_NETMASK=255.255.255.240
-IP_BROADCAST=10.0.2.255
-IP_GATEWAY=10.0.2.2
-ARP=arp
-
-MTU=1492
Index: pace/srv/net/cfg/module/general
===================================================================
--- uspace/srv/net/cfg/module/general	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,12 +1,0 @@
-# general configuration
-
-IPV=4
-IP_ROUTING=no
-
-MTU=1500
-
-ICMP_ERROR_REPORTING=yes
-ICMP_ECHO_REPLYING=yes
-
-UDP_CHECKSUM_COMPUTING=yes
-UDP_AUTOBINDING=yes
Index: pace/srv/net/cfg/module/lo
===================================================================
--- uspace/srv/net/cfg/module/lo	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,13 +1,0 @@
-# loopback configuration
-
-NAME=lo
-
-NETIF=lo
-NIL=lo
-IL=ip
-
-IP_CONFIG=static
-IP_ADDR=127.0.0.1
-IP_NETMASK=255.0.0.0
-
-MTU=15535
Index: pace/srv/net/cfg/module/ne2k
===================================================================
--- uspace/srv/net/cfg/module/ne2k	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,25 +1,0 @@
-# DP8390 (NE2k) configuration
-
-NAME=ne2k
-
-NETIF=dp8390
-NIL=dp8390
-IL=ip
-
-# sysinfo_value("netif.dp8390.inr")
-IRQ=9
-IO=300
-
-# 8023_2_LSAP, 8023_2_SNAP
-ETH_MODE=DIX
-ETH_DUMMY=no
-
-IP_CONFIG=static
-IP_ADDR=10.0.2.15
-IP_ROUTING=yes
-IP_NETMASK=255.255.255.240
-IP_BROADCAST=10.0.2.255
-IP_GATEWAY=10.0.2.2
-ARP=arp
-
-MTU=1492
Index: uspace/srv/net/cfg/ne2k.netif_nil_bundle
===================================================================
--- uspace/srv/net/cfg/ne2k.netif_nil_bundle	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/net/cfg/ne2k.netif_nil_bundle	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,24 @@
+# DP8390 (NE2k) configuration
+
+NAME=ne2k
+
+NETIF=dp8390
+NIL=dp8390
+IL=ip
+
+IRQ=9
+IO=300
+
+# 8023_2_LSAP, 8023_2_SNAP
+ETH_MODE=DIX
+ETH_DUMMY=no
+
+IP_CONFIG=static
+IP_ADDR=10.0.2.15
+IP_ROUTING=yes
+IP_NETMASK=255.255.255.240
+IP_BROADCAST=10.0.2.255
+IP_GATEWAY=10.0.2.2
+ARP=arp
+
+MTU=1492
Index: uspace/srv/net/cfg/ne2k.netif_standalone
===================================================================
--- uspace/srv/net/cfg/ne2k.netif_standalone	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/net/cfg/ne2k.netif_standalone	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,24 @@
+# DP8390 (NE2k) configuration
+
+NAME=ne2k
+
+NETIF=dp8390
+NIL=eth
+IL=ip
+
+IRQ=9
+IO=300
+
+# 8023_2_LSAP, 8023_2_SNAP
+ETH_MODE=DIX
+ETH_DUMMY=no
+
+IP_CONFIG=static
+IP_ADDR=10.0.2.15
+IP_ROUTING=yes
+IP_NETMASK=255.255.255.240
+IP_BROADCAST=10.0.2.255
+IP_GATEWAY=10.0.2.2
+ARP=arp
+
+MTU=1492
Index: pace/srv/net/checksum.c
===================================================================
--- uspace/srv/net/checksum.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,171 +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 net
- *  @{
- */
-
-/** @file
- *  General CRC and checksum computation implementation.
- */
-
-#include <sys/types.h>
-
-#include "include/checksum.h"
-
-/** Big-endian encoding CRC divider.
- */
-#define CRC_DIVIDER_BE	0x04C11DB7
-
-/** Little-endian encoding CRC divider.
- */
-#define CRC_DIVIDER_LE	0xEDB88320
-
-uint16_t compact_checksum(uint32_t sum){
-	// shorten to the 16 bits
-	while(sum >> 16){
-		sum = (sum &0xFFFF) + (sum >> 16);
-	}
-
-	return (uint16_t) sum;
-}
-
-uint32_t compute_checksum(uint32_t seed, uint8_t * data, size_t length){
-	size_t index;
-
-	// sum all the 16 bit fields
-	for(index = 0; index + 1 < length; index += 2){
-		seed += (data[index] << 8) + data[index + 1];
-	}
-
-	// last odd byte with zero padding
-	if(index + 1 == length){
-		seed += data[index] << 8;
-	}
-
-	return seed;
-}
-
-uint32_t compute_crc32_be(uint32_t seed, uint8_t * data, size_t length){
-	size_t index;
-
-	// process full bytes
-	while(length >= 8){
-		// add the data
-		seed ^= (*data) << 24;
-		// for each added bit
-		for(index = 0; index < 8; ++ index){
-			// if the first bit is set
-			if(seed &0x80000000){
-				// shift and divide the checksum
-				seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE);
-			}else{
-				// shift otherwise
-				seed <<= 1;
-			}
-		}
-		// move to the next byte
-		++ data;
-		length -= 8;
-	}
-
-	// process the odd bits
-	if(length > 0){
-		// add the data with zero padding
-		seed ^= ((*data) &(0xFF << (8 - length))) << 24;
-		// for each added bit
-		for(index = 0; index < length; ++ index){
-			// if the first bit is set
-			if(seed &0x80000000){
-				// shift and divide the checksum
-				seed = (seed << 1) ^ ((uint32_t) CRC_DIVIDER_BE);
-			}else{
-				// shift otherwise
-				seed <<= 1;
-			}
-		}
-	}
-
-	return seed;
-}
-
-uint32_t compute_crc32_le(uint32_t seed, uint8_t * data, size_t length){
-	size_t index;
-
-	// process full bytes
-	while(length >= 8){
-		// add the data
-		seed ^= (*data);
-		// for each added bit
-		for(index = 0; index < 8; ++ index){
-			// if the last bit is set
-			if(seed &1){
-				// shift and divide the checksum
-				seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE);
-			}else{
-				// shift otherwise
-				seed >>= 1;
-			}
-		}
-		// move to the next byte
-		++ data;
-		length -= 8;
-	}
-
-	// process the odd bits
-	if(length > 0){
-		// add the data with zero padding
-		seed ^= (*data) >> (8 - length);
-		for(index = 0; index < length; ++ index){
-			// if the last bit is set
-			if(seed &1){
-				// shift and divide the checksum
-				seed = (seed >> 1) ^ ((uint32_t) CRC_DIVIDER_LE);
-			}else{
-				// shift otherwise
-				seed >>= 1;
-			}
-		}
-	}
-
-	return seed;
-}
-
-uint16_t flip_checksum(uint16_t checksum){
-	// flip, zero is returned as 0xFFFF (not flipped)
-	checksum = ~ checksum;
-	return checksum ? checksum : IP_CHECKSUM_ZERO;
-}
-
-uint16_t ip_checksum(uint8_t * data, size_t length){
-	// compute, compact and flip the data checksum
-	return flip_checksum(compact_checksum(compute_checksum(0, data, length)));
-}
-
-/** @}
- */
Index: pace/srv/net/configuration.h
===================================================================
--- uspace/srv/net/configuration.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,95 +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 net
- *  @{
- */
-
-/** @file
- *  Networking subsystem compilation configuration.
- */
-
-#ifndef __NET_CONFIGURATION_H__
-#define __NET_CONFIGURATION_H__
-
-/** Activates the self test.
- */
-#define NET_SELF_TEST					0
-
-/** @name Specific self tests switches
- */
-/*@{*/
-
-/** Activates the char map self test.
- *  The NET_SELF_TEST has to be activated.
- *  @see char_map.h
- */
-#define NET_SELF_TEST_CHAR_MAP			1
-
-/** Activates the CRC computation self test.
- *  The NET_SELF_TEST has to be activated.
- *  @see crc.h
- */
-#define NET_SELF_TEST_CRC				1
-
-/** Activates the dynamic fifo self test.
- *  The NET_SELF_TEST has to be activated.
- *  @see dynamic_fifo.h
- */
-#define NET_SELF_TEST_DYNAMIC_FIFO		1
-
-/** Activates the generic char map self test.
- *  The NET_SELF_TEST has to be activated.
- *  @see generic_char_map.h
- */
-#define NET_SELF_TEST_GENERIC_CHAR_MAP	1
-
-/** Activates the generic field self test.
- *  The NET_SELF_TEST has to be activated.
- *  @see generic_field.h
- */
-#define NET_SELF_TEST_GENERIC_FIELD		1
-
-/** Activates the integral map self test.
- *  The NET_SELF_TEST has to be activated.
- *  @see int_map.h
- */
-#define NET_SELF_TEST_INT_MAP			1
-
-/** Activates the measured strings self test.
- *  The NET_SELF_TEST has to be activated.
- *  @see measured_strings.h
- */
-#define NET_SELF_TEST_MEASURED_STRINGS	1
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/err.h
===================================================================
--- uspace/srv/net/err.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,83 +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 net
- *  @{
- */
-
-/** @file
- *  Common error processing codes and routines.
- */
-
-#ifndef __NET_ERR_H__
-#define __NET_ERR_H__
-
-#include <errno.h>
-
-#ifdef CONFIG_DEBUG
-
-#include <stdio.h>
-
-#endif
-
-/** An actual stored error code.
- */
-#define ERROR_CODE					error_check_return_value
-
-/** An error processing routines declaration.
- *  This has to be declared in the block where the error processing is desired.
- */
-#define ERROR_DECLARE				int ERROR_CODE
-
-/** Stores the value as an error code and checks if an error occurred.
- *  @param[in] value The value to be checked. May be a function call.
- *  @returns FALSE if the value indicates success (EOK).
- *  @returns TRUE otherwise.
- */
-#ifdef CONFIG_DEBUG
-
-#define ERROR_OCCURRED(value)												\
-	(((ERROR_CODE = (value)) != EOK)										\
-	&& ({printf("error at %s:%d %d\n", __FILE__, __LINE__, ERROR_CODE); 1;}))
-
-#else
-
-#define ERROR_OCCURRED(value)		((ERROR_CODE = (value)) != EOK)
-
-#endif
-
-/** Checks if an error occurred and immediately exits the actual function returning the error code.
- *  @param[in] value The value to be checked. May be a function call.
- */
-
-#define ERROR_PROPAGATE(value)	if(ERROR_OCCURRED(value)) return ERROR_CODE
-
-#endif
-
-/** @}
- */
Index: uspace/srv/net/il/arp/Makefile
===================================================================
--- uspace/srv/net/il/arp/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/il/arp/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,20 +28,12 @@
 #
 
-NET_BASE = ../..
 USPACE_PREFIX = ../../../..
+LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBSOCKET_PREFIX)/include
 BINARY = arp
 
 SOURCES = \
 	arp.c \
-	arp_module.c \
-	$(NET_BASE)/module.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/net/net_remote.c \
-	$(NET_BASE)/nil/nil_remote.c \
-	$(NET_BASE)/structures/char_map.c \
-	$(NET_BASE)/structures/measured_strings.c \
-	$(NET_BASE)/structures/packet/packet.c \
-	$(NET_BASE)/structures/packet/packet_client.c \
-	$(NET_BASE)/structures/packet/packet_remote.c
+	arp_module.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/il/arp/arp.c
===================================================================
--- uspace/srv/net/il/arp/arp.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/il/arp/arp.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -43,23 +43,23 @@
 #include <str.h>
 #include <task.h>
-
 #include <ipc/ipc.h>
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../messages.h"
-#include "../../modules.h"
-
-#include "../../include/byteorder.h"
-#include "../../include/device.h"
-#include "../../include/arp_interface.h"
-#include "../../include/nil_interface.h"
-#include "../../include/protocol_map.h"
-
-#include "../../structures/measured_strings.h"
-#include "../../structures/packet/packet.h"
-#include "../../structures/packet/packet_client.h"
-
-#include "../il_messages.h"
+#include <net_err.h>
+#include <net_messages.h>
+#include <net_modules.h>
+#include <net_byteorder.h>
+#include <net_device.h>
+#include <arp_interface.h>
+#include <nil_interface.h>
+#include <protocol_map.h>
+#include <adt/measured_strings.h>
+#include <packet/packet.h>
+#include <packet/packet_client.h>
+#include <packet_remote.h>
+#include <il_messages.h>
+#include <il_interface.h>
+#include <il_local.h>
+#include <arp_messages.h>
 
 #include "arp.h"
@@ -67,5 +67,9 @@
 #include "arp_oc.h"
 #include "arp_module.h"
-#include "arp_messages.h"
+
+
+/** ARP module name.
+ */
+#define NAME  "arp"
 
 /** ARP global data.
@@ -337,5 +341,6 @@
 			return ERROR_CODE;
 		}
-		printf("New device registered:\n\tid\t= %d\n\ttype\t= 0x%x\n\tservice\t= %d\n\tproto\t= %d\n", device->device_id, device->hardware, device->service, protocol);
+		printf("%s: Device registered (id: %d, type: 0x%x, service: %d, proto: %d)\n",
+		    NAME, device->device_id, device->hardware, device->service, protocol);
 	}
 	fibril_rwlock_write_unlock(&arp_globals.lock);
@@ -368,7 +373,9 @@
 }
 
-int arp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+int arp_message_standalone(ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, int *answer_count)
+{
 	ERROR_DECLARE;
-
+	
 	measured_string_ref address;
 	measured_string_ref translation;
@@ -376,8 +383,7 @@
 	packet_t packet;
 	packet_t next;
-
-//	printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_ARP_FIRST);
+	
 	*answer_count = 0;
-	switch(IPC_GET_METHOD(*call)){
+	switch (IPC_GET_METHOD(*call)) {
 		case IPC_M_PHONE_HUNGUP:
 			return EOK;
@@ -416,5 +422,5 @@
 			return EOK;
 		case NET_IL_RECEIVED:
-			if(! ERROR_OCCURRED(packet_translate(arp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
+			if(! ERROR_OCCURRED(packet_translate_remote(arp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
 				fibril_rwlock_read_lock(&arp_globals.lock);
 				do{
@@ -422,5 +428,5 @@
 					ERROR_CODE = arp_receive_message(IPC_GET_DEVICE(call), packet);
 					if(ERROR_CODE != 1){
-						pq_release(arp_globals.net_phone, packet_get_id(packet));
+						pq_release_remote(arp_globals.net_phone, packet_get_id(packet));
 					}
 					packet = next;
@@ -432,4 +438,5 @@
 			return arp_mtu_changed_message(IPC_GET_DEVICE(call), IPC_GET_MTU(call));
 	}
+	
 	return ENOTSUP;
 }
@@ -568,5 +575,5 @@
 		return NULL;
 	}
-	packet = packet_get_4(arp_globals.net_phone, device->packet_dimension.addr_len, device->packet_dimension.prefix, length, device->packet_dimension.suffix);
+	packet = packet_get_4_remote(arp_globals.net_phone, device->packet_dimension.addr_len, device->packet_dimension.prefix, length, device->packet_dimension.suffix);
 	if(! packet){
 		return NULL;
@@ -574,5 +581,5 @@
 	header = (arp_header_ref) packet_suffix(packet, length);
 	if(! header){
-		pq_release(arp_globals.net_phone, packet_get_id(packet));
+		pq_release_remote(arp_globals.net_phone, packet_get_id(packet));
 		return NULL;
 	}
@@ -591,5 +598,5 @@
 	memcpy(((uint8_t *) header) + length, target->value, target->length);
 	if(packet_set_addr(packet, (uint8_t *) device->addr->value, (uint8_t *) device->broadcast_addr->value, CONVERT_SIZE(char, uint8_t, device->addr->length)) != EOK){
-		pq_release(arp_globals.net_phone, packet_get_id(packet));
+		pq_release_remote(arp_globals.net_phone, packet_get_id(packet));
 		return NULL;
 	}
@@ -618,4 +625,62 @@
 }
 
+/** Default thread for new connections.
+ *
+ *  @param[in] iid The initial message identifier.
+ *  @param[in] icall The initial message call structure.
+ *
+ */
+static void il_client_connection(ipc_callid_t iid, ipc_call_t * icall)
+{
+	/*
+	 * Accept the connection
+	 *  - Answer the first IPC_M_CONNECT_ME_TO call.
+	 */
+	ipc_answer_0(iid, EOK);
+	
+	while(true) {
+		ipc_call_t answer;
+		int answer_count;
+		
+		/* Clear the answer structure */
+		refresh_answer(&answer, &answer_count);
+		
+		/* Fetch the next message */
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		/* Process the message */
+		int res = il_module_message_standalone(callid, &call, &answer,
+		    &answer_count);
+		
+		/* End if said to either by the message or the processing result */
+		if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
+			return;
+		
+		/* Answer the message */
+		answer_call(callid, res, &answer, answer_count);
+	}
+}
+
+/** Starts the module.
+ *
+ *  @param argc The count of the command line arguments. Ignored parameter.
+ *  @param argv The command line parameters. Ignored parameter.
+ *
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for each specific module start function.
+ *
+ */
+int main(int argc, char *argv[])
+{
+	ERROR_DECLARE;
+	
+	/* Start the module */
+	if (ERROR_OCCURRED(il_module_start_standalone(il_client_connection)))
+		return ERROR_CODE;
+	
+	return EOK;
+}
+
 /** @}
  */
Index: uspace/srv/net/il/arp/arp.h
===================================================================
--- uspace/srv/net/il/arp/arp.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/il/arp/arp.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -43,10 +43,9 @@
 #include <ipc/services.h>
 
-#include "../../include/device.h"
-#include "../../include/hardware.h"
-
-#include "../../structures/generic_char_map.h"
-#include "../../structures/int_map.h"
-#include "../../structures/measured_strings.h"
+#include <net_device.h>
+#include <net_hardware.h>
+#include <adt/generic_char_map.h>
+#include <adt/int_map.h>
+#include <adt/measured_strings.h>
 
 
Index: pace/srv/net/il/arp/arp_messages.h
===================================================================
--- uspace/srv/net/il/arp/arp_messages.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,84 +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 arp
- *  @{
- */
-
-/** @file
- *  ARP module messages.
- *  @see arp_interface.h
- */
-
-#ifndef __NET_ARP_MESSAGES__
-#define __NET_ARP_MESSAGES__
-
-#include <ipc/ipc.h>
-
-#include "../../messages.h"
-
-/** ARP module messages.
- */
-typedef enum{
-	/** Clean cache message.
-	 *  @see arp_clean_cache()
-	 */
-	NET_ARP_CLEAN_CACHE = NET_ARP_FIRST,
-	/** Clear address cache message.
-	 *  @see arp_clear_address_msg()
-	 */
-	NET_ARP_CLEAR_ADDRESS,
-	/** Clear device cache message.
-	 *  @see arp_clear_device_req()
-	 */
-	NET_ARP_CLEAR_DEVICE,
-	/** New device message.
-	 *  @see arp_device_req()
-	 */
-	NET_ARP_DEVICE,
-	/** Address translation message.
-	 *  @see arp_translate_req()
-	 */
-	NET_ARP_TRANSLATE
-} arp_messages;
-
-/** @name ARP specific message parameters definitions
- */
-/*@{*/
-
-/** Returns the protocol service message parameter.
- *  @param[in] call The message call structure.
- */
-#define ARP_GET_NETIF(call)		(services_t) IPC_GET_ARG2(*call)
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: uspace/srv/net/il/arp/arp_module.c
===================================================================
--- uspace/srv/net/il/arp/arp_module.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/il/arp/arp_module.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -44,17 +44,12 @@
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../modules.h"
-
-#include "../../include/net_interface.h"
-
-#include "../../structures/packet/packet.h"
+#include <net_err.h>
+#include <net_modules.h>
+#include <net_interface.h>
+#include <packet/packet.h>
+#include <il_local.h>
 
 #include "arp.h"
 #include "arp_module.h"
-
-/** ARP module name.
- */
-#define NAME	"ARP protocol"
 
 /** ARP module global data.
@@ -70,10 +65,7 @@
  *  @returns Other error codes as defined for the arp_message() function.
  */
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-/** Prints the module name.
- *  @see NAME
- */
-void module_print_name(void);
+int il_module_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+	return arp_message_standalone(callid, call, answer, answer_count);
+}
 
 /** Starts the ARP module.
@@ -84,30 +76,20 @@
  *  @returns Other error codes as defined for the REGISTER_ME() macro function.
  */
-int module_start(async_client_conn_t client_connection);
-
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	return arp_message(callid, call, answer, answer_count);
-}
-
-void module_print_name(void){
-	printf("%s", NAME);
-}
-
-int module_start(async_client_conn_t client_connection){
+int il_module_start_standalone(async_client_conn_t client_connection){
 	ERROR_DECLARE;
-
-	ipcarg_t phonehash;
-
+	
 	async_set_client_connection(client_connection);
 	arp_globals.net_phone = net_connect_module(SERVICE_NETWORKING);
 	ERROR_PROPAGATE(pm_init());
-	if(ERROR_OCCURRED(arp_initialize(client_connection))
-		|| ERROR_OCCURRED(REGISTER_ME(SERVICE_ARP, &phonehash))){
+	
+	ipcarg_t phonehash;
+	if (ERROR_OCCURRED(arp_initialize(client_connection))
+	    || ERROR_OCCURRED(REGISTER_ME(SERVICE_ARP, &phonehash))) {
 		pm_destroy();
 		return ERROR_CODE;
 	}
-
+	
 	async_manager();
-
+	
 	pm_destroy();
 	return EOK;
Index: uspace/srv/net/il/arp/arp_module.h
===================================================================
--- uspace/srv/net/il/arp/arp_module.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/il/arp/arp_module.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -58,5 +58,5 @@
  *  @see IS_NET_ARP_MESSAGE()
  */
-int arp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
+int arp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
 
 #endif
Index: pace/srv/net/il/arp/arp_remote.c
===================================================================
--- uspace/srv/net/il/arp/arp_remote.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,98 +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 arp
- *  @{
- */
-
-/** @file
- *  ARP interface implementation for standalone remote modules.
- *  @see arp_interface.h
- */
-
-#include <async.h>
-#include <errno.h>
-
-#include <ipc/ipc.h>
-#include <ipc/services.h>
-
-#include "../../messages.h"
-#include "../../modules.h"
-
-#include "../../include/device.h"
-#include "../../include/arp_interface.h"
-
-#include "../../structures/measured_strings.h"
-
-#include "arp_messages.h"
-
-int arp_connect_module(services_t service){
-	if(service != SERVICE_ARP){
-		return EINVAL;
-	}
-	return connect_to_service(SERVICE_ARP);
-}
-
-int arp_clean_cache_req(int arp_phone){
-	return (int) async_req_0_0(arp_phone, NET_ARP_CLEAN_CACHE);
-}
-
-int arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address){
-	aid_t message_id;
-	ipcarg_t result;
-
-	message_id = async_send_2(arp_phone, NET_ARP_CLEAR_ADDRESS, (ipcarg_t) device_id, protocol, NULL);
-	measured_strings_send(arp_phone, address, 1);
-	async_wait_for(message_id, &result);
-	return (int) result;
-}
-
-int arp_clear_device_req(int arp_phone, device_id_t device_id){
-	return (int) async_req_1_0(arp_phone, NET_ARP_CLEAR_DEVICE, (ipcarg_t) device_id);
-}
-
-int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address){
-	aid_t message_id;
-	ipcarg_t result;
-
-	message_id = async_send_3(arp_phone, NET_ARP_DEVICE, (ipcarg_t) device_id, protocol, netif, NULL);
-	measured_strings_send(arp_phone, address, 1);
-	async_wait_for(message_id, &result);
-	return (int) result;
-}
-
-task_id_t arp_task_get_id(void){
-	return 0;
-}
-
-int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data){
-	return generic_translate_req(arp_phone, NET_ARP_TRANSLATE, device_id, protocol, address, 1, translation, data);
-}
-
-/** @}
- */
Index: pace/srv/net/il/il_messages.h
===================================================================
--- uspace/srv/net/il/il_messages.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,92 +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 net_il
- *  @{
- */
-
-/** @file
- *  Internetwork layer modules messages.
- *  @see il_interface.h
- *  @see ip_interface.h
- */
-
-#ifndef __NET_IL_MESSAGES_H__
-#define __NET_IL_MESSAGES_H__
-
-#include <ipc/ipc.h>
-
-/** Internet layer modules messages.
- */
-typedef enum{
-	/** New device message.
-	 *  @see ip_device_req()
-	 */
-	NET_IL_DEVICE = NET_IL_FIRST,
-	/** Device state changed message.
-	 *  @see il_device_state_msg()
-	 */
-	NET_IL_DEVICE_STATE,
-	/** Device MTU changed message.
-	 *  @see il_mtu_changed_msg()
-	 */
-	NET_IL_MTU_CHANGED,
-	/** Packet size message.
-	 *  @see il_packet_size_req()
-	 */
-	NET_IL_PACKET_SPACE,
-	/** Packet received message.
-	 *  @see il_received_msg()
-	 */
-	NET_IL_RECEIVED,
-	/** Packet send message.
-	 *  @see il_send_msg()
-	 */
-	NET_IL_SEND
-} il_messages;
-
-/** @name Internetwork layer specific message parameters definitions
- */
-/*@{*/
-
-/** Returns the protocol number message parameter.
- *  @param[in] call The message call structure.
- */
-#define IL_GET_PROTO(call)		(int) IPC_GET_ARG1(*call)
-
-/** Returns the registering service message parameter.
- *  @param[in] call The message call structure.
- */
-#define IL_GET_SERVICE(call)	(services_t) IPC_GET_ARG2(*call)
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: uspace/srv/net/il/ip/Makefile
===================================================================
--- uspace/srv/net/il/ip/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/il/ip/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,28 +28,12 @@
 #
 
-NET_BASE = ../..
 USPACE_PREFIX = ../../../..
+LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBSOCKET_PREFIX)/include
 BINARY = ip
 
 SOURCES = \
 	ip.c \
-	ip_client.c \
-	ip_module.c \
-	$(NET_BASE)/checksum.c \
-	$(NET_BASE)/inet.c \
-	$(NET_BASE)/module.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/il/arp/arp_remote.c \
-	$(NET_BASE)/nil/nil_remote.c \
-	$(NET_BASE)/net/net_remote.c \
-	$(NET_BASE)/tl/icmp/icmp_client.c \
-	$(NET_BASE)/tl/icmp/icmp_common.c \
-	$(NET_BASE)/tl/icmp/icmp_remote.c \
-	$(NET_BASE)/structures/char_map.c \
-	$(NET_BASE)/structures/measured_strings.c \
-	$(NET_BASE)/structures/module_map.c \
-	$(NET_BASE)/structures/packet/packet.c \
-	$(NET_BASE)/structures/packet/packet_client.c \
-	$(NET_BASE)/structures/packet/packet_remote.c
+	ip_module.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/il/ip/ip.c
===================================================================
--- uspace/srv/net/il/ip/ip.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/il/ip/ip.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -41,39 +41,37 @@
 #include <stdio.h>
 #include <str.h>
-
 #include <ipc/ipc.h>
 #include <ipc/services.h>
-
 #include <sys/types.h>
 
-#include "../../err.h"
-#include "../../messages.h"
-#include "../../modules.h"
-
-#include "../../include/arp_interface.h"
-#include "../../include/byteorder.h"
-#include "../../include/checksum.h"
-#include "../../include/device.h"
-#include "../../include/icmp_client.h"
-#include "../../include/icmp_codes.h"
-#include "../../include/icmp_interface.h"
-#include "../../include/il_interface.h"
-#include "../../include/in.h"
-#include "../../include/in6.h"
-#include "../../include/inet.h"
-#include "../../include/ip_client.h"
-#include "../../include/ip_interface.h"
-#include "../../include/net_interface.h"
-#include "../../include/nil_interface.h"
-#include "../../include/tl_interface.h"
-#include "../../include/socket_codes.h"
-#include "../../include/socket_errno.h"
-#include "../../structures/measured_strings.h"
-#include "../../structures/module_map.h"
-#include "../../structures/packet/packet_client.h"
-
-#include "../../nil/nil_messages.h"
-
-#include "../il_messages.h"
+#include <net_err.h>
+#include <net_messages.h>
+#include <net_modules.h>
+#include <arp_interface.h>
+#include <net_byteorder.h>
+#include <net_checksum.h>
+#include <net_device.h>
+#include <icmp_client.h>
+#include <icmp_codes.h>
+#include <icmp_interface.h>
+#include <il_interface.h>
+#include <in.h>
+#include <in6.h>
+#include <inet.h>
+#include <ip_client.h>
+#include <ip_interface.h>
+#include <net_interface.h>
+#include <nil_interface.h>
+#include <tl_interface.h>
+#include <socket_codes.h>
+#include <socket_errno.h>
+#include <adt/measured_strings.h>
+#include <adt/module_map.h>
+#include <packet/packet_client.h>
+#include <packet_remote.h>
+#include <nil_messages.h>
+#include <il_messages.h>
+#include <il_local.h>
+#include <ip_local.h>
 
 #include "ip.h"
@@ -81,4 +79,8 @@
 #include "ip_messages.h"
 #include "ip_module.h"
+
+/** IP module name.
+ */
+#define NAME  "ip"
 
 /** IP version 4.
@@ -425,5 +427,5 @@
 }
 
-int ip_device_req(int il_phone, device_id_t device_id, services_t netif){
+int ip_device_req_local(int il_phone, device_id_t device_id, services_t netif){
 	ERROR_DECLARE;
 
@@ -431,5 +433,4 @@
 	ip_route_ref route;
 	int index;
-	char * data;
 
 	ip_netif = (ip_netif_ref) malloc(sizeof(ip_netif_t));
@@ -455,25 +456,28 @@
 	}
 	// print the settings
-	printf("New device registered:\n\tid\t= %d\n\tphone\t= %d\n\tIPV\t= %d\n", ip_netif->device_id, ip_netif->phone, ip_netif->ipv);
-	printf("\tconfiguration\t= %s\n", ip_netif->dhcp ? "dhcp" : "static");
+	printf("%s: Device registered (id: %d, phone: %d, ipv: %d, conf: %s)\n",
+	    NAME, ip_netif->device_id, ip_netif->phone, ip_netif->ipv,
+	    ip_netif->dhcp ? "dhcp" : "static");
+	
 	// TODO ipv6 addresses
-	data = (char *) malloc(INET_ADDRSTRLEN);
-	if(data){
-		for(index = 0; index < ip_routes_count(&ip_netif->routes); ++ index){
-			route = ip_routes_get_index(&ip_netif->routes, index);
-			if(route){
-				printf("\tRouting %d:\n", index);
-				inet_ntop(AF_INET, (uint8_t *) &route->address.s_addr, data, INET_ADDRSTRLEN);
-				printf("\t\taddress\t= %s\n", data);
-				inet_ntop(AF_INET, (uint8_t *) &route->netmask.s_addr, data, INET_ADDRSTRLEN);
-				printf("\t\tnetmask\t= %s\n", data);
-				inet_ntop(AF_INET, (uint8_t *) &route->gateway.s_addr, data, INET_ADDRSTRLEN);
-				printf("\t\tgateway\t= %s\n", data);
-			}
-		}
-		inet_ntop(AF_INET, (uint8_t *) &ip_netif->broadcast.s_addr, data, INET_ADDRSTRLEN);
-		printf("\t\tbroadcast\t= %s\n", data);
-		free(data);
-	}
+	
+	char address[INET_ADDRSTRLEN];
+	char netmask[INET_ADDRSTRLEN];
+	char gateway[INET_ADDRSTRLEN];
+	
+	for (index = 0; index < ip_routes_count(&ip_netif->routes); ++ index){
+		route = ip_routes_get_index(&ip_netif->routes, index);
+		if (route) {
+			inet_ntop(AF_INET, (uint8_t *) &route->address.s_addr, address, INET_ADDRSTRLEN);
+			inet_ntop(AF_INET, (uint8_t *) &route->netmask.s_addr, netmask, INET_ADDRSTRLEN);
+			inet_ntop(AF_INET, (uint8_t *) &route->gateway.s_addr, gateway, INET_ADDRSTRLEN);
+			printf("%s: Route %d (address: %s, netmask: %s, gateway: %s)\n",
+			    NAME, index, address, netmask, gateway);
+		}
+	}
+	
+	inet_ntop(AF_INET, (uint8_t *) &ip_netif->broadcast.s_addr, address, INET_ADDRSTRLEN);
+	printf("%s: Broadcast (%s)\n", NAME, address);
+	
 	fibril_rwlock_write_unlock(&ip_globals.netifs_lock);
 	return EOK;
@@ -596,5 +600,5 @@
 	}
 	netif->packet_dimension.content = mtu;
-	printf("ip - device %d changed mtu to %d\n\n", device_id, mtu);
+	printf("%s: Device %d changed MTU to %d\n", NAME, device_id, mtu);
 	fibril_rwlock_write_unlock(&ip_globals.netifs_lock);
 	return EOK;
@@ -612,5 +616,5 @@
 	}
 	netif->state = state;
-	printf("ip - device %d changed state to %d\n\n", device_id, state);
+	printf("%s: Device %d changed state to %d\n", NAME, device_id, state);
 	fibril_rwlock_write_unlock(&ip_globals.netifs_lock);
 	return EOK;
@@ -647,10 +651,13 @@
 		return index;
 	}
-	printf("New protocol registered:\n\tprotocol\t= %d\n\tphone\t= %d\n", proto->protocol, proto->phone);
+	
+	printf("%s: Protocol registered (protocol: %d, phone: %d)\n",
+	    NAME, proto->protocol, proto->phone);
+	
 	fibril_rwlock_write_unlock(&ip_globals.protos_lock);
 	return EOK;
 }
 
-int ip_send_msg(int il_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){
+int ip_send_msg_local(int il_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){
 	ERROR_DECLARE;
 
@@ -778,5 +785,5 @@
 //			sleep(1);
 //			ERROR_PROPAGATE(arp_translate_req(netif->arp->phone, netif->device_id, SERVICE_IP, &destination, &translation, &data));
-			pq_release(ip_globals.net_phone, packet_get_id(packet));
+			pq_release_remote(ip_globals.net_phone, packet_get_id(packet));
 			return ERROR_CODE;
 		}
@@ -795,5 +802,5 @@
 	}else translation = NULL;
 	if(ERROR_OCCURRED(ip_prepare_packet(src, dest, packet, translation))){
-		pq_release(ip_globals.net_phone, packet_get_id(packet));
+		pq_release_remote(ip_globals.net_phone, packet_get_id(packet));
 	}else{
 		packet = ip_split_packet(packet, netif->packet_dimension.prefix, netif->packet_dimension.content, netif->packet_dimension.suffix, netif->packet_dimension.addr_len, error);
@@ -887,64 +894,92 @@
 }
 
-int ip_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+int ip_message_standalone(ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, int * answer_count)
+{
 	ERROR_DECLARE;
-
+	
 	packet_t packet;
-	struct sockaddr * addr;
+	struct sockaddr *addr;
 	size_t addrlen;
-	ip_pseudo_header_ref header;
+	size_t prefix;
+	size_t suffix;
+	size_t content;
+	void *header;
 	size_t headerlen;
 	device_id_t device_id;
-
+	
 	*answer_count = 0;
-	switch(IPC_GET_METHOD(*call)){
+	switch (IPC_GET_METHOD(*call)) {
 		case IPC_M_PHONE_HUNGUP:
 			return EOK;
 		case NET_IL_DEVICE:
-			return ip_device_req(0, IPC_GET_DEVICE(call), IPC_GET_SERVICE(call));
+			return ip_device_req_local(0, IPC_GET_DEVICE(call),
+			    IPC_GET_SERVICE(call));
 		case IPC_M_CONNECT_TO_ME:
-			return ip_register(IL_GET_PROTO(call), IL_GET_SERVICE(call), IPC_GET_PHONE(call), NULL);
+			return ip_register(IL_GET_PROTO(call), IL_GET_SERVICE(call),
+			    IPC_GET_PHONE(call), NULL);
 		case NET_IL_SEND:
-			ERROR_PROPAGATE(packet_translate(ip_globals.net_phone, &packet, IPC_GET_PACKET(call)));
-			return ip_send_msg(0, IPC_GET_DEVICE(call), packet, 0, IPC_GET_ERROR(call));
+			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));
 		case NET_IL_DEVICE_STATE:
-			return ip_device_state_message(IPC_GET_DEVICE(call), IPC_GET_STATE(call));
+			return ip_device_state_message(IPC_GET_DEVICE(call),
+			    IPC_GET_STATE(call));
 		case NET_IL_RECEIVED:
-			ERROR_PROPAGATE(packet_translate(ip_globals.net_phone, &packet, IPC_GET_PACKET(call)));
+			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:
-			ERROR_PROPAGATE(packet_translate(ip_globals.net_phone, &packet, IPC_GET_PACKET(call)));
-			return ip_received_error_msg(0, IPC_GET_DEVICE(call), packet, IPC_GET_TARGET(call), IPC_GET_ERROR(call));
+			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));
 		case NET_IP_ADD_ROUTE:
-			return ip_add_route_req(0, IPC_GET_DEVICE(call), IP_GET_ADDRESS(call), IP_GET_NETMASK(call), IP_GET_GATEWAY(call));
+			return ip_add_route_req_local(0, IPC_GET_DEVICE(call),
+			    IP_GET_ADDRESS(call), IP_GET_NETMASK(call), IP_GET_GATEWAY(call));
 		case NET_IP_SET_GATEWAY:
-			return ip_set_gateway_req(0, IPC_GET_DEVICE(call), IP_GET_GATEWAY(call));
+			return ip_set_gateway_req_local(0, IPC_GET_DEVICE(call),
+			    IP_GET_GATEWAY(call));
 		case NET_IP_GET_ROUTE:
 			ERROR_PROPAGATE(data_receive((void **) &addr, &addrlen));
-			ERROR_PROPAGATE(ip_get_route_req(0, IP_GET_PROTOCOL(call), addr, (socklen_t) addrlen,
-			    &device_id, &header, &headerlen));
-			*IPC_SET_DEVICE(answer) = device_id;
-			*IP_SET_HEADERLEN(answer) = headerlen;
+			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;
-			if(! ERROR_OCCURRED(data_reply(&headerlen, sizeof(headerlen)))){
+			
+			if (!ERROR_OCCURRED(data_reply(&headerlen, sizeof(headerlen))))
 				ERROR_CODE = data_reply(header, headerlen);
-			}
+			
 			free(header);
 			return ERROR_CODE;
 		case NET_IL_PACKET_SPACE:
-			ERROR_PROPAGATE(ip_packet_size_message(IPC_GET_DEVICE(call), IPC_SET_ADDR(answer), IPC_SET_PREFIX(answer), IPC_SET_CONTENT(answer), IPC_SET_SUFFIX(answer)));
-			*answer_count = 3;
+			ERROR_PROPAGATE(ip_packet_size_message(IPC_GET_DEVICE(call),
+			    &addrlen, &prefix, &content, &suffix));
+			IPC_SET_ADDR(answer, addrlen);
+			IPC_SET_PREFIX(answer, prefix);
+			IPC_SET_CONTENT(answer, content);
+			IPC_SET_SUFFIX(answer, suffix);
+			*answer_count = 4;
 			return EOK;
 		case NET_IL_MTU_CHANGED:
-			return ip_mtu_changed_message(IPC_GET_DEVICE(call), IPC_GET_MTU(call));
-	}
+			return ip_mtu_changed_message(IPC_GET_DEVICE(call),
+			    IPC_GET_MTU(call));
+	}
+	
 	return ENOTSUP;
 }
 
-int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension){
-	if(! packet_dimension){
+int ip_packet_size_req_local(int ip_phone, device_id_t device_id,
+    packet_dimension_ref packet_dimension)
+{
+	if (!packet_dimension)
 		return EBADMEM;
-	}
-	return ip_packet_size_message(device_id, &packet_dimension->addr_len, &packet_dimension->prefix, &packet_dimension->content, &packet_dimension->suffix);
+	
+	return ip_packet_size_message(device_id, &packet_dimension->addr_len,
+	    &packet_dimension->prefix, &packet_dimension->content,
+	    &packet_dimension->suffix);
 }
 
@@ -992,5 +1027,5 @@
 }
 
-int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){
+int ip_add_route_req_local(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){
 	ip_route_ref route;
 	ip_netif_ref netif;
@@ -1056,5 +1091,6 @@
 }
 
-int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway){
+int ip_set_gateway_req_local(int ip_phone, device_id_t device_id, in_addr_t gateway)
+{
 	ip_netif_ref netif;
 
@@ -1101,5 +1137,5 @@
 					}
 				}else{
-					pq_release(ip_globals.net_phone, packet_get_id(next));
+					pq_release_remote(ip_globals.net_phone, packet_get_id(next));
 				}
 				next = new_packet;
@@ -1142,5 +1178,5 @@
 	}
 	// create the last fragment
-	new_packet = packet_get_4(ip_globals.net_phone, prefix, length, suffix, ((addrlen > addr_len) ? addrlen : addr_len));
+	new_packet = packet_get_4_remote(ip_globals.net_phone, prefix, length, suffix, ((addrlen > addr_len) ? addrlen : addr_len));
 	if(! new_packet){
 		return ENOMEM;
@@ -1166,5 +1202,5 @@
 	// create middle framgents
 	while(IP_TOTAL_LENGTH(header) > length){
-		new_packet = packet_get_4(ip_globals.net_phone, prefix, length, suffix, ((addrlen >= addr_len) ? addrlen : addr_len));
+		new_packet = packet_get_4_remote(ip_globals.net_phone, prefix, length, suffix, ((addrlen >= addr_len) ? addrlen : addr_len));
 		if(! new_packet){
 			return ENOMEM;
@@ -1346,5 +1382,18 @@
 }
 
-int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){
+/** Notify the IP module about the received error notification packet.
+ *
+ * @param[in] ip_phone  The IP module phone used for (semi)remote calls.
+ * @param[in] device_id The device identifier.
+ * @param[in] packet    The received packet or the received packet queue.
+ * @param[in] target    The target internetwork module service to be
+ *                      delivered to.
+ * @param[in] error     The packet error reporting service. Prefixes the
+ *                      received packet.
+ *
+ * @return EOK on success.
+ *
+ */
+int ip_received_error_msg_local(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){
 	uint8_t * data;
 	int offset;
@@ -1481,5 +1530,5 @@
 	next = pq_detach(packet);
 	if(next){
-		pq_release(ip_globals.net_phone, packet_get_id(next));
+		pq_release_remote(ip_globals.net_phone, packet_get_id(next));
 	}
 	if(! header){
@@ -1545,9 +1594,9 @@
 
 int ip_release_and_return(packet_t packet, int result){
-	pq_release(ip_globals.net_phone, packet_get_id(packet));
+	pq_release_remote(ip_globals.net_phone, packet_get_id(packet));
 	return result;
 }
 
-int ip_get_route_req(int ip_phone, ip_protocol_t protocol, const struct sockaddr * destination, socklen_t addrlen, device_id_t * device_id, ip_pseudo_header_ref * header, size_t * headerlen){
+int ip_get_route_req_local(int ip_phone, ip_protocol_t protocol, const struct sockaddr * destination, socklen_t addrlen, device_id_t * device_id, void **header, size_t * headerlen){
 	struct sockaddr_in * address_in;
 //	struct sockaddr_in6 *	address_in6;
@@ -1613,8 +1662,66 @@
 	header_in->protocol = protocol;
 	header_in->data_length = 0;
-	*header = (ip_pseudo_header_ref) header_in;
+	*header = header_in;
 	return EOK;
 }
 
+/** Default thread for new connections.
+ *
+ *  @param[in] iid The initial message identifier.
+ *  @param[in] icall The initial message call structure.
+ *
+ */
+static void il_client_connection(ipc_callid_t iid, ipc_call_t * icall)
+{
+	/*
+	 * Accept the connection
+	 *  - Answer the first IPC_M_CONNECT_ME_TO call.
+	 */
+	ipc_answer_0(iid, EOK);
+	
+	while(true) {
+		ipc_call_t answer;
+		int answer_count;
+		
+		/* Clear the answer structure */
+		refresh_answer(&answer, &answer_count);
+		
+		/* Fetch the next message */
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		/* Process the message */
+		int res = il_module_message_standalone(callid, &call, &answer,
+		    &answer_count);
+		
+		/* End if said to either by the message or the processing result */
+		if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
+			return;
+		
+		/* Answer the message */
+		answer_call(callid, res, &answer, answer_count);
+	}
+}
+
+/** Starts the module.
+ *
+ *  @param argc The count of the command line arguments. Ignored parameter.
+ *  @param argv The command line parameters. Ignored parameter.
+ *
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for each specific module start function.
+ *
+ */
+int main(int argc, char *argv[])
+{
+	ERROR_DECLARE;
+	
+	/* Start the module */
+	if (ERROR_OCCURRED(il_module_start_standalone(il_client_connection)))
+		return ERROR_CODE;
+	
+	return EOK;
+}
+
 /** @}
  */
Index: uspace/srv/net/il/ip/ip.h
===================================================================
--- uspace/srv/net/il/ip/ip.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/il/ip/ip.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -39,15 +39,13 @@
 
 #include <fibril_synch.h>
-
 #include <ipc/ipc.h>
 #include <ipc/services.h>
 
-#include "../../include/device.h"
-#include "../../include/inet.h"
-#include "../../include/ip_interface.h"
-
-#include "../../structures/int_map.h"
-#include "../../structures/generic_field.h"
-#include "../../structures/module_map.h"
+#include <net_device.h>
+#include <inet.h>
+#include <ip_interface.h>
+#include <adt/int_map.h>
+#include <adt/generic_field.h>
+#include <adt/module_map.h>
 
 /** Type definition of the IP global data.
Index: pace/srv/net/il/ip/ip_client.c
===================================================================
--- uspace/srv/net/il/ip/ip_client.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,187 +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 ip
- *  @{
- */
-
-/** @file
- *  IP client interface implementation.
- *  @see ip_client.h
- */
-
-#include <errno.h>
-
-#include <sys/types.h>
-
-#include "../../include/ip_client.h"
-#include "../../include/socket_errno.h"
-
-#include "../../structures/packet/packet.h"
-#include "../../structures/packet/packet_client.h"
-
-#include "ip_header.h"
-
-size_t ip_client_header_length(packet_t packet){
-	ip_header_ref header;
-
-	header = (ip_header_ref) packet_get_data(packet);
-	if((! header)
-		|| (packet_get_data_length(packet) < sizeof(ip_header_t))){
-		return 0;
-	}
-	return IP_HEADER_LENGTH(header);
-}
-
-int ip_client_get_pseudo_header(ip_protocol_t protocol, struct sockaddr * src, socklen_t srclen, struct sockaddr * dest, socklen_t destlen, size_t data_length, ip_pseudo_header_ref * header, size_t * headerlen){
-	ipv4_pseudo_header_ref header_in;
-	struct sockaddr_in * address_in;
-
-	if(!(header && headerlen)){
-		return EBADMEM;
-	}
-	if(!(src && dest && (srclen > 0) && ((size_t) srclen >= sizeof(struct sockaddr)) && (srclen == destlen) && (src->sa_family == dest->sa_family))){
-		return EINVAL;
-	}
-
-	switch(src->sa_family){
-		case AF_INET:
-			if(srclen != sizeof(struct sockaddr_in)){
-				return EINVAL;
-			}
-			*headerlen = sizeof(*header_in);
-			header_in = (ipv4_pseudo_header_ref) malloc(*headerlen);
-			if(! header_in){
-				return ENOMEM;
-			}
-			bzero(header_in, * headerlen);
-			address_in = (struct sockaddr_in *) dest;
-			header_in->destination_address = address_in->sin_addr.s_addr;
-			address_in = (struct sockaddr_in *) src;
-			header_in->source_address = address_in->sin_addr.s_addr;
-			header_in->protocol = protocol;
-			header_in->data_length = htons(data_length);
-			*header = (ip_pseudo_header_ref) header_in;
-			return EOK;
-		// TODO IPv6
-/*		case AF_INET6:
-			if(addrlen != sizeof(struct sockaddr_in6)){
-				return EINVAL;
-			}
-			address_in6 = (struct sockaddr_in6 *) addr;
-			return EOK;
-*/		default:
-			return EAFNOSUPPORT;
-	}
-}
-
-int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length){
-	ip_header_ref header;
-	uint8_t * data;
-	size_t padding;
-
-	// compute the padding if IP options are set
-	// multiple of 4 bytes
-	padding =  ipopt_length % 4;
-	if(padding){
-		padding = 4 - padding;
-		ipopt_length += padding;
-	}
-
-	// prefix the header
-	data = (uint8_t *) packet_prefix(packet, sizeof(ip_header_t) + padding);
-	if(! data){
-		return ENOMEM;
-	}
-
-	// add the padding
-	while(padding --){
-		data[sizeof(ip_header_t) + padding] = IPOPT_NOOP;
-	}
-
-	// set the header
-	header = (ip_header_ref) data;
-	header->header_length = IP_COMPUTE_HEADER_LENGTH(sizeof(ip_header_t) + ipopt_length);
-	header->ttl = (ttl ? ttl : IPDEFTTL); //(((ttl) <= MAXTTL) ? ttl : MAXTTL) : IPDEFTTL;
-	header->tos = tos;
-	header->protocol = protocol;
-
-	if(dont_fragment){
-		header->flags = IPFLAG_DONT_FRAGMENT;
-	}
-	return EOK;
-}
-
-int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length){
-	ip_header_ref header;
-
-	header = (ip_header_ref) packet_get_data(packet);
-	if((! header)
-		|| (packet_get_data_length(packet) < sizeof(ip_header_t))){
-		return ENOMEM;
-	}
-
-	if(protocol){
-		*protocol = header->protocol;
-	}
-	if(ttl){
-		*ttl = header->ttl;
-	}
-	if(tos){
-		*tos = header->tos;
-	}
-	if(dont_fragment){
-		*dont_fragment = header->flags &IPFLAG_DONT_FRAGMENT;
-	}
-	if(ipopt_length){
-		*ipopt_length = IP_HEADER_LENGTH(header) - sizeof(ip_header_t);
-		return sizeof(ip_header_t);
-	}else{
-		return IP_HEADER_LENGTH(header);
-	}
-}
-
-int ip_client_set_pseudo_header_data_length(ip_pseudo_header_ref header, size_t headerlen, size_t data_length){
-	ipv4_pseudo_header_ref header_in;
-
-	if(! header){
-		return EBADMEM;
-	}
-
-	if(headerlen == sizeof(ipv4_pseudo_header_t)){
-		header_in = (ipv4_pseudo_header_ref) header;
-		header_in->data_length = htons(data_length);
-		return EOK;
-	// TODO IPv6
-	}else{
-		return EINVAL;
-	}
-}
-
-/** @}
- */
Index: pace/srv/net/il/ip/ip_header.h
===================================================================
--- uspace/srv/net/il/ip/ip_header.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,282 +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 ip
- *  @{
- */
-
-/** @file
- *  IP header and options definitions.
- *  Based on the RFC~791.
- */
-
-#ifndef __NET_IP_HEADER_H__
-#define __NET_IP_HEADER_H__
-
-#include <byteorder.h>
-#include <sys/types.h>
-
-/** Returns the fragment offest high bits.
- *  @param[in] length The prefixed data total length.
- */
-#define IP_COMPUTE_FRAGMENT_OFFSET_HIGH(length) ((((length) / 8u) &0x1F00) >> 8)
-
-/** Returns the fragment offest low bits.
- *  @param[in] length The prefixed data total length.
- */
-#define IP_COMPUTE_FRAGMENT_OFFSET_LOW(length) (((length) / 8u) &0xFF)
-
-/** Returns the IP header length.
- *  @param[in] length The IP header length in bytes.
- */
-#define IP_COMPUTE_HEADER_LENGTH(length)		((uint8_t) ((length) / 4u))
-
-/** Returns the fragment offest.
- *  @param[in] header The IP packet header.
- */
-#define IP_FRAGMENT_OFFSET(header) ((((header)->fragment_offset_high << 8) + (header)->fragment_offset_low) * 8u)
-
-/** Returns the IP packet header checksum.
- *  @param[in] header The IP packet header.
- */
-#define IP_HEADER_CHECKSUM(header)	(htons(ip_checksum((uint8_t *)(header), IP_HEADER_LENGTH(header))))
-
-/** Returns the actual IP packet data length.
- *  @param[in] header The IP packet header.
- */
-#define IP_HEADER_DATA_LENGTH(header)	(IP_TOTAL_LENGTH(header) - IP_HEADER_LENGTH(header))
-
-/** Returns the actual IP header length in bytes.
- *  @param[in] header The IP packet header.
- */
-#define IP_HEADER_LENGTH(header)		((header)->header_length * 4u)
-
-/** Returns the actual IP packet total length.
- *  @param[in] header The IP packet header.
- */
-#define IP_TOTAL_LENGTH(header)		ntohs((header)->total_length)
-
-/** @name IP flags definitions
- */
-/*@{*/
-
-/** Fragment flag field shift.
- */
-#define IPFLAG_FRAGMENT_SHIFT		1
-
-/** Fragmented flag field shift.
- */
-#define IPFLAG_FRAGMENTED_SHIFT		0
-
-/** Don't fragment flag value.
- *  Permits the packet fragmentation.
- */
-#define IPFLAG_DONT_FRAGMENT		(0x1 << IPFLAG_FRAGMENT_SHIFT)
-
-/** Last fragment flag value.
- *  Indicates the last packet fragment.
- */
-#define IPFLAG_LAST_FRAGMENT		(0x0 << IPFLAG_FRAGMENTED_SHIFT)
-
-/** May fragment flag value.
- *  Allows the packet fragmentation.
- */
-#define IPFLAG_MAY_FRAGMENT			(0x0 << IPFLAG_FRAGMENT_SHIFT)
-
-/** More fragments flag value.
- *  Indicates that more packet fragments follow.
- */
-#define IPFLAG_MORE_FRAGMENTS		(0x1 << IPFLAG_FRAGMENTED_SHIFT)
-
-/*@}*/
-
-/** Type definition of the internet header.
- *  @see ip_header
- */
-typedef struct ip_header	ip_header_t;
-
-/** Type definition of the internet header pointer.
- *  @see ip_header
- */
-typedef ip_header_t *		ip_header_ref;
-
-/** Type definition of the internet option header.
- *  @see ip_header
- */
-typedef struct ip_option	ip_option_t;
-
-/** Type definition of the internet option header pointer.
- *  @see ip_header
- */
-typedef ip_option_t *		ip_option_ref;
-
-/** Type definition of the internet version 4 pseudo header.
- *  @see ipv4_pseudo_header
- */
-typedef struct ipv4_pseudo_header	ipv4_pseudo_header_t;
-
-/** Type definition of the internet version 4 pseudo header pointer.
- *  @see ipv4_pseudo_header
- */
-typedef ipv4_pseudo_header_t *		ipv4_pseudo_header_ref;
-
-/** Internet header.
- *  The variable options should be included after the header itself and indicated by the increased header length value.
- */
-struct ip_header{
-#ifdef ARCH_IS_BIG_ENDIAN
-	/** The Version field indicates the format of the internet header.
-	 */
-	uint8_t version:4;
-	/** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
-	 *  Note that the minimum value for a~correct header is~5.
-	 */
-	uint8_t header_length:4;
-#else
-	/** Internet Header Length is the length of the internet header in 32~bit words, and thus points to the beginning of the data.
-	 *  Note that the minimum value for a~correct header is~5.
-	 */
-	uint8_t header_length:4;
-	/** The Version field indicates the format of the internet header.
-	 */
-	uint8_t version:4;
-#endif
-	/** The Type of Service provides an indication of the abstract parameters of the quality of service desired.
-	 *  These parameters are to be used to guide the selection of the actual service parameters when transmitting a~datagram through a~particular network.
-	 *  Several networks offer service precedence, which somehow treats high precedence traffic as more important than other traffic (generally by accepting only traffic above a~certain precedence at time of high load).
-	 *  The major choice is a~three way tradeoff between low-delay, high-reliability, and high-throughput.
-	 */
-	uint8_t tos;
-	/** Total Length is the length of the datagram, measured in octets, including internet header and data.
-	 *  This field allows the length of a~datagram to be up to 65,535~octets.
-	 */
-	uint16_t total_length;
-	/** An identifying value assigned by the sender to aid in assembling the fragments of a~datagram.
-	 */
-	uint16_t identification;
-#ifdef ARCH_IS_BIG_ENDIAN
-	/** Various control flags.
-	 */
-	uint8_t flags:3;
-	/** This field indicates where in the datagram this fragment belongs.
-	 *  High bits.
-	 */
-	uint8_t fragment_offset_high:5;
-#else
-	/** This field indicates where in the datagram this fragment belongs.
-	 *  High bits.
-	 */
-	uint8_t fragment_offset_high:5;
-	/** Various control flags.
-	 */
-	uint8_t flags:3;
-#endif
-	/** This field indicates where in the datagram this fragment belongs.
-	 *  Low bits.
-	 */
-	uint8_t fragment_offset_low;
-	/** This field indicates the maximum time the datagram is allowed to remain in the internet system.
-	 *  If this field contains the value zero, then the datagram must be destroyed.
-	 *  This field is modified in internet header processing.
-	 *  The time is measured in units of seconds, but since every module that processes a~datagram must decrease the TTL by at least one even if it process the datagram in less than a~second, the TTL must be thought of only as an upper bound on the time a~datagram may exist.
-	 *  The intention is to cause undeliverable datagrams to be discarded, and to bound the maximum datagram lifetime.
-	 */
-	uint8_t ttl;
-	/** This field indicates the next level protocol used in the data portion of the internet datagram.
-	 */
-	uint8_t protocol;
-	/** A checksum of the header only.
-	 *  Since some header fields change (e.g., time to live), this is recomputed and verified at each point that the internet header is processed.
-	 *  The checksum algorithm is: The checksum field is the 16~bit one's complement of the one's complement sum of all 16~bit words in the header.
-	 *  For purposes of computing the checksum, the value of the checksum field is zero.
-	 */
-	uint16_t header_checksum;
-	/** The source address.
-	 */
-	uint32_t source_address;
-	/** The destination address.
-	 */
-	uint32_t destination_address;
-} __attribute__ ((packed));
-
-/** Internet option header.
- *  Only type field is always valid.
- *  Other fields' validity depends on the option type.
- */
-struct ip_option{
-	/** A single octet of option-type.
-	 */
-	uint8_t type;
-	/** An option length octet.
-	 */
-	uint8_t length;
-	/** A~pointer.
-	 */
-	uint8_t pointer;
-#ifdef ARCH_IS_BIG_ENDIAN
-	/** The number of IP modules that cannot register timestamps due to lack of space.
-	 */
-	uint8_t overflow:4;
-	/** Various internet timestamp control flags.
-	 */
-	uint8_t flags:4;
-#else
-	/** Various internet timestamp control flags.
-	 */
-	uint8_t flags:4;
-	/** The number of IP modules that cannot register timestamps due to lack of space.
-	 */
-	uint8_t overflow:4;
-#endif
-} __attribute__ ((packed));
-
-/** Internet version 4 pseudo header.
- */
-struct ipv4_pseudo_header{
-	/** The source address.
-	 */
-	uint32_t source_address;
-	/** The destination address.
-	 */
-	uint32_t destination_address;
-	/** Reserved byte.
-	 *  Must be zero.
-	 */
-	uint8_t reserved;
-	/** This field indicates the next level protocol used in the data portion of the internet datagram.
-	 */
-	uint8_t protocol;
-	/** Data length is the length of the datagram, measured in octets.
-	 */
-	uint16_t data_length;
-} __attribute__ ((packed));
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/il/ip/ip_messages.h
===================================================================
--- uspace/srv/net/il/ip/ip_messages.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(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 ip
- *  @{
- */
-
-/** @file
- *  IP module messages.
- *  @see ip_interface.h
- */
-
-#ifndef __NET_IP_MESSAGES_H__
-#define __NET_IP_MESSAGES_H__
-
-#include <ipc/ipc.h>
-
-#include "../../include/in.h"
-#include "../../include/ip_codes.h"
-
-/** IP module messages.
- */
-typedef enum{
-	/** Adds the routing entry.
-	 *  @see ip_add_route()
-	 */
-	NET_IP_ADD_ROUTE = NET_IP_FIRST,
-	/** Gets the actual route information.
-	 *  @see ip_get_route()
-	 */
-	NET_IP_GET_ROUTE,
-	/** Processes the received error notification.
-	 *  @see ip_received_error_msg()
-	 */
-	NET_IP_RECEIVED_ERROR,
-	/** Sets the default gateway.
-	 *  @see ip_set_default_gateway()
-	 */
-	NET_IP_SET_GATEWAY
-} ip_messages;
-
-/** @name IP specific message parameters definitions
- */
-/*@{*/
-
-/** Returns the address message parameter.
- *  @param[in] call The message call structure.
- */
-#define IP_GET_ADDRESS(call)		({in_addr_t addr; addr.s_addr = IPC_GET_ARG3(*call); addr;})
-
-/** Returns the gateway message parameter.
- *  @param[in] call The message call structure.
- */
-#define IP_GET_GATEWAY(call)		({in_addr_t addr; addr.s_addr = IPC_GET_ARG2(*call); addr;})
-
-/** Sets the header length in the message answer.
- *  @param[out] answer The message answer structure.
- */
-#define IP_SET_HEADERLEN(answer)	(&IPC_GET_ARG2(*answer))
-
-/** Returns the network mask message parameter.
- *  @param[in] call The message call structure.
- */
-#define IP_GET_NETMASK(call)		({in_addr_t addr; addr.s_addr = IPC_GET_ARG4(*call); addr;})
-
-/** Returns the protocol message parameter.
- *  @param[in] call The message call structure.
- */
-#define IP_GET_PROTOCOL(call)		((ip_protocol_t) IPC_GET_ARG1(*call))
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: uspace/srv/net/il/ip/ip_module.c
===================================================================
--- uspace/srv/net/il/ip/ip_module.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/il/ip/ip_module.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -40,25 +40,19 @@
 #include <async.h>
 #include <stdio.h>
-
 #include <ipc/ipc.h>
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../modules.h"
-
-#include "../../include/net_interface.h"
-
-#include "../../structures/packet/packet.h"
+#include <net_err.h>
+#include <net_modules.h>
+#include <net_interface.h>
+#include <packet/packet.h>
+#include <il_local.h>
 
 #include "ip.h"
 #include "ip_module.h"
 
-/** IP module name.
- */
-#define NAME	"IP protocol"
-
 /** IP module global data.
  */
-extern ip_globals_t	ip_globals;
+extern ip_globals_t ip_globals;
 
 /** Processes the IP message.
@@ -70,10 +64,7 @@
  *  @returns Other error codes as defined for the ip_message() function.
  */
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-/** Prints the module name.
- *  @see NAME
- */
-void module_print_name(void);
+int il_module_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+	return ip_message_standalone(callid, call, answer, answer_count);
+}
 
 /** Starts the IP module.
@@ -84,30 +75,20 @@
  *  @returns Other error codes as defined for the REGISTER_ME() macro function.
  */
-int module_start(async_client_conn_t client_connection);
-
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	return ip_message(callid, call, answer, answer_count);
-}
-
-void module_print_name(void){
-	printf("%s", NAME);
-}
-
-int module_start(async_client_conn_t client_connection){
+int il_module_start_standalone(async_client_conn_t client_connection){
 	ERROR_DECLARE;
-
-	ipcarg_t phonehash;
-
+	
 	async_set_client_connection(client_connection);
 	ip_globals.net_phone = net_connect_module(SERVICE_NETWORKING);
 	ERROR_PROPAGATE(pm_init());
-	if(ERROR_OCCURRED(ip_initialize(client_connection))
-		|| ERROR_OCCURRED(REGISTER_ME(SERVICE_IP, &phonehash))){
+	
+	ipcarg_t phonehash;
+	if (ERROR_OCCURRED(ip_initialize(client_connection))
+	    || ERROR_OCCURRED(REGISTER_ME(SERVICE_IP, &phonehash))) {
 		pm_destroy();
 		return ERROR_CODE;
 	}
-
+	
 	async_manager();
-
+	
 	pm_destroy();
 	return EOK;
Index: uspace/srv/net/il/ip/ip_module.h
===================================================================
--- uspace/srv/net/il/ip/ip_module.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/il/ip/ip_module.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -59,5 +59,5 @@
  *  @see IS_NET_IP_MESSAGE()
  */
-int ip_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
+int ip_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
 
 #endif
Index: pace/srv/net/il/ip/ip_remote.c
===================================================================
--- uspace/srv/net/il/ip/ip_remote.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,121 +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 ip
- *  @{
- */
-
-/** @file
- *  IP interface implementation for standalone remote modules.
- *  @see ip_interface.h
- *  @see il_interface.h
- */
-
-#include <ipc/services.h>
-
-#include "../../messages.h"
-#include "../../modules.h"
-
-#include "../../include/device.h"
-#include "../../include/inet.h"
-#include "../../include/ip_interface.h"
-
-#include "../../structures/packet/packet_client.h"
-
-#include "../il_messages.h"
-
-#include "ip_messages.h"
-
-int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway){
-	return (int) async_req_4_0(ip_phone, NET_IP_ADD_ROUTE, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr, (ipcarg_t) address.s_addr, (ipcarg_t) netmask.s_addr);
-}
-
-int ip_bind_service(services_t service, int protocol, services_t me, async_client_conn_t receiver, tl_received_msg_t tl_received_msg){
-	return (int) bind_service(service, (ipcarg_t) protocol, me, service, receiver);
-}
-
-int ip_connect_module(services_t service){
-	return connect_to_service(SERVICE_IP);
-}
-
-int ip_device_req(int ip_phone, device_id_t device_id, services_t service){
-	return generic_device_req(ip_phone, NET_IL_DEVICE, device_id, 0, service);
-}
-
-int ip_get_route_req(int ip_phone, ip_protocol_t protocol, const struct sockaddr * destination, socklen_t addrlen, device_id_t * device_id, ip_pseudo_header_ref * header, size_t * headerlen){
-	aid_t message_id;
-	ipcarg_t result;
-	ipc_call_t answer;
-
-	if(!(destination && (addrlen > 0))){
-		return EINVAL;
-	}
-	if(!(device_id && header && headerlen)){
-		return EBADMEM;
-	}
-
-	*header = NULL;
-	message_id = async_send_1(ip_phone, NET_IP_GET_ROUTE, (ipcarg_t) protocol, &answer);
-	if((async_data_write_start(ip_phone, destination, addrlen) == EOK)
-		&& (async_data_read_start(ip_phone, headerlen, sizeof(*headerlen)) == EOK)
-		&& (*headerlen > 0)){
-		*header = (ip_pseudo_header_ref) malloc(*headerlen);
-		if(*header){
-			if(async_data_read_start(ip_phone, * header, * headerlen) != EOK){
-				free(*header);
-			}
-		}
-	}
-	async_wait_for(message_id, &result);
-
-	if((result != EOK) && (*header)){
-		free(*header);
-	}else{
-		*device_id = IPC_GET_DEVICE(&answer);
-	}
-	return (int) result;
-}
-
-int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension){
-	return generic_packet_size_req(ip_phone, NET_IL_PACKET_SPACE, device_id, packet_dimension);
-}
-
-int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){
-	return generic_received_msg(ip_phone, NET_IP_RECEIVED_ERROR, device_id, packet_get_id(packet), target, error);
-}
-
-int ip_send_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error){
-	return generic_send_msg(ip_phone, NET_IL_SEND, device_id, packet_get_id(packet), sender, error);
-}
-
-int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway){
-	return (int) async_req_2_0(ip_phone, NET_IP_SET_GATEWAY, (ipcarg_t) device_id, (ipcarg_t) gateway.s_addr);
-}
-
-/** @}
- */
Index: pace/srv/net/include/arp_interface.h
===================================================================
--- uspace/srv/net/include/arp_interface.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,129 +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 arp
- *  @{
- */
-
-/** @file
- *  ARP module interface.
- *  The same interface is used for standalone remote modules as well as for bundle modules.
- *  The standalone remote modules have to be compiled with the arp_remote.c source file.
- *  The bundle modules with the arp.c source file.
- */
-
-#ifndef __NET_ARP_INTERFACE_H__
-#define __NET_ARP_INTERFACE_H__
-
-#include "../structures/measured_strings.h"
-
-#include "device.h"
-
-/** @name ARP module interface
- *  This interface is used by other modules.
- */
-/*@{*/
-
-/** Registers the new device and the requesting protocol service.
- *  Connects to the network interface layer service.
- *  Determines the device broadcast address, its address lengths and packet size.
- *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
- *  @param[in] device_id The new device identifier.
- *  @param[in] protocol The requesting protocol service.
- *  @param[in] netif The underlying device network interface layer service.
- *  @param[in] address The local requesting protocol address of the device.
- *  @returns EOK on success.
- *  @returns EEXIST if the device is already used.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns ENOENT if the network interface service is not known.
- *  @returns EREFUSED if the network interface service is not responding.
- *  @returns Other error codes as defined for the nil_packet_get_size() function.
- *  @returns Other error codes as defined for the nil_get_addr() function.
- *  @returns Other error codes as defined for the nil_get_broadcast_addr() function.
- */
-int arp_device_req(int arp_phone, device_id_t device_id, services_t protocol, services_t netif, measured_string_ref address);
-
-/** Translates the given protocol address to the network interface address.
- *  Broadcasts the ARP request if the mapping is not found.
- *  Allocates and returns the needed memory block as the data parameter.
- *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
- *  @param[in] device_id The device identifier.
- *  @param[in] protocol The requesting protocol service.
- *  @param[in] address The local requesting protocol address.
- *  @param[out] translation The translation of the local protocol address.
- *  @param[out] data The allocated raw translation data container.
- *  @returns EOK on success.
- *  @returns EINVAL if the address parameter is NULL.
- *  @returns EBADMEM if the translation or the data parameters are NULL.
- *  @returns ENOENT if the mapping is not found.
- */
-int arp_translate_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address, measured_string_ref * translation, char ** data);
-
-/** Clears the device cache.
- *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
- *  @param[in] device_id The device identifier.
- *  @returns EOK on success.
- *  @returns ENOENT if the device is not found.
- */
-int arp_clear_device_req(int arp_phone, device_id_t device_id);
-
-/** Clears the given protocol address from the cache.
- *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
- *  @param[in] device_id The device identifier.
- *  @param[in] protocol The requesting protocol service.
- *  @param[in] address The protocol address to be cleared.
- *  @returns EOK on success.
- *  @returns ENOENT if the mapping is not found.
- */
-int arp_clear_address_req(int arp_phone, device_id_t device_id, services_t protocol, measured_string_ref address);
-
-/** Cleans the cache.
- *  @param[in] arp_phone The ARP module phone used for (semi)remote calls.
- *  @returns EOK on success.
- */
-int arp_clean_cache_req(int arp_phone);
-
-/** Connects to the ARP module.
- *  @param service The ARP module service. Ignored parameter.
- *  @returns The ARP module phone on success.
- *  @returns 0 if called by the bundle module.
- */
-int arp_connect_module(services_t service);
-
-/** Returns the ARP task identifier.
- *  @returns The current task identifier if called by the bundle module.
- *  @returns 0 if called by the remote module.
- */
-task_id_t arp_task_get_id(void);
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/byteorder.h
===================================================================
--- uspace/srv/net/include/byteorder.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,71 +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 net
- *  @{
- */
-
-/** @file
- *  Host - network byte order manipulation functions.
- */
-
-#ifndef __NET_BYTEORDER_H__
-#define __NET_BYTEORDER_H__
-
-#include <byteorder.h>
-#include <sys/types.h>
-
-
-/** Converts the given short number (16 bit) from the host byte order to the network byte order (big endian).
- *  @param[in] number The number in the host byte order to be converted.
- *  @returns The number in the network byte order.
- */
-#define htons(number)		host2uint16_t_be(number)
-
-/** Converts the given long number (32 bit) from the host byte order to the network byte order (big endian).
- *  @param[in] number The number in the host byte order to be converted.
- *  @returns The number in the network byte order.
- */
-#define htonl(number)		host2uint32_t_be(number)
-
-/** Converts the given short number (16 bit) from the network byte order (big endian) to the host byte order.
- *  @param[in] number The number in the network byte order to be converted.
- *  @returns The number in the host byte order.
- */
-#define ntohs(number) 	uint16_t_be2host(number)
-
-/** Converts the given long number (32 bit) from the network byte order (big endian) to the host byte order.
- *  @param[in] number The number in the network byte order to be converted.
- *  @returns The number in the host byte order.
- */
-#define ntohl(number)		uint32_t_be2host(number)
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/checksum.h
===================================================================
--- uspace/srv/net/include/checksum.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,113 +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 net
- *  @{
- */
-
-/** @file
- *  General CRC and checksum computation.
- */
-
-#ifndef __NET_CHECKSUM_H__
-#define __NET_CHECKSUM_H__
-
-#include <byteorder.h>
-
-#include <sys/types.h>
-
-/** IP checksum value for computed zero checksum.
- *  Zero is returned as 0xFFFF (not flipped)
- */
-#define IP_CHECKSUM_ZERO			0xFFFFu
-
-/**	Computes CRC32 value.
- *  @param[in] seed Initial value. Often used as 0 or ~0.
- *  @param[in] data Pointer to the beginning of data to process.
- *  @param[in] length Length of the data in bits.
- *  @returns The computed CRC32 of the length bits of the data.
- */
-#ifdef ARCH_IS_BIG_ENDIAN
-	#define compute_crc32(seed, data, length)	compute_crc32_be(seed, (uint8_t *) data, length)
-#else
-	#define compute_crc32(seed, data, length)	compute_crc32_le(seed, (uint8_t *) data, length)
-#endif
-
-/**	Computes CRC32 value in the little-endian environment.
- *  @param[in] seed Initial value. Often used as 0 or ~0.
- *  @param[in] data Pointer to the beginning of data to process.
- *  @param[in] length Length of the data in bits.
- *  @returns The computed CRC32 of the length bits of the data.
- */
-uint32_t compute_crc32_le(uint32_t seed, uint8_t * data, size_t length);
-
-/**	Computes CRC32 value in the big-endian environment.
- *  @param[in] seed Initial value. Often used as 0 or ~0.
- *  @param[in] data Pointer to the beginning of data to process.
- *  @param[in] length Length of the data in bits.
- *  @returns The computed CRC32 of the length bits of the data.
- */
-uint32_t compute_crc32_be(uint32_t seed, uint8_t * data, size_t length);
-
-/** Computes sum of the 2 byte fields.
- *  Padds one zero (0) byte if odd.
- *  @param[in] seed Initial value. Often used as 0 or ~0.
- *  @param[in] data Pointer to the beginning of data to process.
- *  @param[in] length Length of the data in bytes.
- *  @returns The computed checksum of the length bytes of the data.
- */
-uint32_t compute_checksum(uint32_t seed, uint8_t * data, size_t length);
-
-/** Compacts the computed checksum to the 16 bit number adding the carries.
- *  @param[in] sum Computed checksum.
- *  @returns Compacted computed checksum to the 16 bits.
- */
-uint16_t compact_checksum(uint32_t sum);
-
-/** Returns or flips the checksum if zero.
- *  @param[in] checksum The computed checksum.
- *  @returns The internet protocol header checksum.
- *  @returns 0xFFFF if the computed checksum is zero.
- */
-uint16_t flip_checksum(uint16_t checksum);
-
-/** Computes the ip header checksum.
- *  To compute the checksum of a new packet, the checksum header field must be zero.
- *  To check the checksum of a received packet, the checksum may be left set.
- *  The zero (0) value will be returned in this case if valid.
- *  @param[in] data The header data.
- *  @param[in] length The header length in bytes.
- *  @returns The internet protocol header checksum.
- *  @returns 0xFFFF if the computed checksum is zero.
- */
-uint16_t ip_checksum(uint8_t * data, size_t length);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/device.h
===================================================================
--- uspace/srv/net/include/device.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,173 +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 netif
- *  @{
- */
-
-/** @file
- *  Device identifier, state and usage statistics.
- */
-
-#ifndef __NET_DEVICE_ID_TYPE_H__
-#define __NET_DEVICE_ID_TYPE_H__
-
-#include "../structures/int_map.h"
-
-/** Device identifier to generic type map declaration.
- */
-#define DEVICE_MAP_DECLARE		INT_MAP_DECLARE
-
-/** Device identifier to generic type map implementation.
- */
-#define DEVICE_MAP_IMPLEMENT	INT_MAP_IMPLEMENT
-
-/** Invalid device identifier.
- */
-#define DEVICE_INVALID_ID		(-1)
-
-/** Device identifier type.
- */
-typedef int	device_id_t;
-
-/** Device state type.
- */
-typedef enum device_state	device_state_t;
-
-/** Type definition of the device usage statistics.
- *  @see device_stats
- */
-typedef struct device_stats	device_stats_t;
-
-/** Type definition of the device usage statistics pointer.
- *  @see device_stats
- */
-typedef device_stats_t *	device_stats_ref;
-
-/** Device state.
- */
-enum	device_state{
-	/** Device not present or not initialized.
-	 */
-	NETIF_NULL = 0,
-	/** Device present and stopped.
-	 */
-	NETIF_STOPPED,
-	/** Device present and active.
-	 */
-	NETIF_ACTIVE,
-	/** Device present but unable to transmit.
-	 */
-	NETIF_CARRIER_LOST
-};
-
-/** Device usage statistics.
- */
-struct	device_stats{
-	/** Total packets received.
-	 */
-	unsigned long receive_packets;
-	/** Total packets transmitted.
-	 */
-	unsigned long send_packets;
-	/** Total bytes received.
-	 */
-	unsigned long receive_bytes;
-	/** Total bytes transmitted.
-	 */
-	unsigned long send_bytes;
-	/** Bad packets received counter.
-	 */
-	unsigned long receive_errors;
-	/** Packet transmition problems counter.
-	 */
-	unsigned long send_errors;
-	/** No space in buffers counter.
-	 */
-	unsigned long receive_dropped;
-	/** No space available counter.
-	 */
-	unsigned long send_dropped;
-	/** Total multicast packets received.
-	 */
-	unsigned long multicast;
-	/** The number of collisions due to congestion on the medium.
-	 */
-	unsigned long collisions;
-
-	/* detailed receive_errors: */
-	/** Received packet length error counter.
-	 */
-	unsigned long receive_length_errors;
-	/** Receiver buffer overflow counter.
-	 */
-	unsigned long receive_over_errors;
-	/** Received packet with crc error counter.
-	 */
-	unsigned long receive_crc_errors;
-	/** Received frame alignment error counter.
-	 */
-	unsigned long receive_frame_errors;
-	/** Receiver fifo overrun counter.
-	 */
-	unsigned long receive_fifo_errors;
-	/** Receiver missed packet counter.
-	 */
-	unsigned long receive_missed_errors;
-
-	/* detailed send_errors */
-	/** Transmitter aborted counter.
-	 */
-	unsigned long send_aborted_errors;
-	/** Transmitter carrier errors counter.
-	 */
-	unsigned long send_carrier_errors;
-	/** Transmitter fifo overrun counter.
-	 */
-	unsigned long send_fifo_errors;
-	/** Transmitter carrier errors counter.
-	 */
-	unsigned long send_heartbeat_errors;
-	/** Transmitter window errors counter.
-	 */
-	unsigned long send_window_errors;
-
-	/* for cslip etc */
-	/** Total compressed packets received.
-	 */
-	unsigned long receive_compressed;
-	/** Total compressed packet transmitted.
-	 */
-	unsigned long send_compressed;
-};
-
-#endif
-
-/** @}
- */
-
Index: pace/srv/net/include/ethernet_lsap.h
===================================================================
--- uspace/srv/net/include/ethernet_lsap.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,137 +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 eth
- *  @{
- */
-
-/** @file
- *  Link service access point identifiers.
- */
-
-#ifndef __NET_ETHERNET_LSAP_H__
-#define __NET_ETHERNET_LSAP_H__
-
-#include <sys/types.h>
-
-/** Ethernet LSAP type definition.
- */
-typedef uint8_t	eth_lsap_t;
-
-/** @name Ethernet LSAP values definitions
- */
-/*@{*/
-
-/** Null LSAP LSAP identifier.
- */
-#define ETH_LSAP_NULL	0x00
-/** Individual LLC Sublayer Management Function LSAP identifier.
- */
-#define ETH_LSAP_ISLMF	0x02
-/** Group LLC Sublayer Management Function LSAP identifier.
- */
-#define ETH_LSAP_GSLMI	0x03
-/** IBM SNA Path Control (individual) LSAP identifier.
- */
-#define ETH_LSAP_ISNA	0x04
-/** IBM SNA Path Control (group) LSAP identifier.
- */
-#define ETH_LSAP_GSNA	0x05
-/** ARPANET Internet Protocol (IP) LSAP identifier.
- */
-#define ETH_LSAP_IP	0x06
-/** SNA LSAP identifier.
- */
-#define ETH_LSAP_SNA	0x08
-/** SNA LSAP identifier.
- */
-#define ETH_LSAP_SNA2	0x0C
-/** PROWAY (IEC955) Network Management &Initialization LSAP identifier.
- */
-#define ETH_LSAP_PROWAY_NMI	0x0E
-/** Texas Instruments LSAP identifier.
- */
-#define ETH_LSAP_TI	0x18
-/** IEEE 802.1 Bridge Spanning Tree Protocol LSAP identifier.
- */
-#define ETH_LSAP_BRIDGE	0x42
-/** EIA RS-511 Manufacturing Message Service LSAP identifier.
- */
-#define ETH_LSAP_EIS	0x4E
-/** ISO 8208 (X.25 over IEEE 802.2 Type 2 LLC) LSAP identifier.
- */
-#define ETH_LSAP_ISO8208	0x7E
-/** Xerox Network Systems (XNS) LSAP identifier.
- */
-#define ETH_LSAP_XNS	0x80
-/** Nestar LSAP identifier.
- */
-#define ETH_LSAP_NESTAR	0x86
-/** PROWAY (IEC 955) Active Station List Maintenance LSAP identifier.
- */
-#define ETH_LSAP_PROWAY_ASLM	0x8E
-/** ARPANET Address Resolution Protocol (ARP) LSAP identifier.
- */
-#define ETH_LSAP_ARP	0x98
-/** Banyan VINES LSAP identifier.
- */
-#define ETH_LSAP_VINES	0xBC
-/** SubNetwork Access Protocol (SNAP) LSAP identifier.
- */
-#define ETH_LSAP_SNAP	0xAA
-/** Novell NetWare LSAP identifier.
- */
-#define ETH_LSAP_NETWARE	0xE0
-/** IBM NetBIOS LSAP identifier.
- */
-#define ETH_LSAP_NETBIOS	0xF0
-/** IBM LAN Management (individual) LSAP identifier.
- */
-#define ETH_LSAP_ILAN	0xF4
-/** IBM LAN Management (group) LSAP identifier.
- */
-#define ETH_LSAP_GLAN	0xF5
-/** IBM Remote Program Load (RPL) LSAP identifier.
- */
-#define ETH_LSAP_RPL	0xF8
-/** Ungermann-Bass LSAP identifier.
- */
-#define ETH_LSAP_UB	0xFA
-/** ISO Network Layer Protocol LSAP identifier.
- */
-#define ETH_LSAP_ISONLP	0xFE
-/** Global LSAP LSAP identifier.
- */
-#define ETH_LSAP_GLSAP	0xFF
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/ethernet_protocols.h
===================================================================
--- uspace/srv/net/include/ethernet_protocols.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,1012 +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 eth
- *  @{
- */
-
-/** @file
- *  Ethernet protocol numbers according to the on-line IANA - Ethernet numbers - <http://www.iana.org/assignments/ethernet-numbers>, cited January 17 2009.
- */
-
-#ifndef __NET_ETHERNET_PROTOCOLS_H__
-#define __NET_ETHERNET_PROTOCOLS_H__
-
-#include <sys/types.h>
-
-/** Ethernet protocol type definition.
- */
-typedef uint16_t	eth_type_t;
-
-/** @name Ethernet protocols definitions
- */
-/*@{*/
-
-/** Ethernet minimal protocol number.
- *  According to the IEEE 802.3 specification.
- */
-#define ETH_MIN_PROTO	0x0600 /*1536*/
-
-/** Ethernet loopback packet protocol type.
- */
-#define ETH_P_LOOP		0x0060
-
-/** XEROX PUP (see 0A00) ethernet protocol type.
- */
-#define ETH_P_PUP		0x0200
-
-/** PUP Addr Trans (see 0A01) ethernet protocol type.
- */
-#define ETH_P_PUPAT		0x0201
-
-/** Nixdorf ethernet protocol type.
- */
-#define ETH_P_Nixdorf		0x0400
-
-/** XEROX NS IDP ethernet protocol type.
- */
-#define ETH_P_XEROX_NS_IDP		0x0600
-
-/** DLOG ethernet protocol type.
- */
-#define ETH_P_DLOG		0x0660
-
-/** DLOG ethernet protocol type.
- */
-#define ETH_P_DLOG2		0x0661
-
-/** Internet IP (IPv4) ethernet protocol type.
- */
-#define ETH_P_IP		0x0800
-
-/** X.75 Internet ethernet protocol type.
- */
-#define ETH_P_X_75		0x0801
-
-/** NBS Internet ethernet protocol type.
- */
-#define ETH_P_NBS		0x0802
-
-/** ECMA Internet ethernet protocol type.
- */
-#define ETH_P_ECMA		0x0803
-
-/** Chaosnet ethernet protocol type.
- */
-#define ETH_P_Chaosnet		0x0804
-
-/** X.25 Level 3 ethernet protocol type.
- */
-#define ETH_P_X25		0x0805
-
-/** ARP ethernet protocol type.
- */
-#define ETH_P_ARP		0x0806
-
-/** XNS Compatability ethernet protocol type.
- */
-#define ETH_P_XNS_Compatability		0x0807
-
-/** Frame Relay ARP ethernet protocol type.
- */
-#define ETH_P_Frame_Relay_ARP		0x0808
-
-/** Symbolics Private ethernet protocol type.
- */
-#define ETH_P_Symbolics_Private		0x081C
-
-/** Xyplex ethernet protocol type.
- */
-#define ETH_P_Xyplex_MIN		0x0888
-
-/** Xyplex ethernet protocol type.
- */
-#define ETH_P_Xyplex_MAX		0x088A
-
-/** Ungermann-Bass net debugr ethernet protocol type.
- */
-#define ETH_P_Ungermann_Bass_net_debugr		0x0900
-
-/** Xerox IEEE802.3 PUP ethernet protocol type.
- */
-#define ETH_P_IEEEPUP		0x0A00
-
-/** PUP Addr Trans ethernet protocol type.
- */
-#define ETH_P_IEEEPUPAT		0x0A01
-
-/** Banyan VINES ethernet protocol type.
- */
-#define ETH_P_Banyan_VINES		0x0BAD
-
-/** VINES Loopback ethernet protocol type.
- */
-#define ETH_P_VINES_Loopback		0x0BAE
-
-/** VINES Echo ethernet protocol type.
- */
-#define ETH_P_VINES_Echo		0x0BAF
-
-/** Berkeley Trailer nego ethernet protocol type.
- */
-#define ETH_P_Berkeley_Trailer_nego		0x1000
-
-/** Berkeley Trailer encap/IP ethernet protocol type.
- */
-#define ETH_P_Berkeley_Trailer_encapIP_MIN		0x1001
-
-/** Berkeley Trailer encap/IP ethernet protocol type.
- */
-#define ETH_P_Berkeley_Trailer_encapIP_MAX		0x100F
-
-/** Valid Systems ethernet protocol type.
- */
-#define ETH_P_Valid_Systems		0x1600
-
-/** PCS Basic Block Protocol ethernet protocol type.
- */
-#define ETH_P_PCS_Basic_Block_Protocol		0x4242
-
-/** BBN Simnet ethernet protocol type.
- */
-#define ETH_P_BBN_Simnet		0x5208
-
-/** DEC Unassigned (Exp.) ethernet protocol type.
- */
-#define ETH_P_DEC		0x6000
-
-/** DEC MOP Dump/Load ethernet protocol type.
- */
-#define ETH_P_DNA_DL		0x6001
-
-/** DEC MOP Remote Console ethernet protocol type.
- */
-#define ETH_P_DNA_RC		0x6002
-
-/** DEC DECNET Phase IV Route ethernet protocol type.
- */
-#define ETH_P_DNA_RT		0x6003
-
-/** DEC LAT ethernet protocol type.
- */
-#define ETH_P_LAT		0x6004
-
-/** DEC Diagnostic Protocol ethernet protocol type.
- */
-#define ETH_P_DIAG		0x6005
-
-/** DEC Customer Protocol ethernet protocol type.
- */
-#define ETH_P_CUST		0x6006
-
-/** DEC LAVC, SCA ethernet protocol type.
- */
-#define ETH_P_SCA		0x6007
-
-/** DEC Unassigned ethernet protocol type.
- */
-#define ETH_P_DEC_Unassigned_MIN		0x6008
-
-/** DEC Unassigned ethernet protocol type.
- */
-#define ETH_P_DEC_Unassigned_MAX		0x6009
-
-/** Com Corporation ethernet protocol type.
- */
-#define ETH_P_Com_Corporation_MIN		0x6010
-
-/** Com Corporation ethernet protocol type.
- */
-#define ETH_P_Com_Corporation_MAX		0x6014
-
-/** Trans Ether Bridging ethernet protocol type.
- */
-#define ETH_P_Trans_Ether_Bridging		0x6558
-
-/** Raw Frame Relay ethernet protocol type.
- */
-#define ETH_P_Raw_Frame_Relay		0x6559
-
-/** Ungermann-Bass download ethernet protocol type.
- */
-#define ETH_P_Ungermann_Bass_download		0x7000
-
-/** Ungermann-Bass dia/loop ethernet protocol type.
- */
-#define ETH_P_Ungermann_Bass_dialoop		0x7002
-
-/** LRT ethernet protocol type.
- */
-#define ETH_P_LRT_MIN		0x7020
-
-/** LRT ethernet protocol type.
- */
-#define ETH_P_LRT_MAX		0x7029
-
-/** Proteon ethernet protocol type.
- */
-#define ETH_P_Proteon		0x7030
-
-/** Cabletron ethernet protocol type.
- */
-#define ETH_P_Cabletron		0x7034
-
-/** Cronus VLN ethernet protocol type.
- */
-#define ETH_P_Cronus_VLN		0x8003
-
-/** Cronus Direct ethernet protocol type.
- */
-#define ETH_P_Cronus_Direct		0x8004
-
-/** HP Probe ethernet protocol type.
- */
-#define ETH_P_HP_Probe		0x8005
-
-/** Nestar ethernet protocol type.
- */
-#define ETH_P_Nestar		0x8006
-
-/** AT&T ethernet protocol type.
- */
-#define ETH_P_AT_T		0x8008
-
-/** Excelan ethernet protocol type.
- */
-#define ETH_P_Excelan		0x8010
-
-/** SGI diagnostics ethernet protocol type.
- */
-#define ETH_P_SGI_diagnostics		0x8013
-
-/** SGI network games ethernet protocol type.
- */
-#define ETH_P_SGI_network_games		0x8014
-
-/** SGI reserved ethernet protocol type.
- */
-#define ETH_P_SGI_reserved		0x8015
-
-/** SGI bounce server ethernet protocol type.
- */
-#define ETH_P_SGI_bounce_server		0x8016
-
-/** Apollo Domain ethernet protocol type.
- */
-#define ETH_P_Apollo_Domain		0x8019
-
-/** Tymshare ethernet protocol type.
- */
-#define ETH_P_Tymshare		0x802E
-
-/** Tigan, Inc. ethernet protocol type.
- */
-#define ETH_P_Tigan		0x802F
-
-/** Reverse ARP ethernet protocol type.
- */
-#define ETH_P_RARP		0x8035
-
-/** Aeonic Systems ethernet protocol type.
- */
-#define ETH_P_Aeonic_Systems		0x8036
-
-/** DEC LANBridge ethernet protocol type.
- */
-#define ETH_P_DEC_LANBridge		0x8038
-
-/** DEC Unassigned ethernet protocol type.
- */
-#define ETH_P_DEC_Unassigned_MIN1		0x8039
-
-/** DEC Unassigned ethernet protocol type.
- */
-#define ETH_P_DEC_Unassigned_MAX2		0x803C
-
-/** DEC Ethernet Encryption ethernet protocol type.
- */
-#define ETH_P_DEC_Ethernet_Encryption		0x803D
-
-/** DEC Unassigned ethernet protocol type.
- */
-#define ETH_P_DEC_Unassigned		0x803E
-
-/** DEC LAN Traffic Monitor ethernet protocol type.
- */
-#define ETH_P_DEC_LAN_Traffic_Monitor		0x803F
-
-/** DEC Unassigned ethernet protocol type.
- */
-#define ETH_P_DEC_Unassigned_MIN3		0x8040
-
-/** DEC Unassigned ethernet protocol type.
- */
-#define ETH_P_DEC_Unassigned_MAX3		0x8042
-
-/** Planning Research Corp. ethernet protocol type.
- */
-#define ETH_P_Planning_Research_Corp		0x8044
-
-/** AT&T ethernet protocol type.
- */
-#define ETH_P_AT_T2		0x8046
-
-/** AT&T ethernet protocol type.
- */
-#define ETH_P_AT_T3		0x8047
-
-/** ExperData ethernet protocol type.
- */
-#define ETH_P_ExperData		0x8049
-
-/** Stanford V Kernel exp. ethernet protocol type.
- */
-#define ETH_P_Stanford_V_Kernel_exp		0x805B
-
-/** Stanford V Kernel prod. ethernet protocol type.
- */
-#define ETH_P_Stanford_V_Kernel_prod		0x805C
-
-/** Evans &Sutherland ethernet protocol type.
- */
-#define ETH_P_Evans_Sutherland		0x805D
-
-/** Little Machines ethernet protocol type.
- */
-#define ETH_P_Little_Machines		0x8060
-
-/** Counterpoint Computers ethernet protocol type.
- */
-#define ETH_P_Counterpoint_Computers		0x8062
-
-/** Univ. of Mass. @ Amherst ethernet protocol type.
- */
-#define ETH_P_Univ_of_Mass		0x8065
-
-/** Univ. of Mass. @ Amherst ethernet protocol type.
- */
-#define ETH_P_Univ_of_Mass2		0x8066
-
-/** Veeco Integrated Auto. ethernet protocol type.
- */
-#define ETH_P_Veeco_Integrated_Auto		0x8067
-
-/** General Dynamics ethernet protocol type.
- */
-#define ETH_P_General_Dynamics		0x8068
-
-/** AT&T ethernet protocol type.
- */
-#define ETH_P_AT_T4		0x8069
-
-/** Autophon ethernet protocol type.
- */
-#define ETH_P_Autophon		0x806A
-
-/** ComDesign ethernet protocol type.
- */
-#define ETH_P_ComDesign		0x806C
-
-/** Computgraphic Corp. ethernet protocol type.
- */
-#define ETH_P_Computgraphic_Corp		0x806D
-
-/** Landmark Graphics Corp. ethernet protocol type.
- */
-#define ETH_P_Landmark_Graphics_Corp_MIN		0x806E
-
-/** Landmark Graphics Corp. ethernet protocol type.
- */
-#define ETH_P_Landmark_Graphics_Corp_MAX		0x8077
-
-/** Matra ethernet protocol type.
- */
-#define ETH_P_Matra		0x807A
-
-/** Dansk Data Elektronik ethernet protocol type.
- */
-#define ETH_P_Dansk_Data_Elektronik		0x807B
-
-/** Merit Internodal ethernet protocol type.
- */
-#define ETH_P_Merit_Internodal		0x807C
-
-/** Vitalink Communications ethernet protocol type.
- */
-#define ETH_P_Vitalink_Communications_MIN		0x807D
-
-/** Vitalink Communications ethernet protocol type.
- */
-#define ETH_P_Vitalink_Communications_MAX		0x807F
-
-/** Vitalink TransLAN III ethernet protocol type.
- */
-#define ETH_P_Vitalink_TransLAN_III		0x8080
-
-/** Counterpoint Computers ethernet protocol type.
- */
-#define ETH_P_Counterpoint_Computers_MIN		0x8081
-
-/** Counterpoint Computers ethernet protocol type.
- */
-#define ETH_P_Counterpoint_Computers_MAX		0x8083
-
-/** Appletalk ethernet protocol type.
- */
-#define ETH_P_ATALK		0x809B
-
-/** Datability ethernet protocol type.
- */
-#define ETH_P_Datability_MIN		0x809C
-
-/** Datability ethernet protocol type.
- */
-#define ETH_P_Datability_MAX		0x809E
-
-/** Spider Systems Ltd. ethernet protocol type.
- */
-#define ETH_P_Spider_Systems_Ltd		0x809F
-
-/** Nixdorf Computers ethernet protocol type.
- */
-#define ETH_P_Nixdorf_Computers		0x80A3
-
-/** Siemens Gammasonics Inc. ethernet protocol type.
- */
-#define ETH_P_Siemens_Gammasonics_Inc_MIN		0x80A4
-
-/** Siemens Gammasonics Inc. ethernet protocol type.
- */
-#define ETH_P_Siemens_Gammasonics_Inc_MAX		0x80B3
-
-/** DCA Data Exchange Cluster ethernet protocol type.
- */
-#define ETH_P_DCA_Data_Exchange_Cluster_MIN		0x80C0
-
-/** DCA Data Exchange Cluster ethernet protocol type.
- */
-#define ETH_P_DCA_Data_Exchange_Cluster_MAX		0x80C3
-
-/** Banyan Systems ethernet protocol type.
- */
-#define ETH_P_Banyan_Systems		0x80C4
-
-/** Banyan Systems ethernet protocol type.
- */
-#define ETH_P_Banyan_Systems2		0x80C5
-
-/** Pacer Software ethernet protocol type.
- */
-#define ETH_P_Pacer_Software		0x80C6
-
-/** Applitek Corporation ethernet protocol type.
- */
-#define ETH_P_Applitek_Corporation		0x80C7
-
-/** Intergraph Corporation ethernet protocol type.
- */
-#define ETH_P_Intergraph_Corporation_MIN		0x80C8
-
-/** Intergraph Corporation ethernet protocol type.
- */
-#define ETH_P_Intergraph_Corporation_MAX		0x80CC
-
-/** Harris Corporation ethernet protocol type.
- */
-#define ETH_P_Harris_Corporation_MIN		0x80CD
-
-/** Harris Corporation ethernet protocol type.
- */
-#define ETH_P_Harris_Corporation_MAX		0x80CE
-
-/** Taylor Instrument ethernet protocol type.
- */
-#define ETH_P_Taylor_Instrument_MIN		0x80CF
-
-/** Taylor Instrument ethernet protocol type.
- */
-#define ETH_P_Taylor_Instrument_MAX		0x80D2
-
-/** Rosemount Corporation ethernet protocol type.
- */
-#define ETH_P_Rosemount_Corporation_MIN		0x80D3
-
-/** Rosemount Corporation ethernet protocol type.
- */
-#define ETH_P_Rosemount_Corporation_MAX		0x80D4
-
-/** IBM SNA Service on Ether ethernet protocol type.
- */
-#define ETH_P_IBM_SNA_Service_on_Ether		0x80D5
-
-/** Varian Associates ethernet protocol type.
- */
-#define ETH_P_Varian_Associates		0x80DD
-
-/** Integrated Solutions TRFS ethernet protocol type.
- */
-#define ETH_P_Integrated_Solutions_TRFS_MIN		0x80DE
-
-/** Integrated Solutions TRFS ethernet protocol type.
- */
-#define ETH_P_Integrated_Solutions_TRFS_MAX		0x80DF
-
-/** Allen-Bradley ethernet protocol type.
- */
-#define ETH_P_Allen_Bradley_MIN		0x80E0
-
-/** Allen-Bradley ethernet protocol type.
- */
-#define ETH_P_Allen_Bradley_MAX		0x80E3
-
-/** Datability ethernet protocol type.
- */
-#define ETH_P_Datability_MIN2		0x80E4
-
-/** Datability ethernet protocol type.
- */
-#define ETH_P_Datability_MAX2		0x80F0
-
-/** Retix ethernet protocol type.
- */
-#define ETH_P_Retix		0x80F2
-
-/** AppleTalk AARP (Kinetics) ethernet protocol type.
- */
-#define ETH_P_AARP		0x80F3
-
-/** Kinetics ethernet protocol type.
- */
-#define ETH_P_Kinetics_MIN		0x80F4
-
-/** Kinetics ethernet protocol type.
- */
-#define ETH_P_Kinetics_MAX		0x80F5
-
-/** Apollo Computer ethernet protocol type.
- */
-#define ETH_P_Apollo_Computer		0x80F7
-
-/** Wellfleet Communications ethernet protocol type.
- */
-#define ETH_P_Wellfleet_Communications		0x80FF
-
-/** IEEE 802.1Q VLAN-tagged frames (initially Wellfleet) ethernet protocol type.
- */
-#define ETH_P_8021Q		0x8100
-
-/** Wellfleet Communications ethernet protocol type.
- */
-#define ETH_P_Wellfleet_Communications_MIN		0x8101
-
-/** Wellfleet Communications ethernet protocol type.
- */
-#define ETH_P_Wellfleet_Communications_MAX		0x8103
-
-/** Symbolics Private ethernet protocol type.
- */
-#define ETH_P_Symbolics_Private_MIN		0x8107
-
-/** Symbolics Private ethernet protocol type.
- */
-#define ETH_P_Symbolics_Private_MAX		0x8109
-
-/** Hayes Microcomputers ethernet protocol type.
- */
-#define ETH_P_Hayes_Microcomputers		0x8130
-
-/** VG Laboratory Systems ethernet protocol type.
- */
-#define ETH_P_VG_Laboratory_Systems		0x8131
-
-/** Bridge Communications ethernet protocol type.
- */
-#define ETH_P_Bridge_Communications_MIN		0x8132
-
-/** Bridge Communications ethernet protocol type.
- */
-#define ETH_P_Bridge_Communications_MAX		0x8136
-
-/** Novell, Inc. ethernet protocol type.
- */
-#define ETH_P_Novell_Inc_MIN		0x8137
-
-/** Novell, Inc. ethernet protocol type.
- */
-#define ETH_P_Novell_Inc_MAX		0x8138
-
-/** KTI ethernet protocol type.
- */
-#define ETH_P_KTI_MIN		0x8139
-
-/** KTI ethernet protocol type.
- */
-#define ETH_P_KTI_MAX		0x813D
-
-/** Logicraft ethernet protocol type.
- */
-#define ETH_P_Logicraft		0x8148
-
-/** Network Computing Devices ethernet protocol type.
- */
-#define ETH_P_Network_Computing_Devices		0x8149
-
-/** Alpha Micro ethernet protocol type.
- */
-#define ETH_P_Alpha_Micro		0x814A
-
-/** SNMP ethernet protocol type.
- */
-#define ETH_P_SNMP		0x814C
-
-/** BIIN ethernet protocol type.
- */
-#define ETH_P_BIIN		0x814D
-
-/** BIIN ethernet protocol type.
- */
-#define ETH_P_BIIN2		0x814E
-
-/** Technically Elite Concept ethernet protocol type.
- */
-#define ETH_P_Technically_Elite_Concept		0x814F
-
-/** Rational Corp ethernet protocol type.
- */
-#define ETH_P_Rational_Corp		0x8150
-
-/** Qualcomm ethernet protocol type.
- */
-#define ETH_P_Qualcomm_MIN		0x8151
-
-/** Qualcomm ethernet protocol type.
- */
-#define ETH_P_Qualcomm_MAX		0x8153
-
-/** Computer Protocol Pty Ltd ethernet protocol type.
- */
-#define ETH_P_Computer_Protocol_Pty_Ltd_MIN		0x815C
-
-/** Computer Protocol Pty Ltd ethernet protocol type.
- */
-#define ETH_P_Computer_Protocol_Pty_Ltd_MAX		0x815E
-
-/** Charles River Data System ethernet protocol type.
- */
-#define ETH_P_Charles_River_Data_System_MIN		0x8164
-
-/** Charles River Data System ethernet protocol type.
- */
-#define ETH_P_Charles_River_Data_System_MAX		0x8166
-
-/** XTP ethernet protocol type.
- */
-#define ETH_P_XTP		0x817D
-
-/** SGI/Time Warner prop. ethernet protocol type.
- */
-#define ETH_P_SGITime_Warner_prop		0x817E
-
-/** HIPPI-FP encapsulation ethernet protocol type.
- */
-#define ETH_P_HIPPI_FP_encapsulation		0x8180
-
-/** STP, HIPPI-ST ethernet protocol type.
- */
-#define ETH_P_STP_HIPPI_ST		0x8181
-
-/** Reserved for HIPPI-6400 ethernet protocol type.
- */
-#define ETH_P_Reserved_for_HIPPI_6400		0x8182
-
-/** Reserved for HIPPI-6400 ethernet protocol type.
- */
-#define ETH_P_Reserved_for_HIPPI_64002		0x8183
-
-/** Silicon Graphics prop. ethernet protocol type.
- */
-#define ETH_P_Silicon_Graphics_prop_MIN		0x8184
-
-/** Silicon Graphics prop. ethernet protocol type.
- */
-#define ETH_P_Silicon_Graphics_prop_MAX		0x818C
-
-/** Motorola Computer ethernet protocol type.
- */
-#define ETH_P_Motorola_Computer		0x818D
-
-/** Qualcomm ethernet protocol type.
- */
-#define ETH_P_Qualcomm_MIN2		0x819A
-
-/** Qualcomm ethernet protocol type.
- */
-#define ETH_P_Qualcomm_MAX2		0x81A3
-
-/** ARAI Bunkichi ethernet protocol type.
- */
-#define ETH_P_ARAI_Bunkichi		0x81A4
-
-/** RAD Network Devices ethernet protocol type.
- */
-#define ETH_P_RAD_Network_Devices_MIN		0x81A5
-
-/** RAD Network Devices ethernet protocol type.
- */
-#define ETH_P_RAD_Network_Devices_MAX		0x81AE
-
-/** Xyplex ethernet protocol type.
- */
-#define ETH_P_Xyplex_MIN2		0x81B7
-
-/** Xyplex ethernet protocol type.
- */
-#define ETH_P_Xyplex_MAX2		0x81B9
-
-/** Apricot Computers ethernet protocol type.
- */
-#define ETH_P_Apricot_Computers_MIN		0x81CC
-
-/** Apricot Computers ethernet protocol type.
- */
-#define ETH_P_Apricot_Computers_MAX		0x81D5
-
-/** Artisoft ethernet protocol type.
- */
-#define ETH_P_Artisoft_MIN		0x81D6
-
-/** Artisoft ethernet protocol type.
- */
-#define ETH_P_Artisoft_MAX		0x81DD
-
-/** Polygon ethernet protocol type.
- */
-#define ETH_P_Polygon_MIN		0x81E6
-
-/** Polygon ethernet protocol type.
- */
-#define ETH_P_Polygon_MAX		0x81EF
-
-/** Comsat Labs ethernet protocol type.
- */
-#define ETH_P_Comsat_Labs_MIN		0x81F0
-
-/** Comsat Labs ethernet protocol type.
- */
-#define ETH_P_Comsat_Labs_MAX		0x81F2
-
-/** SAIC ethernet protocol type.
- */
-#define ETH_P_SAIC_MIN		0x81F3
-
-/** SAIC ethernet protocol type.
- */
-#define ETH_P_SAIC_MAX		0x81F5
-
-/** VG Analytical ethernet protocol type.
- */
-#define ETH_P_VG_Analytical_MIN		0x81F6
-
-/** VG Analytical ethernet protocol type.
- */
-#define ETH_P_VG_Analytical_MAX		0x81F8
-
-/** Quantum Software ethernet protocol type.
- */
-#define ETH_P_Quantum_Software_MIN		0x8203
-
-/** Quantum Software ethernet protocol type.
- */
-#define ETH_P_Quantum_Software_MAX		0x8205
-
-/** Ascom Banking Systems ethernet protocol type.
- */
-#define ETH_P_Ascom_Banking_Systems_MIN		0x8221
-
-/** Ascom Banking Systems ethernet protocol type.
- */
-#define ETH_P_Ascom_Banking_Systems_MAX		0x8222
-
-/** Advanced Encryption Syste ethernet protocol type.
- */
-#define ETH_P_Advanced_Encryption_Syste_MIN		0x823E
-
-/** Advanced Encryption Syste ethernet protocol type.
- */
-#define ETH_P_Advanced_Encryption_Syste_MAX		0x8240
-
-/** Athena Programming ethernet protocol type.
- */
-#define ETH_P_Athena_Programming_MIN		0x827F
-
-/** Athena Programming ethernet protocol type.
- */
-#define ETH_P_Athena_Programming_MAX		0x8282
-
-/** Charles River Data System ethernet protocol type.
- */
-#define ETH_P_Charles_River_Data_System_MIN2		0x8263
-
-/** Charles River Data System ethernet protocol type.
- */
-#define ETH_P_Charles_River_Data_System_MAX2		0x826A
-
-/** Inst Ind Info Tech ethernet protocol type.
- */
-#define ETH_P_Inst_Ind_Info_Tech_MIN		0x829A
-
-/** Inst Ind Info Tech ethernet protocol type.
- */
-#define ETH_P_Inst_Ind_Info_Tech_MAX		0x829B
-
-/** Taurus Controls ethernet protocol type.
- */
-#define ETH_P_Taurus_Controls_MIN		0x829C
-
-/** Taurus Controls ethernet protocol type.
- */
-#define ETH_P_Taurus_Controls_MAX		0x82AB
-
-/** Walker Richer &Quinn ethernet protocol type.
- */
-#define ETH_P_Walker_Richer_Quinn_MIN		0x82AC
-
-/** Walker Richer &Quinn ethernet protocol type.
- */
-#define ETH_P_Walker_Richer_Quinn_MAX		0x8693
-
-/** Idea Courier ethernet protocol type.
- */
-#define ETH_P_Idea_Courier_MIN		0x8694
-
-/** Idea Courier ethernet protocol type.
- */
-#define ETH_P_Idea_Courier_MAX		0x869D
-
-/** Computer Network Tech ethernet protocol type.
- */
-#define ETH_P_Computer_Network_Tech_MIN		0x869E
-
-/** Computer Network Tech ethernet protocol type.
- */
-#define ETH_P_Computer_Network_Tech_MAX		0x86A1
-
-/** Gateway Communications ethernet protocol type.
- */
-#define ETH_P_Gateway_Communications_MIN		0x86A3
-
-/** Gateway Communications ethernet protocol type.
- */
-#define ETH_P_Gateway_Communications_MAX		0x86AC
-
-/** SECTRA ethernet protocol type.
- */
-#define ETH_P_SECTRA		0x86DB
-
-/** Delta Controls ethernet protocol type.
- */
-#define ETH_P_Delta_Controls		0x86DE
-
-/** IPv6 ethernet protocol type.
- */
-#define ETH_P_IPV6		0x86DD
-
-/** ATOMIC ethernet protocol type.
- */
-#define ETH_P_ATOMIC		0x86DF
-
-/** Landis &Gyr Powers ethernet protocol type.
- */
-#define ETH_P_Landis_Gyr_Powers_MIN		0x86E0
-
-/** Landis &Gyr Powers ethernet protocol type.
- */
-#define ETH_P_Landis_Gyr_Powers_MAX		0x86EF
-
-/** Motorola ethernet protocol type.
- */
-#define ETH_P_Motorola_MIN		0x8700
-
-/** Motorola ethernet protocol type.
- */
-#define ETH_P_Motorola_MAX		0x8710
-
-/** TCP/IP Compression ethernet protocol type.
- */
-#define ETH_P_TCPIP_Compression		0x876B
-
-/** IP Autonomous Systems ethernet protocol type.
- */
-#define ETH_P_IP_Autonomous_Systems		0x876C
-
-/** Secure Data ethernet protocol type.
- */
-#define ETH_P_Secure_Data		0x876D
-
-/** PPP ethernet protocol type.
- */
-#define ETH_P_PPP		0x880B
-
-/** MPLS ethernet protocol type.
- */
-#define ETH_P_MPLS_UC		0x8847
-
-/** MPLS with upstream-assigned label ethernet protocol type.
- */
-#define ETH_P_MPLS_MC		0x8848
-
-/** Invisible Software ethernet protocol type.
- */
-#define ETH_P_Invisible_Software_MIN		0x8A96
-
-/** Invisible Software ethernet protocol type.
- */
-#define ETH_P_Invisible_Software_MAX		0x8A97
-
-/** PPPoE Discovery Stage ethernet protocol type.
- */
-#define ETH_P_PPP_DISC		0x8863
-
-/** PPPoE Session Stage ethernet protocol type.
- */
-#define ETH_P_PPP_SES		0x8864
-
-/** Loopback ethernet protocol type.
- */
-#define ETH_P_Loopback		0x9000
-
-/** Com(Bridge) XNS Sys Mgmt ethernet protocol type.
- */
-#define ETH_P_Com_XNS_Sys_Mgmt		0x9001
-
-/** Com(Bridge) TCP-IP Sys ethernet protocol type.
- */
-#define ETH_P_Com_TCP_IP_Sys		0x9002
-
-/** Com(Bridge) loop detect ethernet protocol type.
- */
-#define ETH_P_Com_loop_detect		0x9003
-
-/** BBN VITAL-LanBridge cache ethernet protocol type.
- */
-#define ETH_P_BBN_VITAL_LanBridge_cache		0xFF00
-
-/** ISC Bunker Ramo ethernet protocol type.
- */
-#define ETH_P_ISC_Bunker_Ramo_MIN		0xFF00
-
-/** ISC Bunker Ramo ethernet protocol type.
- */
-#define ETH_P_ISC_Bunker_Ramo_MAX		0xFF0F
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/hardware.h
===================================================================
--- uspace/srv/net/include/hardware.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,195 +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 net_nil
- *  @{
- */
-
-/** @file
- *  Hardware types according to the on-line IANA - Address Resolution Protocol (ARP) Parameters - <http://www.iana.org/assignments/arp-parameters/arp-parameters.xml>, cited January 14 2009.
- */
-
-#ifndef __NET_HW_TYPES_H__
-#define __NET_HW_TYPES_H__
-
-#include <sys/types.h>
-
-/** Network interface layer type type definition.
- */
-typedef uint8_t	hw_type_t;
-
-/** @name Network interface layer types definitions
- */
-/*@{*/
-
-/** Ethernet (10Mb) hardware type.
- */
-#define HW_ETHER		1
-
-/** Experimental Ethernet (3Mb) hardware type.
- */
-#define HW_EETHER		2
-
-/** Amateur Radio AX.25 hardware type.
- */
-#define HW_AX25		3
-
-/** Proteon ProNET Token Ring hardware type.
- */
-#define HW_PRONET		4
-
-/** Chaos hardware type.
- */
-#define HW_CHAOS		5
-
-/** IEEE 802 Networks hardware type.
- */
-#define HW_IEEE802		6
-
-/** ARCNET hardware type.
- */
-#define HW_ARCNET		7
-
-/** Hyperchannel hardware type.
- */
-#define HW_Hyperchannel		8
-
-/** Lanstar hardware type.
- */
-#define HW_Lanstar		9
-
-/** Autonet Short Address hardware type.
- */
-#define HW_ASA		10
-
-/** LocalTalk hardware type.
- */
-#define HW_LocalTalk		11
-
-/** LocalNet (IBM PCNet or SYTEK LocalNET) hardware type.
- */
-#define HW_LocalNet		12
-
-/** Ultra link hardware type.
- */
-#define HW_Ultra_link		13
-
-/** SMDS hardware type.
- */
-#define HW_SMDS		14
-
-/** Frame Relay DLCI hardware type.
- */
-#define HW_DLCI		15
-
-/** Asynchronous Transmission Mode (ATM) hardware type.
- */
-#define HW_ATM		16
-
-/** HDLC hardware type.
- */
-#define HW_HDLC		17
-
-/** Fibre Channel hardware type.
- */
-#define HW_Fibre_Channel		18
-
-/** Asynchronous Transmission Mode (ATM) hardware type.
- */
-#define HW_ATM2		19
-
-/** Serial Line hardware type.
- */
-#define HW_Serial_Line		20
-
-/** Asynchronous Transmission Mode (ATM) hardware type.
- */
-#define HW_ATM3		21
-
-/** MIL-STD-188-220 hardware type.
- */
-#define HW_MIL_STD_188_220		22
-
-/** Metricom hardware type.
- */
-#define HW_METRICOM		23
-
-/** IEEE 1394.1995 hardware type.
- */
-#define HW_IEEE1394		24
-
-/** MAPOS hardware type.
- */
-#define HW_MAPOS		25
-
-/** Twinaxial hardware type.
- */
-#define HW_Twinaxial		26
-
-/** EUI-64 hardware type.
- */
-#define HW_EUI64		27
-
-/** HIPARP hardware type.
- */
-#define HW_HIPARP		28
-
-/** IP and ARP over ISO 7816-3 hardware type.
- */
-#define HW_ISO_7816_3		29
-
-/** ARPSec hardware type.
- */
-#define HW_ARPSec		30
-
-/** IPsec tunnel hardware type.
- */
-#define HW_IPsec_tunnel		31
-
-/** InfiniBand (TM) hardware type.
- */
-#define HW_INFINIBAND		32
-
-/** TIA-102 Project 25 Common Air Interface (CAI) hardware type.
- */
-#define HW_CAI		33
-
-/** Wiegand Interface hardware type.
- */
-#define HW_Wiegand		34
-
-/** Pure IP hardware type.
- */
-#define HW_Pure_IP		35
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/icmp_api.h
===================================================================
--- uspace/srv/net/include/icmp_api.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,88 +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 icmp
- *  @{
- */
-
-/** @file
- *  ICMP module application interface.
- */
-
-#ifndef __NET_ICMP_API_H__
-#define __NET_ICMP_API_H__
-
-#include <sys/types.h>
-
-#include "device.h"
-
-#include "../structures/measured_strings.h"
-#include "../structures/packet/packet.h"
-
-#include "inet.h"
-#include "ip_codes.h"
-#include "socket_codes.h"
-
-#include "icmp_codes.h"
-#include "icmp_common.h"
-
-/** Miliseconds type definition.
- */
-typedef size_t	mseconds_t;
-
-/** @name ICMP module application interface
- *  This interface is used by other application modules.
- */
-/*@{*/
-
-/** Requests an echo message.
- *  Sends a packet with specified parameters to the target host and waits for the reply upto the given timeout.
- *  Blocks the caller until the reply or the timeout occurres.
- *  @param[in] icmp_phone The ICMP module phone used for (semi)remote calls.
- *  @param[in] size The message data length in bytes.
- *  @param[in] timeout The timeout in miliseconds.
- *  @param[in] ttl The time to live.
- *  @param[in] tos The type of service.
- *  @param[in] dont_fragment The value indicating whether the datagram must not be fragmented. Is used as a MTU discovery.
- *  @param[in] addr The target host address.
- *  @param[in] addrlen The torget host address length.
- *  @returns ICMP_ECHO on success.
- *  @returns ETIMEOUT if the reply has not arrived before the timeout.
- *  @returns ICMP type of the received error notification. 
- *  @returns EINVAL if the addrlen parameter is less or equal to zero (<=0).
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns EPARTY if there was an internal error.
- */
-int icmp_echo_msg(int icmp_phone, size_t size, mseconds_t timeout, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, const struct sockaddr * addr, socklen_t addrlen);
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/icmp_client.h
===================================================================
--- uspace/srv/net/include/icmp_client.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,63 +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 icmp
- *  @{
- */
-
-/** @file
- *  ICMP client interface.
- */
-
-#ifndef __NET_ICMP_CLIENT_H__
-#define __NET_ICMP_CLIENT_H__
-
-#include "icmp_codes.h"
-#include "../structures/packet/packet.h"
-
-/** Processes the received packet prefixed with an ICMP header.
- *  @param[in] packet The received packet.
- *  @param[out] type The ICMP header type.
- *  @param[out] code The ICMP header code.
- *  @param[out] pointer The ICMP header pointer.
- *  @param[out] mtu The ICMP header MTU.
- *  @returns The ICMP header length.
- *  @returns Zero (0) if the packet contains no data.
- */
-int icmp_client_process_packet(packet_t packet, icmp_type_t * type, icmp_code_t * code, icmp_param_t * pointer, icmp_param_t * mtu);
-
-/** Returns the ICMP header length.
- *  @param[in] packet The packet.
- *  @returns The ICMP header length in bytes.
- */
-size_t icmp_client_header_length(packet_t packet);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/icmp_codes.h
===================================================================
--- uspace/srv/net/include/icmp_codes.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,347 +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 icmp
- *  @{
- */
-
-/** @file
- *  ICMP types and codes according to the on-line IANA - ICMP Type Numbers - <http://http://www.iana.org/assignments/icmp-parameters>, cited September 14 2009.
- */
-
-#ifndef __NET_ICMP_CODES_H__
-#define __NET_ICMP_CODES_H__
-
-/** ICMP type type definition.
- */
-typedef uint8_t	icmp_type_t;
-
-/** ICMP code type definition.
- */
-typedef uint8_t	icmp_code_t;
-
-/** ICMP parameter type definition.
- */
-typedef uint16_t	icmp_param_t;
-
-/** @name ICMP types definitions
- */
-/*@{*/
-
-/** Echo Reply.
- */
-#define ICMP_ECHOREPLY		0
-
-/** Destination Unreachable.
- */
-#define ICMP_DEST_UNREACH	3
-
-/** Source Quench.
- */
-#define ICMP_SOURCE_QUENCH	4
-
-/** Redirect.
- */
-#define ICMP_REDIRECT		5
-
-/** Alternate Host Address.
- */
-#define ICMP_ALTERNATE_ADDR	6
-
-/** Echo Request.
- */
-#define ICMP_ECHO			8
-
-/** Router Advertisement.
- */
-#define ICMP_ROUTER_ADV		9
-
-/** Router solicitation.
- */
-#define ICMP_ROUTER_SOL		10
-
-/** Time Exceeded.
- */
-#define ICMP_TIME_EXCEEDED	11
-
-/** Parameter Problem.
- */
-#define ICMP_PARAMETERPROB	12
-
-/** Timestamp Request.
- */
-#define ICMP_TIMESTAMP		13
-
-/** Timestamp Reply.
- */
-#define ICMP_TIMESTAMPREPLY	14
-
-/** Information Request.
- */
-#define ICMP_INFO_REQUEST	15
-
-/** Information Reply.
- */
-#define ICMP_INFO_REPLY		16
-
-/** Address Mask Request.
- */
-#define ICMP_ADDRESS		17
-
-/** Address Mask Reply.
- */
-#define ICMP_ADDRESSREPLY	18
-
-/** Traceroute.
- */
-#define ICMP_TRACEROUTE		30
-
-/** Datagram Conversion Error.
- */
-#define ICMP_CONVERSION_ERROR	31
-
-/** Mobile Host Redirect.
- */
-#define ICMP_REDIRECT_MOBILE	32
-
-/** IPv6 Where-Are-You.
- */
-#define ICMP_IPV6_WHERE_ARE_YOU	33
-
-/** IPv6 I-Am-Here.
- */
-#define ICMP_IPV6_I_AM_HERE	34
-
-/** Mobile Registration Request.
- */
-#define ICMP_MOBILE_REQUEST	35
-
-/** Mobile Registration Reply.
- */
-#define ICMP_MOBILE_REPLY	36
-
-/** Domain name request.
- */
-#define ICMP_DN_REQUEST		37
-
-/** Domain name reply.
- */
-#define ICMP_DN_REPLY		38
-
-/** SKIP.
- */
-#define ICMP_SKIP			39
-
-/** Photuris.
- */
-#define ICMP_PHOTURIS		40
-
-/*@}*/
-
-/** @name ICMP_DEST_UNREACH codes definitions
- */
-/*@{*/
-
-/** Network Unreachable.
- */
-#define ICMP_NET_UNREACH	0
-
-/** Host Unreachable.
- */
-#define ICMP_HOST_UNREACH	1
-
-/** Protocol Unreachable.
- */
-#define ICMP_PROT_UNREACH	2
-
-/** Port Unreachable.
- */
-#define ICMP_PORT_UNREACH	3
-
-/** Fragmentation needed but the Do Not Fragment bit was set.
- */
-#define ICMP_FRAG_NEEDED	4
-
-/** Source Route failed.
- */
-#define ICMP_SR_FAILED		5
-
-/** Destination network unknown.
- */
-#define ICMP_NET_UNKNOWN	6
-
-/** Destination host unknown.
- */
-#define ICMP_HOST_UNKNOWN	7
-
-/** Source host isolated (obsolete).
- */
-#define ICMP_HOST_ISOLATED	8
-
-/** Destination network administratively prohibited.
- */
-#define ICMP_NET_ANO		9
-
-/** Destination host administratively prohibited.
- */
-#define ICMP_HOST_ANO		10
-
-/** Network unreachable for this type of service.
- */
-#define ICMP_NET_UNR_TOS	11
-
-/** Host unreachable for this type of service.
- */
-#define ICMP_HOST_UNR_TOS	12
-
-/** Communication administratively prohibited by filtering.
- */
-#define ICMP_PKT_FILTERED	13
-
-/** Host precedence violation.
- */
-#define ICMP_PREC_VIOLATION	14
-
-/** Precedence cutoff in effect.
- */
-#define ICMP_PREC_CUTOFF	15
-
-/*@}*/
-
-/** @name ICMP_REDIRECT codes definitions
- */
-/*@{*/
-
-/** Network redirect (or subnet).
- */
-#define ICMP_REDIR_NET		0
-
-/** Host redirect.
- */
-#define ICMP_REDIR_HOST		1
-
-/** Network redirect for this type of service.
- */
-#define ICMP_REDIR_NETTOS	2
-
-/** Host redirect for this type of service.
- */
-#define ICMP_REDIR_HOSTTOS	3
-
-/*@}*/
-
-/** @name ICMP_ALTERNATE_ADDRESS codes definitions
- */
-/*@{*/
-
-/** Alternate address for host.
- */
-#define ICMP_ALTERNATE_HOST	0
-
-/*@}*/
-
-/** @name ICMP_ROUTER_ADV codes definitions
- */
-/*@{*/
-
-/** Normal router advertisement.
- */
-#define ICMP_ROUTER_NORMAL	0
-
-/** Does not route common traffic.
- */
-#define ICMP_ROUTER_NO_NORMAL_TRAFFIC	16
-
-/*@}*/
-
-/** @name ICMP_TIME_EXCEEDED codes definitions
- */
-/*@{*/
-
-/** Transit TTL exceeded.
- */
-#define ICMP_EXC_TTL		0
-
-/** Reassembly TTL exceeded.
- */
-#define ICMP_EXC_FRAGTIME	1
-
-/*@}*/
-
-/** @name ICMP_PARAMETERPROB codes definitions
- */
-/*@{*/
-
-/** Pointer indicates the error.
- */
-#define ICMP_PARAM_POINTER	0
-
-/** Missing required option.
- */
-#define ICMP_PARAM_MISSING	1
-
-/** Bad length.
- */
-#define ICMP_PARAM_LENGTH	2
-
-/*@}*/
-
-/** @name ICMP_PHOTURIS codes definitions
- */
-/*@{*/
-
-/** Bad SPI.
- */
-#define ICMP_PHOTURIS_BAD_SPI	0
-
-/** Authentication failed.
- */
-#define ICMP_PHOTURIS_AUTHENTICATION	1
-
-/** Decompression failed.
- */
-#define ICMP_PHOTURIS_DECOMPRESSION		2
-
-/** Decryption failed.
- */
-#define ICMP_PHOTURIS_DECRYPTION	3
-
-/** Need authentication.
- */
-#define ICMP_PHOTURIS_NEED_AUTHENTICATION	4
-
-/** Need authorization.
- */
-#define ICMP_PHOTURIS_NEED_AUTHORIZATION	5
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/icmp_common.h
===================================================================
--- uspace/srv/net/include/icmp_common.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,60 +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 icmp
- *  @{
- */
-
-/** @file
- *  ICMP module common interface.
- */
-
-#ifndef __NET_ICMP_COMMON_H__
-#define __NET_ICMP_COMMON_H__
-
-#include <ipc/services.h>
-
-#include <sys/time.h>
-
-/** Default timeout for incoming connections in microseconds.
- */
-#define ICMP_CONNECT_TIMEOUT	(1 * 1000 * 1000)
-
-/** Connects to the ICMP module.
- *  @param service The ICMP module service. Ignored parameter.
- *  @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0).
- *  @returns The ICMP module phone on success.
- *  @returns The ICMP socket identifier if called by the bundle module.
- *  @returns ETIMEOUT if the connection timeouted.
- */
-int icmp_connect_module(services_t service, suseconds_t timeout);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/icmp_interface.h
===================================================================
--- uspace/srv/net/include/icmp_interface.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,116 +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 icmp
- *  @{
- */
-
-/** @file
- *  ICMP module interface.
- *  The same interface is used for standalone remote modules as well as for bundle modules.
- *  The standalone remote modules have to be compiled with the icmp_remote.c source file.
- *  The bundle modules with the icmp.c source file.
- */
-
-#ifndef __NET_ICMP_INTERFACE_H__
-#define __NET_ICMP_INTERFACE_H__
-
-#include <sys/types.h>
-
-#include "device.h"
-
-#include "../structures/measured_strings.h"
-#include "../structures/packet/packet.h"
-
-#include "inet.h"
-#include "ip_codes.h"
-#include "socket_codes.h"
-
-#include "icmp_codes.h"
-#include "icmp_common.h"
-
-/** @name ICMP module interface
- *  This interface is used by other modules.
- */
-/*@{*/
-
-/** Sends the Destination Unreachable error notification packet.
- *  Beginning of the packet is sent as the notification packet data.
- *  The source and the destination addresses should be set in the original packet.
- *  @param[in] icmp_phone The ICMP module phone used for (semi)remote calls.
- *  @param[in] code The error specific code.
- *  @param[in] mtu The error MTU value.
- *  @param[in] packet The original packet.
- *  @returns EOK on success.
- *  @returns EPERM if the ICMP error notifications are disabled.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int icmp_destination_unreachable_msg(int icmp_phone, icmp_code_t code, icmp_param_t mtu, packet_t packet);
-
-/** Sends the Source Quench error notification packet.
- *  Beginning of the packet is sent as the notification packet data.
- *  The source and the destination addresses should be set in the original packet.
- *  @param[in] icmp_phone The ICMP module phone used for (semi)remote calls.
- *  @param[in] packet The original packet.
- *  @returns EOK on success.
- *  @returns EPERM if the ICMP error notifications are disabled.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int icmp_source_quench_msg(int icmp_phone, packet_t packet);
-
-/** Sends the Time Exceeded error notification packet.
- *  Beginning of the packet is sent as the notification packet data.
- *  The source and the destination addresses should be set in the original packet.
- *  @param[in] icmp_phone The ICMP module phone used for (semi)remote calls.
- *  @param[in] code The error specific code.
- *  @param[in] packet The original packet.
- *  @returns EOK on success.
- *  @returns EPERM if the ICMP error notifications are disabled.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int icmp_time_exceeded_msg(int icmp_phone, icmp_code_t code, packet_t packet);
-
-/** Sends the Parameter Problem error notification packet.
- *  Beginning of the packet is sent as the notification packet data.
- *  The source and the destination addresses should be set in the original packet.
- *  @param[in] icmp_phone The ICMP module phone used for (semi)remote calls.
- *  @param[in] code The error specific code.
- *  @param[in] pointer The problematic parameter offset.
- *  @param[in] packet The original packet.
- *  @returns EOK on success.
- *  @returns EPERM if the ICMP error notifications are disabled.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int icmp_parameter_problem_msg(int icmp_phone, icmp_code_t code, icmp_param_t pointer, packet_t packet);
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/il_interface.h
===================================================================
--- uspace/srv/net/include/il_interface.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,97 +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 net_il
- *  @{
- */
-
-/** @file
- *  Internetwork layer module interface for the underlying network interface layer.
- *  This interface is always called by the standalone remote modules.
- */
-
-#ifndef __NET_IL_INTERFACE_H__
-#define __NET_IL_INTERFACE_H__
-
-#include <async.h>
-
-#include <ipc/services.h>
-
-#include "../messages.h"
-
-#include "../include/device.h"
-
-#include "../structures/packet/packet.h"
-#include "../structures/packet/packet_client.h"
-
-#include "../il/il_messages.h"
-
-/** @name Internetwork layer module interface
- *  This interface is used by other modules.
- */
-/*@{*/
-
-/** Notifies the internetwork layer modules about the device state change.
- *  @param[in] il_phone The internetwork layer module phone used for (semi)remote calls.
- *  @param[in] device_id The device identifier.
- *  @param[in] state The new device state.
- *  @param[in] target The target internetwork module service to be delivered to.
- *  @returns EOK on success.
- */
-static inline int il_device_state_msg(int il_phone, device_id_t device_id, device_state_t state, services_t target){
-	return generic_device_state_msg(il_phone, NET_IL_DEVICE_STATE, device_id, state, target);
-}
-
-/** Notifies the internetwork layer modules about the received packet/s.
- *  @param[in] il_phone The internetwork layer module phone used for (semi)remote calls.
- *  @param[in] device_id The device identifier.
- *  @param[in] packet The received packet or the received packet queue.
- *  @param[in] target The target internetwork module service to be delivered to.
- *  @returns EOK on success.
- */
-inline static int il_received_msg(int il_phone, device_id_t device_id, packet_t packet, services_t target){
-	return generic_received_msg(il_phone, NET_IL_RECEIVED, device_id, packet_get_id(packet), target, 0);
-}
-
-/** Notifies the internetwork layer modules about the mtu change.
- *  @param[in] il_phone The internetwork layer module phone used for (semi)remote calls.
- *  @param[in] device_id The device identifier.
- *  @param[in] mtu The new mtu value.
- *  @param[in] target The target internetwork module service to be delivered to.
- *  @returns EOK on success.
- */
-inline static int il_mtu_changed_msg(int il_phone, device_id_t device_id, size_t mtu, services_t target){
-	return generic_device_state_msg(il_phone, NET_IL_MTU_CHANGED, device_id, (int) mtu, target);
-}
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/in.h
===================================================================
--- uspace/srv/net/include/in.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,89 +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 net
- *  @{
- */
-
-/** @file
- *  INET family common definitions.
- */
-
-#ifndef __NET_IN_H__
-#define __NET_IN_H__
-
-#include <sys/types.h>
-
-#include "ip_protocols.h"
-#include "inet.h"
-
-/** INET string address maximum length.
- */
-#define INET_ADDRSTRLEN		(4 * 3 + 3 + 1)
-
-/** Type definition of the INET address.
- *  @see in_addr
- */
-typedef struct in_addr		in_addr_t;
-
-/** Type definition of the INET socket address.
- *  @see sockaddr_in
- */
-typedef struct sockaddr_in	sockaddr_in_t;
-
-/** INET address.
- */
-struct in_addr{
-	/** 4 byte IP address.
-	 */
-	uint32_t s_addr;
-};
-
-/** INET socket address.
- *  @see sockaddr
- */
-struct sockaddr_in{
-	/** Address family.
-	 *  Should be AF_INET.
-	 */
-	uint16_t sin_family;
-	/** Port number.
-	 */
-	uint16_t sin_port;
-	/** Internet address.
-	 */
-	struct in_addr sin_addr;
-	/** Padding to meet the sockaddr size.
-	 */
-	uint8_t sin_zero[8];
-};
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/in6.h
===================================================================
--- uspace/srv/net/include/in6.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,92 +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 net
- *  @{
- */
-
-/** @file
- *  INET6 family common definitions.
- */
-
-#ifndef __NET_IN6_H__
-#define __NET_IN6_H__
-
-#include <sys/types.h>
-
-#include "ip_protocols.h"
-#include "inet.h"
-
-/** INET6 string address maximum length.
- */
-#define INET6_ADDRSTRLEN	(8 * 4 + 7 + 1)
-
-/** Type definition of the INET6 address.
- *  @see in6_addr
- */
-typedef struct in6_addr	in6_addr_t;
-
-/** Type definition of the INET6 socket address.
- *  @see sockaddr_in6
- */
-typedef struct sockaddr_in6	sockaddr_in6_t;
-
-/** INET6 address.
- */
-struct in6_addr{
-	/** 16 byte IPv6 address.
-	 */
-	unsigned char s6_addr[16];
-};
-
-/** INET6 socket address.
- *  @see sockaddr
- */
-struct sockaddr_in6{
-	/** Address family.
-	 *  Should be AF_INET6.
-	 */
-	uint16_t sin6_family;
-	/** Port number.
-	 */
-	uint16_t sin6_port;
-	/** IPv6 flow information.
-	 */
-	uint32_t sin6_flowinfo;
-	/** IPv6 address.
-	 */
-	struct in6_addr sin6_addr;
-	/** Scope identifier.
-	 */
-	uint32_t sin6_scope_id;
-};
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/inet.h
===================================================================
--- uspace/srv/net/include/inet.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,115 +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 net
- *  @{
- */
-
-/** @file
- *  Internet common definitions.
- */
-
-#ifndef __NET_INET_H__
-#define __NET_INET_H__
-
-#include <sys/types.h>
-
-#include "byteorder.h"
-
-/** Type definition of the socket address.
- *  @see sockaddr
- */
-typedef struct sockaddr		sockaddr_t;
-
-/** Type definition of the address information.
- *  @see addrinfo
- */
-typedef struct addrinfo		addrinfo_t;
-
-/** Prints the address into the character buffer.
- *  @param[in] family The address family.
- *  @param[in] data The address data.
- *  @param[out] address The character buffer to be filled.
- *  @param[in] length The buffer length.
- *  @returns EOK on success.
- *  @returns EINVAL if the data or address parameter is NULL.
- *  @returns ENOMEM if the character buffer is not long enough.
- *  @returns ENOTSUP if the address family is not supported.
- */
-int inet_ntop(uint16_t family, const uint8_t * data, char * address, size_t length);
-
-/** Parses the character string into the address.
- *  If the string is shorter than the full address, zero bytes are added.
- *  @param[in] family The address family.
- *  @param[in] address The character buffer to be parsed.
- *  @param[out] data The address data to be filled.
- *  @returns EOK on success.
- *  @returns EINVAL if the data parameter is NULL.
- *  @returns ENOENT if the address parameter is NULL.
- *  @returns ENOTSUP if the address family is not supported.
- */
-int inet_pton(uint16_t family, const char * address, uint8_t * data);
-
-/** Socket address.
- */
-struct sockaddr{
-	/** Address family.
-	 *  @see socket.h
-	 */
-	uint16_t sa_family;
-	/** 14 byte protocol address.
-	 */
-	uint8_t sa_data[14];
-};
-
-// TODO define address information
-// /** Address information.
-// * \todo
-// */
-//struct addrinfo{
-//	int				ai_flags;		// AI_PASSIVE, AI_CANONNAME, etc.
-//	uint16_t		ai_family;		// AF_INET, AF_INET6, AF_UNSPEC
-//	int				ai_socktype;	// SOCK_STREAM, SOCK_DGRAM
-//	int				ai_protocol;	// use 0 for "any"
-//	size_t			ai_addrlen;		// size of ai_addr in bytes
-//	struct sockaddr *	ai_addr;	// struct sockaddr_in or _in6
-//	char *			ai_canonname;	// full canonical hostname
-//	struct addrinfo *	ai_next;	// linked list, next node
-//};
-
-/*int getaddrinfo(const char *node, // e.g. "www.example.com" or IP
-const char *service, // e.g. "http" or port number
-const struct addrinfo *hints,
-struct addrinfo **res);
-getnameinfo
-*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/ip_client.h
===================================================================
--- uspace/srv/net/include/ip_client.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,117 +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 ip
- *  @{
- */
-
-/** @file
- *  IP client interface.
- */
-
-#ifndef __NET_IP_CLIENT_H__
-#define __NET_IP_CLIENT_H__
-
-#include <sys/types.h>
-
-#include "../structures/packet/packet.h"
-
-#include "ip_codes.h"
-#include "ip_interface.h"
-#include "socket_codes.h"
-
-/** Prepares the packet to be transfered via IP.
- *  The IP header is prefixed.
- *  @param[in,out] packet The packet to be prepared.
- *  @param[in] protocol The transport protocol.
- *  @param[in] ttl The time to live counter. The IPDEFTTL is set if zero (0).
- *  @param[in] tos The type of service.
- *  @param[in] dont_fragment The value indicating whether fragmentation is disabled.
- *  @param[in] ipopt_length The prefixed IP options length in bytes.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left in the packet.
- */
-int ip_client_prepare_packet(packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length);
-
-/** Processes the received IP packet.
- *  Fills set header fields.
- *  Returns the prefixed IP header length.
- *  @param[in] packet The received packet.
- *  @param[out] protocol The transport protocol. May be NULL if not desired.
- *  @param[out] ttl The time to live counter. May be NULL if not desired.
- *  @param[out] tos The type of service. May be NULL if not desired.
- *  @param[out] dont_fragment The value indicating whether the fragmentation is disabled. May be NULL if not desired.
- *  @param[out] ipopt_length The IP options length in bytes. May be NULL if not desired.
- *  @returns The prefixed IP header length in bytes on success.
- *  @returns ENOMEM if the packet is too short to contain the IP header.
- */
-int ip_client_process_packet(packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length);
-
-/** Returns the IP header length.
- *  @param[in] packet The packet.
- *  @returns The IP header length in bytes.
- *  @returns Zero (0) if there is no IP header.
- */
-size_t ip_client_header_length(packet_t packet);
-
-/** Updates the IPv4 pseudo header data length field.
- *  @param[in,out] header The IPv4 pseudo header to be updated.
- *  @param[in] headerlen The length of the IP pseudo header in bytes.
- *  @param[in] data_length The data length to be set.
- *  @returns EOK on success.
- *  @returns EBADMEM if the header parameter is NULL.
- *  @returns EINVAL if the headerlen parameter is not IPv4 pseudo header length.
- */
-int ip_client_set_pseudo_header_data_length(ip_pseudo_header_ref header, size_t headerlen, size_t data_length);
-
-/** Constructs the IPv4 pseudo header.
- *  @param[in] protocol The transport protocol.
- *  @param[in] src The source address.
- *  @param[in] srclen The source address length.
- *  @param[in] dest The destination address.
- *  @param[in] destlen The destination address length.
- *  @param[in] data_length The data length to be set.
- *  @param[out] header The constructed IPv4 pseudo header.
- *  @param[out] headerlen The length of the IP pseudo header in bytes.
- *  @returns EOK on success.
- *  @returns EBADMEM if the header and/or the headerlen parameter is NULL.
- *  @returns EINVAL if the source address and/or the destination address parameter is NULL.
- *  @returns EINVAL if the source address length is less than struct sockaddr length.
- *  @returns EINVAL if the source address length differs from the destination address length.
- *  @returns EINVAL if the source address family differs from the destination family.
- *  @returns EAFNOSUPPORT if the address family is not supported.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int ip_client_get_pseudo_header(ip_protocol_t protocol, struct sockaddr * src, socklen_t srclen, struct sockaddr * dest, socklen_t destlen, size_t data_length, ip_pseudo_header_ref * header, size_t * headerlen);
-
-// TODO ipopt manipulation
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/ip_codes.h
===================================================================
--- uspace/srv/net/include/ip_codes.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,374 +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 ip
- *  @{
- */
-
-/** @file
- *  IP codes and definitions.
- */
-
-#ifndef __NET_IP_CODES_H__
-#define __NET_IP_CODES_H__
-
-#include <sys/types.h>
-
-/** IP time to live counter type definition.
- */
-typedef uint8_t	ip_ttl_t;
-
-/** IP type of service type definition.
- */
-typedef uint8_t	ip_tos_t;
-
-/** IP transport protocol type definition.
- */
-typedef uint8_t	ip_protocol_t;
-
-/** Default IPVERSION.
- */
-#define IPVERSION	4
-
-/** Maximum time to live counter.
- */
-#define MAXTTL		255
-
-/** Default time to live counter.
- */
-#define IPDEFTTL	64
-
-/** @name IP type of service definitions
- */
-/*@{*/
-
-/** IP TOS mask.
- */
-#define IPTOS_TOS_MASK				0x1E
-
-/** Precedence shift.
- */
-#define IPTOS_PRECEDENCE_SHIFT		5
-
-/** Delay shift.
- */
-#define IPTOS_DELAY_SHIFT			4
-
-/** Throughput shift.
- */
-#define IPTOS_THROUGHPUT_SHIFT		3
-
-/** Reliability shift.
- */
-#define IPTOS_RELIABILITY_SHIFT		2
-
-/** Cost shift.
- */
-#define IPTOS_COST_SHIFT			1
-
-/** Normal delay.
- */
-#define IPTOS_NORMALDELAY			(0x0 << IPTOS_DELAY_SHIFT)
-
-/** Low delay.
- */
-#define IPTOS_LOWDELAY				(0x1 << IPTOS_DELAY_SHIFT)
-
-/** Normal throughput.
- */
-#define IPTOS_NORMALTHROUGHPUT		(0x0 << IPTOS_THROUGHPUT_SHIFT)
-
-/** Throughput.
- */
-#define IPTOS_THROUGHPUT			(0x1 << IPTOS_THROUGHPUT_SHIFT)
-
-/** Normal reliability.
- */
-#define IPTOS_NORMALRELIABILITY		(0x0 << IPTOS_RELIABILITY_SHIFT)
-
-/** Reliability.
- */
-#define IPTOS_RELIABILITY			(0x1 << IPTOS_RELIABILITY_SHIFT)
-
-/** Normal cost.
- */
-#define IPTOS_NORMALCOST			(0x0 << IPTOS_COST_SHIFT)
-
-/** Minimum cost.
- */
-#define IPTOS_MICNCOST				(0x1 << IPTOS_COST_SHIFT)
-
-/*@}*/
-
-/** @name IP TOS precedence definitions
- */
-/*@{*/
-
-
-/** Precedence mask.
- */
-#define IPTOS_PREC_MASK				0xE0
-
-/** Routine precedence.
- */
-#define IPTOS_PREC_ROUTINE			(0x0 << IPTOS_PRECEDENCE_SHIFT)
-
-/** Priority precedence.
- */
-#define IPTOS_PREC_PRIORITY			(0x1 << IPTOS_PRECEDENCE_SHIFT)
-
-/** Immediate precedence.
- */
-#define IPTOS_PREC_IMMEDIATE		(0x2 << IPTOS_PRECEDENCE_SHIFT)
-
-/** Flash precedence.
- */
-#define IPTOS_PREC_FLASH			(0x3 << IPTOS_PRECEDENCE_SHIFT)
-
-/** Flash override precedence.
- */
-#define IPTOS_PREC_FLASHOVERRIDE	(0x4 << IPTOS_PRECEDENCE_SHIFT)
-
-/** Critical precedence.
- */
-#define IPTOS_PREC_CRITIC_ECP		(0x5 << IPTOS_PRECEDENCE_SHIFT)
-
-/** Inter-network control precedence.
- */
-#define IPTOS_PREC_INTERNETCONTROL	(0x6 << IPTOS_PRECEDENCE_SHIFT)
-
-/** Network control precedence.
- */
-#define IPTOS_PREC_NETCONTROL		(0x7 << IPTOS_PRECEDENCE_SHIFT)
-
-/*@}*/
-
-/** @name IP options definitions
- */
-/*@{*/
-
-/** Copy shift.
- */
-#define IPOPT_COPY_SHIFT			7
-
-/** Class shift.
- */
-#define IPOPT_CLASS_SHIFT			5
-
-/** Number shift.
- */
-#define IPOPT_NUMBER_SHIFT			0
-
-/** Class mask.
- */
-#define IPOPT_CLASS_MASK			0x60
-
-/** Number mask.
- */
-#define IPOPT_NUMBER_MASK			0x1F
-
-/** Copy flag.
- */
-#define IPOPT_COPY					(1 << IPOPT_COPY_SHIFT)
-
-/** Returns IP option type.
- *  @param[in] copy The value indication whether the IP option should be copied.
- *  @param[in] class The IP option class.
- *  @param[in] number The IP option number.
- */
-#define IPOPT_TYPE(copy, class, number)	(((copy) &IPOPT_COPY) | ((class) &IPOPT_CLASS_MASK) | ((number << IPOPT_NUMBER_SHIFT) &IPOPT_NUMBER_MASK))
-
-/** Returns a value indicating whether the IP option should be copied.
- *  @param[in] o The IP option.
- */
-#define	IPOPT_COPIED(o)			((o) &IPOPT_COPY)
-
-/** Returns an IP option class.
- *  @param[in] o The IP option.
- */
-#define	IPOPT_CLASS(o)			((o) &IPOPT_CLASS_MASK)
-
-/** Returns an IP option number.
- *  @param[in] o The IP option.
- */
-#define	IPOPT_NUMBER(o)			((o) &IPOPT_NUMBER_MASK)
-
-/*@}*/
-
-/** @name IP option class definitions
- */
-/*@{*/
-
-/** Control class.
- */
-#define	IPOPT_CONTROL				(0 << IPOPT_CLASS_SHIFT)
-
-/** Reserved class 1.
- */
-#define	IPOPT_RESERVED1				(1 << IPOPT_CLASS_SHIFT)
-
-/** Measurement class.
- */
-#define	IPOPT_MEASUREMENT			(2 << IPOPT_CLASS_SHIFT)
-
-/** Reserved class 2.
- */
-#define	IPOPT_RESERVED2				(3 << IPOPT_CLASS_SHIFT)
-
-/*@}*/
-
-/** @name IP option type definitions
- */
-/*@{*/
-
-/** End of list.
- */
-//#define IPOPT_END_OF_LIST			0x0
-#define IPOPT_END					IPOPT_TYPE(0, IPOPT_CONTROL, 0)
-
-/** No operation.
- */
-//#define IPOPT_NO_OPERATION		0x1
-#define IPOPT_NOOP					IPOPT_TYPE(0, IPOPT_CONTROL, 1)
-
-/** Security.
- */
-//#define IPOPT_SECURITY			0x82
-#define IPOPT_SEC					IPOPT_TYPE(IPOPT_COPY, IPOPT_CONTROL, 2)
-
-/** Loose source.
- */
-//#define IPOPT_LOOSE_SOURCE		0x83
-#define IPOPT_LSRR					IPOPT_TYPE(IPOPT_COPY, IPOPT_CONTROL, 3)
-
-/** Strict route.
- */
-//#define IPOPT_STRICT_SOURCE		0x89
-#define IPOPT_SSRR					IPOPT_TYPE(IPOPT_COPY, IPOPT_CONTROL, 9)
-
-/** Record route.
- */
-//#define IPOPT_RECORD_ROUTE		0x07
-#define IPOPT_RR					IPOPT_TYPE(IPOPT_COPY, IPOPT_CONTROL, 7)
-
-/** Stream identifier.
- */
-//#define IPOPT_STREAM_IDENTIFIER	0x88
-#define IPOPT_SID					IPOPT_TYPE(IPOPT_COPY, IPOPT_CONTROL, 8)
-
-/** Stream identifier length.
- */
-#define IPOPT_SID_LENGTH			4
-
-/** Internet timestamp.
- */
-//#define IPOPT_INTERNET_TIMESTAMP	0x44
-#define IPOPT_TIMESTAMP				IPOPT_TYPE(IPOPT_COPY, IPOPT_MEASUREMENT, 4)
-
-/** Commercial IP security option.
- */
-#define IPOPT_CIPSO					IPOPT_TYPE(IPOPT_COPY, IPOPT_CONTROL, 5)
-
-/** No operation variant.
- */
-#define IPOPT_NOP IPOPT_NOOP
-
-/** End of list variant.
- */
-#define IPOPT_EOL IPOPT_END
-
-/** Timestamp variant.
- */
-#define IPOPT_TS  IPOPT_TIMESTAMP
-
-/*@}*/
-
-/** @name IP security option definitions
- */
-/*@{*/
-
-/** Security length.
- */
-#define IPOPT_SEC_LENGTH			11
-
-/** Unclasified.
- */
-#define IPOPT_SEC_UNCLASIFIED		0x0
-
-/** Confidential.
- */
-#define IPOPT_SEC_CONFIDENTIAL		0xF035
-
-/** EFTO.
- */
-#define IPOPT_SEC_EFTO				0x789A
-
-/** MMMM.
- */
-#define IPOPT_SEC_MMMM				0xBC4D
-
-/** PROG.
- */
-#define IPOPT_SEC_PROG				0x5E26
-
-/** Restricted.
- */
-#define IPOPT_SEC_RESTRICTED		0xAF13
-
-/** Secret.
- */
-#define IPOPT_SEC_SECRET			0xD788
-
-/** Top secret.
- */
-#define IPOPT_SEC_TOP_SECRET		0x6BC5
-
-/*@}*/
-
-/** @name IP timestamp option definitions
- */
-/*@{*/
-
-/** Tiemstamp only.
- */
-#define	IPOPT_TS_TSONLY		0
-
-/** Timestamps and addresses.
- */
-#define	IPOPT_TS_TSANDADDR	1
-
-/** Specified modules only.
- */
-#define	IPOPT_TS_PRESPEC	3
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/ip_interface.h
===================================================================
--- uspace/srv/net/include/ip_interface.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,175 +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 ip
- *  @{
- */
-
-/** @file
- *  IP module interface.
- *  The same interface is used for standalone remote modules as well as for bundle modules.
- *  The standalone remote modules have to be compiled with the ip_remote.c source file.
- *  The bundle modules with the ip.c source file.
- */
-
-#ifndef __NET_IP_INTERFACE_H__
-#define __NET_IP_INTERFACE_H__
-
-#include <async.h>
-
-#include <ipc/services.h>
-
-#include "../include/device.h"
-
-#include "../structures/packet/packet.h"
-
-#include "in.h"
-#include "ip_codes.h"
-#include "socket_codes.h"
-
-/** @name IP module interface
- *  This interface is used by other modules.
- */
-/*@{*/
-
-/** Type definition of the internet pseudo header pointer.
- */
-typedef void *		ip_pseudo_header_ref;
-
-/** The transport layer notification function type definition.
- *  Notifies the transport layer modules about the received packet/s.
- *  @param[in] device_id The device identifier.
- *  @param[in] packet The received packet or the received packet queue.
- *  @param[in] receiver The receiving module service.
- *  @param[in] error The packet error reporting service. Prefixes the received packet.
- *  @returns EOK on success.
- */
-typedef int	(*tl_received_msg_t)(device_id_t device_id, packet_t packet, services_t receiver, services_t error);
-
-/** Creates bidirectional connection with the ip module service and registers the message receiver.
- *  @param[in] service The IP module service.
- *  @param[in] protocol The transport layer protocol.
- *  @param[in] me The requesting module service.
- *  @param[in] receiver The message receiver. Used for remote connection.
- *  @param[in] tl_received_msg The message processing function. Used if bundled together.
- *  @returns The phone of the needed service.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the bind_service() function.
- */
-int ip_bind_service(services_t service, int protocol, services_t me, async_client_conn_t receiver, tl_received_msg_t tl_received_msg);
-
-/** Registers the new device.
- *  Registers itself as the ip packet receiver.
- *  If the device uses ARP registers also the new ARP device.
- *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
- *  @param[in] device_id The new device identifier.
- *  @param[in] netif The underlying device network interface layer service.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns EINVAL if the device configuration is invalid.
- *  @returns ENOTSUP if the device uses IPv6.
- *  @returns ENOTSUP if the device uses DHCP.
- *  @returns Other error codes as defined for the net_get_device_conf_req() function.
- *  @returns Other error codes as defined for the arp_device_req() function.
- */
-int ip_device_req(int ip_phone, device_id_t device_id, services_t netif);
-
-/** Sends the packet queue.
- *  The packets may get fragmented if needed.
- *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
- *  @param[in] device_id The device identifier.
- *  @param[in] packet The packet fragments as a~packet queue. All the packets have to have the same destination address.
- *  @param[in] sender The sending module service.
- *  @param[in] error The packet error reporting service. Prefixes the received packet.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the generic_send_msg() function.
- */
-int ip_send_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t sender, services_t error);
-
-/** Connects to the IP module.
- *  @param service The IP module service. Ignored parameter.
- *  @returns The IP module phone on success.
- *  @returns 0 if called by the bundle module.
- */
-int ip_connect_module(services_t service);
-
-/** Adds a route to the device routing table.
- *  The target network is routed using this device.
- *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
- *  @param[in] device_id The device identifier.
- *  @param[in] address The target network address.
- *  @param[in] netmask The target network mask.
- *  @param[in] gateway The target network gateway. Not used if zero.
- */
-int ip_add_route_req(int ip_phone, device_id_t device_id, in_addr_t address, in_addr_t netmask, in_addr_t gateway);
-
-/** Sets the default gateway.
- *  This gateway is used if no other route is found.
- *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
- *  @param[in] device_id The device identifier.
- *  @param[in] gateway The default gateway.
- */
-int ip_set_gateway_req(int ip_phone, device_id_t device_id, in_addr_t gateway);
-
-/** Returns the device packet dimension for sending.
- *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
- *  @param[in] device_id The device identifier.
- *  @param[out] packet_dimension The packet dimension.
- *  @returns EOK on success.
- *  @returns ENOENT if there is no such device.
- *  @returns Other error codes as defined for the generic_packet_size_req() function.
- */
-int ip_packet_size_req(int ip_phone, device_id_t device_id, packet_dimension_ref packet_dimension);
-
-/** Notifies the IP module about the received error notification packet.
- *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
- *  @param[in] device_id The device identifier.
- *  @param[in] packet The received packet or the received packet queue.
- *  @param[in] target The target internetwork module service to be delivered to.
- *  @param[in] error The packet error reporting service. Prefixes the received packet.
- *  @returns EOK on success.
- */
-int ip_received_error_msg(int ip_phone, device_id_t device_id, packet_t packet, services_t target, services_t error);
-
-/** Returns the device identifier and the IP pseudo header based on the destination address.
- *  @param[in] ip_phone The IP module phone used for (semi)remote calls.
- *  @param[in] protocol The transport protocol.
- *  @param[in] destination The destination address.
- *  @param[in] addrlen The destination address length.
- *  @param[out] device_id The device identifier.
- *  @param[out] header The constructed IP pseudo header.
- *  @param[out] headerlen The IP pseudo header length.
- */
-int ip_get_route_req(int ip_phone, ip_protocol_t protocol, const struct sockaddr * destination, socklen_t addrlen, device_id_t * device_id, ip_pseudo_header_ref * header, size_t * headerlen);
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/ip_protocols.h
===================================================================
--- uspace/srv/net/include/ip_protocols.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,619 +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 ip
- *  @{
- */
-
-/** @file
- *  Internet protocol numbers according to the on-line IANA - Assigned Protocol numbers - <http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml>, cited January 14 2009.
- */
-
-#ifndef __NET_IPPROTOCOLS_H__
-#define __NET_IPPROTOCOLS_H__
-
-/** @name IP protocols definitions
- */
-/*@{*/
-
-/** IPv6 Hop-by-Hop Option internet protocol number.
- */
-#define IPPROTO_HOPOPT		0
-
-/** Internet Control Message internet protocol number.
- */
-#define IPPROTO_ICMP		1
-
-/** Internet Group Management internet protocol number.
- */
-#define IPPROTO_IGMP		2
-
-/** Gateway-to-Gateway internet protocol number.
- */
-#define IPPROTO_GGP		3
-
-/** IP in IP (encapsulation) internet protocol number.
- */
-#define IPPROTO_IP		4
-
-/** Stream internet protocol number.
- */
-#define IPPROTO_ST		5
-
-/** Transmission Control internet protocol number.
- */
-#define IPPROTO_TCP		6
-
-/** CBT internet protocol number.
- */
-#define IPPROTO_CBT		7
-
-/** Exterior Gateway Protocol internet protocol number.
- */
-#define IPPROTO_EGP		8
-
-/** any private interior gateway             
-(used by Cisco for their IGRP) internet protocol number.
- */
-#define IPPROTO_IGP		9
-
-/** BBN RCC Monitoring internet protocol number.
- */
-#define IPPROTO_BBN_RCC_MON		10
-
-/** Network Voice Protocol internet protocol number.
- */
-#define IPPROTO_NVP_II		11
-
-/** PUP internet protocol number.
- */
-#define IPPROTO_PUP		12
-
-/** ARGUS internet protocol number.
- */
-#define IPPROTO_ARGUS		13
-
-/** EMCON internet protocol number.
- */
-#define IPPROTO_EMCON		14
-
-/** Cross Net Debugger internet protocol number.
- */
-#define IPPROTO_XNET		15
-
-/** Chaos internet protocol number.
- */
-#define IPPROTO_CHAOS		16
-
-/** User Datagram internet protocol number.
- */
-#define IPPROTO_UDP		17
-
-/** Multiplexing internet protocol number.
- */
-#define IPPROTO_MUX		18
-
-/** DCN Measurement Subsystems internet protocol number.
- */
-#define IPPROTO_DCN_MEAS		19
-
-/** Host Monitoring internet protocol number.
- */
-#define IPPROTO_HMP		20
-
-/** Packet Radio Measurement internet protocol number.
- */
-#define IPPROTO_PRM		21
-
-/** XEROX NS IDP internet protocol number.
- */
-#define IPPROTO_XNS_IDP		22
-
-/** Trunk-1 internet protocol number.
- */
-#define IPPROTO_TRUNK_1		23
-
-/** Trunk-2 internet protocol number.
- */
-#define IPPROTO_TRUNK_2		24
-
-/** Leaf-1 internet protocol number.
- */
-#define IPPROTO_LEAF_1		25
-
-/** Leaf-2 internet protocol number.
- */
-#define IPPROTO_LEAF_2		26
-
-/** Reliable Data Protocol internet protocol number.
- */
-#define IPPROTO_RDP		27
-
-/** Internet Reliable Transaction internet protocol number.
- */
-#define IPPROTO_IRTP		28
-
-/** ISO Transport Protocol Class 4 internet protocol number.
- */
-#define IPPROTO_ISO_TP4		29
-
-/** Bulk Data Transfer Protocol internet protocol number.
- */
-#define IPPROTO_NETBLT		30
-
-/** MFE Network Services Protocol internet protocol number.
- */
-#define IPPROTO_MFE_NSP		31
-
-/** MERIT Internodal Protocol internet protocol number.
- */
-#define IPPROTO_MERIT_INP		32
-
-/** Datagram Congestion Control Protocol internet protocol number.
- */
-#define IPPROTO_DCCP		33
-
-/** Third Party Connect Protocol internet protocol number.
- */
-#define IPPROTO_3PC		34
-
-/** Inter-Domain Policy Routing Protocol internet protocol number.
- */
-#define IPPROTO_IDPR		35
-
-/** XTP internet protocol number.
- */
-#define IPPROTO_XTP		36
-
-/** Datagram Delivery Protocol internet protocol number.
- */
-#define IPPROTO_DDP		37
-
-/** IDPR Control Message Transport Proto internet protocol number.
- */
-#define IPPROTO_IDPR_CMTP		38
-
-/** TP++ Transport Protocol internet protocol number.
- */
-#define IPPROTO_TP		39
-
-/** IL Transport Protocol internet protocol number.
- */
-#define IPPROTO_IL		40
-
-/** Ipv6 internet protocol number.
- */
-#define IPPROTO_IPV6		41
-
-/** Source Demand Routing Protocol internet protocol number.
- */
-#define IPPROTO_SDRP		42
-
-/** Routing Header for IPv6 internet protocol number.
- */
-#define IPPROTO_IPv6_Route		43
-
-/** Fragment Header for IPv6 internet protocol number.
- */
-#define IPPROTO_IPv6_Frag		44
-
-/** Inter-Domain Routing Protocol internet protocol number.
- */
-#define IPPROTO_IDRP		45
-
-/** Reservation Protocol internet protocol number.
- */
-#define IPPROTO_RSVP		46
-
-/** General Routing Encapsulation internet protocol number.
- */
-#define IPPROTO_GRE		47
-
-/** Dynamic Source Routing Protocol internet protocol number.
- */
-#define IPPROTO_DSR		48
-
-/** BNA internet protocol number.
- */
-#define IPPROTO_BNA		49
-
-/** Encap Security Payload internet protocol number.
- */
-#define IPPROTO_ESP		50
-
-/** Authentication Header internet protocol number.
- */
-#define IPPROTO_AH		51
-
-/** Integrated Net Layer Security  TUBA internet protocol number.
- */
-#define IPPROTO_I_NLSP		52
-
-/** IP with Encryption internet protocol number.
- */
-#define IPPROTO_SWIPE		53
-
-/** NBMA Address Resolution Protocol internet protocol number.
- */
-#define IPPROTO_NARP		54
-
-/** IP Mobility internet protocol number.
- */
-#define IPPROTO_MOBILE		55
-
-/** Transport Layer Security Protocol        
-using Kryptonet key management internet protocol number.
- */
-#define IPPROTO_TLSP		56
-
-/** SKIP internet protocol number.
- */
-#define IPPROTO_SKIP		57
-
-/** ICMP for IPv6 internet protocol number.
- */
-#define IPPROTO_IPv6_ICMP		58
-
-/** No Next Header for IPv6 internet protocol number.
- */
-#define IPPROTO_IPv6_NoNxt		59
-
-/** Destination Options for IPv6 internet protocol number.
- */
-#define IPPROTO_IPv6_Opts		60
-
-/** Any host internal protocol internet protocol number.
- */
-#define IPPROTO_AHIP		61
-
-/** CFTP internet protocol number.
- */
-#define IPPROTO_CFTP		62
-
-/** Any local network internet protocol number.
- */
-#define IPPROTO_ALN		63
-
-/** SATNET and Backroom EXPAK internet protocol number.
- */
-#define IPPROTO_SAT_EXPAK		64
-
-/** Kryptolan internet protocol number.
- */
-#define IPPROTO_KRYPTOLAN		65
-
-/** MIT Remote Virtual Disk Protocol internet protocol number.
- */
-#define IPPROTO_RVD		66
-
-/** Internet Pluribus Packet Core internet protocol number.
- */
-#define IPPROTO_IPPC		67
-
-/** Any distributed file system internet protocol number.
- */
-#define IPPROTO_ADFS		68
-
-/** SATNET Monitoring internet protocol number.
- */
-#define IPPROTO_SAT_MON		69
-
-/** VISA Protocol internet protocol number.
- */
-#define IPPROTO_VISA		70
-
-/** Internet Packet Core Utility internet protocol number.
- */
-#define IPPROTO_IPCV		71
-
-/** Computer Protocol Network Executive internet protocol number.
- */
-#define IPPROTO_CPNX		72
-
-/** Computer Protocol Heart Beat internet protocol number.
- */
-#define IPPROTO_CPHB		73
-
-/** Wang Span Network internet protocol number.
- */
-#define IPPROTO_WSN		74
-
-/** Packet Video Protocol internet protocol number.
- */
-#define IPPROTO_PVP		75
-
-/** Backroom SATNET Monitoring internet protocol number.
- */
-#define IPPROTO_BR_SAT_MON		76
-
-/** SUN ND IPPROTOCOL_Temporary internet protocol number.
- */
-#define IPPROTO_SUN_ND		77
-
-/** WIDEBAND Monitoring internet protocol number.
- */
-#define IPPROTO_WB_MON		78
-
-/** WIDEBAND EXPAK internet protocol number.
- */
-#define IPPROTO_WB_EXPAK		79
-
-/** ISO Internet Protocol internet protocol number.
- */
-#define IPPROTO_ISO_IP		80
-
-/** VMTP internet protocol number.
- */
-#define IPPROTO_VMTP		81
-
-/** SECURE-VMTP internet protocol number.
- */
-#define IPPROTO_SECURE_VMTP		82
-
-/** VINES internet protocol number.
- */
-#define IPPROTO_VINES		83
-
-/** TTP internet protocol number.
- */
-#define IPPROTO_TTP		84
-
-/** NSFNET-IGP internet protocol number.
- */
-#define IPPROTO_NSFNET_IGP		85
-
-/** Dissimilar Gateway Protocol internet protocol number.
- */
-#define IPPROTO_DGP		86
-
-/** TCF internet protocol number.
- */
-#define IPPROTO_TCF		87
-
-/** EIGRP internet protocol number.
- */
-#define IPPROTO_EIGRP		88
-
-/** OSPFIGP internet protocol number.
- */
-#define IPPROTO_OSPFIGP		89
-
-/** Sprite RPC Protocol internet protocol number.
- */
-#define IPPROTO_Sprite_RPC		90
-
-/** Locus Address Resolution Protocol internet protocol number.
- */
-#define IPPROTO_LARP		91
-
-/** Multicast Transport Protocol internet protocol number.
- */
-#define IPPROTO_MTP		92
-
-/** AX.25 Frames internet protocol number.
- */
-#define IPPROTO_AX25		93
-
-/** IP-within-IP Encapsulation Protocol internet protocol number.
- */
-#define IPPROTO_IPIP		94
-
-/** Mobile Internetworking Control Pro. internet protocol number.
- */
-#define IPPROTO_MICP		95
-
-/** Semaphore Communications Sec. Pro. internet protocol number.
- */
-#define IPPROTO_SCC_SP		96
-
-/** Ethernet-within-IP Encapsulation internet protocol number.
- */
-#define IPPROTO_ETHERIP		97
-
-/** Encapsulation Header internet protocol number.
- */
-#define IPPROTO_ENCAP		98
-
-/** Any private encryption scheme internet protocol number.
- */
-#define IPPROTO_APES		99
-
-/** GMTP internet protocol number.
- */
-#define IPPROTO_GMTP		100
-
-/** Ipsilon Flow Management Protocol internet protocol number.
- */
-#define IPPROTO_IFMP		101
-
-/** PNNI over IP internet protocol number.
- */
-#define IPPROTO_PNNI		102
-
-/** Protocol Independent Multicast internet protocol number.
- */
-#define IPPROTO_PIM		103
-
-/** ARIS internet protocol number.
- */
-#define IPPROTO_ARIS		104
-
-/** SCPS internet protocol number.
- */
-#define IPPROTO_SCPS		105
-
-/** QNX internet protocol number.
- */
-#define IPPROTO_QNX		106
-
-/** Active Networks internet protocol number.
- */
-#define IPPROTO_AN		107
-
-/** IP Payload Compression Protocol internet protocol number.
- */
-#define IPPROTO_IPComp		108
-
-/** Sitara Networks Protocol internet protocol number.
- */
-#define IPPROTO_SNP		109
-
-/** Compaq Peer Protocol internet protocol number.
- */
-#define IPPROTO_Compaq_Peer		110
-
-/** IPX in IP internet protocol number.
- */
-#define IPPROTO_IPX_in_IP		111
-
-/** Virtual Router Redundancy Protocol internet protocol number.
- */
-#define IPPROTO_VRRP		112
-
-/** PGM Reliable Transport Protocol internet protocol number.
- */
-#define IPPROTO_PGM		113
-
-/** Any 0-hop protocol internet protocol number.
- */
-#define IPPROTO_A0HP		114
-
-/** Layer Two Tunneling Protocol internet protocol number.
- */
-#define IPPROTO_L2TP		115
-
-/** D-II Data Exchange (DDX) internet protocol number.
- */
-#define IPPROTO_DDX		116
-
-/** Interactive Agent Transfer Protocol internet protocol number.
- */
-#define IPPROTO_IATP		117
-
-/** Schedule Transfer Protocol internet protocol number.
- */
-#define IPPROTO_STP		118
-
-/** SpectraLink Radio Protocol internet protocol number.
- */
-#define IPPROTO_SRP		119
-
-/** UTI internet protocol number.
- */
-#define IPPROTO_UTI		120
-
-/** Simple Message Protocol internet protocol number.
- */
-#define IPPROTO_SMP		121
-
-/** SM internet protocol number.
- */
-#define IPPROTO_SM		122
-
-/** Performance Transparency Protocol internet protocol number.
- */
-#define IPPROTO_PTP		123
-
-/** ISIS over IPv4 internet protocol number.
- */
-#define IPPROTO_ISIS		124
-
-/** FIRE internet protocol number.
- */
-#define IPPROTO_FIRE		125
-
-/** Combat Radio Transport Protocol internet protocol number.
- */
-#define IPPROTO_CRTP		126
-
-/** Combat Radio User Datagram internet protocol number.
- */
-#define IPPROTO_CRUDP		127
-
-/** SSCOPMCE internet protocol number.
- */
-#define IPPROTO_SSCOPMCE		128
-
-/** IPLT internet protocol number.
- */
-#define IPPROTO_IPLT		129
-
-/** Secure Packet Shield internet protocol number.
- */
-#define IPPROTO_SPS		130
-
-/** Private IP Encapsulation within IP internet protocol number.
- */
-#define IPPROTO_PIPE		131
-
-/** Stream Control Transmission Protocol internet protocol number.
- */
-#define IPPROTO_SCTP		132
-
-/** Fibre Channel internet protocol number.
- */
-#define IPPROTO_FC		133
-
-/** RSVP-E2E-IGNORE internet protocol number.
- */
-#define IPPROTO_RSVP_E2E_IGNORE		134
-
-/** Mobility Header internet protocol number.
- */
-#define IPPROTO_MH		135
-
-/** UDPLite internet protocol number.
- */
-#define IPPROTO_UDPLITE		136
-
-/** MPLS-in-IP internet protocol number.
- */
-#define IPPROTO_MPLS_in_IP		137
-
-/** MANET Protocols internet protocol number.
- */
-#define IPPROTO_manet		138
-
-/** Host Identity Protocol internet protocol number.
- */
-#define IPPROTO_HIP		139
-
-/** Raw internet protocol number.
- */
-#define IPPROTO_RAW		255
-
-/** Maximum internet protocol number.
- */
-#define IPPROTO_MAX		(IPPROTO_RAW + 1)
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/net_interface.h
===================================================================
--- uspace/srv/net/include/net_interface.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,104 +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 net
- *  @{
- */
-
-/** @file
- *  Networking module interface.
- *  The same interface is used for standalone remote modules as well as for bundle modules.
- *  The standalone remote modules have to be compiled with the net_remote.c source file.
- *  The bundle networking module is compiled with the net_bundle.c source file and the choosen bundle module implementation source files.
- */
-
-#ifndef __NET_NET_INTERFACE_H__
-#define __NET_NET_INTERFACE_H__
-
-#include <ipc/services.h>
-
-#include "../include/device.h"
-
-#include "../structures/measured_strings.h"
-
-/** @name Networking module interface
- *  This interface is used by other modules.
- */
-/*@{*/
-
-/** Returns the device specific configuration.
- *  Returns the global configuration if the device specific is not found.
- *  The configuration names are read and the appropriate settings are set instead.
- *  Call net_free_settings() function to release the returned configuration.
- *  @param[in] net_phone The networking module phone.
- *  @param[in] device_id The device identifier.
- *  @param[in,out] configuration The requested device configuration. The names are read and the appropriate settings are set instead.
- *  @param[in] count The configuration entries count.
- *  @param[in,out] data The configuration and settings data.
- *  @returns EOK on success.
- *  @returns EINVAL if the configuration is NULL.
- *  @returns EINVAL if the count is zero (0).
- *  @returns Other error codes as defined for the generic_translate_req() function.
- */
-int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data);
-
-/** Returns the global configuration.
- *  The configuration names are read and the appropriate settings are set instead.
- *  Call net_free_settings() function to release the returned configuration.
- *  @param[in] net_phone The networking module phone.
- *  @param[in,out] configuration The requested configuration. The names are read and the appropriate settings are set instead.
- *  @param[in] count The configuration entries count.
- *  @param[in,out] data The configuration and settings data.
- *  @returns EOK on success.
- *  @returns EINVAL if the configuration is NULL.
- *  @returns EINVAL if the count is zero (0).
- *  @returns Other error codes as defined for the generic_translate_req() function.
- */
-int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data);
-
-/** Frees the received settings.
- *  @param[in] settings The received settings.
- *  @param[in] data The received settings data.
- *  @see net_get_device_conf_req()
- *  @see net_get_conf_req()
- */
-void net_free_settings(measured_string_ref settings, char * data);
-
-/** Connects to the networking module.
- *  @param service The networking module service. Ignored parameter.
- *  @returns The networking module phone on success.
- *  @returns 0 if called by the bundle module.
- */
-int net_connect_module(services_t service);
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/netdb.h
===================================================================
--- uspace/srv/net/include/netdb.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,109 +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 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: pace/srv/net/include/netif_interface.h
===================================================================
--- uspace/srv/net/include/netif_interface.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,131 +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 netif
- *  @{
- */
-
-/** @file
- *  Network interface module interface.
- *  The same interface is used for standalone remote modules as well as for bundle network interface layer modules.
- *  The standalone remote modules have to be compiled with the netif_remote.c source file.
- *  The bundle network interface layer modules are compiled with the netif_nil_bundle.c source file and the choosen network interface layer implementation source file.
- */
-
-#ifndef __NET_NETIF_INTERFACE_H__
-#define __NET_NETIF_INTERFACE_H__
-
-#include <ipc/services.h>
-
-#include "../messages.h"
-
-#include "../structures/measured_strings.h"
-#include "../structures/packet/packet.h"
-
-#include "device.h"
-
-/** @name Network interface module interface
- *  This interface is used by other modules.
- */
-/*@{*/
-
-/** Returns the device local hardware address.
- *  @param[in] netif_phone The network interface phone.
- *  @param[in] device_id The device identifier.
- *  @param[out] address The device local hardware address.
- *  @param[out] data The address data.
- *  @returns EOK on success.
- *  @returns EBADMEM if the address parameter is NULL.
- *  @returns ENOENT if there no such device.
- *  @returns Other error codes as defined for the netif_get_addr_message() function.
- */
-int netif_get_addr_req(int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data);
-
-/** Probes the existence of the device.
- *  @param[in] netif_phone The network interface phone.
- *  @param[in] device_id The device identifier.
- *  @param[in] irq The device interrupt number.
- *  @param[in] io The device input/output address.
- *  @returns EOK on success.
- *  @returns Other errro codes as defined for the netif_probe_message().
- */
-int netif_probe_req(int netif_phone, device_id_t device_id, int irq, int io);
-
-/** Sends the packet queue.
- *  @param[in] netif_phone The network interface phone.
- *  @param[in] device_id The device identifier.
- *  @param[in] packet The packet queue.
- *  @param[in] sender The sending module service.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the generic_send_msg() function.
- */
-int netif_send_msg(int netif_phone, device_id_t device_id, packet_t packet, services_t sender);
-
-/** Starts the device.
- *  @param[in] netif_phone The network interface phone.
- *  @param[in] device_id The device identifier.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the find_device() function.
- *  @returns Other error codes as defined for the netif_start_message() function.
- */
-int netif_start_req(int netif_phone, device_id_t device_id);
-
-/** Stops the device.
- *  @param[in] netif_phone The network interface phone.
- *  @param[in] device_id The device identifier.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the find_device() function.
- *  @returns Other error codes as defined for the netif_stop_message() function.
- */
-int netif_stop_req(int netif_phone, device_id_t device_id);
-
-/** Returns the device usage statistics.
- *  @param[in] netif_phone The network interface phone.
- *  @param[in] device_id The device identifier.
- *  @param[out] stats The device usage statistics.
- *  @returns EOK on success.
- */
-int netif_stats_req(int netif_phone, device_id_t device_id, device_stats_ref stats);
-
-/** Creates bidirectional connection with the network interface module and registers the message receiver.
- *  @param[in] service The network interface module service.
- *  @param[in] device_id The device identifier.
- *  @param[in] me The requesting module service.
- *  @param[in] receiver The message receiver.
- *  @returns The phone of the needed service.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the bind_service() function.
- */
-int netif_bind_service(services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver);
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/nil_interface.h
===================================================================
--- uspace/srv/net/include/nil_interface.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,160 +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 net_nil
- *  @{
- */
-
-/** @file
- *  Network interface layer module interface.
- *  The same interface is used for standalone remote device modules as well as for bundle device modules.
- *  The standalone remote device modules have to be compiled with the nil_remote.c source file.
- *  The bundle device modules with the appropriate network interface layer source file (eth.c etc.).
- *  The upper layers cannot be bundled with the network interface layer.
- */
-
-#ifndef __NET_NIL_INTERFACE_H__
-#define __NET_NIL_INTERFACE_H__
-
-#include <async.h>
-#include <errno.h>
-
-#include <ipc/ipc.h>
-
-#include "../messages.h"
-
-#include "../structures/measured_strings.h"
-#include "../structures/packet/packet.h"
-
-#include "../nil/nil_messages.h"
-
-#include "device.h"
-
-/** @name Network interface layer module interface
- *  This interface is used by other modules.
- */
-/*@{*/
-
-/** Returns the device local hardware address.
- *  @param[in] nil_phone The network interface layer phone.
- *  @param[in] device_id The device identifier.
- *  @param[out] address The device local hardware address.
- *  @param[out] data The address data.
- *  @returns EOK on success.
- *  @returns EBADMEM if the address parameter and/or the data parameter is NULL.
- *  @returns ENOENT if there no such device.
- *  @returns Other error codes as defined for the generic_get_addr_req() function.
- */
-#define nil_get_addr_req(nil_phone, device_id, address, data)	\
-	generic_get_addr_req(nil_phone, NET_NIL_ADDR, device_id, address, data)
-
-/** Returns the device broadcast hardware address.
- *  @param[in] nil_phone The network interface layer phone.
- *  @param[in] device_id The device identifier.
- *  @param[out] address The device broadcast hardware address.
- *  @param[out] data The address data.
- *  @returns EOK on success.
- *  @returns EBADMEM if the address parameter is NULL.
- *  @returns ENOENT if there no such device.
- *  @returns Other error codes as defined for the generic_get_addr_req() function.
- */
-#define nil_get_broadcast_addr_req(nil_phone, device_id, address, data)	\
-	generic_get_addr_req(nil_phone, NET_NIL_BROADCAST_ADDR, device_id, address, data)
-
-/** Sends the packet queue.
- *  @param[in] nil_phone The network interface layer phone.
- *  @param[in] device_id The device identifier.
- *  @param[in] packet The packet queue.
- *  @param[in] sender The sending module service.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the generic_send_msg() function.
- */
-#define nil_send_msg(nil_phone, device_id, packet, sender)	\
-	generic_send_msg(nil_phone, NET_NIL_SEND, device_id, packet_get_id(packet), sender, 0)
-
-/** Returns the device packet dimension for sending.
- *  @param[in] nil_phone The network interface layer phone.
- *  @param[in] device_id The device identifier.
- *  @param[out] packet_dimension The packet dimensions.
- *  @returns EOK on success.
- *  @returns ENOENT if there is no such device.
- *  @returns Other error codes as defined for the generic_packet_size_req() function.
- */
-#define nil_packet_size_req(nil_phone, device_id, packet_dimension)	\
-	generic_packet_size_req(nil_phone, NET_NIL_PACKET_SPACE, device_id, packet_dimension)
-
-/** Registers new device or updates the MTU of an existing one.
- *  @param[in] nil_phone The network interface layer phone.
- *  @param[in] device_id The new device identifier.
- *  @param[in] mtu The device maximum transmission unit.
- *  @param[in] netif_service The device driver service.
- *  @returns EOK on success.
- *  @returns EEXIST if the device with the different service exists.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns Other error codes as defined for the generic_device_req() function.
- */
-#define nil_device_req(nil_phone, device_id, mtu, netif_service)	\
-	generic_device_req(nil_phone, NET_NIL_DEVICE, device_id, mtu, netif_service)
-
-/** Notifies the network interface layer about the device state change.
- *  @param[in] nil_phone The network interface layer phone.
- *  @param[in] device_id The device identifier.
- *  @param[in] state The new device state.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for each specific module device state function.
- */
-int nil_device_state_msg(int nil_phone, device_id_t device_id, int state);
-
-/** Passes the packet queue to the network interface layer.
- *  Processes and redistributes the received packet queue to the registered upper layers.
- *  @param[in] nil_phone The network interface layer phone.
- *  @param[in] device_id The source device identifier.
- *  @param[in] packet The received packet or the received packet queue.
- *  @param target The target service. Ignored parameter.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for each specific module received function.
- */
-int nil_received_msg(int nil_phone, device_id_t device_id, packet_t packet, services_t target);
-
-/** Creates bidirectional connection with the network interface layer module and registers the message receiver.
- *  @param[in] service The network interface layer module service.
- *  @param[in] device_id The device identifier.
- *  @param[in] me The requesting module service.
- *  @param[in] receiver The message receiver.
- *  @returns The phone of the needed service.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the bind_service() function.
- */
-#define	nil_bind_service(service, device_id, me, receiver)	\
-	bind_service(service, device_id, me, 0, receiver);
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/protocol_map.h
===================================================================
--- uspace/srv/net/include/protocol_map.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,142 +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 net_nil
- *  @{
- */
-
-/** @file
- *  Internetwork layer services - network interface layer service type translation.
- */
-
-#ifndef __NET_PROTOCOL_MAP_H__
-#define __NET_PROTOCOL_MAP_H__
-
-#include <ipc/services.h>
-
-#include "ethernet_lsap.h"
-#include "ethernet_protocols.h"
-#include "hardware.h"
-
-/** Maps the internetwork layer service to the network interface layer type.
- *  @param[in] nil Network interface layer service.
- *  @param[in] il Internetwork layer service.
- *  @returns Network interface layer type of the internetworking layer service.
- *  @returns 0 if mapping is not found.
- */
-static inline eth_type_t protocol_map(services_t nil, services_t il){
-	switch(nil){
-		case SERVICE_ETHERNET:
-		case SERVICE_DP8390:
-			switch(il){
-				case SERVICE_IP:
-					return ETH_P_IP;
-				case SERVICE_ARP:
-					return ETH_P_ARP;
-				default:
-					return 0;
-			}
-		default:
-			return 0;
-	}
-}
-
-/** Maps the network interface layer type to the internetwork layer service.
- *  @param[in] nil Network interface layer service.
- *  @param[in] protocol Network interface layer type.
- *  @returns Internetwork layer service of the network interface layer type.
- *  @returns 0 if mapping is not found.
- */
-static inline services_t protocol_unmap(services_t nil, int protocol){
-	switch(nil){
-		case SERVICE_ETHERNET:
-		case SERVICE_DP8390:
-			switch(protocol){
-				case ETH_P_IP:
-					return SERVICE_IP;
-				case ETH_P_ARP:
-					return SERVICE_ARP;
-				default:
-					return 0;
-			}
-		default:
-			return 0;
-	}
-}
-
-/** Maps the link service access point identifier to the Ethernet protocol identifier.
- *  @param[in] lsap Link service access point identifier.
- *  @returns Ethernet protocol identifier of the link service access point identifier.
- *  @returns ETH_LSAP_NULL if mapping is not found.
- */
-static inline eth_type_t lsap_map(eth_lsap_t lsap){
-	switch(lsap){
-		case ETH_LSAP_IP:
-			return ETH_P_IP;
-		case ETH_LSAP_ARP:
-			return ETH_P_ARP;
-		default:
-			return ETH_LSAP_NULL;
-	}
-}
-
-/** Maps the Ethernet protocol identifier to the link service access point identifier.
- *  @param[in] ethertype Ethernet protocol identifier.
- *  @returns Link service access point identifier.
- *  @returns 0 if mapping is not found.
- */
-static inline eth_lsap_t lsap_unmap(eth_type_t ethertype){
-	switch(ethertype){
-		case ETH_P_IP:
-			return ETH_LSAP_IP;
-		case ETH_P_ARP:
-			return ETH_LSAP_ARP;
-		default:
-			return 0;
-	}
-}
-
-/** Maps the network interface layer services to the hardware types.
- *  @param[in] nil The network interface service.
- *  @returns The hardware type of the network interface service.
- *  @returns 0 if mapping is not found.
- */
-static inline hw_type_t hardware_map(services_t nil){
-	switch(nil){
-		case SERVICE_ETHERNET:
-		case SERVICE_DP8390:
-			return HW_ETHER;
-		default:
-			return 0;
-	}
-}
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/socket.h
===================================================================
--- uspace/srv/net/include/socket.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,215 +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 application program interface (API).
- *  This is a part of the network application library.
- *  Based on the BSD socket interface.
- */
-
-#ifndef __NET_SOCKET_H__
-#define __NET_SOCKET_H__
-
-#include "byteorder.h"
-#include "in.h"
-#include "in6.h"
-#include "inet.h"
-
-#include "socket_codes.h"
-#include "socket_errno.h"
-
-/** @name Socket application programming interface
- */
-/*@{*/
-
-/** Creates a new socket.
- *  @param[in] domain The socket protocol family.
- *  @param[in] type Socket type.
- *  @param[in] protocol Socket protocol.
- *  @returns The socket identifier on success.
- *  @returns EPFNOTSUPPORT if the protocol family is not supported.
- *  @returns ESOCKNOTSUPPORT if the socket type is not supported.
- *  @returns EPROTONOSUPPORT if the protocol is not supported.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns ELIMIT if there was not a free socket identifier found this time.
- *  @returns Other error codes as defined for the NET_SOCKET message.
- *  @returns Other error codes as defined for the bind_service_timeout() function.
- */
-int socket(int domain, int type, int protocol);
-
-/** Binds the socket to a port address.
- *  @param[in] socket_id Socket identifier.
- *  @param[in] my_addr The port address.
- *  @param[in] addrlen The address length.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns EBADMEM if the my_addr parameter is NULL.
- *  @returns NO_DATA if the addlen parameter is zero (0).
- *  @returns Other error codes as defined for the NET_SOCKET_BIND message.
- */
-int bind(int socket_id, const struct sockaddr * my_addr, socklen_t addrlen);
-
-/** Sets the number of connections waiting to be accepted.
- *  @param[in] socket_id Socket identifier.
- *  @param[in] backlog The maximum number of waiting sockets to be accepted.
- *  @returns EOK on success.
- *  @returns EINVAL if the backlog parameter is not positive (<=0).
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns Other error codes as defined for the NET_SOCKET_LISTEN message.
- */
-int listen(int socket_id, int backlog);
-
-/** Accepts waiting socket.
- *  Blocks until such a socket exists.
- *  @param[in] socket_id Socket identifier.
- *  @param[out] cliaddr The remote client address.
- *  @param[in] addrlen The address length.
- *  @returns EOK on success.
- *  @returns EBADMEM if the cliaddr or addrlen parameter is NULL.
- *  @returns EINVAL if the backlog parameter is not positive (<=0).
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns Other error codes as defined for the NET_SOCKET_ACCEPT message.
- */
-int accept(int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen);
-
-/** Connects socket to the remote server.
- *  @param[in] socket_id Socket identifier.
- *  @param[in] serv_addr The remote server address.
- *  @param[in] addrlen The address length.
- *  @returns EOK on success.
- *  @returns EBADMEM if the serv_addr parameter is NULL.
- *  @returns NO_DATA if the addlen parameter is zero (0).
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns Other error codes as defined for the NET_SOCKET_CONNECT message.
- */
-int connect(int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen);
-
-/** Closes the socket.
- *  @param[in] socket_id Socket identifier.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns EINPROGRESS if there is another blocking function in progress.
- *  @returns Other error codes as defined for the NET_SOCKET_CLOSE message.
- */
-int closesocket(int socket_id);
-
-/** Sends data via the socket.
- *  @param[in] socket_id Socket identifier.
- *  @param[in] data The data to be sent.
- *  @param[in] datalength The data length.
- *  @param[in] flags Various send flags.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns EBADMEM if the data parameter is NULL.
- *  @returns NO_DATA if the datalength parameter is zero (0).
- *  @returns Other error codes as defined for the NET_SOCKET_SEND message.
- */
-int send(int socket_id, void * data, size_t datalength, int flags);
-
-/** Sends data via the socket to the remote address.
- *  Binds the socket to a free port if not already connected/bound.
- *  @param[in] socket_id Socket identifier.
- *  @param[in] data The data to be sent.
- *  @param[in] datalength The data length.
- *  @param[in] flags Various send flags.
- *  @param[in] toaddr The destination address.
- *  @param[in] addrlen The address length.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns EBADMEM if the data or toaddr parameter is NULL.
- *  @returns NO_DATA if the datalength or the addrlen parameter is zero (0).
- *  @returns Other error codes as defined for the NET_SOCKET_SENDTO message.
- */
-int sendto(int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen);
-
-/** Receives data via the socket.
- *  @param[in] socket_id Socket identifier.
- *  @param[out] data The data buffer to be filled.
- *  @param[in] datalength The data length.
- *  @param[in] flags Various receive flags.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns EBADMEM if the data parameter is NULL.
- *  @returns NO_DATA if the datalength parameter is zero (0).
- *  @returns Other error codes as defined for the NET_SOCKET_RECV message.
- */
-int recv(int socket_id, void * data, size_t datalength, int flags);
-
-/** Receives data via the socket.
- *  @param[in] socket_id Socket identifier.
- *  @param[out] data The data buffer to be filled.
- *  @param[in] datalength The data length.
- *  @param[in] flags Various receive flags.
- *  @param[out] fromaddr The source address.
- *  @param[in,out] addrlen The address length. The maximum address length is read. The actual address length is set.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns EBADMEM if the data or fromaddr parameter is NULL.
- *  @returns NO_DATA if the datalength or addrlen parameter is zero (0).
- *  @returns Other error codes as defined for the NET_SOCKET_RECVFROM message.
- */
-int recvfrom(int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen);
-
-/** Gets socket option.
- *  @param[in] socket_id Socket identifier.
- *  @param[in] level The socket options level.
- *  @param[in] optname The socket option to be get.
- *  @param[out] value The value buffer to be filled.
- *  @param[in,out] optlen The value buffer length. The maximum length is read. The actual length is set.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns EBADMEM if the value or optlen parameter is NULL.
- *  @returns NO_DATA if the optlen parameter is zero (0).
- *  @returns Other error codes as defined for the NET_SOCKET_GETSOCKOPT message.
- */
-int getsockopt(int socket_id, int level, int optname, void * value, size_t * optlen);
-
-/** Sets socket option.
- *  @param[in] socket_id Socket identifier.
- *  @param[in] level The socket options level.
- *  @param[in] optname The socket option to be set.
- *  @param[in] value The value to be set.
- *  @param[in] optlen The value length.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns EBADMEM if the value parameter is NULL.
- *  @returns NO_DATA if the optlen parameter is zero (0).
- *  @returns Other error codes as defined for the NET_SOCKET_SETSOCKOPT message.
- */
-int setsockopt(int socket_id, int level, int optname, const void * value, size_t optlen);
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/socket_codes.h
===================================================================
--- uspace/srv/net/include/socket_codes.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,460 +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 codes and definitions.
- *  This is a part of the network application library.
- */
-
-#ifndef __NET_SOCKET_CODES_H__
-#define __NET_SOCKET_CODES_H__
-
-#include <sys/types.h>
-
-/** @name Address families definitions
- */
-/*@{*/
-
-/** Unspecified address family.
- */
-#define AF_UNSPEC	0
-
-/** Unix domain sockets address family.
- */
-#define AF_UNIXL	1
-
-/** POSIX name for AF_UNIX address family.
- */
-#define AF_LOCAL	1
-
-/** Internet IP Protocol address family.
- */
-#define AF_INET		2
-
-/** Amateur Radio AX.25 address family.
- */
-#define AF_AX25		3
-
-/** Novell IPX address family.
- */
-#define AF_IPX		4
-
-/** AppleTalk DDP address family.
- */
-#define AF_APPLETALK	5
-
-/** Amateur Radio NET/ROM address family.
- */
-#define AF_NETROM	6
-
-/** Multiprotocol bridge address family.
- */
-#define AF_BRIDGE	7
-
-/** ATM PVCs address family.
- */
-#define AF_ATMPVC	8
-
-/** Reserved for X.25 project address family.
- */
-#define AF_X25		9
-
-/** IP version 6 address family.
- */
-#define AF_INET6	10
-
-/** Amateur Radio X.25 PLP address family.
- */
-#define AF_ROSE		11
-
-/** Reserved for DECnet project address family.
- */
-#define AF_DECnet	12
-
-/** Reserved for 802.2LLC project address family.
- */
-#define AF_NETBEUI	13
-
-/** Security callback pseudo AF address family.
- */
-#define AF_SECURITY	14
-
-/** PF_KEY key management API address family.
- */
-#define AF_KEY		15
-
-/** Alias to emulate 4.4BSD address family.
- */
-#define AF_NETLINK	16
-
-/** Packet family address family.
- */
-#define AF_PACKET	17
-
-/** Ash address family.
- */
-#define AF_ASH		18
-
-/** Acorn Econet address family.
- */
-#define AF_ECONET	19
-
-/** ATM SVCs address family.
- */
-#define AF_ATMSVC	20
-
-/** Linux SNA Project (nutters!) address family.
- */
-#define AF_SNA		22
-
-/** IRDA sockets address family.
- */
-#define AF_IRDA		23
-
-/** PPPoX sockets address family.
- */
-#define AF_PPPOX	24
-
-/** Wanpipe API Sockets address family.
- */
-#define AF_WANPIPE	25
-
-/** Linux LLC address family.
- */
-#define AF_LLC		26
-
-/** Controller Area Network address family.
- */
-#define AF_CAN		29
-
-/** TIPC sockets address family.
- */
-#define AF_TIPC		30
-
-/** Bluetooth sockets address family.
- */
-#define AF_BLUETOOTH	31
-
-/** IUCV sockets address family.
- */
-#define AF_IUCV		32
-
-/** RxRPC sockets address family.
- */
-#define AF_RXRPC	33
-
-/** Maximum address family.
- */
-#define AF_MAX		34
-
-/*@}*/
-
-/** @name Protocol families definitions
- *  Same as address families.
- */
-/*@{*/
-
-/** Unspecified protocol family.
- */
-#define PF_UNSPEC	AF_UNSPEC
-
-/** Unix domain sockets protocol family.
- */
-#define PF_UNIXL	AF_UNIXL
-
-/** POSIX name for AF_UNIX protocol family.
- */
-#define PF_LOCAL	AF_LOCAL
-
-/** Internet IP Protocol protocol family.
- */
-#define PF_INET		AF_INET
-
-/** Amateur Radio AX.25 protocol family.
- */
-#define PF_AX25		AF_AX25
-
-/** Novell IPX protocol family.
- */
-#define PF_IPX		AF_IPX
-
-/** AppleTalk DDP protocol family.
- */
-#define PF_APPLETALK	AF_APPLETALK
-
-/** Amateur Radio NET/ROM protocol family.
- */
-#define PF_NETROM	AF_NETROM
-
-/** Multiprotocol bridge protocol family.
- */
-#define PF_BRIDGE	AF_BRIDGE
-
-/** ATM PVCs protocol family.
- */
-#define PF_ATMPVC	AF_ATMPVC
-
-/** Reserved for X.25 project protocol family.
- */
-#define PF_X25		AF_X25
-
-/** IP version 6 protocol family.
- */
-#define PF_INET6	AF_INET6
-
-/** Amateur Radio X.25 PLP protocol family.
- */
-#define PF_ROSE		AF_ROSE
-
-/** Reserved for DECnet project protocol family.
- */
-#define PF_DECnet	AF_DECnet
-
-/** Reserved for 802.2LLC project protocol family.
- */
-#define PF_NETBEUI	AF_NETBEUI
-
-/** Security callback pseudo AF protocol family.
- */
-#define PF_SECURITY	AF_SECURITY
-
-/** PF_KEY key management API protocol family.
- */
-#define PF_KEY		AF_KEY
-
-/** Alias to emulate 4.4BSD protocol family.
- */
-#define PF_NETLINK	AF_NETLINK
-
-/** Packet family protocol family.
- */
-#define PF_PACKET	AF_PACKET
-
-/** Ash protocol family.
- */
-#define PF_ASH		AF_ASH
-
-/** Acorn Econet protocol family.
- */
-#define PF_ECONET	AF_ECONET
-
-/** ATM SVCs protocol family.
- */
-#define PF_ATMSVC	AF_ATMSVC
-
-/** Linux SNA Project (nutters!) protocol family.
- */
-#define PF_SNA		AF_SNA
-
-/** IRDA sockets protocol family.
- */
-#define PF_IRDA		AF_IRDA
-
-/** PPPoX sockets protocol family.
- */
-#define PF_PPPOX	AF_PPPOX
-
-/** Wanpipe API Sockets protocol family.
- */
-#define PF_WANPIPE	AF_WANPIPE
-
-/** Linux LLC protocol family.
- */
-#define PF_LLC		AF_LLC
-
-/** Controller Area Network protocol family.
- */
-#define PF_CAN		AF_CAN
-
-/** TIPC sockets protocol family.
- */
-#define PF_TIPC		AF_TIPC
-
-/** Bluetooth sockets protocol family.
- */
-#define PF_BLUETOOTH	AF_BLUETOOTH
-
-/** IUCV sockets protocol family.
- */
-#define PF_IUCV		AF_IUCV
-
-/** RxRPC sockets protocol family.
- */
-#define PF_RXRPC	AF_RXRPC
-
-/** Maximum protocol family.
- */
-#define PF_MAX		AF_MAX
-
-/*@}*/
-
-/** @name Socket option levels definitions
- *  Thanks to BSD these must match IPPROTO_xxx
- */
-/*@{*/
-
-/** IP socket option level.
- */
-#define SOL_IP		0
-
-/** ICMP socket option level.
- */
-#define SOL_ICMP	1
-
-/** TCP socket option level.
- */
-#define SOL_TCP		6
-
-/** UDP socket option level.
- */
-#define SOL_UDP		17
-
-/** IPV socket option level.
- */
-#define SOL_IPV6	41
-
-/** ICMPV socket option level.
- */
-#define SOL_ICMPV6	58
-
-/** SCTP socket option level.
- */
-#define SOL_SCTP	132
-
-/** UDP-Lite (RFC 3828) socket option level.
- */
-#define SOL_UDPLITE	136
-
-/** RAW socket option level.
- */
-#define SOL_RAW		255
-
-/** IPX socket option level.
- */
-#define SOL_IPX		256
-
-/** AX socket option level.
- */
-#define SOL_AX25	257
-
-/** ATALK socket option level.
- */
-#define SOL_ATALK	258
-
-/** NETROM socket option level.
- */
-#define SOL_NETROM	259
-
-/** ROSE socket option level.
- */
-#define SOL_ROSE	260
-
-/** DECNET socket option level.
- */
-#define SOL_DECNET	261
-
-/** X25 socket option level.
- */
-#define	SOL_X25		262
-
-/** PACKET socket option level.
- */
-#define SOL_PACKET	263
-
-/** ATM layer (cell level) socket option level.
- */
-#define SOL_ATM		264
-
-/** ATM Adaption Layer (packet level) socket option level.
- */
-#define SOL_AAL		265
-
-/** IRDA socket option level.
- */
-#define SOL_IRDA	266
-
-/** NETBEUI socket option level.
- */
-#define SOL_NETBEUI	267
-
-/** LLC socket option level.
- */
-#define SOL_LLC		268
-
-/** DCCP socket option level.
- */
-#define SOL_DCCP	269
-
-/** NETLINK socket option level.
- */
-#define SOL_NETLINK	270
-
-/** TIPC socket option level.
- */
-#define SOL_TIPC	271
-
-/** RXRPC socket option level.
- */
-#define SOL_RXRPC	272
-
-/** PPPOL socket option level.
- */
-#define SOL_PPPOL2TP	273
-
-/** BLUETOOTH socket option level.
- */
-#define SOL_BLUETOOTH	274
-
-/*@}*/
-
-/** Socket types.
- */
-typedef enum sock_type{
-	/** Stream (connection oriented) socket.
-	 */
-	SOCK_STREAM = 1,
-	/** Datagram (connectionless oriented) socket.
-	 */
-	SOCK_DGRAM = 2,
-	/** Raw socket.
-	 */
-	SOCK_RAW = 3
-} sock_type_t;
-
-/** Type definition of the socket length.
- */
-typedef int32_t	socklen_t;
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/socket_errno.h
===================================================================
--- uspace/srv/net/include/socket_errno.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,136 +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 net
- *  @{
- */
-
-/** @file
- *  Socket error codes.
- *  Based on BSD.
- */
-
-#ifndef __NET_SOCKET_ERR_H__
-#define __NET_SOCKET_ERR_H__
-
-#include <errno.h>
-
-/** @name Socket error codes definitions
- */
-/*@{*/
-
-////#define EINTR			(-10004)
-////#define EBADF			(-10009)
-//#define EACCES			(-10013)
-//#define EFAULT			(-10014)
-////#define EINVAL			(-10022)
-////#define EMFILE			(-10024)
-//#define EWOULDBLOCK		(-10035)
-
-/** An API function is called while another blocking function is in progress.
- */
-#define EINPROGRESS		(-10036)
-
-//#define EALREADY		(-10037)
-
-/** The socket identifier is not valid.
- */
-#define ENOTSOCK		(-10038)
-
-/** The destination address required.
- */
-#define EDESTADDRREQ	(-10039)
-
-//#define EMSGSIZE		(-10040)
-//#define EPROTOTYPE		(-10041)
-//#define ENOPROTOOPT		(-10042)
-
-/** Protocol is not supported.
- */
-#define EPROTONOSUPPORT	(-10043)
-
-/** Socket type is not supported.
- */
-#define ESOCKTNOSUPPORT	(-10044)
-
-//#define EOPNOTSUPP		(-10045)
-
-/** Protocol family is not supported.
- */
-#define EPFNOSUPPORT	(-10046)
-
-/** Address family is not supported.
- */
-#define EAFNOSUPPORT	(-10047)
-
-/** Address is already in use.
- */
-#define EADDRINUSE		(-10048)
-
-//#define EADDRNOTAVAIL	(-10049)
-/* May be reported at any time if the implementation detects an underlying failure.
- */
-//#define ENETDOWN		(-10050)
-//#define ENETUNREACH		(-10051)
-//#define ENETRESET		(-10052)
-//#define ECONNABORTED	(-10053)
-//#define ECONNRESET		(-10054)
-//#define ENOBUFS			(-10055)
-//#define EISCONN			(-10056)
-
-/** The socket is not connected or bound.
- */
-#define ENOTCONN		(-10057)
-
-//#define ESHUTDOWN		(-10058)
-//#define ETOOMANYREFS	(-10059)
-//#define ETIMEDOUT		(-10060)
-//#define ECONNREFUSED	(-10061)
-//#define ELOOP			(-10062)
-////#define ENAMETOOLONG	(-10063)
-//#define EHOSTDOWN		(-10064)
-//#define EHOSTUNREACH	(-10065)
-//#define HOST_NOT_FOUND	(-11001)
-
-/** The requested operation was not performed.
- *  Try again later.
- */
-#define TRY_AGAIN		(-11002)
-
-//#define NO_RECOVERY		(-11003)
-
-/** No data.
- */
-#define NO_DATA			(-11004)
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/include/tcp_codes.h
===================================================================
--- uspace/srv/net/include/tcp_codes.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,88 +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 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: pace/srv/net/include/tl_interface.h
===================================================================
--- uspace/srv/net/include/tl_interface.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,75 +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 net_tl
- *  @{
- */
-
-/** @file
- *  Transport layer module interface for the underlying internetwork layer.
- */
-
-#ifndef __NET_TL_INTERFACE_H__
-#define __NET_TL_INTERFACE_H__
-
-#include <async.h>
-
-#include <ipc/services.h>
-
-#include "../messages.h"
-
-#include "../include/device.h"
-
-#include "../structures/packet/packet.h"
-#include "../structures/packet/packet_client.h"
-
-#include "../tl/tl_messages.h"
-
-/** @name Transport layer module interface
- *  This interface is used by other modules.
- */
-/*@{*/
-
-/** Notifies the remote transport layer modules about the received packet/s.
- *  @param[in] tl_phone The transport layer module phone used for remote calls.
- *  @param[in] device_id The device identifier.
- *  @param[in] packet The received packet or the received packet queue. The packet queue is used to carry a~fragmented datagram. The first packet contains the headers, the others contain only data.
- *  @param[in] target The target transport layer module service to be delivered to.
- *  @param[in] error The packet error reporting service. Prefixes the received packet.
- *  @returns EOK on success.
- */
-inline static int tl_received_msg(int tl_phone, device_id_t device_id, packet_t packet, services_t target, services_t error){
-	return generic_received_msg(tl_phone, NET_TL_RECEIVED, device_id, packet_get_id(packet), target, error);
-}
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/inet.c
===================================================================
--- uspace/srv/net/inet.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,156 +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 net
- *  @{
- */
-
-/** @file
- *  Internet protocol address conversion functions implementation.
- */
-
-#include <errno.h>
-#include <mem.h>
-#include <stdio.h>
-#include <str.h>
-
-#include "include/in.h"
-#include "include/in6.h"
-#include "include/inet.h"
-#include "include/socket_codes.h"
-
-int inet_ntop(uint16_t family, const uint8_t * data, char * address, size_t length){
-	if((! data) || (! address)){
-		return EINVAL;
-	}
-
-	switch(family){
-		case AF_INET:
-			// check the output buffer size
-			if(length < INET_ADDRSTRLEN){
-				return ENOMEM;
-			}
-			// fill the buffer with the IPv4 address
-			snprintf(address, length, "%hhu.%hhu.%hhu.%hhu", data[0], data[1], data[2], data[3]);
-			return EOK;
-		case AF_INET6:
-			// check the output buffer size
-			if(length < INET6_ADDRSTRLEN){
-				return ENOMEM;
-			}
-			// fill the buffer with the IPv6 address
-			snprintf(address, length, "%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx:%hhx%hhx", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15]);
-			return EOK;
-		default:
-			return ENOTSUP;
-	}
-}
-
-int inet_pton(uint16_t family, const char * address, uint8_t * data){
-	/** The base number of the values.
-	 */
-	int base;
-	/** The number of bytes per a section.
-	 */
-	size_t bytes;
-	/** The number of bytes of the address data.
-	 */
-	int count;
-
-	const char * next;
-	char * last;
-	int index;
-	size_t shift;
-	unsigned long value;
-
-	if(! data){
-		return EINVAL;
-	}
-
-	// set the processing parameters
-	switch(family){
-		case AF_INET:
-			count = 4;
-			base = 10;
-			bytes = 1;
-			break;
-		case AF_INET6:
-			count = 16;
-			base = 16;
-			bytes = 4;
-			break;
-		default:
-			return ENOTSUP;
-	}
-
-	// erase if no address
-	if(! address){
-		bzero(data, count);
-		return ENOENT;
-	}
-
-	// process the string from the beginning
-	next = address;
-	index = 0;
-	do{
-		// if the actual character is set
-		if(next && (*next)){
-
-			// if not on the first character
-			if(index){
-				// move to the next character
-				++ next;
-			}
-
-			// parse the actual integral value
-			value = strtoul(next, &last, base);
-			// remember the last problematic character
-			// should be either '.' or ':' but is ignored to be more generic
-			next = last;
-
-			// fill the address data byte by byte
-			shift = bytes - 1;
-			do{
-				// like little endian
-				data[index + shift] = value;
-				value >>= 8;
-			}while(shift --);
-
-			index += bytes;
-		}else{
-			// erase the rest of the address
-			bzero(data + index, count - index);
-			return EOK;
-		}
-	}while(index < count);
-
-	return EOK;
-}
-
-/** @}
- */
Index: pace/srv/net/messages.h
===================================================================
--- uspace/srv/net/messages.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,606 +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 net
- *  @{
- */
-
-/** @file
- *  Networking common message definitions.
- */
-
-#ifndef __NET_MESSAGES_H__
-#define __NET_MESSAGES_H__
-
-#include <async.h>
-
-#include <ipc/ipc.h>
-#include <ipc/services.h>
-
-#include "include/device.h"
-
-#include "structures/measured_strings.h"
-#include "structures/packet/packet.h"
-
-/** Returns a value indicating whether the value is in the interval.
- *  @param[in] item The value to be checked.
- *  @param[in] first_inclusive The first value in the interval inclusive.
- *  @param[in] last_exclusive The first value after the interval.
- */
-#define IS_IN_INTERVAL(item, first_inclusive, last_exclusive)	(((item) >= (first_inclusive)) && ((item) < (last_exclusive)))
-
-/** @name Networking message counts
- */
-/*@{*/
-
-/** The number of ARP messages.
- */
-#define NET_ARP_COUNT		5
-
-/** The number of Ethernet messages.
- */
-#define NET_ETH_COUNT		0
-
-/** The number of ICMP messages.
- */
-#define NET_ICMP_COUNT		6
-
-/** The number of inter-network messages.
- */
-#define NET_IL_COUNT		6
-
-/** The number of IP messages.
- */
-#define NET_IP_COUNT		4
-
-/** The number of general networking messages.
- */
-#define NET_NET_COUNT		3
-
-/** The number of network interface driver messages.
- */
-#define NET_NETIF_COUNT		6
-
-/** The number of network interface layer messages.
- */
-#define NET_NIL_COUNT		7
-
-/** The number of packet management system messages.
- */
-#define NET_PACKET_COUNT	5
-
-/** The number of socket messages.
- */
-#define NET_SOCKET_COUNT	14
-
-/** The number of TCP messages.
- */
-#define NET_TCP_COUNT		0
-
-/** The number of transport layer messages.
- */
-#define NET_TL_COUNT		1
-
-/** The number of UDP messages.
- */
-#define NET_UDP_COUNT		0
-
-/*@}*/
-
-/** @name Networking message intervals
- */
-/*@{*/
-
-/** The first networking message.
- */
-#define NET_FIRST			2000
-
-/** The first network interface layer message.
- */
-#define NET_NETIF_FIRST		NET_FIRST
-
-/** The last network interface layer message.
- */
-#define NET_NETIF_LAST		(NET_NETIF_FIRST + NET_NETIF_COUNT)
-
-/** The first general networking message.
- */
-#define NET_NET_FIRST		(NET_NETIF_LAST + 0)
-
-/** The last general networking message.
- */
-#define NET_NET_LAST		(NET_NET_FIRST + NET_NET_COUNT)
-
-/** The first network interface layer message.
- */
-#define NET_NIL_FIRST		(NET_NET_LAST + 0)
-
-/** The last network interface layer message.
- */
-#define NET_NIL_LAST		(NET_NIL_FIRST + NET_NIL_COUNT)
-
-/** The first Ethernet message.
- */
-#define NET_ETH_FIRST		(NET_NIL_LAST + 0)
-
-/** The last Ethernet message.
- */
-#define NET_ETH_LAST		(NET_ETH_FIRST + NET_ETH_COUNT)
-
-/** The first inter-network message.
- */
-#define NET_IL_FIRST		(NET_ETH_LAST + 0)
-
-/** The last inter-network message.
- */
-#define NET_IL_LAST			(NET_IL_FIRST + NET_IL_COUNT)
-
-/** The first IP message.
- */
-#define NET_IP_FIRST		(NET_IL_LAST + 0)
-
-/** The last IP message.
- */
-#define NET_IP_LAST			(NET_IP_FIRST + NET_IP_COUNT)
-
-/** The first ARP message.
- */
-#define NET_ARP_FIRST		(NET_IP_LAST + 0)
-
-/** The last ARP message.
- */
-#define NET_ARP_LAST		(NET_ARP_FIRST + NET_ARP_COUNT)
-
-/** The first ICMP message.
- */
-#define NET_ICMP_FIRST		(NET_ARP_LAST + 0)
-
-/** The last ICMP message.
- */
-#define NET_ICMP_LAST		(NET_ICMP_FIRST + NET_ICMP_COUNT)
-
-/** The first ICMP message.
- */
-#define NET_TL_FIRST		(NET_ICMP_LAST + 0)
-
-/** The last ICMP message.
- */
-#define NET_TL_LAST			(NET_TL_FIRST + NET_TL_COUNT)
-
-/** The first UDP message.
- */
-#define NET_UDP_FIRST		(NET_TL_LAST + 0)
-
-/** The last UDP message.
- */
-#define NET_UDP_LAST		(NET_UDP_FIRST + NET_UDP_COUNT)
-
-/** The first TCP message.
- */
-#define NET_TCP_FIRST		(NET_UDP_LAST + 0)
-
-/** The last TCP message.
- */
-#define NET_TCP_LAST		(NET_TCP_FIRST + NET_TCP_COUNT)
-
-/** The first socket message.
- */
-#define NET_SOCKET_FIRST	(NET_TCP_LAST + 0)
-
-/** The last socket message.
- */
-#define NET_SOCKET_LAST		(NET_SOCKET_FIRST + NET_SOCKET_COUNT)
-
-/** The first packet management system message.
- */
-#define NET_PACKET_FIRST	(NET_SOCKET_LAST + 0)
-
-/** The last packet management system message.
- */
-#define NET_PACKET_LAST		(NET_PACKET_FIRST + NET_PACKET_COUNT)
-
-/** The last networking message.
- */
-#define NET_LAST			NET_PACKET_LAST
-
-/** The number of networking messages.
- */
-#define NET_COUNT			(NET_LAST - NET_FIRST)
-
-/** Returns a value indicating whether the IPC call is a generic networking message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_MESSAGE(call)			IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_FIRST, NET_LAST)
-
-/** Returns a value indicating whether the IPC call is an ARP message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_ARP_MESSAGE(call)		IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_ARP_FIRST, NET_ARP_LAST)
-
-/** Returns a value indicating whether the IPC call is an Ethernet message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_ETH_MESSAGE(call)		IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_ETH_FIRST, NET_ETH_LAST)
-
-/** Returns a value indicating whether the IPC call is an ICMP message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_ICMP_MESSAGE(call)		IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_ICMP_FIRST, NET_ICMP_LAST)
-
-/** Returns a value indicating whether the IPC call is an inter-network layer message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_IL_MESSAGE(call)		IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_IL_FIRST, NET_IL_LAST)
-
-/** Returns a value indicating whether the IPC call is an IP message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_IP_MESSAGE(call)		IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_IP_FIRST, NET_IP_LAST)
-
-/** Returns a value indicating whether the IPC call is a generic networking message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_NET_MESSAGE(call)		IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_NET_FIRST, NET_NET_LAST)
-
-/** Returns a value indicating whether the IPC call is a network interface layer message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_NIL_MESSAGE(call)		IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_NIL_FIRST, NET_NIL_LAST)
-
-/** Returns a value indicating whether the IPC call is a packet manaagement system message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_PACKET_MESSAGE(call)	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_PACKET_FIRST, NET_PACKET_LAST)
-
-/** Returns a value indicating whether the IPC call is a socket message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_SOCKET_MESSAGE(call)	IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_SOCKET_FIRST, NET_SOCKET_LAST)
-
-/** Returns a value indicating whether the IPC call is a TCP message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_TCP_MESSAGE(call)		IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_TCP_FIRST, NET_TCP_LAST)
-
-/** Returns a value indicating whether the IPC call is a transport layer message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_TL_MESSAGE(call)		IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_TL_FIRST, NET_TL_LAST)
-
-/** Returns a value indicating whether the IPC call is a UDP message.
- *  @param[in] call The IPC call to be checked.
- */
-#define IS_NET_UDP_MESSAGE(call)		IS_IN_INTERVAL(IPC_GET_METHOD(*call), NET_UDP_FIRST, NET_UDP_LAST)
-
-/*@}*/
-
-/** @name Networking specific message arguments definitions
- */
-/*@{*/
-
-/** @name First arguments
- */
-/*@{*/
-
-/** Returns the device identifier message argument.
- *  @param[in] call The message call structure.
- */
-#define IPC_GET_DEVICE(call)		(device_id_t) IPC_GET_ARG1(*call)
-
-/*@}*/
-
-/** @name Second arguments
- */
-/*@{*/
-
-/** Returns the packet identifier message argument.
- *  @param[in] call The message call structure.
- */
-#define IPC_GET_PACKET(call)		(packet_id_t) IPC_GET_ARG2(*call)
-
-/** Returns the count message argument.
- *  @param[in] call The message call structure.
- */
-#define IPC_GET_COUNT(call)		(size_t) IPC_GET_ARG2(*call)
-
-/** Returns the device state message argument.
- *  @param[in] call The message call structure.
- */
-#define IPC_GET_STATE(call)		(device_state_t) IPC_GET_ARG2(*call)
-
-/** Returns the maximum transmission unit message argument.
- *  @param[in] call The message call structure.
- */
-#define IPC_GET_MTU(call)			(size_t) IPC_GET_ARG2(*call)
-
-/*@}*/
-
-/** @name Third arguments
- */
-/*@{*/
-
-/** Returns the device driver service message argument.
- *  @param[in] call The message call structure.
- */
-#define IPC_GET_SERVICE(call)		(services_t) IPC_GET_ARG3(*call)
-
-/** Returns the target service message argument.
- *  @param[in] call The message call structure.
- */
-#define IPC_GET_TARGET(call)		(services_t) IPC_GET_ARG3(*call)
-
-/** Returns the sender service message argument.
- *  @param[in] call The message call structure.
- */
-#define IPC_GET_SENDER(call)		(services_t) IPC_GET_ARG3(*call)
-
-/*@}*/
-
-/** @name Fourth arguments
- */
-/*@{*/
-
-/** Returns the error service message argument.
- *  @param[in] call The message call structure.
- */
-#define IPC_GET_ERROR(call)		(services_t) IPC_GET_ARG4(*call)
-
-/*@}*/
-
-/** @name Fifth arguments
- */
-/*@{*/
-
-/** Returns the phone message argument.
- *  @param[in] call The message call structure.
- */
-#define IPC_GET_PHONE(call)		(int) IPC_GET_ARG5(*call)
-
-/*@}*/
-
-/** @name First answers
- */
-/*@{*/
-
-/** Sets the device identifier in the message answer.
- *  @param[out] answer The message answer structure.
- */
-#define IPC_SET_DEVICE(answer)	(&IPC_GET_ARG1(*answer))
-
-/** Sets the minimum address length in the message answer.
- *  @param[out] answer The message answer structure.
- */
-#define IPC_SET_ADDR(answer)		(&IPC_GET_ARG1(*answer))
-
-/*@}*/
-
-/** @name Second answers
- */
-/*@{*/
-
-/** Sets the minimum prefix size in the message answer.
- *  @param[out] answer The message answer structure.
- */
-#define IPC_SET_PREFIX(answer)	(&IPC_GET_ARG2(*answer))
-
-/*@}*/
-
-/** @name Third answers
- */
-/*@{*/
-
-/** Sets the maximum content size in the message answer.
- *  @param[out] answer The message answer structure.
- */
-#define IPC_SET_CONTENT(answer)	(&IPC_GET_ARG3(*answer))
-
-/*@}*/
-
-/** @name Fourth answers
- */
-/*@{*/
-
-/** Sets the minimum suffix size in the message answer.
- *  @param[out] answer The message answer structure.
- */
-#define IPC_SET_SUFFIX(answer)	(&IPC_GET_ARG4(*answer))
-
-/*@}*/
-
-/*@}*/
-
-/** Notifies the module about the device state change.
- *  @param[in] phone The service module phone.
- *  @param[in] message The service specific message.
- *  @param[in] device_id The device identifier.
- *  @param[in] state The new device state.
- *  @param[in] target The target module service.
- *  @returns EOK on success.
- */
-static inline int generic_device_state_msg(int phone, int message, device_id_t device_id, int state, services_t target){
-	async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) state, target);
-	return EOK;
-}
-
-/** Notifies a module about the device.
- *  @param[in] phone The service module phone.
- *  @param[in] message The service specific message.
- *  @param[in] device_id The device identifier.
- *  @param[in] arg2 The second argument of the message.
- *  @param[in] service The device module service.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the specific service message.
- */
-static inline int generic_device_req(int phone, int message, device_id_t device_id, int arg2, services_t service){
-	return (int) async_req_3_0(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) arg2, (ipcarg_t) service);
-}
-
-/** Returns the address.
- *  @param[in] phone The service module phone.
- *  @param[in] message The service specific message.
- *  @param[in] device_id The device identifier.
- *  @param[out] address The desired address.
- *  @param[out] data The address data container.
- *  @returns EOK on success.
- *  @returns EBADMEM if the address parameter and/or the data parameter is NULL.
- *  @returns Other error codes as defined for the specific service message.
- */
-static inline int generic_get_addr_req(int phone, int message, device_id_t device_id, measured_string_ref * address, char ** data){
-	aid_t message_id;
-	ipcarg_t result;
-	int string;
-
-	if(!(address && data)){
-		return EBADMEM;
-	}
-
-	// request the address
-	message_id = async_send_1(phone, (ipcarg_t) message, (ipcarg_t) device_id, NULL);
-	string = measured_strings_return(phone, address, data, 1);
-	async_wait_for(message_id, &result);
-
-	// if not successful
-	if((string == EOK) && (result != EOK)){
-		// clear the data
-		free(*address);
-		free(*data);
-	}
-	return (int) result;
-}
-
-/** Returns the device packet dimension for sending.
- *  @param[in] phone The service module phone.
- *  @param[in] message The service specific message.
- *  @param[in] device_id The device identifier.
- *  @param[out] packet_dimension The packet dimension.
- *  @returns EOK on success.
- *  @returns EBADMEM if the packet_dimension parameter is NULL.
- *  @returns Other error codes as defined for the specific service message.
- */
-static inline int generic_packet_size_req(int phone, int message, device_id_t device_id, packet_dimension_ref packet_dimension){
-	ipcarg_t result;
-	ipcarg_t prefix;
-	ipcarg_t content;
-	ipcarg_t suffix;
-	ipcarg_t addr_len;
-
-	if(! packet_dimension){
-		return EBADMEM;
-	}
-	result = async_req_1_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, &addr_len, &prefix, &content, &suffix);
-	packet_dimension->prefix = (size_t) prefix;
-	packet_dimension->content = (size_t) content;
-	packet_dimension->suffix = (size_t) suffix;
-	packet_dimension->addr_len = (size_t) addr_len;
-	return (int) result;
-}
-
-/** Passes the packet queue to the module.
- *  @param[in] phone The service module phone.
- *  @param[in] message The service specific message.
- *  @param[in] device_id The device identifier.
- *  @param[in] packet_id The received packet or the received packet queue identifier.
- *  @param[in] target The target module service.
- *  @param[in] error The error module service.
- *  @returns EOK on success.
- */
-static inline int generic_received_msg(int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t target, services_t error){
-	if(error){
-		async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) target, (ipcarg_t) error);
-	}else{
-		async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) target);
-	}
-	return EOK;
-}
-
-/** Sends the packet queue.
- *  @param[in] phone The service module phone.
- *  @param[in] message The service specific message.
- *  @param[in] device_id The device identifier.
- *  @param[in] packet_id The packet or the packet queue identifier.
- *  @param[in] sender The sending module service.
- *  @param[in] error The error module service.
- *  @returns EOK on success.
- */
-static inline int generic_send_msg(int phone, int message, device_id_t device_id, packet_id_t packet_id, services_t sender, services_t error){
-	if(error){
-		async_msg_4(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) sender, (ipcarg_t) error);
-	}else{
-		async_msg_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) packet_id, (ipcarg_t) sender);
-	}
-	return EOK;
-}
-
-/** Translates the given strings.
- *  Allocates and returns the needed memory block as the data parameter.
- *  @param[in] phone The service module phone.
- *  @param[in] message The service specific message.
- *  @param[in] device_id The device identifier.
- *  @param[in] service The module service.
- *  @param[in] configuration The key strings.
- *  @param[in] count The number of configuration keys.
- *  @param[out] translation The translated values.
- *  @param[out] data The translation data container.
- *  @returns EOK on success.
- *  @returns EINVAL if the configuration parameter is NULL.
- *  @returns EINVAL if the count parameter is zero (0).
- *  @returns EBADMEM if the translation or the data parameters are NULL.
- *  @returns Other error codes as defined for the specific service message.
- */
-static inline int generic_translate_req(int phone, int message, device_id_t device_id, services_t service, measured_string_ref configuration, size_t count, measured_string_ref * translation, char ** data){
-	aid_t message_id;
-	ipcarg_t result;
-	int string;
-
-	if(!(configuration && (count > 0))){
-		return EINVAL;
-	}
-	if(!(translation && data)){
-		return EBADMEM;
-	}
-
-	// request the translation
-	message_id = async_send_3(phone, (ipcarg_t) message, (ipcarg_t) device_id, (ipcarg_t) count, (ipcarg_t) service, NULL);
-	measured_strings_send(phone, configuration, count);
-	string = measured_strings_return(phone, translation, data, count);
-	async_wait_for(message_id, &result);
-
-	// if not successful
-	if((string == EOK) && (result != EOK)){
-		// clear the data
-		free(*translation);
-		free(*data);
-	}
-
-	return (int) result;
-}
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/module.c
===================================================================
--- uspace/srv/net/module.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,146 +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 net
- *  @{
- */
-
-/** @file
- *  Generic module skeleton implementation.
- */
-
-#include <async.h>
-#include <stdio.h>
-#include <task.h>
-
-#include <ipc/ipc.h>
-
-#include "err.h"
-#include "modules.h"
-
-/** @name External module functions.
- *  This functions have to be implemented in every module.
- */
-/*@{*/
-
-/** External message processing function.
- *  Should process the messages.
- *  The function has to be defined in each module.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOTSUP if the message is not known.
- *  @returns Other error codes as defined for each specific module message function.
- */
-extern int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-/** External function to print the module name.
- *  Should print the module name.
- *  The function has to be defined in each module.
- */
-extern void module_print_name(void);
-
-/** External module startup function.
- *  Should start and initialize the module and register the given client connection function.
- *  The function has to be defined in each module.
- *  @param[in] client_connection The client connection function to be registered.
- */
-extern int module_start(async_client_conn_t client_connection);
-
-/*@}*/
-
-/** Default thread for new connections.
- *  @param[in] iid The initial message identifier.
- *  @param[in] icall The initial message call structure.
- */
-void client_connection(ipc_callid_t iid, ipc_call_t * icall);
-
-/**	Starts the module.
- *  @param argc The count of the command line arguments. Ignored parameter.
- *  @param argv The command line parameters. Ignored parameter.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for each specific module start function.
- */
-int main(int argc, char * argv[]);
-
-void client_connection(ipc_callid_t iid, ipc_call_t * icall){
-	ipc_callid_t callid;
-	ipc_call_t call;
-	ipc_call_t answer;
-	int answer_count;
-	int res;
-
-	/*
-	 * Accept the connection
-	 *  - Answer the first IPC_M_CONNECT_ME_TO call.
-	 */
-	ipc_answer_0(iid, EOK);
-
-	// process additional messages
-	while(true){
-
-		// clear the answer structure
-		refresh_answer(&answer, &answer_count);
-
-		// fetch the next message
-		callid = async_get_call(&call);
-
-		// process the message
-		res = module_message(callid, &call, &answer, &answer_count);
-
-		// end if said to either by the message or the processing result
-		if((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP)){
-			return;
-		}
-
-		// answer the message
-		answer_call(callid, res, &answer, answer_count);
-	}
-}
-
-int main(int argc, char * argv[]){
-	ERROR_DECLARE;
-
-	// print the module label
-	printf("Task %d - ", task_get_id());
-	module_print_name();
-	printf("\n");
-
-	// start the module
-	if(ERROR_OCCURRED(module_start(client_connection))){
-		printf(" - ERROR %i\n", ERROR_CODE);
-		return ERROR_CODE;
-	}
-
-	return EOK;
-}
-
-/** @}
- */
Index: pace/srv/net/modules.c
===================================================================
--- uspace/srv/net/modules.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,198 +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 net
- *  @{
- */
-
-/** @file
- *  Generic module functions implementation.
- */
-
-#include <async.h>
-#include <malloc.h>
-
-#include <ipc/ipc.h>
-#include <ipc/services.h>
-
-#include <sys/time.h>
-
-#include "err.h"
-#include "modules.h"
-
-/** The time between connect requests in microseconds.
- */
-#define MODULE_WAIT_TIME	(10 * 1000)
-
-void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count){
-	// choose the most efficient answer function
-	if(answer || (! answer_count)){
-		switch(answer_count){
-			case 0:
-				ipc_answer_0(callid, (ipcarg_t) result);
-				break;
-			case 1:
-				ipc_answer_1(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer));
-				break;
-			case 2:
-				ipc_answer_2(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer));
-				break;
-			case 3:
-				ipc_answer_3(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer));
-				break;
-			case 4:
-				ipc_answer_4(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer));
-				break;
-			case 5:
-			default:
-				ipc_answer_5(callid, (ipcarg_t) result, IPC_GET_ARG1(*answer), IPC_GET_ARG2(*answer), IPC_GET_ARG3(*answer), IPC_GET_ARG4(*answer), IPC_GET_ARG5(*answer));
-				break;
-		}
-	}
-}
-
-int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver){
-	return bind_service_timeout(need, arg1, arg2, arg3, client_receiver, 0);
-}
-
-int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout){
-	ERROR_DECLARE;
-
-	int phone;
-	ipcarg_t phonehash;
-
-	// connect to the needed service
-	phone = connect_to_service_timeout(need, timeout);
-	// if connected
-	if(phone >= 0){
-		// request the bidirectional connection
-		if(ERROR_OCCURRED(ipc_connect_to_me(phone, arg1, arg2, arg3, &phonehash))){
-			ipc_hangup(phone);
-			return ERROR_CODE;
-		}
-		async_new_connection(phonehash, 0, NULL, client_receiver);
-	}
-	return phone;
-}
-
-int connect_to_service(services_t need){
-	return connect_to_service_timeout(need, 0);
-}
-
-int connect_to_service_timeout(services_t need, suseconds_t timeout){
-	int phone;
-
-	// if no timeout is set
-	if (timeout <= 0){
-		return async_connect_me_to_blocking(PHONE_NS, need, 0, 0);
-	}
-
-	while(true){
-		phone = async_connect_me_to(PHONE_NS, need, 0, 0);
-		if((phone >= 0) || (phone != ENOENT)){
-			return phone;
-		}
-
-		// end if no time is left
-		if(timeout <= 0){
-			return ETIMEOUT;
-		}
-
-		// wait the minimum of the module wait time and the timeout
-		usleep((timeout <= MODULE_WAIT_TIME) ? timeout : MODULE_WAIT_TIME);
-		timeout -= MODULE_WAIT_TIME;
-	}
-}
-
-int data_receive(void ** data, size_t * length){
-	ERROR_DECLARE;
-
-	ipc_callid_t callid;
-
-	if(!(data && length)){
-		return EBADMEM;
-	}
-
-	// fetch the request
-	if(! async_data_write_receive(&callid, length)){
-		return EINVAL;
-	}
-
-	// allocate the buffer
-	*data = malloc(*length);
-	if(!(*data)){
-		return ENOMEM;
-	}
-
-	// fetch the data
-	if(ERROR_OCCURRED(async_data_write_finalize(callid, * data, * length))){
-		free(data);
-		return ERROR_CODE;
-	}
-	return EOK;
-}
-
-int data_reply(void * data, size_t data_length){
-	size_t length;
-	ipc_callid_t callid;
-
-	// fetch the request
-	if(! async_data_read_receive(&callid, &length)){
-		return EINVAL;
-	}
-
-	// check the requested data size
-	if(length < data_length){
-		async_data_read_finalize(callid, data, length);
-		return EOVERFLOW;
-	}
-
-	// send the data
-	return async_data_read_finalize(callid, data, data_length);
-}
-
-void refresh_answer(ipc_call_t * answer, int * answer_count){
-
-	if(answer_count){
-		*answer_count = 0;
-	}
-
-	if(answer){
-		IPC_SET_RETVAL(*answer, 0);
-		// just to be precize
-		IPC_SET_METHOD(*answer, 0);
-		IPC_SET_ARG1(*answer, 0);
-		IPC_SET_ARG2(*answer, 0);
-		IPC_SET_ARG3(*answer, 0);
-		IPC_SET_ARG4(*answer, 0);
-		IPC_SET_ARG5(*answer, 0);
-	}
-}
-
-/** @}
- */
Index: pace/srv/net/modules.h
===================================================================
--- uspace/srv/net/modules.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,144 +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 net
- *  @{
- */
-
-/** @file
- *  Generic module functions.
- */
-
-#ifndef __NET_MODULES_H__
-#define __NET_MODULES_H__
- 
-#include <async.h>
-
-#include <ipc/ipc.h>
-#include <ipc/services.h>
-
-#include <sys/time.h>
-
-/** Converts the data length between different types.
- *	@param[in] type_from The source type.
- *  @param[in] type_to The destination type.
- *  @param[in] count The number units of the source type size.
- */
-#define CONVERT_SIZE(type_from, type_to, count)	((sizeof(type_from) / sizeof(type_to)) * (count))
-
-/** Registers the module service at the name server.
- *  @param[in] me The module service.
- *  @param[out] phonehash The created phone hash.
- */
-#define REGISTER_ME(me, phonehash)	ipc_connect_to_me(PHONE_NS, (me), 0, 0, (phonehash))
-
-/** Connect to the needed module function type definition.
- *  @param[in] need The needed module service.
- *  @returns The phone of the needed service.
- */
-typedef int connect_module_t(services_t need);
-
-/** Answers the call.
- *  @param[in] callid The call identifier.
- *  @param[in] result The message processing result.
- *  @param[in] answer The message processing answer.
- *  @param[in] answer_count The number of answer parameters.
- */
-void answer_call(ipc_callid_t callid, int result, ipc_call_t * answer, int answer_count);
-
-/** Creates bidirectional connection with the needed module service and registers the message receiver.
- *  @param[in] need The needed module service.
- *  @param[in] arg1 The first parameter.
- *  @param[in] arg2 The second parameter.
- *  @param[in] arg3 The third parameter.
- *  @param[in] client_receiver The message receiver.
- *  @returns The phone of the needed service.
- *  @returns Other error codes as defined for the ipc_connect_to_me() function.
- */
-int bind_service(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver);
-
-/** Creates bidirectional connection with the needed module service and registers the message receiver.
- *  @param[in] need The needed module service.
- *  @param[in] arg1 The first parameter.
- *  @param[in] arg2 The second parameter.
- *  @param[in] arg3 The third parameter.
- *  @param[in] client_receiver The message receiver.
- *  @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0).
- *  @returns The phone of the needed service.
- *  @returns ETIMEOUT if the connection timeouted.
- *  @returns Other error codes as defined for the ipc_connect_to_me() function.
- */
-int bind_service_timeout(services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout);
-
-/** Connects to the needed module.
- *  @param[in] need The needed module service.
- *  @returns The phone of the needed service.
- */
-int connect_to_service(services_t need);
-
-/** Connects to the needed module.
- *  @param[in] need The needed module service.
- *  @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0).
- *  @returns The phone of the needed service.
- *  @returns ETIMEOUT if the connection timeouted.
- */
-int connect_to_service_timeout(services_t need, suseconds_t timeout);
-
-/** Receives data from the other party.
- *  The received data buffer is allocated and returned.
- *  @param[out] data The data buffer to be filled.
- *  @param[out] length The buffer length.
- *  @returns EOK on success.
- *  @returns EBADMEM if the data or the length parameter is NULL.
- *  @returns EINVAL if the client does not send data.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns Other error codes as defined for the async_data_write_finalize() function.
- */
-int data_receive(void ** data, size_t * length);
-
-/** Replies the data to the other party.
- *  @param[in] data The data buffer to be sent.
- *  @param[in] data_length The buffer length.
- *  @returns EOK on success.
- *  @returns EINVAL if the client does not expect the data.
- *  @returns EOVERFLOW if the client does not expect all the data. Only partial data are transfered.
- *  @returns Other error codes as defined for the async_data_read_finalize() function.
- */
-int data_reply(void * data, size_t data_length);
-
-/** Refreshes answer structure and parameters count.
- *  Erases all attributes.
- *  @param[in,out] answer The message processing answer structure.
- *  @param[in,out] answer_count The number of answer parameters.
- */
-void refresh_answer(ipc_call_t * answer, int * answer_count);
-
-#endif
-
-/** @}
- */
Index: uspace/srv/net/net/Makefile
===================================================================
--- uspace/srv/net/net/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/net/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,50 +28,20 @@
 #
 
-NET_BASE = ..
 USPACE_PREFIX = ../../..
 ROOT_PATH = $(USPACE_PREFIX)/..
+LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBSOCKET_PREFIX)/include
 
 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
 
-BINARY = net
-
 -include $(COMMON_MAKEFILE)
 -include $(CONFIG_MAKEFILE)
 
+BINARY = net
+
 SOURCES = \
 	net.c \
-	$(NET_BASE)/module.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/netif/netif_remote.c \
-	$(NET_BASE)/structures/char_map.c \
-	$(NET_BASE)/structures/measured_strings.c \
-	$(NET_BASE)/structures/module_map.c \
-	$(NET_BASE)/structures/packet/packet.c \
-	$(NET_BASE)/structures/packet/packet_client.c \
-	$(NET_BASE)/structures/packet/packet_server.c
-
-ifeq ($(CONFIG_NETWORKING),module)
-	SOURCES += \
-		net_bundle.c \
-		$(NET_BASE)/checksum.c \
-		$(NET_BASE)/inet.c \
-		$(NET_BASE)/il/arp/arp.c \
-		$(NET_BASE)/il/ip/ip.c \
-		$(NET_BASE)/il/ip/ip_client.c \
-		$(NET_BASE)/socket/socket_core.c \
-		$(NET_BASE)/tl/icmp/icmp.c \
-		$(NET_BASE)/tl/icmp/icmp_client.c \
-		$(NET_BASE)/tl/tcp/tcp.c \
-		$(NET_BASE)/tl/tl_common.c \
-		$(NET_BASE)/tl/udp/udp.c \
-		$(NET_BASE)/structures/dynamic_fifo.c
-endif
-
-ifeq ($(CONFIG_NETWORKING),modular)
-	SOURCES += \
-		net_standalone.c \
-		$(NET_BASE)/il/ip/ip_remote.c
-endif
+	net_standalone.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/net/net.c
===================================================================
--- uspace/srv/net/net/net.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/net/net.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,9 +28,10 @@
 
 /** @addtogroup net
- *  @{
+ * @{
  */
 
 /** @file
- *  Networking subsystem central module implementation.
+ * Networking subsystem central module implementation.
+ *
  */
 
@@ -46,263 +47,582 @@
 #include <ipc/services.h>
 
-#include "../err.h"
-#include "../messages.h"
-#include "../modules.h"
-
-#include "../structures/char_map.h"
-#include "../structures/generic_char_map.h"
-#include "../structures/measured_strings.h"
-#include "../structures/module_map.h"
-#include "../structures/packet/packet.h"
-
-#include "../il/il_messages.h"
-#include "../include/device.h"
-#include "../include/netif_interface.h"
-#include "../include/nil_interface.h"
-#include "../include/net_interface.h"
-#include "../include/ip_interface.h"
+#include <net_err.h>
+#include <net_messages.h>
+#include <net_modules.h>
+#include <adt/char_map.h>
+#include <adt/generic_char_map.h>
+#include <adt/measured_strings.h>
+#include <adt/module_map.h>
+#include <packet/packet.h>
+#include <il_messages.h>
+#include <netif_remote.h>
+#include <net_device.h>
+#include <nil_interface.h>
+#include <net_interface.h>
+#include <ip_interface.h>
+#include <net_net_messages.h>
 
 #include "net.h"
-#include "net_messages.h"
+
+/** Networking module name.
+ *
+ */
+#define NAME  "net"
 
 /** File read buffer size.
- */
-#define BUFFER_SIZE	256
-
-/** Networking module name.
- */
-#define NAME	"Networking"
+ *
+ */
+#define BUFFER_SIZE  256
 
 /** Networking module global data.
- */
-net_globals_t	net_globals;
-
-/** Generates new system-unique device identifier.
- *  @returns The system-unique devic identifier.
- */
-device_id_t generate_new_device_id(void);
-
-/** Prints the module name.
- *  @see NAME
- */
-void module_print_name(void);
-
-/** Starts the networking module.
- *  Initializes the client connection serving function, initializes the module, registers the module service and starts the async manager, processing IPC messages in an infinite loop.
- *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
- *  @returns EOK on successful module termination.
- *  @returns Other error codes as defined for the net_initialize() function.
- *  @returns Other error codes as defined for the REGISTER_ME() macro function.
- */
-int module_start(async_client_conn_t client_connection);
-
-/** Returns the configured values.
- *  The network interface configuration is searched first.
- *  @param[in] netif_conf The network interface configuration setting.
- *  @param[out] configuration The found configured values.
- *  @param[in] count The desired settings count.
- *  @param[out] data The found configuration settings data.
- *  @returns EOK.
- */
-int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data);
-
-/** Initializes the networking module.
- *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int net_initialize(async_client_conn_t client_connection);
-
-/** \todo
- */
-int parse_line(measured_strings_ref configuration, char * line);
-
-/** Reads the networking subsystem global configuration.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the add_configuration() function.
- */
-int read_configuration(void);
-
-/** \todo
- */
-int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration);
-
-/** Reads the network interface specific configuration.
- *  @param[in] name The network interface name.
- *  @param[in,out] netif The network interface structure.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the add_configuration() function.
- */
-int read_netif_configuration(const char * name, netif_ref netif);
-
-/** Starts the network interface according to its configuration.
- *  Registers the network interface with the subsystem modules.
- *  Starts the needed subsystem modules.
- *  @param[in] netif The network interface specific data.
- *  @returns EOK on success.
- *  @returns EINVAL if there are some settings missing.
- *  @returns ENOENT if the internet protocol module is not known.
- *  @returns Other error codes as defined for the netif_probe_req() function.
- *  @returns Other error codes as defined for the nil_device_req() function.
- *  @returns Other error codes as defined for the needed internet layer registering function.
- */
-int start_device(netif_ref netif);
-
-/** Reads the configuration and starts all network interfaces.
- *  @returns EOK on success.
- *  @returns EXDEV if there is no available system-unique device identifier.
- *  @returns EINVAL if any of the network interface names are not configured.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns Other error codes as defined for the read_configuration() function.
- *  @returns Other error codes as defined for the read_netif_configuration() function.
- *  @returns Other error codes as defined for the start_device() function.
- */
-int startup(void);
-
-GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t)
-
-DEVICE_MAP_IMPLEMENT(netifs, netif_t)
-
-int add_configuration(measured_strings_ref configuration, const char * name, const char * value){
-	ERROR_DECLARE;
-
-	measured_string_ref setting;
-
-	setting = measured_string_create_bulk(value, 0);
-	if(! setting){
+ *
+ */
+net_globals_t net_globals;
+
+GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t);
+DEVICE_MAP_IMPLEMENT(netifs, netif_t);
+
+/** Add the configured setting to the configuration map.
+ *
+ * @param[in] configuration The configuration map.
+ * @param[in] name          The setting name.
+ * @param[in] value         The setting value.
+ *
+ * @returns EOK on success.
+ * @returns ENOMEM if there is not enough memory left.
+ *
+ */
+int add_configuration(measured_strings_ref configuration, const char *name,
+    const char *value)
+{
+	ERROR_DECLARE;
+	
+	measured_string_ref setting =
+	    measured_string_create_bulk(value, 0);
+	
+	if (!setting)
 		return ENOMEM;
-	}
-	// add the configuration setting
-	if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){
+	
+	/* Add the configuration setting */
+	if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))) {
 		free(setting);
 		return ERROR_CODE;
 	}
-	return EOK;
-}
-
-device_id_t generate_new_device_id(void){
+	
+	return EOK;
+}
+
+/** Generate new system-unique device identifier.
+ *
+ * @returns The system-unique devic identifier.
+ *
+ */
+static device_id_t generate_new_device_id(void)
+{
 	return device_assign_devno();
 }
 
-void module_print_name(void){
-	printf("%s", NAME);
-}
-
-int module_start(async_client_conn_t client_connection){
-	ERROR_DECLARE;
-
-	ipcarg_t phonehash;
-
-	async_set_client_connection(client_connection);
-	ERROR_PROPAGATE(pm_init());
-	if(ERROR_OCCURRED(net_initialize(client_connection))
-		|| ERROR_OCCURRED(REGISTER_ME(SERVICE_NETWORKING, &phonehash))){
-		pm_destroy();
+static int parse_line(measured_strings_ref configuration, char *line)
+{
+	ERROR_DECLARE;
+	
+	/* From the beginning */
+	char *name = line;
+	
+	/* Skip comments and blank lines */
+	if ((*name == '#') || (*name == '\0'))
+		return EOK;
+	
+	/* Skip spaces */
+	while (isspace(*name))
+		name++;
+	
+	/* Remember the name start */
+	char *value = name;
+	
+	/* Skip the name */
+	while (isalnum(*value) || (*value == '_'))
+		value++;
+	
+	if (*value == '=') {
+		/* Terminate the name */
+		*value = '\0';
+	} else {
+		/* Terminate the name */
+		*value = '\0';
+		
+		/* Skip until '=' */
+		value++;
+		while ((*value) && (*value != '='))
+			value++;
+		
+		/* Not found? */
+		if (*value != '=')
+			return EINVAL;
+	}
+	
+	value++;
+	
+	/* Skip spaces */
+	while (isspace(*value))
+		value++;
+	
+	/* Create a bulk measured string till the end */
+	measured_string_ref setting =
+	    measured_string_create_bulk(value, 0);
+	if (!setting)
+		return ENOMEM;
+	
+	/* Add the configuration setting */
+	if (ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))) {
+		free(setting);
 		return ERROR_CODE;
 	}
-
-	async_manager();
-
-	pm_destroy();
-	return EOK;
-}
-
-int net_connect_module(services_t service){
-	return EOK;
-}
-
-void net_free_settings(measured_string_ref settings, char * data){
-}
-
-int net_get_conf(measured_strings_ref netif_conf, measured_string_ref configuration, size_t count, char ** data){
-	measured_string_ref setting;
-	size_t index;
-
-	if(data){
-		*data = NULL;
-	}
-
-	for(index = 0; index < count; ++ index){
-		setting = measured_strings_find(netif_conf, configuration[index].value, 0);
-		if(! setting){
-			setting = measured_strings_find(&net_globals.configuration, configuration[index].value, 0);
+	
+	return EOK;
+}
+
+static int read_configuration_file(const char *directory, const char *filename,
+    measured_strings_ref configuration)
+{
+	ERROR_DECLARE;
+	
+	printf("%s: Reading configuration file %s/%s\n", NAME, directory, filename);
+	
+	/* Construct the full filename */
+	char line[BUFFER_SIZE];
+	if (snprintf(line, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE)
+		return EOVERFLOW;
+	
+	/* Open the file */
+	FILE *cfg = fopen(line, "r");
+	if (!cfg)
+		return ENOENT;
+	
+	/*
+	 * Read the configuration line by line
+	 * until an error or the end of file
+	 */
+	unsigned int line_number = 0;
+	size_t index = 0;
+	while ((!ferror(cfg)) && (!feof(cfg))) {
+		int read = fgetc(cfg);
+		if ((read > 0) && (read != '\n') && (read != '\r')) {
+			if (index >= BUFFER_SIZE) {
+				line[BUFFER_SIZE - 1] = '\0';
+				fprintf(stderr, "%s: Configuration line %u too long: %s\n",
+				    NAME, line_number, line);
+				
+				/* No space left in the line buffer */
+				return EOVERFLOW;
+			} else {
+				/* Append the character */
+				line[index] = (char) read;
+				index++;
+			}
+		} else {
+			/* On error or new line */
+			line[index] = '\0';
+			line_number++;
+			if (ERROR_OCCURRED(parse_line(configuration, line)))
+				fprintf(stderr, "%s: Configuration error on line %u: %s\n",
+				    NAME, line_number, line);
+			
+			index = 0;
 		}
-		if(setting){
-			configuration[index].length = setting->length;
-			configuration[index].value = setting->value;
-		}else{
-			configuration[index].length = 0;
-			configuration[index].value = NULL;
-		}
-	}
-	return EOK;
-}
-
-int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){
-	if(!(configuration && (count > 0))){
-		return EINVAL;
-	}
-
-	return net_get_conf(NULL, * configuration, count, data);
-}
-
-int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){
-	netif_ref netif;
-
-	if(!(configuration && (count > 0))){
-		return EINVAL;
-	}
-
-	netif = netifs_find(&net_globals.netifs, device_id);
-	if(netif){
-		return net_get_conf(&netif->configuration, * configuration, count, data);
-	}else{
-		return net_get_conf(NULL, * configuration, count, data);
-	}
-}
-
-int net_initialize(async_client_conn_t client_connection){
-	ERROR_DECLARE;
-
+	}
+	
+	fclose(cfg);
+	return EOK;
+}
+
+/** Read the network interface specific configuration.
+ *
+ * @param[in]     name  The network interface name.
+ * @param[in,out] netif The network interface structure.
+ *
+ * @returns EOK on success.
+ * @returns Other error codes as defined for the add_configuration() function.
+ *
+ */
+static int read_netif_configuration(const char *name, netif_t *netif)
+{
+	return read_configuration_file(CONF_DIR, name, &netif->configuration);
+}
+
+/** Read the networking subsystem global configuration.
+ *
+ * @returns EOK on success.
+ * @returns Other error codes as defined for the add_configuration() function.
+ *
+ */
+static int read_configuration(void)
+{
+	return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE,
+	    &net_globals.configuration);
+}
+
+/** Initialize the networking module.
+ *
+ * @param[in] client_connection The client connection processing
+ *                              function. The module skeleton propagates
+ *                              its own one.
+ *
+ * @returns EOK on success.
+ * @returns ENOMEM if there is not enough memory left.
+ *
+ */
+static int net_initialize(async_client_conn_t client_connection)
+{
+	ERROR_DECLARE;
+	
 	netifs_initialize(&net_globals.netifs);
 	char_map_initialize(&net_globals.netif_names);
 	modules_initialize(&net_globals.modules);
 	measured_strings_initialize(&net_globals.configuration);
-
-	// TODO dynamic configuration
+	
+	// TODO: dynamic configuration
 	ERROR_PROPAGATE(read_configuration());
-
-	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service));
-	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service));
-	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service));
-	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service));
-
-	// build specific initialization
+	
+	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
+	    LO_NAME, LO_FILENAME, SERVICE_LO, 0, connect_to_service));
+	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
+	    DP8390_NAME, DP8390_FILENAME, SERVICE_DP8390, 0, connect_to_service));
+	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
+	    ETHERNET_NAME, ETHERNET_FILENAME, SERVICE_ETHERNET, 0,
+	    connect_to_service));
+	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules,
+	    NILDUMMY_NAME, NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0,
+	    connect_to_service));
+	
+	/* Build specific initialization */
 	return net_initialize_build(client_connection);
 }
 
-int net_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	ERROR_DECLARE;
-
+/** Start the networking module.
+ *
+ * Initializes the client connection serving function,
+ * initializes the module, registers the module service
+ * and starts the async manager, processing IPC messages
+ * in an infinite loop.
+ *
+ * @param[in] client_connection The client connection
+ *                              processing function. The
+ *                              module skeleton propagates
+ *                              its own one.
+ *
+ * @returns EOK on successful module termination.
+ * @returns Other error codes as defined for the net_initialize() function.
+ * @returns Other error codes as defined for the REGISTER_ME() macro function.
+ *
+ */
+static int net_module_start(async_client_conn_t client_connection)
+{
+	ERROR_DECLARE;
+	
+	async_set_client_connection(client_connection);
+	ERROR_PROPAGATE(pm_init());
+	
+	ipcarg_t phonehash;
+	
+	if (ERROR_OCCURRED(net_initialize(client_connection))
+	    || ERROR_OCCURRED(REGISTER_ME(SERVICE_NETWORKING, &phonehash))){
+		pm_destroy();
+		return ERROR_CODE;
+	}
+	
+	async_manager();
+	
+	pm_destroy();
+	return EOK;
+}
+
+/** Return the configured values.
+ *
+ * The network interface configuration is searched first.
+ &
+ * @param[in]  netif_conf    The network interface configuration setting.
+ * @param[out] configuration The found configured values.
+ * @param[in]  count         The desired settings count.
+ * @param[out] data          The found configuration settings data.
+ *
+ * @returns EOK.
+ *
+ */
+static int net_get_conf(measured_strings_ref netif_conf,
+    measured_string_ref configuration, size_t count, char **data)
+{
+	if (data)
+		*data = NULL;
+	
+	size_t index;
+	for (index = 0; index < count; index++) {
+		measured_string_ref setting =
+		    measured_strings_find(netif_conf, configuration[index].value, 0);
+		if (!setting)
+			setting = measured_strings_find(&net_globals.configuration,
+			    configuration[index].value, 0);
+		
+		if (setting) {
+			configuration[index].length = setting->length;
+			configuration[index].value = setting->value;
+		} else {
+			configuration[index].length = 0;
+			configuration[index].value = NULL;
+		}
+	}
+	
+	return EOK;
+}
+
+int net_get_conf_req(int net_phone, measured_string_ref *configuration,
+    size_t count, char **data)
+{
+	if (!(configuration && (count > 0)))
+		return EINVAL;
+	
+	return net_get_conf(NULL, *configuration, count, data);
+}
+
+int net_get_device_conf_req(int net_phone, device_id_t device_id,
+    measured_string_ref *configuration, size_t count, char **data)
+{
+	if ((!configuration) || (count == 0))
+		return EINVAL;
+
+	netif_t *netif = netifs_find(&net_globals.netifs, device_id);
+	if (netif)
+		return net_get_conf(&netif->configuration, *configuration, count, data);
+	else
+		return net_get_conf(NULL, *configuration, count, data);
+}
+
+void net_free_settings(measured_string_ref settings, char *data)
+{
+}
+
+/** Start the network interface according to its configuration.
+ *
+ * Register the network interface with the subsystem modules.
+ * Start the needed subsystem modules.
+ *
+ * @param[in] netif The network interface specific data.
+ *
+ * @returns EOK on success.
+ * @returns EINVAL if there are some settings missing.
+ * @returns ENOENT if the internet protocol module is not known.
+ * @returns Other error codes as defined for the netif_probe_req() function.
+ * @returns Other error codes as defined for the nil_device_req() function.
+ * @returns Other error codes as defined for the needed internet layer
+ *          registering function.
+ *
+ */
+static int start_device(netif_t *netif)
+{
+	ERROR_DECLARE;
+	
+	/* Mandatory netif */
+	measured_string_ref setting =
+	    measured_strings_find(&netif->configuration, CONF_NETIF, 0);
+	
+	netif->driver = get_running_module(&net_globals.modules, setting->value);
+	if (!netif->driver) {
+		fprintf(stderr, "%s: Failed to start network interface driver '%s'\n",
+		    NAME, setting->value);
+		return EINVAL;
+	}
+	
+	/* Optional network interface layer */
+	setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);
+	if (setting) {
+		netif->nil = get_running_module(&net_globals.modules, setting->value);
+		if (!netif->nil) {
+			fprintf(stderr, "%s: Failed to start network interface layer '%s'\n",
+			    NAME, setting->value);
+			return EINVAL;
+		}
+	} else
+		netif->nil = NULL;
+	
+	/* Mandatory internet layer */
+	setting = measured_strings_find(&netif->configuration, CONF_IL, 0);
+	netif->il = get_running_module(&net_globals.modules, setting->value);
+	if (!netif->il) {
+		fprintf(stderr, "%s: Failed to start internet layer '%s'\n",
+		    NAME, setting->value);
+		return EINVAL;
+	}
+	
+	/* Hardware configuration */
+	setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0);
+	int irq = setting ? strtol(setting->value, NULL, 10) : 0;
+	
+	setting = measured_strings_find(&netif->configuration, CONF_IO, 0);
+	int io = setting ? strtol(setting->value, NULL, 16) : 0;
+	
+	ERROR_PROPAGATE(netif_probe_req_remote(netif->driver->phone, netif->id, irq, io));
+	
+	/* Network interface layer startup */
+	services_t internet_service;
+	if (netif->nil) {
+		setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);
+		if (!setting)
+			setting = measured_strings_find(&net_globals.configuration,
+			    CONF_MTU, 0);
+		
+		int mtu = setting ? strtol(setting->value, NULL, 10) : 0;
+		
+		ERROR_PROPAGATE(nil_device_req(netif->nil->phone, netif->id, mtu,
+		    netif->driver->service));
+		
+		internet_service = netif->nil->service;
+	} else
+		internet_service = netif->driver->service;
+	
+	/* Inter-network layer startup */
+	switch (netif->il->service) {
+		case SERVICE_IP:
+			ERROR_PROPAGATE(ip_device_req(netif->il->phone, netif->id,
+			    internet_service));
+			break;
+		default:
+			return ENOENT;
+	}
+	
+	ERROR_PROPAGATE(netif_start_req_remote(netif->driver->phone, netif->id));
+	return EOK;
+}
+
+/** Read the configuration and start all network interfaces.
+ *
+ * @returns EOK on success.
+ * @returns EXDEV if there is no available system-unique device identifier.
+ * @returns EINVAL if any of the network interface names are not configured.
+ * @returns ENOMEM if there is not enough memory left.
+ * @returns Other error codes as defined for the read_configuration()
+ *          function.
+ * @returns Other error codes as defined for the read_netif_configuration()
+ *          function.
+ * @returns Other error codes as defined for the start_device() function.
+ *
+ */
+static int startup(void)
+{
+	ERROR_DECLARE;
+	
+	const char *conf_files[] = {"lo", "ne2k"};
+	size_t count = sizeof(conf_files) / sizeof(char *);
+	
+	size_t i;
+	for (i = 0; i < count; i++) {
+		netif_t *netif = (netif_t *) malloc(sizeof(netif_t));
+		if (!netif)
+			return ENOMEM;
+		
+		netif->id = generate_new_device_id();
+		if (!netif->id)
+			return EXDEV;
+		
+		ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration));
+		
+		/* Read configuration files */
+		if (ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))) {
+			measured_strings_destroy(&netif->configuration);
+			free(netif);
+			return ERROR_CODE;
+		}
+		
+		/* Mandatory name */
+		measured_string_ref setting =
+		    measured_strings_find(&netif->configuration, CONF_NAME, 0);
+		if (!setting) {
+			fprintf(stderr, "%s: Network interface name is missing\n", NAME);
+			measured_strings_destroy(&netif->configuration);
+			free(netif);
+			return EINVAL;
+		}
+		netif->name = setting->value;
+		
+		/* Add to the netifs map */
+		int index = netifs_add(&net_globals.netifs, netif->id, netif);
+		if (index < 0) {
+			measured_strings_destroy(&netif->configuration);
+			free(netif);
+			return index;
+		}
+		
+		/*
+		 * Add to the netif names map and start network interfaces
+		 * and needed modules.
+		 */
+		if ((ERROR_OCCURRED(char_map_add(&net_globals.netif_names,
+		    netif->name, 0, index))) || (ERROR_OCCURRED(start_device(netif)))) {
+			measured_strings_destroy(&netif->configuration);
+			netifs_exclude_index(&net_globals.netifs, index);
+			return ERROR_CODE;
+		}
+		
+		/* Increment modules' usage */
+		netif->driver->usage++;
+		if (netif->nil)
+			netif->nil->usage++;
+		netif->il->usage++;
+		
+		printf("%s: Network interface started (name: %s, id: %d, driver: %s, "
+		    "nil: %s, il: %s)\n", NAME, netif->name, netif->id,
+		    netif->driver->name,  netif->nil ? netif->nil->name : "[none]",
+		    netif->il->name);
+	}
+	
+	return EOK;
+}
+
+/** Process the networking message.
+ *
+ * @param[in] callid        The message identifier.
+ * @param[in] call          The message parameters.
+ * @param[out] answer       The message answer parameters.
+ * @param[out] answer_count The last parameter for the actual answer
+ *                          in the answer parameter.
+ *
+ * @returns EOK on success.
+ * @returns ENOTSUP if the message is not known.
+ *
+ * @see net_interface.h
+ * @see IS_NET_NET_MESSAGE()
+ *
+ */
+int net_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer,
+    int *answer_count)
+{
+	ERROR_DECLARE;
+	
 	measured_string_ref strings;
-	char * data;
-
+	char *data;
+	
 	*answer_count = 0;
-	switch(IPC_GET_METHOD(*call)){
+	switch (IPC_GET_METHOD(*call)) {
 		case IPC_M_PHONE_HUNGUP:
 			return EOK;
 		case NET_NET_GET_DEVICE_CONF:
-			ERROR_PROPAGATE(measured_strings_receive(&strings, &data, IPC_GET_COUNT(call)));
-			net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings, IPC_GET_COUNT(call), NULL);
-			// strings should not contain received data anymore
+			ERROR_PROPAGATE(measured_strings_receive(&strings, &data,
+			    IPC_GET_COUNT(call)));
+			net_get_device_conf_req(0, IPC_GET_DEVICE(call), &strings,
+			    IPC_GET_COUNT(call), NULL);
+			
+			/* Strings should not contain received data anymore */
 			free(data);
+			
 			ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
 			free(strings);
 			return ERROR_CODE;
 		case NET_NET_GET_CONF:
-			ERROR_PROPAGATE(measured_strings_receive(&strings, &data, IPC_GET_COUNT(call)));
+			ERROR_PROPAGATE(measured_strings_receive(&strings, &data,
+			    IPC_GET_COUNT(call)));
 			net_get_conf_req(0, &strings, IPC_GET_COUNT(call), NULL);
-			// strings should not contain received data anymore
+			
+			/* Strings should not contain received data anymore */
 			free(data);
+			
 			ERROR_CODE = measured_strings_reply(strings, IPC_GET_COUNT(call));
 			free(strings);
@@ -314,267 +634,49 @@
 }
 
-int parse_line(measured_strings_ref configuration, char * line){
-	ERROR_DECLARE;
-
-	measured_string_ref setting;
-	char * name;
-	char * value;
-
-	// from the beginning
-	name = line;
-
-	// skip comments and blank lines
-	if((*name == '#') || (*name == '\0')){
-		return EOK;
-	}
-	// skip spaces
-	while(isspace(*name)){
-		++ name;
-	}
-
-	// remember the name start
-	value = name;
-	// skip the name
-	while(isalnum(*value) || (*value == '_')){
-		// make uppercase
-//		*value = toupper(*value);
-		++ value;
-	}
-
-	if(*value == '='){
-		// terminate the name
-		*value = '\0';
-	}else{
-		// terminate the name
-		*value = '\0';
-		// skip until '='
-		++ value;
-		while((*value) && (*value != '=')){
-			++ value;
-		}
-		// not found?
-		if(*value != '='){
-			return EINVAL;
-		}
-	}
-
-	++ value;
-	// skip spaces
-	while(isspace(*value)){
-		++ value;
-	}
-	// create a bulk measured string till the end
-	setting = measured_string_create_bulk(value, 0);
-	if(! setting){
-		return ENOMEM;
-	}
-
-	// add the configuration setting
-	if(ERROR_OCCURRED(measured_strings_add(configuration, name, 0, setting))){
-		free(setting);
+/** Default thread for new connections.
+ *
+ * @param[in] iid The initial message identifier.
+ * @param[in] icall The initial message call structure.
+ *
+ */
+static void net_client_connection(ipc_callid_t iid, ipc_call_t *icall)
+{
+	/*
+	 * Accept the connection
+	 *  - Answer the first IPC_M_CONNECT_ME_TO call.
+	 */
+	ipc_answer_0(iid, EOK);
+	
+	while (true) {
+		/* Clear the answer structure */
+		ipc_call_t answer;
+		int answer_count;
+		refresh_answer(&answer, &answer_count);
+		
+		/* Fetch the next message */
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		/* Process the message */
+		int res = net_module_message(callid, &call, &answer, &answer_count);
+		
+		/* End if said to either by the message or the processing result */
+		if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
+			return;
+		
+		/* Answer the message */
+		answer_call(callid, res, &answer, answer_count);
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	ERROR_DECLARE;
+	
+	if (ERROR_OCCURRED(net_module_start(net_client_connection))) {
+		fprintf(stderr, "%s: net_module_start error %i\n", NAME, ERROR_CODE);
 		return ERROR_CODE;
 	}
-	return EOK;
-}
-
-int read_configuration(void){
-	// read the general configuration file
-	return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE, &net_globals.configuration);
-}
-
-int read_configuration_file(const char * directory, const char * filename, measured_strings_ref configuration){
-	ERROR_DECLARE;
-
-	size_t index = 0;
-	char line[BUFFER_SIZE];
-	FILE * cfg;
-	int read;
-	int line_number = 0;
-
-	// construct the full filename
-	printf("Reading file %s/%s\n", directory, filename);
-	if(snprintf(line, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE){
-		return EOVERFLOW;
-	}
-	// open the file
-	cfg = fopen(line, "r");
-	if(! cfg){
-		return ENOENT;
-	}
-
-	// read the configuration line by line
-	// until an error or the end of file
-	while((! ferror(cfg)) && (! feof(cfg))){
-		read = fgetc(cfg);
-		if((read > 0) && (read != '\n') && (read != '\r')){
-			if(index >= BUFFER_SIZE){
-				line[BUFFER_SIZE - 1] = '\0';
-				printf("line %d too long: %s\n", line_number, line);
-				// no space left in the line buffer
-				return EOVERFLOW;
-			}else{
-				// append the character
-				line[index] = (char) read;
-				++ index;
-			}
-		}else{
-			// on error or new line
-			line[index] = '\0';
-			++ line_number;
-			if(ERROR_OCCURRED(parse_line(configuration, line))){
-				printf("error on line %d: %s\n", line_number, line);
-				//fclose(cfg);
-				//return ERROR_CODE;
-			}
-			index = 0;
-		}
-	}
-	fclose(cfg);
-	return EOK;
-}
-
-int read_netif_configuration(const char * name, netif_ref netif){
-	// read the netif configuration file
-	return read_configuration_file(CONF_DIR, name, &netif->configuration);
-}
-
-int start_device(netif_ref netif){
-	ERROR_DECLARE;
-
-	measured_string_ref setting;
-	services_t internet_service;
-	int irq;
-	int io;
-	int mtu;
-
-	// mandatory netif
-	setting = measured_strings_find(&netif->configuration, CONF_NETIF, 0);
-	netif->driver = get_running_module(&net_globals.modules, setting->value);
-	if(! netif->driver){
-		printf("Failed to start the network interface driver %s\n", setting->value);
-		return EINVAL;
-	}
-
-	// optional network interface layer
-	setting = measured_strings_find(&netif->configuration, CONF_NIL, 0);
-	if(setting){
-		netif->nil = get_running_module(&net_globals.modules, setting->value);
-		if(! netif->nil){
-			printf("Failed to start the network interface layer %s\n", setting->value);
-			return EINVAL;
-		}
-	}else{
-		netif->nil = NULL;
-	}
-
-	// mandatory internet layer
-	setting = measured_strings_find(&netif->configuration, CONF_IL, 0);
-	netif->il = get_running_module(&net_globals.modules, setting->value);
-	if(! netif->il){
-		printf("Failed to start the internet layer %s\n", setting->value);
-		return EINVAL;
-	}
-
-	// hardware configuration
-	setting = measured_strings_find(&netif->configuration, CONF_IRQ, 0);
-	irq = setting ? strtol(setting->value, NULL, 10) : 0;
-	setting = measured_strings_find(&netif->configuration, CONF_IO, 0);
-	io = setting ? strtol(setting->value, NULL, 16) : 0;
-	ERROR_PROPAGATE(netif_probe_req(netif->driver->phone, netif->id, irq, io));
-
-	// network interface layer startup
-	if(netif->nil){
-		setting = measured_strings_find(&netif->configuration, CONF_MTU, 0);
-		if(! setting){
-			setting = measured_strings_find(&net_globals.configuration, CONF_MTU, 0);
-		}
-		mtu = setting ? strtol(setting->value, NULL, 10) : 0;
-		ERROR_PROPAGATE(nil_device_req(netif->nil->phone, netif->id, mtu, netif->driver->service));
-		internet_service = netif->nil->service;
-	}else{
-		internet_service = netif->driver->service;
-	}
-
-	// inter-network layer startup
-	switch(netif->il->service){
-		case SERVICE_IP:
-			ERROR_PROPAGATE(ip_device_req(netif->il->phone, netif->id, internet_service));
-			break;
-		default:
-			return ENOENT;
-	}
-	ERROR_PROPAGATE(netif_start_req(netif->driver->phone, netif->id));
-	return EOK;
-}
-
-int startup(void){
-	ERROR_DECLARE;
-
-#ifdef CONFIG_NETIF_DP8390
-	const char * conf_files[] = {"lo", "ne2k"};
-#else
-	const char * conf_files[] = {"lo"};
-#endif
-
-	int count = sizeof(conf_files) / sizeof(char *);
-	int index;
-	netif_ref netif;
-	int i;
-	measured_string_ref setting;
-
-	for(i = 0; i < count; ++ i){
-		netif = (netif_ref) malloc(sizeof(netif_t));
-		if(! netif){
-			return ENOMEM;
-		}
-
-		netif->id = generate_new_device_id();
-		if(! netif->id){
-			return EXDEV;
-		}
-		ERROR_PROPAGATE(measured_strings_initialize(&netif->configuration));
-
-		// read configuration files
-		if(ERROR_OCCURRED(read_netif_configuration(conf_files[i], netif))){
-			measured_strings_destroy(&netif->configuration);
-			free(netif);
-			return ERROR_CODE;
-		}
-
-		// mandatory name
-		setting = measured_strings_find(&netif->configuration, CONF_NAME, 0);
-		if(! setting){
-			printf("The name is missing\n");
-			measured_strings_destroy(&netif->configuration);
-			free(netif);
-			return EINVAL;
-		}
-		netif->name = setting->value;
-
-		// add to the netifs map
-		index = netifs_add(&net_globals.netifs, netif->id, netif);
-		if(index < 0){
-			measured_strings_destroy(&netif->configuration);
-			free(netif);
-			return index;
-		}
-
-		// add to the netif names map
-		if(ERROR_OCCURRED(char_map_add(&net_globals.netif_names, netif->name, 0, index))
-		// start network interfaces and needed modules
-			|| ERROR_OCCURRED(start_device(netif))){
-			measured_strings_destroy(&netif->configuration);
-			netifs_exclude_index(&net_globals.netifs, index);
-			return ERROR_CODE;
-		}
-
-		// increment modules' usage
-		++ netif->driver->usage;
-		if(netif->nil){
-			++ netif->nil->usage;
-		}
-		++ netif->il->usage;
-		printf("New network interface started:\n\tname\t= %s\n\tid\t= %d\n\tdriver\t= %s\n\tnil\t= %s\n\til\t= %s\n", netif->name, netif->id, netif->driver->name, netif->nil ? netif->nil->name : NULL, netif->il->name);
-	}
+	
 	return EOK;
 }
Index: uspace/srv/net/net/net.h
===================================================================
--- uspace/srv/net/net/net.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/net/net.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,9 +28,10 @@
 
 /** @addtogroup net
- *  @{
+ * @{
  */
 
 /** @file
- *  Networking subsystem central module.
+ * Networking subsystem central module.
+ *
  */
 
@@ -40,206 +41,100 @@
 #include <ipc/ipc.h>
 
-#include "../include/device.h"
-
-#include "../structures/char_map.h"
-#include "../structures/generic_char_map.h"
-#include "../structures/measured_strings.h"
-#include "../structures/module_map.h"
-#include "../structures/packet/packet.h"
+#include <net_device.h>
+#include <adt/char_map.h>
+#include <adt/generic_char_map.h>
+#include <adt/measured_strings.h>
+#include <adt/module_map.h>
+#include <packet/packet.h>
 
 /** @name Modules definitions
+ * @{
  */
-/*@{*/
 
-/** DP8390 network interface module full path filename.
+#define DP8390_FILENAME  "/srv/dp8390"
+#define DP8390_NAME      "dp8390"
+
+#define ETHERNET_FILENAME  "/srv/eth"
+#define ETHERNET_NAME      "eth"
+
+#define IP_FILENAME  "/srv/ip"
+#define IP_NAME      "ip"
+
+#define LO_FILENAME  "/srv/lo"
+#define LO_NAME      "lo"
+
+#define NILDUMMY_FILENAME  "/srv/nildummy"
+#define NILDUMMY_NAME      "nildummy"
+
+/** @}
  */
-#define DP8390_FILENAME		"/srv/dp8390"
-
-/** DP8390 network interface module name.
- */
-#define DP8390_NAME			"dp8390"
-
-/** Ethernet module full path filename.
- */
-#define ETHERNET_FILENAME	"/srv/eth"
-
-/** Ethernet module name.
- */
-#define ETHERNET_NAME		"ethernet"
-
-/** IP module full path filename.
- */
-#define IP_FILENAME			"/srv/ip"
-
-/** IP module name.
- */
-#define IP_NAME				"ip"
-
-/** Loopback network interface module full path filename.
- */
-#define LO_FILENAME			"/srv/lo"
-
-/** Loopback network interface module name.
- */
-#define LO_NAME				"lo"
-
-/** Ethernet module full path filename.
- */
-#define NILDUMMY_FILENAME	"/srv/nildummy"
-
-/** Ethernet module name.
- */
-#define NILDUMMY_NAME		"nildummy"
-
-/*@}*/
 
 /** @name Configuration setting names definitions
+ * @{
  */
-/*@{*/
 
-/** Internet protocol module name configuration label.
+#define CONF_IL     "IL"     /**< Internet protocol module name configuration label. */
+#define CONF_IO     "IO"     /**< Device input/output address configuration label. */
+#define CONF_IRQ    "IRQ"    /**< Interrupt number configuration label. */
+#define CONF_MTU    "MTU"    /**< Maximum transmission unit configuration label. */
+#define CONF_NAME   "NAME"   /**< Network interface name configuration label. */
+#define CONF_NETIF  "NETIF"  /**< Network interface module name configuration label. */
+#define CONF_NIL    "NIL"    /**< Network interface layer module name configuration label. */
+
+/** @}
  */
-#define CONF_IL				"IL"
 
-/** Device input/output address configuration label.
- */
-#define CONF_IO				"IO"
-
-/** Interrupt number configuration label.
- */
-#define CONF_IRQ			"IRQ"
-
-/** Maximum transmission unit configuration label.
- */
-#define CONF_MTU			"MTU"
-
-/** Network interface name configuration label.
- */
-#define CONF_NAME			"NAME"
-
-/** Network interface module name configuration label.
- */
-#define CONF_NETIF			"NETIF"
-
-/** Network interface layer module name configuration label.
- */
-#define CONF_NIL			"NIL"
-
-/*@}*/
-
-/** Configuration directory.
- */
-#define CONF_DIR			"/cfg/net"
-
-/** General configuration file.
- */
-#define CONF_GENERAL_FILE	"general"
-
-/** Type definition of the networking module global data.
- *  @see net_globals
- */
-typedef struct net_globals	net_globals_t;
-
-/** Type definition of the network interface specific data.
- *  @see netif
- */
-typedef struct netif	netif_t;
-
-/** Type definition of the network interface specific data pointer.
- *  @see netif
- */
-typedef netif_t *		netif_ref;
+#define CONF_DIR           "/cfg/net"  /**< Configuration directory. */
+#define CONF_GENERAL_FILE  "general"   /**< General configuration file. */
 
 /** Configuration settings.
- *  Maps setting names to the values.
- *  @see generic_char_map.h
+ *
+ * Maps setting names to the values.
+ * @see generic_char_map.h
+ *
  */
-GENERIC_CHAR_MAP_DECLARE(measured_strings, measured_string_t)
+GENERIC_CHAR_MAP_DECLARE(measured_strings, measured_string_t);
+
+/** Present network interface device.
+ *
+ */
+typedef struct {
+	measured_strings_t configuration;  /**< Configuration. */
+	
+	/** Serving network interface driver module index. */
+	module_ref driver;
+	
+	device_id_t id;  /**< System-unique network interface identifier. */
+	module_ref il;   /**< Serving internet layer module index. */
+	char *name;      /**< System-unique network interface name. */
+	module_ref nil;  /**< Serving link layer module index. */
+} netif_t;
 
 /** Present network interfaces.
- *  Maps devices to the networking device specific data.
- *  @see device.h
+ *
+ * Maps devices to the networking device specific data.
+ * @see device.h
+ *
  */
-DEVICE_MAP_DECLARE(netifs, netif_t)
+DEVICE_MAP_DECLARE(netifs, netif_t);
 
-/** Networking module global variables.
+/** Networking module global data.
+ *
  */
-struct net_globals{
-	/** Global configuration.
-	 */
-	measured_strings_t configuration;
-	/** Available modules.
-	 */
-	modules_t modules;
-	/** Network interface structure indices by names.
-	 */
+typedef struct {
+	measured_strings_t configuration;  /**< Global configuration. */
+	modules_t modules;                 /**< Available modules. */
+	
+	/** Network interface structure indices by names. */
 	char_map_t netif_names;
-	/** Present network interfaces.
-	 */
+	
+	/** Present network interfaces. */
 	netifs_t netifs;
-};
+} net_globals_t;
 
-/** Present network interface device.
- */
-struct netif{
-	/** Configuration.
-	 */
-	measured_strings_t configuration;
-	/** Serving network interface driver module index.
-	 */
-	module_ref driver;
-	/** System-unique network interface identifier.
-	 */
-	device_id_t id;
-	/** Serving internet layer module index.
-	 */
-	module_ref il;
-	/** System-unique network interface name.
-	 */
-	char * name;
-	/** Serving link layer module index.
-	 */
-	module_ref nil;
-};
-
-/** Adds the configured setting to the configuration map.
- *  @param[in] configuration The configuration map.
- *  @param[in] name The setting name.
- *  @param[in] value The setting value.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int add_configuration(measured_strings_ref configuration, const char * name, const char * value);
-
-/** Processes the module message.
- *  Distributes the message to the right bundled module.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOTSUP if the message is not known.
- *  @returns Other error codes as defined for each bundled module message function.
- */
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-/** Initializes the networking module for the chosen subsystem build type.
- *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int net_initialize_build(async_client_conn_t client_connection);
-
-/** Processes the networking message.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOTSUP if the message is not known.
- *  @see net_interface.h
- *  @see IS_NET_NET_MESSAGE()
- */
-int net_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
+extern int add_configuration(measured_strings_ref, const char *, const char *);
+extern int net_module_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, int *);
+extern int net_initialize_build(async_client_conn_t);
+extern int net_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, int *);
 
 #endif
Index: uspace/srv/net/net/net_bundle.c
===================================================================
--- uspace/srv/net/net/net_bundle.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/net/net_bundle.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -60,4 +60,9 @@
 extern net_globals_t	net_globals;
 
+/** Initializes the networking module for the chosen subsystem build type.
+ *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
+ *  @returns EOK on success.
+ *  @returns ENOMEM if there is not enough memory left.
+ */
 int net_initialize_build(async_client_conn_t client_connection){
 	ERROR_DECLARE;
@@ -79,5 +84,15 @@
 }
 
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+/** Processes the module message.
+ *  Distributes the message to the right bundled module.
+ *  @param[in] callid The message identifier.
+ *  @param[in] call The message parameters.
+ *  @param[out] answer The message answer parameters.
+ *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
+ *  @returns EOK on success.
+ *  @returns ENOTSUP if the message is not known.
+ *  @returns Other error codes as defined for each bundled module message function.
+ */
+int net_module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
 	if((IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME)
 		|| IS_NET_IL_MESSAGE(call)
Index: pace/srv/net/net/net_messages.h
===================================================================
--- uspace/srv/net/net/net_messages.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,64 +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 net
- *  @{
- */
-
-/** @file
- *  Networking subsystem central module messages.
- *  @see net_interface.h
- */
-
-#ifndef __NET_NET_MESSAGES_H__
-#define __NET_NET_MESSAGES_H__
-
-#include <ipc/ipc.h>
-
-#include "../messages.h"
-
-/** Networking subsystem central module messages.
- */
-typedef enum{
-	/** Returns the general configuration
-	 *  @see net_get_conf_req()
-	 */
-	NET_NET_GET_CONF = NET_FIRST,
-	/** Returns the device specific configuration
-	 *  @see net_get_device_conf_req()
-	 */
-	NET_NET_GET_DEVICE_CONF,
-	/** Starts the networking stack.
-	 */
-	NET_NET_STARTUP,
-} net_messages;
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/net/net_remote.c
===================================================================
--- uspace/srv/net/net/net_remote.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,74 +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 net
- *  @{
- */
-
-/** @file
- *  Networking interface implementation for standalone remote modules.
- *  @see net_interface.h
- */
-
-#include <ipc/services.h>
-
-#include <malloc.h>
-
-#include "../messages.h"
-#include "../modules.h"
-
-#include "../include/device.h"
-#include "../include/net_interface.h"
-
-#include "../structures/measured_strings.h"
-
-#include "net_messages.h"
-
-int net_connect_module(services_t service){
-	return connect_to_service(SERVICE_NETWORKING);
-}
-
-void net_free_settings(measured_string_ref settings, char * data){
-	if(settings){
-		free(settings);
-	}
-	if(data){
-		free(data);
-	}
-}
-
-int net_get_conf_req(int net_phone, measured_string_ref * configuration, size_t count, char ** data){
-	return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, 0, 0, * configuration, count, configuration, data);
-}
-
-int net_get_device_conf_req(int net_phone, device_id_t device_id, measured_string_ref * configuration, size_t count, char ** data){
-	return generic_translate_req(net_phone, NET_NET_GET_DEVICE_CONF, device_id, 0, * configuration, count, configuration, data);
-}
-
-/** @}
- */
Index: uspace/srv/net/net/net_standalone.c
===================================================================
--- uspace/srv/net/net/net_standalone.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/net/net_standalone.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -39,11 +39,9 @@
 #include <ipc/ipc.h>
 
-#include "../messages.h"
-
-#include "../include/ip_interface.h"
-
-#include "../structures/measured_strings.h"
-#include "../structures/module_map.h"
-#include "../structures/packet/packet_server.h"
+#include <net_messages.h>
+#include <ip_interface.h>
+#include <adt/measured_strings.h>
+#include <adt/module_map.h>
+#include <packet/packet_server.h>
 
 #include "net.h"
@@ -51,34 +49,60 @@
 /** Networking module global data.
  */
-extern net_globals_t	net_globals;
+extern net_globals_t net_globals;
 
+/** Initialize the networking module for the chosen subsystem build type.
+ *
+ *  @param[in] client_connection The client connection processing function.
+ *                               The module skeleton propagates its own one.
+ *
+ *  @return EOK on success.
+ *  @return ENOMEM if there is not enough memory left.
+ *
+ */
 int net_initialize_build(async_client_conn_t client_connection){
 	ERROR_DECLARE;
-
-	task_id_t task_id;
-
-	task_id = spawn("/srv/ip");
-	if(! task_id){
+	
+	task_id_t task_id = spawn("/srv/ip");
+	if (!task_id)
 		return EINVAL;
-	}
-	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, IP_NAME, IP_FILENAME, SERVICE_IP, task_id, ip_connect_module));
-	if(! spawn("/srv/icmp")){
+	
+	ERROR_PROPAGATE(add_module(NULL, &net_globals.modules, IP_NAME,
+	    IP_FILENAME, SERVICE_IP, task_id, ip_connect_module));
+	
+	if (!spawn("/srv/icmp"))
 		return EINVAL;
-	}
-	if(! spawn("/srv/udp")){
+	
+	if (!spawn("/srv/udp"))
 		return EINVAL;
-	}
-	if(! spawn("/srv/tcp")){
+	
+	if (!spawn("/srv/tcp"))
 		return EINVAL;
-	}
+	
 	return EOK;
 }
 
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	if(IS_NET_PACKET_MESSAGE(call)){
+/** Process the module message.
+ *
+ * Distribute the message to the right module.
+ *
+ * @param[in]  callid       The message identifier.
+ * @param[in]  call         The message parameters.
+ * @param[out] answer       The message answer parameters.
+ * @param[out] answer_count The last parameter for the actual answer in
+ *                          the answer parameter.
+ *
+ * @return EOK on success.
+ * @return ENOTSUP if the message is not known.
+ * @return Other error codes as defined for each bundled module
+ *         message function.
+ *
+ */
+int net_module_message(ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, int *answer_count)
+{
+	if (IS_NET_PACKET_MESSAGE(call))
 		return packet_server_message(callid, call, answer, answer_count);
-	}else{
-		return net_message(callid, call, answer, answer_count);
-	}
+	
+	return net_message(callid, call, answer, answer_count);
 }
 
Index: pace/srv/net/net/start/Makefile
===================================================================
--- uspace/srv/net/net/start/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,43 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# 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.
-#
-
-NET_BASE = ../..
-USPACE_PREFIX = ../../../..
-BINARY = netstart
-
-SOURCES = \
-	netstart.c \
-	$(NET_BASE)/checksum.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/self_test.c \
-	$(NET_BASE)/structures/char_map.c \
-	$(NET_BASE)/structures/dynamic_fifo.c \
-	$(NET_BASE)/structures/measured_strings.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: pace/srv/net/net/start/netstart.c
===================================================================
--- uspace/srv/net/net/start/netstart.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,115 +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 net
- *  @{
- */
-
-/** @file
- *  Starts the networking subsystem.
- *  Performs self test if configured to.
- *  @see configuration.h
- */
-
-#include <async.h>
-#include <stdio.h>
-#include <task.h>
-
-#include <ipc/ipc.h>
-#include <ipc/services.h>
-
-#include "../../err.h"
-#include "../../modules.h"
-#include "../../self_test.h"
-
-#include "../net_messages.h"
-
-/** Networking startup module name.
- */
-#define NAME	"Networking startup"
-
-/** Module entry point.
- *  @param[in] argc The number of command line parameters.
- *  @param[in] argv The command line parameters.
- *  @returns EOK on success.
- *  @returns EINVAL if the net module cannot be started.
- *  @returns Other error codes as defined for the self_test() function.
- *  @returns Other error codes as defined for the NET_NET_STARTUP message.
- */
-int main(int argc, char * argv[]);
-
-/** Starts the module.
- *  @param[in] fname The module absolute name.
- *  @returns The started module task identifier.
- *  @returns Other error codes as defined for the task_spawn() function.
- */
-task_id_t spawn(const char * fname);
-
-int main(int argc, char * argv[]){
-	ERROR_DECLARE;
-
-	int net_phone;
-
-	// print the module label
-	printf("Task %d - ", task_get_id());
-	printf("%s\n", NAME);
-
-	// run self tests
-	ERROR_PROPAGATE(self_test());
-
-	// start the networking service
-	if(! spawn("/srv/net")){
-		fprintf(stderr, "Could not spawn net\n");
-		return EINVAL;
-	}
-
-	// start the networking
-	net_phone = connect_to_service(SERVICE_NETWORKING);
-	if(ERROR_OCCURRED(ipc_call_sync_0_0(net_phone, NET_NET_STARTUP))){
-		printf("ERROR %d\n", ERROR_CODE);
-		return ERROR_CODE;
-	}else{
-		printf("OK\n");
-	}
-
-	return EOK;
-}
-
-task_id_t spawn(const char * fname){
-	const char * argv[2];
-	task_id_t res;
-
-	argv[0] = fname;
-	argv[1] = NULL;
-	res = task_spawn(fname, argv);
-	
-	return res;
-}
-
-/** @}
- */
Index: pace/srv/net/netif/dp8390/Makefile
===================================================================
--- uspace/srv/net/netif/dp8390/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,68 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# 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.
-#
-
-NET_BASE = ../..
-USPACE_PREFIX = ../../../..
-ROOT_PATH = $(USPACE_PREFIX)/..
-
-COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
-CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
-
-BINARY = dp8390
-
--include $(COMMON_MAKEFILE)
--include $(CONFIG_MAKEFILE)
-
-SOURCES = \
-	dp8390.c \
-	dp8390_module.c \
-	ne2000.c \
-	$(NET_BASE)/module.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/netif/netif.c \
-	$(NET_BASE)/structures/measured_strings.c \
-	$(NET_BASE)/structures/packet/packet.c \
-	$(NET_BASE)/structures/packet/packet_client.c \
-	$(NET_BASE)/structures/packet/packet_remote.c
-
-ifeq ($(CONFIG_NETWORKING),module)
-	SOURCES += \
-		$(NET_BASE)/checksum.c \
-		$(NET_BASE)/nil/eth/eth.c \
-		$(NET_BASE)/net/net_remote.c \
-		$(NET_BASE)/netif/netif_nil_bundle.c
-endif
-
-ifeq ($(CONFIG_NETWORKING),modular)
-	SOURCES += \
-		$(NET_BASE)/nil/nil_remote.c \
-		$(NET_BASE)/netif/netif_standalone.c
-endif
-
-include $(USPACE_PREFIX)/Makefile.common
Index: pace/srv/net/netif/dp8390/dp8390.c
===================================================================
--- uspace/srv/net/netif/dp8390/dp8390.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,1674 +1,0 @@
-/*
- * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system 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.
- * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
- * * Any deviations from these conditions require written permission from the copyright holder in advance
- *
- *
- * Disclaimer
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``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 COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS 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.
- *
- * Changes:
- *  2009 ported to HelenOS, Lukas Mejdrech
- */
-
-/** @addtogroup dp8390
- *  @{
- */
-
-/** @file
- *  DP8390 network interface core implementation.
- */
-
-#include <assert.h>
-#include <errno.h>
-
-#include "../../include/byteorder.h"
-
-#include "../../structures/packet/packet.h"
-#include "../../structures/packet/packet_client.h"
-
-#include "../netif.h"
-
-#include "dp8390_drv.h"
-#include "dp8390_port.h"
-
-/*
- * dp8390.c
- *
- * Created:	before Dec 28, 1992 by Philip Homburg <philip@f-mnx.phicoh.com>
- *
- * Modified Mar 10 1994 by Philip Homburg
- *	Become a generic dp8390 driver.
- *
- * Modified Dec 20 1996 by G. Falzoni <falzoni@marina.scn.de>
- *	Added support for 3c503 boards.
- */
-
-#include "local.h"
-#include "dp8390.h"
-
-/** Queues the outgoing packet.
- *  @param[in] dep The network interface structure.
- *  @param[in] packet The outgoing packet.
- *  @returns EOK on success.
- *  @returns EINVAL 
- */
-int queue_packet(dpeth_t * dep, packet_t packet);
-
-/** Reads a memory block byte by byte.
- *  @param[in] port The source address.
- *  @param[out] buf The destination buffer.
- *  @param[in] size The memory block size in bytes.
- */
-static void outsb(port_t port, void * buf, size_t size);
-
-/** Reads a memory block word by word.
- *  @param[in] port The source address.
- *  @param[out] buf The destination buffer.
- *  @param[in] size The memory block size in bytes.
- */
-static void outsw(port_t port, void * buf, size_t size);
-
-//static u16_t eth_ign_proto;
-//static char *progname;
-
-/* Configuration */
-/*typedef struct dp_conf
-{
-	port_t dpc_port;
-	int dpc_irq;
-	phys_bytes dpc_mem;
-	char *dpc_envvar;
-} dp_conf_t;
-*/
-//dp_conf_t dp_conf[]=	/* Card addresses */
-//{
-	/* I/O port, IRQ,  Buffer address,  Env. var. */
-/*	{ 0x280,     3,    0xD0000,        "DPETH0"	},
-	{ 0x300,     5,    0xC8000,        "DPETH1"	},
-	{ 0x380,    10,    0xD8000,        "DPETH2"	},
-};
-*/
-/* Test if dp_conf has exactly DE_PORT_NR entries.  If not then you will see
- * the error: "array size is negative".
- */
-//extern int ___dummy[DE_PORT_NR == sizeof(dp_conf)/sizeof(dp_conf[0]) ? 1 : -1];
-
-/* Card inits configured out? */
-#if !ENABLE_WDETH
-#define wdeth_probe(dep)	(0)
-#endif
-#if !ENABLE_NE2000
-#define ne_probe(dep)		(0)
-#endif
-#if !ENABLE_3C503
-#define el2_probe(dep)		(0)
-#endif
-
-/* Some clones of the dp8390 and the PC emulator 'Bochs' require the CR_STA
- * on writes to the CR register. Additional CR_STAs do not appear to hurt
- * genuine dp8390s
- */
-#define CR_EXTRA	CR_STA
-
-//#if ENABLE_PCI
-//_PROTOTYPE(static void pci_conf, (void)				);
-//#endif
-//_PROTOTYPE(static void do_vwrite, (message *mp, int from_int,
-//							int vectored)	);
-//_PROTOTYPE(static void do_vwrite_s, (message *mp, int from_int)	);
-//_PROTOTYPE(static void do_vread, (message *mp, int vectored)		);
-//_PROTOTYPE(static void do_vread_s, (message *mp)			);
-//_PROTOTYPE(static void do_init, (message *mp)				);
-//_PROTOTYPE(static void do_int, (dpeth_t *dep)				);
-//_PROTOTYPE(static void do_getstat, (message *mp)			);
-//_PROTOTYPE(static void do_getstat_s, (message *mp)			);
-//_PROTOTYPE(static void do_getname, (message *mp)			);
-//_PROTOTYPE(static void do_stop, (message *mp)				);
-_PROTOTYPE(static void dp_init, (dpeth_t *dep)				);
-//_PROTOTYPE(static void dp_confaddr, (dpeth_t *dep)			);
-_PROTOTYPE(static void dp_reinit, (dpeth_t *dep)			);
-_PROTOTYPE(static void dp_reset, (dpeth_t *dep)			);
-//_PROTOTYPE(static void dp_check_ints, (dpeth_t *dep)			);
-_PROTOTYPE(static void dp_recv, (dpeth_t *dep)				);
-_PROTOTYPE(static void dp_send, (dpeth_t *dep)				);
-//_PROTOTYPE(static void dp8390_stop, (void)				);
-_PROTOTYPE(static void dp_getblock, (dpeth_t *dep, int page,
-				size_t offset, size_t size, void *dst)	);
-_PROTOTYPE(static void dp_pio8_getblock, (dpeth_t *dep, int page,
-				size_t offset, size_t size, void *dst)	);
-_PROTOTYPE(static void dp_pio16_getblock, (dpeth_t *dep, int page,
-				size_t offset, size_t size, void *dst)	);
-_PROTOTYPE(static int dp_pkt2user, (dpeth_t *dep, int page,
-							int length) );
-//_PROTOTYPE(static int dp_pkt2user_s, (dpeth_t *dep, int page,
-//							int length)	);
-_PROTOTYPE(static void dp_user2nic, (dpeth_t *dep, iovec_dat_t *iovp, 
-		vir_bytes offset, int nic_addr, vir_bytes count) );
-//_PROTOTYPE(static void dp_user2nic_s, (dpeth_t *dep, iovec_dat_s_t *iovp, 
-//		vir_bytes offset, int nic_addr, vir_bytes count)	);
-_PROTOTYPE(static void dp_pio8_user2nic, (dpeth_t *dep,
-				iovec_dat_t *iovp, vir_bytes offset,
-				int nic_addr, vir_bytes count) );
-//_PROTOTYPE(static void dp_pio8_user2nic_s, (dpeth_t *dep,
-//				iovec_dat_s_t *iovp, vir_bytes offset,
-//				int nic_addr, vir_bytes count)		);
-_PROTOTYPE(static void dp_pio16_user2nic, (dpeth_t *dep,
-				iovec_dat_t *iovp, vir_bytes offset,
-				int nic_addr, vir_bytes count) );
-//_PROTOTYPE(static void dp_pio16_user2nic_s, (dpeth_t *dep,
-//				iovec_dat_s_t *iovp, vir_bytes offset,
-//				int nic_addr, vir_bytes count)		);
-_PROTOTYPE(static void dp_nic2user, (dpeth_t *dep, int nic_addr, 
-		iovec_dat_t *iovp, vir_bytes offset, vir_bytes count)	);
-//_PROTOTYPE(static void dp_nic2user_s, (dpeth_t *dep, int nic_addr, 
-//		iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count)	);
-_PROTOTYPE(static void dp_pio8_nic2user, (dpeth_t *dep, int nic_addr, 
-		iovec_dat_t *iovp, vir_bytes offset, vir_bytes count)	);
-//_PROTOTYPE(static void dp_pio8_nic2user_s, (dpeth_t *dep, int nic_addr, 
-//		iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count)	);
-_PROTOTYPE(static void dp_pio16_nic2user, (dpeth_t *dep, int nic_addr, 
-		iovec_dat_t *iovp, vir_bytes offset, vir_bytes count)	);
-//_PROTOTYPE(static void dp_pio16_nic2user_s, (dpeth_t *dep, int nic_addr, 
-//		iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count)	);
-_PROTOTYPE(static void dp_next_iovec, (iovec_dat_t *iovp)		);
-//_PROTOTYPE(static void dp_next_iovec_s, (iovec_dat_s_t *iovp)		);
-_PROTOTYPE(static void conf_hw, (dpeth_t *dep)				);
-//_PROTOTYPE(static void update_conf, (dpeth_t *dep, dp_conf_t *dcp)	);
-_PROTOTYPE(static void map_hw_buffer, (dpeth_t *dep)			);
-//_PROTOTYPE(static int calc_iovec_size, (iovec_dat_t *iovp)		);
-//_PROTOTYPE(static int calc_iovec_size_s, (iovec_dat_s_t *iovp)		);
-_PROTOTYPE(static void reply, (dpeth_t *dep, int err, int may_block)	);
-//_PROTOTYPE(static void mess_reply, (message *req, message *reply)	);
-_PROTOTYPE(static void get_userdata, (int user_proc,
-		vir_bytes user_addr, vir_bytes count, void *loc_addr)	);
-//_PROTOTYPE(static void get_userdata_s, (int user_proc,
-//		cp_grant_id_t grant, vir_bytes offset, vir_bytes count,
-//		void *loc_addr)	);
-//_PROTOTYPE(static void put_userdata, (int user_proc,
-//		vir_bytes user_addr, vir_bytes count, void *loc_addr)	);
-//_PROTOTYPE(static void put_userdata_s, (int user_proc,
-//		cp_grant_id_t grant, size_t count, void *loc_addr)	);
-_PROTOTYPE(static void insb, (port_t port, void *buf, size_t size)				);
-_PROTOTYPE(static void insw, (port_t port, void *buf, size_t size)				);
-//_PROTOTYPE(static void do_vir_insb, (port_t port, int proc,
-//					vir_bytes buf, size_t size)	);
-//_PROTOTYPE(static void do_vir_insw, (port_t port, int proc,
-//					vir_bytes buf, size_t size)	);
-//_PROTOTYPE(static void do_vir_outsb, (port_t port, int proc,
-//					vir_bytes buf, size_t size)	);
-//_PROTOTYPE(static void do_vir_outsw, (port_t port, int proc,
-//					vir_bytes buf, size_t size)	);
-
-int do_probe(dpeth_t * dep){
-	/* This is the default, try to (re)locate the device. */
-	conf_hw(dep);
-	if (dep->de_mode == DEM_DISABLED)
-	{
-		/* Probe failed, or the device is configured off. */
-		return EXDEV;//ENXIO;
-	}
-	if (dep->de_mode == DEM_ENABLED)
-		dp_init(dep);
-	return EOK;
-}
-
-/*===========================================================================*
- *				dp8390_dump				     *
- *===========================================================================*/
-void dp8390_dump(dpeth_t * dep)
-{
-//	dpeth_t *dep;
-	int /*i,*/ isr;
-
-//	printf("\n");
-//	for (i= 0, dep = &de_table[0]; i<DE_PORT_NR; i++, dep++)
-//	{
-#if XXX
-		if (dep->de_mode == DEM_DISABLED)
-			printf("dp8390 port %d is disabled\n", i);
-		else if (dep->de_mode == DEM_SINK)
-			printf("dp8390 port %d is in sink mode\n", i);
-#endif
-
-		if (dep->de_mode != DEM_ENABLED)
-//			continue;
-			return;
-
-//		printf("dp8390 statistics of port %d:\n", i);
-
-		printf("recvErr    :%8ld\t", dep->de_stat.ets_recvErr);
-		printf("sendErr    :%8ld\t", dep->de_stat.ets_sendErr);
-		printf("OVW        :%8ld\n", dep->de_stat.ets_OVW);
-
-		printf("CRCerr     :%8ld\t", dep->de_stat.ets_CRCerr);
-		printf("frameAll   :%8ld\t", dep->de_stat.ets_frameAll);
-		printf("missedP    :%8ld\n", dep->de_stat.ets_missedP);
-
-		printf("packetR    :%8ld\t", dep->de_stat.ets_packetR);
-		printf("packetT    :%8ld\t", dep->de_stat.ets_packetT);
-		printf("transDef   :%8ld\n", dep->de_stat.ets_transDef);
-
-		printf("collision  :%8ld\t", dep->de_stat.ets_collision);
-		printf("transAb    :%8ld\t", dep->de_stat.ets_transAb);
-		printf("carrSense  :%8ld\n", dep->de_stat.ets_carrSense);
-
-		printf("fifoUnder  :%8ld\t", dep->de_stat.ets_fifoUnder);
-		printf("fifoOver   :%8ld\t", dep->de_stat.ets_fifoOver);
-		printf("CDheartbeat:%8ld\n", dep->de_stat.ets_CDheartbeat);
-
-		printf("OWC        :%8ld\t", dep->de_stat.ets_OWC);
-
-		isr= inb_reg0(dep, DP_ISR);
-		printf("dp_isr = 0x%x + 0x%x, de_flags = 0x%x\n", isr,
-					inb_reg0(dep, DP_ISR), dep->de_flags);
-//	}
-}
-
-/*===========================================================================*
- *				do_init					     *
- *===========================================================================*/
-int do_init(dpeth_t * dep, int mode){
-	if (dep->de_mode == DEM_DISABLED)
-	{
-		// might call do_probe()
-		return EXDEV;
-	}
-
-	if (dep->de_mode == DEM_SINK)
-	{
-//		strncpy((char *) dep->de_address.ea_addr, "ZDP", 6);
-//		dep->de_address.ea_addr[5] = port;
-//		dp_confaddr(dep);
-//		reply_mess.m_type = DL_CONF_REPLY;
-//		reply_mess.m3_i1 = mp->DL_PORT;
-//		reply_mess.m3_i2 = DE_PORT_NR;
-//		*(ether_addr_t *) reply_mess.m3_ca1 = dep->de_address;
-//		mess_reply(mp, &reply_mess);
-//		return;
-		return EOK;
-	}
-	assert(dep->de_mode == DEM_ENABLED);
-	assert(dep->de_flags &DEF_ENABLED);
-
-	dep->de_flags &= ~(DEF_PROMISC | DEF_MULTI | DEF_BROAD);
-
-	if (mode &DL_PROMISC_REQ)
-		dep->de_flags |= DEF_PROMISC | DEF_MULTI | DEF_BROAD;
-	if (mode &DL_MULTI_REQ)
-		dep->de_flags |= DEF_MULTI;
-	if (mode &DL_BROAD_REQ)
-		dep->de_flags |= DEF_BROAD;
-
-//	dep->de_client = mp->m_source;
-	dp_reinit(dep);
-
-//	reply_mess.m_type = DL_CONF_REPLY;
-//	reply_mess.m3_i1 = mp->DL_PORT;
-//	reply_mess.m3_i2 = DE_PORT_NR;
-//	*(ether_addr_t *) reply_mess.m3_ca1 = dep->de_address;
-
-//	mess_reply(mp, &reply_mess);
-	return EOK;
-}
-
-/*===========================================================================*
- *				do_stop					     *
- *===========================================================================*/
-void do_stop(dpeth_t * dep){
-	if((dep->de_mode != DEM_SINK) && (dep->de_mode == DEM_ENABLED) && (dep->de_flags &DEF_ENABLED)){
-		outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
-		(dep->de_stopf)(dep);
-
-		dep->de_flags = DEF_EMPTY;
-	}
-}
-
-int queue_packet(dpeth_t * dep, packet_t packet){
-	packet_t tmp;
-
-	if(dep->packet_count >= MAX_PACKETS){
-		netif_pq_release(packet_get_id(packet));
-		return ELIMIT;
-	}
-
-	tmp = dep->packet_queue;
-	while(pq_next(tmp)){
-		tmp = pq_next(tmp);
-	}
-	if(pq_add(&tmp, packet, 0, 0) != EOK){
-		return EINVAL;
-	}
-	if(! dep->packet_count){
-		dep->packet_queue = packet;
-	}
-	++ dep->packet_count;
-	return EBUSY;
-}
-
-/*===========================================================================*
- *			based on	do_vwrite				     *
- *===========================================================================*/
-int do_pwrite(dpeth_t * dep, packet_t packet, int from_int)
-{
-//	int port, count, size;
-	int size;
-	int sendq_head;
-/*	dpeth_t *dep;
-
-	port = mp->DL_PORT;
-	count = mp->DL_COUNT;
-	if (port < 0 || port >= DE_PORT_NR)
-		panic("", "dp8390: illegal port", port);
-	dep= &de_table[port];
-	dep->de_client= mp->DL_PROC;
-*/
-	if (dep->de_mode == DEM_SINK)
-	{
-		assert(!from_int);
-//		dep->de_flags |= DEF_PACK_SEND;
-		reply(dep, OK, FALSE);
-//		return;
-		return EOK;
-	}
-	assert(dep->de_mode == DEM_ENABLED);
-	assert(dep->de_flags &DEF_ENABLED);
-	if(dep->packet_queue && (! from_int)){
-//	if (dep->de_flags &DEF_SEND_AVAIL){
-//		panic("", "dp8390: send already in progress", NO_NUM);
-		return queue_packet(dep, packet);
-	}
-
-	sendq_head= dep->de_sendq_head;
-//	if (dep->de_sendq[sendq_head].sq_filled)
-//	{
-//		if (from_int)
-//			panic("", "dp8390: should not be sending\n", NO_NUM);
-//		dep->de_sendmsg= *mp;
-//		dep->de_flags |= DEF_SEND_AVAIL;
-//		reply(dep, OK, FALSE);
-//		return;
-//		return queue_packet(dep, packet);
-//	}
-//	assert(!(dep->de_flags &DEF_PACK_SEND));
-
-/*	if (vectored)
-	{
-		get_userdata(mp->DL_PROC, (vir_bytes) mp->DL_ADDR,
-			(count > IOVEC_NR ? IOVEC_NR : count) *
-			sizeof(iovec_t), dep->de_write_iovec.iod_iovec);
-		dep->de_write_iovec.iod_iovec_s = count;
-		dep->de_write_iovec.iod_proc_nr = mp->DL_PROC;
-		dep->de_write_iovec.iod_iovec_addr = (vir_bytes) mp->DL_ADDR;
-
-		dep->de_tmp_iovec = dep->de_write_iovec;
-		size = calc_iovec_size(&dep->de_tmp_iovec);
-	}
-	else
-	{ 
-		dep->de_write_iovec.iod_iovec[0].iov_addr =
-			(vir_bytes) mp->DL_ADDR;
-		dep->de_write_iovec.iod_iovec[0].iov_size =
-			mp->DL_COUNT;
-		dep->de_write_iovec.iod_iovec_s = 1;
-		dep->de_write_iovec.iod_proc_nr = mp->DL_PROC;
-		dep->de_write_iovec.iod_iovec_addr = 0;
-		size= mp->DL_COUNT;
-	}
-*/
-	size = packet_get_data_length(packet);
-	dep->de_write_iovec.iod_iovec[0].iov_addr = (vir_bytes) packet_get_data(packet);
-	dep->de_write_iovec.iod_iovec[0].iov_size = size;
-	dep->de_write_iovec.iod_iovec_s = 1;
-	dep->de_write_iovec.iod_iovec_addr = NULL;
-
-	if (size < ETH_MIN_PACK_SIZE || size > ETH_MAX_PACK_SIZE_TAGGED)
-	{
-		panic("", "dp8390: invalid packet size", size);
-		return EINVAL;
-	}
-	(dep->de_user2nicf)(dep, &dep->de_write_iovec, 0,
-		dep->de_sendq[sendq_head].sq_sendpage * DP_PAGESIZE,
-		size);
-	dep->de_sendq[sendq_head].sq_filled= TRUE;
-	if (dep->de_sendq_tail == sendq_head)
-	{
-		outb_reg0(dep, DP_TPSR, dep->de_sendq[sendq_head].sq_sendpage);
-		outb_reg0(dep, DP_TBCR1, size >> 8);
-		outb_reg0(dep, DP_TBCR0, size &0xff);
-		outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA);/* there it goes.. */
-	}
-	else
-		dep->de_sendq[sendq_head].sq_size= size;
-	
-	if (++sendq_head == dep->de_sendq_nr)
-		sendq_head= 0;
-	assert(sendq_head < SENDQ_NR);
-	dep->de_sendq_head= sendq_head;
-
-//	dep->de_flags |= DEF_PACK_SEND;
-
-	/* If the interrupt handler called, don't send a reply. The reply
-	 * will be sent after all interrupts are handled. 
-	 */
-	if (from_int)
-		return EOK;
-	reply(dep, OK, FALSE);
-
-	assert(dep->de_mode == DEM_ENABLED);
-	assert(dep->de_flags &DEF_ENABLED);
-	return EOK;
-}
-
-/*===========================================================================*
- *				dp_init					     *
- *===========================================================================*/
-void dp_init(dep)
-dpeth_t *dep;
-{
-	int dp_rcr_reg;
-	int i;//, r;
-
-	/* General initialization */
-	dep->de_flags = DEF_EMPTY;
-	(*dep->de_initf)(dep);
-
-//	dp_confaddr(dep);
-
-	if (debug)
-	{
-		printf("%s: Ethernet address ", dep->de_name);
-		for (i= 0; i < 6; i++)
-			printf("%x%c", dep->de_address.ea_addr[i],
-							i < 5 ? ':' : '\n');
-	}
-
-	/* Map buffer */
-	map_hw_buffer(dep);
-
-	/* Initialization of the dp8390 following the mandatory procedure
-	 * in reference manual ("DP8390D/NS32490D NIC Network Interface
-	 * Controller", National Semiconductor, July 1995, Page 29).
-	 */
-	/* Step 1: */
-	outb_reg0(dep, DP_CR, CR_PS_P0 | CR_STP | CR_DM_ABORT);
-	/* Step 2: */
-	if (dep->de_16bit)
-		outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS);
-	else
-		outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES | DCR_BMS);
-	/* Step 3: */
-	outb_reg0(dep, DP_RBCR0, 0);
-	outb_reg0(dep, DP_RBCR1, 0);
-	/* Step 4: */
-	dp_rcr_reg = 0;
-	if (dep->de_flags &DEF_PROMISC)
-		dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM;
-	if (dep->de_flags &DEF_BROAD)
-		dp_rcr_reg |= RCR_AB;
-	if (dep->de_flags &DEF_MULTI)
-		dp_rcr_reg |= RCR_AM;
-	outb_reg0(dep, DP_RCR, dp_rcr_reg);
-	/* Step 5: */
-	outb_reg0(dep, DP_TCR, TCR_INTERNAL);
-	/* Step 6: */
-	outb_reg0(dep, DP_BNRY, dep->de_startpage);
-	outb_reg0(dep, DP_PSTART, dep->de_startpage);
-	outb_reg0(dep, DP_PSTOP, dep->de_stoppage);
-	/* Step 7: */
-	outb_reg0(dep, DP_ISR, 0xFF);
-	/* Step 8: */
-	outb_reg0(dep, DP_IMR, IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE |
-		IMR_OVWE | IMR_CNTE);
-	/* Step 9: */
-	outb_reg0(dep, DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP);
-
-	outb_reg1(dep, DP_PAR0, dep->de_address.ea_addr[0]);
-	outb_reg1(dep, DP_PAR1, dep->de_address.ea_addr[1]);
-	outb_reg1(dep, DP_PAR2, dep->de_address.ea_addr[2]);
-	outb_reg1(dep, DP_PAR3, dep->de_address.ea_addr[3]);
-	outb_reg1(dep, DP_PAR4, dep->de_address.ea_addr[4]);
-	outb_reg1(dep, DP_PAR5, dep->de_address.ea_addr[5]);
-
-	outb_reg1(dep, DP_MAR0, 0xff);
-	outb_reg1(dep, DP_MAR1, 0xff);
-	outb_reg1(dep, DP_MAR2, 0xff);
-	outb_reg1(dep, DP_MAR3, 0xff);
-	outb_reg1(dep, DP_MAR4, 0xff);
-	outb_reg1(dep, DP_MAR5, 0xff);
-	outb_reg1(dep, DP_MAR6, 0xff);
-	outb_reg1(dep, DP_MAR7, 0xff);
-
-	outb_reg1(dep, DP_CURR, dep->de_startpage + 1);
-	/* Step 10: */
-	outb_reg0(dep, DP_CR, CR_DM_ABORT | CR_STA);
-	/* Step 11: */
-	outb_reg0(dep, DP_TCR, TCR_NORMAL);
-
-	inb_reg0(dep, DP_CNTR0);		/* reset counters by reading */
-	inb_reg0(dep, DP_CNTR1);
-	inb_reg0(dep, DP_CNTR2);
-
-	/* Finish the initialization. */
-	dep->de_flags |= DEF_ENABLED;
-	for (i= 0; i<dep->de_sendq_nr; i++)
-		dep->de_sendq[i].sq_filled= 0;
-	dep->de_sendq_head= 0;
-	dep->de_sendq_tail= 0;
-	if (!dep->de_prog_IO)
-	{
-		dep->de_user2nicf= dp_user2nic;
-//		dep->de_user2nicf_s= dp_user2nic_s;
-		dep->de_nic2userf= dp_nic2user;
-//		dep->de_nic2userf_s= dp_nic2user_s;
-		dep->de_getblockf= dp_getblock;
-	}
-	else if (dep->de_16bit)
-	{
-		dep->de_user2nicf= dp_pio16_user2nic;
-//		dep->de_user2nicf_s= dp_pio16_user2nic_s;
-		dep->de_nic2userf= dp_pio16_nic2user;
-//		dep->de_nic2userf_s= dp_pio16_nic2user_s;
-		dep->de_getblockf= dp_pio16_getblock;
-	}
-	else
-	{
-		dep->de_user2nicf= dp_pio8_user2nic;
-//		dep->de_user2nicf_s= dp_pio8_user2nic_s;
-		dep->de_nic2userf= dp_pio8_nic2user;
-//		dep->de_nic2userf_s= dp_pio8_nic2user_s;
-		dep->de_getblockf= dp_pio8_getblock;
-	}
-
-	/* Set the interrupt handler and policy. Do not automatically 
-	 * reenable interrupts. Return the IRQ line number on interrupts.
- 	 */
-/* 	dep->de_hook = dep->de_irq;
-	r= sys_irqsetpolicy(dep->de_irq, 0, &dep->de_hook);
-	if (r != OK)
-		panic("DP8390", "sys_irqsetpolicy failed", r);
-
-	r= sys_irqenable(&dep->de_hook);
-	if (r != OK)
-	{
-		panic("DP8390", "unable enable interrupts", r);
-	}
-*/
-}
-
-/*===========================================================================*
- *				dp_reinit				     *
- *===========================================================================*/
-static void dp_reinit(dep)
-dpeth_t *dep;
-{
-	int dp_rcr_reg;
-
-	outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA);
-
-	dp_rcr_reg = 0;
-	if (dep->de_flags &DEF_PROMISC)
-		dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM;
-	if (dep->de_flags &DEF_BROAD)
-		dp_rcr_reg |= RCR_AB;
-	if (dep->de_flags &DEF_MULTI)
-		dp_rcr_reg |= RCR_AM;
-	outb_reg0(dep, DP_RCR, dp_rcr_reg);
-}
-
-/*===========================================================================*
- *				dp_reset				     *
- *===========================================================================*/
-static void dp_reset(dep)
-dpeth_t *dep;
-{
-	int i;
-
-	/* Stop chip */
-	outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
-	outb_reg0(dep, DP_RBCR0, 0);
-	outb_reg0(dep, DP_RBCR1, 0);
-	for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) &ISR_RST) == 0); i++)
-		; /* Do nothing */
-	outb_reg0(dep, DP_TCR, TCR_1EXTERNAL|TCR_OFST);
-	outb_reg0(dep, DP_CR, CR_STA|CR_DM_ABORT);
-	outb_reg0(dep, DP_TCR, TCR_NORMAL);
-
-	/* Acknowledge the ISR_RDC (remote dma) interrupt. */
-	for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) &ISR_RDC) == 0); i++)
-		; /* Do nothing */
-	outb_reg0(dep, DP_ISR, inb_reg0(dep, DP_ISR) &~ISR_RDC);
-
-	/* Reset the transmit ring. If we were transmitting a packet, we
-	 * pretend that the packet is processed. Higher layers will
-	 * retransmit if the packet wasn't actually sent.
-	 */
-	dep->de_sendq_head= dep->de_sendq_tail= 0;
-	for (i= 0; i<dep->de_sendq_nr; i++)
-		dep->de_sendq[i].sq_filled= 0;
-	dp_send(dep);
-	dep->de_flags &= ~DEF_STOPPED;
-}
-
-/*===========================================================================*
- *				dp_check_ints				     *
- *===========================================================================*/
-void dp_check_ints(dep, isr)
-dpeth_t *dep;
-int isr;
-{
-	int /*isr,*/ tsr;
-	int size, sendq_tail;
-
-	if (!(dep->de_flags &DEF_ENABLED))
-		panic("", "dp8390: got premature interrupt", NO_NUM);
-
-	for(;;)
-	{
-//		isr = inb_reg0(dep, DP_ISR);
-		if (!isr)
-			break;
-		outb_reg0(dep, DP_ISR, isr);
-		if (isr &(ISR_PTX|ISR_TXE))
-		{
-			if (isr &ISR_TXE)
-			{
-#if DEBUG
- {printf("%s: got send Error\n", dep->de_name);}
-#endif
-				dep->de_stat.ets_sendErr++;
-			}
-			else
-			{
-				tsr = inb_reg0(dep, DP_TSR);
-
-				if (tsr &TSR_PTX) dep->de_stat.ets_packetT++;
-#if 0	/* Reserved in later manuals, should be ignored */
-				if (!(tsr &TSR_DFR))
-				{
-					/* In most (all?) implementations of
-					 * the dp8390, this bit is set
-					 * when the packet is not deferred
-					 */
-					dep->de_stat.ets_transDef++;
-				}
-#endif
-				if (tsr &TSR_COL) dep->de_stat.ets_collision++;
-				if (tsr &TSR_ABT) dep->de_stat.ets_transAb++;
-				if (tsr &TSR_CRS) dep->de_stat.ets_carrSense++;
-				if (tsr &TSR_FU
-					&& ++dep->de_stat.ets_fifoUnder <= 10)
-				{
-					printf("%s: fifo underrun\n",
-						dep->de_name);
-				}
-				if (tsr &TSR_CDH
-					&& ++dep->de_stat.ets_CDheartbeat <= 10)
-				{
-					printf("%s: CD heart beat failure\n",
-						dep->de_name);
-				}
-				if (tsr &TSR_OWC) dep->de_stat.ets_OWC++;
-			}
-			sendq_tail= dep->de_sendq_tail;
-
-			if (!(dep->de_sendq[sendq_tail].sq_filled))
-			{
-				/* Software bug? */
-				assert(!debug);
-
-				/* Or hardware bug? */
-				printf(
-				"%s: transmit interrupt, but not sending\n",
-					dep->de_name);
-				continue;
-			}
-			dep->de_sendq[sendq_tail].sq_filled= 0;
-			if (++sendq_tail == dep->de_sendq_nr)
-				sendq_tail= 0;
-			dep->de_sendq_tail= sendq_tail;
-			if (dep->de_sendq[sendq_tail].sq_filled)
-			{
-				size= dep->de_sendq[sendq_tail].sq_size;
-				outb_reg0(dep, DP_TPSR,
-					dep->de_sendq[sendq_tail].sq_sendpage);
-				outb_reg0(dep, DP_TBCR1, size >> 8);
-				outb_reg0(dep, DP_TBCR0, size &0xff);
-				outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA);
-			}
-//			if (dep->de_flags &DEF_SEND_AVAIL)
-				dp_send(dep);
-		}
-
-		if (isr &ISR_PRX)
-		{
-			/* Only call dp_recv if there is a read request */
-//			if (dep->de_flags) &DEF_READING)
-				dp_recv(dep);
-		}
-		
-		if (isr &ISR_RXE) dep->de_stat.ets_recvErr++;
-		if (isr &ISR_CNT)
-		{
-			dep->de_stat.ets_CRCerr += inb_reg0(dep, DP_CNTR0);
-			dep->de_stat.ets_frameAll += inb_reg0(dep, DP_CNTR1);
-			dep->de_stat.ets_missedP += inb_reg0(dep, DP_CNTR2);
-		}
-		if (isr &ISR_OVW)
-		{
-			dep->de_stat.ets_OVW++;
-#if 0
-			{printW(); printf(
-				"%s: got overwrite warning\n", dep->de_name);}
-#endif
-/*			if (dep->de_flags &DEF_READING)
-			{
-				printf(
-"dp_check_ints: strange: overwrite warning and pending read request\n");
-				dp_recv(dep);
-			}
-*/		}
-		if (isr &ISR_RDC)
-		{
-			/* Nothing to do */
-		}
-		if (isr &ISR_RST)
-		{
-			/* this means we got an interrupt but the ethernet 
-			 * chip is shutdown. We set the flag DEF_STOPPED,
-			 * and continue processing arrived packets. When the
-			 * receive buffer is empty, we reset the dp8390.
-			 */
-#if 0
-			 {printW(); printf(
-				"%s: NIC stopped\n", dep->de_name);}
-#endif
-			dep->de_flags |= DEF_STOPPED;
-			break;
-		}
-		isr = inb_reg0(dep, DP_ISR);
-	}
-//	if ((dep->de_flags &(DEF_READING|DEF_STOPPED)) == 
-//						(DEF_READING|DEF_STOPPED))
-	if ((dep->de_flags &DEF_STOPPED) == DEF_STOPPED)
-	{
-		/* The chip is stopped, and all arrived packets are 
-		 * delivered.
-		 */
-		dp_reset(dep);
-	}
-}
-
-/*===========================================================================*
- *				dp_recv					     *
- *===========================================================================*/
-static void dp_recv(dep)
-dpeth_t *dep;
-{
-	dp_rcvhdr_t header;
-	//unsigned pageno, curr, next;
-	int pageno, curr, next;
-	vir_bytes length;
-	int packet_processed, r;
-	u16_t eth_type;
-
-	packet_processed = FALSE;
-	pageno = inb_reg0(dep, DP_BNRY) + 1;
-	if (pageno == dep->de_stoppage) pageno = dep->de_startpage;
-
-	do
-	{
-		outb_reg0(dep, DP_CR, CR_PS_P1 | CR_EXTRA);
-		curr = inb_reg1(dep, DP_CURR);
-		outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA);
-
-		if (curr == pageno) break;
-
-		(dep->de_getblockf)(dep, pageno, (size_t)0, sizeof(header),
-			&header);
-		(dep->de_getblockf)(dep, pageno, sizeof(header) +
-			2*sizeof(ether_addr_t), sizeof(eth_type), &eth_type);
-
-		length = (header.dr_rbcl | (header.dr_rbch << 8)) -
-			sizeof(dp_rcvhdr_t);
-		next = header.dr_next;
-		if (length < ETH_MIN_PACK_SIZE ||
-			length > ETH_MAX_PACK_SIZE_TAGGED)
-		{
-			printf("%s: packet with strange length arrived: %d\n",
-				dep->de_name, (int) length);
-			next= curr;
-		}
-		else if (next < dep->de_startpage || next >= dep->de_stoppage)
-		{
-			printf("%s: strange next page\n", dep->de_name);
-			next= curr;
-		}
-/*		else if (eth_type == eth_ign_proto)
-		{
-*/			/* Hack: ignore packets of a given protocol, useful
-			 * if you share a net with 80 computers sending
-			 * Amoeba FLIP broadcasts.  (Protocol 0x8146.)
-			 */
-/*			static int first= 1;
-			if (first)
-			{
-				first= 0;
-				printf("%s: dropping proto 0x%04x packets\n",
-					dep->de_name,
-					ntohs(eth_ign_proto));
-			}
-			dep->de_stat.ets_packetR++;
-		}
-*/		else if (header.dr_status &RSR_FO)
-		{
-			/* This is very serious, so we issue a warning and
-			 * reset the buffers */
-			printf("%s: fifo overrun, resetting receive buffer\n",
-				dep->de_name);
-			dep->de_stat.ets_fifoOver++;
-			next = curr;
-		}
-		else if ((header.dr_status &RSR_PRX) && 
-					   (dep->de_flags &DEF_ENABLED))
-		{
-//			if (dep->de_safecopy_read)
-//				r = dp_pkt2user_s(dep, pageno, length);
-//			else
-				r = dp_pkt2user(dep, pageno, length);
-			if (r != OK)
-				return;
-
-			packet_processed = TRUE;
-			dep->de_stat.ets_packetR++;
-		}
-		if (next == dep->de_startpage)
-			outb_reg0(dep, DP_BNRY, dep->de_stoppage - 1);
-		else
-			outb_reg0(dep, DP_BNRY, next - 1);
-
-		pageno = next;
-	}
-	while (!packet_processed);
-}
-
-/*===========================================================================*
- *				dp_send					     *
- *===========================================================================*/
-static void dp_send(dep)
-dpeth_t *dep;
-{
-	packet_t packet;
-
-//	if (!(dep->de_flags &DEF_SEND_AVAIL))
-//		return;
-
-	if(dep->packet_queue){
-		packet = dep->packet_queue;
-		dep->packet_queue = pq_detach(packet);
-		do_pwrite(dep, packet, TRUE);
-		netif_pq_release(packet_get_id(packet));
-		-- dep->packet_count;
-	}
-//	if(! dep->packet_queue){
-//		dep->de_flags &= ~DEF_SEND_AVAIL;
-//	}
-/*	switch(dep->de_sendmsg.m_type)
-	{
-	case DL_WRITE:	do_vwrite(&dep->de_sendmsg, TRUE, FALSE);	break;
-	case DL_WRITEV:	do_vwrite(&dep->de_sendmsg, TRUE, TRUE);	break;
-	case DL_WRITEV_S: do_vwrite_s(&dep->de_sendmsg, TRUE);	break;
-	default:
-		panic("", "dp8390: wrong type", dep->de_sendmsg.m_type);
-		break;
-	}
-*/
-}
-
-/*===========================================================================*
- *				dp_getblock				     *
- *===========================================================================*/
-static void dp_getblock(dep, page, offset, size, dst)
-dpeth_t *dep;
-int page;
-size_t offset;
-size_t size;
-void *dst;
-{
-//	int r;
-
-	offset = page * DP_PAGESIZE + offset;
-
-	memcpy(dst, dep->de_locmem + offset, size);
-}
-
-/*===========================================================================*
- *				dp_pio8_getblock			     *
- *===========================================================================*/
-static void dp_pio8_getblock(dep, page, offset, size, dst)
-dpeth_t *dep;
-int page;
-size_t offset;
-size_t size;
-void *dst;
-{
-	offset = page * DP_PAGESIZE + offset;
-	outb_reg0(dep, DP_RBCR0, size &0xFF);
-	outb_reg0(dep, DP_RBCR1, size >> 8);
-	outb_reg0(dep, DP_RSAR0, offset &0xFF);
-	outb_reg0(dep, DP_RSAR1, offset >> 8);
-	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
-
-	insb(dep->de_data_port, dst, size);
-}
-
-/*===========================================================================*
- *				dp_pio16_getblock			     *
- *===========================================================================*/
-static void dp_pio16_getblock(dep, page, offset, size, dst)
-dpeth_t *dep;
-int page;
-size_t offset;
-size_t size;
-void *dst;
-{
-	offset = page * DP_PAGESIZE + offset;
-	outb_reg0(dep, DP_RBCR0, size &0xFF);
-	outb_reg0(dep, DP_RBCR1, size >> 8);
-	outb_reg0(dep, DP_RSAR0, offset &0xFF);
-	outb_reg0(dep, DP_RSAR1, offset >> 8);
-	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
-
-	assert (!(size &1));
-	insw(dep->de_data_port, dst, size);
-}
-
-/*===========================================================================*
- *				dp_pkt2user				     *
- *===========================================================================*/
-static int dp_pkt2user(dep, page, length)
-dpeth_t *dep;
-int page, length;
-{
-	int last, count;
-	packet_t packet;
-
-//	if (!(dep->de_flags &DEF_READING))
-//		return EGENERIC;
-
-	packet = netif_packet_get_1(length);
-	if(! packet){
-		return ENOMEM;
-	}
-	dep->de_read_iovec.iod_iovec[0].iov_addr = (vir_bytes) packet_suffix(packet, length);
-	dep->de_read_iovec.iod_iovec[0].iov_size = length;
-	dep->de_read_iovec.iod_iovec_s = 1;
-	dep->de_read_iovec.iod_iovec_addr = NULL;
-
-	last = page + (length - 1) / DP_PAGESIZE;
-	if (last >= dep->de_stoppage)
-	{
-		count = (dep->de_stoppage - page) * DP_PAGESIZE -
-			sizeof(dp_rcvhdr_t);
-
-		/* Save read_iovec since we need it twice. */
-		dep->de_tmp_iovec = dep->de_read_iovec;
-		(dep->de_nic2userf)(dep, page * DP_PAGESIZE +
-			sizeof(dp_rcvhdr_t), &dep->de_tmp_iovec, 0, count);
-		(dep->de_nic2userf)(dep, dep->de_startpage * DP_PAGESIZE, 
-			&dep->de_read_iovec, count, length - count);
-	}
-	else
-	{
-		(dep->de_nic2userf)(dep, page * DP_PAGESIZE +
-			sizeof(dp_rcvhdr_t), &dep->de_read_iovec, 0, length);
-	}
-
-	dep->de_read_s = length;
-	dep->de_flags |= DEF_PACK_RECV;
-//	dep->de_flags &= ~DEF_READING;
-
-	if(dep->received_count >= MAX_PACKETS){
-		netif_pq_release(packet_get_id(packet));
-		return ELIMIT;
-	}else{
-		if(pq_add(&dep->received_queue, packet, 0, 0) == EOK){
-			++ dep->received_count;
-		}else{
-			netif_pq_release(packet_get_id(packet));
-		}
-	}
-	return OK;
-}
-
-/*===========================================================================*
- *				dp_user2nic				     *
- *===========================================================================*/
-static void dp_user2nic(dep, iovp, offset, nic_addr, count)
-dpeth_t *dep;
-iovec_dat_t *iovp;
-vir_bytes offset;
-int nic_addr;
-vir_bytes count;
-{
-	vir_bytes vir_hw;//, vir_user;
-	//int bytes, i, r;
-	int i, r;
-	vir_bytes bytes;
-
-	vir_hw = (vir_bytes)dep->de_locmem + nic_addr;
-
-	i= 0;
-	while (count > 0)
-	{
-		if (i >= IOVEC_NR)
-		{
-			dp_next_iovec(iovp);
-			i= 0;
-			continue;
-		}
-		assert(i < iovp->iod_iovec_s);
-		if (offset >= iovp->iod_iovec[i].iov_size)
-		{
-			offset -= iovp->iod_iovec[i].iov_size;
-			i++;
-			continue;
-		}
-		bytes = iovp->iod_iovec[i].iov_size - offset;
-		if (bytes > count)
-			bytes = count;
-
-		r= sys_vircopy(iovp->iod_proc_nr, D,
-			iovp->iod_iovec[i].iov_addr + offset,
-			SELF, D, vir_hw, bytes);
-		if (r != OK)
-			panic("DP8390", "dp_user2nic: sys_vircopy failed", r);
-
-		count -= bytes;
-		vir_hw += bytes;
-		offset += bytes;
-	}
-	assert(count == 0);
-}
-
-/*===========================================================================*
- *				dp_pio8_user2nic			     *
- *===========================================================================*/
-static void dp_pio8_user2nic(dep, iovp, offset, nic_addr, count)
-dpeth_t *dep;
-iovec_dat_t *iovp;
-vir_bytes offset;
-int nic_addr;
-vir_bytes count;
-{
-//	phys_bytes phys_user;
-	int i;
-	vir_bytes bytes;
-
-	outb_reg0(dep, DP_ISR, ISR_RDC);
-
-	outb_reg0(dep, DP_RBCR0, count &0xFF);
-	outb_reg0(dep, DP_RBCR1, count >> 8);
-	outb_reg0(dep, DP_RSAR0, nic_addr &0xFF);
-	outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
-	outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
-
-	i= 0;
-	while (count > 0)
-	{
-		if (i >= IOVEC_NR)
-		{
-			dp_next_iovec(iovp);
-			i= 0;
-			continue;
-		}
-		assert(i < iovp->iod_iovec_s);
-		if (offset >= iovp->iod_iovec[i].iov_size)
-		{
-			offset -= iovp->iod_iovec[i].iov_size;
-			i++;
-			continue;
-		}
-		bytes = iovp->iod_iovec[i].iov_size - offset;
-		if (bytes > count)
-			bytes = count;
-
-		do_vir_outsb(dep->de_data_port, iovp->iod_proc_nr,
-			iovp->iod_iovec[i].iov_addr + offset, bytes);
-		count -= bytes;
-		offset += bytes;
-	}
-	assert(count == 0);
-
-	for (i= 0; i<100; i++)
-	{
-		if (inb_reg0(dep, DP_ISR) &ISR_RDC)
-			break;
-	}
-	if (i == 100)
-	{
-		panic("", "dp8390: remote dma failed to complete", NO_NUM);
-	}
-}
-
-/*===========================================================================*
- *				dp_pio16_user2nic			     *
- *===========================================================================*/
-static void dp_pio16_user2nic(dep, iovp, offset, nic_addr, count)
-dpeth_t *dep;
-iovec_dat_t *iovp;
-vir_bytes offset;
-int nic_addr;
-vir_bytes count;
-{
-	vir_bytes vir_user;
-	vir_bytes ecount;
-	int i, r, user_proc;
-	vir_bytes bytes;
-	//u8_t two_bytes[2];
-	u16_t two_bytes;
-	int odd_byte;
-
-	ecount= (count+1) &~1;
-	odd_byte= 0;
-
-	outb_reg0(dep, DP_ISR, ISR_RDC);
-	outb_reg0(dep, DP_RBCR0, ecount &0xFF);
-	outb_reg0(dep, DP_RBCR1, ecount >> 8);
-	outb_reg0(dep, DP_RSAR0, nic_addr &0xFF);
-	outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
-	outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
-
-	i= 0;
-	while (count > 0)
-	{
-		if (i >= IOVEC_NR)
-		{
-			dp_next_iovec(iovp);
-			i= 0;
-			continue;
-		}
-		assert(i < iovp->iod_iovec_s);
-		if (offset >= iovp->iod_iovec[i].iov_size)
-		{
-			offset -= iovp->iod_iovec[i].iov_size;
-			i++;
-			continue;
-		}
-		bytes = iovp->iod_iovec[i].iov_size - offset;
-		if (bytes > count)
-			bytes = count;
-
-		user_proc= iovp->iod_proc_nr;
-		vir_user= iovp->iod_iovec[i].iov_addr + offset;
-		if (odd_byte)
-		{
-			r= sys_vircopy(user_proc, D, vir_user, 
-			//	SELF, D, (vir_bytes)&two_bytes[1], 1);
-				SELF, D, (vir_bytes)&(((u8_t *)&two_bytes)[1]), 1);
-			if (r != OK)
-			{
-				panic("DP8390",
-					"dp_pio16_user2nic: sys_vircopy failed",
-					r);
-			}
-			//outw(dep->de_data_port, *(u16_t *)two_bytes);
-			outw(dep->de_data_port, two_bytes);
-			count--;
-			offset++;
-			bytes--;
-			vir_user++;
-			odd_byte= 0;
-			if (!bytes)
-				continue;
-		}
-		ecount= bytes &~1;
-		if (ecount != 0)
-		{
-			do_vir_outsw(dep->de_data_port, user_proc, vir_user,
-				ecount);
-			count -= ecount;
-			offset += ecount;
-			bytes -= ecount;
-			vir_user += ecount;
-		}
-		if (bytes)
-		{
-			assert(bytes == 1);
-			r= sys_vircopy(user_proc, D, vir_user, 
-			//	SELF, D, (vir_bytes)&two_bytes[0], 1);
-				SELF, D, (vir_bytes)&(((u8_t *)&two_bytes)[0]), 1);
-			if (r != OK)
-			{
-				panic("DP8390",
-					"dp_pio16_user2nic: sys_vircopy failed",
-					r);
-			}
-			count--;
-			offset++;
-			bytes--;
-			vir_user++;
-			odd_byte= 1;
-		}
-	}
-	assert(count == 0);
-
-	if (odd_byte)
-		//outw(dep->de_data_port, *(u16_t *)two_bytes);
-		outw(dep->de_data_port, two_bytes);
-
-	for (i= 0; i<100; i++)
-	{
-		if (inb_reg0(dep, DP_ISR) &ISR_RDC)
-			break;
-	}
-	if (i == 100)
-	{
-		panic("", "dp8390: remote dma failed to complete", NO_NUM);
-	}
-}
-
-/*===========================================================================*
- *				dp_nic2user				     *
- *===========================================================================*/
-static void dp_nic2user(dep, nic_addr, iovp, offset, count)
-dpeth_t *dep;
-int nic_addr;
-iovec_dat_t *iovp;
-vir_bytes offset;
-vir_bytes count;
-{
-	vir_bytes vir_hw;//, vir_user;
-	vir_bytes bytes;
-	int i, r;
-
-	vir_hw = (vir_bytes)dep->de_locmem + nic_addr;
-
-	i= 0;
-	while (count > 0)
-	{
-		if (i >= IOVEC_NR)
-		{
-			dp_next_iovec(iovp);
-			i= 0;
-			continue;
-		}
-		assert(i < iovp->iod_iovec_s);
-		if (offset >= iovp->iod_iovec[i].iov_size)
-		{
-			offset -= iovp->iod_iovec[i].iov_size;
-			i++;
-			continue;
-		}
-		bytes = iovp->iod_iovec[i].iov_size - offset;
-		if (bytes > count)
-			bytes = count;
-
-		r= sys_vircopy(SELF, D, vir_hw,
-			iovp->iod_proc_nr, D,
-			iovp->iod_iovec[i].iov_addr + offset, bytes);
-		if (r != OK)
-			panic("DP8390", "dp_nic2user: sys_vircopy failed", r);
-
-		count -= bytes;
-		vir_hw += bytes;
-		offset += bytes;
-	}
-	assert(count == 0);
-}
-
-/*===========================================================================*
- *				dp_pio8_nic2user			     *
- *===========================================================================*/
-static void dp_pio8_nic2user(dep, nic_addr, iovp, offset, count)
-dpeth_t *dep;
-int nic_addr;
-iovec_dat_t *iovp;
-vir_bytes offset;
-vir_bytes count;
-{
-//	phys_bytes phys_user;
-	int i;
-	vir_bytes bytes;
-
-	outb_reg0(dep, DP_RBCR0, count &0xFF);
-	outb_reg0(dep, DP_RBCR1, count >> 8);
-	outb_reg0(dep, DP_RSAR0, nic_addr &0xFF);
-	outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
-	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
-
-	i= 0;
-	while (count > 0)
-	{
-		if (i >= IOVEC_NR)
-		{
-			dp_next_iovec(iovp);
-			i= 0;
-			continue;
-		}
-		assert(i < iovp->iod_iovec_s);
-		if (offset >= iovp->iod_iovec[i].iov_size)
-		{
-			offset -= iovp->iod_iovec[i].iov_size;
-			i++;
-			continue;
-		}
-		bytes = iovp->iod_iovec[i].iov_size - offset;
-		if (bytes > count)
-			bytes = count;
-
-		do_vir_insb(dep->de_data_port, iovp->iod_proc_nr,
-			iovp->iod_iovec[i].iov_addr + offset, bytes);
-		count -= bytes;
-		offset += bytes;
-	}
-	assert(count == 0);
-}
-
-/*===========================================================================*
- *				dp_pio16_nic2user			     *
- *===========================================================================*/
-static void dp_pio16_nic2user(dep, nic_addr, iovp, offset, count)
-dpeth_t *dep;
-int nic_addr;
-iovec_dat_t *iovp;
-vir_bytes offset;
-vir_bytes count;
-{
-	vir_bytes vir_user;
-	vir_bytes ecount;
-	int i, r, user_proc;
-	vir_bytes bytes;
-	//u8_t two_bytes[2];
-	u16_t two_bytes;
-	int odd_byte;
-
-	ecount= (count+1) &~1;
-	odd_byte= 0;
-
-	outb_reg0(dep, DP_RBCR0, ecount &0xFF);
-	outb_reg0(dep, DP_RBCR1, ecount >> 8);
-	outb_reg0(dep, DP_RSAR0, nic_addr &0xFF);
-	outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
-	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
-
-	i= 0;
-	while (count > 0)
-	{
-		if (i >= IOVEC_NR)
-		{
-			dp_next_iovec(iovp);
-			i= 0;
-			continue;
-		}
-		assert(i < iovp->iod_iovec_s);
-		if (offset >= iovp->iod_iovec[i].iov_size)
-		{
-			offset -= iovp->iod_iovec[i].iov_size;
-			i++;
-			continue;
-		}
-		bytes = iovp->iod_iovec[i].iov_size - offset;
-		if (bytes > count)
-			bytes = count;
-
-		user_proc= iovp->iod_proc_nr;
-		vir_user= iovp->iod_iovec[i].iov_addr + offset;
-		if (odd_byte)
-		{
-			//r= sys_vircopy(SELF, D, (vir_bytes)&two_bytes[1],
-			r= sys_vircopy(SELF, D, (vir_bytes)&(((u8_t *)&two_bytes)[1]),
-				user_proc, D, vir_user,  1);
-			if (r != OK)
-			{
-				panic("DP8390",
-					"dp_pio16_nic2user: sys_vircopy failed",
-					r);
-			}
-			count--;
-			offset++;
-			bytes--;
-			vir_user++;
-			odd_byte= 0;
-			if (!bytes)
-				continue;
-		}
-		ecount= bytes &~1;
-		if (ecount != 0)
-		{
-			do_vir_insw(dep->de_data_port, user_proc, vir_user,
-				ecount);
-			count -= ecount;
-			offset += ecount;
-			bytes -= ecount;
-			vir_user += ecount;
-		}
-		if (bytes)
-		{
-			assert(bytes == 1);
-			//*(u16_t *)two_bytes= inw(dep->de_data_port);
-			two_bytes= inw(dep->de_data_port);
-			//r= sys_vircopy(SELF, D, (vir_bytes)&two_bytes[0],
-			r= sys_vircopy(SELF, D, (vir_bytes)&(((u8_t *)&two_bytes)[0]),
-				user_proc, D, vir_user,  1);
-			if (r != OK)
-			{
-				panic("DP8390",
-					"dp_pio16_nic2user: sys_vircopy failed",
-					r);
-			}
-			count--;
-			offset++;
-			bytes--;
-			vir_user++;
-			odd_byte= 1;
-		}
-	}
-	assert(count == 0);
-}
-
-/*===========================================================================*
- *				dp_next_iovec				     *
- *===========================================================================*/
-static void dp_next_iovec(iovp)
-iovec_dat_t *iovp;
-{
-	assert(iovp->iod_iovec_s > IOVEC_NR);
-
-	iovp->iod_iovec_s -= IOVEC_NR;
-
-	iovp->iod_iovec_addr += IOVEC_NR * sizeof(iovec_t);
-
-	get_userdata(iovp->iod_proc_nr, iovp->iod_iovec_addr, 
-		(iovp->iod_iovec_s > IOVEC_NR ? IOVEC_NR : iovp->iod_iovec_s) *
-		sizeof(iovec_t), iovp->iod_iovec); 
-}
-
-/*===========================================================================*
- *				conf_hw					     *
- *===========================================================================*/
-static void conf_hw(dep)
-dpeth_t *dep;
-{
-//	static eth_stat_t empty_stat = {0, 0, 0, 0, 0, 0 	/* ,... */};
-
-//	int ifnr;
-//	dp_conf_t *dcp;
-
-//	dep->de_mode= DEM_DISABLED;	/* Superfluous */
-//	ifnr= dep-de_table;
-
-//	dcp= &dp_conf[ifnr];
-//	update_conf(dep, dcp);
-//	if (dep->de_mode != DEM_ENABLED)
-//		return;
-	if (!wdeth_probe(dep) && !ne_probe(dep) && !el2_probe(dep))
-	{
-		printf("%s: No ethernet card found at 0x%x\n", 
-			dep->de_name, dep->de_base_port);
-		dep->de_mode= DEM_DISABLED;
-		return;
-	}
-
-/* XXX */ if (dep->de_linmem == 0) dep->de_linmem= 0xFFFF0000;
-
-	dep->de_mode = DEM_ENABLED;
-
-	dep->de_flags = DEF_EMPTY;
-//	dep->de_stat = empty_stat;
-}
-
-/*===========================================================================*
- *				map_hw_buffer				     *
- *===========================================================================*/
-static void map_hw_buffer(dep)
-dpeth_t *dep;
-{
-//	int r;
-//	size_t o, size;
-//	char *buf, *abuf;
-
-	if (dep->de_prog_IO)
-	{
-#if 0
-		if(debug){
-			printf(
-			"map_hw_buffer: programmed I/O, no need to map buffer\n");
-		}
-#endif
-		dep->de_locmem = (char *)-dep->de_ramsize; /* trap errors */
-		return;
-	}else{
-		printf("map_hw_buffer: no buffer!\n");
-	}
-
-//	size = dep->de_ramsize + PAGE_SIZE;	/* Add PAGE_SIZE for
-//						 * alignment
-//						 */
-//	buf= malloc(size);
-//	if (buf == NULL)
-//		panic(__FILE__, "map_hw_buffer: cannot malloc size", size);
-//	o= PAGE_SIZE - ((vir_bytes)buf % PAGE_SIZE);
-//	abuf= buf + o;
-//	printf("buf at 0x%x, abuf at 0x%x\n", buf, abuf);
-
-//	r= sys_vm_map(SELF, 1 /* map */, (vir_bytes)abuf,
-//			dep->de_ramsize, (phys_bytes)dep->de_linmem);
-//	if (r != OK)
-//		panic(__FILE__, "map_hw_buffer: sys_vm_map failed", r);
-//	dep->de_locmem = abuf;
-}
-
-/*===========================================================================*
- *				reply					     *
- *===========================================================================*/
-static void reply(dep, err, may_block)
-dpeth_t *dep;
-int err;
-int may_block;
-{
-/*	message reply;
-	int status;
-	int r;
-
-	status = 0;
-	if (dep->de_flags &DEF_PACK_SEND)
-		status |= DL_PACK_SEND;
-	if (dep->de_flags &DEF_PACK_RECV)
-		status |= DL_PACK_RECV;
-
-	reply.m_type = DL_TASK_REPLY;
-	reply.DL_PORT = dep - de_table;
-	reply.DL_PROC = dep->de_client;
-	reply.DL_STAT = status | ((u32_t) err << 16);
-	reply.DL_COUNT = dep->de_read_s;
-	reply.DL_CLCK = 0;	*//* Don't know */
-/*	r= send(dep->de_client, &reply);
-
-	if (r == ELOCKED && may_block)
-	{
-#if 0
-		printf("send locked\n");
-#endif
-		return;
-	}
-
-	if (r < 0)
-		panic("", "dp8390: send failed:", r);
-	
-*/	dep->de_read_s = 0;
-//	dep->de_flags &= ~(DEF_PACK_SEND | DEF_PACK_RECV);
-}
-
-/*===========================================================================*
- *				get_userdata				     *
- *===========================================================================*/
-static void get_userdata(user_proc, user_addr, count, loc_addr)
-int user_proc;
-vir_bytes user_addr;
-vir_bytes count;
-void *loc_addr;
-{
-	int r;
-
-	r= sys_vircopy(user_proc, D, user_addr,
-		SELF, D, (vir_bytes)loc_addr, count);
-	if (r != OK)
-		panic("DP8390", "get_userdata: sys_vircopy failed", r);
-}
-
-static void insb(port_t port, void *buf, size_t size)
-{
-	size_t i;
-
-	for(i = 0; i < size; ++ i){
-		*((uint8_t *) buf + i) = inb(port);
-	}
-}
-
-static void insw(port_t port, void *buf, size_t size)
-{
-	size_t i;
-
-	for(i = 0; i * 2 < size; ++ i){
-		*((uint16_t *) buf + i) = inw(port);
-	}
-}
-
-static void outsb(port_t port, void *buf, size_t size)
-{
-	size_t i;
-
-	for(i = 0; i < size; ++ i){
-		outb(port, *((uint8_t *) buf + i));
-	}
-}
-
-static void outsw(port_t port, void *buf, size_t size)
-{
-	size_t i;
-
-	for(i = 0; i * 2 < size; ++ i){
-		outw(port, *((uint16_t *) buf + i));
-	}
-}
-
-/*
- * $PchId: dp8390.c,v 1.25 2005/02/10 17:32:07 philip Exp $
- */
-
-/** @}
- */
Index: pace/srv/net/netif/dp8390/dp8390.h
===================================================================
--- uspace/srv/net/netif/dp8390/dp8390.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,431 +1,0 @@
-/*
- * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system 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.
- * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
- * * Any deviations from these conditions require written permission from the copyright holder in advance
- *
- *
- * Disclaimer
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``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 COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS 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.
- *
- * Changes:
- *  2009 ported to HelenOS, Lukas Mejdrech
- */
-
-/** @addtogroup dp8390
- *  @{
- */
-
-/** @file
- *  DP8390 network interface definitions.
- */
-
-#ifndef __NET_NETIF_DP8390_H__
-#define __NET_NETIF_DP8390_H__
-
-#include "../../structures/packet/packet.h"
-
-#include "dp8390_port.h"
-#include "local.h"
-
-/** Input/output size.
- */
-#define DP8390_IO_SIZE	0x01f
-
-/*
-dp8390.h
-
-Created:	before Dec 28, 1992 by Philip Homburg
-*/
-
-/* National Semiconductor DP8390 Network Interface Controller. */
-
-				/* Page 0, for reading ------------- */
-#define	DP_CR		0x0	/* Read side of Command Register     */
-#define	DP_CLDA0	0x1	/* Current Local Dma Address 0       */
-#define	DP_CLDA1	0x2	/* Current Local Dma Address 1       */
-#define	DP_BNRY		0x3	/* Boundary Pointer                  */
-#define	DP_TSR		0x4	/* Transmit Status Register          */
-#define	DP_NCR		0x5	/* Number of Collisions Register     */
-#define	DP_FIFO		0x6	/* Fifo ??                           */
-#define	DP_ISR		0x7	/* Interrupt Status Register         */
-#define	DP_CRDA0	0x8	/* Current Remote Dma Address 0      */
-#define	DP_CRDA1	0x9	/* Current Remote Dma Address 1      */
-#define	DP_DUM1		0xA	/* unused                            */
-#define	DP_DUM2		0xB	/* unused                            */
-#define	DP_RSR		0xC	/* Receive Status Register           */
-#define	DP_CNTR0	0xD	/* Tally Counter 0                   */
-#define	DP_CNTR1	0xE	/* Tally Counter 1                   */
-#define	DP_CNTR2	0xF	/* Tally Counter 2                   */
-
-				/* Page 0, for writing ------------- */
-#define	DP_CR		0x0	/* Write side of Command Register    */
-#define	DP_PSTART	0x1	/* Page Start Register               */
-#define	DP_PSTOP	0x2	/* Page Stop Register                */
-#define	DP_BNRY		0x3	/* Boundary Pointer                  */
-#define	DP_TPSR		0x4	/* Transmit Page Start Register      */
-#define	DP_TBCR0	0x5	/* Transmit Byte Count Register 0    */
-#define	DP_TBCR1	0x6	/* Transmit Byte Count Register 1    */
-#define	DP_ISR		0x7	/* Interrupt Status Register         */
-#define	DP_RSAR0	0x8	/* Remote Start Address Register 0   */
-#define	DP_RSAR1	0x9	/* Remote Start Address Register 1   */
-#define	DP_RBCR0	0xA	/* Remote Byte Count Register 0      */
-#define	DP_RBCR1	0xB	/* Remote Byte Count Register 1      */
-#define	DP_RCR		0xC	/* Receive Configuration Register    */
-#define	DP_TCR		0xD	/* Transmit Configuration Register   */
-#define	DP_DCR		0xE	/* Data Configuration Register       */
-#define	DP_IMR		0xF	/* Interrupt Mask Register           */
-
-				/* Page 1, read/write -------------- */
-#define	DP_CR		0x0	/* Command Register                  */
-#define	DP_PAR0		0x1	/* Physical Address Register 0       */
-#define	DP_PAR1		0x2	/* Physical Address Register 1       */
-#define	DP_PAR2		0x3	/* Physical Address Register 2       */
-#define	DP_PAR3		0x4	/* Physical Address Register 3       */
-#define	DP_PAR4		0x5	/* Physical Address Register 4       */
-#define	DP_PAR5		0x6	/* Physical Address Register 5       */
-#define	DP_CURR		0x7	/* Current Page Register             */
-#define	DP_MAR0		0x8	/* Multicast Address Register 0      */
-#define	DP_MAR1		0x9	/* Multicast Address Register 1      */
-#define	DP_MAR2		0xA	/* Multicast Address Register 2      */
-#define	DP_MAR3		0xB	/* Multicast Address Register 3      */
-#define	DP_MAR4		0xC	/* Multicast Address Register 4      */
-#define	DP_MAR5		0xD	/* Multicast Address Register 5      */
-#define	DP_MAR6		0xE	/* Multicast Address Register 6      */
-#define	DP_MAR7		0xF	/* Multicast Address Register 7      */
-
-/* Bits in dp_cr */
-#define CR_STP		0x01	/* Stop: software reset              */
-#define CR_STA		0x02	/* Start: activate NIC               */
-#define CR_TXP		0x04	/* Transmit Packet                   */
-#define CR_DMA		0x38	/* Mask for DMA control              */
-#define CR_DM_NOP	0x00	/* DMA: No Operation                 */
-#define CR_DM_RR	0x08	/* DMA: Remote Read                  */
-#define CR_DM_RW	0x10	/* DMA: Remote Write                 */
-#define CR_DM_SP	0x18	/* DMA: Send Packet                  */
-#define CR_DM_ABORT	0x20	/* DMA: Abort Remote DMA Operation   */
-#define CR_PS		0xC0	/* Mask for Page Select              */
-#define CR_PS_P0	0x00	/* Register Page 0                   */
-#define CR_PS_P1	0x40	/* Register Page 1                   */
-#define CR_PS_P2	0x80	/* Register Page 2                   */
-#define CR_PS_T1	0xC0	/* Test Mode Register Map            */
-
-/* Bits in dp_isr */
-#define ISR_PRX		0x01	/* Packet Received with no errors    */
-#define ISR_PTX		0x02	/* Packet Transmitted with no errors */
-#define ISR_RXE		0x04	/* Receive Error                     */
-#define ISR_TXE		0x08	/* Transmit Error                    */
-#define ISR_OVW		0x10	/* Overwrite Warning                 */
-#define ISR_CNT		0x20	/* Counter Overflow                  */
-#define ISR_RDC		0x40	/* Remote DMA Complete               */
-#define ISR_RST		0x80	/* Reset Status                      */
-
-/* Bits in dp_imr */
-#define IMR_PRXE	0x01	/* Packet Received iEnable           */
-#define IMR_PTXE	0x02	/* Packet Transmitted iEnable        */
-#define IMR_RXEE	0x04	/* Receive Error iEnable             */
-#define IMR_TXEE	0x08	/* Transmit Error iEnable            */
-#define IMR_OVWE	0x10	/* Overwrite Warning iEnable         */
-#define IMR_CNTE	0x20	/* Counter Overflow iEnable          */
-#define IMR_RDCE	0x40	/* DMA Complete iEnable              */
-
-/* Bits in dp_dcr */
-#define DCR_WTS		0x01	/* Word Transfer Select              */
-#define DCR_BYTEWIDE	0x00	/* WTS: byte wide transfers          */
-#define DCR_WORDWIDE	0x01	/* WTS: word wide transfers          */
-#define DCR_BOS		0x02	/* Byte Order Select                 */
-#define DCR_LTLENDIAN	0x00	/* BOS: Little Endian                */
-#define DCR_BIGENDIAN	0x02	/* BOS: Big Endian                   */
-#define DCR_LAS		0x04	/* Long Address Select               */
-#define DCR_BMS		0x08	/* Burst Mode Select
-				 * Called Loopback Select (LS) in 
-				 * later manuals. Should be set.     */
-#define DCR_AR		0x10	/* Autoinitialize Remote             */
-#define DCR_FTS		0x60	/* Fifo Threshold Select             */
-#define DCR_2BYTES	0x00	/* 2 bytes                           */
-#define DCR_4BYTES	0x40	/* 4 bytes                           */
-#define DCR_8BYTES	0x20	/* 8 bytes                           */
-#define DCR_12BYTES	0x60	/* 12 bytes                          */
-
-/* Bits in dp_tcr */
-#define TCR_CRC		0x01	/* Inhibit CRC                       */
-#define TCR_ELC		0x06	/* Encoded Loopback Control          */
-#define TCR_NORMAL	0x00	/* ELC: Normal Operation             */
-#define TCR_INTERNAL	0x02	/* ELC: Internal Loopback            */
-#define TCR_0EXTERNAL	0x04	/* ELC: External Loopback LPBK=0     */
-#define TCR_1EXTERNAL	0x06	/* ELC: External Loopback LPBK=1     */
-#define TCR_ATD		0x08	/* Auto Transmit Disable             */
-#define TCR_OFST	0x10	/* Collision Offset Enable (be nice) */
-
-/* Bits in dp_tsr */
-#define TSR_PTX		0x01	/* Packet Transmitted (without error)*/
-#define TSR_DFR		0x02	/* Transmit Deferred, reserved in
-				 * later manuals.		     */
-#define TSR_COL		0x04	/* Transmit Collided                 */
-#define TSR_ABT		0x08	/* Transmit Aborted                  */
-#define TSR_CRS		0x10	/* Carrier Sense Lost                */
-#define TSR_FU		0x20	/* FIFO Underrun                     */
-#define TSR_CDH		0x40	/* CD Heartbeat                      */
-#define TSR_OWC		0x80	/* Out of Window Collision           */
-
-/* Bits in tp_rcr */
-#define RCR_SEP		0x01	/* Save Errored Packets              */
-#define RCR_AR		0x02	/* Accept Runt Packets               */
-#define RCR_AB		0x04	/* Accept Broadcast                  */
-#define RCR_AM		0x08	/* Accept Multicast                  */
-#define RCR_PRO		0x10	/* Physical Promiscuous              */
-#define RCR_MON		0x20	/* Monitor Mode                      */
-
-/* Bits in dp_rsr */
-#define RSR_PRX		0x01	/* Packet Received Intact            */
-#define RSR_CRC		0x02	/* CRC Error                         */
-#define RSR_FAE		0x04	/* Frame Alignment Error             */
-#define RSR_FO		0x08	/* FIFO Overrun                      */
-#define RSR_MPA		0x10	/* Missed Packet                     */
-#define RSR_PHY		0x20	/* Multicast Address Match           */
-#define RSR_DIS		0x40	/* Receiver Disabled                 */
-#define RSR_DFR		0x80	/* In later manuals: Deferring       */
-
-/** Type definition of the receive header.
- */
-typedef struct dp_rcvhdr
-{
-	/** Copy of rsr.
-	 */
-	u8_t dr_status;
-	/** Pointer to next packet.
-	 */
-	u8_t dr_next;
-	/** Receive Byte Count Low.
-	 */
-	u8_t dr_rbcl;
-	/** Receive Byte Count High.
-	 */
-	u8_t dr_rbch;
-} dp_rcvhdr_t;
-
-/** Page size.
- */
-#define DP_PAGESIZE	256
-
-/* Some macros to simplify accessing the dp8390 */
-/** Reads 1 byte from the zero page register.
- *  @param[in] dep The network interface structure.
- *  @param[in] reg The register offset.
- *  @returns The read value.
- */
-#define inb_reg0(dep, reg)		(inb(dep->de_dp8390_port+reg))
-
-/** Writes 1 byte zero page register.
- *  @param[in] dep The network interface structure.
- *  @param[in] reg The register offset.
- *  @param[in] data The value to be written.
- */
-#define outb_reg0(dep, reg, data)	(outb(dep->de_dp8390_port+reg, data))
-
-/** Reads 1 byte from the first page register.
- *  @param[in] dep The network interface structure.
- *  @param[in] reg The register offset.
- *  @returns The read value.
- */
-#define inb_reg1(dep, reg)		(inb(dep->de_dp8390_port+reg))
-
-/** Writes 1 byte first page register.
- *  @param[in] dep The network interface structure.
- *  @param[in] reg The register offset.
- *  @param[in] data The value to be written.
- */
-#define outb_reg1(dep, reg, data)	(outb(dep->de_dp8390_port+reg, data))
-
-/* Software interface to the dp8390 driver */
-
-struct dpeth;
-struct iovec_dat;
-//struct iovec_dat_s;
-_PROTOTYPE(typedef void (*dp_initf_t), (struct dpeth *dep)		);
-_PROTOTYPE(typedef void (*dp_stopf_t), (struct dpeth *dep)		);
-_PROTOTYPE(typedef void (*dp_user2nicf_t), (struct dpeth *dep,
-			struct iovec_dat *iovp, vir_bytes offset,
-			int nic_addr, vir_bytes count) );
-//_PROTOTYPE(typedef void (*dp_user2nicf_s_t), (struct dpeth *dep,
-//			struct iovec_dat_s *iovp, vir_bytes offset,
-//			int nic_addr, vir_bytes count)			);
-_PROTOTYPE(typedef void (*dp_nic2userf_t), (struct dpeth *dep,
-			int nic_addr, struct iovec_dat *iovp,
-			vir_bytes offset, vir_bytes count) );
-//_PROTOTYPE(typedef void (*dp_nic2userf_s_t), (struct dpeth *dep,
-//			int nic_addr, struct iovec_dat_s *iovp,
-//			vir_bytes offset, vir_bytes count)		);
-//#if 0
-//_PROTOTYPE(typedef void (*dp_getheaderf_t), (struct dpeth *dep,
-//			int page, struct dp_rcvhdr *h, u16_t *eth_type)	);
-//#endif
-_PROTOTYPE(typedef void (*dp_getblock_t), (struct dpeth *dep,
-		int page, size_t offset, size_t size, void *dst)	);
-
-/* iovectors are handled IOVEC_NR entries at a time. */
-//#define IOVEC_NR	16
-// no vectors allowed
-#define IOVEC_NR	1
-
-/*
-typedef int irq_hook_t;
-*/
-typedef struct iovec_dat
-{
-  iovec_t iod_iovec[IOVEC_NR];
-  int iod_iovec_s;
-  // no direct process access
-  int iod_proc_nr;
-  vir_bytes iod_iovec_addr;
-} iovec_dat_t;
-/*
-typedef struct iovec_dat_s
-{
-  iovec_s_t iod_iovec[IOVEC_NR];
-  int iod_iovec_s;
-  int iod_proc_nr;
-  cp_grant_id_t iod_grant;
-  vir_bytes iod_iovec_offset;
-} iovec_dat_s_t;
-*/
-#define SENDQ_NR	1	/* Maximum size of the send queue */
-#define SENDQ_PAGES	6	/* 6 * DP_PAGESIZE >= 1514 bytes */
-
-/** Maximum number of waiting packets to be sent or received.
- */
-#define MAX_PACKETS	4
-
-typedef struct dpeth
-{
-	/** Outgoing packets queue.
-	 */
-	packet_t packet_queue;
-	/** Outgoing packets count.
-	 */
-	int packet_count;
-
-	/** Received packets queue.
-	 */
-	packet_t received_queue;
-	/** Received packets count.
-	 */
-	int received_count;
-
-	/* The de_base_port field is the starting point of the probe.
-	 * The conf routine also fills de_linmem and de_irq. If the probe
-	 * routine knows the irq and/or memory address because they are
-	 * hardwired in the board, the probe should modify these fields.
-	 * Futhermore, the probe routine should also fill in de_initf and
-	 * de_stopf fields with the appropriate function pointers and set
-	 * de_prog_IO iff programmed I/O is to be used.
-	 */
-	port_t de_base_port;
-	phys_bytes de_linmem;
-	char *de_locmem;
-	int de_irq;
-	int de_int_pending;
-//	irq_hook_t de_hook;
-	dp_initf_t de_initf; 
-	dp_stopf_t de_stopf; 
-	int de_prog_IO;
-	char de_name[sizeof("dp8390#n")];
-
-	/* The initf function fills the following fields. Only cards that do
-	 * programmed I/O fill in the de_pata_port field.
-	 * In addition, the init routine has to fill in the sendq data
-	 * structures.
-	 */
-	ether_addr_t de_address;
-	port_t de_dp8390_port;
-	port_t de_data_port;
-	int de_16bit;
-	long de_ramsize;
-	int de_offset_page;
-	int de_startpage;
-	int de_stoppage;
-
-	/* should be here - read even for ne2k isa init... */
-	char de_pci;			/* TRUE iff PCI device */
-
-#if ENABLE_PCI
-	/* PCI config */
-//	char de_pci;			/* TRUE iff PCI device */
-//	u8_t de_pcibus;	
-//	u8_t de_pcidev;	
-//	u8_t de_pcifunc;	
-#endif
-
-	/* Do it yourself send queue */
-	struct sendq
-	{
-		int sq_filled;		/* this buffer contains a packet */
-		int sq_size;		/* with this size */
-		int sq_sendpage;	/* starting page of the buffer */
-	} de_sendq[SENDQ_NR];
-	int de_sendq_nr;
-	int de_sendq_head;		/* Enqueue at the head */
-	int de_sendq_tail;		/* Dequeue at the tail */
-
-	/* Fields for internal use by the dp8390 driver. */
-	int de_flags;
-	int de_mode;
-	eth_stat_t de_stat;
-	iovec_dat_t de_read_iovec;
-//	iovec_dat_s_t de_read_iovec_s;
-//	int de_safecopy_read;
-	iovec_dat_t de_write_iovec;
-//	iovec_dat_s_t de_write_iovec_s;
-	iovec_dat_t de_tmp_iovec;
-//	iovec_dat_s_t de_tmp_iovec_s;
-	vir_bytes de_read_s;
-//	int de_client;
-//	message de_sendmsg;
-	dp_user2nicf_t de_user2nicf; 
-//	dp_user2nicf_s_t de_user2nicf_s; 
-	dp_nic2userf_t de_nic2userf;
-//	dp_nic2userf_s_t de_nic2userf_s; 
-	dp_getblock_t de_getblockf;
-} dpeth_t;
-
-#define DEI_DEFAULT	0x8000
-
-#define DEF_EMPTY	0x000
-#define DEF_PACK_SEND	0x001
-#define DEF_PACK_RECV	0x002
-#define DEF_SEND_AVAIL	0x004
-#define DEF_READING	0x010
-#define DEF_PROMISC	0x040
-#define DEF_MULTI	0x080
-#define DEF_BROAD	0x100
-#define DEF_ENABLED	0x200
-#define DEF_STOPPED	0x400
-
-#define DEM_DISABLED	0x0
-#define DEM_SINK	0x1
-#define DEM_ENABLED	0x2
-
-//#if !__minix_vmd
-#define debug		1	/* Standard Minix lacks debug variable */
-//#endif
-
-/*
- * $PchId: dp8390.h,v 1.10 2005/02/10 17:26:06 philip Exp $
- */
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/netif/dp8390/dp8390_drv.h
===================================================================
--- uspace/srv/net/netif/dp8390/dp8390_drv.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,84 +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 dp8390
- *  @{
- */
-
-/** @file
- *  DP8390 network interface driver interface.
- */
-
-#ifndef __NET_NETIF_DP8390_DRIVER_H__
-#define __NET_NETIF_DP8390_DRIVER_H__
-
-#include "dp8390.h"
-
-/** Initializes and/or starts the network interface.
- *  @param[in,out] dep The network interface structure.
- *  @param[in] mode The state mode.
- *  @returns EOK on success.
- *  @returns EXDEV if the network interface is disabled.
- */
-int do_init(dpeth_t *dep, int mode);
-
-/** Stops the network interface.
- *  @param[in,out] dep The network interface structure.
- */
-void do_stop(dpeth_t *dep);
-
-/** Processes the interrupt.
- *  @param[in,out] dep The network interface structure.
- *  @param[in] isr The interrupt status register.
- */
-void dp_check_ints(dpeth_t *dep, int isr);
-
-/** Probes and initializes the network interface.
- *  @param[in,out] dep The network interface structure.
- *  @returns EOK on success.
- *  @returns EXDEV if the network interface was not recognized.
- */
-int do_probe(dpeth_t * dep);
-
-/** Sends a packet.
- *  @param[in,out] dep The network interface structure.
- *  @param[in] packet The packet t be sent.
- *  @param[in] from_int The value indicating whether the sending is initialized from the interrupt handler.
- *  @returns 
- */
-int do_pwrite(dpeth_t * dep, packet_t packet, int from_int);
-
-/** Prints out network interface information.
- *  @param[in] dep The network interface structure.
- */
-void dp8390_dump(dpeth_t * dep);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/netif/dp8390/dp8390_module.c
===================================================================
--- uspace/srv/net/netif/dp8390/dp8390_module.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,332 +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 dp8390
- *  @{
- */
-
-/** @file
- *  DP8390 network interface implementation.
- */
-
-#include <assert.h>
-#include <async.h>
-#include <ddi.h>
-#include <errno.h>
-#include <malloc.h>
-//#include <stdio.h>
-#include <ipc/ipc.h>
-#include <ipc/services.h>
-
-#include "../../err.h"
-#include "../../messages.h"
-#include "../../modules.h"
-
-#include "../../structures/packet/packet_client.h"
-#include "../../structures/measured_strings.h"
-
-#include "../../include/device.h"
-#include "../../include/nil_interface.h"
-
-#include "../netif.h"
-#include "../netif_module.h"
-
-#include "dp8390.h"
-#include "dp8390_drv.h"
-#include "dp8390_port.h"
-
-/** DP8390 module name.
- */
-#define NAME	"dp8390 network interface"
-
-/** Returns the device from the interrupt call.
- *  @param[in] call The interrupt call.
- */
-#define IRQ_GET_DEVICE(call)			(device_id_t) IPC_GET_METHOD(*call)
-
-/** Returns the interrupt status register from the interrupt call.
- *  @param[in] call The interrupt call.
- */
-#define IPC_GET_ISR(call)				(int) IPC_GET_ARG2(*call)
-
-/** DP8390 kernel interrupt command sequence.
- */
-static irq_cmd_t	dp8390_cmds[] = {
-	{	.cmd = CMD_PIO_READ_8,
-		.addr = NULL,
-		.dstarg = 2
-	},
-	{
-		.cmd = CMD_PREDICATE,
-		.value = 1,
-		.srcarg = 2
-	},
-	{
-		.cmd = CMD_ACCEPT
-	}
-};
-
-/** DP8390 kernel interrupt code.
- */
-static irq_code_t	dp8390_code = {
-	sizeof(dp8390_cmds) / sizeof(irq_cmd_t),
-	dp8390_cmds
-};
-
-/** Network interface module global data.
- */
-netif_globals_t netif_globals;
-
-/** Prints the module name.
- *  @see NAME
- */
-void module_print_name(void);
-
-/** Handles the interrupt messages.
- *  This is the interrupt handler callback function.
- *  @param[in] iid The interrupt message identifier.
- *  @param[in] call The interrupt message.
- */
-void irq_handler(ipc_callid_t iid, ipc_call_t * call);
-
-/** Changes the network interface state.
- *  @param[in,out] device The network interface.
- *  @param[in] state The new state.
- *  @returns The new state.
- */
-int change_state(device_ref device, device_state_t state);
-
-int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	return ENOTSUP;
-}
-
-int netif_get_device_stats(device_id_t device_id, device_stats_ref stats){
-	ERROR_DECLARE;
-
-	device_ref device;
-	eth_stat_t * de_stat;
-
-	if(! stats){
-		return EBADMEM;
-	}
-	ERROR_PROPAGATE(find_device(device_id, &device));
-	de_stat = &((dpeth_t *) device->specific)->de_stat;
-	null_device_stats(stats);
-	stats->receive_errors = de_stat->ets_recvErr;
-	stats->send_errors = de_stat->ets_sendErr;
-	stats->receive_crc_errors = de_stat->ets_CRCerr;
-	stats->receive_frame_errors = de_stat->ets_frameAll;
-	stats->receive_missed_errors = de_stat->ets_missedP;
-	stats->receive_packets = de_stat->ets_packetR;
-	stats->send_packets = de_stat->ets_packetT;
-	stats->collisions = de_stat->ets_collision;
-	stats->send_aborted_errors = de_stat->ets_transAb;
-	stats->send_carrier_errors = de_stat->ets_carrSense;
-	stats->send_heartbeat_errors = de_stat->ets_CDheartbeat;
-	stats->send_window_errors = de_stat->ets_OWC;
-	return EOK;
-}
-
-void module_print_name(void){
-	printf("%s", NAME);
-}
-
-int netif_get_addr_message(device_id_t device_id, measured_string_ref address){
-	ERROR_DECLARE;
-
-	device_ref device;
-
-	if(! address){
-		return EBADMEM;
-	}
-	ERROR_PROPAGATE(find_device(device_id, &device));
-	address->value = (char *) (&((dpeth_t *) device->specific)->de_address);
-	address->length = CONVERT_SIZE(ether_addr_t, char, 1);
-	return EOK;
-}
-
-void irq_handler(ipc_callid_t iid, ipc_call_t * call)
-{
-	device_ref device;
-	dpeth_t * dep;
-	packet_t received;
-	device_id_t device_id;
-	int phone;
-
-	device_id = IRQ_GET_DEVICE(call);
-	fibril_rwlock_write_lock(&netif_globals.lock);
-	if(find_device(device_id, &device) != EOK){
-		fibril_rwlock_write_unlock(&netif_globals.lock);
-		return;
-	}
-	dep = (dpeth_t *) device->specific;
-	if (dep->de_mode != DEM_ENABLED){
-		fibril_rwlock_write_unlock(&netif_globals.lock);
-		return;
-	}
-	assert(dep->de_flags &DEF_ENABLED);
-	dep->de_int_pending = 0;
-//	remove debug print:
-#ifdef CONFIG_DEBUG
-	printf("I%d: 0x%x\n", device_id, IPC_GET_ISR(call));
-#endif
-	dp_check_ints(dep, IPC_GET_ISR(call));
-	if(dep->received_queue){
-		received = dep->received_queue;
-		phone = device->nil_phone;
-		dep->received_queue = NULL;
-		dep->received_count = 0;
-		fibril_rwlock_write_unlock(&netif_globals.lock);
-//	remove debug dump:
-#ifdef CONFIG_DEBUG
-	uint8_t * data;
-	data = packet_get_data(received);
-	printf("Receiving packet:\n\tid\t= %d\n\tlength\t= %d\n\tdata\t= %.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX\n\t\t%.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX\n", packet_get_id(received), packet_get_data_length(received), data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15], data[16], data[17], data[18], data[19], data[20], data[21], data[22], data[23], data[24], data[25], data[26], data[27], data[28], data[29], data[30], data[31], data[32], data[33], data[34], data[35], data[36], data[37], data[38], data[39], data[40], data[41], data[42], data[43], data[44], data[45], data[46], data[47], data[48], data[49], data[50], data[51], data[52], data[53], data[54], data[55], data[56], data[57], data[58], data[59]);
-#endif
-		nil_received_msg(phone, device_id, received, NULL);
-	}else{
-		fibril_rwlock_write_unlock(&netif_globals.lock);
-	}
-	ipc_answer_0(iid, EOK);
-}
-
-int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){
-	ERROR_DECLARE;
-
-	device_ref device;
-	dpeth_t * dep;
-
-	device = (device_ref) malloc(sizeof(device_t));
-	if(! device){
-		return ENOMEM;
-	}
-	dep = (dpeth_t *) malloc(sizeof(dpeth_t));
-	if(! dep){
-		free(device);
-		return ENOMEM;
-	}
-	bzero(device, sizeof(device_t));
-	bzero(dep, sizeof(dpeth_t));
-	device->device_id = device_id;
-	device->nil_phone = -1;
-	device->specific = (void *) dep;
-	device->state = NETIF_STOPPED;
-	dep->de_irq = irq;
-	dep->de_mode = DEM_DISABLED;
-	//TODO address?
-	if(ERROR_OCCURRED(pio_enable((void *) io, DP8390_IO_SIZE, (void **) &dep->de_base_port))
-		|| ERROR_OCCURRED(do_probe(dep))){
-		free(dep);
-		free(device);
-		return ERROR_CODE;
-	}
-	if(ERROR_OCCURRED(device_map_add(&netif_globals.device_map, device->device_id, device))){
-		free(dep);
-		free(device);
-		return ERROR_CODE;
-	}
-	return EOK;
-}
-
-int netif_send_message(device_id_t device_id, packet_t packet, services_t sender){
-	ERROR_DECLARE;
-
-	device_ref device;
-	dpeth_t * dep;
-	packet_t next;
-
-	ERROR_PROPAGATE(find_device(device_id, &device));
-	if(device->state != NETIF_ACTIVE){
-		netif_pq_release(packet_get_id(packet));
-		return EFORWARD;
-	}
-	dep = (dpeth_t *) device->specific;
-	// process packet queue
-	do{
-		next = pq_detach(packet);
-//		remove debug dump:
-#ifdef CONFIG_DEBUG
-		uint8_t * data;
-		data = packet_get_data(packet);
-		printf("Sending packet:\n\tid\t= %d\n\tlength\t= %d\n\tdata\t= %.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX\n\t\t%.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX:%.2hhX %.2hhX %.2hhX %.2hhX\n", packet_get_id(packet), packet_get_data_length(packet), data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13], data[14], data[15], data[16], data[17], data[18], data[19], data[20], data[21], data[22], data[23], data[24], data[25], data[26], data[27], data[28], data[29], data[30], data[31], data[32], data[33], data[34], data[35], data[36], data[37], data[38], data[39], data[40], data[41], data[42], data[43], data[44], data[45], data[46], data[47], data[48], data[49], data[50], data[51], data[52], data[53], data[54], data[55], data[56], data[57], data[58], data[59]);
-#endif
-		if(do_pwrite(dep, packet, FALSE) != EBUSY){
-			netif_pq_release(packet_get_id(packet));
-		}
-		packet = next;
-	}while(packet);
-	return EOK;
-}
-
-int netif_start_message(device_ref device){
-	ERROR_DECLARE;
-
-	dpeth_t * dep;
-
-	if(device->state != NETIF_ACTIVE){
-		dep = (dpeth_t *) device->specific;
-		dp8390_cmds[0].addr = (void *) (uintptr_t) (dep->de_dp8390_port + DP_ISR);
-		dp8390_cmds[2].addr = dp8390_cmds[0].addr;
-		ERROR_PROPAGATE(ipc_register_irq(dep->de_irq, device->device_id, device->device_id, &dp8390_code));
-		if(ERROR_OCCURRED(do_init(dep, DL_BROAD_REQ))){
-			ipc_unregister_irq(dep->de_irq, device->device_id);
-			return ERROR_CODE;
-		}
-		return change_state(device, NETIF_ACTIVE);
-	}
-	return EOK;
-}
-
-int netif_stop_message(device_ref device){
-	dpeth_t * dep;
-
-	if(device->state != NETIF_STOPPED){
-		dep = (dpeth_t *) device->specific;
-		do_stop(dep);
-		ipc_unregister_irq(dep->de_irq, device->device_id);
-		return change_state(device, NETIF_STOPPED);
-	}
-	return EOK;
-}
-
-int change_state(device_ref device, device_state_t state){
-	device->state = state;
-	printf("State changed to %s\n", (state == NETIF_ACTIVE) ? "ACTIVE" : "STOPPED");
-	return state;
-}
-
-int netif_initialize(void){
-	ipcarg_t phonehash;
-
-	async_set_interrupt_received(irq_handler);
-
-	return REGISTER_ME(SERVICE_DP8390, &phonehash);
-}
-
-/** @}
- */
Index: pace/srv/net/netif/dp8390/dp8390_port.h
===================================================================
--- uspace/srv/net/netif/dp8390/dp8390_port.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,274 +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 dp8390
- *  @{
- */
-
-/** @file
- *  DP8390 network interface types and structures ports.
- */
-
-#ifndef __NET_NETIF_DP8390_PORT_H__
-#define __NET_NETIF_DP8390_PORT_H__
-
-#include <errno.h>
-#include <mem.h>
-#include <stdio.h>
-#include <libarch/ddi.h>
-#include <sys/types.h>
-
-/** Macro for difining functions.
- *  @param[in] function The function type and name definition.
- *  @param[in] params The function parameters definition.
- */
-#define _PROTOTYPE(function, params) function params
-
-/** Success error code.
- */
-#define OK	EOK
-
-/** Type definition of the unsigned byte.
- */
-typedef uint8_t u8_t;
-
-/** Type definition of the unsigned short.
- */
-typedef uint16_t u16_t;
-
-/** Compares two memory blocks.
- *  @param[in] first The first memory block.
- *  @param[in] second The second memory block.
- *  @param[in] size The blocks size in bytes.
- *  @returns 0 if equeal.
- *  @returns -1 if the first is greater than the second.
- *  @returns 1 if the second is greater than the first.
- */
-#define memcmp(first, second, size)	bcmp((char *) (first), (char *) (second), (size))
-
-/** Reads 1 byte.
- *  @param[in] port The address to be read.
- *  @returns The read value.
- */
-#define inb(port)	pio_read_8((ioport8_t *) (port))
-
-/** Reads 1 word (2 bytes).
- *  @param[in] port The address to be read.
- *  @returns The read value.
- */
-#define inw(port)	pio_read_16((ioport16_t *) (port))
-
-/** Writes 1 byte.
- *  @param[in] port The address to be written.
- *  @param[in] value The value to be written.
- */
-#define outb(port, value)	pio_write_8((ioport8_t *) (port), (value))
-
-/** Writes 1 word (2 bytes).
- *  @param[in] port The address to be written.
- *  @param[in] value The value to be written.
- */
-#define outw(port, value)	pio_write_16((ioport16_t *) (port), (value))
-
-/** Prints out the driver critical error.
- *  Does not call the system panic().
- */
-#define panic(...)	printf("%s%s%d", __VA_ARGS__)
-
-/** Copies a memory block.
- *  @param proc The source process. Ignored parameter.
- *  @param src_s Ignored parameter.
- *  @param[in] src The source address.
- *  @param me The current proces. Ignored parameter.
- *  @param dst_s Ignored parameter.
- *  @param[in] dst The destination address.
- *  @param[in] bytes The block size in bytes.
- *  @returns EOK.
- */
-#define sys_vircopy(proc, src_s, src, me, dst_s, dst, bytes)	({memcpy((void *)(dst), (void *)(src), (bytes)); EOK;})
-
-/** Reads a memory block byte by byte.
- *  @param[in] port The address to be written.
- *  @param proc The source process. Ignored parameter.
- *  @param[in] dst The destination address.
- *  @param[in] bytes The block size in bytes.
- */
-#define do_vir_insb(port, proc, dst, bytes)	insb((port), (void *)(dst), (bytes))
-
-/** Reads a memory block word by word (2 bytes).
- *  @param[in] port The address to be written.
- *  @param proc The source process. Ignored parameter.
- *  @param[in] dst The destination address.
- *  @param[in] bytes The block size in bytes.
- */
-#define do_vir_insw(port, proc, dst, bytes)	insw((port), (void *)(dst), (bytes))
-
-/** Writes a memory block byte by byte.
- *  @param[in] port The address to be written.
- *  @param proc The source process. Ignored parameter.
- *  @param[in] src The source address.
- *  @param[in] bytes The block size in bytes.
- */
-#define do_vir_outsb(port, proc, src, bytes)	outsb((port), (void *)(src), (bytes))
-
-/** Writes a memory block word by word (2 bytes).
- *  @param[in] port The address to be written.
- *  @param proc The source process. Ignored parameter.
- *  @param[in] src The source address.
- *  @param[in] bytes The block size in bytes.
- */
-#define do_vir_outsw(port, proc, src, bytes)	outsw((port), (void *)(src), (bytes))
-
-/* com.h */
-/* Bits in 'DL_MODE' field of DL requests. */
-#  define DL_NOMODE		0x0
-#  define DL_PROMISC_REQ	0x2
-#  define DL_MULTI_REQ		0x4
-#  define DL_BROAD_REQ		0x8
-
-/* const.h */
-/** True value.
- */
-#define TRUE               1	/* used for turning integers into Booleans */
-
-/** False value.
- */
-#define FALSE              0	/* used for turning integers into Booleans */
-
-/** No number value.
- */
-#define NO_NUM        0x8000	/* used as numerical argument to panic() */
-
-/* devio.h */
-//typedef u16_t port_t;
-/** Type definition of a port.
- */
-typedef long port_t;
-
-/* dl_eth.h */
-/** Ethernet statistics.
- */
-typedef struct eth_stat
-{
-	/** Number of receive errors.
-	 */
-	unsigned long ets_recvErr;
-	/** Number of send error.
-	 */
-	unsigned long ets_sendErr;
-	/** Number of buffer overwrite warnings.
-	 */
-	unsigned long ets_OVW;
-	/** Number of crc errors of read.
-	 */
-	unsigned long ets_CRCerr;
-	/** Number of frames not alligned (number of bits % 8 != 0).
-	 */
-	unsigned long ets_frameAll;
-	/** Number of packets missed due to slow processing.
-	 */
-	unsigned long ets_missedP;
-	/** Number of packets received.
-	 */
-	unsigned long ets_packetR;
-	/** Number of packets transmitted.
-	 */
-	unsigned long ets_packetT;
-	/** Number of transmission defered (Tx was busy).
-	 */
-	unsigned long ets_transDef;
-	/** Number of collissions.
-	 */
-	unsigned long ets_collision;
-	/** Number of Tx aborted due to excess collisions.
-	 */
-	unsigned long ets_transAb;
-	/** Number of carrier sense lost.
-	 */
-	unsigned long ets_carrSense;
-	/** Number of FIFO underruns (processor too busy).
-	 */
-	unsigned long ets_fifoUnder;
-	/** Number of FIFO overruns (processor too busy).
-	 */
-	unsigned long ets_fifoOver;
-	/** Number of times unable to transmit collision sig.
-	 */
-	unsigned long ets_CDheartbeat;
-	/** Number of times out of window collision.
-	 */
-	unsigned long ets_OWC;
-} eth_stat_t;
-
-/* errno.h */
-/** Generic error.
- */
-#define EGENERIC     EINVAL
-
-/* ether.h */
-/** Minimum Ethernet packet size in bytes.
- */
-#define ETH_MIN_PACK_SIZE		  60
-
-/** Maximum Ethernet packet size in bytes.
- */
-#define ETH_MAX_PACK_SIZE_TAGGED	1518
-
-/** Ethernet address type definition.
- */
-typedef struct ether_addr
-{
-	/** Address data.
-	 */
-	u8_t ea_addr[6];
-} ether_addr_t;
-
-/* type.h */
-/** Type definition of the physical addresses and lengths in bytes.
- */
-typedef unsigned long phys_bytes;
-
-/** Type definition of the virtual addresses and lengths in bytes.
- */
-typedef unsigned long vir_bytes;
-
-/** Type definition of the input/output vector.
- */
-typedef struct {
-	/** Address of an I/O buffer.
-	 */
-	vir_bytes iov_addr;
-	/** Sizeof an I/O buffer.
-	 */
-	vir_bytes iov_size;
-} iovec_t;
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/netif/dp8390/local.h
===================================================================
--- uspace/srv/net/netif/dp8390/local.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,99 +1,0 @@
-/*
- * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system 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.
- * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
- * * Any deviations from these conditions require written permission from the copyright holder in advance
- *
- *
- * Disclaimer
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``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 COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS 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.
- *
- * Changes:
- *  2009 ported to HelenOS, Lukas Mejdrech
- */
-
-/** @addtogroup dp8390
- *  @{
- */
-
-/** @file
- *  Network interface probe functions.
- */
-
-#ifndef __NET_NETIF_DP8390_CONFIG_H__
-#define __NET_NETIF_DP8390_CONFIG_H__
-
-#include "dp8390_port.h"
-
-/*
-local.h
-*/
-
-/** WDETH switch.
- */
-#define ENABLE_WDETH 0
-
-/** NE2000 switch.
- */
-#define ENABLE_NE2000 1
-
-/** 3C503 switch.
- */
-#define ENABLE_3C503 0
-
-/** PCI support switch.
- */
-#define ENABLE_PCI 0
-
-struct dpeth;
-
-/* 3c503.c */
-/* * Probes a 3C503 network interface.
- *  @param[in] dep The network interface structure.
- *  @returns 1 if the NE2000 network interface is present.
- *  @returns 0 otherwise.
- */
-//_PROTOTYPE(int el2_probe, (struct dpeth*dep)				);
-
-/* ne2000.c */
-/** Probes a NE2000 or NE1000 network interface.
- *  @param[in] dep The network interface structure.
- *  @returns 1 if the NE2000 network interface is present.
- *  @returns 0 otherwise.
- */
-int ne_probe(struct dpeth * dep);
-//_PROTOTYPE(int ne_probe, (struct dpeth *dep)				);
-//_PROTOTYPE(void ne_init, (struct dpeth *dep)				);
-
-/* rtl8029.c */
-/* * Probes a RTL8029 network interface.
- *  @param[in] dep The network interface structure.
- *  @returns 1 if the NE2000 network interface is present.
- *  @returns 0 otherwise.
- */
-//_PROTOTYPE(int rtl_probe, (struct dpeth *dep)				);
-
-/* wdeth.c */
-/* * Probes a WDETH network interface.
- *  @param[in] dep The network interface structure.
- *  @returns 1 if the NE2000 network interface is present.
- *  @returns 0 otherwise.
- */
-//_PROTOTYPE(int wdeth_probe, (struct dpeth*dep)				);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/netif/dp8390/ne2000.c
===================================================================
--- uspace/srv/net/netif/dp8390/ne2000.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,416 +1,0 @@
-/*
- * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system 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.
- * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
- * * Any deviations from these conditions require written permission from the copyright holder in advance
- *
- *
- * Disclaimer
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``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 COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS 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.
- *
- * Changes:
- *  2009 ported to HelenOS, Lukas Mejdrech
- */
-
-/** @addtogroup ne2k
- *  @{
- */
-
-/** @file
- *  NE1000 and NE2000 network interface initialization and probe functions implementation.
- */
-
-#include <stdio.h>
-#include <unistd.h>
-
-#include "dp8390_port.h"
-
-/*
-ne2000.c
-
-Driver for the ne2000 ethernet cards. This file contains only the ne2000
-specific code, the rest is in dp8390.c
-
-Created:	March 15, 1994 by Philip Homburg <philip@f-mnx.phicoh.com>
-*/
-
-//#include "../drivers.h"
-
-//#include <net/gen/ether.h>
-//#include <net/gen/eth_io.h>
-//#if __minix_vmd
-//#include "config.h"
-//#endif
-
-#include "local.h"
-#include "dp8390.h"
-#include "ne2000.h"
-
-#if ENABLE_NE2000
-
-/** Number of bytes to transfer.
- */
-#define N 100
-
-//#define MILLIS_TO_TICKS(m)  (((m)*HZ/1000)+1)
-
-/** Sleeps for the defined millicesonds.
- *  @param[in] millis The number of milliseconds to sleep.
- */
-#define milli_delay(millis)	usleep((millis) * 1000)
-
-/** Type definition of the testing function.
- */
-_PROTOTYPE(typedef int (*testf_t), (dpeth_t *dep, int pos, u8_t *pat)	);
-
-/** First data pattern.
- */
-u8_t	pat0[]= {0x00, 0x00, 0x00, 0x00};
-
-/** Second data pattern.
- */
-u8_t	pat1[]= {0xFF, 0xFF, 0xFF, 0xFF};
-
-/** Third data pattern.
- */
-u8_t	pat2[]= {0xA5, 0x5A, 0x69, 0x96};
-
-/** Fourth data pattern.
- */
-u8_t	pat3[]= {0x96, 0x69, 0x5A, 0xA5};
-
-/** Tests 8 bit NE2000 network interface.
- *  @param[in,out] dep The network interface structure.
- *  @param[in] pos The starting position.
- *  @param[in] pat The data pattern to be written.
- *  @returns True on success.
- *  @returns FALSE otherwise.
- */
-static int test_8(dpeth_t *dep, int pos, u8_t *pat);
-
-/** Tests 16 bit NE2000 network interface.
- *  @param[in,out] dep The network interface structure.
- *  @param[in] pos The starting position.
- *  @param[in] pat The data pattern to be written.
- *  @returns True on success.
- *  @returns FALSE otherwise.
- */
-static int test_16(dpeth_t *dep, int pos, u8_t *pat);
-
-/** Stops the NE2000 network interface.
- *  @param[in,out] dep The network interface structure.
- */
-static void ne_stop(dpeth_t *dep);
-//_PROTOTYPE(static void milli_delay, (unsigned long millis)		);
-
-/** Initializes the NE2000 network interface.
- *  @param[in,out] dep The network interface structure.
- */
-void ne_init(struct dpeth *dep);
-
-/*===========================================================================*
- *				ne_probe				     *
- *===========================================================================*/
-int ne_probe(dep)
-dpeth_t *dep;
-{
-	int byte;
-	int i;
-	int loc1, loc2;
-	testf_t f;
-
-	dep->de_dp8390_port= dep->de_base_port + NE_DP8390;
-
-	/* We probe for an ne1000 or an ne2000 by testing whether the
-	 * on board is reachable through the dp8390. Note that the
-	 * ne1000 is an 8bit card and has a memory region distict from
-	 * the 16bit ne2000
-	 */
-
-	for (dep->de_16bit= 0; dep->de_16bit < 2; dep->de_16bit++)
-	{
-		/* Reset the ethernet card */
-		byte= inb_ne(dep, NE_RESET);
-		milli_delay(2);
-		outb_ne(dep, NE_RESET, byte);
-		milli_delay(2);
-
-		/* Reset the dp8390 */
-		outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
-		for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) &ISR_RST) == 0); i++)
-			; /* Do nothing */
-
-		/* Check if the dp8390 is really there */
-		if ((inb_reg0(dep, DP_CR) &(CR_STP|CR_DM_ABORT)) !=
-			(CR_STP|CR_DM_ABORT))
-		{
-			return 0;
-		}
-
-		/* Disable the receiver and init TCR and DCR. */
-		outb_reg0(dep, DP_RCR, RCR_MON);
-		outb_reg0(dep, DP_TCR, TCR_NORMAL);
-		if (dep->de_16bit)
-		{
-			outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES |
-				DCR_BMS);
-		}
-		else
-		{
-			outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES |
-				DCR_BMS);
-		}
-
-		if (dep->de_16bit)
-		{
-			loc1= NE2000_START;
-			loc2= NE2000_START + NE2000_SIZE - 4;
-			f= test_16;
-		}
-		else
-		{
-			loc1= NE1000_START;
-			loc2= NE1000_START + NE1000_SIZE - 4;
-			f= test_8;
-		}
-		if (f(dep, loc1, pat0) && f(dep, loc1, pat1) && 
-			f(dep, loc1, pat2) && f(dep, loc1, pat3) && 
-			f(dep, loc2, pat0) && f(dep, loc2, pat1) && 
-			f(dep, loc2, pat2) && f(dep, loc2, pat3))
-		{
-			/* We don't need a memory segment */
-			dep->de_linmem= 0;
-			if (!dep->de_pci)
-				dep->de_initf= ne_init;
-			dep->de_stopf= ne_stop;
-			dep->de_prog_IO= 1;
-			return 1;
-		}
-	}
-	return 0;
-}
-
-/*===========================================================================*
- *				ne_init					     *
- *===========================================================================*/
-void ne_init(dep)
-dpeth_t *dep;
-{
-	int i;
-	int word, sendq_nr;
-
-	/* Setup a transfer to get the ethernet address. */
-	if (dep->de_16bit)
-		outb_reg0(dep, DP_RBCR0, 6*2);
-	else
-		outb_reg0(dep, DP_RBCR0, 6);
-	outb_reg0(dep, DP_RBCR1, 0);
-	outb_reg0(dep, DP_RSAR0, 0);
-	outb_reg0(dep, DP_RSAR1, 0);
-	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
-
-	for (i= 0; i<6; i++)
-	{
-		if (dep->de_16bit)
-		{
-			word= inw_ne(dep, NE_DATA);
-			dep->de_address.ea_addr[i]= word;
-		}
-		else
-		{
-			dep->de_address.ea_addr[i] = inb_ne(dep, NE_DATA);
-		}
-	}
-	dep->de_data_port= dep->de_base_port + NE_DATA;
-	if (dep->de_16bit)
-	{
-		dep->de_ramsize= NE2000_SIZE;
-		dep->de_offset_page= NE2000_START / DP_PAGESIZE;
-	}
-	else
-	{
-		dep->de_ramsize= NE1000_SIZE;
-		dep->de_offset_page= NE1000_START / DP_PAGESIZE;
-	}
-
-	/* Allocate one send buffer (1.5KB) per 8KB of on board memory. */
-	sendq_nr= dep->de_ramsize / 0x2000;
-	if (sendq_nr < 1)
-		sendq_nr= 1;
-	else if (sendq_nr > SENDQ_NR)
-		sendq_nr= SENDQ_NR;
-	dep->de_sendq_nr= sendq_nr;
-	for (i= 0; i<sendq_nr; i++)
-	{
-		dep->de_sendq[i].sq_sendpage= dep->de_offset_page +
-			i*SENDQ_PAGES;	
-	}
-
-	dep->de_startpage= dep->de_offset_page + i*SENDQ_PAGES;
-	dep->de_stoppage= dep->de_offset_page + dep->de_ramsize / DP_PAGESIZE;
-
-	/* Can't override the default IRQ. */
-	dep->de_irq &= ~DEI_DEFAULT;
-
-	if (!debug)
-	{
-		printf("%s: NE%d000 at %X:%d\n",
-			dep->de_name, dep->de_16bit ? 2 : 1,
-			dep->de_base_port, dep->de_irq);
-	}
-	else
-	{
-		printf("%s: Novell NE%d000 ethernet card at I/O address "
-			"0x%X, memory size 0x%X, irq %d\n",
-			dep->de_name, dep->de_16bit ? 2 : 1,
-			dep->de_base_port, dep->de_ramsize, dep->de_irq);
-	}
-}
-
-/*===========================================================================*
- *				test_8					     *
- *===========================================================================*/
-static int test_8(dep, pos, pat)
-dpeth_t *dep;
-int pos;
-u8_t *pat;
-{
-	u8_t buf[4];
-	int i;
-	int r;
-
-	outb_reg0(dep, DP_ISR, 0xFF);
-
-	/* Setup a transfer to put the pattern. */
-	outb_reg0(dep, DP_RBCR0, 4);
-	outb_reg0(dep, DP_RBCR1, 0);
-	outb_reg0(dep, DP_RSAR0, pos &0xFF);
-	outb_reg0(dep, DP_RSAR1, pos >> 8);
-	outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
-
-	for (i= 0; i<4; i++)
-		outb_ne(dep, NE_DATA, pat[i]);
-
-	for (i= 0; i<N; i++)
-	{
-		if (inb_reg0(dep, DP_ISR) &ISR_RDC)
-			break;
-	}
-	if (i == N)
-	{
-		if (debug)
-		{
-			printf("%s: NE1000 remote DMA test failed\n",
-				dep->de_name);
-		}
-		return 0;
-	}
-
-	outb_reg0(dep, DP_RBCR0, 4);
-	outb_reg0(dep, DP_RBCR1, 0);
-	outb_reg0(dep, DP_RSAR0, pos &0xFF);
-	outb_reg0(dep, DP_RSAR1, pos >> 8);
-	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
-
-	for (i= 0; i<4; i++)
-		buf[i]= inb_ne(dep, NE_DATA);
-
-	r= (memcmp(buf, pat, 4) == 0);
-	return r;
-}
-
-/*===========================================================================*
- *				test_16					     *
- *===========================================================================*/
-static int test_16(dep, pos, pat)
-dpeth_t *dep;
-int pos;
-u8_t *pat;
-{
-	u8_t buf[4];
-	int i;
-	int r;
-
-	outb_reg0(dep, DP_ISR, 0xFF);
-
-	/* Setup a transfer to put the pattern. */
-	outb_reg0(dep, DP_RBCR0, 4);
-	outb_reg0(dep, DP_RBCR1, 0);
-	outb_reg0(dep, DP_RSAR0, pos &0xFF);
-	outb_reg0(dep, DP_RSAR1, pos >> 8);
-	outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
-
-	for (i= 0; i<4; i += 2)
-	{
-		outw_ne(dep, NE_DATA, *(u16_t *)(pat+i));
-	}
-
-	for (i= 0; i<N; i++)
-	{
-		if (inb_reg0(dep, DP_ISR) &ISR_RDC)
-			break;
-	}
-	if (i == N)
-	{
-		if (debug)
-		{
-			printf("%s: NE2000 remote DMA test failed\n",
-				dep->de_name);
-		}
-		return 0;
-	}
-
-	outb_reg0(dep, DP_RBCR0, 4);
-	outb_reg0(dep, DP_RBCR1, 0);
-	outb_reg0(dep, DP_RSAR0, pos &0xFF);
-	outb_reg0(dep, DP_RSAR1, pos >> 8);
-	outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
-
-	for (i= 0; i<4; i += 2)
-	{
-		*(u16_t *)(buf+i)= inw_ne(dep, NE_DATA);
-	}
-
-	r= (memcmp(buf, pat, 4) == 0);
-	return r;
-}
-
-/*===========================================================================*
- *				ne_stop					     *
- *===========================================================================*/
-static void ne_stop(dep)
-dpeth_t *dep;
-{
-	int byte;
-
-	/* Reset the ethernet card */
-	byte= inb_ne(dep, NE_RESET);
-	milli_delay(2);
-	outb_ne(dep, NE_RESET, byte);
-}
-/*
-static void milli_delay(unsigned long millis)
-{
-	tickdelay(MILLIS_TO_TICKS(millis));
-}
-*/
-#endif /* ENABLE_NE2000 */
-
-/*
- * $PchId: ne2000.c,v 1.10 2004/08/03 12:03:00 philip Exp $
- */
-
-/** @}
- */
Index: pace/srv/net/netif/dp8390/ne2000.h
===================================================================
--- uspace/srv/net/netif/dp8390/ne2000.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,111 +1,0 @@
-/*
- * Copyright (c) 1987,1997, 2006, Vrije Universiteit, Amsterdam, The Netherlands All rights reserved. Redistribution and use of the MINIX 3 operating system 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.
- * * Neither the name of the Vrije Universiteit nor the names of the software authors or contributors may be used to endorse or promote products derived from this software without specific prior written permission.
- * * Any deviations from these conditions require written permission from the copyright holder in advance
- *
- *
- * Disclaimer
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND CONTRIBUTORS ``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 COPYRIGHT HOLDER OR ANY AUTHORS OR CONTRIBUTORS 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.
- *
- * Changes:
- *  2009 ported to HelenOS, Lukas Mejdrech
- */
-
-/*
-ne2000.h
-
-Created:	March 15, 1994 by Philip Homburg <philip@f-mnx.phicoh.com>
-*/
-
-/** @addtogroup ne2k
- *  @{
- */
-
-/** @file
- *  NE1000 and NE2000 network interface definitions.
- */
-
-#ifndef __NET_NETIF_NE2000_H__
-#define __NET_NETIF_NE2000_H__
-
-#include <libarch/ddi.h>
-
-#include "dp8390_port.h"
-
-/** DP8390 register offset.
- */
-#define NE_DP8390	0x00
-
-/** Data register.
- */
-#define NE_DATA		0x10
-
-/** Reset register.
- */
-#define NE_RESET	0x1F
-
-/** NE1000 data start.
- */
-#define NE1000_START	0x2000
-
-/** NE1000 data size.
- */
-#define NE1000_SIZE	0x2000
-
-/** NE2000 data start.
- */
-#define NE2000_START	0x4000
-
-/** NE2000 data size.
- */
-#define NE2000_SIZE	0x4000
-
-/** Reads 1 byte register.
- *  @param[in] dep The network interface structure.
- *  @param[in] reg The register offset.
- *  @returns The read value.
- */
-#define inb_ne(dep, reg)	(inb(dep->de_base_port+reg))
-
-/** Writes 1 byte register.
- *  @param[in] dep The network interface structure.
- *  @param[in] reg The register offset.
- *  @param[in] data The value to be written.
- */
-#define outb_ne(dep, reg, data)	(outb(dep->de_base_port+reg, data))
-
-/** Reads 1 word (2 bytes) register.
- *  @param[in] dep The network interface structure.
- *  @param[in] reg The register offset.
- *  @returns The read value.
- */
-#define inw_ne(dep, reg)	(inw(dep->de_base_port+reg))
-
-/** Writes 1 word (2 bytes) register.
- *  @param[in] dep The network interface structure.
- *  @param[in] reg The register offset.
- *  @param[in] data The value to be written.
- */
-#define outw_ne(dep, reg, data)	(outw(dep->de_base_port+reg, data))
-
-#endif /* __NET_NETIF_NE2000_H__ */
-
-/*
- * $PchId: ne2000.h,v 1.4 2004/08/03 12:03:20 philip Exp $
- */
-
-/** @}
- */
Index: uspace/srv/net/netif/lo/Makefile
===================================================================
--- uspace/srv/net/netif/lo/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/netif/lo/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,38 +28,23 @@
 #
 
-NET_BASE = ../..
 USPACE_PREFIX = ../../../..
 ROOT_PATH = $(USPACE_PREFIX)/..
+LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBSOCKET_PREFIX)/include
 
 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
 CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
 
-BINARY = lo
-
 -include $(COMMON_MAKEFILE)
 -include $(CONFIG_MAKEFILE)
 
-SOURCES = \
-	lo.c \
-	$(NET_BASE)/module.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/net/net_remote.c \
-	$(NET_BASE)/netif/netif.c \
-	$(NET_BASE)/structures/measured_strings.c \
-	$(NET_BASE)/structures/packet/packet.c \
-	$(NET_BASE)/structures/packet/packet_client.c \
-	$(NET_BASE)/structures/packet/packet_remote.c
-
-ifeq ($(CONFIG_NETWORKING),module)
-	SOURCES += \
-		$(NET_BASE)/nil/nildummy/nildummy.c \
-		$(NET_BASE)/netif/netif_nil_bundle.c
+ifeq ($(CONFIG_NETIF_NIL_BUNDLE),y)
+	LIBS += $(USPACE_PREFIX)/srv/net/nil/nildummy/libnildummy.a
 endif
 
-ifeq ($(CONFIG_NETWORKING),modular)
-	SOURCES += \
-		$(NET_BASE)/nil/nil_remote.c \
-		$(NET_BASE)/netif/netif_standalone.c
-endif
+BINARY = lo
+
+SOURCES = \
+	lo.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/netif/lo/lo.c
===================================================================
--- uspace/srv/net/netif/lo/lo.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/netif/lo/lo.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -43,18 +43,14 @@
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../messages.h"
-#include "../../modules.h"
-
-#include "../../structures/measured_strings.h"
-#include "../../structures/packet/packet_client.h"
-
-#include "../../include/device.h"
-#include "../../include/nil_interface.h"
-
-#include "../../nil/nil_messages.h"
-
-#include "../netif.h"
-#include "../netif_module.h"
+#include <net_err.h>
+#include <net_messages.h>
+#include <net_modules.h>
+#include <adt/measured_strings.h>
+#include <packet/packet_client.h>
+#include <net_device.h>
+#include <nil_interface.h>
+#include <nil_messages.h>
+#include <netif_interface.h>
+#include <netif_local.h>
 
 /** Default hardware address.
@@ -68,5 +64,5 @@
 /** Loopback module name.
  */
-#define NAME	"lo - loopback interface"
+#define NAME  "lo"
 
 /** Network interface global data.
@@ -80,5 +76,5 @@
  *  @returns EOK otherwise.
  */
-int change_state_message(device_ref device, device_state_t state);
+int change_state_message(netif_device_t * device, device_state_t state);
 
 /** Creates and returns the loopback network interface structure.
@@ -89,10 +85,5 @@
  *  @returns ENOMEM if there is not enough memory left.
  */
-int create(device_id_t device_id, device_ref * device);
-
-/** Prints the module name.
- *  @see NAME
- */
-void module_print_name(void);
+int create(device_id_t device_id, netif_device_t * * device);
 
 int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
@@ -112,5 +103,5 @@
 	ERROR_DECLARE;
 
-	device_ref device;
+	netif_device_t * device;
 
 	if(! stats){
@@ -122,20 +113,25 @@
 }
 
-int change_state_message(device_ref device, device_state_t state){
-	if(device->state != state){
+int change_state_message(netif_device_t * device, device_state_t state)
+{
+	if (device->state != state) {
 		device->state = state;
-		printf("State changed to %s\n", (state == NETIF_ACTIVE) ? "ACTIVE" : "STOPPED");
+		
+		printf("%s: State changed to %s\n", NAME,
+		    (state == NETIF_ACTIVE) ? "active" : "stopped");
+		
 		return state;
 	}
-	return EOK;
-}
-
-int create(device_id_t device_id, device_ref * device){
+	
+	return EOK;
+}
+
+int create(device_id_t device_id, netif_device_t * * device){
 	int index;
 
-	if(device_map_count(&netif_globals.device_map) > 0){
+	if(netif_device_map_count(&netif_globals.device_map) > 0){
 		return EXDEV;
 	}else{
-		*device = (device_ref) malloc(sizeof(device_t));
+		*device = (netif_device_t *) malloc(sizeof(netif_device_t));
 		if(!(*device)){
 			return ENOMEM;
@@ -150,5 +146,5 @@
 		(** device).nil_phone = -1;
 		(** device).state = NETIF_STOPPED;
-		index = device_map_add(&netif_globals.device_map, (** device).device_id, * device);
+		index = netif_device_map_add(&netif_globals.device_map, (** device).device_id, * device);
 		if(index < 0){
 			free(*device);
@@ -167,17 +163,13 @@
 }
 
-void module_print_name(void){
-	printf("%s", NAME);
-}
-
 int netif_probe_message(device_id_t device_id, int irq, uintptr_t io){
 	ERROR_DECLARE;
 
-	device_ref device;
+	netif_device_t * device;
 
 	// create a new device
 	ERROR_PROPAGATE(create(device_id, &device));
 	// print the settings
-	printf("New device created:\n\tid\t= %d\n", device->device_id);
+	printf("%s: Device created (id: %d)\n", NAME, device->device_id);
 	return EOK;
 }
@@ -186,5 +178,5 @@
 	ERROR_DECLARE;
 
-	device_ref device;
+	netif_device_t * device;
 	size_t length;
 	packet_t next;
@@ -212,12 +204,61 @@
 }
 
-int netif_start_message(device_ref device){
+int netif_start_message(netif_device_t * device){
 	return change_state_message(device, NETIF_ACTIVE);
 }
 
-int netif_stop_message(device_ref device){
+int netif_stop_message(netif_device_t * device){
 	return change_state_message(device, NETIF_STOPPED);
 }
 
+/** Default thread for new connections.
+ *
+ * @param[in] iid The initial message identifier.
+ * @param[in] icall The initial message call structure.
+ *
+ */
+static void netif_client_connection(ipc_callid_t iid, ipc_call_t *icall)
+{
+	/*
+	 * Accept the connection
+	 *  - Answer the first IPC_M_CONNECT_ME_TO call.
+	 */
+	ipc_answer_0(iid, EOK);
+	
+	while(true) {
+		ipc_call_t answer;
+		int answer_count;
+		
+		/* Clear the answer structure */
+		refresh_answer(&answer, &answer_count);
+		
+		/* Fetch the next message */
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		/* Process the message */
+		int res = netif_module_message(NAME, callid, &call, &answer,
+		    &answer_count);
+		
+		/* End if said to either by the message or the processing result */
+		if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
+			return;
+		
+		/* Answer the message */
+		answer_call(callid, res, &answer, answer_count);
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	ERROR_DECLARE;
+	
+	/* Start the module */
+	if (ERROR_OCCURRED(netif_module_start(netif_client_connection)))
+		return ERROR_CODE;
+	
+	return EOK;
+}
+
 /** @}
  */
Index: pace/srv/net/netif/netif.c
===================================================================
--- uspace/srv/net/netif/netif.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,292 +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 netif
- *  @{
- */
-
-/** @file
- *  Network interface module skeleton implementation.
- *  @see netif.h
- */
-
-#include <async.h>
-#include <mem.h>
-#include <fibril_synch.h>
-#include <stdio.h>
-
-#include <ipc/ipc.h>
-#include <ipc/services.h>
-
-#include "../err.h"
-#include "../messages.h"
-#include "../modules.h"
-
-#include "../structures/packet/packet.h"
-#include "../structures/packet/packet_client.h"
-#include "../structures/measured_strings.h"
-
-#include "../include/device.h"
-#include "../include/netif_interface.h"
-#include "../include/nil_interface.h"
-
-#include "netif.h"
-#include "netif_messages.h"
-#include "netif_module.h"
-
-/** Network interface module global data.
- */
-extern netif_globals_t netif_globals;
-
-DEVICE_MAP_IMPLEMENT(device_map, device_t)
-
-/** @name Message processing functions
- */
-/*@{*/
-
-/** Registers the device notification receiver, the network interface layer module.
- *  @param[in] device_id The device identifier.
- *  @param[in] phone The network interface layer module phone.
- *  @returns EOK on success.
- *  @returns ENOENT if there is no such device.
- *  @returns ELIMIT if there is another module registered.
- */
-int register_message(device_id_t device_id, int phone);
-
-/*@}*/
-
-int netif_probe_req(int netif_phone, device_id_t device_id, int irq, int io){
-	int result;
-
-	fibril_rwlock_write_lock(&netif_globals.lock);
-	result = netif_probe_message(device_id, irq, io);
-	fibril_rwlock_write_unlock(&netif_globals.lock);
-	return result;
-}
-
-int netif_send_msg(int netif_phone, device_id_t device_id, packet_t packet, services_t sender){
-	int result;
-
-	fibril_rwlock_write_lock(&netif_globals.lock);
-	result = netif_send_message(device_id, packet, sender);
-	fibril_rwlock_write_unlock(&netif_globals.lock);
-	return result;
-}
-
-int netif_start_req(int netif_phone, device_id_t device_id){
-	ERROR_DECLARE;
-
-	device_ref device;
-	int result;
-	int phone;
-
-	fibril_rwlock_write_lock(&netif_globals.lock);
-	if(ERROR_OCCURRED(find_device(device_id, &device))){
-		fibril_rwlock_write_unlock(&netif_globals.lock);
-		return ERROR_CODE;
-	}
-	result = netif_start_message(device);
-	if(result > NETIF_NULL){
-		phone = device->nil_phone;
-		fibril_rwlock_write_unlock(&netif_globals.lock);
-		nil_device_state_msg(phone, device_id, result);
-		return EOK;
-	}else{
-		fibril_rwlock_write_unlock(&netif_globals.lock);
-	}
-	return result;
-}
-
-int netif_stop_req(int netif_phone, device_id_t device_id){
-	ERROR_DECLARE;
-
-	device_ref device;
-	int result;
-	int phone;
-
-	fibril_rwlock_write_lock(&netif_globals.lock);
-	if(ERROR_OCCURRED(find_device(device_id, &device))){
-		fibril_rwlock_write_unlock(&netif_globals.lock);
-		return ERROR_CODE;
-	}
-	result = netif_stop_message(device);
-	if(result > NETIF_NULL){
-		phone = device->nil_phone;
-		fibril_rwlock_write_unlock(&netif_globals.lock);
-		nil_device_state_msg(phone, device_id, result);
-		return EOK;
-	}else{
-		fibril_rwlock_write_unlock(&netif_globals.lock);
-	}
-	return result;
-}
-
-int netif_stats_req(int netif_phone, device_id_t device_id, device_stats_ref stats){
-	int res;
-
-	fibril_rwlock_read_lock(&netif_globals.lock);
-	res = netif_get_device_stats(device_id, stats);
-	fibril_rwlock_read_unlock(&netif_globals.lock);
-	return res;
-}
-
-int netif_get_addr_req(int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data){
-	ERROR_DECLARE;
-
-	measured_string_t translation;
-
-	if(!(address && data)){
-		return EBADMEM;
-	}
-	fibril_rwlock_read_lock(&netif_globals.lock);
-	if(! ERROR_OCCURRED(netif_get_addr_message(device_id, &translation))){
-		*address = measured_string_copy(&translation);
-		ERROR_CODE = (*address) ? EOK : ENOMEM;
-	}
-	fibril_rwlock_read_unlock(&netif_globals.lock);
-	*data = (** address).value;
-	return ERROR_CODE;
-}
-
-int netif_bind_service(services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver){
-	return EOK;
-}
-
-int find_device(device_id_t device_id, device_ref * device){
-	if(! device){
-		return EBADMEM;
-	}
-	*device = device_map_find(&netif_globals.device_map, device_id);
-	if(! * device){
-		return ENOENT;
-	}
-	if((** device).state == NETIF_NULL) return EPERM;
-	return EOK;
-}
-
-void null_device_stats(device_stats_ref stats){
-	bzero(stats, sizeof(device_stats_t));
-}
-
-int register_message(device_id_t device_id, int phone){
-	ERROR_DECLARE;
-
-	device_ref device;
-
-	ERROR_PROPAGATE(find_device(device_id, &device));
-	if(device->nil_phone > 0){
-		return ELIMIT;
-	}
-	device->nil_phone = phone;
-	printf("New receiver of the device %d registered:\n\tphone\t= %d\n", device->device_id, device->nil_phone);
-	return EOK;
-}
-
-int netif_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	ERROR_DECLARE;
-
-	size_t length;
-	device_stats_t stats;
-	packet_t packet;
-	measured_string_t address;
-
-//	printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NETIF_FIRST);
-	*answer_count = 0;
-	switch(IPC_GET_METHOD(*call)){
-		case IPC_M_PHONE_HUNGUP:
-			return EOK;
-		case NET_NETIF_PROBE:
-			return netif_probe_req(0, IPC_GET_DEVICE(call), NETIF_GET_IRQ(call), NETIF_GET_IO(call));
-		case IPC_M_CONNECT_TO_ME:
-			fibril_rwlock_write_lock(&netif_globals.lock);
-			ERROR_CODE = register_message(IPC_GET_DEVICE(call), IPC_GET_PHONE(call));
-			fibril_rwlock_write_unlock(&netif_globals.lock);
-			return ERROR_CODE;
-		case NET_NETIF_SEND:
-			ERROR_PROPAGATE(packet_translate(netif_globals.net_phone, &packet, IPC_GET_PACKET(call)));
-			return netif_send_msg(0, IPC_GET_DEVICE(call), packet, IPC_GET_SENDER(call));
-		case NET_NETIF_START:
-			return netif_start_req(0, IPC_GET_DEVICE(call));
-		case NET_NETIF_STATS:
-			fibril_rwlock_read_lock(&netif_globals.lock);
-			if(! ERROR_OCCURRED(async_data_read_receive(&callid, &length))){
-				if(length < sizeof(device_stats_t)){
-					ERROR_CODE = EOVERFLOW;
-				}else{
-					if(! ERROR_OCCURRED(netif_get_device_stats(IPC_GET_DEVICE(call), &stats))){
-						ERROR_CODE = async_data_read_finalize(callid, &stats, sizeof(device_stats_t));
-					}
-				}
-			}
-			fibril_rwlock_read_unlock(&netif_globals.lock);
-			return ERROR_CODE;
-		case NET_NETIF_STOP:
-			return netif_stop_req(0, IPC_GET_DEVICE(call));
-		case NET_NETIF_GET_ADDR:
-			fibril_rwlock_read_lock(&netif_globals.lock);
-			if(! ERROR_OCCURRED(netif_get_addr_message(IPC_GET_DEVICE(call), &address))){
-				ERROR_CODE = measured_strings_reply(&address, 1);
-			}
-			fibril_rwlock_read_unlock(&netif_globals.lock);
-			return ERROR_CODE;
-	}
-	return netif_specific_message(callid, call, answer, answer_count);
-}
-
-int netif_init_module(async_client_conn_t client_connection){
-	ERROR_DECLARE;
-
-	async_set_client_connection(client_connection);
-	netif_globals.net_phone = connect_to_service(SERVICE_NETWORKING);
-	device_map_initialize(&netif_globals.device_map);
-	ERROR_PROPAGATE(pm_init());
-	fibril_rwlock_initialize(&netif_globals.lock);
-	if(ERROR_OCCURRED(netif_initialize())){
-		pm_destroy();
-		return ERROR_CODE;
-	}
-	return EOK;
-}
-
-int netif_run_module(void){
-	async_manager();
-
-	pm_destroy();
-	return EOK;
-}
-
-void netif_pq_release(packet_id_t packet_id){
-	pq_release(netif_globals.net_phone, packet_id);
-}
-
-packet_t netif_packet_get_1(size_t content){
-	return packet_get_1(netif_globals.net_phone, content);
-}
-
-/** @}
- */
Index: pace/srv/net/netif/netif.h
===================================================================
--- uspace/srv/net/netif/netif.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,161 +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 netif
- *  @{
- */
-
-/** @file
- *  Network interface module skeleton.
- *  The skeleton has to be part of each network interface module.
- *  The skeleton can be also part of the module bundled with the network interface layer.
- */
-
-#ifndef __NET_NETIF_H__
-#define __NET_NETIF_H__
-
-#include <async.h>
-#include <fibril_synch.h>
-
-#include <ipc/ipc.h>
-
-#include "../err.h"
-
-#include "../include/device.h"
-
-#include "../structures/packet/packet.h"
-
-/** Network interface module skeleton global data.
- */
-typedef struct netif_globals	netif_globals_t;
-
-/** Type definition of the device specific data.
- *  @see netif_device
- */
-typedef struct netif_device	device_t;
-
-/** Type definition of the device specific data pointer.
- *  @see netif_device
- */
-typedef device_t *			device_ref;
-
-/** Device map.
- *  Maps device identifiers to the network interface device specific data.
- *  @see device.h
- */
-DEVICE_MAP_DECLARE(device_map, device_t);
-
-/** Network interface device specific data.
- */
-struct	netif_device{
-	/** Device identifier.
-	 */
-	device_id_t device_id;
-	/** Receiving network interface layer phone.
-	 */
-	int nil_phone;
-	/** Actual device state.
-	 */
-	device_state_t state;
-	/** Driver specific data.
-	 */
-	void * specific;
-};
-
-/** Network interface module skeleton global data.
- */
-struct	netif_globals{
-	/** Networking module phone.
-	 */
-	int net_phone;
-	/**	Device map.
-	 */
-	device_map_t device_map;
-	/** Safety lock.
-	 */
-	fibril_rwlock_t lock;
-};
-
-/**	Finds the device specific data.
- *  @param[in] device_id The device identifier.
- *  @param[out] device The device specific data.
- *  @returns EOK on success.
- *  @returns ENOENT if device is not found.
- *  @returns EPERM if the device is not initialized.
- */
-int find_device(device_id_t device_id, device_ref * device);
-
-/** Clears the usage statistics.
- *  @param[in] stats The usage statistics.
- */
-void null_device_stats(device_stats_ref stats);
-
-// prepared for future optimalizations
-/** Releases the given packet.
- *  @param[in] packet_id The packet identifier.
- */
-void netif_pq_release(packet_id_t packet_id);
-
-/** Allocates new packet to handle the given content size.
- *  @param[in] content The minimum content size.
- *  @returns The allocated packet.
- *  @returns NULL if there is an error.
- */
-packet_t netif_packet_get_1(size_t content);
-
-/** Processes the netif module messages.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOTSUP if the message is not known.
- *  @returns Other error codes as defined for each specific module message function.
- *  @see netif_interface.h
- *  @see IS_NET_NETIF_MESSAGE()
- */
-int netif_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-/** Initializes the netif module.
- *  The function has to be defined in each module.
- *  @param[in] client_connection The client connection functio to be registered.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for each specific module message function.
- */
-int netif_init_module(async_client_conn_t client_connection);
-
-/** Starts and maintains the netif module until terminated.
- *  @returns EOK after the module is terminated.
- */
-int netif_run_module(void);
-
-#endif
-
-/** @}
- */
-
Index: pace/srv/net/netif/netif_messages.h
===================================================================
--- uspace/srv/net/netif/netif_messages.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(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 netif
- *  @{
- */
-
-/** @file
- *  Network interface common module messages.
- *  @see netif_interface.h
- */
-
-#ifndef __NET_NETIF_MESSAGES_H__
-#define __NET_NETIF_MESSAGES_H__
-
-#include <ipc/ipc.h>
-
-#include "../messages.h"
-
-/** Network interface common module messages.
- */
-typedef enum {
-	/** Probe device message.
-	 *  @see netif_probe_req()
-	 */
-	NET_NETIF_PROBE = NET_NETIF_FIRST,
-	/** Send packet message.
-	 *  @see netif_send_msg()
-	 */
-	NET_NETIF_SEND,
-	/** Start device message.
-	 *  @see netif_start_req()
-	 */
-	NET_NETIF_START,
-	/** Get device usage statistics message.
-	 *  @see netif_stats_req()
-	 */
-	NET_NETIF_STATS,
-	/** Stop device message.
-	 *  @see netif_stop_req()
-	 */
-	NET_NETIF_STOP,
-	/** Get device address message.
-	 *  @see netif_get_addr_req()
-	 */
-	NET_NETIF_GET_ADDR,
-} netif_messages;
-
-/** @name Network interface specific message parameters definitions
- */
-/*@{*/
-
-/** Returns the interrupt number message parameter.
- *  @param[in] call The message call structure.
- */
-#define NETIF_GET_IRQ(call)		(int)	IPC_GET_ARG2(*call)
-
-/** Returns the input/output address message parameter.
- *  @param[in] call The message call structure.
- */
-#define NETIF_GET_IO(call)		(int)	IPC_GET_ARG3(*call)
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/netif/netif_module.h
===================================================================
--- uspace/srv/net/netif/netif_module.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,126 +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 netif
- *  @{
- */
-
-/** @file
- *  Network interface module interface.
- *  The interface has to be implemented by each network interface module.
- *  The interface is used by the network interface module skeleton.
- */
-
-#ifndef __NET_NETIF_MODULE_H__
-#define __NET_NETIF_MODULE_H__
-
-#include <ipc/ipc.h>
-#include <ipc/services.h>
-
-#include "../structures/measured_strings.h"
-#include "../structures/packet/packet.h"
-
-#include "../include/device.h"
-
-/** Initializes the specific module.
- */
-int netif_initialize(void);
-
-/** Probes the existence of the device.
- *  @param[in] device_id The device identifier.
- *  @param[in] irq The device interrupt number.
- *  @param[in] io The device input/output address.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the find_device() function.
- *  @returns Other error codes as defined for the specific module message implementation.
- */
-int netif_probe_message(device_id_t device_id, int irq, uintptr_t io);
-
-/** Sends the packet queue.
- *  @param[in] device_id The device identifier.
- *  @param[in] packet The packet queue.
- *  @param[in] sender The sending module service.
- *  @returns EOK on success.
- *  @returns EFORWARD if the device is not active (in the NETIF_ACTIVE state).
- *  @returns Other error codes as defined for the find_device() function.
- *  @returns Other error codes as defined for the specific module message implementation.
- */
-int netif_send_message(device_id_t device_id, packet_t packet, services_t sender);
-
-/** Starts the device.
- *  @param[in] device The device structure.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the find_device() function.
- *  @returns Other error codes as defined for the specific module message implementation.
- */
-int netif_start_message(device_ref device);
-
-/** Stops the device.
- *  @param[in] device The device structure.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the find_device() function.
- *  @returns Other error codes as defined for the specific module message implementation.
- */
-int netif_stop_message(device_ref device);
-
-/** Returns the device local hardware address.
- *  @param[in] device_id The device identifier.
- *  @param[out] address The device local hardware address.
- *  @returns EOK on success.
- *  @returns EBADMEM if the address parameter is NULL.
- *  @returns ENOENT if there no such device.
- *  @returns Other error codes as defined for the find_device() function.
- *  @returns Other error codes as defined for the specific module message implementation.
- */
-int netif_get_addr_message(device_id_t device_id, measured_string_ref address);
-
-/** Processes the netif driver specific message.
- *  This function is called for uncommon messages received by the netif skeleton.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOTSUP if the message is not known.
- *  @returns Other error codes as defined for the specific module message implementation.
- */
-int netif_specific_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-/** Returns the device usage statistics.
- *  @param[in] device_id The device identifier.
- *  @param[out] stats The device usage statistics.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the find_device() function.
- *  @returns Other error codes as defined for the specific module message implementation.
- */
-int netif_get_device_stats(device_id_t device_id, device_stats_ref stats);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/netif/netif_nil_bundle.c
===================================================================
--- uspace/srv/net/netif/netif_nil_bundle.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(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 netif
- *  @{
- */
-
-/** @file
- *  Wrapper for the bundled network interface and network interface layer module.
- *  Distributes messages and initializes both module parts.
- */
-
-#include <async.h>
-
-#include <ipc/ipc.h>
-
-#include "../messages.h"
-
-#include "../structures/packet/packet.h"
-
-#include "../nil/nil_module.h"
-
-#include "netif.h"
-
-/** Network interface module global data.
- */
-extern netif_globals_t netif_globals;
-
-/** Distributes the messages between the module parts.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOTSUP if the message is not known.
- *  @returns Other error codes as defined for each specific module message function.
- */
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-/** Starts the bundle network interface module.
- *  Initializes the client connection serving function, initializes both module parts, registers the module service and starts the async manager, processing IPC messages in an infinite loop.
- *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for each specific module message function.
- */
-int module_start(async_client_conn_t client_connection);
-
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	if(IS_NET_NIL_MESSAGE(call) || (IPC_GET_METHOD(*call) == IPC_M_CONNECT_TO_ME)){
-		return nil_message(callid, call, answer, answer_count);
-	}else{
-		return netif_message(callid, call, answer, answer_count);
-	}
-}
-
-int module_start(async_client_conn_t client_connection){
-	ERROR_DECLARE;
-
-	ERROR_PROPAGATE(netif_init_module(client_connection));
-	if(ERROR_OCCURRED(nil_initialize(netif_globals.net_phone))){
-		pm_destroy();
-		return ERROR_CODE;
-	}
-	return netif_run_module();
-}
-
-/** @}
- */
Index: pace/srv/net/netif/netif_remote.c
===================================================================
--- uspace/srv/net/netif/netif_remote.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,89 +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 netif
- *  @{
- */
-
-/** @file
- *  Network interface module interface implementation for standalone remote modules.
- *  @see netif_interface.h
- */
-
-#include <ipc/services.h>
-
-#include "../modules.h"
-
-#include "../structures/measured_strings.h"
-#include "../structures/packet/packet.h"
-#include "../structures/packet/packet_client.h"
-
-#include "../include/device.h"
-#include "../include/netif_interface.h"
-
-#include "netif_messages.h"
-
-int netif_get_addr_req(int netif_phone, device_id_t device_id, measured_string_ref * address, char ** data){
-	return generic_get_addr_req(netif_phone, NET_NETIF_GET_ADDR, device_id, address, data);
-}
-
-int netif_probe_req(int netif_phone, device_id_t device_id, int irq, int io){
-	return async_req_3_0(netif_phone, NET_NETIF_PROBE, device_id, irq, io);
-}
-
-int netif_send_msg(int netif_phone, device_id_t device_id, packet_t packet, services_t sender){
-	return generic_send_msg(netif_phone, NET_NETIF_SEND, device_id, packet_get_id(packet), sender, 0);
-}
-
-int netif_start_req(int netif_phone, device_id_t device_id){
-	return async_req_1_0(netif_phone, NET_NETIF_START, device_id);
-}
-
-int netif_stop_req(int netif_phone, device_id_t device_id){
-	return async_req_1_0(netif_phone, NET_NETIF_STOP, device_id);
-}
-
-int netif_stats_req(int netif_phone, device_id_t device_id, device_stats_ref stats){
-	aid_t message_id;
-	ipcarg_t result;
-
-	if(! stats){
-		return EBADMEM;
-	}
-	message_id = async_send_1(netif_phone, NET_NETIF_STATS, (ipcarg_t) device_id, NULL);
-	async_data_read_start(netif_phone, stats, sizeof(*stats));
-	async_wait_for(message_id, &result);
-	return (int) result;
-}
-
-int netif_bind_service(services_t service, device_id_t device_id, services_t me, async_client_conn_t receiver){
-	return bind_service(service, device_id, me, 0, receiver);
-}
-
-/** @}
- */
Index: pace/srv/net/netif/netif_standalone.c
===================================================================
--- uspace/srv/net/netif/netif_standalone.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,74 +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 netif
- *  @{
- */
-
-/** @file
- *  Wrapper for the standalone network interface module.
- */
-
-#include <async.h>
-
-#include <ipc/ipc.h>
-
-#include "netif.h"
-
-/** Delegates the messages to the netif_message() function.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOTSUP if the message is not known.
- *  @returns Other error codes as defined for each specific module message function.
- */
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-/** Starts the network interface module.
- *  Initializes the client connection serving function, initializes the module, registers the module service and starts the async manager, processing IPC messages in an infinite loop.
- *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for each specific module message function.
- */
-int module_start(async_client_conn_t client_connection);
-
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	return netif_message(callid, call, answer, answer_count);
-}
-
-int module_start(async_client_conn_t client_connection){
-	ERROR_DECLARE;
-
-	ERROR_PROPAGATE(netif_init_module(client_connection));
-	return netif_run_module();
-}
-
-/** @}
- */
Index: uspace/srv/net/netstart/Makefile
===================================================================
--- uspace/srv/net/netstart/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/net/netstart/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,40 @@
+#
+# Copyright (c) 2005 Martin Decky
+# Copyright (c) 2007 Jakub Jermar
+# 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.
+#
+
+USPACE_PREFIX = ../../..
+LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBSOCKET_PREFIX)/include
+
+BINARY = netstart
+
+SOURCES = \
+	netstart.c \
+	self_test.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/netstart/netstart.c
===================================================================
--- uspace/srv/net/netstart/netstart.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/net/netstart/netstart.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -0,0 +1,107 @@
+/*
+ * 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
+ *
+ * Start the networking subsystem.
+ * Perform networking self-test if executed
+ * with the -s argument.
+ *
+ */
+
+#define NAME  "netstart"
+
+#include <async.h>
+#include <stdio.h>
+#include <task.h>
+#include <str_error.h>
+#include <ipc/ipc.h>
+#include <ipc/services.h>
+
+#include <net_err.h>
+#include <net_modules.h>
+#include <net_net_messages.h>
+
+#include "self_test.h"
+
+/** Start a module.
+ *
+ * @param[in] desc The module description
+ * @param[in] path The module absolute path.
+ *
+ * @returns true on succesful spanwning
+ * @returns false on failure
+ *
+ */
+static bool spawn(const char *desc, const char *path)
+{
+	printf("%s: Spawning %s (%s)\n", NAME, desc, path);
+	
+	const char *argv[2];
+	
+	argv[0] = path;
+	argv[1] = NULL;
+	
+	int err;
+	if (task_spawn(path, argv, &err) == 0) {
+		fprintf(stderr, "%s: Error spawning %s (%s)\n", NAME, path,
+		    str_error(err));
+		return false;
+	}
+	
+	return true;
+}
+
+int main(int argc, char *argv[])
+{
+	ERROR_DECLARE;
+	
+	/* Run self-tests */
+	if ((argc > 1) && (str_cmp(argv[1], "-s") == 0))
+		ERROR_PROPAGATE(self_test());
+	
+	if (!spawn("networking service", "/srv/net"))
+		return EINVAL;
+	
+	printf("%s: Initializing networking\n", NAME);
+	
+	int net_phone = connect_to_service(SERVICE_NETWORKING);
+	if (ERROR_OCCURRED(ipc_call_sync_0_0(net_phone, NET_NET_STARTUP))) {
+		fprintf(stderr, "%s: Startup error %d\n", NAME, ERROR_CODE);
+		return ERROR_CODE;
+	}
+	
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/srv/net/netstart/self_test.c
===================================================================
--- uspace/srv/net/netstart/self_test.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/net/netstart/self_test.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -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/srv/net/netstart/self_test.h
===================================================================
--- uspace/srv/net/netstart/self_test.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
+++ uspace/srv/net/netstart/self_test.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -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/srv/net/nil/eth/Makefile
===================================================================
--- uspace/srv/net/nil/eth/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/nil/eth/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,20 +28,24 @@
 #
 
-NET_BASE = ../..
 USPACE_PREFIX = ../../../..
-BINARY = eth
+ROOT_PATH = $(USPACE_PREFIX)/..
+LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBSOCKET_PREFIX)/include
+
+COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
+CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
+
+-include $(COMMON_MAKEFILE)
+-include $(CONFIG_MAKEFILE)
+
+ifeq ($(CONFIG_NETIF_NIL_BUNDLE),y)
+	LIBRARY = libeth
+else
+	BINARY = eth
+endif
 
 SOURCES = \
 	eth.c \
-	eth_module.c \
-	$(NET_BASE)/checksum.c \
-	$(NET_BASE)/module.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/net/net_remote.c \
-	$(NET_BASE)/netif/netif_remote.c \
-	$(NET_BASE)/structures/measured_strings.c \
-	$(NET_BASE)/structures/packet/packet.c \
-	$(NET_BASE)/structures/packet/packet_client.c \
-	$(NET_BASE)/structures/packet/packet_remote.c
+	eth_module.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/nil/eth/eth.c
===================================================================
--- uspace/srv/net/nil/eth/eth.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/nil/eth/eth.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -45,26 +45,28 @@
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../messages.h"
-#include "../../modules.h"
-
-#include "../../include/byteorder.h"
-#include "../../include/checksum.h"
-#include "../../include/ethernet_lsap.h"
-#include "../../include/ethernet_protocols.h"
-#include "../../include/protocol_map.h"
-#include "../../include/device.h"
-#include "../../include/netif_interface.h"
-#include "../../include/net_interface.h"
-#include "../../include/nil_interface.h"
-#include "../../include/il_interface.h"
-
-#include "../../structures/measured_strings.h"
-#include "../../structures/packet/packet_client.h"
-
-#include "../nil_module.h"
+#include <net_err.h>
+#include <net_messages.h>
+#include <net_modules.h>
+#include <net_byteorder.h>
+#include <net_checksum.h>
+#include <ethernet_lsap.h>
+#include <ethernet_protocols.h>
+#include <protocol_map.h>
+#include <net_device.h>
+#include <netif_interface.h>
+#include <net_interface.h>
+#include <nil_interface.h>
+#include <il_interface.h>
+#include <adt/measured_strings.h>
+#include <packet/packet_client.h>
+#include <packet_remote.h>
+#include <nil_local.h>
 
 #include "eth.h"
 #include "eth_header.h"
+
+/** The module name.
+ */
+#define NAME  "eth"
 
 /** Reserved packet prefix length.
@@ -270,5 +272,5 @@
 INT_MAP_IMPLEMENT(eth_protos, eth_proto_t)
 
-int nil_device_state_msg(int nil_phone, device_id_t device_id, int state){
+int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state){
 	int index;
 	eth_proto_ref proto;
@@ -401,5 +403,10 @@
 			return index;
 		}
-		printf("New device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n\taddress\t= %X:%X:%X:%X:%X:%X\n\tflags\t= 0x%x\n", device->device_id, device->service, device->mtu, device->addr_data[0], device->addr_data[1], device->addr_data[2], device->addr_data[3], device->addr_data[4], device->addr_data[5], device->flags);
+		printf("%s: Device registered (id: %d, service: %d: mtu: %d, "
+		    "mac: %x:%x:%x:%x:%x:%x, flags: 0x%x)\n",
+		    NAME, device->device_id, device->service, device->mtu,
+		    device->addr_data[0], device->addr_data[1],
+		    device->addr_data[2], device->addr_data[3],
+		    device->addr_data[4], device->addr_data[5], device->flags);
 	}
 	fibril_rwlock_write_unlock(&eth_globals.devices_lock);
@@ -469,5 +476,5 @@
 }
 
-int nil_received_msg(int nil_phone, device_id_t device_id, packet_t packet, services_t target){
+int nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet, services_t target){
 	eth_proto_ref proto;
 	packet_t next;
@@ -491,5 +498,5 @@
 		}else{
 			// drop invalid/unknown
-			pq_release(eth_globals.net_phone, packet_get_id(packet));
+			pq_release_remote(eth_globals.net_phone, packet_get_id(packet));
 		}
 		packet = next;
@@ -571,5 +578,8 @@
 		}
 	}
-	printf("New protocol registered:\n\tprotocol\t= 0x%x\n\tservice\t= %d\n\tphone\t= %d\n", proto->protocol, proto->service, proto->phone);
+	
+	printf("%s: Protocol registered (protocol: %d, service: %d, phone: %d)\n",
+	    NAME, proto->protocol, proto->service, proto->phone);
+	
 	fibril_rwlock_write_unlock(&eth_globals.protos_lock);
 	return EOK;
@@ -672,5 +682,5 @@
 	ethertype = htons(protocol_map(SERVICE_ETHERNET, sender));
 	if(! ethertype){
-		pq_release(eth_globals.net_phone, packet_get_id(packet));
+		pq_release_remote(eth_globals.net_phone, packet_get_id(packet));
 		return EINVAL;
 	}
@@ -690,5 +700,5 @@
 				packet = tmp;
 			}
-			pq_release(eth_globals.net_phone, packet_get_id(next));
+			pq_release_remote(eth_globals.net_phone, packet_get_id(next));
 			next = tmp;
 		}else{
@@ -704,33 +714,50 @@
 }
 
-int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+int nil_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, int *answer_count)
+{
 	ERROR_DECLARE;
-
+	
 	measured_string_ref address;
 	packet_t packet;
-
-//	printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NIL_FIRST);
+	size_t addrlen;
+	size_t prefix;
+	size_t suffix;
+	size_t content;
+	
 	*answer_count = 0;
-	switch(IPC_GET_METHOD(*call)){
+	switch (IPC_GET_METHOD(*call)) {
 		case IPC_M_PHONE_HUNGUP:
 			return EOK;
 		case NET_NIL_DEVICE:
-			return eth_device_message(IPC_GET_DEVICE(call), IPC_GET_SERVICE(call), IPC_GET_MTU(call));
+			return eth_device_message(IPC_GET_DEVICE(call),
+			    IPC_GET_SERVICE(call), IPC_GET_MTU(call));
 		case NET_NIL_SEND:
-			ERROR_PROPAGATE(packet_translate(eth_globals.net_phone, &packet, IPC_GET_PACKET(call)));
-			return eth_send_message(IPC_GET_DEVICE(call), packet, IPC_GET_SERVICE(call));
+			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:
-			ERROR_PROPAGATE(eth_packet_space_message(IPC_GET_DEVICE(call), IPC_SET_ADDR(answer), IPC_SET_PREFIX(answer), IPC_SET_CONTENT(answer), IPC_SET_SUFFIX(answer)));
+			ERROR_PROPAGATE(eth_packet_space_message(IPC_GET_DEVICE(call),
+			    &addrlen, &prefix, &content, &suffix));
+			IPC_SET_ADDR(answer, addrlen);
+			IPC_SET_PREFIX(answer, prefix);
+			IPC_SET_CONTENT(answer, content);
+			IPC_SET_SUFFIX(answer, suffix);
 			*answer_count = 4;
 			return EOK;
 		case NET_NIL_ADDR:
-			ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), ETH_LOCAL_ADDR, &address));
+			ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call),
+			    ETH_LOCAL_ADDR, &address));
 			return measured_strings_reply(address, 1);
 		case NET_NIL_BROADCAST_ADDR:
-			ERROR_PROPAGATE(eth_addr_message(IPC_GET_DEVICE(call), ETH_BROADCAST_ADDR, &address));
+			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:
-			return eth_register_message(NIL_GET_PROTO(call), IPC_GET_PHONE(call));
-	}
+			return eth_register_message(NIL_GET_PROTO(call),
+			    IPC_GET_PHONE(call));
+	}
+	
 	return ENOTSUP;
 }
@@ -745,10 +772,10 @@
 		switch(IPC_GET_METHOD(*icall)){
 			case NET_NIL_DEVICE_STATE:
-				nil_device_state_msg(0, IPC_GET_DEVICE(icall), IPC_GET_STATE(icall));
+				nil_device_state_msg_local(0, IPC_GET_DEVICE(icall), IPC_GET_STATE(icall));
 				ipc_answer_0(iid, EOK);
 				break;
 			case NET_NIL_RECEIVED:
-				if(! ERROR_OCCURRED(packet_translate(eth_globals.net_phone, &packet, IPC_GET_PACKET(icall)))){
-					ERROR_CODE = nil_received_msg(0, IPC_GET_DEVICE(icall), packet, 0);
+				if(! ERROR_OCCURRED(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) ERROR_CODE);
@@ -761,4 +788,57 @@
 }
 
+#ifndef CONFIG_NETIF_NIL_BUNDLE
+
+/** Default thread for new connections.
+ *
+ * @param[in] iid The initial message identifier.
+ * @param[in] icall The initial message call structure.
+ *
+ */
+static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall)
+{
+	/*
+	 * Accept the connection
+	 *  - Answer the first IPC_M_CONNECT_ME_TO call.
+	 */
+	ipc_answer_0(iid, EOK);
+	
+	while(true) {
+		ipc_call_t answer;
+		int answer_count;
+		
+		/* Clear the answer structure */
+		refresh_answer(&answer, &answer_count);
+		
+		/* Fetch the next message */
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		/* Process the message */
+		int res = nil_module_message_standalone(NAME, callid, &call, &answer,
+		    &answer_count);
+		
+		/* End if said to either by the message or the processing result */
+		if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
+			return;
+		
+		/* Answer the message */
+		answer_call(callid, res, &answer, answer_count);
+	}
+}
+
+int main(int argc, char *argv[])
+{
+	ERROR_DECLARE;
+	
+	/* Start the module */
+	if (ERROR_OCCURRED(nil_module_start_standalone(nil_client_connection)))
+		return ERROR_CODE;
+	
+	return EOK;
+}
+
+#endif /* CONFIG_NETIF_NIL_BUNDLE */
+
 /** @}
  */
Index: uspace/srv/net/nil/eth/eth.h
===================================================================
--- uspace/srv/net/nil/eth/eth.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/nil/eth/eth.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -41,6 +41,6 @@
 #include <ipc/services.h>
 
-#include "../../include/device.h"
-#include "../../structures/measured_strings.h"
+#include <net_device.h>
+#include <adt/measured_strings.h>
 
 /** Type definition of the Ethernet global data.
Index: uspace/srv/net/nil/eth/eth_module.c
===================================================================
--- uspace/srv/net/nil/eth/eth_module.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/nil/eth/eth_module.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -42,22 +42,11 @@
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../modules.h"
-
-#include "../../include/net_interface.h"
-
-#include "../../structures/packet/packet.h"
-
-#include "../nil_module.h"
+#include <net_err.h>
+#include <net_modules.h>
+#include <net_interface.h>
+#include <packet/packet.h>
+#include <nil_local.h>
 
 #include "eth.h"
-
-/** The module name.
- */
-#define NAME	"Ethernet protocol"
-
-/** Prints the module name.
- */
-void module_print_name(void);
 
 /** Starts the Ethernet module.
@@ -69,44 +58,44 @@
  *  @returns Other error codes as defined for the REGISTER_ME() macro function.
  */
-int module_start(async_client_conn_t client_connection);
-
-/** Passes the parameters to the module specific nil_message() function.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOTSUP if the message is not known.
- *  @returns Other error codes as defined for each specific module message function.
- */
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-void module_print_name(void){
-	printf("%s", NAME);
-}
-
-int module_start(async_client_conn_t client_connection){
+int nil_module_start_standalone(async_client_conn_t client_connection)
+{
 	ERROR_DECLARE;
-
+	
+	async_set_client_connection(client_connection);
+	int net_phone = net_connect_module(SERVICE_NETWORKING);
+	ERROR_PROPAGATE(pm_init());
+	
 	ipcarg_t phonehash;
-	int net_phone;
-
-	async_set_client_connection(client_connection);
-	net_phone = net_connect_module(SERVICE_NETWORKING);
-	ERROR_PROPAGATE(pm_init());
-	if(ERROR_OCCURRED(nil_initialize(net_phone))
-		|| ERROR_OCCURRED(REGISTER_ME(SERVICE_ETHERNET, &phonehash))){
+	if (ERROR_OCCURRED(nil_initialize(net_phone))
+	    || ERROR_OCCURRED(REGISTER_ME(SERVICE_ETHERNET, &phonehash))) {
 		pm_destroy();
 		return ERROR_CODE;
 	}
-
+	
 	async_manager();
-
+	
 	pm_destroy();
 	return EOK;
 }
 
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	return nil_message(callid, call, answer, answer_count);
+/** Pass the parameters to the module specific nil_message() function.
+ *
+ * @param[in]  name         Module name.
+ * @param[in]  callid       The message identifier.
+ * @param[in]  call         The message parameters.
+ * @param[out] answer       The message answer parameters.
+ * @param[out] answer_count The last parameter for the actual answer
+ *                          in the answer parameter.
+ *
+ * @return EOK on success.
+ * @return ENOTSUP if the message is not known.
+ * @return Other error codes as defined for each
+ *         specific module message function.
+ *
+ */
+int nil_module_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, int *answer_count)
+{
+	return nil_message_standalone(name, callid, call, answer, answer_count);
 }
 
Index: pace/srv/net/nil/nil_messages.h
===================================================================
--- uspace/srv/net/nil/nil_messages.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,91 +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 net_nil
- *  @{
- */
-
-/** @file
- *  Network interface layer module messages.
- *  @see nil_interface.h
- */
-
-#ifndef __NET_NIL_MESSAGES_H__
-#define __NET_NIL_MESSAGES_H__
-
-#include <ipc/ipc.h>
-
-#include "../messages.h"
-
-/**  Network interface layer module messages.
- */
-typedef enum {
-	/** New device or update MTU message.
-	 *  @see nil_device_req()
-	 */
-	NET_NIL_DEVICE = NET_NIL_FIRST,
-	/** New device state message.
-	 *  @see nil_device_state_msg()
-	 */
-	NET_NIL_DEVICE_STATE,
-	/** Received packet queue message.
-	 *  @see nil_received_msg()
-	 */
-	NET_NIL_RECEIVED,
-	/** Send packet queue message.
-	 *  @see nil_send_msg()
-	 */
-	NET_NIL_SEND,
-	/** Packet size message.
-	 *  @see nil_packet_size_req()
-	 */
-	NET_NIL_PACKET_SPACE,
-	/** Device local hardware address message.
-	 *  @see nil_get_addr()
-	 */
-	NET_NIL_ADDR,
-	/** Device broadcast hardware address message.
-	 *  @see nil_get_broadcast_addr()
-	 */
-	NET_NIL_BROADCAST_ADDR,
-} nil_messages;
-
-/** @name Network interface layer specific message parameters definitions
- */
-/*@{*/
-
-/** Returns the protocol service message parameter.
- */
-#define NIL_GET_PROTO(call)		(services_t) IPC_GET_ARG2(*call)
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/nil/nil_module.h
===================================================================
--- uspace/srv/net/nil/nil_module.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,67 +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 net_nil
- *  @{
- */
-
-/** @file
- *  Network interface layer modules common skeleton.
- *  All network interface layer modules have to implement this interface.
- */
-
-#ifndef __NET_ETH_MODULE_H__
-#define __NET_ETH_MODULE_H__
-
-#include <ipc/ipc.h>
-
-/** Module initialization.
- *  Is called by the module_start() function.
- *  @param[in] net_phone The networking moduel phone.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for each specific module initialize function.
- */
-int nil_initialize(int net_phone);
-
-/** Message processing function.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOTSUP if the message is not known.
- *  @returns Other error codes as defined for each specific module message function.
- *  @see nil_interface.h
- *  @see IS_NET_NIL_MESSAGE()
- */
-int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/nil/nil_remote.c
===================================================================
--- uspace/srv/net/nil/nil_remote.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,57 +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 net_nil
- *  @{
- */
-
-/** @file
- *  Network interface layer interface implementation for standalone remote modules.
- *  @see nil_interface.h
- */
-
-#include "../messages.h"
-
-#include "../include/device.h"
-#include "../include/nil_interface.h"
-
-#include "../structures/packet/packet.h"
-#include "../structures/packet/packet_client.h"
-
-#include "nil_messages.h"
-
-int nil_device_state_msg(int nil_phone, device_id_t device_id, int state){
-	return generic_device_state_msg(nil_phone, NET_NIL_DEVICE_STATE, device_id, state, 0);
-}
-
-int nil_received_msg(int nil_phone, device_id_t device_id, packet_t packet, services_t target){
-	return generic_received_msg(nil_phone, NET_NIL_RECEIVED, device_id, packet_get_id(packet), target, 0);
-}
-
-/** @}
- */
Index: uspace/srv/net/nil/nildummy/Makefile
===================================================================
--- uspace/srv/net/nil/nildummy/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/nil/nildummy/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,19 +28,24 @@
 #
 
-NET_BASE = ../..
 USPACE_PREFIX = ../../../..
-BINARY = nildummy
+ROOT_PATH = $(USPACE_PREFIX)/..
+LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBSOCKET_PREFIX)/include
+
+COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
+CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
+
+-include $(COMMON_MAKEFILE)
+-include $(CONFIG_MAKEFILE)
+
+ifeq ($(CONFIG_NETIF_NIL_BUNDLE),y)
+	LIBRARY = libnildummy
+else
+	BINARY = nildummy
+endif
 
 SOURCES = \
 	nildummy.c \
-	nildummy_module.c \
-	$(NET_BASE)/module.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/net/net_remote.c \
-	$(NET_BASE)/netif/netif_remote.c \
-	$(NET_BASE)/structures/measured_strings.c \
-	$(NET_BASE)/structures/packet/packet.c \
-	$(NET_BASE)/structures/packet/packet_client.c \
-	$(NET_BASE)/structures/packet/packet_remote.c
+	nildummy_module.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/nil/nildummy/nildummy.c
===================================================================
--- uspace/srv/net/nil/nildummy/nildummy.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/nil/nildummy/nildummy.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,10 +28,10 @@
 
 /** @addtogroup nildummy
- *  @{
+ * @{
  */
 
 /** @file
- *  Dummy network interface layer module implementation.
- *  @see nildummy.h
+ * Dummy network interface layer module implementation.
+ * @see nildummy.h
  */
 
@@ -41,125 +41,118 @@
 #include <stdio.h>
 #include <str.h>
-
 #include <ipc/ipc.h>
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../messages.h"
-#include "../../modules.h"
-
-#include "../../include/device.h"
-#include "../../include/netif_interface.h"
-#include "../../include/nil_interface.h"
-#include "../../include/il_interface.h"
-
-#include "../../structures/measured_strings.h"
-#include "../../structures/packet/packet.h"
-
-#include "../nil_module.h"
+#include <net_err.h>
+#include <net_messages.h>
+#include <net_modules.h>
+#include <net_device.h>
+#include <netif_interface.h>
+#include <nil_interface.h>
+#include <il_interface.h>
+#include <adt/measured_strings.h>
+#include <packet/packet.h>
+#include <packet_remote.h>
+#include <nil_local.h>
 
 #include "nildummy.h"
 
+/** The module name.
+ *
+ */
+#define NAME  "nildummy"
+
 /** Default maximum transmission unit.
- */
-#define NET_DEFAULT_MTU	1500
+ *
+ */
+#define NET_DEFAULT_MTU  1500
 
 /** Network interface layer module global data.
- */
-nildummy_globals_t	nildummy_globals;
-
-/** @name Message processing functions
- */
-/*@{*/
-
-/** Processes IPC messages from the registered device driver modules in an infinite loop.
- *  @param[in] iid The message identifier.
- *  @param[in,out] icall The message parameters.
- */
-void nildummy_receiver(ipc_callid_t iid, ipc_call_t * icall);
-
-/** Registers new device or updates the MTU of an existing one.
- *  Determines the device local hardware address.
- *  @param[in] device_id The new device identifier.
- *  @param[in] service The device driver service.
- *  @param[in] mtu The device maximum transmission unit.
- *  @returns EOK on success.
- *  @returns EEXIST if the device with the different service exists.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns Other error codes as defined for the netif_bind_service() function.
- *  @returns Other error codes as defined for the netif_get_addr_req() function.
- */
-int nildummy_device_message(device_id_t device_id, services_t service, size_t mtu);
-
-/** Returns the device packet dimensions for sending.
- *  @param[in] device_id The device identifier.
- *  @param[out] addr_len The minimum reserved address length.
- *  @param[out] prefix The minimum reserved prefix size.
- *  @param[out] content The maximum content size.
- *  @param[out] suffix The minimum reserved suffix size.
- *  @returns EOK on success.
- *  @returns EBADMEM if either one of the parameters is NULL.
- *  @returns ENOENT if there is no such device.
- */
-int nildummy_packet_space_message(device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix);
-
-/** Registers receiving module service.
- *  Passes received packets for this service.
- *  @param[in] service The module service.
- *  @param[in] phone The service phone.
- *  @returns EOK on success.
- *  @returns ENOENT if the service is not known.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int nildummy_register_message(services_t service, int phone);
-
-/** Sends the packet queue.
- *  @param[in] device_id The device identifier.
- *  @param[in] packet The packet queue.
- *  @param[in] sender The sending module service.
- *  @returns EOK on success.
- *  @returns ENOENT if there no such device.
- *  @returns EINVAL if the service parameter is not known.
- */
-int nildummy_send_message(device_id_t device_id, packet_t packet, services_t sender);
-
-/** Returns the device hardware address.
- *  @param[in] device_id The device identifier.
- *  @param[out] address The device hardware address.
- *  @returns EOK on success.
- *  @returns EBADMEM if the address parameter is NULL.
- *  @returns ENOENT if there no such device.
- */
-int nildummy_addr_message(device_id_t device_id, measured_string_ref * address);
-
-/*@}*/
-
-DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t)
-
-int nil_device_state_msg(int nil_phone, device_id_t device_id, int state){
+ *
+ */
+nildummy_globals_t nildummy_globals;
+
+DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t);
+
+int nil_device_state_msg_local(int nil_phone, device_id_t device_id, int state)
+{
 	fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
-	if(nildummy_globals.proto.phone){
-		il_device_state_msg(nildummy_globals.proto.phone, device_id, state, nildummy_globals.proto.service);
-	}
+	
+	if (nildummy_globals.proto.phone)
+		il_device_state_msg(nildummy_globals.proto.phone, device_id, state,
+		    nildummy_globals.proto.service);
+	
 	fibril_rwlock_read_unlock(&nildummy_globals.protos_lock);
-	return EOK;
-}
-
-int nil_initialize(int net_phone){
+	
+	return EOK;
+}
+
+int nil_initialize(int net_phone)
+{
 	ERROR_DECLARE;
-
+	
 	fibril_rwlock_initialize(&nildummy_globals.devices_lock);
 	fibril_rwlock_initialize(&nildummy_globals.protos_lock);
 	fibril_rwlock_write_lock(&nildummy_globals.devices_lock);
 	fibril_rwlock_write_lock(&nildummy_globals.protos_lock);
+	
 	nildummy_globals.net_phone = net_phone;
 	nildummy_globals.proto.phone = 0;
 	ERROR_PROPAGATE(nildummy_devices_initialize(&nildummy_globals.devices));
+	
 	fibril_rwlock_write_unlock(&nildummy_globals.protos_lock);
 	fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
-	return EOK;
-}
-
-int nildummy_device_message(device_id_t device_id, services_t service, size_t mtu){
+	
+	return EOK;
+}
+
+/** Process IPC messages from the registered device driver modules in an infinite loop.
+ *
+ * @param[in]     iid   The message identifier.
+ * @param[in,out] icall The message parameters.
+ *
+ */
+static void nildummy_receiver(ipc_callid_t iid, ipc_call_t * icall){
+	ERROR_DECLARE;
+
+	packet_t packet;
+
+	while(true){
+		switch(IPC_GET_METHOD(*icall)){
+			case NET_NIL_DEVICE_STATE:
+				ERROR_CODE = nil_device_state_msg_local(0, IPC_GET_DEVICE(icall), IPC_GET_STATE(icall));
+				ipc_answer_0(iid, (ipcarg_t) ERROR_CODE);
+				break;
+			case NET_NIL_RECEIVED:
+				if(! ERROR_OCCURRED(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) ERROR_CODE);
+				break;
+			default:
+				ipc_answer_0(iid, (ipcarg_t) ENOTSUP);
+		}
+		iid = async_get_call(icall);
+	}
+}
+
+/** Register new device or updates the MTU of an existing one.
+ *
+ * Determine the device local hardware address.
+ *
+ * @param[in] device_id The new device identifier.
+ * @param[in] service   The device driver service.
+ * @param[in] mtu       The device maximum transmission unit.
+ *
+ * @returns EOK on success.
+ * @returns EEXIST if the device with the different service exists.
+ * @returns ENOMEM if there is not enough memory left.
+ * @returns Other error codes as defined for the netif_bind_service() function.
+ * @returns Other error codes as defined for the netif_get_addr_req() function.
+ *
+ */
+static int nildummy_device_message(device_id_t device_id, services_t service,
+    size_t mtu)
+{
 	ERROR_DECLARE;
 
@@ -227,5 +220,6 @@
 			return index;
 		}
-		printf("New device registered:\n\tid\t= %d\n\tservice\t= %d\n\tMTU\t= %d\n", device->device_id, device->service, device->mtu);
+		printf("%s: Device registered (id: %d, service: %d, mtu: %d)\n",
+		    NAME, device->device_id, device->service, device->mtu);
 	}
 	fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
@@ -233,5 +227,17 @@
 }
 
-int nildummy_addr_message(device_id_t device_id, measured_string_ref * address){
+/** Return the device hardware address.
+ *
+ * @param[in]  device_id The device identifier.
+ * @param[out] address   The device hardware address.
+ *
+ * @return EOK on success.
+ * @return EBADMEM if the address parameter is NULL.
+ * @return ENOENT if there no such device.
+ *
+ */
+static int nildummy_addr_message(device_id_t device_id,
+    measured_string_ref *address)
+{
 	nildummy_device_ref device;
 
@@ -250,5 +256,20 @@
 }
 
-int nildummy_packet_space_message(device_id_t device_id, size_t * addr_len, size_t * prefix, size_t * content, size_t * suffix){
+/** Return the device packet dimensions for sending.
+ *
+ * @param[in]  device_id The device identifier.
+ * @param[out] addr_len  The minimum reserved address length.
+ * @param[out] prefix    The minimum reserved prefix size.
+ * @param[out] content   The maximum content size.
+ * @param[out] suffix    The minimum reserved suffix size.
+ *
+ * @return EOK on success.
+ * @return EBADMEM if either one of the parameters is NULL.
+ * @return ENOENT if there is no such device.
+ *
+ */
+static int nildummy_packet_space_message(device_id_t device_id,
+    size_t *addr_len, size_t *prefix, size_t *content, size_t *suffix)
+{
 	nildummy_device_ref device;
 
@@ -270,5 +291,5 @@
 }
 
-int nil_received_msg(int nil_phone, device_id_t device_id, packet_t packet, services_t target){
+int nil_received_msg_local(int nil_phone, device_id_t device_id, packet_t packet, services_t target){
 	packet_t next;
 
@@ -285,14 +306,43 @@
 }
 
-int nildummy_register_message(services_t service, int phone){
+/** Register receiving module service.
+ *
+ * Pass received packets for this service.
+ *
+ * @param[in] service The module service.
+ * @param[in] phone   The service phone.
+ *
+ * @return EOK on success.
+ * @return ENOENT if the service is not known.
+ * @return ENOMEM if there is not enough memory left.
+ *
+ */
+static int nildummy_register_message(services_t service, int phone)
+{
 	fibril_rwlock_write_lock(&nildummy_globals.protos_lock);
 	nildummy_globals.proto.service = service;
 	nildummy_globals.proto.phone = phone;
-	printf("New protocol registered:\n\tservice\t= %d\n\tphone\t= %d\n", nildummy_globals.proto.service, nildummy_globals.proto.phone);
+	
+	printf("%s: Protocol registered (service: %d, phone: %d)\n",
+	    NAME, nildummy_globals.proto.service, nildummy_globals.proto.phone);
+	
 	fibril_rwlock_write_unlock(&nildummy_globals.protos_lock);
 	return EOK;
 }
 
-int nildummy_send_message(device_id_t device_id, packet_t packet, services_t sender){
+/** Send the packet queue.
+ *
+ * @param[in] device_id The device identifier.
+ * @param[in] packet    The packet queue.
+ * @param[in] sender    The sending module service.
+ *
+ * @return EOK on success.
+ * @return ENOENT if there no such device.
+ * @return EINVAL if the service parameter is not known.
+ *
+ */
+static int nildummy_send_message(device_id_t device_id, packet_t packet,
+    services_t sender)
+{
 	nildummy_device_ref device;
 
@@ -311,57 +361,105 @@
 }
 
-int nil_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+int nil_message_standalone(const char *name, ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, int *answer_count)
+{
 	ERROR_DECLARE;
-
+	
 	measured_string_ref address;
 	packet_t packet;
-
-//	printf("message %d - %d\n", IPC_GET_METHOD(*call), NET_NIL_FIRST);
+	size_t addrlen;
+	size_t prefix;
+	size_t suffix;
+	size_t content;
+	
 	*answer_count = 0;
-	switch(IPC_GET_METHOD(*call)){
+	switch (IPC_GET_METHOD(*call)) {
 		case IPC_M_PHONE_HUNGUP:
 			return EOK;
 		case NET_NIL_DEVICE:
-			return nildummy_device_message(IPC_GET_DEVICE(call), IPC_GET_SERVICE(call), IPC_GET_MTU(call));
+			return nildummy_device_message(IPC_GET_DEVICE(call),
+			    IPC_GET_SERVICE(call), IPC_GET_MTU(call));
 		case NET_NIL_SEND:
-			ERROR_PROPAGATE(packet_translate(nildummy_globals.net_phone, &packet, IPC_GET_PACKET(call)));
-			return nildummy_send_message(IPC_GET_DEVICE(call), packet, IPC_GET_SERVICE(call));
+			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:
-			ERROR_PROPAGATE(nildummy_packet_space_message(IPC_GET_DEVICE(call), IPC_SET_ADDR(answer), IPC_SET_PREFIX(answer), IPC_SET_CONTENT(answer), IPC_SET_SUFFIX(answer)));
+			ERROR_PROPAGATE(nildummy_packet_space_message(IPC_GET_DEVICE(call),
+			    &addrlen, &prefix, &content, &suffix));
+			IPC_SET_ADDR(answer, addrlen);
+			IPC_SET_PREFIX(answer, prefix);
+			IPC_SET_CONTENT(answer, content);
+			IPC_SET_SUFFIX(answer, suffix);
 			*answer_count = 4;
 			return EOK;
 		case NET_NIL_ADDR:
-			ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call), &address));
+			ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call),
+			    &address));
+			return measured_strings_reply(address, 1);
+		case NET_NIL_BROADCAST_ADDR:
+			ERROR_PROPAGATE(nildummy_addr_message(IPC_GET_DEVICE(call),
+			    &address));
 			return measured_strings_reply(address, 1);
 		case IPC_M_CONNECT_TO_ME:
-			return nildummy_register_message(NIL_GET_PROTO(call), IPC_GET_PHONE(call));
-	}
+			return nildummy_register_message(NIL_GET_PROTO(call),
+			    IPC_GET_PHONE(call));
+	}
+	
 	return ENOTSUP;
 }
 
-void nildummy_receiver(ipc_callid_t iid, ipc_call_t * icall){
+#ifndef CONFIG_NETIF_NIL_BUNDLE
+
+/** Default thread for new connections.
+ *
+ * @param[in] iid   The initial message identifier.
+ * @param[in] icall The initial message call structure.
+ *
+ */
+static void nil_client_connection(ipc_callid_t iid, ipc_call_t *icall)
+{
+	/*
+	 * Accept the connection
+	 *  - Answer the first IPC_M_CONNECT_ME_TO call.
+	 */
+	ipc_answer_0(iid, EOK);
+	
+	while(true) {
+		ipc_call_t answer;
+		int answer_count;
+		
+		/* Clear the answer structure */
+		refresh_answer(&answer, &answer_count);
+		
+		/* Fetch the next message */
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		/* Process the message */
+		int res = nil_module_message_standalone(NAME, callid, &call, &answer,
+		    &answer_count);
+		
+		/* End if said to either by the message or the processing result */
+		if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
+			return;
+		
+		/* Answer the message */
+		answer_call(callid, res, &answer, answer_count);
+	}
+}
+
+int main(int argc, char *argv[])
+{
 	ERROR_DECLARE;
-
-	packet_t packet;
-
-	while(true){
-//		printf("message %d - %d\n", IPC_GET_METHOD(*icall), NET_NIL_FIRST);
-		switch(IPC_GET_METHOD(*icall)){
-			case NET_NIL_DEVICE_STATE:
-				ERROR_CODE = nil_device_state_msg(0, IPC_GET_DEVICE(icall), IPC_GET_STATE(icall));
-				ipc_answer_0(iid, (ipcarg_t) ERROR_CODE);
-				break;
-			case NET_NIL_RECEIVED:
-				if(! ERROR_OCCURRED(packet_translate(nildummy_globals.net_phone, &packet, IPC_GET_PACKET(icall)))){
-					ERROR_CODE = nil_received_msg(0, IPC_GET_DEVICE(icall), packet, 0);
-				}
-				ipc_answer_0(iid, (ipcarg_t) ERROR_CODE);
-				break;
-			default:
-				ipc_answer_0(iid, (ipcarg_t) ENOTSUP);
-		}
-		iid = async_get_call(icall);
-	}
-}
+	
+	/* Start the module */
+	if (ERROR_OCCURRED(nil_module_start_standalone(nil_client_connection)))
+		return ERROR_CODE;
+	
+	return EOK;
+}
+
+#endif /* CONFIG_NETIF_NIL_BUNDLE */
 
 /** @}
Index: uspace/srv/net/nil/nildummy/nildummy.h
===================================================================
--- uspace/srv/net/nil/nildummy/nildummy.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/nil/nildummy/nildummy.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -41,6 +41,6 @@
 #include <ipc/services.h>
 
-#include "../../include/device.h"
-#include "../../structures/measured_strings.h"
+#include <net_device.h>
+#include <adt/measured_strings.h>
 
 /** Type definition of the dummy nil global data.
Index: uspace/srv/net/nil/nildummy/nildummy_module.c
===================================================================
--- uspace/srv/net/nil/nildummy/nildummy_module.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/nil/nildummy/nildummy_module.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -42,71 +42,68 @@
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../modules.h"
-
-#include "../../include/net_interface.h"
-
-#include "../../structures/packet/packet.h"
-
-#include "../nil_module.h"
+#include <net_err.h>
+#include <net_modules.h>
+#include <net_interface.h>
+#include <packet/packet.h>
+#include <nil_local.h>
 
 #include "nildummy.h"
 
-/** The module name.
+/** Start the dummy nil module.
+ *
+ * Initialize the client connection serving function, initialize
+ * the module, register the module service and start the async
+ * manager, processing IPC messages in an infinite loop.
+ *
+ * @param[in] client_connection The client connection processing
+ *                              function. The module skeleton propagates
+ *                              its own one.
+ *
+ * @return EOK on success.
+ * @return Other error codes as defined for the pm_init() function.
+ * @return Other error codes as defined for the nil_initialize() function.
+ * @return Other error codes as defined for the REGISTER_ME() macro function.
+ *
  */
-#define NAME	"Dummy nil protocol"
-
-/** Prints the module name.
- */
-void module_print_name(void);
-
-/** Starts the dummy nil module.
- *  Initializes the client connection serving function, initializes the module, registers the module service and starts the async manager, processing IPC messages in an infinite loop.
- *  @param[in] client_connection The client connection processing function. The module skeleton propagates its own one.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the pm_init() function.
- *  @returns Other error codes as defined for the nil_initialize() function.
- *  @returns Other error codes as defined for the REGISTER_ME() macro function.
- */
-int module_start(async_client_conn_t client_connection);
-
-/** Passes the parameters to the module specific nil_message() function.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOTSUP if the message is not known.
- *  @returns Other error codes as defined for each specific module message function.
- */
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-void module_print_name(void){
-	printf("%s", NAME);
-}
-
-int module_start(async_client_conn_t client_connection){
+int nil_module_start_standalone(async_client_conn_t client_connection)
+{
 	ERROR_DECLARE;
-
+	
+	async_set_client_connection(client_connection);
+	int net_phone = net_connect_module(SERVICE_NETWORKING);
+	ERROR_PROPAGATE(pm_init());
+	
 	ipcarg_t phonehash;
-	int net_phone;
-
-	async_set_client_connection(client_connection);
-	net_phone = net_connect_module(SERVICE_NETWORKING);
-	ERROR_PROPAGATE(pm_init());
-	if(ERROR_OCCURRED(nil_initialize(net_phone))
-		|| ERROR_OCCURRED(REGISTER_ME(SERVICE_NILDUMMY, &phonehash))){
+	if (ERROR_OCCURRED(nil_initialize(net_phone))
+	    || ERROR_OCCURRED(REGISTER_ME(SERVICE_NILDUMMY, &phonehash))){
 		pm_destroy();
 		return ERROR_CODE;
 	}
-
+	
 	async_manager();
-
+	
 	pm_destroy();
 	return EOK;
 }
 
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	return nil_message(callid, call, answer, answer_count);
+/** Pass the parameters to the module specific nil_message() function.
+ *
+ * @param[in]  name         Module name.
+ * @param[in]  callid       The message identifier.
+ * @param[in]  call         The message parameters.
+ * @param[out] answer       The message answer parameters.
+ * @param[out] answer_count The last parameter for the actual answer
+ *                          in the answer parameter.
+ *
+ * @return EOK on success.
+ * @return ENOTSUP if the message is not known.
+ * @return Other error codes as defined for each specific
+ *          module message function.
+ *
+ */
+int nil_module_message_standalone(const char *name, ipc_callid_t callid,
+    ipc_call_t *call, ipc_call_t *answer, int *answer_count)
+{
+	return nil_message_standalone(name, callid, call, answer, answer_count);
 }
 
Index: pace/srv/net/self_test.c
===================================================================
--- uspace/srv/net/self_test.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,400 +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 net
- *  @{
- */
-
-/** @file
- *  Self tests implementation.
- */
-
-#include "configuration.h"
-
-#if NET_SELF_TEST
-
-#include <errno.h>
-#include <malloc.h>
-#include <stdio.h>
-
-#include "include/checksum.h"
-#include "structures/int_map.h"
-#include "structures/char_map.h"
-#include "structures/generic_char_map.h"
-#include "structures/measured_strings.h"
-#include "structures/dynamic_fifo.h"
-
-#include "self_test.h"
-
-/** Tests the function, compares the result and remembers if the result differs.
- *  @param[in] name The test name.
- *  @param[in] function_call The function to be called and checked.
- *  @param[in] result The expected result.
- */
-#define TEST(name, function_call, result);	{								\
-	printf("\n\t%s", (name)); 												\
-	if((function_call) != (result)){										\
-		printf("\tERROR\n");												\
-		error = 1;															\
-	}else{																	\
-		printf("\tOK\n");													\
-	}																		\
-}
-
-#if NET_SELF_TEST_GENERIC_CHAR_MAP
-
-	GENERIC_CHAR_MAP_DECLARE(int_char_map, int)
-
-	GENERIC_CHAR_MAP_IMPLEMENT(int_char_map, int)
-
-#endif
-
-#if NET_SELF_TEST_GENERIC_FIELD
-
-	GENERIC_FIELD_DECLARE(int_field, int)
-
-	GENERIC_FIELD_IMPLEMENT(int_field, int)
-
-#endif
-
-#if NET_SELF_TEST_INT_MAP
-
-	INT_MAP_DECLARE(int_map, int);
-
-	INT_MAP_IMPLEMENT(int_map, int);
-
-#endif
-
-int self_test(void){
-	int error;
-	int * x;
-	int * y;
-	int * z;
-	int * u;
-	int * v;
-	int * w;
-
-	error = 0;
-
-#if NET_SELF_TEST_CHAR_MAP
-	char_map_t cm;
-
-	printf("\nChar map test");
-	TEST("update ucho 3 einval", char_map_update(&cm, "ucho", 0, 3), EINVAL);
-	TEST("initialize", char_map_initialize(&cm), EOK);
-	TEST("exclude bla null", char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST("find bla null", char_map_find(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST("add bla 1 eok", char_map_add(&cm, "bla", 0, 1), EOK);
-	TEST("find bla 1", char_map_find(&cm, "bla", 0), 1);
-	TEST("add bla 10 eexists", char_map_add(&cm, "bla", 0, 10), EEXISTS);
-	TEST("update bla 2 eok", char_map_update(&cm, "bla", 0, 2), EOK);
-	TEST("find bla 2", char_map_find(&cm, "bla", 0), 2);
-	TEST("update ucho 2 eok", char_map_update(&cm, "ucho", 0, 2), EOK);
-	TEST("exclude bla 2", char_map_exclude(&cm, "bla", 0), 2);
-	TEST("exclude bla null", char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST("find ucho 2", char_map_find(&cm, "ucho", 0), 2);
-	TEST("update ucho 3 eok", char_map_update(&cm, "ucho", 0, 3), EOK);
-	TEST("find ucho 3", char_map_find(&cm, "ucho", 0), 3);
-	TEST("add blabla 5 eok", char_map_add(&cm, "blabla", 0, 5), EOK);
-	TEST("find blabla 5", char_map_find(&cm, "blabla", 0), 5);
-	TEST("add bla 6 eok", char_map_add(&cm, "bla", 0, 6), EOK);
-	TEST("find bla 6", char_map_find(&cm, "bla", 0), 6);
-	TEST("exclude bla 6", char_map_exclude(&cm, "bla", 0), 6);
-	TEST("find bla null", char_map_find(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST("find blabla 5", char_map_find(&cm, "blabla", 0), 5);
-	TEST("add auto 7 eok", char_map_add(&cm, "auto", 0, 7), EOK);
-	TEST("find auto 7", char_map_find(&cm, "auto", 0), 7);
-	TEST("add kara 8 eok", char_map_add(&cm, "kara", 0, 8), EOK);
-	TEST("find kara 8", char_map_find(&cm, "kara", 0), 8);
-	TEST("add nic 9 eok", char_map_add(&cm, "nic", 0, 9), EOK);
-	TEST("find nic 9", char_map_find(&cm, "nic", 0), 9);
-	TEST("find blabla 5", char_map_find(&cm, "blabla", 0), 5);
-	TEST("add micnicnic 5 9 eok", char_map_add(&cm, "micnicnic", 5, 9), EOK);
-	TEST("find micni 9", char_map_find(&cm, "micni", 0), 9);
-	TEST("find micnicn 5 9", char_map_find(&cm, "micnicn", 5), 9);
-	TEST("add 10.0.2.2 4 15 eok", char_map_add(&cm, "\x10\x0\x2\x2", 4, 15), EOK);
-	TEST("find 10.0.2.2 4 15", char_map_find(&cm, "\x10\x0\x2\x2", 4), 15);
-	printf("\n\tdestroy");
-	char_map_destroy(&cm);
-	TEST("update ucho 3 einval", char_map_update(&cm, "ucho", 0, 3), EINVAL);
-	printf("\nOK");
-
-	if(error){
-		return EINVAL;
-	}
-
-#endif
-
-#if NET_SELF_TEST_CRC
-	uint32_t value;
-
-	printf("\nCRC computation test");
-	value = ~ compute_crc32(~ 0, "123456789", 8 * 9);
-	TEST("123456789", value, 0xCBF43926);
-	printf("\t=> %X", value);
-	value = ~ compute_crc32(~ 0, "1", 8);
-	TEST("1", value, 0x83DCEFB7);
-	printf("\t=> %X", value);
-	value = ~ compute_crc32(~ 0, "12", 8 * 2);
-	TEST("12", value, 0x4F5344CD);
-	printf("\t=> %X", value);
-	value = ~ compute_crc32(~ 0, "123", 8 * 3);
-	TEST("123", value, 0x884863D2);
-	printf("\t=> %X", value);
-	value = ~ compute_crc32(~ 0, "1234", 8 * 4);
-	TEST("1234", value, 0x9BE3E0A3);
-	printf("\t=> %X", value);
-	value = ~ compute_crc32(~ 0, "12345678", 8 * 8);
-	TEST("12345678", value, 0x9AE0DAAF);
-	printf("\t=> %X", value);
-	value = ~ compute_crc32(~ 0, "ahoj pane", 8 * 9);
-	TEST("ahoj pane", value, 0x5FC3D706);
-	printf("\t=> %X", value);
-
-	if(error){
-		return EINVAL;
-	}
-
-#endif
-
-#if NET_SELF_TEST_DYNAMIC_FIFO
-	dyn_fifo_t fifo;
-
-	printf("\nDynamic fifo test");
-	TEST("add 1 einval", dyn_fifo_push(&fifo, 1, 0), EINVAL);
-	TEST("initialize", dyn_fifo_initialize(&fifo, 1), EOK);
-	TEST("add 1 eok", dyn_fifo_push(&fifo, 1, 0), EOK);
-	TEST("pop 1", dyn_fifo_pop(&fifo), 1);
-	TEST("pop enoent", dyn_fifo_pop(&fifo), ENOENT);
-	TEST("add 2 eok", dyn_fifo_push(&fifo, 2, 1), EOK);
-	TEST("add 3 enomem", dyn_fifo_push(&fifo, 3, 1), ENOMEM);
-	TEST("add 3 eok", dyn_fifo_push(&fifo, 3, 0), EOK);
-	TEST("pop 2", dyn_fifo_pop(&fifo), 2);
-	TEST("pop 3", dyn_fifo_pop(&fifo), 3);
-	TEST("add 4 eok", dyn_fifo_push(&fifo, 4, 2), EOK);
-	TEST("add 5 eok", dyn_fifo_push(&fifo, 5, 2), EOK);
-	TEST("add 6 enomem", dyn_fifo_push(&fifo, 6, 2), ENOMEM);
-	TEST("add 6 eok", dyn_fifo_push(&fifo, 6, 5), EOK);
-	TEST("add 7 eok", dyn_fifo_push(&fifo, 7, 5), EOK);
-	TEST("pop 4", dyn_fifo_pop(&fifo), 4);
-	TEST("pop 5", dyn_fifo_pop(&fifo), 5);
-	TEST("add 8 eok", dyn_fifo_push(&fifo, 8, 5), EOK);
-	TEST("add 9 eok", dyn_fifo_push(&fifo, 9, 5), EOK);
-	TEST("add 10 eok", dyn_fifo_push(&fifo, 10, 6), EOK);
-	TEST("add 11 eok", dyn_fifo_push(&fifo, 11, 6), EOK);
-	TEST("pop 6", dyn_fifo_pop(&fifo), 6);
-	TEST("pop 7", dyn_fifo_pop(&fifo), 7);
-	TEST("add 12 eok", dyn_fifo_push(&fifo, 12, 6), EOK);
-	TEST("add 13 eok", dyn_fifo_push(&fifo, 13, 6), EOK);
-	TEST("add 14 enomem", dyn_fifo_push(&fifo, 14, 6), ENOMEM);
-	TEST("add 14 eok", dyn_fifo_push(&fifo, 14, 8), EOK);
-	TEST("pop 8", dyn_fifo_pop(&fifo), 8);
-	TEST("pop 9", dyn_fifo_pop(&fifo), 9);
-	TEST("pop 10", dyn_fifo_pop(&fifo), 10);
-	TEST("pop 11", dyn_fifo_pop(&fifo), 11);
-	TEST("pop 12", dyn_fifo_pop(&fifo), 12);
-	TEST("pop 13", dyn_fifo_pop(&fifo), 13);
-	TEST("pop 14", dyn_fifo_pop(&fifo), 14);
-	TEST("destroy", dyn_fifo_destroy(&fifo), EOK);
-	TEST("add 15 einval", dyn_fifo_push(&fifo, 1, 0), EINVAL);
-	if(error){
-		return EINVAL;
-	}
-
-#endif
-
-#if NET_SELF_TEST_GENERIC_CHAR_MAP
-	int_char_map_t icm;
-
-	x = (int *) malloc(sizeof(int));
-	y = (int *) malloc(sizeof(int));
-	z = (int *) malloc(sizeof(int));
-	u = (int *) malloc(sizeof(int));
-	v = (int *) malloc(sizeof(int));
-	w = (int *) malloc(sizeof(int));
-
-	icm.magic = 0;
-	printf("\nGeneric char map test");
-	TEST("add ucho z einval", int_char_map_add(&icm, "ucho", 0, z), EINVAL);
-	TEST("initialize", int_char_map_initialize(&icm), EOK);
-	printf("\n\texclude bla null");
-	int_char_map_exclude(&icm, "bla", 0);
-	TEST("find bla null", int_char_map_find(&icm, "bla", 0), NULL);
-	TEST("add bla x eok", int_char_map_add(&icm, "bla", 0, x), EOK);
-	TEST("find bla x", int_char_map_find(&icm, "bla", 0), x);
-	TEST("add bla y eexists", int_char_map_add(&icm, "bla", 0, y), EEXISTS);
-	printf("\n\texclude bla y");
-	int_char_map_exclude(&icm, "bla", 0);
-	printf("\n\texclude bla null");
-	int_char_map_exclude(&icm, "bla", 0);
-	TEST("add blabla v eok", int_char_map_add(&icm, "blabla", 0, v), EOK);
-	TEST("find blabla v", int_char_map_find(&icm, "blabla", 0), v);
-	TEST("add bla w eok", int_char_map_add(&icm, "bla", 0, w), EOK);
-	TEST("find bla w", int_char_map_find(&icm, "bla", 0), w);
-	printf("\n\texclude bla");
-	int_char_map_exclude(&icm, "bla", 0);
-	TEST("find bla null", int_char_map_find(&icm, "bla", 0), NULL);
-	TEST("find blabla v", int_char_map_find(&icm, "blabla", 0), v);
-	TEST("add auto u eok", int_char_map_add(&icm, "auto", 0, u), EOK);
-	TEST("find auto u", int_char_map_find(&icm, "auto", 0), u);
-	printf("\n\tdestroy");
-	int_char_map_destroy(&icm);
-	TEST("add ucho z einval", int_char_map_add(&icm, "ucho", 0, z), EINVAL);
-	printf("\nOK");
-
-	if(error){
-		return EINVAL;
-	}
-
-#endif
-
-#if NET_SELF_TEST_GENERIC_FIELD
-	int_field_t gf;
-
-	x = (int *) malloc(sizeof(int));
-	y = (int *) malloc(sizeof(int));
-	z = (int *) malloc(sizeof(int));
-	u = (int *) malloc(sizeof(int));
-	v = (int *) malloc(sizeof(int));
-	w = (int *) malloc(sizeof(int));
-
-	gf.magic = 0;
-	printf("\nGeneric field test");
-	TEST("add x einval", int_field_add(&gf, x), EINVAL);
-	TEST("count -1", int_field_count(&gf), -1);
-	TEST("initialize", int_field_initialize(&gf), EOK);
-	TEST("count 0", int_field_count(&gf), 0);
-	TEST("get 1 null", int_field_get_index(&gf, 1), NULL);
-	TEST("add x 0", int_field_add(&gf, x), 0);
-	TEST("get 0 x", int_field_get_index(&gf, 0), x);
-	int_field_exclude_index(&gf, 0);
-	TEST("get 0 null", int_field_get_index(&gf, 0), NULL);
-	TEST("add y 1", int_field_add(&gf, y), 1);
-	TEST("get 1 y", int_field_get_index(&gf, 1), y);
-	TEST("add z 2", int_field_add(&gf, z), 2);
-	TEST("get 2 z", int_field_get_index(&gf, 2), z);
-	TEST("get 1 y", int_field_get_index(&gf, 1), y);
-	TEST("count 3", int_field_count(&gf), 3);
-	TEST("add u 3", int_field_add(&gf, u), 3);
-	TEST("get 3 u", int_field_get_index(&gf, 3), u);
-	TEST("add v 4", int_field_add(&gf, v), 4);
-	TEST("get 4 v", int_field_get_index(&gf, 4), v);
-	TEST("add w 5", int_field_add(&gf, w), 5);
-	TEST("get 5 w", int_field_get_index(&gf, 5), w);
-	TEST("count 6", int_field_count(&gf), 6);
-	int_field_exclude_index(&gf, 1);
-	TEST("get 1 null", int_field_get_index(&gf, 1), NULL);
-	TEST("get 3 u", int_field_get_index(&gf, 3), u);
-	int_field_exclude_index(&gf, 7);
-	TEST("get 3 u", int_field_get_index(&gf, 3), u);
-	TEST("get 5 w", int_field_get_index(&gf, 5), w);
-	int_field_exclude_index(&gf, 4);
-	TEST("get 4 null", int_field_get_index(&gf, 4), NULL);
-	printf("\n\tdestroy");
-	int_field_destroy(&gf);
-	TEST("count -1", int_field_count(&gf), -1);
-	printf("\nOK");
-
-	if(error){
-		return EINVAL;
-	}
-
-#endif
-
-#if NET_SELF_TEST_INT_MAP
-	int_map_t im;
-
-	x = (int *) malloc(sizeof(int));
-	y = (int *) malloc(sizeof(int));
-	z = (int *) malloc(sizeof(int));
-	u = (int *) malloc(sizeof(int));
-	v = (int *) malloc(sizeof(int));
-	w = (int *) malloc(sizeof(int));
-
-	im.magic = 0;
-	printf("\nInt map test");
-	TEST("add 1 x einval", int_map_add(&im, 1, x), EINVAL);
-	TEST("count -1", int_map_count(&im), -1);
-	TEST("initialize", int_map_initialize(&im), EOK);
-	TEST("count 0", int_map_count(&im), 0);
-	TEST("find 1 null", int_map_find(&im, 1), NULL);
-	TEST("add 1 x 0", int_map_add(&im, 1, x), 0);
-	TEST("find 1 x", int_map_find(&im, 1), x);
-	int_map_exclude(&im, 1);
-	TEST("find 1 null", int_map_find(&im, 1), NULL);
-	TEST("add 1 y 1", int_map_add(&im, 1, y), 1);
-	TEST("find 1 y", int_map_find(&im, 1), y);
-	TEST("add 4 z 2", int_map_add(&im, 4, z), 2);
-	TEST("get 2 z", int_map_get_index(&im, 2), z);
-	TEST("find 4 z", int_map_find(&im, 4), z);
-	TEST("find 1 y", int_map_find(&im, 1), y);
-	TEST("count 3", int_map_count(&im), 3);
-	TEST("add 2 u 3", int_map_add(&im, 2, u), 3);
-	TEST("find 2 u", int_map_find(&im, 2), u);
-	TEST("add 3 v 4", int_map_add(&im, 3, v), 4);
-	TEST("find 3 v", int_map_find(&im, 3), v);
-	TEST("get 4 v", int_map_get_index(&im, 4), v);
-	TEST("add 6 w 5", int_map_add(&im, 6, w), 5);
-	TEST("find 6 w", int_map_find(&im, 6), w);
-	TEST("count 6", int_map_count(&im), 6);
-	int_map_exclude(&im, 1);
-	TEST("find 1 null", int_map_find(&im, 1), NULL);
-	TEST("find 2 u", int_map_find(&im, 2), u);
-	int_map_exclude(&im, 7);
-	TEST("find 2 u", int_map_find(&im, 2), u);
-	TEST("find 6 w", int_map_find(&im, 6), w);
-	int_map_exclude_index(&im, 4);
-	TEST("get 4 null", int_map_get_index(&im, 4), NULL);
-	TEST("find 3 null", int_map_find(&im, 3), NULL);
-	printf("\n\tdestroy");
-	int_map_destroy(&im);
-	TEST("count -1", int_map_count(&im), -1);
-	printf("\nOK");
-
-	if(error){
-		return EINVAL;
-	}
-
-#endif
-
-#if NET_SELF_TEST_MEASURED_STRINGS
-	measured_string_ref string;
-
-	printf("\nMeasured strings test");
-	string = measured_string_create_bulk("I am a measured string!", 0);
-	printf("\n%x, %s at %x of %d", string, string->value, string->value, string->length);
-	printf("\nOK");
-#endif
-
-	return EOK;
-}
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/self_test.h
===================================================================
--- uspace/srv/net/self_test.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,64 +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 net
- *  @{
- */
-
-/** @file
- *  Self tests.
- *  @see configuration.h
- */
-
-#ifndef __SELF_TEST_H__
-#define __SELF_TEST_H__
-
-#include "configuration.h"
-
-/** Self test start function.
- *  Runs all the configured self tests.
- *  @see configuration.h
- *  @returns EOK on success.
- *  @returns The first error occurred.
- */
-#if NET_SELF_TEST
-
-int self_test(void);
-
-#else
-
-#include <errno.h>
-
-#define self_test()	EOK
-
-#endif
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/socket/Makefile
===================================================================
--- uspace/srv/net/socket/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,40 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# 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.
-#
-
-NET_BASE = ..
-USPACE_PREFIX = ../../..
-LIBRARY = libsocket
-
-SOURCES = \
-	socket_client.c \
-	$(NET_BASE)/inet.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/structures/dynamic_fifo.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: pace/srv/net/socket/socket_client.c
===================================================================
--- uspace/srv/net/socket/socket_client.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,901 +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 application program interface (API) implementation.
- *  @see socket.h for more information.
- *  This is a part of the network application library.
- */
-
-#include <assert.h>
-#include <async.h>
-#include <fibril_synch.h>
-#include <limits.h>
-#include <stdlib.h>
-
-#include <ipc/services.h>
-
-#include "../err.h"
-#include "../modules.h"
-
-#include "../include/in.h"
-#include "../include/socket.h"
-#include "../include/socket_errno.h"
-
-#include "../structures/dynamic_fifo.h"
-#include "../structures/int_map.h"
-
-#include "socket_messages.h"
-
-/** Initial received packet queue size.
- */
-#define SOCKET_INITIAL_RECEIVED_SIZE	4
-
-/** Maximum received packet queue size.
- */
-#define SOCKET_MAX_RECEIVED_SIZE		0
-
-/** Initial waiting sockets queue size.
- */
-#define SOCKET_INITIAL_ACCEPTED_SIZE	1
-
-/** Maximum waiting sockets queue size.
- */
-#define SOCKET_MAX_ACCEPTED_SIZE		0
-
-/** Default timeout for connections in microseconds.
- */
-#define SOCKET_CONNECT_TIMEOUT	(1 * 1000 * 1000)
-
-/** Maximum number of random attempts to find a new socket identifier before switching to the sequence.
- */
-#define SOCKET_ID_TRIES					100
-
-/** Type definition of the socket specific data.
- *  @see socket
- */
-typedef struct socket	socket_t;
-
-/** Type definition of the socket specific data pointer.
- *  @see socket
- */
-typedef socket_t *	socket_ref;
-
-/** Socket specific data.
- *  Each socket lock locks only its structure part and any number of them may be locked simultaneously.
- */
-struct socket{
-	/** Socket identifier.
-	 */
-	int socket_id;
-	/** Parent module phone.
-	 */
-	int phone;
-	/** Parent module service.
-	 */
-	services_t service;
-	/** Underlying protocol header size.
-	 *  Sending and receiving optimalization.
-	 */
-	size_t header_size;
-	/** Packet data fragment size.
-	 *  Sending optimalization.
-	 */
-	size_t data_fragment_size;
-	/** Sending safety lock.
-	 *  Locks the header_size and data_fragment_size attributes.
-	 */
-	fibril_rwlock_t sending_lock;
-	/** Received packets queue.
-	 */
-	dyn_fifo_t received;
-	/** Received packets safety lock.
-	 *  Used for receiving and receive notifications.
-	 *  Locks the received attribute.
-	 */
-	fibril_mutex_t receive_lock;
-	/** Received packets signaling.
-	 *  Signaled upon receive notification.
-	 */
-	fibril_condvar_t receive_signal;
-	/** Waiting sockets queue.
-	 */
-	dyn_fifo_t accepted;
-	/** Waiting sockets safety lock.
-	 *  Used for accepting and accept notifications.
-	 *  Locks the accepted attribute.
-	 */
-	fibril_mutex_t accept_lock;
-	/** Waiting sockets signaling.
-	 *  Signaled upon accept notification.
-	 */
-	fibril_condvar_t accept_signal;
-	/** The number of blocked functions called.
-	 *  Used while waiting for the received packets or accepted sockets.
-	 */
-	int blocked;
-};
-
-/** Sockets map.
- *  Maps socket identifiers to the socket specific data.
- *  @see int_map.h
- */
-INT_MAP_DECLARE(sockets, socket_t);
-
-/** Socket client library global data.
- */
-static struct socket_client_globals {
-	/** TCP module phone.
-	 */
-	int tcp_phone;
-	/** UDP module phone.
-	 */
-	int udp_phone;
-//	/** The last socket identifier.
-//	 */
-//	int last_id;
-	/** Active sockets.
-	 */
-	sockets_ref sockets;
-	/** Safety lock.
-	 *  Write lock is used only for adding or removing sockets.
-	 *  When locked for writing, no other socket locks need to be locked.
-	 *  When locked for reading, any other socket locks may be locked.
-	 *  No socket lock may be locked if this lock is unlocked.
-	 */
-	fibril_rwlock_t lock;
-} socket_globals = {
-	.tcp_phone = -1,
-	.udp_phone = -1,
-//	.last_id = 0,
-	.sockets = NULL,
-	.lock = {
-		.readers = 0,
-		.writers = 0,
-		.waiters = {
-			.prev = &socket_globals.lock.waiters,
-			.next = &socket_globals.lock.waiters
-		}
-	}
-};
-
-INT_MAP_IMPLEMENT(sockets, socket_t);
-
-/** Returns the TCP module phone.
- *  Connects to the TCP module if necessary.
- *  @returns The TCP module phone.
- *  @returns Other error codes as defined for the bind_service_timeout() function.
- */
-static int socket_get_tcp_phone(void);
-
-/** Returns the UDP module phone.
- *  Connects to the UDP module if necessary.
- *  @returns The UDP module phone.
- *  @returns Other error codes as defined for the bind_service_timeout() function.
- */
-static int socket_get_udp_phone(void);
-
-/** Returns the active sockets.
- *  @returns The active sockets.
- */
-static sockets_ref socket_get_sockets(void);
-
-/** Tries to find a new free socket identifier.
- *	@returns The new socket identifier.
- *  @returns ELIMIT if there is no socket identifier available.
- */
-static int socket_generate_new_id(void);
-
-/** Default thread for new connections.
- *  @param[in] iid The initial message identifier.
- *  @param[in] icall The initial message call structure.
- */
-void socket_connection(ipc_callid_t iid, ipc_call_t * icall);
-
-/** Sends message to the socket parent module with specified data.
- *  @param[in] socket_id Socket identifier.
- *  @param[in] message The action message.
- *  @param[in] arg2 The second message parameter.
- *  @param[in] data The data to be sent.
- *  @param[in] datalength The data length.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns EBADMEM if the data parameter is NULL.
- *  @returns NO_DATA if the datalength parameter is zero (0).
- *  @returns Other error codes as defined for the spcific message.
- */
-int socket_send_data(int socket_id, ipcarg_t message, ipcarg_t arg2, const void * data, size_t datalength);
-
-/** Initializes a new socket specific data.
- *  @param[in,out] socket The socket to be initialized.
- *  @param[in] socket_id The new socket identifier.
- *  @param[in] phone The parent module phone.
- *  @param[in] service The parent module service.
- */
-void socket_initialize(socket_ref socket, int socket_id, int phone, services_t service);
-
-/** Clears and destroys the socket.
- *  @param[in] socket The socket to be destroyed.
- */
-void socket_destroy(socket_ref socket);
-
-/** Receives data via the socket.
- *  @param[in] message The action message.
- *  @param[in] socket_id Socket identifier.
- *  @param[out] data The data buffer to be filled.
- *  @param[in] datalength The data length.
- *  @param[in] flags Various receive flags.
- *  @param[out] fromaddr The source address. May be NULL for connected sockets.
- *  @param[in,out] addrlen The address length. The maximum address length is read. The actual address length is set. Used only if fromaddr is not NULL.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns EBADMEM if the data parameter is NULL.
- *  @returns NO_DATA if the datalength or addrlen parameter is zero (0).
- *  @returns Other error codes as defined for the spcific message.
- */
-int recvfrom_core(ipcarg_t message, int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen);
-
-/** Sends data via the socket to the remote address.
- *  Binds the socket to a free port if not already connected/bound.
- *  @param[in] message The action message.
- *  @param[in] socket_id Socket identifier.
- *  @param[in] data The data to be sent.
- *  @param[in] datalength The data length.
- *  @param[in] flags Various send flags.
- *  @param[in] toaddr The destination address. May be NULL for connected sockets.
- *  @param[in] addrlen The address length. Used only if toaddr is not NULL.
- *  @returns EOK on success.
- *  @returns ENOTSOCK if the socket is not found.
- *  @returns EBADMEM if the data or toaddr parameter is NULL.
- *  @returns NO_DATA if the datalength or the addrlen parameter is zero (0).
- *  @returns Other error codes as defined for the NET_SOCKET_SENDTO message.
- */
-int sendto_core(ipcarg_t message, int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen);
-
-static int socket_get_tcp_phone(void){
-	if(socket_globals.tcp_phone < 0){
-		socket_globals.tcp_phone = bind_service_timeout(SERVICE_TCP, 0, 0, SERVICE_TCP, socket_connection, SOCKET_CONNECT_TIMEOUT);
-	}
-	return socket_globals.tcp_phone;
-}
-
-static int socket_get_udp_phone(void){
-	if(socket_globals.udp_phone < 0){
-		socket_globals.udp_phone = bind_service_timeout(SERVICE_UDP, 0, 0, SERVICE_UDP, socket_connection, SOCKET_CONNECT_TIMEOUT);
-	}
-	return socket_globals.udp_phone;
-}
-
-static sockets_ref socket_get_sockets(void){
-	if(! socket_globals.sockets){
-		socket_globals.sockets = (sockets_ref) malloc(sizeof(sockets_t));
-		if(! socket_globals.sockets){
-			return NULL;
-		}
-		if(sockets_initialize(socket_globals.sockets) != EOK){
-			free(socket_globals.sockets);
-			socket_globals.sockets = NULL;
-		}
-		srand(task_get_id());
-	}
-	return socket_globals.sockets;
-}
-
-static int socket_generate_new_id(void){
-	sockets_ref sockets;
-	int socket_id;
-	int count;
-
-	sockets = socket_get_sockets();
-	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(sockets_find(sockets, socket_id));
-//	last_id = socket_id
-	return socket_id;
-}
-
-void socket_initialize(socket_ref socket, int socket_id, int phone, services_t service){
-	socket->socket_id = socket_id;
-	socket->phone = phone;
-	socket->service = service;
-	dyn_fifo_initialize(&socket->received, SOCKET_INITIAL_RECEIVED_SIZE);
-	dyn_fifo_initialize(&socket->accepted, SOCKET_INITIAL_ACCEPTED_SIZE);
-	fibril_mutex_initialize(&socket->receive_lock);
-	fibril_condvar_initialize(&socket->receive_signal);
-	fibril_mutex_initialize(&socket->accept_lock);
-	fibril_condvar_initialize(&socket->accept_signal);
-	fibril_rwlock_initialize(&socket->sending_lock);
-}
-
-void socket_connection(ipc_callid_t iid, ipc_call_t * icall){
-	ERROR_DECLARE;
-
-	ipc_callid_t callid;
-	ipc_call_t call;
-	socket_ref socket;
-
-	while(true){
-
-		callid = async_get_call(&call);
-		switch(IPC_GET_METHOD(call)){
-			case NET_SOCKET_RECEIVED:
-			case NET_SOCKET_ACCEPTED:
-			case NET_SOCKET_DATA_FRAGMENT_SIZE:
-				fibril_rwlock_read_lock(&socket_globals.lock);
-				// find the socket
-				socket = sockets_find(socket_get_sockets(), SOCKET_GET_SOCKET_ID(call));
-				if(! socket){
-					ERROR_CODE = ENOTSOCK;
-				}else{
-					switch(IPC_GET_METHOD(call)){
-						case NET_SOCKET_RECEIVED:
-							fibril_mutex_lock(&socket->receive_lock);
-							// push the number of received packet fragments
-							if(! ERROR_OCCURRED(dyn_fifo_push(&socket->received, SOCKET_GET_DATA_FRAGMENTS(call), SOCKET_MAX_RECEIVED_SIZE))){
-								// signal the received packet
-								fibril_condvar_signal(&socket->receive_signal);
-							}
-							fibril_mutex_unlock(&socket->receive_lock);
-							break;
-						case NET_SOCKET_ACCEPTED:
-							// push the new socket identifier
-							fibril_mutex_lock(&socket->accept_lock);
-							if(! ERROR_OCCURRED(dyn_fifo_push(&socket->accepted, 1, SOCKET_MAX_ACCEPTED_SIZE))){
-								// signal the accepted socket
-								fibril_condvar_signal(&socket->accept_signal);
-							}
-							fibril_mutex_unlock(&socket->accept_lock);
-							break;
-						default:
-							ERROR_CODE = ENOTSUP;
-					}
-					if((SOCKET_GET_DATA_FRAGMENT_SIZE(call) > 0)
-						&& (SOCKET_GET_DATA_FRAGMENT_SIZE(call) != socket->data_fragment_size)){
-						fibril_rwlock_write_lock(&socket->sending_lock);
-						// set the data fragment size
-						socket->data_fragment_size = SOCKET_GET_DATA_FRAGMENT_SIZE(call);
-						fibril_rwlock_write_unlock(&socket->sending_lock);
-					}
-				}
-				fibril_rwlock_read_unlock(&socket_globals.lock);
-				break;
-			default:
-				ERROR_CODE = ENOTSUP;
-		}
-		ipc_answer_0(callid, (ipcarg_t) ERROR_CODE);
-	}
-}
-
-int socket(int domain, int type, int protocol){
-	ERROR_DECLARE;
-
-	socket_ref socket;
-	int phone;
-	int socket_id;
-	services_t service;
-
-	// find the appropriate service
-	switch(domain){
-		case PF_INET:
-			switch(type){
-				case SOCK_STREAM:
-					if(! protocol){
-						protocol = IPPROTO_TCP;
-					}
-					switch(protocol){
-						case IPPROTO_TCP:
-							phone = socket_get_tcp_phone();
-							service = SERVICE_TCP;
-							break;
-						default:
-							return EPROTONOSUPPORT;
-					}
-					break;
-				case SOCK_DGRAM:
-					if(! protocol){
-						protocol = IPPROTO_UDP;
-					}
-					switch(protocol){
-						case IPPROTO_UDP:
-							phone = socket_get_udp_phone();
-							service = SERVICE_UDP;
-							break;
-						default:
-							return EPROTONOSUPPORT;
-					}
-					break;
-				case SOCK_RAW:
-				default:
-					return ESOCKTNOSUPPORT;
-			}
-			break;
-		// TODO IPv6
-		default:
-			return EPFNOSUPPORT;
-	}
-	if(phone < 0){
-		return phone;
-	}
-	// create a new socket structure
-	socket = (socket_ref) malloc(sizeof(socket_t));
-	if(! socket){
-		return ENOMEM;
-	}
-	bzero(socket, sizeof(*socket));
-	fibril_rwlock_write_lock(&socket_globals.lock);
-	// request a new socket
-	socket_id = socket_generate_new_id();
-	if(socket_id <= 0){
-		fibril_rwlock_write_unlock(&socket_globals.lock);
-		free(socket);
-		return socket_id;
-	}
-	if(ERROR_OCCURRED((int) async_req_3_3(phone, NET_SOCKET, socket_id, 0, service, NULL, (ipcarg_t *) &socket->data_fragment_size, (ipcarg_t *) &socket->header_size))){
-		fibril_rwlock_write_unlock(&socket_globals.lock);
-		free(socket);
-		return ERROR_CODE;
-	}
-	// finish the new socket initialization
-	socket_initialize(socket, socket_id, phone, service);
-	// store the new socket
-	ERROR_CODE = sockets_add(socket_get_sockets(), socket_id, socket);
-	fibril_rwlock_write_unlock(&socket_globals.lock);
-	if(ERROR_CODE < 0){
-		dyn_fifo_destroy(&socket->received);
-		dyn_fifo_destroy(&socket->accepted);
-		free(socket);
-		async_msg_3(phone, NET_SOCKET_CLOSE, (ipcarg_t) socket_id, 0, service);
-		return ERROR_CODE;
-	}
-
-	return socket_id;
-}
-
-int socket_send_data(int socket_id, ipcarg_t message, ipcarg_t arg2, const void * data, size_t datalength){
-	socket_ref socket;
-	aid_t message_id;
-	ipcarg_t result;
-
-	if(! data){
-		return EBADMEM;
-	}
-	if(! datalength){
-		return NO_DATA;
-	}
-
-	fibril_rwlock_read_lock(&socket_globals.lock);
-	// find the socket
-	socket = sockets_find(socket_get_sockets(), socket_id);
-	if(! socket){
-		fibril_rwlock_read_unlock(&socket_globals.lock);
-		return ENOTSOCK;
-	}
-	// request the message
-	message_id = async_send_3(socket->phone, message, (ipcarg_t) socket->socket_id, arg2, socket->service, NULL);
-	// send the address
-	async_data_write_start(socket->phone, data, datalength);
-	fibril_rwlock_read_unlock(&socket_globals.lock);
-	async_wait_for(message_id, &result);
-	return (int) result;
-}
-
-int bind(int socket_id, const struct sockaddr * my_addr, socklen_t addrlen){
-	if(addrlen <= 0){
-		return EINVAL;
-	}
-	// send the address
-	return socket_send_data(socket_id, NET_SOCKET_BIND, 0, my_addr, (size_t) addrlen);
-}
-
-int listen(int socket_id, int backlog){
-	socket_ref socket;
-	int result;
-
-	if(backlog <= 0){
-		return EINVAL;
-	}
-	fibril_rwlock_read_lock(&socket_globals.lock);
-	// find the socket
-	socket = sockets_find(socket_get_sockets(), socket_id);
-	if(! socket){
-		fibril_rwlock_read_unlock(&socket_globals.lock);
-		return ENOTSOCK;
-	}
-	// request listen backlog change
-	result = (int) async_req_3_0(socket->phone, NET_SOCKET_LISTEN, (ipcarg_t) socket->socket_id, (ipcarg_t) backlog, socket->service);
-	fibril_rwlock_read_unlock(&socket_globals.lock);
-	return result;
-}
-
-int accept(int socket_id, struct sockaddr * cliaddr, socklen_t * addrlen){
-	socket_ref socket;
-	socket_ref new_socket;
-	aid_t message_id;
-	ipcarg_t ipc_result;
-	int result;
-	ipc_call_t answer;
-
-	if((! cliaddr) || (! addrlen)){
-		return EBADMEM;
-	}
-
-	fibril_rwlock_write_lock(&socket_globals.lock);
-	// find the socket
-	socket = sockets_find(socket_get_sockets(), socket_id);
-	if(! socket){
-		fibril_rwlock_write_unlock(&socket_globals.lock);
-		return ENOTSOCK;
-	}
-	fibril_mutex_lock(&socket->accept_lock);
-	// wait for an accepted socket
-	++ socket->blocked;
-	while(dyn_fifo_value(&socket->accepted) <= 0){
-		fibril_rwlock_write_unlock(&socket_globals.lock);
-		fibril_condvar_wait(&socket->accept_signal, &socket->accept_lock);
-		// drop the accept lock to avoid deadlock
-		fibril_mutex_unlock(&socket->accept_lock);
-		fibril_rwlock_write_lock(&socket_globals.lock);
-		fibril_mutex_lock(&socket->accept_lock);
-	}
-	-- socket->blocked;
-
-	// create a new scoket
-	new_socket = (socket_ref) malloc(sizeof(socket_t));
-	if(! new_socket){
-		fibril_mutex_unlock(&socket->accept_lock);
-		fibril_rwlock_write_unlock(&socket_globals.lock);
-		return ENOMEM;
-	}
-	bzero(new_socket, sizeof(*new_socket));
-	socket_id = socket_generate_new_id();
-	if(socket_id <= 0){
-		fibril_mutex_unlock(&socket->accept_lock);
-		fibril_rwlock_write_unlock(&socket_globals.lock);
-		free(new_socket);
-		return socket_id;
-	}
-	socket_initialize(new_socket, socket_id, socket->phone, socket->service);
-	result = sockets_add(socket_get_sockets(), new_socket->socket_id, new_socket);
-	if(result < 0){
-		fibril_mutex_unlock(&socket->accept_lock);
-		fibril_rwlock_write_unlock(&socket_globals.lock);
-		free(new_socket);
-		return result;
-	}
-
-	// request accept
-	message_id = async_send_5(socket->phone, NET_SOCKET_ACCEPT, (ipcarg_t) socket->socket_id, 0, socket->service, 0, new_socket->socket_id, &answer);
-	// read address
-	ipc_data_read_start(socket->phone, cliaddr, * addrlen);
-	fibril_rwlock_write_unlock(&socket_globals.lock);
-	async_wait_for(message_id, &ipc_result);
-	result = (int) ipc_result;
-	if(result > 0){
-		if(result != socket_id){
-			result = EINVAL;
-		}
-		// dequeue the accepted socket if successful
-		dyn_fifo_pop(&socket->accepted);
-		// set address length
-		*addrlen = SOCKET_GET_ADDRESS_LENGTH(answer);
-		new_socket->data_fragment_size = SOCKET_GET_DATA_FRAGMENT_SIZE(answer);
-	}else if(result == ENOTSOCK){
-		// empty the queue if no accepted sockets
-		while(dyn_fifo_pop(&socket->accepted) > 0);
-	}
-	fibril_mutex_unlock(&socket->accept_lock);
-	return result;
-}
-
-int connect(int socket_id, const struct sockaddr * serv_addr, socklen_t addrlen){
-	if(! serv_addr){
-		return EDESTADDRREQ;
-	}
-	if(! addrlen){
-		return EDESTADDRREQ;
-	}
-	// send the address
-	return socket_send_data(socket_id, NET_SOCKET_CONNECT, 0, serv_addr, addrlen);
-}
-
-int closesocket(int socket_id){
-	ERROR_DECLARE;
-
-	socket_ref socket;
-
-	fibril_rwlock_write_lock(&socket_globals.lock);
-	socket = sockets_find(socket_get_sockets(), socket_id);
-	if(! socket){
-		fibril_rwlock_write_unlock(&socket_globals.lock);
-		return ENOTSOCK;
-	}
-	if(socket->blocked){
-		fibril_rwlock_write_unlock(&socket_globals.lock);
-		return EINPROGRESS;
-	}
-	// request close
-	ERROR_PROPAGATE((int) async_req_3_0(socket->phone, NET_SOCKET_CLOSE, (ipcarg_t) socket->socket_id, 0, socket->service));
-	// free the socket structure
-	socket_destroy(socket);
-	fibril_rwlock_write_unlock(&socket_globals.lock);
-	return EOK;
-}
-
-void socket_destroy(socket_ref socket){
-	int accepted_id;
-
-	// destroy all accepted sockets
-	while((accepted_id = dyn_fifo_pop(&socket->accepted)) >= 0){
-		socket_destroy(sockets_find(socket_get_sockets(), accepted_id));
-	}
-	dyn_fifo_destroy(&socket->received);
-	dyn_fifo_destroy(&socket->accepted);
-	sockets_exclude(socket_get_sockets(), socket->socket_id);
-}
-
-int send(int socket_id, void * data, size_t datalength, int flags){
-	// without the address
-	return sendto_core(NET_SOCKET_SEND, socket_id, data, datalength, flags, NULL, 0);
-}
-
-int sendto(int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen){
-	if(! toaddr){
-		return EDESTADDRREQ;
-	}
-	if(! addrlen){
-		return EDESTADDRREQ;
-	}
-	// with the address
-	return sendto_core(NET_SOCKET_SENDTO, socket_id, data, datalength, flags, toaddr, addrlen);
-}
-
-int sendto_core(ipcarg_t message, int socket_id, const void * data, size_t datalength, int flags, const struct sockaddr * toaddr, socklen_t addrlen){
-	socket_ref socket;
-	aid_t message_id;
-	ipcarg_t result;
-	size_t fragments;
-	ipc_call_t answer;
-
-	if(! data){
-		return EBADMEM;
-	}
-	if(! datalength){
-		return NO_DATA;
-	}
-	fibril_rwlock_read_lock(&socket_globals.lock);
-	// find socket
-	socket = sockets_find(socket_get_sockets(), socket_id);
-	if(! socket){
-		fibril_rwlock_read_unlock(&socket_globals.lock);
-		return ENOTSOCK;
-	}
-	fibril_rwlock_read_lock(&socket->sending_lock);
-	// compute data fragment count
-	if(socket->data_fragment_size > 0){
-		fragments = (datalength + socket->header_size) / socket->data_fragment_size;
-		if((datalength + socket->header_size) % socket->data_fragment_size) ++ fragments;
-	}else{
-		fragments = 1;
-	}
-	// request send
-	message_id = async_send_5(socket->phone, message, (ipcarg_t) socket->socket_id, (fragments == 1 ? datalength : socket->data_fragment_size), socket->service, (ipcarg_t) flags, fragments, &answer);
-	// send the address if given
-	if((! toaddr) || (async_data_write_start(socket->phone, toaddr, addrlen) == EOK)){
-		if(fragments == 1){
-			// send all if only one fragment
-			async_data_write_start(socket->phone, data, datalength);
-		}else{
-			// send the first fragment
-			async_data_write_start(socket->phone, data, socket->data_fragment_size - socket->header_size);
-			data = ((const uint8_t *) data) + socket->data_fragment_size - socket->header_size;
-			// send the middle fragments
-			while((-- fragments) > 1){
-				async_data_write_start(socket->phone, data, socket->data_fragment_size);
-				data = ((const uint8_t *) data) + socket->data_fragment_size;
-			}
-			// send the last fragment
-			async_data_write_start(socket->phone, data, (datalength + socket->header_size) % socket->data_fragment_size);
-		}
-	}
-	async_wait_for(message_id, &result);
-	if((SOCKET_GET_DATA_FRAGMENT_SIZE(answer) > 0)
-		&& (SOCKET_GET_DATA_FRAGMENT_SIZE(answer) != socket->data_fragment_size)){
-		// set the data fragment size
-		socket->data_fragment_size = SOCKET_GET_DATA_FRAGMENT_SIZE(answer);
-	}
-	fibril_rwlock_read_unlock(&socket->sending_lock);
-	fibril_rwlock_read_unlock(&socket_globals.lock);
-	return (int) result;
-}
-
-int recv(int socket_id, void * data, size_t datalength, int flags){
-	// without the address
-	return recvfrom_core(NET_SOCKET_RECV, socket_id, data, datalength, flags, NULL, NULL);
-}
-
-int recvfrom(int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen){
-	if(! fromaddr){
-		return EBADMEM;
-	}
-	if(! addrlen){
-		return NO_DATA;
-	}
-	// with the address
-	return recvfrom_core(NET_SOCKET_RECVFROM, socket_id, data, datalength, flags, fromaddr, addrlen);
-}
-
-int recvfrom_core(ipcarg_t message, int socket_id, void * data, size_t datalength, int flags, struct sockaddr * fromaddr, socklen_t * addrlen){
-	socket_ref socket;
-	aid_t message_id;
-	ipcarg_t ipc_result;
-	int result;
-	size_t fragments;
-	size_t * lengths;
-	size_t index;
-	ipc_call_t answer;
-
-	if(! data){
-		return EBADMEM;
-	}
-	if(! datalength){
-		return NO_DATA;
-	}
-	if(fromaddr && (! addrlen)){
-		return EINVAL;
-	}
-	fibril_rwlock_read_lock(&socket_globals.lock);
-	// find the socket
-	socket = sockets_find(socket_get_sockets(), socket_id);
-	if(! socket){
-		fibril_rwlock_read_unlock(&socket_globals.lock);
-		return ENOTSOCK;
-	}
-	fibril_mutex_lock(&socket->receive_lock);
-	// wait for a received packet
-	++ socket->blocked;
-	while((result = dyn_fifo_value(&socket->received)) <= 0){
-		fibril_rwlock_read_unlock(&socket_globals.lock);
-		fibril_condvar_wait(&socket->receive_signal, &socket->receive_lock);
-		// drop the receive lock to avoid deadlock
-		fibril_mutex_unlock(&socket->receive_lock);
-		fibril_rwlock_read_lock(&socket_globals.lock);
-		fibril_mutex_lock(&socket->receive_lock);
-	}
-	-- socket->blocked;
-	fragments = (size_t) result;
-	// prepare lengths if more fragments
-	if(fragments > 1){
-		lengths = (size_t *) malloc(sizeof(size_t) * fragments + sizeof(size_t));
-		if(! lengths){
-			fibril_mutex_unlock(&socket->receive_lock);
-			fibril_rwlock_read_unlock(&socket_globals.lock);
-			return ENOMEM;
-		}
-		// request packet data
-		message_id = async_send_4(socket->phone, message, (ipcarg_t) socket->socket_id, 0, socket->service, (ipcarg_t) flags, &answer);
-		// read the address if desired
-		if((! fromaddr) || (async_data_read_start(socket->phone, fromaddr, * addrlen) == EOK)){
-		// read the fragment lengths
-			if(async_data_read_start(socket->phone, lengths, sizeof(int) * (fragments + 1)) == EOK){
-				if(lengths[fragments] <= datalength){
-					// read all fragments if long enough
-					for(index = 0; index < fragments; ++ index){
-						async_data_read_start(socket->phone, data, lengths[index]);
-						data = ((uint8_t *) data) + lengths[index];
-					}
-				}
-			}
-		}
-		free(lengths);
-	}else{
-		// request packet data
-		message_id = async_send_4(socket->phone, message, (ipcarg_t) socket->socket_id, 0, socket->service, (ipcarg_t) flags, &answer);
-		// read the address if desired
-		if((! fromaddr) || (async_data_read_start(socket->phone, fromaddr, * addrlen) == EOK)){
-			// read all if only one fragment
-			async_data_read_start(socket->phone, data, datalength);
-		}
-	}
-	async_wait_for(message_id, &ipc_result);
-	result = (int) ipc_result;
-	// if successful
-	if(result == EOK){
-		// dequeue the received packet
-		dyn_fifo_pop(&socket->received);
-		// return read data length
-		result = SOCKET_GET_READ_DATA_LENGTH(answer);
-		// set address length
-		if(fromaddr && addrlen){
-			*addrlen = SOCKET_GET_ADDRESS_LENGTH(answer);
-		}
-	}
-	fibril_mutex_unlock(&socket->receive_lock);
-	fibril_rwlock_read_unlock(&socket_globals.lock);
-	return result;
-}
-
-int getsockopt(int socket_id, int level, int optname, void * value, size_t * optlen){
-	socket_ref socket;
-	aid_t message_id;
-	ipcarg_t result;
-
-	if(!(value && optlen)){
-		return EBADMEM;
-	}
-	if(!(*optlen)){
-		return NO_DATA;
-	}
-	fibril_rwlock_read_lock(&socket_globals.lock);
-	// find the socket
-	socket = sockets_find(socket_get_sockets(), socket_id);
-	if(! socket){
-		fibril_rwlock_read_unlock(&socket_globals.lock);
-		return ENOTSOCK;
-	}
-	// request option value
-	message_id = async_send_3(socket->phone, NET_SOCKET_GETSOCKOPT, (ipcarg_t) socket->socket_id, (ipcarg_t) optname, socket->service, NULL);
-	// read the length
-	if(async_data_read_start(socket->phone, optlen, sizeof(*optlen)) == EOK){
-		// read the value
-		async_data_read_start(socket->phone, value, * optlen);
-	}
-	fibril_rwlock_read_unlock(&socket_globals.lock);
-	async_wait_for(message_id, &result);
-	return (int) result;
-}
-
-int setsockopt(int socket_id, int level, int optname, const void * value, size_t optlen){
-	// send the value
-	return socket_send_data(socket_id, NET_SOCKET_SETSOCKOPT, (ipcarg_t) optname, value, optlen);
-
-}
-
-/** @}
- */
Index: pace/srv/net/socket/socket_core.c
===================================================================
--- uspace/srv/net/socket/socket_core.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,490 +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 <limits.h>
-#include <stdlib.h>
-
-#include "../err.h"
-
-#include "../include/in.h"
-#include "../include/inet.h"
-
-#include "../include/socket_codes.h"
-#include "../include/socket_errno.h"
-
-#include "../structures/dynamic_fifo.h"
-#include "../structures/int_map.h"
-#include "../structures/packet/packet.h"
-#include "../structures/packet/packet_client.h"
-
-#include "../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;
-};
-
-/** 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.
- */
-int socket_bind_insert(socket_ports_ref global_sockets, socket_core_ref socket, int port);
-
-/** 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.
- */
-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));
-
-/** 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.
- */
-int socket_port_add_core(socket_port_ref socket_port, socket_core_ref socket, const char * key, size_t key_length);
-
-/** 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_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);
-
-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);
-	}
-}
-
-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(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);
-}
-
-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);
-}
-
-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;
-}
-
-
-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;
-}
-
-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;
-}
-
-/** @}
- */
Index: pace/srv/net/socket/socket_core.h
===================================================================
--- uspace/srv/net/socket/socket_core.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,243 +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 "../include/in.h"
-#include "../include/device.h"
-
-#include "../structures/generic_char_map.h"
-#include "../structures/dynamic_fifo.h"
-#include "../structures/int_map.h"
-#include "../structures/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.
- */
-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.
- */
-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.
- */
-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.
- */
-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.
- */
-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.
- */
-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.
- */
-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.
- */
-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.
- */
-int socket_port_add(socket_ports_ref global_sockets, int port, socket_core_ref socket, const char * key, size_t key_length);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/socket/socket_messages.h
===================================================================
--- uspace/srv/net/socket/socket_messages.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,199 +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 messages.
- *  @see socket.h
- */
-
-
-#ifndef __NET_SOCKET_MESSAGES_H__
-#define __NET_SOCKET_MESSAGES_H__
-
-#include <ipc/ipc.h>
-
-#include "../messages.h"
-
-#include "../include/socket_codes.h"
-
-/** Socket client messages.
- */
-typedef enum{
-	/** Creates a new socket.
-	 *  @see socket()
-	 */
-	NET_SOCKET = NET_SOCKET_FIRST,
-	/** Binds the socket.
-	 *  @see bind()
-	 */
-	NET_SOCKET_BIND,
-	/** Creates a new socket.
-	 *  @see socket()
-	 */
-	NET_SOCKET_LISTEN,
-	/** Accepts an incomming connection.
-	 *  @see accept()
-	 */
-	NET_SOCKET_ACCEPT,
-	/** Connects the socket.
-	 *  @see connect()
-	 */
-	NET_SOCKET_CONNECT,
-	/** Closes the socket.
-	 *  @see closesocket()
-	 */
-	NET_SOCKET_CLOSE,
-	/** Sends data via the stream socket.
-	 *  @see send()
-	 */
-	NET_SOCKET_SEND,
-	/** Sends data via the datagram socket.
-	 *  @see sendto()
-	 */
-	NET_SOCKET_SENDTO,
-	/** Receives data from the stream socket.
-	 *  @see socket()
-	 */
-	NET_SOCKET_RECV,
-	/** Receives data from the datagram socket.
-	 *  @see socket()
-	 */
-	NET_SOCKET_RECVFROM,
-	/** Gets the socket option.
-	 *  @see getsockopt()
-	 */
-	NET_SOCKET_GETSOCKOPT,
-	/** Sets the socket option.
-	 *  @see setsockopt()
-	 */
-	NET_SOCKET_SETSOCKOPT,
-	/** New socket for acceptence notification message.
-	 */
-	NET_SOCKET_ACCEPTED,
-	/** New data received notification message.
-	 */
-	NET_SOCKET_RECEIVED,
-	/** New socket data fragment size notification message.
-	 */
-	NET_SOCKET_DATA_FRAGMENT_SIZE
-} socket_messages;
-
-/** @name Socket specific message parameters definitions
- */
-/*@{*/
-
-/** Sets the socket identifier in the message answer.
- *  @param[out] answer The message answer structure.
- */
-#define SOCKET_SET_SOCKET_ID(answer)		&IPC_GET_ARG1(answer)
-
-/** Returns the socket identifier message parameter.
- *  @param[in] call The message call structure.
- */
-#define SOCKET_GET_SOCKET_ID(call)		(int) IPC_GET_ARG1(call)
-
-/** Sets the read data length in the message answer.
- *  @param[out] answer The message answer structure.
- */
-#define SOCKET_SET_READ_DATA_LENGTH(answer)	&IPC_GET_ARG1(answer)
-
-/** Returns the read data length message parameter.
- *  @param[in] call The message call structure.
- */
-#define SOCKET_GET_READ_DATA_LENGTH(call)	(int) IPC_GET_ARG1(call)
-
-/** Returns the backlog message parameter.
- *  @param[in] call The message call structure.
- */
-#define SOCKET_GET_BACKLOG(call)		(int) IPC_GET_ARG2(call)
-
-/** Returns the option level message parameter.
- *  @param[in] call The message call structure.
- */
-#define SOCKET_GET_OPT_LEVEL(call)		(int) IPC_GET_ARG2(call)
-
-/** Returns the data fragment size message parameter.
- *  @param[in] call The message call structure.
- */
-#define SOCKET_GET_DATA_FRAGMENT_SIZE(call)	(size_t) IPC_GET_ARG2(call)
-
-/** Sets the data fragment size in the message answer.
- *  @param[out] answer The message answer structure.
- */
-#define SOCKET_SET_DATA_FRAGMENT_SIZE(answer)	&IPC_GET_ARG2(answer)
-
-/** Sets the address length in the message answer.
- *  @param[out] answer The message answer structure.
- */
-#define SOCKET_SET_ADDRESS_LENGTH(answer)	&IPC_GET_ARG3(answer)
-
-/** Returns the address length message parameter.
- *  @param[in] call The message call structure.
- */
-#define SOCKET_GET_ADDRESS_LENGTH(call)		(socklen_t) IPC_GET_ARG3(call)
-
-/** Sets the header size in the message answer.
- *  @param[out] answer The message answer structure.
- */
-#define SOCKET_SET_HEADER_SIZE(answer)		&IPC_GET_ARG3(answer)
-
-/** Returns the header size message parameter.
- *  @param[in] call The message call structure.
- */
-#define SOCKET_GET_HEADER_SIZE(call)		(size_t) IPC_GET_ARG3(call)
-
-/** Returns the flags message parameter.
- *  @param[in] call The message call structure.
- */
-#define SOCKET_GET_FLAGS(call)			(int) IPC_GET_ARG4(call)
-
-/** Returns the option name message parameter.
- *  @param[in] call The message call structure.
- */
-#define SOCKET_GET_OPT_NAME(call)		(int) IPC_GET_ARG4(call)
-
-/** Returns the data fragments message parameter.
- *  @param[in] call The message call structure.
- */
-#define SOCKET_GET_DATA_FRAGMENTS(call)		(int) IPC_GET_ARG5(call)
-
-/** Returns the new socket identifier message parameter.
- *  @param[in] call The message call structure.
- */
-#define SOCKET_GET_NEW_SOCKET_ID(call)		(int) IPC_GET_ARG5(call)
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/structures/char_map.c
===================================================================
--- uspace/srv/net/structures/char_map.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,234 +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 net
- *  @{
- */
-
-/** @file
- *  Character string to integer map implementation.
- *  @see char_map.h
- */
-
-#include <errno.h>
-#include <malloc.h>
-#include <mem.h>
-#include <unistd.h>
-
-#include "char_map.h"
-
-/** Internal magic value for a&nbsp;consistency check.
- */
-#define CHAR_MAP_MAGIC_VALUE	0x12345611
-
-/** Adds the value with the key to the map.
- *  Creates new nodes to map the key.
- *  @param[in,out] map The character string to integer map.
- *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
- *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
- *  @param[in] value The integral value to be stored for the key character string.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns EEXIST if the key character string is already used.
- */
-int char_map_add_item(char_map_ref map, const char * identifier, size_t length, const int value);
-
-/** Returns the node assigned to the key from the map.
- *  @param[in] map The character string to integer map.
- *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
- *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
- *  @returns The node holding the integral value assigned to the key character string.
- *  @returns NULL if the key is not assigned a&nbsp;node.
- */
-char_map_ref char_map_find_node(const char_map_ref map, const char * identifier, const size_t length);
-
-/** Returns the value assigned to the map.
- *  @param[in] map The character string to integer map.
- *  @returns The integral value assigned to the map.
- *  @returns CHAR_MAP_NULL if the map is not assigned a&nbsp;value.
- */
-int char_map_get_value(const char_map_ref map);
-
-/** Checks if the map is valid.
- *  @param[in] map The character string to integer map.
- *  @returns TRUE if the map is valid.
- *  @returns FALSE otherwise.
- */
-int char_map_is_valid(const char_map_ref map);
-
-int char_map_add(char_map_ref map, const char * identifier, size_t length, const int value){
-	if(char_map_is_valid(map) && (identifier) && ((length) || (*identifier))){
-		int index;
-
-		for(index = 0; index < map->next; ++ index){
-			if(map->items[index]->c == * identifier){
-				++ identifier;
-				if((length > 1) || ((length == 0) && (*identifier))){
-					return char_map_add(map->items[index], identifier, length ? length - 1 : 0, value);
-				}else{
-					if(map->items[index]->value != CHAR_MAP_NULL){
-						return EEXISTS;
-					}
-					map->items[index]->value = value;
-					return EOK;
-				}
-			}
-		}
-		return char_map_add_item(map, identifier, length, value);
-	}
-	return EINVAL;
-}
-
-int char_map_add_item(char_map_ref map, const char * identifier, size_t length, const int value){
-	if(map->next == (map->size - 1)){
-		char_map_ref *tmp;
-
-		tmp = (char_map_ref *) realloc(map->items, sizeof(char_map_ref) * 2 * map->size);
-		if(! tmp){
-			return ENOMEM;
-		}
-		map->size *= 2;
-		map->items = tmp;
-	}
-	map->items[map->next] = (char_map_ref) malloc(sizeof(char_map_t));
-	if(! map->items[map->next]){
-		return ENOMEM;
-	}
-	if(char_map_initialize(map->items[map->next]) != EOK){
-		free(map->items[map->next]);
-		map->items[map->next] = NULL;
-		return ENOMEM;
-	}
-	map->items[map->next]->c = * identifier;
-	++ identifier;
-	++ map->next;
-	if((length > 1) || ((length == 0) && (*identifier))){
-		map->items[map->next - 1]->value = CHAR_MAP_NULL;
-		return char_map_add_item(map->items[map->next - 1], identifier, length ? length - 1 : 0, value);
-	}else{
-		map->items[map->next - 1]->value = value;
-	}
-	return EOK;
-}
-
-void char_map_destroy(char_map_ref map){
-	if(char_map_is_valid(map)){
-		int index;
-
-		map->magic = 0;
-		for(index = 0; index < map->next; ++ index){
-			char_map_destroy(map->items[index]);
-		}
-		free(map->items);
-		map->items = NULL;
-	}
-}
-
-int char_map_exclude(char_map_ref map, const char * identifier, size_t length){
-	char_map_ref node;
-
-	node = char_map_find_node(map, identifier, length);
-	if(node){
-		int value;
-
-		value = node->value;
-		node->value = CHAR_MAP_NULL;
-		return value;
-	}
-	return CHAR_MAP_NULL;
-}
-
-int char_map_find(const char_map_ref map, const char * identifier, size_t length){
-	char_map_ref node;
-
-	node = char_map_find_node(map, identifier, length);
-	return node ? node->value : CHAR_MAP_NULL;
-}
-
-char_map_ref char_map_find_node(const char_map_ref map, const char * identifier, size_t length){
-	if(! char_map_is_valid(map)){
-		return NULL;
-	}
-	if(length || (*identifier)){
-		int index;
-
-		for(index = 0; index < map->next; ++ index){
-			if(map->items[index]->c == * identifier){
-				++ identifier;
-				if(length == 1){
-					return map->items[index];
-				}
-				return char_map_find_node(map->items[index], identifier, length ? length - 1 : 0);
-			}
-		}
-		return NULL;
-	}
-	return map;
-}
-
-int char_map_get_value(const char_map_ref map){
-	return char_map_is_valid(map) ? map->value : CHAR_MAP_NULL;
-}
-
-int char_map_initialize(char_map_ref map){
-	if(! map){
-		return EINVAL;
-	}
-	map->c = '\0';
-	map->value = CHAR_MAP_NULL;
-	map->size = 2;
-	map->next = 0;
-	map->items = malloc(sizeof(char_map_ref) * map->size);
-	if(! map->items){
-		map->magic = 0;
-		return ENOMEM;
-	}
-	map->items[map->next] = NULL;
-	map->magic = CHAR_MAP_MAGIC_VALUE;
-	return EOK;
-}
-
-int char_map_is_valid(const char_map_ref map){
-	return map && (map->magic == CHAR_MAP_MAGIC_VALUE);
-}
-
-int char_map_update(char_map_ref map, const char * identifier, const size_t length, const int value){
-	char_map_ref node;
-
-//	if(! char_map_is_valid(map)) return EINVAL;
-	node = char_map_find_node(map, identifier, length);
-	if(node){
-		node->value = value;
-		return EOK;
-	}else{
-		return char_map_add(map, identifier, length, value);
-	}
-}
-
-/** @}
- */
Index: pace/srv/net/structures/char_map.h
===================================================================
--- uspace/srv/net/structures/char_map.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,142 +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 net
- *  @{
- */
-
-/** @file
- *  Character string to integer map.
- */
-
-#ifndef __CHAR_MAP_H__
-#define __CHAR_MAP_H__
-
-/** Invalid assigned value used also if an&nbsp;entry does not exist.
- */
-#define CHAR_MAP_NULL	(-1)
-
-/** Type definition of the character string to integer map.
- *  @see char_map
- */
-typedef struct char_map	char_map_t;
-
-/** Type definition of the character string to integer map pointer.
- *  @see char_map
- */
-typedef char_map_t *	char_map_ref;
-
-/** Character string to integer map item.
- *  This structure recursivelly contains itself as a&nbsp;character by character tree.
- *  The actually mapped character string consists o fall the parent characters and the actual one.
- */
-struct	char_map{
-	/** Actually mapped character.
-	 */
-	char c;
-	/** Stored integral value.
-	 */
-	int value;
-	/** Next character array size.
-	 */
-	int size;
-	/** First free position in the next character array.
-	 */
-	int next;
-	/** Next character array.
-	 */
-	char_map_ref * items;
-	/** Consistency check magic value.
-	 */
-	int magic;
-};
-
-/** Adds the value with the key to the map.
- *  @param[in,out] map The character string to integer map.
- *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
- *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
- *  @param[in] value The integral value to be stored for the key character string.
- *  @returns EOK on success.
- *  @returns EINVAL if the map is not valid.
- *  @returns EINVAL if the identifier parameter is NULL.
- *  @returns EINVAL if the length parameter zero (0) and the identifier parameter is an empty character string (the first character is the terminating zero ('\\0') character.
- *  @returns EEXIST if the key character string is already used.
- *  @returns Other error codes as defined for the char_map_add_item() function.
- */
-int char_map_add(char_map_ref map, const char * identifier, size_t length, const int value);
-
-/** Clears and destroys the map.
- *  @param[in,out] map The character string to integer map.
- */
-void char_map_destroy(char_map_ref map);
-
-/** Excludes the value assigned to the key from the map.
- *  The entry is cleared from the map.
- *  @param[in,out] map The character string to integer map.
- *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
- *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
- *  @returns The integral value assigned to the key character string.
- *  @returns CHAR_MAP_NULL if the key is not assigned a&nbsp;value.
- */
-int char_map_exclude(char_map_ref map, const char * identifier, size_t length);
-
-/** Returns the value assigned to the key from the map.
- *  @param[in] map The character string to integer map.
- *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
- *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
- *  @returns The integral value assigned to the key character string.
- *  @returns CHAR_MAP_NULL if the key is not assigned a&nbsp;value.
- */
-int char_map_find(const char_map_ref map, const char * identifier, size_t length);
-
-/** Initializes the map.
- *  @param[in,out] map The character string to integer map.
- *  @returns EOK on success.
- *  @returns EINVAL if the map parameter is NULL.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int char_map_initialize(char_map_ref map);
-
-/** Adds or updates the value with the key to the map.
- *  @param[in,out] map The character string to integer map.
- *  @param[in] identifier The key zero ('\\0') terminated character string. The key character string is processed until the first terminating zero ('\\0') character after the given length is found.
- *  @param[in] length The key character string length. The parameter may be zero (0) which means that the string is processed until the terminating zero ('\\0') character is found.
- *  @param[in] value The integral value to be stored for the key character string.
- *  @returns EOK on success.
- *  @returns EINVAL if the map is not valid.
- *  @returns EINVAL if the identifier parameter is NULL.
- *  @returns EINVAL if the length parameter zero (0) and the identifier parameter is an empty character string (the first character is the terminating zero ('\\0) character.
- *  @returns EEXIST if the key character string is already used.
- *  @returns Other error codes as defined for the char_map_add_item() function.
- */
-int char_map_update(char_map_ref map, const char * identifier, size_t length, const int value);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/structures/dynamic_fifo.c
===================================================================
--- uspace/srv/net/structures/dynamic_fifo.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,153 +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 net
- *  @{
- */
-
-/** @file
- *  Dynamic first in first out positive integer queue implementation.
- */
-
-#include <errno.h>
-#include <malloc.h>
-#include <mem.h>
-
-#include "dynamic_fifo.h"
-
-/** Internal magic value for a&nbsp;consistency check.
- */
-#define DYN_FIFO_MAGIC_VALUE	0x58627659
-
-/** Returns the next queue index.
- *  The queue field is circular.
- *  @param[in] fifo The dynamic queue.
- *  @param[in] index The actual index to be shifted.
- */
-#define NEXT_INDEX(fifo, index)	(((index) + 1) % ((fifo)->size + 1))
-
-/** Checks if the queue is valid.
- *  @param[in] fifo The dynamic queue.
- *  @returns TRUE if the queue is valid.
- *  @returns FALSE otherwise.
- */
-int dyn_fifo_is_valid(dyn_fifo_ref fifo);
-
-int dyn_fifo_is_valid(dyn_fifo_ref fifo){
-	return fifo && (fifo->magic_value == DYN_FIFO_MAGIC_VALUE);
-}
-
-int dyn_fifo_initialize(dyn_fifo_ref fifo, int size){
-	if(! fifo){
-		return EBADMEM;
-	}
-	if(size <= 0){
-		return EINVAL;
-	}
-	fifo->items = (int *) malloc(sizeof(int) * size + 1);
-	if(! fifo->items){
-		return ENOMEM;
-	}
-	fifo->size = size;
-	fifo->head = 0;
-	fifo->tail = 0;
-	fifo->magic_value = DYN_FIFO_MAGIC_VALUE;
-	return EOK;
-}
-
-int dyn_fifo_push(dyn_fifo_ref fifo, int value, int max_size){
-	int * new_items;
-
-	if(! dyn_fifo_is_valid(fifo)){
-		return EINVAL;
-	}
-	if(NEXT_INDEX(fifo, fifo->tail) == fifo->head){
-		if((max_size > 0) && ((fifo->size * 2) > max_size)){
-			if(fifo->size >= max_size){
-				return ENOMEM;
-			}
-		}else{
-			max_size = fifo->size * 2;
-		}
-		new_items = realloc(fifo->items, sizeof(int) * max_size + 1);
-		if(! new_items){
-			return ENOMEM;
-		}
-		fifo->items = new_items;
-		if(fifo->tail < fifo->head){
-			if(fifo->tail < max_size - fifo->size){
-				memcpy(fifo->items + fifo->size + 1, fifo->items, fifo->tail * sizeof(int));
-				fifo->tail += fifo->size + 1;
-			}else{
-				memcpy(fifo->items + fifo->size + 1, fifo->items, (max_size - fifo->size) * sizeof(int));
-				memcpy(fifo->items, fifo->items + max_size - fifo->size, fifo->tail - max_size + fifo->size);
-				fifo->tail -= max_size - fifo->size;
-			}
-		}
-		fifo->size = max_size;
-	}
-	fifo->items[fifo->tail] = value;
-	fifo->tail = NEXT_INDEX(fifo, fifo->tail);
-	return EOK;
-}
-
-int dyn_fifo_pop(dyn_fifo_ref fifo){
-	int value;
-
-	if(! dyn_fifo_is_valid(fifo)){
-		return EINVAL;
-	}
-	if(fifo->head == fifo->tail){
-		return ENOENT;
-	}
-	value = fifo->items[fifo->head];
-	fifo->head = NEXT_INDEX(fifo, fifo->head);
-	return value;
-}
-
-int dyn_fifo_value(dyn_fifo_ref fifo){
-	if(! dyn_fifo_is_valid(fifo)){
-		return EINVAL;
-	}
-	if(fifo->head == fifo->tail){
-		return ENOENT;
-	}
-	return fifo->items[fifo->head];
-}
-
-int dyn_fifo_destroy(dyn_fifo_ref fifo){
-	if(! dyn_fifo_is_valid(fifo)){
-		return EINVAL;
-	}
-	free(fifo->items);
-	fifo->magic_value = 0;
-	return EOK;
-}
-
-/** @}
- */
Index: pace/srv/net/structures/dynamic_fifo.h
===================================================================
--- uspace/srv/net/structures/dynamic_fifo.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,119 +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 net
- *  @{
- */
-
-/** @file
- *  Dynamic first in first out positive integer queue.
- *  Possitive integer values only.
- */
-
-#ifndef __NET_DYNAMIC_FIFO_H__
-#define __NET_DYNAMIC_FIFO_H__
-
-/** Type definition of the dynamic fifo queue.
- *  @see dyn_fifo
- */
-typedef struct dyn_fifo	dyn_fifo_t;
-
-/** Type definition of the dynamic fifo queue pointer.
- *  @see dyn_fifo
- */
-typedef dyn_fifo_t *	dyn_fifo_ref;
-
-/** Dynamic first in first out positive integer queue.
- *  Possitive integer values only.
- *  The queue automatically resizes if needed.
- */
-struct dyn_fifo{
-	/** Stored item field.
-	 */
-	int *	items;
-	/** Actual field size.
-	 */
-	int size;
-	/** First item in the queue index.
-	 */
-	int head;
-	/** Last item in the queue index.
-	 */
-	int tail;
-	/** Consistency check magic value.
-	 */
-	int magic_value;
-};
-
-/** Initializes the dynamic queue.
- *  @param[in,out] fifo The dynamic queue.
- *  @param[in] size The initial queue size.
- *  @returns EOK on success.
- *  @returns EINVAL if the queue is not valid.
- *  @returns EBADMEM if the fifo parameter is NULL.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int dyn_fifo_initialize(dyn_fifo_ref fifo, int size);
-
-/** Appends a new item to the queue end.
- *  @param[in,out] fifo The dynamic queue.
- *  @param[in] value The new item value. Should be positive.
- *  @param[in] max_size The maximum queue size. The queue is not resized beyound this limit. May be zero or negative (<=0) to indicate no limit.
- *  @returns EOK on success.
- *  @returns EINVAL if the queue is not valid.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int dyn_fifo_push(dyn_fifo_ref fifo, int value, int max_size);
-
-/** Returns and excludes the first item in the queue.
- *  @param[in,out] fifo The dynamic queue.
- *  @returns Value of the first item in the queue.
- *  @returns EINVAL if the queue is not valid.
- *  @returns ENOENT if the queue is empty.
- */
-int dyn_fifo_pop(dyn_fifo_ref fifo);
-
-/** Returns and keeps the first item in the queue.
- *  @param[in,out] fifo The dynamic queue.
- *  @returns Value of the first item in the queue.
- *  @returns EINVAL if the queue is not valid.
- *  @returns ENOENT if the queue is empty.
- */
-int dyn_fifo_value(dyn_fifo_ref fifo);
-
-/** Clears and destroys the queue.
- *  @param[in,out] fifo The dynamic queue.
- *  @returns EOK on success.
- *  @returns EINVAL if the queue is not valid.
- */
-int dyn_fifo_destroy(dyn_fifo_ref fifo);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/structures/generic_char_map.h
===================================================================
--- uspace/srv/net/structures/generic_char_map.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,161 +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 net
- *  @{
- */
-
-/** @file
- *  Character string to generic type map.
- */
-
-#ifndef __GENERIC_CHAR_MAP_H__
-#define __GENERIC_CHAR_MAP_H__
-
-#include <errno.h>
-#include <unistd.h>
-
-#include "../err.h"
-
-#include "char_map.h"
-#include "generic_field.h"
-
-/** Internal magic value for a&nbsp;map consistency check.
- */
-#define GENERIC_CHAR_MAP_MAGIC_VALUE	0x12345622
-
-/** Character string to generic type map declaration.
- *  @param[in] name Name of the map.
- *  @param[in] type Inner object type.
- */
-#define GENERIC_CHAR_MAP_DECLARE(name, type)									\
-																				\
-GENERIC_FIELD_DECLARE(name##_items, type)										\
-																				\
-typedef	struct name		name##_t;												\
-typedef	name##_t *		name##_ref;												\
-																				\
-struct	name{																	\
-	char_map_t names;														\
-	name##_items_t values;														\
-	int magic;														\
-};																				\
-																				\
-int name##_add(name##_ref map, const char * name, const size_t length, type * value);	\
-int name##_count(name##_ref map);												\
-void name##_destroy(name##_ref map);											\
-void name##_exclude(name##_ref map, const char * name, const size_t length);	\
-type * name##_find(name##_ref map, const char * name, const size_t length);		\
-int name##_initialize(name##_ref map);											\
-int name##_is_valid(name##_ref map);
-
-/** Character string to generic type map implementation.
- *  Should follow declaration with the same parameters.
- *  @param[in] name Name of the map.
- *  @param[in] type Inner object type.
- */
-#define GENERIC_CHAR_MAP_IMPLEMENT(name, type)									\
-																				\
-GENERIC_FIELD_IMPLEMENT(name##_items, type)										\
-																				\
-int name##_add(name##_ref map, const char * name, const size_t length, type * value){	\
-	ERROR_DECLARE;																\
-																				\
-	int index;																	\
-																				\
-	if(! name##_is_valid(map)){													\
-		return EINVAL;															\
-	}																			\
-	index = name##_items_add(&map->values, value);								\
-	if(index < 0){																\
-		return index;															\
-	}																			\
-	if(ERROR_OCCURRED(char_map_add(&map->names, name, length, index))){			\
-		name##_items_exclude_index(&map->values, index);						\
-		return ERROR_CODE;														\
-	}																			\
-	return EOK;																	\
-}																				\
-																				\
-int name##_count(name##_ref map){												\
-	return name##_is_valid(map) ? name##_items_count(&map->values) : -1;		\
-}																				\
-																				\
-void name##_destroy(name##_ref map){											\
-	if(name##_is_valid(map)){													\
-		char_map_destroy(&map->names);											\
-		name##_items_destroy(&map->values);										\
-	}																			\
-}																				\
-																				\
-void name##_exclude(name##_ref map, const char * name, const size_t length){	\
-	if(name##_is_valid(map)){													\
-		int index;																\
-																				\
-		index = char_map_exclude(&map->names, name, length);					\
-		if(index != CHAR_MAP_NULL){												\
-			name##_items_exclude_index(&map->values, index);					\
-		}																		\
-	}																			\
-}																				\
-																				\
-type * name##_find(name##_ref map, const char * name, const size_t length){		\
-	if(name##_is_valid(map)){													\
-		int index;																\
-																				\
-		index = char_map_find(&map->names, name, length);						\
-		if(index != CHAR_MAP_NULL){												\
-			return name##_items_get_index(&map->values, index);					\
-		}																		\
-	}																			\
-	return NULL;																\
-}																				\
-																				\
-int name##_initialize(name##_ref map){											\
-	ERROR_DECLARE;																\
-																				\
-	if(! map){																	\
-		return EINVAL;															\
-	}																			\
-	ERROR_PROPAGATE(char_map_initialize(&map->names));							\
-	if(ERROR_OCCURRED(name##_items_initialize(&map->values))){					\
-		char_map_destroy(&map->names);											\
-		return ERROR_CODE;														\
-	}																			\
-	map->magic = GENERIC_CHAR_MAP_MAGIC_VALUE;									\
-	return EOK;																	\
-}																				\
-																				\
-int name##_is_valid(name##_ref map){											\
-	return map && (map->magic == GENERIC_CHAR_MAP_MAGIC_VALUE);					\
-}
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/structures/generic_field.h
===================================================================
--- uspace/srv/net/structures/generic_field.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,160 +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 net
- *  @{
- */
-
-/** @file
- *  Generic type field.
- */
-
-#ifndef __GENERIC_FIELD_H__
-#define __GENERIC_FIELD_H__
-
-#include <errno.h>
-#include <malloc.h>
-#include <mem.h>
-#include <unistd.h>
-
-/** Internal magic value for a&nbsp;field consistency check.
- */
-#define GENERIC_FIELD_MAGIC_VALUE		0x55667788
-
-/** Generic type field declaration.
- *  @param[in] name Name of the field.
- *  @param[in] type Inner object type.
- */
-#define GENERIC_FIELD_DECLARE(name, type)										\
-																				\
-typedef	struct name		name##_t;												\
-typedef	name##_t *		name##_ref;												\
-																				\
-struct	name{																	\
-	int size;																	\
-	int next;																	\
-	type **	items;																\
-	int magic;																	\
-};																				\
-																				\
-int name##_add(name##_ref field, type * value);									\
-int name##_count(name##_ref field);												\
-void name##_destroy(name##_ref field);											\
-void name##_exclude_index(name##_ref field, int index);							\
-type ** name##_get_field(name##_ref field);										\
-type * name##_get_index(name##_ref field, int index);							\
-int name##_initialize(name##_ref field);										\
-int name##_is_valid(name##_ref field);
-
-/** Generic type field implementation.
- *  Should follow declaration with the same parameters.
- *  @param[in] name Name of the field.
- *  @param[in] type Inner object type.
- */
-#define GENERIC_FIELD_IMPLEMENT(name, type)										\
-																				\
-int name##_add(name##_ref field, type * value){									\
-	if(name##_is_valid(field)){													\
-		if(field->next == (field->size - 1)){									\
-			type **	tmp;														\
-																				\
-			tmp = (type **) realloc(field->items, sizeof(type *) * 2 * field->size);	\
-			if(! tmp){															\
-				return ENOMEM;													\
-			}																	\
-			field->size *= 2;													\
-			field->items = tmp;													\
-		}																		\
-		field->items[field->next] = value;										\
-		++ field->next;															\
-		field->items[field->next] = NULL;										\
-		return field->next - 1;													\
-	}																			\
-	return EINVAL;																\
-}																				\
-																				\
-int name##_count(name##_ref field){												\
-	return name##_is_valid(field) ? field->next : -1;							\
-}																				\
-																				\
-void name##_destroy(name##_ref field){											\
-	if(name##_is_valid(field)){													\
-		int index;																\
-																				\
-		field->magic = 0;														\
-		for(index = 0; index < field->next; ++ index){							\
-			if(field->items[index]){											\
-				free(field->items[index]);										\
-			}																	\
-		}																		\
-		free(field->items);														\
-	}																			\
-}																				\
-																				\
-void name##_exclude_index(name##_ref field, int index){							\
-	if(name##_is_valid(field) && (index >= 0) && (index < field->next) && (field->items[index])){	\
-		free(field->items[index]);												\
-		field->items[index] = NULL;												\
-	}																			\
-}																				\
-																				\
-type * name##_get_index(name##_ref field, int index){							\
-	if(name##_is_valid(field) && (index >= 0) && (index < field->next) && (field->items[index])){	\
-		return field->items[index];												\
-	}																			\
-	return NULL;																\
-}																				\
-																				\
-type ** name##_get_field(name##_ref field){										\
-	return name##_is_valid(field) ? field->items : NULL;						\
-}																				\
-																				\
-int name##_initialize(name##_ref field){										\
-	if(! field){																\
-		return EINVAL;															\
-	}																			\
-	field->size = 2;															\
-	field->next = 0;															\
-	field->items = (type **) malloc(sizeof(type *) * field->size);				\
-	if(! field->items){															\
-		return ENOMEM;															\
-	}																			\
-	field->items[field->next] = NULL;											\
-	field->magic = GENERIC_FIELD_MAGIC_VALUE;									\
-	return EOK;																	\
-}																				\
-																				\
-int name##_is_valid(name##_ref field){											\
-	return field && (field->magic == GENERIC_FIELD_MAGIC_VALUE);				\
-}
-
-#endif
-
-/** @}
- */
-
Index: pace/srv/net/structures/int_map.h
===================================================================
--- uspace/srv/net/structures/int_map.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,247 +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 net
- *  @{
- */
-
-/** @file
- *  Integer to generic type map.
- */
-
-#ifndef __NET_INT_MAP_H__
-#define __NET_INT_MAP_H__
-
-#include <errno.h>
-#include <malloc.h>
-#include <mem.h>
-#include <unistd.h>
-
-/** Internal magic value for a&nbsp;map consistency check.
- */
-#define INT_MAP_MAGIC_VALUE			0x11223344
-
-/** Internal magic value for an item consistency check.
- */
-#define INT_MAP_ITEM_MAGIC_VALUE	0x55667788
-
-/** Integer to generic type map declaration.
- *  @param[in] name Name of the map.
- *  @param[in] type Inner object type.
- */
-#define INT_MAP_DECLARE(name, type)												\
-																				\
-typedef	struct name			name##_t;											\
-typedef	name##_t *			name##_ref;											\
-typedef	struct name##_item	name##_item_t;										\
-typedef	name##_item_t *		name##_item_ref;									\
-																				\
-struct	name##_item{															\
-	int key;																\
-	type * value;																\
-	int magic;																\
-};																				\
-																				\
-struct	name{																	\
-	int size;														\
-	int next;														\
-	name##_item_ref items;														\
-	int magic;														\
-};																				\
-																				\
-int name##_add(name##_ref map, int key, type * value);							\
-void name##_clear(name##_ref map);												\
-int name##_count(name##_ref map);												\
-void name##_destroy(name##_ref map);											\
-void name##_exclude(name##_ref map, int key);									\
-void name##_exclude_index(name##_ref map, int index);							\
-type * name##_find(name##_ref map, int key);									\
-int name##_update(name##_ref map, int key, int new_key);						\
-type * name##_get_index(name##_ref map, int index);								\
-int name##_initialize(name##_ref map);											\
-int name##_is_valid(name##_ref map);											\
-void name##_item_destroy(name##_item_ref item);									\
-int name##_item_is_valid(name##_item_ref item);
-
-/** Integer to generic type map implementation.
- *  Should follow declaration with the same parameters.
- *  @param[in] name Name of the map.
- *  @param[in] type Inner object type.
- */
-#define INT_MAP_IMPLEMENT(name, type)											\
-																				\
-int name##_add(name##_ref map, int key, type * value){							\
-	if(name##_is_valid(map)){													\
-		if(map->next == (map->size - 1)){										\
-			name##_item_ref tmp;												\
-																				\
-			tmp = (name##_item_ref) realloc(map->items, sizeof(name##_item_t) * 2 * map->size);	\
-			if(! tmp){															\
-				return ENOMEM;													\
-			}																	\
-			map->size *= 2;														\
-			map->items = tmp;													\
-		}																		\
-		map->items[map->next].key = key;										\
-		map->items[map->next].value = value;									\
-		map->items[map->next].magic = INT_MAP_ITEM_MAGIC_VALUE;					\
-		++ map->next;															\
-		map->items[map->next].magic = 0;										\
-		return map->next - 1;													\
-	}																			\
-	return EINVAL;																\
-}																				\
-																				\
-void name##_clear(name##_ref map){												\
-	if(name##_is_valid(map)){													\
-		int index;																\
-																				\
-/*		map->magic = 0;*/														\
-		for(index = 0; index < map->next; ++ index){							\
-			if(name##_item_is_valid(&(map->items[index]))){						\
-				name##_item_destroy(&(map->items[index]));						\
-			}																	\
-		}																		\
-		map->next = 0;															\
-		map->items[map->next].magic = 0;										\
-/*		map->magic = INT_MAP_MAGIC_VALUE;*/										\
-	}																			\
-}																				\
-																				\
-int name##_count(name##_ref map){												\
-	return name##_is_valid(map) ? map->next : -1;								\
-}																				\
-																				\
-void name##_destroy(name##_ref map){											\
-	if(name##_is_valid(map)){													\
-		int index;																\
-																				\
-		map->magic = 0;															\
-		for(index = 0; index < map->next; ++ index){							\
-			if(name##_item_is_valid(&(map->items[index]))){						\
-				name##_item_destroy(&(map->items[index]));						\
-			}																	\
-		}																		\
-		free(map->items);														\
-	}																			\
-}																				\
-																				\
-void name##_exclude(name##_ref map, int key){									\
-	if(name##_is_valid(map)){													\
-		int index;																\
-																				\
-		for(index = 0; index < map->next; ++ index){							\
-			if(name##_item_is_valid(&(map->items[index])) && (map->items[index].key == key)){	\
-				name##_item_destroy(&(map->items[index]));						\
-			}																	\
-		}																		\
-	}																			\
-}																				\
-																				\
-void name##_exclude_index(name##_ref map, int index){							\
-	if(name##_is_valid(map) && (index >= 0) && (index < map->next) && name##_item_is_valid(&(map->items[index]))){	\
-		name##_item_destroy(&(map->items[index]));								\
-	}																			\
-}																				\
-																				\
-type * name##_find(name##_ref map, int key){									\
-	if(name##_is_valid(map)){													\
-		int index;																\
-																				\
-		for(index = 0; index < map->next; ++ index){							\
-			if(name##_item_is_valid(&(map->items[index])) && (map->items[index].key == key)){	\
-				return map->items[index].value;									\
-			}																	\
-		}																		\
-	}																			\
-	return NULL;																\
-}																				\
-																				\
-int name##_update(name##_ref map, int key, int new_key){						\
-	if(name##_is_valid(map)){													\
-		int index;																\
-																				\
-		for(index = 0; index < map->next; ++ index){							\
-			if(name##_item_is_valid(&(map->items[index]))){						\
-				if(map->items[index].key == new_key){							\
-					return EEXIST;												\
-				}else if(map->items[index].key == key){							\
-					map->items[index].key = new_key;							\
-					return EOK;													\
-				}																\
-			}																	\
-		}																		\
-	}																			\
-	return ENOENT;																\
-}																				\
-																				\
-type * name##_get_index(name##_ref map, int index){								\
-	if(name##_is_valid(map) && (index >= 0) && (index < map->next) && name##_item_is_valid(&(map->items[index]))){	\
-		return map->items[index].value;											\
-	}																			\
-	return NULL;																\
-}																				\
-																				\
-int name##_initialize(name##_ref map){											\
-	if(! map){																	\
-		return EINVAL;															\
-	}																			\
-	map->size = 2;																\
-	map->next = 0;																\
-	map->items = (name##_item_ref) malloc(sizeof(name##_item_t) * map->size);	\
-	if(! map->items){															\
-		return ENOMEM;															\
-	}																			\
-	map->items[map->next].magic = 0;											\
-	map->magic = INT_MAP_MAGIC_VALUE;											\
-	return EOK;																	\
-}																				\
-																				\
-int name##_is_valid(name##_ref map){											\
-	return map && (map->magic == INT_MAP_MAGIC_VALUE);							\
-}																				\
-																				\
-void name##_item_destroy(name##_item_ref item){									\
-	if(name##_item_is_valid(item)){												\
-		item->magic = 0;														\
-		if(item->value){														\
-			free(item->value);													\
-			item->value = NULL;													\
-		}																		\
-	}																			\
-}																				\
-																				\
-int name##_item_is_valid(name##_item_ref item){									\
-	return item && (item->magic == INT_MAP_ITEM_MAGIC_VALUE);					\
-}
-
-#endif
-
-/** @}
- */
-
Index: pace/srv/net/structures/measured_strings.c
===================================================================
--- uspace/srv/net/structures/measured_strings.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,287 +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 net
- *  @{
- */
-
-/** @file
- *  Character string with measured length implementation.
- *  @see measured_strings.h
- */
-
-#include <errno.h>
-#include <malloc.h>
-#include <mem.h>
-#include <unistd.h>
-
-#include <ipc/ipc.h>
-
-#include "../err.h"
-#include "../modules.h"
-
-#include "measured_strings.h"
-
-/** Computes the lengths of the measured strings in the given array.
- *  @param[in] strings The measured strings array to be processed.
- *  @param[in] count The measured strings array size.
- *  @returns The computed sizes array.
- *  @returns NULL if there is not enough memory left.
- */
-size_t * prepare_lengths(const measured_string_ref strings, size_t count);
-
-measured_string_ref measured_string_create_bulk(const char * string, size_t length){
-	measured_string_ref new;
-
-	if(length == 0){
-		while(string[length]){
-			++ length;
-		}
-	}
-	new = (measured_string_ref) malloc(sizeof(measured_string_t) + (sizeof(char) * (length + 1)));
-	if(! new){
-		return NULL;
-	}
-	new->length = length;
-	new->value = ((char *) new) + sizeof(measured_string_t);
-	// append terminating zero explicitly - to be safe
-	memcpy(new->value, string, new->length);
-	new->value[new->length] = '\0';
-	return new;
-}
-
-measured_string_ref measured_string_copy(measured_string_ref source){
-	measured_string_ref new;
-
-	if(! source){
-		return NULL;
-	}
-	new = (measured_string_ref) malloc(sizeof(measured_string_t));
-	if(new){
-		new->value = (char *) malloc(source->length + 1);
-		if(new->value){
-			new->length = source->length;
-			memcpy(new->value, source->value, new->length);
-			new->value[new->length] = '\0';
-			return new;
-		}else{
-			free(new);
-		}
-	}
-	return NULL;
-}
-
-int measured_strings_receive(measured_string_ref * strings, char ** data, size_t count){
-	ERROR_DECLARE;
-
-	size_t * lengths;
-	size_t index;
-	size_t length;
-	char * next;
-	ipc_callid_t callid;
-
-	if((! strings) || (! data) || (count <= 0)){
-		return EINVAL;
-	}
-	lengths = (size_t *) malloc(sizeof(size_t) * (count + 1));
-	if(! lengths){
-		return ENOMEM;
-	}
-	if((! async_data_write_receive(&callid, &length))
-		|| (length != sizeof(size_t) * (count + 1))){
-		free(lengths);
-		return EINVAL;
-	}
-	if(ERROR_OCCURRED(async_data_write_finalize(callid, lengths, sizeof(size_t) * (count + 1)))){
-		free(lengths);
-		return ERROR_CODE;
-	}
-	*data = malloc(lengths[count]);
-	if(!(*data)){
-		return ENOMEM;
-	}
-	(*data)[lengths[count] - 1] = '\0';
-	*strings = (measured_string_ref) malloc(sizeof(measured_string_t) * count);
-	if(!(*strings)){
-		free(lengths);
-		free(*data);
-		return ENOMEM;
-	}
-	next = * data;
-	for(index = 0; index < count; ++ index){
-		(*strings)[index].length = lengths[index];
-		if(lengths[index] > 0){
-			if((! async_data_write_receive(&callid, &length))
-				|| (length != lengths[index])){
-				free(*data);
-				free(*strings);
-				free(lengths);
-				return EINVAL;
-			}
-			ERROR_PROPAGATE(async_data_write_finalize(callid, next, lengths[index]));
-			(*strings)[index].value = next;
-			next += lengths[index];
-			*next = '\0';
-			++ next;
-		}else{
-			(*strings)[index].value = NULL;
-		}
-	}
-	free(lengths);
-	return EOK;
-}
-
-int measured_strings_reply(const measured_string_ref strings, size_t count){
-	ERROR_DECLARE;
-
-	size_t * lengths;
-	size_t index;
-	size_t length;
-	ipc_callid_t callid;
-
-	if((! strings) || (count <= 0)){
-		return EINVAL;
-	}
-	lengths = prepare_lengths(strings, count);
-	if(! lengths){
-		return ENOMEM;
-	}
-	if((! async_data_read_receive(&callid, &length))
-		|| (length != sizeof(size_t) * (count + 1))){
-		free(lengths);
-		return EINVAL;
-	}
-	if(ERROR_OCCURRED(async_data_read_finalize(callid, lengths, sizeof(size_t) * (count + 1)))){
-		free(lengths);
-		return ERROR_CODE;
-	}
-	free(lengths);
-	for(index = 0; index < count; ++ index){
-		if(strings[index].length > 0){
-			if((! async_data_read_receive(&callid, &length))
-				|| (length != strings[index].length)){
-				return EINVAL;
-			}
-			ERROR_PROPAGATE(async_data_read_finalize(callid, strings[index].value, strings[index].length));
-		}
-	}
-	return EOK;
-}
-
-int measured_strings_return(int phone, measured_string_ref * strings, char ** data, size_t count){
-	ERROR_DECLARE;
-
-	size_t * lengths;
-	size_t index;
-	char * next;
-
-	if((phone <= 0) || (! strings) || (! data) || (count <= 0)){
-		return EINVAL;
-	}
-	lengths = (size_t *) malloc(sizeof(size_t) * (count + 1));
-	if(! lengths){
-		return ENOMEM;
-	}
-	if(ERROR_OCCURRED(async_data_read_start(phone, lengths, sizeof(size_t) * (count + 1)))){
-		free(lengths);
-		return ERROR_CODE;
-	}
-	*data = malloc(lengths[count]);
-	if(!(*data)){
-		return ENOMEM;
-	}
-	*strings = (measured_string_ref) malloc(sizeof(measured_string_t) * count);
-	if(!(*strings)){
-		free(lengths);
-		free(*data);
-		return ENOMEM;
-	}
-	next = * data;
-	for(index = 0; index < count; ++ index){
-		(*strings)[index].length = lengths[index];
-		if(lengths[index] > 0){
-			ERROR_PROPAGATE(async_data_read_start(phone, next, lengths[index]));
-			(*strings)[index].value = next;
-			next += lengths[index];
-			*next = '\0';
-			++ next;
-		}else{
-			(*strings)[index].value = NULL;
-		}
-	}
-	free(lengths);
-	return EOK;
-}
-
-int measured_strings_send(int phone, const measured_string_ref strings, size_t count){
-	ERROR_DECLARE;
-
-	size_t * lengths;
-	size_t index;
-
-	if((phone <= 0) || (! strings) || (count <= 0)){
-		return EINVAL;
-	}
-	lengths = prepare_lengths(strings, count);
-	if(! lengths){
-		return ENOMEM;
-	}
-	if(ERROR_OCCURRED(async_data_write_start(phone, lengths, sizeof(size_t) * (count + 1)))){
-		free(lengths);
-		return ERROR_CODE;
-	}
-	free(lengths);
-	for(index = 0; index < count; ++ index){
-		if(strings[index].length > 0){
-			ERROR_PROPAGATE(async_data_write_start(phone, strings[index].value, strings[index].length));
-		}
-	}
-	return EOK;
-}
-
-size_t * prepare_lengths(const measured_string_ref strings, size_t count){
-	size_t * lengths;
-	size_t index;
-	size_t length;
-
-	lengths = (size_t *) malloc(sizeof(size_t) * (count + 1));
-	if(! lengths){
-		return NULL;
-	}
-	length = 0;
-	for(index = 0; index < count; ++ index){
-		lengths[index] = strings[index].length;
-		length += lengths[index] + 1;
-	}
-	lengths[count] = length;
-	return lengths;
-}
-
-/** @}
- */
-
Index: pace/srv/net/structures/measured_strings.h
===================================================================
--- uspace/srv/net/structures/measured_strings.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,144 +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 net
- *  @{
- */
-
-/** @file
- *  Character string with measured length.
- *  The structure has been designed for serialization of character strings between modules.
- */
-
-#ifndef __MEASURED_STRINGS_H__
-#define __MEASURED_STRINGS_H__
-
-#include <sys/types.h>
-
-/** Type definition of the character string with measured length.
- *  @see measured_string
- */
-typedef struct measured_string	measured_string_t;
-
-/** Type definition of the character string with measured length pointer.
- *  @see measured_string
- */
-typedef measured_string_t *		measured_string_ref;
-
-/** Character string with measured length.
- *  This structure has been designed for serialization of character strings between modules.
- */
-struct	measured_string{
-	/** Character string data.
-	 */
-	char * value;
-	/** Character string length.
-	 */
-	size_t length;
-};
-
-/** Creates a&nbsp;new measured string bundled with a&nbsp;copy of the given string itself as one memory block.
- *  If the measured string is being freed, whole memory block is freed.
- *  The measured string should be used only as a&nbsp;constant.
- *  @param[in] string The initial character string to be stored.
- *  @param[in] length The length of the given string without the terminating zero ('/0') character. If the length is zero (0), the actual length is computed. The given length is used and appended with the terminating zero ('\\0') character otherwise.
- *  @returns The new bundled character string with measured length.
- *  @returns NULL if there is not enough memory left.
- */
-measured_string_ref measured_string_create_bulk(const char * string, size_t length);
-
-/** Copies the given measured string with separated header and data parts.
- *  @param[in] source The source measured string to be copied.
- *  @returns The copy of the given measured string.
- *  @returns NULL if the source parameter is NULL.
- *  @returns NULL if there is not enough memory left.
- */
-measured_string_ref measured_string_copy(measured_string_ref source);
-
-/** Receives a&nbsp;measured strings array from a&nbsp;calling module.
- *  Creates the array and the data memory blocks.
- *  This method should be used only while processing IPC messages as the array size has to be negotiated in advance.
- *  @param[out] strings The received measured strings array.
- *  @param[out] data The measured strings data. This memory block stores the actual character strings.
- *  @param[in] count The size of the measured strings array.
- *  @returns EOK on success.
- *  @returns EINVAL if the strings or data parameter is NULL.
- *  @returns EINVAL if the count parameter is zero (0).
- *  @returns EINVAL if the sent array differs in size.
- *  @returns EINVAL if there is inconsistency in sent measured strings' lengths (should not occur).
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns Other error codes as defined for the async_data_write_finalize() function.
- */
-int measured_strings_receive(measured_string_ref * strings, char ** data, size_t count);
-
-/** Replies the given measured strings array to a&nbsp;calling module.
- *  This method should be used only while processing IPC messages as the array size has to be negotiated in advance.
- *  @param[in] strings The measured strings array to be transferred.
- *  @param[in] count The measured strings array size.
- *  @returns EOK on success.
- *  @returns EINVAL if the strings parameter is NULL.
- *  @returns EINVAL if the count parameter is zero (0).
- *  @returns EINVAL if the calling module does not accept the given array size.
- *  @returns EINVAL if there is inconsistency in sent measured strings' lengths (should not occur).
- *  @returns Other error codes as defined for the async_data_read_finalize() function.
- */
-int measured_strings_reply(const measured_string_ref strings, size_t count);
-
-/** Receives a&nbsp;measured strings array from another module.
- *  Creates the array and the data memory blocks.
- *  This method should be used only following other IPC messages as the array size has to be negotiated in advance.
- *  @param[in] phone The other module phone.
- *  @param[out] strings The returned measured strings array.
- *  @param[out] data The measured strings data. This memory block stores the actual character strings.
- *  @param[in] count The size of the measured strings array.
- *  @returns EOK on success.
- *  @returns EINVAL if the strings or data parameter is NULL.
- *  @returns EINVAL if the phone or count parameter is not positive (<=0).
- *  @returns EINVAL if the sent array differs in size.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns Other error codes as defined for the async_data_read_start() function.
- */
-int measured_strings_return(int phone, measured_string_ref * strings, char ** data, size_t count);
-
-/** Sends the given measured strings array to another module.
- *  This method should be used only following other IPC messages as the array size has to be negotiated in advance.
- *  @param[in] phone The other module phone.
- *  @param[in] strings The measured strings array to be transferred.
- *  @param[in] count The measured strings array size.
- *  @returns EOK on success.
- *  @returns EINVAL if the strings parameter is NULL.
- *  @returns EINVAL if the phone or count parameter is not positive (<=0).
- *  @returns Other error codes as defined for the async_data_write_start() function.
- */
-int measured_strings_send(int phone, const measured_string_ref strings, size_t count);
-
-#endif
-
-/** @}
- */
-
Index: pace/srv/net/structures/module_map.c
===================================================================
--- uspace/srv/net/structures/module_map.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,108 +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 net
- *  @{
- */
-
-/** @file
- *  Character string to module map implementation.
- */
-
-#include <malloc.h>
-#include <task.h>
-#include <unistd.h>
-
-#include <ipc/services.h>
-
-#include "../err.h"
-#include "../modules.h"
-
-#include "generic_char_map.h"
-#include "module_map.h"
-
-GENERIC_CHAR_MAP_IMPLEMENT(modules, module_t)
-
-int add_module(module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id, connect_module_t connect_module){
-	ERROR_DECLARE;
-
-	module_ref tmp_module;
-
-	tmp_module = (module_ref) malloc(sizeof(module_t));
-	if(! tmp_module){
-		return ENOMEM;
-	}
-	tmp_module->task_id = task_id;
-	tmp_module->phone = 0;
-	tmp_module->usage = 0;
-	tmp_module->name = name;
-	tmp_module->filename = filename;
-	tmp_module->service = service;
-	tmp_module->connect_module = connect_module;
-	if(ERROR_OCCURRED(modules_add(modules, tmp_module->name, 0, tmp_module))){
-		free(tmp_module);
-		return ERROR_CODE;
-	}
-	if(module){
-		*module = tmp_module;
-	}
-	return EOK;
-}
-
-module_ref get_running_module(modules_ref modules, char * name){
-	module_ref module;
-
-	module = modules_find(modules, name, 0);
-	if(! module){
-		return NULL;
-	}
-	if(! module->task_id){
-		module->task_id = spawn(module->filename);
-		if(! module->task_id){
-			return NULL;
-		}
-	}
-	if(! module->phone){
-		module->phone = module->connect_module(module->service);
-	}
-	return module;
-}
-
-task_id_t spawn(const char * fname){
-	const char * argv[2];
-	task_id_t res;
-
-	argv[0] = fname;
-	argv[1] = NULL;
-	res = task_spawn(fname, argv);
-
-	return res;
-}
-
-/** @}
- */
Index: pace/srv/net/structures/module_map.h
===================================================================
--- uspace/srv/net/structures/module_map.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,123 +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 net
- *  @{
- */
-
-/** @file
- *  Character string to module map.
- */
-
-#ifndef __NET_MODULES_MAP_H__
-#define __NET_MODULES_MAP_H__
-
-#include <task.h>
-
-#include <ipc/services.h>
-
-#include "../modules.h"
-
-#include "generic_char_map.h"
-
-/** Type definition of the module structure.
- *  @see module_struct
- */
-typedef struct module_struct	module_t;
-
-/** Type definition of the module structure pointer.
- *  @see module_struct
- */
-typedef module_t *				module_ref;
-
-/** Module map.
- *  Sorted by module names.
- *  @see generic_char_map.h
- */
-GENERIC_CHAR_MAP_DECLARE(modules, module_t)
-
-/** Module structure.
- */
-struct	module_struct{
-	/** Module task identifier if running.
-	 */
-	task_id_t task_id;
-	/** Module service identifier.
-	 */
-	services_t service;
-	/** Module phone if running and connected.
-	 */
-	int phone;
-	/** Usage counter.
-	 */
-	int usage;
-	/** Module name.
-	 */
-	const char * name;
-	/** Module full path filename.
-	 */
-	const char * filename;
-	/** Connecting function.
-	 */
-	connect_module_t * connect_module;
-};
-
-/** Adds module to the module map.
- *  @param[out] module The module structure added.
- *  @param[in] modules The module map.
- *  @param[in] name The module name.
- *  @param[in] filename The full path filename.
- *  @param[in] service The module service.
- *  @param[in] task_id The module current task identifier. Zero (0) means not running.
- *  @param[in] connect_module The module connecting function.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int add_module(module_ref * module, modules_ref modules, const char * name, const char * filename, services_t service, task_id_t task_id, connect_module_t * connect_module);
-
-/** Searches and returns the specified module.
- *  If the module is not running, the module filaname is spawned.
- *  If the module is not connected, the connect_function is called.
- *  @param[in] modules The module map.
- *  @param[in] name The module name.
- *  @returns The running module found. It does not have to be connected.
- *  @returns NULL if there is no such module.
- */
-module_ref get_running_module(modules_ref modules, char * name);
-
-/** Starts the given module.
- *  @param[in] fname The module full or relative path filename.
- *  @returns The new module task identifier on success.
- *  @returns 0 if there is no such module.
- */
-task_id_t spawn(const char * fname);
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/structures/packet/packet.c
===================================================================
--- uspace/srv/net/structures/packet/packet.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,333 +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 map and queue implementation.
- *  This file has to be compiled with both the packet server and the client.
- */
-
-#include <errno.h>
-#include <malloc.h>
-#include <mem.h>
-#include <fibril_synch.h>
-//#include <stdio.h>
-#include <unistd.h>
-
-#include <sys/mman.h>
-
-#include "../../err.h"
-
-#include "../generic_field.h"
-
-#include "packet.h"
-#include "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: pace/srv/net/structures/packet/packet.h
===================================================================
--- uspace/srv/net/structures/packet/packet.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,196 +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 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.
- */
-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.
- */
-int pm_add(packet_t packet);
-
-/** Initializes the packet map.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left.
- */
-int pm_init(void);
-
-/** Releases the packet map.
- */
-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.
- */
-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.
- */
-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.
- */
-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.
- */
-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..
- */
-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..
- */
-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.
- */
-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.
- */
-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.
- */
-packet_t pq_previous(packet_t packet);
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/structures/packet/packet_client.c
===================================================================
--- uspace/srv/net/structures/packet/packet_client.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,188 +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 <stdio.h>
-
-#include <sys/mman.h>
-
-#include "../../messages.h"
-
-#include "packet.h"
-#include "packet_header.h"
-#include "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;
-	uint8_t * dest;
-	size_t addrlen;
-
-	if(! packet_is_valid(packet)){
-		return NULL;
-	}
-	// get a new packet
-	copy = packet_get_4(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(phone, copy->packet_id);
-		return NULL;
-	}
-}
-
-/** @}
- */
Index: pace/srv/net/structures/packet/packet_client.h
===================================================================
--- uspace/srv/net/structures/packet/packet_client.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(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 "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.
- */
-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.
- */
-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.
- */
-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.
- */
-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.
- */
-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.
- */
-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.
- */
-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.
- */
-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.
- */
-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.
- */
-int packet_translate(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.
- */
-packet_t packet_get_4(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.
- */
-packet_t packet_get_1(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.
- */
-void pq_release(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.
- */
-packet_t packet_get_copy(int phone, packet_t packet);
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/structures/packet/packet_header.h
===================================================================
--- uspace/srv/net/structures/packet/packet_header.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,123 +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 header.
- */
-
-#ifndef __NET_PACKET_HEADER_H__
-#define __NET_PACKET_HEADER_H__
-
-#include "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/srv/net/structures/packet/packet_messages.h
===================================================================
--- uspace/srv/net/structures/packet/packet_messages.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,96 +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 server module messages.
- */
-
-#ifndef __NET_PACKET_MESSAGES__
-#define __NET_PACKET_MESSAGES__
-
-#include <ipc/ipc.h>
-
-#include "../../messages.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/srv/net/structures/packet/packet_remote.c
===================================================================
--- uspace/srv/net/structures/packet/packet_remote.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,145 +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 interface implementation for standalone remote modules.
- *  @see packet_client.h
- */
-
-#include <async.h>
-#include <errno.h>
-
-#include <ipc/ipc.h>
-#include <sys/mman.h>
-
-#include "../../err.h"
-#include "../../messages.h"
-
-#include "packet.h"
-#include "packet_client.h"
-#include "packet_header.h"
-#include "packet_messages.h"
-
-/** Obtains the packet from the packet server as the shared memory block.
- *  Creates the local packet mapping as well.
- *  @param[in] phone The packet server module phone.
- *  @param[out] packet The packet reference pointer to store the received packet reference.
- *  @param[in] packet_id The packet identifier.
- *  @param[in] size The packet total size in bytes.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the pm_add() function.
- *  @returns Other error codes as defined for the async_share_in_start() function.
- */
-int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size);
-
-int packet_translate(int phone, packet_ref packet, packet_id_t packet_id){
-	ERROR_DECLARE;
-
-	ipcarg_t size;
-	packet_t next;
-
-	if(! packet){
-		return EINVAL;
-	}
-	*packet = pm_find(packet_id);
-	if(!(*packet)){
-		ERROR_PROPAGATE(async_req_1_1(phone, NET_PACKET_GET_SIZE, packet_id, &size));
-		ERROR_PROPAGATE(packet_return(phone, packet, packet_id, size));
-	}
-	if((** packet).next){
-		return packet_translate(phone, &next, (** packet).next);
-	}else return EOK;
-}
-
-int packet_return(int phone, packet_ref packet, packet_id_t packet_id, size_t size){
-	ERROR_DECLARE;
-
-	aid_t message;
-	ipc_call_t answer;
-	ipcarg_t result;
-
-	message = async_send_1(phone, NET_PACKET_GET, packet_id, &answer);
-	*packet = (packet_t) as_get_mappable_page(size);
-	if(ERROR_OCCURRED(async_share_in_start_0_0(phone, * packet, size))
-		|| ERROR_OCCURRED(pm_add(*packet))){
-		munmap(*packet, size);
-		async_wait_for(message, NULL);
-		return ERROR_CODE;
-	}
-	async_wait_for(message, &result);
-	return result;
-}
-
-packet_t packet_get_4(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix){
-	ERROR_DECLARE;
-
-	ipcarg_t packet_id;
-	ipcarg_t size;
-	packet_t packet;
-
-	if(ERROR_OCCURRED(async_req_4_2(phone, NET_PACKET_CREATE_4, max_content, addr_len, max_prefix, max_suffix, &packet_id, &size))){
-		return NULL;
-	}
-	packet = pm_find(packet_id);
-	if(! packet){
-		if(ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size))){
-			return NULL;
-		}
-	}
-	return packet;
-}
-
-packet_t packet_get_1(int phone, size_t content){
-	ERROR_DECLARE;
-
-	ipcarg_t packet_id;
-	ipcarg_t size;
-	packet_t packet;
-
-	if(ERROR_OCCURRED(async_req_1_2(phone, NET_PACKET_CREATE_1, content, &packet_id, &size))){
-		return NULL;
-	}
-	packet = pm_find(packet_id);
-	if(! packet){
-		if(ERROR_OCCURRED(packet_return(phone, &packet, packet_id, size))){
-			return NULL;
-		}
-	}
-	return packet;
-}
-
-void pq_release(int phone, packet_id_t packet_id){
-	async_msg_1(phone, NET_PACKET_RELEASE, packet_id);
-}
-
-/** @}
- */
Index: pace/srv/net/structures/packet/packet_server.c
===================================================================
--- uspace/srv/net/structures/packet/packet_server.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,340 +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 server implementation.
- */
-
-#include <align.h>
-#include <assert.h>
-#include <async.h>
-#include <errno.h>
-#include <fibril_synch.h>
-#include <unistd.h>
-
-#include <ipc/ipc.h>
-#include <sys/mman.h>
-
-#include "../../err.h"
-#include "../../messages.h"
-
-#include "packet.h"
-#include "packet_client.h"
-#include "packet_header.h"
-#include "packet_messages.h"
-#include "packet_server.h"
-
-#define FREE_QUEUES_COUNT	7
-
-/** The default address length reserved for new packets.
- */
-#define DEFAULT_ADDR_LEN	32
-
-/** The default prefix reserved for new packets.
- */
-#define DEFAULT_PREFIX		64
-
-/** The default suffix reserved for new packets.
- */
-#define DEFAULT_SUFFIX		64
-
-/** Packet server global data.
- */
-static struct{
-	/** Safety lock.
-	 */
-	fibril_mutex_t lock;
-	/** Free packet queues.
-	 */
-	packet_t free[FREE_QUEUES_COUNT];
-	/** Packet length upper bounds of the free packet queues.
-	 *  The maximal lengths of packets in each queue in the ascending order.
-	 *  The last queue is not limited.
-	 */
-	size_t sizes[FREE_QUEUES_COUNT];
-	/** Total packets allocated.
-	 */
-	unsigned int count;
-} ps_globals = {
-	.lock = {
-		.counter = 1,
-		.waiters = {
-			.prev = &ps_globals.lock.waiters,
-			.next = &ps_globals.lock.waiters,
-		}
-	},
-	.free = {NULL, NULL, NULL, NULL, NULL, NULL, NULL},
-	.sizes = {PAGE_SIZE, PAGE_SIZE * 2, PAGE_SIZE * 4, PAGE_SIZE * 8, PAGE_SIZE * 16, PAGE_SIZE * 32, PAGE_SIZE * 64},
-	.count = 0
-};
-
-/** @name Packet server support functions
- */
-/*@{*/
-
-/** Returns the packet of dimensions at least as given.
- *  Tries to reuse free packets first.
- *  Creates a&nbsp;new packet aligned to the memory page size if none available.
- *  Locks the global data during its processing.
- *  @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 of dimensions at least as given.
- *  @returns NULL if there is not enough memory left.
- */
-packet_t packet_get(size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix);
-
-/** Releases the packet queue.
- *  @param[in] packet_id The first packet identifier.
- *  @returns EOK on success.
- *  @returns ENOENT if there is no such packet.
- */
-int packet_release_wrapper(packet_id_t packet_id);
-
-/** Releases the packet and returns it to the appropriate free packet queue.
- *  Should be used only when the global data are locked.
- *  @param[in] packet The packet to be released.
- */
-void packet_release(packet_t packet);
-
-/** Creates a&nbsp;new packet of dimensions at least as given.
- *  Should be used only when the global data are locked.
- *  @param[in] length The total length of the packet, including the header, the addresses and the data of the packet.
- *  @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 of dimensions at least as given.
- *  @returns NULL if there is not enough memory left.
- */
-packet_t packet_create(size_t length, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix);
-
-/** Clears and initializes the packet according to the given dimensions.
- *  @param[in] packet The packet to be initialized.
- *  @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.
- */
-void packet_init(packet_t packet, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix);
-
-/** Shares the packet memory block.
- *  @param[in] packet The packet to be shared.
- *  @returns EOK on success.
- *  @returns EINVAL if the packet is not valid.
- *  @returns EINVAL if the calling module does not accept the memory.
- *  @returns ENOMEM if the desired and actual sizes differ.
- *  @returns Other error codes as defined for the async_share_in_finalize() function.
- */
-int packet_reply(const packet_t packet);
-
-/*@}*/
-
-int packet_translate(int phone, packet_ref packet, packet_id_t packet_id){
-	if(! packet){
-		return EINVAL;
-	}
-	*packet = pm_find(packet_id);
-	return (*packet) ? EOK : ENOENT;
-}
-
-packet_t packet_get_4(int phone, size_t max_content, size_t addr_len, size_t max_prefix, size_t max_suffix){
-	return packet_get(addr_len, max_prefix, max_content, max_suffix);
-}
-
-packet_t packet_get_1(int phone, size_t content){
-	return packet_get(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, content, DEFAULT_SUFFIX);
-}
-
-void pq_release(int phone, packet_id_t packet_id){
-	(void) packet_release_wrapper(packet_id);
-}
-
-int packet_server_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	packet_t packet;
-
-	*answer_count = 0;
-	switch(IPC_GET_METHOD(*call)){
-		case IPC_M_PHONE_HUNGUP:
-			return EOK;
-		case NET_PACKET_CREATE_1:
-			packet = packet_get(DEFAULT_ADDR_LEN, DEFAULT_PREFIX, IPC_GET_CONTENT(call), DEFAULT_SUFFIX);
-			if(! packet){
-				return ENOMEM;
-			}
-			*answer_count = 2;
-			IPC_SET_ARG1(*answer, packet->packet_id);
-			IPC_SET_ARG2(*answer, packet->length);
-			return EOK;
-		case NET_PACKET_CREATE_4:
-			packet = packet_get(((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(call)) ? IPC_GET_ADDR_LEN(call) : DEFAULT_ADDR_LEN), DEFAULT_PREFIX + IPC_GET_PREFIX(call), IPC_GET_CONTENT(call), DEFAULT_SUFFIX + IPC_GET_SUFFIX(call));
-			if(! packet){
-				return ENOMEM;
-			}
-			*answer_count = 2;
-			IPC_SET_ARG1(*answer, packet->packet_id);
-			IPC_SET_ARG2(*answer, packet->length);
-			return EOK;
-		case NET_PACKET_GET:
-			packet = pm_find(IPC_GET_ID(call));
-			if(! packet_is_valid(packet)){
-				return ENOENT;
-			}
-			return packet_reply(packet);
-		case NET_PACKET_GET_SIZE:
-			packet = pm_find(IPC_GET_ID(call));
-			if(! packet_is_valid(packet)){
-				return ENOENT;
-			}
-			IPC_SET_ARG1(*answer, packet->length);
-			*answer_count = 1;
-			return EOK;
-		case NET_PACKET_RELEASE:
-			return packet_release_wrapper(IPC_GET_ID(call));
-	}
-	return ENOTSUP;
-}
-
-int packet_release_wrapper(packet_id_t packet_id){
-	packet_t packet;
-
-	packet = pm_find(packet_id);
-	if(! packet_is_valid(packet)){
-		return ENOENT;
-	}
-	fibril_mutex_lock(&ps_globals.lock);
-	pq_destroy(packet, packet_release);
-	fibril_mutex_unlock(&ps_globals.lock);
-	return EOK;
-}
-
-void packet_release(packet_t packet){
-	int index;
-	int result;
-
-	// remove debug dump
-//	printf("packet %d released\n", packet->packet_id);
-	for(index = 0; (index < FREE_QUEUES_COUNT - 1) && (packet->length > ps_globals.sizes[index]); ++ index);
-	result = pq_add(&ps_globals.free[index], packet, packet->length, packet->length);
-	assert(result == EOK);
-}
-
-packet_t packet_get(size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix){
-	int index;
-	packet_t packet;
-	size_t length;
-
-	length = ALIGN_UP(sizeof(struct packet) + 2 * addr_len + max_prefix + max_content + max_suffix, PAGE_SIZE);
-	fibril_mutex_lock(&ps_globals.lock);
-	for(index = 0; index < FREE_QUEUES_COUNT - 1; ++ index){
-		if(length <= ps_globals.sizes[index]){
-			packet = ps_globals.free[index];
-			while(packet_is_valid(packet) && (packet->length < length)){
-				packet = pm_find(packet->next);
-			}
-			if(packet_is_valid(packet)){
-				if(packet == ps_globals.free[index]){
-					ps_globals.free[index] = pq_detach(packet);
-				}else{
-					pq_detach(packet);
-				}
-				packet_init(packet, addr_len, max_prefix, max_content, max_suffix);
-				fibril_mutex_unlock(&ps_globals.lock);
-				// remove debug dump
-//				printf("packet %d got\n", packet->packet_id);
-				return packet;
-			}
-		}
-	}
-	packet = packet_create(length, addr_len, max_prefix, max_content, max_suffix);
-	fibril_mutex_unlock(&ps_globals.lock);
-	// remove debug dump
-//	printf("packet %d created\n", packet->packet_id);
-	return packet;
-}
-
-packet_t packet_create(size_t length, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix){
-	ERROR_DECLARE;
-
-	packet_t packet;
-
-	// already locked
-	packet = (packet_t) mmap(NULL, length, PROTO_READ | PROTO_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0);
-	if(packet == MAP_FAILED){
-		return NULL;
-	}
-	++ ps_globals.count;
-	packet->packet_id = ps_globals.count;
-	packet->length = length;
-	packet_init(packet, addr_len, max_prefix, max_content, max_suffix);
-	packet->magic_value = PACKET_MAGIC_VALUE;
-	if(ERROR_OCCURRED(pm_add(packet))){
-		munmap(packet, packet->length);
-		return NULL;
-	}
-	return packet;
-}
-
-void packet_init(packet_t packet, size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix){
-	// clear the packet content
-	bzero(((void *) packet) + sizeof(struct packet), packet->length - sizeof(struct packet));
-	// clear the packet header
-	packet->order = 0;
-	packet->metric = 0;
-	packet->previous = 0;
-	packet->next = 0;
-	packet->addr_len = 0;
-	packet->src_addr = sizeof(struct packet);
-	packet->dest_addr = packet->src_addr + addr_len;
-	packet->max_prefix = max_prefix;
-	packet->max_content = max_content;
-	packet->data_start = packet->dest_addr + addr_len + packet->max_prefix;
-	packet->data_end = packet->data_start;
-}
-
-int packet_reply(const packet_t packet){
-	ipc_callid_t callid;
-	size_t size;
-
-	if(! packet_is_valid(packet)){
-		return EINVAL;
-	}
-	if(async_share_in_receive(&callid, &size) <= 0) return EINVAL;
-	if(size != packet->length){
-		return ENOMEM;
-	}
-	return async_share_in_finalize(callid, packet, PROTO_READ | PROTO_WRITE);
-}
-
-/** @}
- */
Index: pace/srv/net/structures/packet/packet_server.h
===================================================================
--- uspace/srv/net/structures/packet/packet_server.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,63 +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 server.
- *  The hosting module has to be compiled with both the packet.c and the packet_server.c source files.
- *  To function correctly, initialization of the packet map by the pm_init() function has to happen at the first place.
- *  Then the packet messages have to be processed by the packet_server_message() function.
- *  The packet map should be released by the pm_destroy() function during the module termination.
- *  @see IS_NET_PACKET_MESSAGE()
- */
-
-#ifndef __NET_PACKET_SERVER_H__
-#define __NET_PACKET_SERVER_H__
-
-#include <ipc/ipc.h>
-
-/** Processes the packet server message.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns ENOENT if there is no such packet as in the packet message parameter..
- *  @returns ENOTSUP if the message is not known.
- *  @returns Other error codes as defined for the packet_release_wrapper() function.
- */
-int packet_server_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-#endif
-
-/** @}
- */
Index: uspace/srv/net/tl/icmp/Makefile
===================================================================
--- uspace/srv/net/tl/icmp/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/icmp/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,22 +28,12 @@
 #
 
-NET_BASE = ../..
 USPACE_PREFIX = ../../../..
+LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBSOCKET_PREFIX)/include
 BINARY = icmp
 
 SOURCES = \
 	icmp.c \
-	icmp_module.c \
-	icmp_client.c \
-	$(NET_BASE)/checksum.c \
-	$(NET_BASE)/module.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/il/ip/ip_client.c \
-	$(NET_BASE)/il/ip/ip_remote.c \
-	$(NET_BASE)/net/net_remote.c \
-	$(NET_BASE)/structures/measured_strings.c \
-	$(NET_BASE)/structures/packet/packet.c \
-	$(NET_BASE)/structures/packet/packet_client.c \
-	$(NET_BASE)/structures/packet/packet_remote.c
+	icmp_module.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/tl/icmp/icmp.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/icmp/icmp.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -42,39 +42,41 @@
 #include <stdint.h>
 #include <str.h>
-
 #include <ipc/ipc.h>
 #include <ipc/services.h>
-
 #include <sys/time.h>
 #include <sys/types.h>
 
-#include "../../err.h"
-#include "../../messages.h"
-#include "../../modules.h"
-
-#include "../../structures/packet/packet_client.h"
-
-#include "../../include/byteorder.h"
-#include "../../include/checksum.h"
-#include "../../include/icmp_api.h"
-#include "../../include/icmp_client.h"
-#include "../../include/icmp_codes.h"
-#include "../../include/icmp_common.h"
-#include "../../include/icmp_interface.h"
-#include "../../include/il_interface.h"
-#include "../../include/inet.h"
-#include "../../include/ip_client.h"
-#include "../../include/ip_interface.h"
-#include "../../include/ip_protocols.h"
-#include "../../include/net_interface.h"
-#include "../../include/socket_codes.h"
-#include "../../include/socket_errno.h"
-
-#include "../../tl/tl_messages.h"
+#include <net_err.h>
+#include <net_messages.h>
+#include <net_modules.h>
+#include <packet/packet_client.h>
+#include <packet_remote.h>
+#include <net_byteorder.h>
+#include <net_checksum.h>
+#include <icmp_api.h>
+#include <icmp_client.h>
+#include <icmp_codes.h>
+#include <icmp_common.h>
+#include <icmp_interface.h>
+#include <il_interface.h>
+#include <inet.h>
+#include <ip_client.h>
+#include <ip_interface.h>
+#include <ip_protocols.h>
+#include <net_interface.h>
+#include <socket_codes.h>
+#include <socket_errno.h>
+#include <tl_messages.h>
+#include <tl_interface.h>
+#include <tl_local.h>
+#include <icmp_messages.h>
+#include <icmp_header.h>
 
 #include "icmp.h"
-#include "icmp_header.h"
-#include "icmp_messages.h"
 #include "icmp_module.h"
+
+/** ICMP module name.
+ */
+#define NAME	"ICMP protocol"
 
 /** Default ICMP error reporting.
@@ -289,5 +291,5 @@
 	// TODO do not ask all the time
 	ERROR_PROPAGATE(ip_packet_size_req(icmp_globals.ip_phone, -1, &icmp_globals.packet_dimension));
-	packet = packet_get_4(icmp_globals.net_phone, size, icmp_globals.packet_dimension.addr_len, ICMP_HEADER_SIZE + icmp_globals.packet_dimension.prefix, icmp_globals.packet_dimension.suffix);
+	packet = packet_get_4_remote(icmp_globals.net_phone, size, icmp_globals.packet_dimension.addr_len, ICMP_HEADER_SIZE + icmp_globals.packet_dimension.prefix, icmp_globals.packet_dimension.suffix);
 	if(! packet){
 		return ENOMEM;
@@ -627,5 +629,5 @@
 	// compute the reply key
 	reply_key = ICMP_GET_REPLY_KEY(header->un.echo.identifier, header->un.echo.sequence_number);
-	pq_release(icmp_globals.net_phone, packet_get_id(packet));
+	pq_release_remote(icmp_globals.net_phone, packet_get_id(packet));
 	// lock the globals
 	fibril_rwlock_write_lock(&icmp_globals.lock);
@@ -642,5 +644,5 @@
 }
 
-int icmp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+int icmp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
 	ERROR_DECLARE;
 
@@ -650,5 +652,5 @@
 	switch(IPC_GET_METHOD(*call)){
 		case NET_TL_RECEIVED:
-			if(! ERROR_OCCURRED(packet_translate(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
+			if(! ERROR_OCCURRED(packet_translate_remote(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
 				ERROR_CODE = icmp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_ICMP, IPC_GET_ERROR(call));
 			}
@@ -760,20 +762,20 @@
 	switch(IPC_GET_METHOD(*call)){
 		case NET_ICMP_DEST_UNREACH:
-			if(! ERROR_OCCURRED(packet_translate(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
+			if(! ERROR_OCCURRED(packet_translate_remote(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
 				ERROR_CODE = icmp_destination_unreachable_msg(0, ICMP_GET_CODE(call), ICMP_GET_MTU(call), packet);
 			}
 			return ERROR_CODE;
 		case NET_ICMP_SOURCE_QUENCH:
-			if(! ERROR_OCCURRED(packet_translate(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
+			if(! ERROR_OCCURRED(packet_translate_remote(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
 				ERROR_CODE = icmp_source_quench_msg(0, packet);
 			}
 			return ERROR_CODE;
 		case NET_ICMP_TIME_EXCEEDED:
-			if(! ERROR_OCCURRED(packet_translate(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
+			if(! ERROR_OCCURRED(packet_translate_remote(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
 				ERROR_CODE = icmp_time_exceeded_msg(0, ICMP_GET_CODE(call), packet);
 			}
 			return ERROR_CODE;
 		case NET_ICMP_PARAMETERPROB:
-			if(! ERROR_OCCURRED(packet_translate(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
+			if(! ERROR_OCCURRED(packet_translate_remote(icmp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
 				ERROR_CODE = icmp_parameter_problem_msg(0, ICMP_GET_CODE(call), ICMP_GET_POINTER(call), packet);
 			}
@@ -785,5 +787,5 @@
 
 int icmp_release_and_return(packet_t packet, int result){
-	pq_release(icmp_globals.net_phone, packet_get_id(packet));
+	pq_release_remote(icmp_globals.net_phone, packet_get_id(packet));
 	return result;
 }
@@ -820,4 +822,62 @@
 }
 
+/** Default thread for new connections.
+ *
+ *  @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)
+{
+	/*
+	 * Accept the connection
+	 *  - Answer the first IPC_M_CONNECT_ME_TO call.
+	 */
+	ipc_answer_0(iid, EOK);
+	
+	while(true) {
+		ipc_call_t answer;
+		int answer_count;
+		
+		/* Clear the answer structure */
+		refresh_answer(&answer, &answer_count);
+		
+		/* Fetch the next message */
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		/* Process the message */
+		int res = tl_module_message_standalone(callid, &call, &answer,
+		    &answer_count);
+		
+		/* End if said to either by the message or the processing result */
+		if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
+			return;
+		
+		/* Answer the message */
+		answer_call(callid, res, &answer, answer_count);
+	}
+}
+
+/** Starts the module.
+ *
+ *  @param argc The count of the command line arguments. Ignored parameter.
+ *  @param argv The command line parameters. Ignored parameter.
+ *
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for each specific module start function.
+ *
+ */
+int main(int argc, char *argv[])
+{
+	ERROR_DECLARE;
+	
+	/* Start the module */
+	if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection)))
+		return ERROR_CODE;
+	
+	return EOK;
+}
+
 /** @}
  */
Index: uspace/srv/net/tl/icmp/icmp.h
===================================================================
--- uspace/srv/net/tl/icmp/icmp.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/icmp/icmp.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -40,9 +40,7 @@
 #include <fibril_synch.h>
 
-#include "../../include/icmp_codes.h"
-
-#include "../../structures/int_map.h"
-
-#include "icmp_header.h"
+#include <icmp_codes.h>
+#include <adt/int_map.h>
+#include <icmp_header.h>
 
 /** Type definition of the ICMP reply data.
Index: pace/srv/net/tl/icmp/icmp_api.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp_api.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,71 +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 icmp
- *  @{
- */
-
-/** @file
- *  ICMP application interface implementation.
- *  @see icmp_api.h
- */
-
-#include <async.h>
-
-#include <ipc/ipc.h>
-#include <ipc/services.h>
-
-#include <sys/types.h>
-
-#include "../../modules.h"
-
-#include "../../include/icmp_api.h"
-#include "../../include/inet.h"
-#include "../../include/ip_codes.h"
-#include "../../include/socket_codes.h"
-
-#include "icmp_messages.h"
-
-int icmp_echo_msg(int icmp_phone, size_t size, mseconds_t timeout, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, const struct sockaddr * addr, socklen_t addrlen){
-	aid_t message_id;
-	ipcarg_t result;
-
-	if(addrlen <= 0){
-		return EINVAL;
-	}
-	message_id = async_send_5(icmp_phone, NET_ICMP_ECHO, size, timeout, ttl, tos, (ipcarg_t) dont_fragment, NULL);
-	// send the address
-	async_data_write_start(icmp_phone, addr, (size_t) addrlen);
-	// timeout version may cause inconsistency - there is also an inner timer
-	// return async_wait_timeout(message_id, &result, timeout);
-	async_wait_for(message_id, &result);
-	return (int) result;
-}
-
-/** @}
- */
Index: pace/srv/net/tl/icmp/icmp_client.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp_client.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,89 +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 icmp
- *  @{
- */
-
-/** @file
- *  ICMP client interface implementation.
- *  @see icmp_client.h
- */
-
-#include <errno.h>
-
-#ifdef CONFIG_DEBUG
-	#include <stdio.h>
-#endif
-
-#include <sys/types.h>
-
-#include "../../include/icmp_codes.h"
-#include "../../include/icmp_client.h"
-
-#include "../../structures/packet/packet.h"
-#include "../../structures/packet/packet_client.h"
-
-#include "icmp_header.h"
-
-int icmp_client_process_packet(packet_t packet, icmp_type_t * type, icmp_code_t * code, icmp_param_t * pointer, icmp_param_t * mtu){
-	icmp_header_ref header;
-
-	header = (icmp_header_ref) packet_get_data(packet);
-	if((! header)
-		|| (packet_get_data_length(packet) < sizeof(icmp_header_t))){
-		return 0;
-	}
-	if(type){
-		*type = header->type;
-	}
-	if(code){
-		*code = header->code;
-	}
-	if(pointer){
-		*pointer = header->un.param.pointer;
-	}
-	if(mtu){
-		*mtu = header->un.frag.mtu;
-	}
-	// remove debug dump
-#ifdef CONFIG_DEBUG
-	printf("ICMP error %d (%d) in packet %d\n", header->type, header->code, packet_get_id(packet));
-#endif
-	return sizeof(icmp_header_t);
-}
-
-size_t icmp_client_header_length(packet_t packet){
-	if(packet_get_data_length(packet) < sizeof(icmp_header_t)){
-		return 0;
-	}
-	return sizeof(icmp_header_t);
-}
-
-/** @}
- */
Index: pace/srv/net/tl/icmp/icmp_common.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp_common.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,58 +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 icmp
- *  @{
- */
-
-/** @file
- *  ICMP common interface implementation.
- *  @see icmp_common.h
- */
-
-#include <async.h>
-#include <ipc/services.h>
-
-#include "../../modules.h"
-
-#include "../../include/icmp_common.h"
-
-#include "icmp_messages.h"
-
-int icmp_connect_module(services_t service, suseconds_t timeout){
-	int phone;
-
-	phone = connect_to_service_timeout(SERVICE_ICMP, timeout);
-	if(phone >= 0){
-		async_req_0_0(phone, NET_ICMP_INIT);
-	}
-	return phone;
-}
-
-/** @}
- */
Index: pace/srv/net/tl/icmp/icmp_header.h
===================================================================
--- uspace/srv/net/tl/icmp/icmp_header.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,133 +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 icmp
- *  @{
- */
-
-/** @file
- *  ICMP header definition.
- *  Based on the RFC~792.
- */
-
-#ifndef __NET_ICMP_HEADER_H__
-#define __NET_ICMP_HEADER_H__
-
-#include <sys/types.h>
-
-#include "../../include/in.h"
-#include "../../include/icmp_codes.h"
-
-/** ICMP header size in bytes.
- */
-#define ICMP_HEADER_SIZE			sizeof(icmp_header_t)
-
-/** Type definition of the echo specific data.
- *  @see icmp_echo
- */
-typedef struct icmp_echo	icmp_echo_t;
-
-/** Type definition of the echo specific data pointer.
- *  @see icmp_echo
- */
-typedef icmp_echo_t *		icmp_echo_ref;
-
-/** Echo specific data.
- */
-struct icmp_echo{
-	/** Message idintifier.
-	 */
-	icmp_param_t identifier;
-	/** Message sequence number.
-	 */
-	icmp_param_t sequence_number;
-} __attribute__ ((packed));
-
-/** Type definition of the internet control message header.
- *  @see icmp_header
- */
-typedef struct icmp_header	icmp_header_t;
-
-/** Type definition of the internet control message header pointer.
- *  @see icmp_header
- */
-typedef icmp_header_t *		icmp_header_ref;
-
-/** Internet control message header.
- */
-struct icmp_header{
-	/** The type of the message.
-	 */
-	uint8_t type;
-	/** The error code for the datagram reported by the ICMP message.
-	 *  The interpretation is dependent on the message type.
-	 */
-	uint8_t code;
-	/** The checksum is the 16-bit ones's complement of the one's complement sum of the ICMP message starting with the ICMP Type.
-     *  For computing the checksum, the checksum field should be zero.
-	 *  If the checksum does not match the contents, the datagram is discarded.
-	 */
-	uint16_t checksum;
-	/** Message specific data.
-	 */
-	union{
-		/** Echo specific data.
-		 */
-		icmp_echo_t  echo;
-		/** Proposed gateway value.
-		 */
-		in_addr_t gateway;
-		/** Fragmentation needed specific data.
-		 */
-		struct{
-			/** Reserved field.
-			 *  Must be zero.
-			 */
-			icmp_param_t reserved;
-			/** Proposed MTU.
-			 */
-			icmp_param_t mtu;
-		} frag;
-		/** Parameter problem specific data.
-		 */
-		struct{
-			/** Problem pointer.
-			 */
-			icmp_param_t pointer;
-			/** Reserved field.
-			 *  Must be zero.
-			 */
-			icmp_param_t reserved;
-		} param;
-	} un;
-} __attribute__ ((packed));
-
-#endif
-
-/** @}
- */
Index: pace/srv/net/tl/icmp/icmp_messages.h
===================================================================
--- uspace/srv/net/tl/icmp/icmp_messages.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,126 +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 icmp
- *  @{
- */
-
-/** @file
- *  ICMP module messages.
- *  @see icmp_interface.h
- */
-
-#ifndef __NET_ICMP_MESSAGES__
-#define __NET_ICMP_MESSAGES__
-
-#include <ipc/ipc.h>
-
-#include <sys/types.h>
-
-#include "../../include/icmp_codes.h"
-
-#include "../../messages.h"
-
-/** ICMP module messages.
- */
-typedef enum{
-	/** Sends echo request.
-	 *  @see icmp_echo()
-	 */
-	NET_ICMP_ECHO = NET_ICMP_FIRST,
-	/** Sends destination unreachable error message.
-	 *  @see icmp_destination_unreachable_msg()
-	 */
-	NET_ICMP_DEST_UNREACH,
-	/** Sends source quench error message.
-	 *  @see icmp_source_quench_msg()
-	 */
-	NET_ICMP_SOURCE_QUENCH,
-	/** Sends time exceeded error message.
-	 *  @see icmp_time_exceeded_msg()
-	 */
-	NET_ICMP_TIME_EXCEEDED,
-	/** Sends parameter problem error message.
-	 *  @see icmp_parameter_problem_msg()
-	 */
-	NET_ICMP_PARAMETERPROB,
-	/** Initializes new connection.
-	 */
-	NET_ICMP_INIT
-} icmp_messages;
-
-/** @name ICMP specific message parameters definitions
- */
-/*@{*/
-
-/** Returns the ICMP code message parameter.
- *  @param[in] call The message call structure.
- */
-#define ICMP_GET_CODE(call)		(icmp_code_t) IPC_GET_ARG1(*call)
-
-/** Returns the ICMP link MTU message parameter.
- *  @param[in] call The message call structure.
- */
-#define ICMP_GET_MTU(call)		(icmp_param_t) IPC_GET_ARG3(*call)
-
-/** Returns the pointer message parameter.
- *  @param[in] call The message call structure.
- */
-#define ICMP_GET_POINTER(call)		(icmp_param_t) IPC_GET_ARG3(*call)
-
-/** Returns the size message parameter.
- *  @param[in] call The message call structure.
- */
-#define ICMP_GET_SIZE(call)	(size_t) IPC_GET_ARG1(call)
-
-/** Returns the timeout message parameter.
- *  @param[in] call The message call structure.
- */
-#define ICMP_GET_TIMEOUT(call)	((suseconds_t) IPC_GET_ARG2(call))
-
-/** Returns the time to live message parameter.
- *  @param[in] call The message call structure.
- */
-#define ICMP_GET_TTL(call)	(ip_ttl_t) IPC_GET_ARG3(call)
-
-/** Returns the type of service message parameter.
- *  @param[in] call The message call structure.
- */
-#define ICMP_GET_TOS(call)	(ip_tos_t) IPC_GET_ARG4(call)
-
-/** Returns the dont fragment message parameter.
- *  @param[in] call The message call structure.
- */
-#define ICMP_GET_DONT_FRAGMENT(call)		(int) IPC_GET_ARG5(call)
-
-/*@}*/
-
-#endif
-
-/** @}
- */
Index: uspace/srv/net/tl/icmp/icmp_module.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp_module.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/icmp/icmp_module.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -40,26 +40,19 @@
 #include <async.h>
 #include <stdio.h>
-
 #include <ipc/ipc.h>
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../modules.h"
-
-#include "../../structures/packet/packet.h"
-
-#include "../../include/net_interface.h"
+#include <net_err.h>
+#include <net_modules.h>
+#include <packet/packet.h>
+#include <net_interface.h>
+#include <tl_local.h>
 
 #include "icmp.h"
 #include "icmp_module.h"
 
-/** ICMP module name.
+/** ICMP module global data.
  */
-#define NAME	"ICMP protocol"
-
-/** Prints the module name.
- *  @see NAME
- */
-void module_print_name(void);
+extern icmp_globals_t	icmp_globals;
 
 /** Starts the ICMP module.
@@ -70,25 +63,5 @@
  *  @returns Other error codes as defined for the REGISTER_ME() macro function.
  */
-int module_start(async_client_conn_t client_connection);
-
-/** Processes the ICMP message.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the icmp_message() function.
- */
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-/** ICMP module global data.
- */
-extern icmp_globals_t	icmp_globals;
-
-void module_print_name(void){
-	printf("%s", NAME);
-}
-
-int module_start(async_client_conn_t client_connection){
+int tl_module_start_standalone(async_client_conn_t client_connection){
 	ERROR_DECLARE;
 
@@ -113,6 +86,14 @@
 }
 
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	return icmp_message(callid, call, answer, answer_count);
+/** Processes the ICMP message.
+ *  @param[in] callid The message identifier.
+ *  @param[in] call The message parameters.
+ *  @param[out] answer The message answer parameters.
+ *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for the icmp_message() function.
+ */
+int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+	return icmp_message_standalone(callid, call, answer, answer_count);
 }
 
Index: uspace/srv/net/tl/icmp/icmp_module.h
===================================================================
--- uspace/srv/net/tl/icmp/icmp_module.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/icmp/icmp_module.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -59,5 +59,5 @@
  *  @see IS_NET_ICMP_MESSAGE()
  */
-int icmp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
+int icmp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
 
 #endif
Index: pace/srv/net/tl/icmp/icmp_remote.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp_remote.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,76 +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 icmp
- *  @{
- */
-
-/** @file
- *  ICMP interface implementation for standalone remote modules.
- *  @see icmp_interface.h
- */
-
-#include <async.h>
-#include <errno.h>
-
-#include <ipc/ipc.h>
-#include <ipc/services.h>
-
-#include <sys/types.h>
-
-#include "../../messages.h"
-#include "../../modules.h"
-
-#include "../../include/icmp_interface.h"
-
-#include "../../structures/packet/packet_client.h"
-
-#include "icmp_messages.h"
-
-int icmp_destination_unreachable_msg(int icmp_phone, icmp_code_t code, icmp_param_t mtu, packet_t packet){
-	async_msg_3(icmp_phone, NET_ICMP_DEST_UNREACH, (ipcarg_t) code, (ipcarg_t) packet_get_id(packet), (ipcarg_t) mtu);
-	return EOK;
-}
-
-int icmp_source_quench_msg(int icmp_phone, packet_t packet){
-	async_msg_2(icmp_phone, NET_ICMP_SOURCE_QUENCH, 0, (ipcarg_t) packet_get_id(packet));
-	return EOK;
-}
-
-int icmp_time_exceeded_msg(int icmp_phone, icmp_code_t code, packet_t packet){
-	async_msg_2(icmp_phone, NET_ICMP_TIME_EXCEEDED, (ipcarg_t) code, (ipcarg_t) packet_get_id(packet));
-	return EOK;
-}
-
-int icmp_parameter_problem_msg(int icmp_phone, icmp_code_t code, icmp_param_t pointer, packet_t packet){
-	async_msg_3(icmp_phone, NET_ICMP_PARAMETERPROB, (ipcarg_t) code, (ipcarg_t) packet_get_id(packet), (ipcarg_t) pointer);
-	return EOK;
-}
-
-/** @}
- */
Index: uspace/srv/net/tl/tcp/Makefile
===================================================================
--- uspace/srv/net/tl/tcp/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/tcp/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,28 +28,12 @@
 #
 
-NET_BASE = ../..
 USPACE_PREFIX = ../../../..
+LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBSOCKET_PREFIX)/include
 BINARY = tcp
 
 SOURCES = \
 	tcp.c \
-	tcp_module.c \
-	$(NET_BASE)/checksum.c \
-	$(NET_BASE)/module.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/il/ip/ip_client.c \
-	$(NET_BASE)/il/ip/ip_remote.c \
-	$(NET_BASE)/net/net_remote.c \
-	$(NET_BASE)/socket/socket_core.c \
-	$(NET_BASE)/tl/icmp/icmp_client.c \
-	$(NET_BASE)/tl/icmp/icmp_common.c \
-	$(NET_BASE)/tl/icmp/icmp_remote.c \
-	$(NET_BASE)/tl/tl_common.c \
-	$(NET_BASE)/structures/char_map.c \
-	$(NET_BASE)/structures/dynamic_fifo.c \
-	$(NET_BASE)/structures/measured_strings.c \
-	$(NET_BASE)/structures/packet/packet.c \
-	$(NET_BASE)/structures/packet/packet_client.c \
-	$(NET_BASE)/structures/packet/packet_remote.c
+	tcp_module.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/tl/tcp/tcp.c
===================================================================
--- uspace/srv/net/tl/tcp/tcp.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/tcp/tcp.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -46,34 +46,37 @@
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../messages.h"
-#include "../../modules.h"
-
-#include "../../structures/dynamic_fifo.h"
-#include "../../structures/packet/packet_client.h"
-
-#include "../../include/checksum.h"
-#include "../../include/in.h"
-#include "../../include/in6.h"
-#include "../../include/inet.h"
-#include "../../include/ip_client.h"
-#include "../../include/ip_interface.h"
-#include "../../include/ip_protocols.h"
-#include "../../include/icmp_client.h"
-#include "../../include/icmp_interface.h"
-#include "../../include/net_interface.h"
-#include "../../include/socket_codes.h"
-#include "../../include/socket_errno.h"
-#include "../../include/tcp_codes.h"
-
-#include "../../socket/socket_core.h"
-#include "../../socket/socket_messages.h"
-
-#include "../tl_common.h"
-#include "../tl_messages.h"
+#include <net_err.h>
+#include <net_messages.h>
+#include <net_modules.h>
+#include <adt/dynamic_fifo.h>
+#include <packet/packet_client.h>
+#include <packet_remote.h>
+#include <net_checksum.h>
+#include <in.h>
+#include <in6.h>
+#include <inet.h>
+#include <ip_client.h>
+#include <ip_interface.h>
+#include <ip_protocols.h>
+#include <icmp_client.h>
+#include <icmp_interface.h>
+#include <net_interface.h>
+#include <socket_codes.h>
+#include <socket_errno.h>
+#include <tcp_codes.h>
+#include <socket_core.h>
+#include <socket_messages.h>
+#include <tl_common.h>
+#include <tl_messages.h>
+#include <tl_local.h>
+#include <tl_interface.h>
 
 #include "tcp.h"
 #include "tcp_header.h"
 #include "tcp_module.h"
+
+/** TCP module name.
+ */
+#define NAME	"TCP protocol"
 
 /** The TCP window default value.
@@ -421,5 +424,5 @@
 			break;
 		default:
-			pq_release(tcp_globals.net_phone, packet_get_id(packet));
+			pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 	}
 
@@ -473,5 +476,5 @@
 			// release the acknowledged packets
 			next_packet = pq_next(packet);
-			pq_release(tcp_globals.net_phone, packet_get_id(packet));
+			pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 			packet = next_packet;
 			offset -= length;
@@ -517,5 +520,5 @@
 			next_packet = pq_next(next_packet);
 			pq_insert_after(tmp_packet, next_packet);
-			pq_release(tcp_globals.net_phone, packet_get_id(tmp_packet));
+			pq_release_remote(tcp_globals.net_phone, packet_get_id(tmp_packet));
 		}
 		assert(new_sequence_number + total_length == socket_data->next_incoming + socket_data->window);
@@ -548,5 +551,5 @@
 					socket_data->incoming = next_packet;
 				}
-				pq_release(tcp_globals.net_phone, packet_get_id(packet));
+				pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 				packet = next_packet;
 				continue;
@@ -568,5 +571,5 @@
 				if(length <= 0){
 					// remove the empty packet
-					pq_release(tcp_globals.net_phone, packet_get_id(packet));
+					pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 					packet = next_packet;
 					continue;
@@ -595,5 +598,5 @@
 				}
 				// remove the duplicit or corrupted packet
-				pq_release(tcp_globals.net_phone, packet_get_id(packet));
+				pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 				packet = next_packet;
 				continue;
@@ -617,6 +620,6 @@
 		if(ERROR_OCCURRED(pq_add(&socket_data->incoming, packet, new_sequence_number, length))){
 			// remove the corrupted packets
-			pq_release(tcp_globals.net_phone, packet_get_id(packet));
-			pq_release(tcp_globals.net_phone, packet_get_id(next_packet));
+			pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
+			pq_release_remote(tcp_globals.net_phone, packet_get_id(next_packet));
 		}else{
 			while(next_packet){
@@ -626,5 +629,5 @@
 				if(ERROR_OCCURRED(pq_set_order(next_packet, new_sequence_number, length))
 					|| ERROR_OCCURRED(pq_insert_after(packet, next_packet))){
-					pq_release(tcp_globals.net_phone, packet_get_id(next_packet));
+					pq_release_remote(tcp_globals.net_phone, packet_get_id(next_packet));
 				}
 				next_packet = tmp_packet;
@@ -634,5 +637,5 @@
 		printf("unexpected\n");
 		// release duplicite or restricted
-		pq_release(tcp_globals.net_phone, packet_get_id(packet));
+		pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 	}
 
@@ -679,5 +682,5 @@
 	// queue the received packet
 	if(ERROR_OCCURRED(dyn_fifo_push(&socket->received, packet_get_id(packet), SOCKET_MAX_RECEIVED_SIZE))
-		|| ERROR_OCCURRED(tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, socket_data->device_id, &packet_dimension))){
+	    || ERROR_OCCURRED(tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, socket_data->device_id, &packet_dimension))){
 		return tcp_release_and_return(packet, ERROR_CODE);
 	}
@@ -710,5 +713,5 @@
 		next_packet = pq_detach(packet);
 		if(next_packet){
-			pq_release(tcp_globals.net_phone, packet_get_id(next_packet));
+			pq_release_remote(tcp_globals.net_phone, packet_get_id(next_packet));
 		}
 		// trim if longer than the header
@@ -780,5 +783,5 @@
 				free(socket_data->addr);
 				free(socket_data);
-				pq_release(tcp_globals.net_phone, packet_get_id(packet));
+				pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 				return ERROR_CODE;
 			}
@@ -846,5 +849,5 @@
 			next_packet = pq_detach(packet);
 			if(next_packet){
-				pq_release(tcp_globals.net_phone, packet_get_id(next_packet));
+				pq_release_remote(tcp_globals.net_phone, packet_get_id(next_packet));
 			}
 			// trim if longer than the header
@@ -895,5 +898,5 @@
 
 		socket_data->next_incoming = ntohl(header->sequence_number);// + 1;
-		pq_release(tcp_globals.net_phone, packet_get_id(packet));
+		pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 		socket_data->state = TCP_SOCKET_ESTABLISHED;
 		listening_socket = socket_cores_find(socket_data->local_sockets, socket_data->listening_socket_id);
@@ -981,5 +984,5 @@
 					// add to acknowledged or release
 					if(pq_add(&acknowledged, packet, 0, 0) != EOK){
-						pq_release(tcp_globals.net_phone, packet_get_id(packet));
+						pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 					}
 					packet = next;
@@ -990,5 +993,5 @@
 			// release acknowledged
 			if(acknowledged){
-				pq_release(tcp_globals.net_phone, packet_get_id(acknowledged));
+				pq_release_remote(tcp_globals.net_phone, packet_get_id(acknowledged));
 			}
 			return;
@@ -1006,5 +1009,5 @@
 }
 
-int tcp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+int tcp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
 	ERROR_DECLARE;
 
@@ -1019,5 +1022,5 @@
 		case NET_TL_RECEIVED:
 			//fibril_rwlock_read_lock(&tcp_globals.lock);
-			if(! ERROR_OCCURRED(packet_translate(tcp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
+			if(! ERROR_OCCURRED(packet_translate_remote(tcp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
 				ERROR_CODE = tcp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_TCP, IPC_GET_ERROR(call));
 			}
@@ -1062,4 +1065,5 @@
 	int socket_id;
 	size_t addrlen;
+	size_t size;
 	fibril_rwlock_t lock;
 	ipc_call_t answer;
@@ -1107,12 +1111,12 @@
 					socket_id = SOCKET_GET_SOCKET_ID(call);
 					res = socket_create(&local_sockets, app_phone, socket_data, &socket_id);
-					*SOCKET_SET_SOCKET_ID(answer) = socket_id;
+					SOCKET_SET_SOCKET_ID(answer, socket_id);
 					fibril_rwlock_write_unlock(&lock);
 					if(res == EOK){
-						if(tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, DEVICE_INVALID_ID, &packet_dimension) == EOK){
-							*SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = ((packet_dimension->content < socket_data->data_fragment_size) ? packet_dimension->content : socket_data->data_fragment_size);
+						if (tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, DEVICE_INVALID_ID, &packet_dimension) == EOK){
+							SOCKET_SET_DATA_FRAGMENT_SIZE(answer, ((packet_dimension->content < socket_data->data_fragment_size) ? packet_dimension->content : socket_data->data_fragment_size));
 						}
-//						*SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = MAX_TCP_FRAGMENT_SIZE;
-						*SOCKET_SET_HEADER_SIZE(answer) = TCP_HEADER_SIZE;
+//						SOCKET_SET_DATA_FRAGMENT_SIZE(answer, MAX_TCP_FRAGMENT_SIZE);
+						SOCKET_SET_HEADER_SIZE(answer, TCP_HEADER_SIZE);
 						answer_count = 3;
 					}else{
@@ -1166,10 +1170,11 @@
 				fibril_rwlock_read_lock(&tcp_globals.lock);
 				fibril_rwlock_write_lock(&lock);
-				res = tcp_accept_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), SOCKET_GET_NEW_SOCKET_ID(call), SOCKET_SET_DATA_FRAGMENT_SIZE(answer), &addrlen);
+				res = tcp_accept_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), SOCKET_GET_NEW_SOCKET_ID(call), &size, &addrlen);
+				SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
 				fibril_rwlock_write_unlock(&lock);
 				fibril_rwlock_read_unlock(&tcp_globals.lock);
 				if(res > 0){
-					*SOCKET_SET_SOCKET_ID(answer) = res;
-					*SOCKET_SET_ADDRESS_LENGTH(answer) = addrlen;
+					SOCKET_SET_SOCKET_ID(answer, res);
+					SOCKET_SET_ADDRESS_LENGTH(answer, addrlen);
 					answer_count = 3;
 				}
@@ -1178,5 +1183,6 @@
 				fibril_rwlock_read_lock(&tcp_globals.lock);
 				fibril_rwlock_write_lock(&lock);
-				res = tcp_send_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), SOCKET_GET_DATA_FRAGMENTS(call), SOCKET_SET_DATA_FRAGMENT_SIZE(answer), SOCKET_GET_FLAGS(call));
+				res = tcp_send_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), SOCKET_GET_DATA_FRAGMENTS(call), &size, SOCKET_GET_FLAGS(call));
+				SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
 				if(res != EOK){
 					fibril_rwlock_write_unlock(&lock);
@@ -1191,5 +1197,6 @@
 					fibril_rwlock_read_lock(&tcp_globals.lock);
 					fibril_rwlock_write_lock(&lock);
-					res = tcp_send_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), SOCKET_GET_DATA_FRAGMENTS(call), SOCKET_SET_DATA_FRAGMENT_SIZE(answer), SOCKET_GET_FLAGS(call));
+					res = tcp_send_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), SOCKET_GET_DATA_FRAGMENTS(call), &size, SOCKET_GET_FLAGS(call));
+					SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
 					if(res != EOK){
 						fibril_rwlock_write_unlock(&lock);
@@ -1208,5 +1215,5 @@
 				fibril_rwlock_read_unlock(&tcp_globals.lock);
 				if(res > 0){
-					*SOCKET_SET_READ_DATA_LENGTH(answer) = res;
+					SOCKET_SET_READ_DATA_LENGTH(answer, res);
 					answer_count = 1;
 					res = EOK;
@@ -1220,6 +1227,6 @@
 				fibril_rwlock_read_unlock(&tcp_globals.lock);
 				if(res > 0){
-					*SOCKET_SET_READ_DATA_LENGTH(answer) = res;
-					*SOCKET_SET_ADDRESS_LENGTH(answer) = addrlen;
+					SOCKET_SET_READ_DATA_LENGTH(answer, res);
+					SOCKET_SET_ADDRESS_LENGTH(answer, addrlen);
 					answer_count = 3;
 					res = EOK;
@@ -1561,5 +1568,5 @@
 			}else{
 				if(ERROR_OCCURRED(pq_insert_after(previous, copy))){
-					pq_release(tcp_globals.net_phone, packet_get_id(copy));
+					pq_release_remote(tcp_globals.net_phone, packet_get_id(copy));
 					return sending;
 				}
@@ -1593,5 +1600,5 @@
 	// adjust the pseudo header
 	if(ERROR_OCCURRED(ip_client_set_pseudo_header_data_length(socket_data->pseudo_header, socket_data->headerlen, packet_get_data_length(packet)))){
-		pq_release(tcp_globals.net_phone, packet_get_id(packet));
+		pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 		return NULL;
 	}
@@ -1600,5 +1607,5 @@
 	header = (tcp_header_ref) packet_get_data(packet);
 	if(! header){
-		pq_release(tcp_globals.net_phone, packet_get_id(packet));
+		pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 		return NULL;
 	}
@@ -1621,5 +1628,5 @@
 	// prepare the timeout
 		|| ERROR_OCCURRED(tcp_prepare_timeout(tcp_timeout, socket, socket_data, sequence_number, socket_data->state, socket_data->timeout, true))){
-		pq_release(tcp_globals.net_phone, packet_get_id(packet));
+		pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 		return NULL;
 	}
@@ -1746,5 +1753,5 @@
 		return NO_DATA;
 	}
-	ERROR_PROPAGATE(packet_translate(tcp_globals.net_phone, &packet, packet_id));
+	ERROR_PROPAGATE(packet_translate_remote(tcp_globals.net_phone, &packet, packet_id));
 
 	// reply the packets
@@ -1753,5 +1760,5 @@
 	// release the packet
 	dyn_fifo_pop(&socket->received);
-	pq_release(tcp_globals.net_phone, packet_get_id(packet));
+	pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 	// return the total length
 	return (int) length;
@@ -1885,5 +1892,5 @@
 	ERROR_PROPAGATE(tl_get_ip_packet_dimension(tcp_globals.ip_phone, &tcp_globals.dimensions, socket_data->device_id, &packet_dimension));
 	// get a new packet
-	*packet = packet_get_4(tcp_globals.net_phone, TCP_HEADER_SIZE, packet_dimension->addr_len, packet_dimension->prefix, packet_dimension->suffix);
+	*packet = packet_get_4_remote(tcp_globals.net_phone, TCP_HEADER_SIZE, packet_dimension->addr_len, packet_dimension->prefix, packet_dimension->suffix);
 	if(! * packet){
 		return ENOMEM;
@@ -1989,8 +1996,66 @@
 
 int tcp_release_and_return(packet_t packet, int result){
-	pq_release(tcp_globals.net_phone, packet_get_id(packet));
+	pq_release_remote(tcp_globals.net_phone, packet_get_id(packet));
 	return result;
 }
 
+/** Default thread for new connections.
+ *
+ *  @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)
+{
+	/*
+	 * Accept the connection
+	 *  - Answer the first IPC_M_CONNECT_ME_TO call.
+	 */
+	ipc_answer_0(iid, EOK);
+	
+	while(true) {
+		ipc_call_t answer;
+		int answer_count;
+		
+		/* Clear the answer structure */
+		refresh_answer(&answer, &answer_count);
+		
+		/* Fetch the next message */
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		/* Process the message */
+		int res = tl_module_message_standalone(callid, &call, &answer,
+		    &answer_count);
+		
+		/* End if said to either by the message or the processing result */
+		if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
+			return;
+		
+		/* Answer the message */
+		answer_call(callid, res, &answer, answer_count);
+	}
+}
+
+/** Starts the module.
+ *
+ *  @param argc The count of the command line arguments. Ignored parameter.
+ *  @param argv The command line parameters. Ignored parameter.
+ *
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for each specific module start function.
+ *
+ */
+int main(int argc, char *argv[])
+{
+	ERROR_DECLARE;
+	
+	/* Start the module */
+	if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection)))
+		return ERROR_CODE;
+	
+	return EOK;
+}
+
 /** @}
  */
Index: uspace/srv/net/tl/tcp/tcp.h
===================================================================
--- uspace/srv/net/tl/tcp/tcp.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/tcp/tcp.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -40,11 +40,8 @@
 #include <fibril_synch.h>
 
-#include "../../structures/packet/packet.h"
-
-#include "../../include/device.h"
-
-#include "../../socket/socket_core.h"
-
-#include "../tl_common.h"
+#include <packet/packet.h>
+#include <net_device.h>
+#include <socket_core.h>
+#include <tl_common.h>
 
 /** Type definition of the TCP global data.
@@ -235,5 +232,5 @@
 	/** IP pseudo header.
 	 */
-	ip_pseudo_header_ref pseudo_header;
+	void *pseudo_header;
 	/** IP pseudo header length.
 	 */
Index: uspace/srv/net/tl/tcp/tcp_module.c
===================================================================
--- uspace/srv/net/tl/tcp/tcp_module.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/tcp/tcp_module.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -40,28 +40,21 @@
 #include <async.h>
 #include <stdio.h>
-
 #include <ipc/ipc.h>
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../modules.h"
-
-#include "../../structures/packet/packet.h"
-
-#include "../../include/net_interface.h"
-#include "../../include/ip_protocols.h"
-#include "../../include/ip_interface.h"
+#include <net_err.h>
+#include <net_modules.h>
+#include <packet/packet.h>
+#include <net_interface.h>
+#include <ip_protocols.h>
+#include <ip_interface.h>
+#include <tl_local.h>
 
 #include "tcp.h"
 #include "tcp_module.h"
 
-/** TCP module name.
+/** TCP module global data.
  */
-#define NAME	"TCP protocol"
-
-/** Prints the module name.
- *  @see NAME
- */
-void module_print_name(void);
+extern tcp_globals_t	tcp_globals;
 
 /** Starts the TCP module.
@@ -72,5 +65,24 @@
  *  @returns Other error codes as defined for the REGISTER_ME() macro function.
  */
-int module_start(async_client_conn_t client_connection);
+int tl_module_start_standalone(async_client_conn_t client_connection)
+{
+	ERROR_DECLARE;
+	
+	async_set_client_connection(client_connection);
+	tcp_globals.net_phone = net_connect_module(SERVICE_NETWORKING);
+	ERROR_PROPAGATE(pm_init());
+	
+	ipcarg_t phonehash;
+	if (ERROR_OCCURRED(tcp_initialize(client_connection))
+	    || ERROR_OCCURRED(REGISTER_ME(SERVICE_TCP, &phonehash))) {
+		pm_destroy();
+		return ERROR_CODE;
+	}
+	
+	async_manager();
+	
+	pm_destroy();
+	return EOK;
+}
 
 /** Processes the TCP message.
@@ -82,36 +94,6 @@
  *  @returns Other error codes as defined for the tcp_message() function.
  */
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-/** TCP module global data.
- */
-extern tcp_globals_t	tcp_globals;
-
-void module_print_name(void){
-	printf("%s", NAME);
-}
-
-int module_start(async_client_conn_t client_connection){
-	ERROR_DECLARE;
-
-	ipcarg_t phonehash;
-
-	async_set_client_connection(client_connection);
-	tcp_globals.net_phone = net_connect_module(SERVICE_NETWORKING);
-	ERROR_PROPAGATE(pm_init());
-	if(ERROR_OCCURRED(tcp_initialize(client_connection))
-		|| ERROR_OCCURRED(REGISTER_ME(SERVICE_TCP, &phonehash))){
-		pm_destroy();
-		return ERROR_CODE;
-	}
-
-	async_manager();
-
-	pm_destroy();
-	return EOK;
-}
-
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	return tcp_message(callid, call, answer, answer_count);
+int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+	return tcp_message_standalone(callid, call, answer, answer_count);
 }
 
Index: uspace/srv/net/tl/tcp/tcp_module.h
===================================================================
--- uspace/srv/net/tl/tcp/tcp_module.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/tcp/tcp_module.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -47,5 +47,5 @@
  *  @returns ENOMEM if there is not enough memory left.
  */
-int tcp_initialize(async_client_conn_t client_connection);
+extern int tcp_initialize(async_client_conn_t client_connection);
 
 /** Processes the TCP message.
@@ -59,5 +59,5 @@
  *  @see IS_NET_TCP_MESSAGE()
  */
-int tcp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
+extern int tcp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
 
 #endif
Index: pace/srv/net/tl/tl_common.c
===================================================================
--- uspace/srv/net/tl/tl_common.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,226 +1,0 @@
-/*
- * Copyright (c) 2008 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_tl
- *  @{
- */
-
-/** @file
- *  Transport layer common functions implementation.
- *  @see tl_common.h
- */
-
-#include <async.h>
-#include <ipc/services.h>
-
-#include "../err.h"
-
-#include "../structures/packet/packet.h"
-#include "../structures/packet/packet_client.h"
-
-#include "../include/device.h"
-#include "../include/icmp_interface.h"
-#include "../include/in.h"
-#include "../include/in6.h"
-#include "../include/inet.h"
-#include "../include/ip_interface.h"
-#include "../include/socket_codes.h"
-#include "../include/socket_errno.h"
-
-#include "tl_common.h"
-
-DEVICE_MAP_IMPLEMENT(packet_dimensions, packet_dimension_t);
-
-int tl_get_address_port(const struct sockaddr * addr, int addrlen, uint16_t * port){
-	const struct sockaddr_in * address_in;
-	const struct sockaddr_in6 * address_in6;
-
-	if((addrlen <= 0) || ((size_t) addrlen < sizeof(struct sockaddr))){
-		return EINVAL;
-	}
-	switch(addr->sa_family){
-		case AF_INET:
-			if(addrlen != sizeof(struct sockaddr_in)){
-				return EINVAL;
-			}
-			address_in = (struct sockaddr_in *) addr;
-			*port = ntohs(address_in->sin_port);
-			break;
-		case AF_INET6:
-			if(addrlen != sizeof(struct sockaddr_in6)){
-				return EINVAL;
-			}
-			address_in6 = (struct sockaddr_in6 *) addr;
-			*port = ntohs(address_in6->sin6_port);
-			break;
-		default:
-			return EAFNOSUPPORT;
-	}
-	return EOK;
-}
-
-int tl_get_ip_packet_dimension(int ip_phone, packet_dimensions_ref packet_dimensions, device_id_t device_id, packet_dimension_ref * packet_dimension){
-	ERROR_DECLARE;
-
-	if(! packet_dimension){
-		return EBADMEM;
-	}
-
-	*packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
-	if(! * packet_dimension){
-		// ask for and remember them if not found
-		*packet_dimension = malloc(sizeof(** packet_dimension));
-		if(! * packet_dimension){
-			return ENOMEM;
-		}
-		if(ERROR_OCCURRED(ip_packet_size_req(ip_phone, device_id, * packet_dimension))){
-			free(*packet_dimension);
-			return ERROR_CODE;
-		}
-		ERROR_CODE = packet_dimensions_add(packet_dimensions, device_id, * packet_dimension);
-		if(ERROR_CODE < 0){
-			free(*packet_dimension);
-			return ERROR_CODE;
-		}
-	}
-	return EOK;
-}
-
-int tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, device_id_t device_id, size_t content){
-	packet_dimension_ref packet_dimension;
-
-	packet_dimension = packet_dimensions_find(packet_dimensions, device_id);
-	if(! packet_dimension){
-		return ENOENT;
-	}
-	packet_dimension->content = content;
-	if(device_id != DEVICE_INVALID_ID){
-		packet_dimension = packet_dimensions_find(packet_dimensions, DEVICE_INVALID_ID);
-		if(packet_dimension){
-			if(packet_dimension->content >= content){
-				packet_dimension->content = content;
-			}else{
-				packet_dimensions_exclude(packet_dimensions, DEVICE_INVALID_ID);
-			}
-		}
-	}
-	return EOK;
-}
-
-int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port){
-	struct sockaddr_in * address_in;
-	struct sockaddr_in6 * address_in6;
-	size_t length;
-
-	if(addrlen < 0){
-		return EINVAL;
-	}
-	length = (size_t) addrlen;
-	if(length < sizeof(struct sockaddr)){
-		return EINVAL;
-	}
-	switch(addr->sa_family){
-		case AF_INET:
-			if(length != sizeof(struct sockaddr_in)){
-				return EINVAL;
-			}
-			address_in = (struct sockaddr_in *) addr;
-			address_in->sin_port = htons(port);
-			return EOK;
-		case AF_INET6:
-			if(length != sizeof(struct sockaddr_in6)){
-				return EINVAL;
-			}
-			address_in6 = (struct sockaddr_in6 *) addr;
-			address_in6->sin6_port = htons(port);
-			return EOK;
-		default:
-			return EAFNOSUPPORT;
-	}
-}
-
-int tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, services_t error){
-	packet_t next;
-	uint8_t * src;
-	int length;
-
-	// detach the first packet and release the others
-	next = pq_detach(packet);
-	if(next){
-		pq_release(packet_phone, packet_get_id(next));
-	}
-	length = packet_get_addr(packet, &src, NULL);
-	if((length > 0)
-		&& (! error)
-		&& (icmp_phone >= 0)
-	// set both addresses to the source one (avoids the source address deletion before setting the destination one)
-		&& (packet_set_addr(packet, src, src, (size_t) length) == EOK)){
-		return EOK;
-	}else{
-		pq_release(packet_phone, packet_get_id(packet));
-	}
-	return ENOENT;
-}
-
-int tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix, const packet_dimension_ref dimension, const struct sockaddr * addr, socklen_t addrlen){
-	ERROR_DECLARE;
-
-	ipc_callid_t callid;
-	size_t length;
-	void * data;
-
-	if(! dimension){
-		return EINVAL;
-	}
-	// get the data length
-	if(! async_data_write_receive(&callid, &length)){
-		return EINVAL;
-	}
-	// get a new packet
-	*packet = packet_get_4(packet_phone, length, dimension->addr_len, prefix + dimension->prefix, dimension->suffix);
-	if(! packet){
-		return ENOMEM;
-	}
-	// allocate space in the packet
-	data = packet_suffix(*packet, length);
-	if(! data){
-		pq_release(packet_phone, packet_get_id(*packet));
-		return ENOMEM;
-	}
-	// read the data into the packet
-	if(ERROR_OCCURRED(async_data_write_finalize(callid, data, length))
-	// set the packet destination address
-		|| ERROR_OCCURRED(packet_set_addr(*packet, NULL, (uint8_t *) addr, addrlen))){
-		pq_release(packet_phone, packet_get_id(*packet));
-		return ERROR_CODE;
-	}
-	return (int) length;
-}
-
-/** @}
- */
Index: pace/srv/net/tl/tl_common.h
===================================================================
--- uspace/srv/net/tl/tl_common.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,128 +1,0 @@
-/*
- * Copyright (c) 2008 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_tl
- *  @{
- */
-
-/** @file
- *  Transport layer common functions.
- */
-
-#ifndef __NET_TL_COMMON_H__
-#define __NET_TL_COMMON_H__
-
-#include "../structures/packet/packet.h"
-
-#include "../include/device.h"
-#include "../include/inet.h"
-#include "../include/socket_codes.h"
-
-/** Device packet dimensions.
- *  Maps devices to the packet dimensions.
- *  @see device.h
- */
-DEVICE_MAP_DECLARE(packet_dimensions, packet_dimension_t);
-
-/** Gets the address port.
- *  Supports AF_INET and AF_INET6 address families.
- *  @param[in,out] addr The address to be updated.
- *  @param[in] addrlen The address length.
- *  @param[out] port The set port.
- *  @returns EOK on success.
- *  @returns EINVAL if the address length does not match the address family.
- *  @returns EAFNOSUPPORT if the address family is not supported.
- */
-int tl_get_address_port(const struct sockaddr * addr, int addrlen, uint16_t * port);
-
-/** Gets IP packet dimensions.
- *  Tries to search a cache and queries the IP module if not found.
- *  The reply is cached then.
- *  @param[in] ip_phone The IP moduel phone for (semi)remote calls.
- *  @param[in] packet_dimensions The packet dimensions cache.
- *  @param[in] device_id The device identifier.
- *  @param[out] packet_dimension The IP packet dimensions.
- *  @returns EOK on success.
- *  @returns EBADMEM if the packet_dimension parameter is NULL.
- *  @return ENOMEM if there is not enough memory left.
- *  @returns EINVAL if the packet_dimensions cache is not valid.
- *  @returns Other codes as defined for the ip_packet_size_req() function.
- */
-int tl_get_ip_packet_dimension(int ip_phone, packet_dimensions_ref packet_dimensions, device_id_t device_id, packet_dimension_ref * packet_dimension);
-
-/** Updates IP device packet dimensions cache.
- *  @param[in,out] packet_dimensions The packet dimensions cache.
- *  @param[in] device_id The device identifier.
- *  @param[in] content The new maximum content size.
- *  @returns EOK on success.
- *  @returns ENOENT if the packet dimension is not cached.
- */
-int tl_update_ip_packet_dimension(packet_dimensions_ref packet_dimensions, device_id_t device_id, size_t content);
-
-/** Sets the address port.
- *  Supports AF_INET and AF_INET6 address families.
- *  @param[in,out] addr The address to be updated.
- *  @param[in] addrlen The address length.
- *  @param[in] port The port to be set.
- *  @returns EOK on success.
- *  @returns EINVAL if the address length does not match the address family.
- *  @returns EAFNOSUPPORT if the address family is not supported.
- */
-int tl_set_address_port(struct sockaddr * addr, int addrlen, uint16_t port);
-
-/** Prepares the packet for ICMP error notification.
- *  Keeps the first packet and releases all the others.
- *  Releases all the packets on error.
- *  @param[in] packet_phone The packet server module phone.
- *  @param[in] icmp_phone The ICMP module phone.
- *  @param[in] packet The packet to be send.
- *  @param[in] error The packet error reporting service. Prefixes the received packet.
- *  @returns EOK on success.
- *  @returns ENOENT if no packet may be sent.
- */
-int tl_prepare_icmp_packet(int packet_phone, int icmp_phone, packet_t packet, services_t error);
-
-/** Receives data from the socket into a packet.
- *  @param[in] packet_phone The packet server module phone.
- *  @param[out] packet The new created packet.
- *  @param[in] prefix Reserved packet data prefix length.
- *  @param[in] dimension The packet dimension.
- *  @param[in] addr The destination address.
- *  @param[in] addrlen The address length.
- *  @returns Number of bytes received.
- *  @returns EINVAL if the client does not send data.
- *  @returns ENOMEM if there is not enough memory left.
- *  @returns Other error codes as defined for the async_data_read_finalize() function.
- */
-int tl_socket_read_packet_data(int packet_phone, packet_ref packet, size_t prefix, const packet_dimension_ref dimension, const struct sockaddr * addr, socklen_t addrlen);
-
-#endif
-
-/** @}
- */
-
Index: pace/srv/net/tl/tl_messages.h
===================================================================
--- uspace/srv/net/tl/tl_messages.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ 	(revision )
@@ -1,57 +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 net_tl
- *  @{
- */
-
-/** @file
- *  Transport layer modules messages.
- *  @see tl_interface.h
- */
-
-#ifndef __NET_TL_MESSAGES_H__
-#define __NET_TL_MESSAGES_H__
-
-#include <ipc/ipc.h>
-
-#include "../messages.h"
-
-/** Transport layer modules messages.
- */
-typedef enum{
-	/** Packet received message.
-	 *  @see tl_received_msg()
-	 */
-	NET_TL_RECEIVED = NET_TL_FIRST
-} tl_messages;
-
-#endif
-
-/** @}
- */
Index: uspace/srv/net/tl/udp/Makefile
===================================================================
--- uspace/srv/net/tl/udp/Makefile	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/udp/Makefile	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -28,28 +28,12 @@
 #
 
-NET_BASE = ../..
 USPACE_PREFIX = ../../../..
+LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBSOCKET_PREFIX)/libsocket.a
+EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBSOCKET_PREFIX)/include
 BINARY = udp
 
 SOURCES = \
 	udp.c \
-	udp_module.c \
-	$(NET_BASE)/checksum.c \
-	$(NET_BASE)/module.c \
-	$(NET_BASE)/modules.c \
-	$(NET_BASE)/il/ip/ip_client.c \
-	$(NET_BASE)/il/ip/ip_remote.c \
-	$(NET_BASE)/net/net_remote.c \
-	$(NET_BASE)/socket/socket_core.c \
-	$(NET_BASE)/tl/icmp/icmp_client.c \
-	$(NET_BASE)/tl/icmp/icmp_common.c \
-	$(NET_BASE)/tl/icmp/icmp_remote.c \
-	$(NET_BASE)/tl/tl_common.c \
-	$(NET_BASE)/structures/char_map.c \
-	$(NET_BASE)/structures/dynamic_fifo.c \
-	$(NET_BASE)/structures/measured_strings.c \
-	$(NET_BASE)/structures/packet/packet.c \
-	$(NET_BASE)/structures/packet/packet_client.c \
-	$(NET_BASE)/structures/packet/packet_remote.c
+	udp_module.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/tl/udp/udp.c
===================================================================
--- uspace/srv/net/tl/udp/udp.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/udp/udp.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -40,37 +40,39 @@
 #include <malloc.h>
 #include <stdio.h>
-
 #include <ipc/ipc.h>
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../messages.h"
-#include "../../modules.h"
-
-#include "../../structures/dynamic_fifo.h"
-#include "../../structures/packet/packet_client.h"
-
-#include "../../include/checksum.h"
-#include "../../include/in.h"
-#include "../../include/in6.h"
-#include "../../include/inet.h"
-#include "../../include/ip_client.h"
-#include "../../include/ip_interface.h"
-#include "../../include/ip_protocols.h"
-#include "../../include/icmp_client.h"
-#include "../../include/icmp_interface.h"
-#include "../../include/net_interface.h"
-#include "../../include/socket_codes.h"
-#include "../../include/socket_errno.h"
-
-#include "../../socket/socket_core.h"
-#include "../../socket/socket_messages.h"
-
-#include "../tl_common.h"
-#include "../tl_messages.h"
+#include <net_err.h>
+#include <net_messages.h>
+#include <net_modules.h>
+#include <adt/dynamic_fifo.h>
+#include <packet/packet_client.h>
+#include <packet_remote.h>
+#include <net_checksum.h>
+#include <in.h>
+#include <in6.h>
+#include <inet.h>
+#include <ip_client.h>
+#include <ip_interface.h>
+#include <ip_protocols.h>
+#include <icmp_client.h>
+#include <icmp_interface.h>
+#include <net_interface.h>
+#include <socket_codes.h>
+#include <socket_errno.h>
+#include <socket_core.h>
+#include <socket_messages.h>
+#include <tl_common.h>
+#include <tl_local.h>
+#include <tl_interface.h>
+#include <tl_messages.h>
 
 #include "udp.h"
 #include "udp_header.h"
 #include "udp_module.h"
+
+/** UDP module name.
+ */
+#define NAME	"UDP protocol"
 
 /** Default UDP checksum computing.
@@ -259,5 +261,5 @@
 	icmp_type_t type;
 	icmp_code_t code;
-	ip_pseudo_header_ref ip_header;
+	void *ip_header;
 	struct sockaddr * src;
 	struct sockaddr * dest;
@@ -357,5 +359,5 @@
 			while(tmp_packet){
 				next_packet = pq_detach(tmp_packet);
-				pq_release(udp_globals.net_phone, packet_get_id(tmp_packet));
+				pq_release_remote(udp_globals.net_phone, packet_get_id(tmp_packet));
 				tmp_packet = next_packet;
 			}
@@ -383,5 +385,5 @@
 	// queue the received packet
 	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))){
+	    || 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);
 	}
@@ -393,5 +395,5 @@
 }
 
-int udp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+int udp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
 	ERROR_DECLARE;
 
@@ -401,5 +403,5 @@
 	switch(IPC_GET_METHOD(*call)){
 		case NET_TL_RECEIVED:
-			if(! ERROR_OCCURRED(packet_translate(udp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
+			if(! ERROR_OCCURRED(packet_translate_remote(udp_globals.net_phone, &packet, IPC_GET_PACKET(call)))){
 				ERROR_CODE = udp_received_msg(IPC_GET_DEVICE(call), packet, SERVICE_UDP, IPC_GET_ERROR(call));
 			}
@@ -419,4 +421,5 @@
 	int socket_id;
 	size_t addrlen;
+	size_t size;
 	ipc_call_t answer;
 	int answer_count;
@@ -454,12 +457,12 @@
 				socket_id = SOCKET_GET_SOCKET_ID(call);
 				res = socket_create(&local_sockets, app_phone, NULL, &socket_id);
-				*SOCKET_SET_SOCKET_ID(answer) = socket_id;
-				
+				SOCKET_SET_SOCKET_ID(answer, socket_id);
+
 				if(res == EOK){
-					if(tl_get_ip_packet_dimension(udp_globals.ip_phone, &udp_globals.dimensions, DEVICE_INVALID_ID, &packet_dimension) == EOK){
-						*SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = packet_dimension->content;
+					if (tl_get_ip_packet_dimension(udp_globals.ip_phone, &udp_globals.dimensions, DEVICE_INVALID_ID, &packet_dimension) == EOK){
+						SOCKET_SET_DATA_FRAGMENT_SIZE(answer, packet_dimension->content);
 					}
-//					*SOCKET_SET_DATA_FRAGMENT_SIZE(answer) = MAX_UDP_FRAGMENT_SIZE;
-					*SOCKET_SET_HEADER_SIZE(answer) = UDP_HEADER_SIZE;
+//					SOCKET_SET_DATA_FRAGMENT_SIZE(answer, MAX_UDP_FRAGMENT_SIZE);
+					SOCKET_SET_HEADER_SIZE(answer, UDP_HEADER_SIZE);
 					answer_count = 3;
 				}
@@ -478,5 +481,6 @@
 				if(res == EOK){
 					fibril_rwlock_write_lock(&udp_globals.lock);
-					res = udp_sendto_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), addr, addrlen, SOCKET_GET_DATA_FRAGMENTS(call), SOCKET_SET_DATA_FRAGMENT_SIZE(answer), SOCKET_GET_FLAGS(call));
+					res = udp_sendto_message(&local_sockets, SOCKET_GET_SOCKET_ID(call), addr, addrlen, SOCKET_GET_DATA_FRAGMENTS(call), &size, SOCKET_GET_FLAGS(call));
+					SOCKET_SET_DATA_FRAGMENT_SIZE(answer, size);
 					if(res != EOK){
 						fibril_rwlock_write_unlock(&udp_globals.lock);
@@ -492,6 +496,6 @@
 				fibril_rwlock_write_unlock(&udp_globals.lock);
 				if(res > 0){
-					*SOCKET_SET_READ_DATA_LENGTH(answer) = res;
-					*SOCKET_SET_ADDRESS_LENGTH(answer) = addrlen;
+					SOCKET_SET_READ_DATA_LENGTH(answer, res);
+					SOCKET_SET_ADDRESS_LENGTH(answer, addrlen);
 					answer_count = 3;
 					res = EOK;
@@ -532,5 +536,5 @@
 	uint16_t dest_port;
 	uint32_t checksum;
-	ip_pseudo_header_ref ip_header;
+	void *ip_header;
 	size_t headerlen;
 	device_id_t device_id;
@@ -661,9 +665,9 @@
 		return NO_DATA;
 	}
-	ERROR_PROPAGATE(packet_translate(udp_globals.net_phone, &packet, packet_id));
+	ERROR_PROPAGATE(packet_translate_remote(udp_globals.net_phone, &packet, packet_id));
 	// get udp header
 	data = packet_get_data(packet);
 	if(! data){
-		pq_release(udp_globals.net_phone, packet_id);
+		pq_release_remote(udp_globals.net_phone, packet_id);
 		return NO_DATA;
 	}
@@ -673,5 +677,5 @@
 	result = packet_get_addr(packet, (uint8_t **) &addr, NULL);
 	if(ERROR_OCCURRED(tl_set_address_port(addr, result, ntohs(header->source_port)))){
-		pq_release(udp_globals.net_phone, packet_id);
+		pq_release_remote(udp_globals.net_phone, packet_id);
 		return ERROR_CODE;
 	}
@@ -688,5 +692,5 @@
 	// release the packet
 	dyn_fifo_pop(&socket->received);
-	pq_release(udp_globals.net_phone, packet_get_id(packet));
+	pq_release_remote(udp_globals.net_phone, packet_get_id(packet));
 	// return the total length
 	return (int) length;
@@ -694,8 +698,66 @@
 
 int udp_release_and_return(packet_t packet, int result){
-	pq_release(udp_globals.net_phone, packet_get_id(packet));
+	pq_release_remote(udp_globals.net_phone, packet_get_id(packet));
 	return result;
 }
 
+/** Default thread for new connections.
+ *
+ *  @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)
+{
+	/*
+	 * Accept the connection
+	 *  - Answer the first IPC_M_CONNECT_ME_TO call.
+	 */
+	ipc_answer_0(iid, EOK);
+	
+	while(true) {
+		ipc_call_t answer;
+		int answer_count;
+		
+		/* Clear the answer structure */
+		refresh_answer(&answer, &answer_count);
+		
+		/* Fetch the next message */
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		/* Process the message */
+		int res = tl_module_message_standalone(callid, &call, &answer,
+		    &answer_count);
+		
+		/* End if said to either by the message or the processing result */
+		if ((IPC_GET_METHOD(call) == IPC_M_PHONE_HUNGUP) || (res == EHANGUP))
+			return;
+		
+		/* Answer the message */
+		answer_call(callid, res, &answer, answer_count);
+	}
+}
+
+/** Starts the module.
+ *
+ *  @param argc The count of the command line arguments. Ignored parameter.
+ *  @param argv The command line parameters. Ignored parameter.
+ *
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for each specific module start function.
+ *
+ */
+int main(int argc, char *argv[])
+{
+	ERROR_DECLARE;
+	
+	/* Start the module */
+	if (ERROR_OCCURRED(tl_module_start_standalone(tl_client_connection)))
+		return ERROR_CODE;
+	
+	return EOK;
+}
+
 /** @}
  */
Index: uspace/srv/net/tl/udp/udp.h
===================================================================
--- uspace/srv/net/tl/udp/udp.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/udp/udp.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -39,8 +39,6 @@
 
 #include <fibril_synch.h>
-
-#include "../../socket/socket_core.h"
-
-#include "../tl_common.h"
+#include <socket_core.h>
+#include <tl_common.h>
 
 /** Type definition of the UDP global data.
Index: uspace/srv/net/tl/udp/udp_module.c
===================================================================
--- uspace/srv/net/tl/udp/udp_module.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/udp/udp_module.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -40,26 +40,19 @@
 #include <async.h>
 #include <stdio.h>
-
 #include <ipc/ipc.h>
 #include <ipc/services.h>
 
-#include "../../err.h"
-#include "../../modules.h"
-
-#include "../../structures/packet/packet.h"
-
-#include "../../include/net_interface.h"
+#include <net_err.h>
+#include <net_modules.h>
+#include <packet/packet.h>
+#include <net_interface.h>
+#include <tl_local.h>
 
 #include "udp.h"
 #include "udp_module.h"
 
-/** UDP module name.
+/** UDP module global data.
  */
-#define NAME	"UDP protocol"
-
-/** Prints the module name.
- *  @see NAME
- */
-void module_print_name(void);
+extern udp_globals_t	udp_globals;
 
 /** Starts the UDP module.
@@ -70,25 +63,5 @@
  *  @returns Other error codes as defined for the REGISTER_ME() macro function.
  */
-int module_start(async_client_conn_t client_connection);
-
-/** Processes the UDP message.
- *  @param[in] callid The message identifier.
- *  @param[in] call The message parameters.
- *  @param[out] answer The message answer parameters.
- *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
- *  @returns EOK on success.
- *  @returns Other error codes as defined for the udp_message() function.
- */
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
-
-/** UDP module global data.
- */
-extern udp_globals_t	udp_globals;
-
-void module_print_name(void){
-	printf("%s", NAME);
-}
-
-int module_start(async_client_conn_t client_connection){
+int tl_module_start_standalone(async_client_conn_t client_connection){
 	ERROR_DECLARE;
 
@@ -113,6 +86,14 @@
 }
 
-int module_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
-	return udp_message(callid, call, answer, answer_count);
+/** Processes the UDP message.
+ *  @param[in] callid The message identifier.
+ *  @param[in] call The message parameters.
+ *  @param[out] answer The message answer parameters.
+ *  @param[out] answer_count The last parameter for the actual answer in the answer parameter.
+ *  @returns EOK on success.
+ *  @returns Other error codes as defined for the udp_message() function.
+ */
+int tl_module_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count){
+	return udp_message_standalone(callid, call, answer, answer_count);
 }
 
Index: uspace/srv/net/tl/udp/udp_module.h
===================================================================
--- uspace/srv/net/tl/udp/udp_module.h	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/net/tl/udp/udp_module.h	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -47,5 +47,5 @@
  *  @returns ENOMEM if there is not enough memory left.
  */
-int udp_initialize(async_client_conn_t client_connection);
+extern int udp_initialize(async_client_conn_t client_connection);
 
 /** Processes the UDP message.
@@ -59,5 +59,5 @@
  *  @see IS_NET_UDP_MESSAGE()
  */
-int udp_message(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
+extern int udp_message_standalone(ipc_callid_t callid, ipc_call_t * call, ipc_call_t * answer, int * answer_count);
 
 #endif
Index: uspace/srv/ns/ns.c
===================================================================
--- uspace/srv/ns/ns.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/ns/ns.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -55,8 +55,8 @@
 static void *klogaddr = NULL;
 
-static void get_as_area(ipc_callid_t callid, ipc_call_t *call, void *ph_addr,
+static void get_as_area(ipc_callid_t callid, ipc_call_t *call, void *faddr,
     size_t pages, void **addr)
 {
-	if (ph_addr == NULL) {
+	if ((faddr == NULL) || (pages == 0)) {
 		ipc_answer_0(callid, ENOENT);
 		return;
@@ -71,5 +71,5 @@
 		}
 		
-		if (physmem_map(ph_addr, *addr, pages,
+		if (physmem_map(faddr, *addr, pages,
 		    AS_AREA_READ | AS_AREA_CACHEABLE) != 0) {
 			ipc_answer_0(callid, ENOENT);
@@ -81,4 +81,32 @@
 }
 
+static void setup_clock_area(ipc_callid_t callid, ipc_call_t *call, void **addr)
+{
+	uintptr_t faddr;
+	int err = sysinfo_get_value("clock.faddr", &faddr);
+	
+	if (err != EOK)
+		ipc_answer_0(callid, err);
+	
+	get_as_area(callid, call, (void *) faddr, 1, addr);
+}
+
+static void setup_klog_area(ipc_callid_t callid, ipc_call_t *call, void **addr)
+{
+	uintptr_t faddr;
+	int err = sysinfo_get_value("klog.faddr", &faddr);
+	
+	if (err != EOK)
+		ipc_answer_0(callid, err);
+	
+	size_t pages;
+	err = sysinfo_get_value("klog.pages", &pages);
+	
+	if (err != EOK)
+		ipc_answer_0(callid, err);
+	
+	get_as_area(callid, call, (void *) faddr, pages, addr);
+}
+
 int main(int argc, char **argv)
 {
@@ -97,5 +125,5 @@
 		return rc;
 	
-	printf(NAME ": Accepting connections\n");
+	printf("%s: Accepting connections\n", NAME);
 	
 	while (true) {
@@ -113,12 +141,8 @@
 			switch (IPC_GET_ARG3(call)) {
 			case SERVICE_MEM_REALTIME:
-				get_as_area(callid, &call,
-				    (void *) sysinfo_value("clock.faddr"),
-				    1, &clockaddr);
+				setup_clock_area(callid, &call, &clockaddr);
 				break;
 			case SERVICE_MEM_KLOG:
-				get_as_area(callid, &call,
-				    (void *) sysinfo_value("klog.faddr"),
-				    sysinfo_value("klog.pages"), &klogaddr);
+				setup_klog_area(callid, &call, &klogaddr);
 				break;
 			default:
Index: uspace/srv/taskmon/taskmon.c
===================================================================
--- uspace/srv/taskmon/taskmon.c	(revision 95319bd04e17f7e1bb127fdbbfb754cd00dda2b6)
+++ uspace/srv/taskmon/taskmon.c	(revision 88dea9d01a9bc5e8482c1ceafa6e6531ac50cb4f)
@@ -44,4 +44,5 @@
 #include <macros.h>
 #include <errno.h>
+#include <str_error.h>
 
 #define NAME  "taskmon"
@@ -96,7 +97,9 @@
 	}
 	putchar('\n');
-
-	if (!task_spawn(fname, argv))
-		printf(NAME ": Error spawning taskdump.\n", fname);
+	
+	int err;
+	if (!task_spawn(fname, argv, &err))
+		printf("%s: Error spawning %s (%s).\n", NAME, fname,
+		    str_error(err));
 }
 
