Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision 9094c0f2b96cb7212fb3fbf06eaeffff70792f26)
+++ boot/Makefile.common	(revision 01a7aa187b82df4ff11a19c34ee7ffac75ab2786)
@@ -177,4 +177,5 @@
 	$(USPACE_PATH)/app/nettest3/nettest3 \
 	$(USPACE_PATH)/app/netecho/netecho \
+	$(USPACE_PATH)/app/nterm/nterm \
 	$(USPACE_PATH)/app/ping/ping \
 	$(USPACE_PATH)/app/stats/stats \
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 9094c0f2b96cb7212fb3fbf06eaeffff70792f26)
+++ uspace/Makefile	(revision 01a7aa187b82df4ff11a19c34ee7ffac75ab2786)
@@ -51,4 +51,5 @@
 	app/mkexfat \
 	app/mkmfs \
+	app/nterm \
 	app/redir \
 	app/sbi \
Index: uspace/app/nterm/Makefile
===================================================================
--- uspace/app/nterm/Makefile	(revision 01a7aa187b82df4ff11a19c34ee7ffac75ab2786)
+++ uspace/app/nterm/Makefile	(revision 01a7aa187b82df4ff11a19c34ee7ffac75ab2786)
@@ -0,0 +1,36 @@
+#
+# Copyright (c) 2012 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 = ../..
+BINARY = nterm
+
+SOURCES = \
+	conn.c \
+	nterm.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/nterm/conn.c
===================================================================
--- uspace/app/nterm/conn.c	(revision 01a7aa187b82df4ff11a19c34ee7ffac75ab2786)
+++ uspace/app/nterm/conn.c	(revision 01a7aa187b82df4ff11a19c34ee7ffac75ab2786)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (c) 2012 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 nterm
+ * @{
+ */
+/** @file
+ */
+
+#include <bool.h>
+#include <errno.h>
+#include <fibril.h>
+#include <net/socket.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+#include "conn.h"
+#include "nterm.h"
+
+static int conn_fd;
+static fid_t rcv_fid;
+
+#define RECV_BUF_SIZE 1
+static uint8_t recv_buf[RECV_BUF_SIZE];
+
+static int rcv_fibril(void *arg)
+{
+	ssize_t nr;
+
+	while (true) {
+		nr = recv(conn_fd, recv_buf, RECV_BUF_SIZE, 0);
+		if (nr < 0)
+			break;
+
+		nterm_received(recv_buf, nr);
+	}
+
+	printf("Recv fibril terminated.\n");
+
+	return 0;
+}
+
+int conn_open(const char *addr_s, const char *port_s)
+{
+	struct sockaddr_in addr;
+	int rc;
+	char *endptr;
+
+	addr.sin_family = AF_INET;
+
+	rc = inet_pton(addr.sin_family, addr_s, (uint8_t *)&addr.sin_addr);
+	if (rc != EOK) {
+		printf("Invalid addres %s\n", addr_s);
+		return EINVAL;
+	}
+
+	addr.sin_port = htons(strtol(port_s, &endptr, 10));
+	if (*endptr != '\0') {
+		printf("Invalid port number %s\n", port_s);
+		return EINVAL;
+	}
+
+	conn_fd = socket(PF_INET, SOCK_STREAM, 0);
+	if (conn_fd < 0)
+		goto error;
+
+	printf("Connecting to address %s port %u\n", addr_s, ntohs(addr.sin_port));
+
+	rc = connect(conn_fd, (struct sockaddr *)&addr, sizeof(addr));
+	if (rc != EOK)
+		goto error;
+
+	rcv_fid = fibril_create(rcv_fibril, NULL);
+	if (rcv_fid == 0)
+		goto error;
+
+	fibril_add_ready(rcv_fid);
+
+	return EOK;
+
+error:
+	if (conn_fd >= 0) {
+		closesocket(conn_fd);
+		conn_fd = -1;
+	}
+
+	return EIO;
+}
+
+int conn_send(void *data, size_t size)
+{
+	int rc;
+
+	rc = send(conn_fd, data, size, 0);
+	if (rc != EOK)
+		return EIO;
+
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/app/nterm/conn.h
===================================================================
--- uspace/app/nterm/conn.h	(revision 01a7aa187b82df4ff11a19c34ee7ffac75ab2786)
+++ uspace/app/nterm/conn.h	(revision 01a7aa187b82df4ff11a19c34ee7ffac75ab2786)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2012 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 edit
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef CONN_H
+#define CONN_H
+
+#include <sys/types.h>
+
+extern int conn_open(const char *, const char *);
+extern int conn_send(void *, size_t);
+
+#endif
+
+/** @}
+ */
Index: uspace/app/nterm/nterm.c
===================================================================
--- uspace/app/nterm/nterm.c	(revision 01a7aa187b82df4ff11a19c34ee7ffac75ab2786)
+++ uspace/app/nterm/nterm.c	(revision 01a7aa187b82df4ff11a19c34ee7ffac75ab2786)
@@ -0,0 +1,146 @@
+/*
+ * Copyright (c) 2012 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 nterm
+ * @{
+ */
+/** @file Network serial terminal emulator.
+ */
+
+#include <bool.h>
+#include <errno.h>
+#include <io/console.h>
+#include <stdio.h>
+
+#include "conn.h"
+#include "nterm.h"
+
+#define NAME "nterm"
+
+static console_ctrl_t *con;
+static bool done;
+
+static void key_handle_ctrl(kbd_event_t *ev)
+{
+	switch (ev->key) {
+	case KC_Q:
+		done = true;
+		break;
+	default:
+		break;
+	}
+}
+
+static void send_char(wchar_t c)
+{
+	char cbuf[STR_BOUNDS(1)];
+	size_t offs;
+	int rc;
+
+	offs = 0;
+	chr_encode(c, cbuf, &offs, STR_BOUNDS(1));
+
+	rc = conn_send(cbuf, offs);
+	if (rc != EOK) {
+		printf("Failed sending data.\n");
+	}
+}
+
+static void key_handle_unmod(kbd_event_t *ev)
+{
+	switch (ev->key) {
+	case KC_ENTER:
+		send_char('\n');
+		break;
+	default:
+		if (ev->c >= 32 || ev->c == '\t') {
+			send_char(ev->c);
+		}
+	}
+}
+
+static void key_handle(kbd_event_t *ev)
+{
+	if ((ev->mods & KM_ALT) == 0 &&
+	    (ev->mods & KM_SHIFT) == 0 &&
+	    (ev->mods & KM_CTRL) != 0) {
+		key_handle_ctrl(ev);
+	} else if ((ev->mods & (KM_CTRL | KM_ALT)) == 0) {
+		key_handle_unmod(ev);
+	}
+}
+
+void nterm_received(void *data, size_t size)
+{
+	uint8_t *dp = (uint8_t *)data;
+	size_t i;
+
+//	printf("Received %zu bytes.\n", size);
+	for (i = 0; i < size; i++) {
+//		printf("0x%02x\n", dp[i]);
+		putchar(dp[i]);
+	}
+}
+
+static void print_syntax(void)
+{
+	printf("syntax: nterm <ip-address> <port>\n");
+}
+
+int main(int argc, char *argv[])
+{
+	kbd_event_t ev;
+	int rc;
+
+	if (argc != 3) {
+		print_syntax();
+		return 1;
+	}
+
+	rc = conn_open(argv[1], argv[2]);
+	if (rc != EOK) {
+		printf("Error connecting.\n");
+		return 1;
+	}
+
+	printf("Connection established.\n");
+
+	con = console_init(stdin, stdout);
+
+	done = false;
+	while (!done) {
+		console_get_kbd_event(con, &ev);
+		if (ev.type == KEY_PRESS)
+			key_handle(&ev);
+	}
+
+	return 0;
+}
+
+/** @}
+ */
Index: uspace/app/nterm/nterm.h
===================================================================
--- uspace/app/nterm/nterm.h	(revision 01a7aa187b82df4ff11a19c34ee7ffac75ab2786)
+++ uspace/app/nterm/nterm.h	(revision 01a7aa187b82df4ff11a19c34ee7ffac75ab2786)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2012 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 edit
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef NTERM_H
+#define NTERM_H
+
+#include <sys/types.h>
+
+extern void nterm_received(void *, size_t);
+
+#endif
+
+/** @}
+ */
