Index: /EcnlProtoTool/trunk/asp3_dcre/Debug/Makefile
===================================================================
--- /EcnlProtoTool/trunk/asp3_dcre/Debug/Makefile	(revision 440)
+++ /EcnlProtoTool/trunk/asp3_dcre/Debug/Makefile	(revision 441)
@@ -246,12 +246,4 @@
 #  システムサービスに関する定義
 #
-ifdef TCINSTALL
-GCC_PATH = $(TCINSTALL)
-else
-GCC_PATH = $(shell which $(CC))/../../
-endif
-MALLOC_LIB = "${GCC_PATH}arm-none-eabi/lib/thumb/v7-ar/fpv3/hard/libc.a"
-MALLOC_OBJS = lib_a-reent.o lib_a-impure.o lib_a-malloc.o lib_a-mallocr.o lib_a-calloc.o lib_a-callocr.o lib_a-realloc.o lib_a-reallocr.o lib_a-sbrkr.o lib_a-freer.o
-
 SYSSVC_DIRS := $(TECSGENDIR) $(SRCDIR)/tecs_kernel \
 				$(SYSSVC_DIRS) $(SRCDIR)/syssvc
@@ -380,5 +372,4 @@
 CFG_COBJS      := $(addprefix $(OBJDIR)/, $(CFG_COBJS))
 CFG_DMY        := $(addprefix $(OBJDIR)/, $(CFG_DMY))
-MALLOC_OBJS    := $(addprefix $(OBJDIR)/, $(MALLOC_OBJS))
 
 #
@@ -387,5 +378,5 @@
 APPL_OBJS = $(APPL_ASMOBJS) $(APPL_COBJS) $(APPL_CXXOBJS)
 SYSSVC_OBJS = $(SYSSVC_ASMOBJS) $(SYSSVC_COBJS) $(HIDDEN_OBJS)
-KERNEL_LIB_OBJS = $(KERNEL_ASMOBJS) $(KERNEL_COBJS) $(KERNEL_LCOBJS) $(MALLOC_OBJS)
+KERNEL_LIB_OBJS = $(KERNEL_ASMOBJS) $(KERNEL_COBJS) $(KERNEL_LCOBJS)
 CFG_OBJS = $(CFG_ASMOBJS) $(CFG_COBJS)
 ALL_OBJS = $(START_OBJS) $(APPL_OBJS) $(SYSSVC_OBJS) $(CFG_OBJS) \
@@ -554,5 +545,4 @@
 	rm -f libsyssvc.a
 endif
-	rm -f $(MALLOC_OBJS)
 
 .PHONY: cleankernel
@@ -678,8 +668,4 @@
 	$(CC) -c -o $@ -MD -MP -MF $(DEPDIR)/$*.d $(CFLAGS) $(APPL_CFLAGS) $<
 
-$(MALLOC_OBJS): $(OBJDIR)/%.o:
-	$(AR) x $(MALLOC_LIB) $(notdir $@)
-	mv $(notdir $@) $@
-
 #
 #  デフォルトコンパイルルールを上書き
Index: /EcnlProtoTool/trunk/ntshell/Debug/Makefile
===================================================================
--- /EcnlProtoTool/trunk/ntshell/Debug/Makefile	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/Debug/Makefile	(revision 441)
@@ -199,5 +199,5 @@
 	CDEFS := -DTOPPERS_OMIT_TECS $(CDEFS)
 endif
-CDEFS := $(CDEFS) -DFD_SETSIZE=32
+CDEFS := $(CDEFS) -DFD_SETSIZE=32 -DDHCP4_CLI_CFG -DUSE_PING -DUSE_RESOLVER -DUSE_NETAPP_SUBR
 INCLUDES := -I. -I$(SRCDIR)/include $(INCLUDES) -I$(SRCDIR)
 LDFLAGS := $(LDFLAGS) -L.
@@ -213,11 +213,11 @@
 APPL_CDL = main.cdl
 
-APPL_DIRS := $(APPLDIRS) $(SRCDIR)/library
+APPL_DIRS := $(APPLDIRS) $(SRCDIR)/library $(SRCDIR)/$(TINETDIR)/netapp
 APPL_ASMOBJS :=
 ifdef USE_CXX
 	APPL_CXXOBJS := main.o
-	APPL_COBJS := fdtable.o io_stub.o socket_stub.o ffarch.o fftime.o tlsf.o diskio.o ff.o sdfs.o ccsbcs.o base64.o http-strings.o http_parser.o httpd.o httpd-fs.o sha1.o websocket.o websocket_fbs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o mbedcall.o
+	APPL_COBJS := fdtable.o stdio_stub.o pipe_stub.o io_stub.o socket_stub.o tlsf.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o base64.o http-strings.o http_parser.o httpd.o httpd-fs.o sha1.o websocket.o websocket_fbs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o mbedcall.o ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o netcmd.o
 else
-	APPL_COBJS := main.o fdtable.o io_stub.o socket_stub.o ffarch.o fftime.o tlsf.o diskio.o ff.o sdfs.o ccsbcs.o base64.o http-strings.o http_parser.o httpd.o httpd-fs.o sha1.o websocket.o websocket_fbs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o mbedcall.o
+	APPL_COBJS := main.o fdtable.o stdio_stub.o pipe_stub.o io_stub.o socket_stub.o tlsf.o ffarch.o diskio.o ff.o sdfs.o ccsbcs.o base64.o http-strings.o http_parser.o httpd.o httpd-fs.o sha1.o websocket.o websocket_fbs.o ntshell.o text_editor.o text_history.o usrcmd.o vtrecv.o vtsend.o ntlibc.o ntstdio.o ntopt.o syscall.o mbedcall.o ping.o ping6.o resolver.o dhcp4_cli.o netapp_subr.o ntp_cli.o net_misc.o netcmd.o
 endif
 APPL_COBJS := $(APPL_COBJS) log_output.o vasyslog.o t_perror.o strerror.o mbed_stub.o
@@ -263,12 +263,4 @@
 #  ã·ã¹ãã ãµã¼ãã¹ã«é¢ããå®ç¾©
 #
-ifdef TCINSTALL
-GCC_PATH = $(TCINSTALL)
-else
-GCC_PATH = $(shell which $(CC))/../../
-endif
-MALLOC_LIB = "${GCC_PATH}arm-none-eabi/lib/thumb/v7-ar/fpv3/hard/libc.a"
-MALLOC_OBJS = lib_a-reent.o lib_a-impure.o lib_a-malloc.o lib_a-mallocr.o lib_a-calloc.o lib_a-callocr.o lib_a-realloc.o lib_a-reallocr.o lib_a-sbrkr.o lib_a-freer.o
-
 SYSSVC_DIRS := $(TECSGENDIR) $(SRCDIR)/tecs_kernel \
 				$(SYSSVC_DIRS) $(SRCDIR)/syssvc
@@ -398,5 +390,4 @@
 CFG_COBJS      := $(addprefix $(OBJDIR)/, $(CFG_COBJS))
 CFG_DMY        := $(addprefix $(OBJDIR)/, $(CFG_DMY))
-MALLOC_OBJS    := $(addprefix $(OBJDIR)/, $(MALLOC_OBJS))
 
 #
@@ -405,5 +396,5 @@
 APPL_OBJS = $(APPL_ASMOBJS) $(APPL_COBJS) $(APPL_CXXOBJS) $(APPL_BINOBJS)
 SYSSVC_OBJS = $(SYSSVC_ASMOBJS) $(SYSSVC_COBJS) $(HIDDEN_OBJS)
-KERNEL_LIB_OBJS = $(KERNEL_ASMOBJS) $(KERNEL_COBJS) $(KERNEL_LCOBJS) $(MALLOC_OBJS)
+KERNEL_LIB_OBJS = $(KERNEL_ASMOBJS) $(KERNEL_COBJS) $(KERNEL_LCOBJS)
 CFG_OBJS = $(CFG_ASMOBJS) $(CFG_COBJS)
 ALL_OBJS = $(START_OBJS) $(APPL_OBJS) $(SYSSVC_OBJS) $(CFG_OBJS) \
@@ -573,5 +564,4 @@
 	rm -f libsyssvc.a
 endif
-	rm -f $(MALLOC_OBJS)
 
 .PHONY: cleankernel
@@ -701,8 +691,4 @@
 	$(OBJCOPY) -B arm -I binary -O elf32-littlearm --rename-section .data=.rodata $< $(OBJDIR)/$*.o
 
-$(MALLOC_OBJS): $(OBJDIR)/%.o:
-	$(AR) x $(MALLOC_LIB) $(notdir $@)
-	mv $(notdir $@) $@
-
 #
 #  ããã©ã«ãã³ã³ãã¤ã«ã«ã¼ã«ãä¸æ¸ã
Index: /EcnlProtoTool/trunk/ntshell/fatfs/diskio.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/fatfs/diskio.h	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/fatfs/diskio.h	(revision 441)
@@ -43,5 +43,5 @@
 void disk_timerproc(void);
 
-#define SZ_RAMDISK	1792	/* Size of RAM disk [kB] */
+#define SZ_RAMDISK	1536	/* Size of RAM disk [kB] */
 #define SS_RAMDISK	512		/* Sector size of RAM disk [byte] */
 
Index: /EcnlProtoTool/trunk/ntshell/fatfs/ffarch.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/fatfs/ffarch.c	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/fatfs/ffarch.c	(revision 441)
@@ -42,24 +42,79 @@
 #include <kernel.h>
 #include <stdlib.h>
-//#include <string.h>
+#include <string.h>
 #include "t_stdlib.h"
 #include "syssvc/serial.h"
 #include "syssvc/syslog.h"
+#include "target_syssvc.h"
 #include "kernel_cfg.h"
 #include "diskio.h"
 #include "sdfs.h"
 #include "ff.h"
-#include "tlsf.h"
-#include "util/ntstdio.h"
+#include <stdio.h>
+#include "hal/rtc_api.h"
+#include "ffarch.h"
 
 #define SD_CARD_LOG_LEVEL LOG_INFO
 
-#define SIO_PORTID 1
-extern ntstdio_t ntstdio;
-
-static tlsf_t sys_tlsf;
-static pool_t sys_pool;
-
-uint8_t shell_heap[64 * 1024];
+enum ffarch_state_t {
+	FFS_IDLE,
+	FFS_RETRY_WAIT,
+};
+
+enum ffarch_state_t ffarch_state;
+volatile int ffarch_timer;
+int ffarch_retry_count;
+uint8_t sdfs_new_status, sdfs_prev_status;
+
+static void ffarch_initialize();
+
+/*
+ * FatFSタスク
+ */
+void ffarch_task(intptr_t exinf)
+{
+	ER ret, ret2;
+	SYSTIM prev, now;
+	int timer;
+
+	ffarch_initialize();
+
+	ret2 = get_tim(&now);
+	if (ret2 != E_OK){
+		syslog(LOG_NOTICE, "[ffarch] get_tim error: %s",
+			itron_strerror(ret2));
+		return;
+	}
+
+	for(;;){
+		prev = now;
+
+		/* タイマー取得 */
+		timer = ffarch_get_timer();
+
+		/* 待ち */
+		ret = tslp_tsk(timer);
+		if ((ret != E_OK) && (ret != E_TMOUT)) {
+			syslog(LOG_NOTICE, "[ffarch] tslp_tsk error: %s %d",
+				itron_strerror(ret), timer);
+			break;
+		}
+
+		ret2 = get_tim(&now);
+		if (ret2 != E_OK) {
+			syslog(LOG_NOTICE, "[ffarch] get_tim error: %s",
+				itron_strerror(ret2));
+			break;
+		}
+
+		/* 時間経過 */
+		int elapse = now - prev;
+		ffarch_progress(elapse);
+
+		/* タイムアウト処理 */
+		ffarch_timeout();
+	}
+}
+
 FATFS RomDisk;
 
@@ -75,14 +130,9 @@
 SD Sd;
 
-void sys_init(void);
 bool_t romdisk_init();
 bool_t SD_begin();
 
-int mruby_arduino_init()
-{
-	int result = -1;
-
-	sys_init();
-
+void ffarch_init(void)
+{
 	/* SD_CD */
 	gpio_init_in(&ins, P7_8);
@@ -91,65 +141,25 @@
 	sdfs_init(&sdfs, P8_5, P8_6, P8_3, P8_4, "sd");
 
-	result = SD_begin() ? 0 : -1;
-	if (result == 0) {
-		ntstdio_printf(&ntstdio, "SD card (1:) OK!\n");
+	ffarch_state = FFS_IDLE;
+	ffarch_timer = 0;
+	ffarch_retry_count = 3;
+	sdfs_new_status = 0;
+	sdfs_prev_status = STA_NODISK;
+
+	ffarch_timeout();
+
+	act_tsk(FFARCH_TASK);
+
+	if (romdisk_init()) {
+		syslog(LOG_NOTICE, "ROM disk (0:) OK!");
 	}
 	else {
-		ntstdio_printf(&ntstdio, "SD card (1:) NG!\n");
-	}
+		syslog(LOG_NOTICE, "ROM disk (0:) NG!");
+	}
+}
+
+void ffarch_initialize()
+{
 	sta_cyc(SDFS_CYC);
-
-	if (romdisk_init())
-		result = 0;
-
-	if (result == 0) {
-		ntstdio_printf(&ntstdio, "ROM disk (0:) OK!\n");
-	}
-	else {
-		ntstdio_printf(&ntstdio, "ROM disk (0:) NG!\n");
-	}
-
-	/* uploadディレクトリを作成しておく */
-	f_mkdir("1:/upload");
-
-	serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV);
-
-	return result;
-}
-
-void sys_init(void)
-{
-	sys_tlsf = tlsf_create(&shell_heap);
-	if (sys_tlsf == NULL)
-		return;
-
-	sys_pool = tlsf_add_pool(sys_tlsf, ((uint8_t *)&shell_heap) + tlsf_size(), sizeof(shell_heap) - tlsf_size());
-}
-
-void sys_fini(void)
-{
-	tlsf_destroy(sys_tlsf);
-}
-
-void *sys_malloc(size_t size)
-{
-	return tlsf_malloc(sys_tlsf, size);
-}
-
-void *sys_calloc(size_t size, size_t count)
-{
-	void *result = tlsf_malloc(sys_tlsf, count * size);
-	memset(result, 0, count * size);
-	return result;
-}
-
-void *sys_realloc(void *ptr, size_t size)
-{
-	return tlsf_realloc(sys_tlsf, ptr, size);
-}
-
-void sys_free(void *ptr)
-{
-	tlsf_free(sys_tlsf, ptr);
 }
 
@@ -219,5 +229,5 @@
 		return ramdisk_get_status();
 	case 1:
-		return sdfs_status(&sdfs);
+		return sdfs._is_initialized;
 	}
 	return STA_NOINIT;
@@ -246,4 +256,6 @@
 }
 
+DRESULT sdfs_ioctl(BYTE ctrl, void *buff);
+
 DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff)
 {
@@ -252,31 +264,166 @@
 		return RES_PARERR; /* ramdisk_ioctl(cmd, buff); */
 	case 1:
-		switch(cmd) {
-		case CTRL_SYNC:
-			return sdfs_sync(&sdfs);
-		case GET_SECTOR_COUNT:
-			return sdfs_sectors(&sdfs);
-		case GET_BLOCK_SIZE:
-			*((DWORD*)buff) = 1; // default when not known
-			return RES_OK;
-		}
+		return sdfs_ioctl(cmd, buff);
 	}
 	return RES_PARERR;
 }
 
+DRESULT sdfs_ioctl(BYTE ctrl, void *buff)
+{
+	DRESULT res;
+	uint32_t *dp = (uint32_t *)buff;
+	uint8_t *ptr = (uint8_t *)buff;
+
+	if (sdfs._is_initialized & STA_NOINIT)
+		return RES_NOTRDY;
+
+	res = RES_ERROR;
+
+	switch (ctrl) {
+	case CTRL_SYNC:
+		if (sdfs_sync(&sdfs) == 0) {
+			res = RES_OK;
+		}
+		break;
+	case GET_SECTOR_SIZE:
+		*(WORD*)buff = 512;
+		res = RES_OK;
+		break;
+	case GET_SECTOR_COUNT:
+		*(DWORD*)buff = sdfs._capacity / 512;
+		res = RES_OK;
+		break;
+	case GET_BLOCK_SIZE:
+		*(DWORD*)buff = sdfs._block_len;
+		res = RES_OK;
+		break;
+	case CTRL_TRIM:
+		res = sdfs_trim(&sdfs, dp[0], dp[1]);
+		break;
+	case MMC_GET_TYPE:
+		*ptr = sdfs._card_type;
+		res = RES_OK;
+		break;
+	case MMC_GET_CSD:
+		memcpy(ptr, sdfs._csd, sizeof(sdfs._csd));
+		res = RES_OK;
+		break;
+	case MMC_GET_CID:
+		memcpy(ptr, sdfs._cid, sizeof(sdfs._cid));
+		res = RES_OK;
+		break;
+	case MMC_GET_OCR:
+		if (sdfs_get_ocr(&sdfs, buff) == 0) {
+			res = RES_OK;
+		}
+		break;
+	case MMC_GET_SDSTAT:
+		if (sdfs_get_sdstat(&sdfs, buff) == 0) {
+			res = RES_OK;
+		}
+		break;
+	default:
+		res = RES_PARERR;
+	}
+
+	return res;
+}
+
 void sdfs_cychdr(intptr_t exinf)
 {
-	BYTE s;
-
-	s = sdfs._is_initialized;
-	if (WP())		/* Write protected */
+	BYTE s = 0;
+             
+	/* Write protected */
+	if (WP())
 		s |= STA_PROTECT;
-	else		/* Write enabled */
+	else
 		s &= ~STA_PROTECT;
-	if (gpio_read(&ins))	/* Card is in socket */
+
+	/* Card is in socket */
+	if (gpio_read(&ins))
+		s |= (STA_NODISK | STA_NOINIT);
+	else
 		s &= ~STA_NODISK;
-	else		/* Socket empty */
-		s |= (STA_NODISK | STA_NOINIT);
-	sdfs._is_initialized = s;
+
+	sdfs_new_status = s;
+
+	if ((sdfs_prev_status != sdfs_new_status) && (ffarch_state == FFS_IDLE)) {
+		ffarch_timer = 0;
+		wup_tsk(FFARCH_TASK);
+	}
+}
+
+int ffarch_get_timer(void)
+{
+	return ffarch_timer;
+}
+
+void ffarch_progress(int elapse)
+{
+	if (ffarch_timer != TMO_FEVR) {
+		ffarch_timer -= elapse;
+		if (ffarch_timer < 0) {
+			ffarch_timer = 0;
+		}
+	}
+}
+
+void ffarch_timeout(void)
+{
+	if (ffarch_timer != 0)
+		return;
+
+	switch (ffarch_state) {
+	case FFS_RETRY_WAIT:
+		if (ffarch_retry_count == 0) {
+			syslog(SD_CARD_LOG_LEVEL, "SD card (1:) initialize tired...");
+
+			ffarch_state = FFS_IDLE;
+			ffarch_timer = TMO_FEVR;
+			ffarch_retry_count = 3;
+			break;
+		}
+		ffarch_retry_count--;
+		//goto case FFS_IDLE;
+	case FFS_IDLE:
+ 		/* SDカードが入れられた場合 */
+ 		if ((sdfs._is_initialized & STA_NOINIT)
+ 			|| (((sdfs_prev_status & STA_NODISK) != 0) && ((sdfs_new_status & STA_NODISK) == 0))) {
+			syslog(SD_CARD_LOG_LEVEL, "SD card initializing ...");
+
+			if (SD_begin()) {
+				syslog(SD_CARD_LOG_LEVEL, "SD card (1:) OK!");
+
+				/* uploadディレクトリを作成しておく */
+				f_mkdir("1:/upload");
+
+				ffarch_state = FFS_IDLE;
+				ffarch_timer = TMO_FEVR;
+				ffarch_retry_count = 3;
+			}
+			else {
+				syslog(SD_CARD_LOG_LEVEL, "SD card (1:) NG!");
+				ffarch_state = FFS_RETRY_WAIT;
+				ffarch_timer = 1000 * 1000;
+			}
+		}
+		/* SDカードが抜かれた場合 */
+		else if (((sdfs_prev_status & STA_NODISK) == 0) && ((sdfs_new_status & STA_NODISK) != 0)) {
+			syslog(SD_CARD_LOG_LEVEL, "SD card unmount");
+
+			f_mount(&Sd.FatFs, "1:", 0);
+			ffarch_state = FFS_IDLE;
+			ffarch_timer = TMO_FEVR;
+			ffarch_retry_count = 3;
+		}
+		if (((sdfs_prev_status ^ sdfs_new_status) & STA_PROTECT) != 0) {
+			if ((sdfs_new_status & STA_PROTECT) != 0)
+				sdfs._is_initialized |= STA_PROTECT;
+			else
+				sdfs._is_initialized &= ~STA_PROTECT;
+		}
+		sdfs_prev_status = sdfs_new_status;
+		break;
+	}
 }
 
@@ -314,10 +461,10 @@
 void* ff_memalloc (UINT msize)
 {
-	return sys_malloc(msize);
+	return malloc(msize);
 }
 
 void ff_memfree (void* mblock)
 {
-	sys_free(mblock);
+	free(mblock);
 }
 
Index: /EcnlProtoTool/trunk/ntshell/fatfs/ffarch.cfg
===================================================================
--- /EcnlProtoTool/trunk/ntshell/fatfs/ffarch.cfg	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/fatfs/ffarch.cfg	(revision 441)
@@ -38,6 +38,7 @@
 #include "ffarch.h"
 
+CRE_TSK(FFARCH_TASK, { TA_NULL, 0, ffarch_task, FFARCH_PRIORITY, FFARCH_STACK_SIZE, NULL });
 CRE_CYC(SDFS_CYC, { TA_NULL, { TNFY_HANDLER, 0, sdfs_cychdr }, 1000000, 0 });
 
-CRE_SEM(SEM_MALLOC, { TA_TPRI, 1, 1 });
+CRE_SEM(SEM_FILESYSTEM, { TA_TPRI, 1, 1 });
 
Index: /EcnlProtoTool/trunk/ntshell/fatfs/ffarch.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/fatfs/ffarch.h	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/fatfs/ffarch.h	(revision 441)
@@ -38,5 +38,13 @@
 #define _FFARCH_H_
 
-int mruby_arduino_init();
+#define FFARCH_PRIORITY			5
+#define FFARCH_STACK_SIZE		512
+
+void ffarch_init(void);
+void ffarch_task(intptr_t exinf);
+int ffarch_get_timer(void);
+void ffarch_progress(int elapse);
+void ffarch_timeout(void);
+
 void sdfs_cychdr(intptr_t exinf);
 
Index: nlProtoTool/trunk/ntshell/fatfs/fftime.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/fatfs/fftime.c	(revision 440)
+++ 	(revision )
@@ -1,255 +1,0 @@
-/* musl-1.1.12/src/time/*.c */
-/* musl as a whole is licensed under the following standard MIT license:
-*
-* ----------------------------------------------------------------------
-* Copyright (C) 2005-2014 Rich Felker, et al.
-*
-* Permission is hereby granted, free of charge, to any person obtaining
-* a copy of this software and associated documentation files (the
-* "Software"), to deal in the Software without restriction, including
-* without limitation the rights to use, copy, modify, merge, publish,
-* distribute, sublicense, and/or sell copies of the Software, and to
-* permit persons to whom the Software is furnished to do so, subject to
-* the following conditions:
-*
-* The above copyright notice and this permission notice shall be
-* included in all copies or substantial portions of the Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
-* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-* ----------------------------------------------------------------------*/
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-#include <errno.h>
-#include "ff.h"
-
-int shell_errno;
-
-/* 2000-03-01 (mod 400 year, immediately after feb29 */
-#define LEAPOCH (946684800LL + 86400*(31+29))
-
-#define DAYS_PER_400Y (365*400 + 97)
-#define DAYS_PER_100Y (365*100 + 24)
-#define DAYS_PER_4Y   (365*4   + 1)
-
-int __secs_to_tm(long long t, struct tm* tm)
-{
-	long long days, secs, years;
-	int remdays, remsecs, remyears;
-	int qc_cycles, c_cycles, q_cycles;
-	int months;
-	int wday, yday, leap;
-	static const char days_in_month[] = {31,30,31,30,31,31,30,31,30,31,31,29};
-
-	/* Reject time_t values whose year would overflow int */
-	if (t < INT_MIN * 31622400LL || t > INT_MAX * 31622400LL)
-		return -1;
-
-	secs = t - LEAPOCH;
-	days = secs / 86400;
-	remsecs = secs % 86400;
-	if (remsecs < 0) {
-		remsecs += 86400;
-		days--;
-	}
-
-	wday = (3 + days) % 7;
-	if (wday < 0) wday += 7;
-
-	qc_cycles = days / DAYS_PER_400Y;
-	remdays = days % DAYS_PER_400Y;
-	if (remdays < 0) {
-		remdays += DAYS_PER_400Y;
-		qc_cycles--;
-	}
-
-	c_cycles = remdays / DAYS_PER_100Y;
-	if (c_cycles == 4) c_cycles--;
-	remdays -= c_cycles * DAYS_PER_100Y;
-
-	q_cycles = remdays / DAYS_PER_4Y;
-	if (q_cycles == 25) q_cycles--;
-	remdays -= q_cycles * DAYS_PER_4Y;
-
-	remyears = remdays / 365;
-	if (remyears == 4) remyears--;
-	remdays -= remyears * 365;
-
-	leap = !remyears && (q_cycles || !c_cycles);
-	yday = remdays + 31 + 28 + leap;
-	if (yday >= 365 + leap) yday -= 365 + leap;
-
-	years = remyears + 4 * q_cycles + 100 * c_cycles + 400LL * qc_cycles;
-
-	for (months = 0; days_in_month[months] <= remdays; months++)
-		remdays -= days_in_month[months];
-
-	if (years + 100 > INT_MAX || years + 100 < INT_MIN)
-		return -1;
-
-	tm->tm_year = years + 100;
-	tm->tm_mon = months + 2;
-	if (tm->tm_mon >= 12) {
-		tm->tm_mon -= 12;
-		tm->tm_year++;
-	}
-	tm->tm_mday = remdays + 1;
-	tm->tm_wday = wday;
-	tm->tm_yday = yday;
-
-	tm->tm_hour = remsecs / 3600;
-	tm->tm_min = remsecs / 60 % 60;
-	tm->tm_sec = remsecs % 60;
-
-	return 0;
-}
-
-long long __year_to_secs(long long year, int *is_leap)
-{
-	if (year - 2ULL <= 136) {
-		int y = year;
-		int leaps = (y - 68) >> 2;
-		if (!((y - 68) & 3)) {
-			leaps--;
-			if (is_leap) *is_leap = 1;
-		}
-		else if (is_leap) *is_leap = 0;
-		return 31536000 * (y - 70) + 86400 * leaps;
-	}
-
-	int cycles, centuries, leaps, rem;
-
-	if (!is_leap) is_leap = &(int) { 0 };
-	cycles = (year - 100) / 400;
-	rem = (year - 100) % 400;
-	if (rem < 0) {
-		cycles--;
-		rem += 400;
-	}
-	if (!rem) {
-		*is_leap = 1;
-		centuries = 0;
-		leaps = 0;
-	}
-	else {
-		if (rem >= 200) {
-			if (rem >= 300) centuries = 3, rem -= 300;
-			else centuries = 2, rem -= 200;
-		}
-		else {
-			if (rem >= 100) centuries = 1, rem -= 100;
-			else centuries = 0;
-		}
-		if (!rem) {
-			*is_leap = 0;
-			leaps = 0;
-		}
-		else {
-			leaps = rem / 4U;
-			rem %= 4U;
-			*is_leap = !rem;
-		}
-	}
-
-	leaps += 97 * cycles + 24 * centuries - *is_leap;
-
-	return (year - 100) * 31536000LL + leaps * 86400LL + 946684800 + 86400;
-}
-
-int __month_to_secs(int month, int is_leap)
-{
-	static const int secs_through_month[] = {
-		0, 31 * 86400, 59 * 86400, 90 * 86400,
-		120 * 86400, 151 * 86400, 181 * 86400, 212 * 86400,
-		243 * 86400, 273 * 86400, 304 * 86400, 334 * 86400};
-	int t = secs_through_month[month];
-	if (is_leap && month >= 2) t += 86400;
-	return t;
-}
-
-long long __tm_to_secs(const struct tm *tm)
-{
-	int is_leap;
-	long long year = tm->tm_year;
-	int month = tm->tm_mon;
-	if (month >= 12 || month < 0) {
-		int adj = month / 12;
-		month %= 12;
-		if (month < 0) {
-			adj--;
-			month += 12;
-		}
-		year += adj;
-	}
-	long long t = __year_to_secs(year, &is_leap);
-	t += __month_to_secs(month, is_leap);
-	t += 86400LL * (tm->tm_mday - 1);
-	t += 3600LL * tm->tm_hour;
-	t += 60LL * tm->tm_min;
-	t += tm->tm_sec;
-	return t;
-}
-
-struct tm *localtime_r(const time_t *t, struct tm *tm)
-{
-	/* Reject time_t values whose year would overflow int because
-	* __secs_to_zone cannot safely handle them. */
-	if (*t < INT_MIN * 31622400LL || *t > INT_MAX * 31622400LL) {
-		shell_errno = EOVERFLOW;
-		return 0;
-	}
-	//TODO:__secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone);
-	if (__secs_to_tm((long long)*t /*+ tm->__tm_gmtoff*/, tm) < 0) {
-		shell_errno = EOVERFLOW;
-		return 0;
-	}
-	return tm;
-}
-
-struct tm *localtime(const time_t *time)
-{
-	static struct tm tm;
-	return localtime_r(time, &tm);
-}
-
-struct tm *gmtime_r(const time_t *t, struct tm *tm)
-{
-	if (__secs_to_tm(*t, tm) < 0) {
-		shell_errno = EOVERFLOW;
-		return 0;
-	}
-	tm->tm_isdst = 0;
-	/*tm->__tm_gmtoff = 0;
-	tm->__tm_zone = NULL;//__gmt;*/
-	return tm;
-}
-
-/* There is no other implemented value than TIME_UTC; all other values
- * are considered erroneous. */
-/*int timespec_get(struct timespec * ts, int base)
-{
-	if (base != TIME_UTC) return 0;
-	int ret = __clock_gettime(CLOCK_REALTIME, ts);
-	return ret < 0 ? 0 : base;
-}*/
-time_t mktime(struct tm *tm)
-{
-	struct tm new;
-	long opp;
-	long long t = __tm_to_secs(tm);
-
-	if (__secs_to_tm(t, &new) < 0) goto error;
-
-	*tm = new;
-	return t;
-
-error:
-	shell_errno = EOVERFLOW;
-	return -1;
-}
Index: /EcnlProtoTool/trunk/ntshell/ntshell/core/ntlibc.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/ntshell/core/ntlibc.h	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/ntshell/core/ntlibc.h	(revision 441)
@@ -52,5 +52,5 @@
 int ntlibc_tolower(int c);
 int ntlibc_atoi(const char *nptr);
-unsigned long ntlibc_strtoul(const char *__restrict nptr, char **__restrict endptr, int base);
+unsigned long ntlibc_strtoul(const char *restrict nptr, char **restrict endptr, int base);
 char *ntlibc_strchr(const char *s, int c);
 char *ntlibc_utoa(unsigned int value, char *s, int radix);
Index: /EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.c	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.c	(revision 441)
@@ -33,12 +33,11 @@
 #include "shellif.h"
 #include <kernel.h>
-//#include <string.h>
 #include <t_syslog.h>
 #include <t_stdlib.h>
 #include <sil.h>
 #include "syssvc/syslog.h"
+#include "target_syssvc.h"
 #include "kernel_cfg.h"
 #include "main.h"
-#include "rza1.h"
 #include "ffarch.h"
 #include "ff.h"
@@ -48,5 +47,5 @@
 #include "util/ntstdio.h"
 
-extern ntstdio_t ntstdio;
+extern ntstdio_t *ntstdio;
 extern int ntshell_exit;
 
@@ -147,20 +146,4 @@
 }
 
-int shell_kill(int pid, int sig)
-{
-	asm("bkpt #0");
-	return -1;
-}
-
-int shell_gettimeofday(struct timeval *tv, void *tzvp)
-{
-	SYSTIM time;
-	if (!tv) return 0;
-	get_tim(&time);
-	tv->tv_sec = time / 1000000;
-	tv->tv_usec = time - (tv->tv_sec * 1000000);
-	return 0;
-}
-
 void put_rc(const char *func, FRESULT rc)
 {
@@ -175,5 +158,5 @@
 		while (*p++);
 	}
-	ntstdio_printf(&ntstdio, "%s() =>%u FR_%s\n", func, (UINT)rc, p);
+	ntstdio_printf(ntstdio, "%s() =>%u FR_%s\n", func, (UINT)rc, p);
 }
 
@@ -187,5 +170,5 @@
 		while (*p++);
 	}
-	ntstdio_printf(&ntstdio, "%s() =>%u %s\n", func, (UINT)rc, p);
+	ntstdio_printf(ntstdio, "%s() =>%u %s\n", func, (UINT)rc, p);
 }
 
@@ -210,5 +193,5 @@
 	for (; s[i] == '/'; i--) if (!i) return (s == _s) ? "/" : _s;
 	for (; s[i] != '/'; i--) if (!i) return (s == _s) ? "." : _s;
-	for (; s[i] == '/'; i--) if (!i) if (s == _s) return "/"; else break;
+	for (; s[i] == '/'; i--) if (!i) { if (s == _s) return "/"; else break; }
 	s[i + 1] = 0;
 	return _s;
@@ -237,5 +220,5 @@
 
 	ntlibc_strlcat(path, "\n", sizeof(path));
-	ntstdio_printf(&ntstdio, path);
+	ntstdio_printf(ntstdio, path);
 
 	return 0;
@@ -260,5 +243,5 @@
 
 	if (list_option & LS_LONG) {
-		ntstdio_printf(&ntstdio, "%c%c%c%c%c %04d/%02d/%02d %02d:%02d:%02d ",
+		ntstdio_printf(ntstdio, "%c%c%c%c%c %04d/%02d/%02d %02d:%02d:%02d ",
 			(fno->fattrib & AM_DIR) ? 'd' : '-',
 			(fno->fattrib & AM_RDO) ? 'r' : '-',
@@ -274,16 +257,16 @@
 
 		if (fno->fattrib & AM_DIR) {                    /* It is a directory */
-			ntstdio_printf(&ntstdio, "%10S ", " ");
+			ntstdio_printf(ntstdio, "%10s ", " ");
 		}
 		else {
-			ntstdio_printf(&ntstdio, "%10d ", fno->fsize);
+			ntstdio_printf(ntstdio, "%10lu ", fno->fsize);
 		}
 	}
 
 	if (fno->fattrib & AM_DIR) {                    /* It is a directory */
-		ntstdio_printf(&ntstdio, "\x1B[32m%s\x1B[0m\n", fn);
+		ntstdio_printf(ntstdio, "\x1B[32m%s\x1B[0m\n", fn);
 	}
 	else {
-		ntstdio_printf(&ntstdio, "%s\n", fn);
+		ntstdio_printf(ntstdio, "%s\n", fn);
 	}
 }
@@ -304,5 +287,5 @@
 	path_backup = ff_memalloc(LFN_BUF_SIZE);
 	if (path_backup == NULL) {
-		ntstdio_printf(&ntstdio, "ff_memalloc err.\n");
+		ntstdio_printf(ntstdio, "ff_memalloc err.\n");
 		return;
 	}
@@ -312,5 +295,5 @@
 	lfn = ff_memalloc(LFN_BUF_SIZE);
 	if (lfn == NULL) {
-		ntstdio_printf(&ntstdio, "ff_memalloc err.\n");
+		ntstdio_printf(ntstdio, "ff_memalloc err.\n");
 		ff_memfree(path_backup);
 		return;
@@ -340,23 +323,23 @@
 			}
 
-			if ((res = f_chdrive(path_p)) != RES_OK) {
+			if ((res = f_chdrive(path_p)) != FR_OK) {
 				put_rc("f_chdrive", res);
 			}
 
-			if ((res = f_chdir(path_p)) != RES_OK) {
+			if ((res = f_chdir(path_p)) != FR_OK) {
 				put_rc("f_chdir", res);
 			}
 
-			ntstdio_printf(&ntstdio, "\n%s/%s:\n", path_p, fn);
+			ntstdio_printf(ntstdio, "\n%s/%s:\n", path_p, fn);
 
 			print_ls(fn, NULL, list_option);
 
-			ntstdio_printf(&ntstdio, "\n");
-
-			if ((res = f_chdrive(path_backup)) != RES_OK) {
+			ntstdio_printf(ntstdio, "\n");
+
+			if ((res = f_chdrive(path_backup)) != FR_OK) {
 				put_rc("f_chdrive", res);
 			}
 
-			if ((res = f_chdir(path_backup)) != RES_OK) {
+			if ((res = f_chdir(path_backup)) != FR_OK) {
 				put_rc("f_chdir", res);
 			}
@@ -449,5 +432,5 @@
 	lfn = ff_memalloc(LFN_BUF_SIZE);
 	if (lfn == NULL) {
-		ntstdio_printf(&ntstdio, "alloc err.\n");
+		ntstdio_printf(ntstdio, "alloc err.\n");
 		goto cp_end;
 	}
@@ -459,5 +442,5 @@
 	local_buff = ff_memalloc(64);
 	if (local_buff == NULL) {
-		ntstdio_printf(&ntstdio, "alloc err.\n");
+		ntstdio_printf(ntstdio, "alloc err.\n");
 		goto cp_end;
 	}
@@ -469,7 +452,7 @@
 	if (res != FR_OK) {
 		if (res == FR_NO_FILE)
-			ntstdio_printf(&ntstdio, "src no file.\n", res);
+			ntstdio_printf(ntstdio, "src no file.\n");
 		else
-			ntstdio_printf(&ntstdio, "src stat err(%d).\n", res);
+			ntstdio_printf(ntstdio, "src stat err(%d).\n", res);
 		goto cp_end;
 	}
@@ -480,5 +463,5 @@
 		res = f_open(&src_fp, src_str_p, (FA_OPEN_EXISTING | FA_READ));
 		if (res != FR_OK) {
-			ntstdio_printf(&ntstdio, "src open err(%d).\n", res);
+			ntstdio_printf(ntstdio, "src open err(%d).\n", res);
 			goto cp_end;
 		}
@@ -495,5 +478,5 @@
 				dst_mod_str_p = ff_memalloc(LFN_BUF_SIZE);
 				if (dst_mod_str_p == NULL) {
-					ntstdio_printf(&ntstdio, "alloc err.\n");
+					ntstdio_printf(ntstdio, "alloc err.\n");
 					goto cp_end;
 				}
@@ -502,10 +485,10 @@
 			}
 			else {
-				ntstdio_printf(&ntstdio, "dst file exists.\n");
+				ntstdio_printf(ntstdio, "dst file exists.\n");
 				goto cp_end_1;
 			}
 		}
 		else {
-			ntstdio_printf(&ntstdio, "src stat err(%d).\n", res);
+			ntstdio_printf(ntstdio, "src stat err(%d).\n", res);
 			goto cp_end_1;
 		}
@@ -513,5 +496,5 @@
 	res = f_open(&dst_fp, dst_str_p, (FA_CREATE_NEW | FA_WRITE));
 	if (res != FR_OK) {
-		ntstdio_printf(&ntstdio, "dst open err(%d).\n", res);
+		ntstdio_printf(ntstdio, "dst open err(%d).\n", res);
 		goto cp_end_1;
 	}
@@ -524,5 +507,5 @@
 		res = f_read(&src_fp, local_buff, sizeof(local_buff), &read_size);
 		if (res != FR_OK) {
-			ntstdio_printf(&ntstdio, "src read err(%d).\n", res);
+			ntstdio_printf(ntstdio, "src read err(%d).\n", res);
 			goto cp_end_2;
 		}
@@ -531,9 +514,9 @@
 		res = f_write(&dst_fp, local_buff, read_size, &write_size);
 		if (res != FR_OK) {
-			ntstdio_printf(&ntstdio, "dst write err(%d).\n", res);
+			ntstdio_printf(ntstdio, "dst write err(%d).\n", res);
 			goto cp_end_2;
 		}
 		if (read_size != write_size) {
-			ntstdio_printf(&ntstdio, "dst write err(disk full).\n", res);
+			ntstdio_printf(ntstdio, "dst write err(disk full).\n");
 			goto cp_end_2;
 		}
@@ -594,6 +577,4 @@
 }
 
-extern WCHAR Utf8_to_Utf16(const char *, int *); /* in ff.c */
-extern void Utf16_to_Utf8(unsigned char *, int *, UINT); /* in ff.c */
 #define HEXDUMP_EXTRA_FOR_UTF8 3 /* need extra buffer size */
 #define CCOLOR_RESET	0
@@ -626,10 +607,10 @@
 		switch (op) {
 		case 'h': /* help */
-			ntstdio_printf(&ntstdio, " hexdump [OPTION] file\n");
-			ntstdio_printf(&ntstdio, "  -h : help\n");
-			ntstdio_printf(&ntstdio, "  -d : print all byte with convert and color [in character area] (default)\n");
-			ntstdio_printf(&ntstdio, "  -u : try print UTF-8 code [in character area]\n");
-			ntstdio_printf(&ntstdio, "  -oOFFSET : print start offset address from top\n");
-			ntstdio_printf(&ntstdio, "  -sSIZE   : print size\n");
+			ntstdio_printf(ntstdio, " hexdump [OPTION] file\n");
+			ntstdio_printf(ntstdio, "  -h : help\n");
+			ntstdio_printf(ntstdio, "  -d : print all byte with convert and color [in character area] (default)\n");
+			ntstdio_printf(ntstdio, "  -u : try print UTF-8 code [in character area]\n");
+			ntstdio_printf(ntstdio, "  -oOFFSET : print start offset address from top\n");
+			ntstdio_printf(ntstdio, "  -sSIZE   : print size\n");
 			break;
 		case 'd': /* print one byte character [in character area] (default) */
@@ -662,5 +643,5 @@
 	/* position adjusting */
 	if (op_offset >= fsrc.fsize) {
-		ntstdio_printf(&ntstdio, "error : input offset is bigger than file size(0x%X).\n", fsrc.fsize);
+		ntstdio_printf(ntstdio, "error : input offset is bigger than file size(0x%lX).\n", fsrc.fsize);
 		return 0;
 	}
@@ -689,5 +670,5 @@
 		if (br > 16) br = 16;
 
-		char *apos = ascii;
+		unsigned char *apos = ascii;
 		int arst = sizeof(ascii);
 		for (int j = 0; j < br; j++) {
@@ -784,5 +765,5 @@
 		rst -= len;
 
-		ntstdio_puts(&ntstdio, line);
+		ntstdio_puts(ntstdio, line);
 	}
 
@@ -799,5 +780,5 @@
 	ret = shell_clock_gettime(CLOCK_REALTIME, &tp);
 	if (ret != 0) {
-		ntstdio_printf(&ntstdio, "clock_gettime error %d", ret);
+		ntstdio_printf(ntstdio, "clock_gettime error %d", ret);
 		return 0;
 	}
@@ -805,5 +786,5 @@
 	memset(buf, 0, sizeof(buf));
 	if (ctime_r(&tp.tv_sec, buf) == NULL) {
-		ntstdio_printf(&ntstdio, "ctime_r error");
+		ntstdio_printf(ntstdio, "ctime_r error");
 		return 0;
 	}
@@ -813,5 +794,5 @@
 	buf[ret - 1] = '\0';
 
-	ntstdio_printf(&ntstdio, "%s .%09ld\n", buf, tp.tv_nsec);
+	ntstdio_printf(ntstdio, "%s .%09ld\n", buf, tp.tv_nsec);
 	return 0;
 }
@@ -820,10 +801,10 @@
 {
 	if (argc != 2) {
-		ntstdio_printf(&ntstdio, "info sys\n");
-		ntstdio_printf(&ntstdio, "info ver\n");
+		ntstdio_printf(ntstdio, "info sys\n");
+		ntstdio_printf(ntstdio, "info ver\n");
 		return 0;
 	}
 	if (ntlibc_strcmp(argv[1], "sys") == 0) {
-		ntstdio_printf(&ntstdio, "GR-PEACH Monitor\n");
+		ntstdio_printf(ntstdio, TARGET_NAME" Monitor\n");
 		return 0;
 	}
@@ -831,8 +812,8 @@
 		int mj, mn, bd;
 		ntshell_version(&mj, &mn, &bd);
-		ntstdio_printf(&ntstdio, "Version %d.%d.%d\n", mj, mn, bd);
-		return 0;
-	}
-	ntstdio_printf(&ntstdio, "Unknown sub command found\n");
+		ntstdio_printf(ntstdio, "Version %d.%d.%d\n", mj, mn, bd);
+		return 0;
+	}
+	ntstdio_printf(ntstdio, "Unknown sub command found\n");
 	return -1;
 }
Index: /EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.h	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.h	(revision 441)
@@ -56,9 +56,4 @@
 int usrcmd_exit(int argc, char **argv);
 
-void shell_abort();
-void shell_exit(int exitcd);
-int shell_kill(int pid, int sig);
-int shell_gettimeofday(struct timeval * tp, void * tzvp);
-
 #endif
 
Index: /EcnlProtoTool/trunk/ntshell/src/fdtable.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/fdtable.c	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/fdtable.c	(revision 441)
@@ -43,76 +43,126 @@
 #include "syssvc/serial.h"
 #include "syssvc/syslog.h"
-#include <tinet_config.h>
-#include <netinet/in.h>
-#include <netinet/in_itron.h>
-#include <tinet_nic_defs.h>
-#include <tinet_cfg.h>
-#include <netinet/in_var.h>
-#include <net/ethernet.h>
-#include <net/if6_var.h>
-#include <net/net.h>
-#include <net/if_var.h>
-#include <netinet/udp_var.h>
-//#include <ethernet_api.h>
-#include "ff.h"
+#include "target_syssvc.h"
 #include "fdtable.h"
 #include "kernel_cfg.h"
-//#include <string.h>
-
-#define SIO_PORTID 1
-
-#define IO_TYPE_FREE	0
-#define IO_TYPE_SIO		1
-#define IO_TYPE_FILE	2
-#define IO_TYPE_DIR		3
-#define IO_TYPE_TCP		4
-#define IO_TYPE_UDP		5
-
-static struct _IO_FILE fd_table[8 * sizeof(FLGPTN)] = {
-	{ 0, IO_TYPE_SIO, 0, stdio_close, stdin_read, stdio_write, sio_seek, sio_ioctl },
-	{ 1, IO_TYPE_SIO, 0, stdio_close, stdio_read, stdout_write, sio_seek, sio_ioctl },
-	{ 2, IO_TYPE_SIO, 0, stdio_close, stdio_read, stderr_write, sio_seek, sio_ioctl },
+#include <string.h>
+#include "util/ntstdio.h"
+#include "hal/serial_api.h"
+
+#ifdef _DEBUG
+static const char THIS_FILE[] = __FILE__;
+#endif
+
+extern IO_TYPE IO_TYPE_STDIN;
+extern IO_TYPE IO_TYPE_STDOUT;
+extern IO_TYPE IO_TYPE_STDERR;
+
+static struct SHELL_FILE fd_table[8 * sizeof(FLGPTN)] = {
+	{ STDIN_FILENO, &IO_TYPE_STDIN, 0 },
+	{ STDOUT_FILENO, &IO_TYPE_STDOUT, 0 },
+	{ STDERR_FILENO, &IO_TYPE_STDERR, 0 },
 };
 #define fd_table_count (sizeof(fd_table) / sizeof(fd_table[0]))
 
-static int new_fd(int type, int id)
-{
+struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable)
+{
+	struct SHELL_FILE *fp = NULL;
+	ER ret;
+
+	ret = wai_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "wai_sem => %d", ret);
+	}
+
 	for (int fd = 3; fd < fd_table_count; fd++) {
-		struct _IO_FILE *fp = &fd_table[fd];
-		if (fp->type != IO_TYPE_FREE)
+		fp = &fd_table[fd];
+		if (fp->type != NULL)
 			continue;
 
+		memset(fp, 0, sizeof(struct SHELL_FILE));
 		fp->fd = fd;
 		fp->type = type;
 		fp->handle = id;
-		return fd;
-	}
-
-	return -ENOMEM;
-}
-
-static struct _IO_FILE *id_to_fd(int type, int id)
-{
+		fp->writable = writable;
+		break;
+	}
+
+	ret = sig_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "sig_sem => %d", ret);
+	}
+
+	if (fp != NULL) {
+		FLGPTN flgptn = 0;
+
+		FD_SET(fp->fd, (fd_set *)&flgptn);
+
+		ret = clr_flg(FLG_SELECT_WAIT, ~flgptn);
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "clr_flg => %d", ret);
+		}
+	}
+
+	return fp;
+}
+
+struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id)
+{
+	struct SHELL_FILE *fp = NULL;
+	ER ret;
+
+	ret = wai_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "wai_sem => %d", ret);
+	}
+
 	for (int fd = 3; fd < fd_table_count; fd++) {
-		struct _IO_FILE *fp = &fd_table[fd];
+		fp = &fd_table[fd];
 		if ((fp->type == type) && (fp->handle == id))
-			return fp;
-	}
-
-	return NULL;
-}
-
-static int delete_fd(int type, int id)
-{
-	struct _IO_FILE *fp = id_to_fd(type, id);
+			break;
+	}
+
+	ret = sig_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "sig_sem => %d", ret);
+	}
+
+	return fp;
+}
+
+int delete_fd_by_id(IO_TYPE *type, int id)
+{
+	struct SHELL_FILE *fp = id_to_fd(type, id);
 	if (fp == NULL)
 		return -EBADF;
 
-	memset(fp, 0, sizeof(struct _IO_FILE));
+	return delete_fp(fp);
+}
+
+int delete_fp(struct SHELL_FILE *fp)
+{
+	ER ret;
+
+	if (fp->type == NULL)
+		return 0;
+
+	fp->type->delete(fp);
+
+	ret = wai_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "wai_sem => %d", ret);
+	}
+
+	memset(fp, 0, sizeof(struct SHELL_FILE));
+
+	ret = sig_sem(SEM_FILEDESC);
+	if (ret < 0) {
+		syslog(LOG_ERROR, "sig_sem => %d", ret);
+	}
 
 	return 0;
 }
 
-struct _IO_FILE *fd_to_fp(int fd)
+struct SHELL_FILE *fd_to_fp(int fd)
 {
 	if ((fd < 0) || (fd >= fd_table_count))
@@ -121,132 +171,13 @@
 }
 
-struct _IO_FILE *new_sio_fd(int sioid)
-{
-	int fd = new_fd(IO_TYPE_SIO, sioid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = sio_close;
-	fp->read = sio_read;
-	fp->write = sio_write;
-	fp->seek = sio_seek;
-	fp->ioctl = sio_ioctl;
-
-	return fp;
-}
-
-int delete_sio_fd(int sioid)
-{
-	return delete_fd(IO_TYPE_SIO, sioid);
-}
-
-struct _IO_FILE *sioid_to_fd(int sioid)
-{
-	return id_to_fd(IO_TYPE_SIO, sioid);
-}
-
-struct _IO_FILE *new_file_fd(int fileid)
-{
-	int fd = new_fd(IO_TYPE_FILE, fileid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = file_close;
-	fp->read = file_read;
-	fp->write = file_write;
-	fp->seek = file_seek;
-	fp->ioctl = file_ioctl;
-
-	return fp;
-}
-
-int delete_file_fd(int fileid)
-{
-	return delete_fd(IO_TYPE_FILE, fileid);
-}
-
-struct _IO_FILE *fileid_to_fd(int fileid)
-{
-	return id_to_fd(IO_TYPE_FILE, fileid);
-}
-
-struct _IO_FILE *new_dir_fd(int fileid)
-{
-	int fd = new_fd(IO_TYPE_DIR, fileid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = dir_close;
-	fp->read = dir_read;
-	fp->write = dir_write;
-	fp->seek = dir_seek;
-	fp->ioctl = dir_ioctl;
-
-	return fp;
-}
-
-int delete_dir_fd(int dirid)
-{
-	return delete_fd(IO_TYPE_DIR, dirid);
-}
-
-struct _IO_FILE *dirid_to_fd(int dirid)
-{
-	return id_to_fd(IO_TYPE_DIR, dirid);
-}
-
-struct _IO_FILE *new_tcp_fd(int tcpid)
-{
-	int fd = new_fd(IO_TYPE_TCP, tcpid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = tcp_fd_close;
-	fp->read = tcp_fd_read;
-	fp->write = tcp_fd_write;
-	fp->seek = tcp_fd_seek;
-	fp->ioctl = tcp_fd_ioctl;
-
-	return fp;
-}
-
-int delete_tcp_fd(int tcpid)
-{
-	return delete_fd(IO_TYPE_TCP, tcpid);
-}
-
-struct _IO_FILE *tcpid_to_fd(int tcpid)
-{
-	return id_to_fd(IO_TYPE_TCP, tcpid);
-}
-
-struct _IO_FILE *new_udp_fd(int udpid)
-{
-	int fd = new_fd(IO_TYPE_UDP, udpid);
-	if ((fd < 0) || (fd >= fd_table_count))
-		return NULL;
-
-	struct _IO_FILE *fp = &fd_table[fd];
-	fp->close = udp_fd_close;
-	fp->read = udp_fd_read;
-	fp->write = udp_fd_write;
-	fp->seek = udp_fd_seek;
-	fp->ioctl = udp_fd_ioctl;
-
-	return fp;
-}
-
-int delete_udp_fd(int udpid)
-{
-	return delete_fd(IO_TYPE_UDP, udpid);
-}
-
-struct _IO_FILE *udpid_to_fd(int udpid)
-{
-	return id_to_fd(IO_TYPE_UDP, udpid);
+void memand(void *dst, void *src, size_t len)
+{
+	uint8_t *d = (uint8_t *)dst;
+	uint8_t *s = (uint8_t *)src;
+	uint8_t *e = &s[len];
+
+	while (s < e) {
+		*d++ &= *s++;
+	}
 }
 
@@ -258,9 +189,9 @@
 };
 
-ER shell_get_evts(struct fd_events *evts, TMO tmout);
+ER shell_get_evts(struct fd_events *evts, TMO *tmout);
 
 #define TMO_MAX INT_MAX
 
-int shell_select(int n, fd_set *__restrict rfds, fd_set *__restrict wfds, fd_set *__restrict efds, struct timeval *__restrict tv)
+int shell_select(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict efds, struct timeval *restrict tv)
 {
 	ER ret;
@@ -275,20 +206,35 @@
 	}
 
-	memcpy(&evts.readfds, rfds, sizeof(fd_set));
-	memcpy(&evts.writefds, wfds, sizeof(fd_set));
-	memcpy(&evts.errorfds, efds, sizeof(fd_set));
+	if (rfds != NULL)
+		memcpy(&evts.readfds, rfds, sizeof(fd_set));
+	else
+		memset(&evts.readfds, 0, sizeof(fd_set));
+	if (wfds != NULL)
+		memcpy(&evts.writefds, wfds, sizeof(fd_set));
+	else
+		memset(&evts.writefds, 0, sizeof(fd_set));
+	if (efds != NULL)
+		memcpy(&evts.errorfds, efds, sizeof(fd_set));
+	else
+		memset(&evts.errorfds, 0, sizeof(fd_set));
 	evts.count = 0;
 
-	ret = shell_get_evts(&evts, tmout);
+	ret = shell_get_evts(&evts, &tmout);
 	if (ret == E_OK) {
-		memcpy(rfds, &evts.readfds, sizeof(fd_set));
-		memcpy(wfds, &evts.writefds, sizeof(fd_set));
-		memcpy(efds, &evts.errorfds, sizeof(fd_set));
+		if (rfds != NULL)
+			memand(rfds, &evts.readfds, sizeof(fd_set));
+		if (wfds != NULL)
+			memand(wfds, &evts.writefds, sizeof(fd_set));
+		if (efds != NULL)
+			memand(efds, &evts.errorfds, sizeof(fd_set));
 		return evts.count;
 	}
 	if (ret == E_TMOUT) {
-		memset(rfds, 0, sizeof(fd_set));
-		memset(wfds, 0, sizeof(fd_set));
-		memset(efds, 0, sizeof(fd_set));
+		if (rfds != NULL)
+			memset(rfds, 0, sizeof(fd_set));
+		if (wfds != NULL)
+			memset(wfds, 0, sizeof(fd_set));
+		if (efds != NULL)
+			memset(efds, 0, sizeof(fd_set));
 		return 0;
 	}
@@ -310,4 +256,5 @@
 		tmout = TMO_MAX;
 
+retry:
 	memset(&evts, 0, sizeof(evts));
 
@@ -327,5 +274,5 @@
 	}
 
-	ret = shell_get_evts(&evts, tmout);
+	ret = shell_get_evts(&evts, &tmout);
 	if (ret == E_OK) {
 		int result = 0;
@@ -345,4 +292,6 @@
 				result++;
 		}
+		if (result == 0)
+			goto retry;
 		return result;
 	}
@@ -354,191 +303,121 @@
 }
 
-void stdio_update_evts()
-{
-	int fd = STDIN_FILENO;
-	struct _IO_FILE *fp = &fd_table[fd];
-	T_SERIAL_RPOR rpor;
-	FLGPTN flgptn = 0;
-
-	ER ret = serial_ref_por(SIO_PORTID, &rpor);
-	if (ret != E_OK)
-		return;
-
-	if (rpor.reacnt != 0) {
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		FD_SET(fd, (fd_set *)&flgptn);
-	}
-	if (rpor.wricnt != 0) {
-		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
-
-		FD_SET(fd, (fd_set *)&flgptn);
-	}
-
-	if (flgptn != 0) {
-		set_flg(FLG_SELECT_WAIT, flgptn);
-	}
-}
-
-void stdio_flgptn(FLGPTN *flgptn)
-{
-	int fd = STDIN_FILENO;
-	struct _IO_FILE *fp = &fd_table[fd];
-	T_SERIAL_RPOR rpor;
-	*flgptn = 0;
-
-	ER ret = serial_ref_por(SIO_PORTID, &rpor);
-	if (ret != E_OK)
-		return;
-
-	if (rpor.reacnt != 0) {
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		FD_SET(fd, (fd_set *)flgptn);
-	}
-	if (rpor.wricnt != 0) {
-		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
-
-		FD_SET(fd, (fd_set *)flgptn);
-	}
-}
-
-ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk)
-{
-	struct _IO_FILE *fp = tcpid_to_fd(cepid);
-	FLGPTN flgptn = 0;
-
-	if (fp == NULL)
-		return E_PAR;
-
-	int fd = fp->fd;
-	FD_SET(fd, (fd_set *)&flgptn);
-
-	switch (fncd) {
-	case TFN_TCP_RCV_DAT:
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_TCP_SND_DAT:
-		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_TCP_CAN_CEP:
-		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_TCP_DEL_REP:
-		delete_tcp_rep(cepid);
-		return E_OK;
-
-	case TFN_TCP_DEL_CEP:
-		delete_tcp_fd(cepid);
-		return E_OK;
-
-	default:
-		return E_OK;
-	}
-}
-
-ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk)
-{
-	struct _IO_FILE *fp = udpid_to_fd(cepid);
-	FLGPTN flgptn = 0;
-
-	if (fp == NULL)
-		return E_PAR;
-
-	int fd = fp->fd;
-	FD_SET(fd, (fd_set *)&flgptn);
-
-	switch (fncd) {
-	case TFN_UDP_CRE_CEP:
-	case TFN_UDP_RCV_DAT:
-		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_UDP_SND_DAT:
-		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_UDP_CAN_CEP:
-		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
-
-		set_flg(FLG_SELECT_WAIT, flgptn);
-		return E_OK;
-
-	case TFN_UDP_DEL_CEP:
-		delete_udp_fd(cepid);
-		return E_OK;
-
-	default:
-		return E_OK;
-	}
-}
-
-ER shell_get_evts(struct fd_events *evts, TMO tmout)
-{
-	ER ret;
-	FLGPTN waitptn, flgptn = 0;
-
-	stdio_update_evts();
-
-	waitptn = *((FLGPTN *)&evts->readfds) | *((FLGPTN *)&evts->writefds) | *((FLGPTN *)&evts->errorfds);
-	memset(evts, 0, sizeof(*evts));
-
-	/* イベント待ち */
-	ret = twai_flg(FLG_SELECT_WAIT, waitptn, TWF_ORW, &flgptn, tmout);
-	if (ret != E_OK) {
-		if (ret != E_TMOUT) {
-			syslog(LOG_ERROR, "twai_flg => %d", ret);
-			return ret;
-		}
-
-		stdio_flgptn(&flgptn);
-
-		if (flgptn == 0)
+ER shell_get_evts(struct fd_events *evts, TMO *tmout)
+{
+	int count;
+	SYSTIM prev, now;
+	FLGPTN flgptn;
+
+	get_tim(&prev);
+
+	for (;;) {
+		ER ret;
+		FLGPTN waitptn, readfds = 0, writefds = 0;
+		struct SHELL_FILE *fp = NULL;
+
+#ifndef NTSHELL_NO_SOCKET
+		waitptn = *((FLGPTN *)&evts->errorfds);
+#else
+		waitptn = *((FLGPTN *)&evts->readfds) | *((FLGPTN *)&evts->errorfds);
+#endif
+		count = 0;
+		for (int fd = 0; fd < fd_table_count; fd++) {
+			fp = &fd_table[fd];
+
+			if (FD_ISSET(fd, &evts->readfds)) {
+				if (fp->type->readable(fp)) {
+					FD_SET(fd, (fd_set *)&readfds);
+					count++;
+					if (fp->readevt_w == fp->readevt_r) fp->readevt_r--;
+				}
+				else {
+					FD_SET(fd, (fd_set *)&waitptn);
+				}
+			}
+
+			if (FD_ISSET(fd, &evts->writefds)) {
+				if (fp->type->writable(fp)) {
+					FD_SET(fd, (fd_set *)&writefds);
+					count++;
+					if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_r--;
+				}
+				else {
+					FD_SET(fd, (fd_set *)&waitptn);
+				}
+			}
+		}
+		memset(evts, 0, sizeof(*evts));
+
+		if (waitptn == 0) {
+			memcpy(&evts->readfds, &readfds, sizeof(evts->readfds));
+			memcpy(&evts->writefds, &writefds, sizeof(evts->writefds));
+			evts->count = count;
+			return E_OK;
+		}
+		else if ((readfds | writefds) != 0) {
+			set_flg(FLG_SELECT_WAIT, (readfds | writefds));
+		}
+
+		/* イベント待ち */
+		flgptn = 0;
+		ret = twai_flg(FLG_SELECT_WAIT, waitptn, TWF_ORW, &flgptn, *tmout);
+		if (ret != E_OK) {
+			if (ret != E_TMOUT) {
+				syslog(LOG_ERROR, "twai_flg => %d", ret);
+				return ret;
+			}
+		}
+
+		if (flgptn != 0) {
+			flgptn &= waitptn;
+
+			/* 受け取ったフラグのみクリア */
+			ret = clr_flg(FLG_SELECT_WAIT, ~flgptn);
+			if (ret != E_OK) {
+				syslog(LOG_ERROR, "clr_flg => %d", ret);
+			}
+		}
+
+		count = 0;
+		for (int fd = 0; fd < fd_table_count; fd++) {
+			fp = &fd_table[fd];
+
+			if (FD_ISSET(fd, (fd_set *)&waitptn)
+				&& (fp->readevt_w != fp->readevt_r)) {
+				fp->readevt_r++;
+				FD_SET(fd, &evts->readfds);
+				count++;
+			}
+			if (FD_ISSET(fd, (fd_set *)&waitptn)
+				&& (fp->writeevt_w != fp->writeevt_r)) {
+				fp->writeevt_r++;
+				FD_SET(fd, &evts->writefds);
+				count++;
+			}
+			if (FD_ISSET(fd, (fd_set *)&waitptn)
+				&& (fp->errorevt_w != fp->errorevt_r)) {
+				fp->errorevt_r++;
+				FD_SET(fd, &evts->errorfds);
+				count++;
+			}
+		}
+
+		if (count > 0)
+			break;
+
+		get_tim(&now);
+
+		SYSTIM elapse = now - prev;
+		if (elapse > *tmout) {
+			*tmout = 0;
+			evts->count = 0;
 			return E_TMOUT;
-	}
-	flgptn &= waitptn;
-
-	/* 受け取ったフラグのみクリア */
-	ret = clr_flg(FLG_SELECT_WAIT, ~flgptn);
-	if (ret != E_OK) {
-		syslog(LOG_ERROR, "clr_flg => %d", ret);
-	}
-
-	struct _IO_FILE *fp = NULL;
-	for (int fd = 0; fd < fd_table_count; fd++) {
-		if (!FD_ISSET(fd, (fd_set *)&flgptn))
-			continue;
-
-		fp = &fd_table[fd];
-
-		if (fp->readevt_w != fp->readevt_r) {
-			fp->readevt_r++;
-			FD_SET(fd, &evts->readfds);
-			evts->count++;
-		}
-		if (fp->writeevt_w != fp->writeevt_r) {
-			fp->writeevt_r++;
-			FD_SET(fd, &evts->writefds);
-			evts->count++;
-		}
-		if (fp->errorevt_w != fp->errorevt_r) {
-			fp->errorevt_r++;
-			FD_SET(fd, &evts->errorfds);
-			evts->count++;
-		}
-	}
+		}
+
+		prev = now;
+		*tmout -= elapse;
+	}
+
+	evts->count = count;
 
 	return E_OK;
@@ -547,5 +426,5 @@
 void clean_fd()
 {
-	struct _IO_FILE *fp = NULL;
+	struct SHELL_FILE *fp = NULL;
 	for (int fd = 3; fd < fd_table_count; fd++) {
 		fp = &fd_table[fd];
@@ -553,16 +432,164 @@
 			continue;
 
-		fp->close(fp);
-
-		memset(fp, 0, sizeof(*fp));
-	}
+		fp->type->close(fp);
+
+		delete_fp(fp);
+	}
+}
+
+int shell_close(int fd)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || (fp->type == NULL))
+		return -EBADF;
+
+	int ret = fp->type->close(fp);
+
+	delete_fp(fp);
+
+	return ret;
+}
+
+ssize_t shell_read(int fd, void *data, size_t len)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || (fp->type == NULL))
+		return -EBADF;
+
+	return fp->type->read(fp, (unsigned char *)data, len);
+}
+
+int shell_readv(int fd, const struct iovec *iov, int iovcnt)
+{
+	int result = 0;
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || (fp->type == NULL))
+		return -EBADF;
+
+	const struct iovec *end = &iov[iovcnt];
+	for (; iov < end; iov++) {
+		result += fp->type->read(fp, (unsigned char *)iov->iov_base, iov->iov_len);
+	}
+
+	return result;
+}
+
+ssize_t shell_write(int fd, const void *data, size_t len)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || (fp->type == NULL))
+		return -EBADF;
+
+	return fp->type->write(fp, (unsigned char *)data, len);
+}
+
+int shell_writev(int fd, const struct iovec *iov, int iovcnt)
+{
+	int result = 0;
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || (fp->type == NULL))
+		return -EBADF;
+
+	const struct iovec *end = &iov[iovcnt];
+	for (; iov < end; iov++) {
+		result += fp->type->write(fp, (unsigned char *)iov->iov_base, iov->iov_len);
+	}
+
+	return result;
+}
+
+int shell_llseek(int fd, off_t ptr, off_t *result, int dir)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || (fp->type == NULL))
+		return -EBADF;
+
+	off_t ret = fp->type->seek(fp, ptr, dir);
+	if (ret < 0)
+		return ret;
+
+	*result = ret;
+	return 0;
 }
 
 int shell_ioctl(int fd, int request, void *arg)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
 
-	return fp->ioctl(fp, request, arg);
-}
+	return fp->type->ioctl(fp, request, arg);
+}
+
+#ifdef NTSHELL_NO_SOCKET
+
+int shell_socket(int family, int type, int protocol)
+{
+	return -ENOMEM;
+}
+
+int shell_bind(int fd, const struct sockaddr *addr, socklen_t len)
+{
+	return -ENOMEM;
+}
+
+int shell_listen(int fd, int backlog)
+{
+	return -ENOMEM;
+}
+
+int shell_connect(int fd, const struct sockaddr *addr, socklen_t len)
+{
+	return -ENOMEM;
+}
+
+int shell_accept(int fd, struct sockaddr *restrict addr, socklen_t *restrict len)
+{
+	return -ENOMEM;
+}
+
+ssize_t shell_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
+{
+	return -ENOMEM;
+}
+
+ssize_t shell_sendmsg(int fd, const struct msghdr *msg, int flags)
+{
+	return -ENOMEM;
+}
+
+ssize_t shell_recvfrom(int fd, void *restrict buf, size_t len, int flags, struct sockaddr *restrict addr, socklen_t *restrict alen)
+{
+	return -ENOMEM;
+}
+
+ssize_t shell_recvmsg(int fd, struct msghdr *msg, int flags)
+{
+	return -ENOMEM;
+}
+
+int shell_shutdown(int fd, int how)
+{
+	return -ENOMEM;
+}
+
+int shell_getsockopt(int fd, int level, int optname, void *optval, socklen_t *restrict optlen)
+{
+	return -ENOMEM;
+}
+
+int shell_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
+{
+	return -ENOMEM;
+}
+
+int shell_getpeername(int fd, struct sockaddr *restrict addr, socklen_t *restrict len)
+{
+	return -ENOMEM;
+}
+
+int shell_getsockname(int fd, struct sockaddr *restrict addr, socklen_t *restrict len)
+{
+	return -ENOMEM;
+}
+#endif
Index: /EcnlProtoTool/trunk/ntshell/src/fdtable.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/fdtable.h	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/fdtable.h	(revision 441)
@@ -35,93 +35,32 @@
  *  @(#) $Id$
  */
-#ifndef SOCKET_STUB_H
-#define SOCKET_STUB_H
+#ifndef _FDTABLE_H_
+#define _FDTABLE_H_
 
-struct addrinfo {
-	int ai_flags;
-	int ai_family;
-	int ai_socktype;
-	int ai_protocol;
-	socklen_t ai_addrlen;
-	struct sockaddr *ai_addr;
-	char *ai_canonname;
-	struct addrinfo *ai_next;
-};
+typedef const struct io_type_s IO_TYPE;
 
-typedef uint16_t in_port_t;
-typedef uint32_t in_addr_t;
-struct in_addr { in_addr_t s_addr; };
-
-struct sockaddr_in {
-	sa_family_t sin_family;
-	in_port_t sin_port;
-	struct in_addr sin_addr;
-	uint8_t sin_zero[8];
-};
-
-struct in6_addr
-{
-	union {
-		uint8_t __s6_addr[16];
-		uint16_t __s6_addr16[8];
-		uint32_t __s6_addr32[4];
-	} __in6_union;
-};
-//#define s6_addr __in6_union.__s6_addr
-//#define s6_addr16 __in6_union.__s6_addr16
-//#define s6_addr32 __in6_union.__s6_addr32
-
-struct sockaddr_in6
-{
-	sa_family_t     sin6_family;
-	in_port_t       sin6_port;
-	uint32_t        sin6_flowinfo;
-	struct in6_addr sin6_addr;
-	uint32_t        sin6_scope_id;
-};
-
-typedef struct socket_t {
-	int family;
-	int type;
-	int protocol;
-	int cepid;
-	int repid;
-	int backlog;
-	unsigned int flags;
-	union {
-		struct sockaddr_in laddr4;
-		struct sockaddr_in6 laddr6;
-	};
-	union {
-		struct sockaddr_in raddr4;
-		struct sockaddr_in6 raddr6;
-	};
-	int buf_size;
-	unsigned char *buf;
-} socket_t;
-
-struct _IO_FILE {
+struct SHELL_FILE {
 	int fd;
-	int type;
+	IO_TYPE *type;
 	int handle;
-	int (*close)(struct _IO_FILE *);
-	size_t (*read)(struct _IO_FILE *, unsigned char *, size_t);
-	size_t (*write)(struct _IO_FILE *, const unsigned char *, size_t);
-	off_t (*seek)(struct _IO_FILE *, off_t, int);
-	int (*ioctl)(struct _IO_FILE *, int, void *);
 	int readevt_r;
 	int readevt_w;
 	int writeevt_r;
 	int writeevt_w;
+	int writable;
 	int errorevt_r;
 	int errorevt_w;
-	union {
-		FIL file;
-		struct {
-			FATFS_DIR dir;
-			struct dirent dirent;
-		};
-		socket_t socket;
-	};
+	void *exinf;
+};
+
+struct io_type_s {
+	const int (*close)(struct SHELL_FILE *);
+	const size_t (*read)(struct SHELL_FILE *, unsigned char *, size_t);
+	const size_t (*write)(struct SHELL_FILE *, const unsigned char *, size_t);
+	const off_t (*seek)(struct SHELL_FILE *, off_t, int);
+	const int (*ioctl)(struct SHELL_FILE *, int, void *);
+	const bool_t (*readable)(struct SHELL_FILE *);
+	const bool_t (*writable)(struct SHELL_FILE *);
+	const void (*delete)(struct SHELL_FILE *);
 };
 
@@ -136,68 +75,11 @@
 #endif
 
-extern int stdio_close(struct _IO_FILE *fp);
-extern size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern size_t stdin_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t stdout_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern size_t stderr_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
+struct SHELL_FILE *new_fp(IO_TYPE *type, int id, int writable);
+int delete_fd_by_id(IO_TYPE *type, int id);
+struct SHELL_FILE *fd_to_fp(int fd);
+struct SHELL_FILE *id_to_fd(IO_TYPE *type, int id);
 
-extern int sio_close(struct _IO_FILE *fp);
-extern size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int sio_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-extern int file_close(struct _IO_FILE *fp);
-extern size_t file_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t file_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t file_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int file_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-extern int dir_close(struct _IO_FILE *fp);
-extern size_t dir_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t dir_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t dir_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int dir_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-extern int tcp_fd_close(struct _IO_FILE *fp);
-extern size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-extern int udp_fd_close(struct _IO_FILE *fp);
-extern size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *data, size_t len);
-extern size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *data, size_t len);
-extern off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org);
-extern int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg);
-
-struct _IO_FILE *fd_to_fp(int fd);
-
-struct _IO_FILE *new_sio_fd(int sioid);
-int delete_sio_fd(int sioid);
-struct _IO_FILE *sioid_to_fd(int sioid);
-
-struct _IO_FILE *new_file_fd(int fileid);
-int delete_file_fd(int fileid);
-struct _IO_FILE *fileid_to_fd(int fileid);
-
-struct _IO_FILE *new_dir_fd(int dirid);
-int delete_dir_fd(int dirid);
-struct _IO_FILE *dirid_to_fd(int dirid);
-
-struct _IO_FILE *new_tcp_fd(int tcpid);
-int delete_tcp_fd(int tcpid);
-struct _IO_FILE *tcpid_to_fd(int tcpid);
-
-struct _IO_FILE *new_udp_fd(int udpid);
-int delete_udp_fd(int udpid);
-struct _IO_FILE *udpid_to_fd(int udpid);
-
-int delete_tcp_rep(int repid);
+int delete_fp(struct SHELL_FILE *fp);
 void clean_fd();
 
-ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk);
-ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk);
-
-#endif // !SOCKET_STUB_H
+#endif /* _FDTABLE_H_ */
Index: /EcnlProtoTool/trunk/ntshell/src/io_stub.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/io_stub.c	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/io_stub.c	(revision 441)
@@ -1,7 +1,7 @@
 /*
  *  TOPPERS PROJECT Home Network Working Group Software
- * 
+ *
  *  Copyright (C) 2017-2019 Cores Co., Ltd. Japan
- * 
+ *
  *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
  *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
@@ -26,5 +26,5 @@
  *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
  *      免責すること．
- * 
+ *
  *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
  *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
@@ -32,5 +32,5 @@
  *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
  *  の責任を負わない．
- * 
+ *
  *  @(#) $Id$
  */
@@ -42,24 +42,18 @@
 #include <t_stdlib.h>
 #include <sil.h>
-//#include <string.h>
-#include <setjmp.h>
+#include <string.h>
+#include "syssvc/serial.h"
 #include "syssvc/syslog.h"
-#include <tinet_config.h>
-#include <netinet/in.h>
-#include <netinet/in_itron.h>
-#include <tinet_nic_defs.h>
-#include <tinet_cfg.h>
-#include <netinet/in_var.h>
-#include <net/ethernet.h>
-#include <net/if6_var.h>
-#include <net/net.h>
-#include <net/if_var.h>
-#include <netinet/udp_var.h>
-//#include <ethernet_api.h>
 #include "fdtable.h"
-//#include <sys/stat.h>
 #include "util/ntstdio.h"
 #include "usrcmd.h"
 #include "core/ntlibc.h"
+#include "kernel_cfg.h"
+#include "target_syssvc.h"
+
+struct SHELL_DIR {
+	FATFS_DIR dir;
+	struct dirent dirent;
+};
 
 int fresult2errno(FRESULT res)
@@ -90,17 +84,41 @@
 }
 
-int shell_open(const char * path, int flags, void *arg)
-{
-	FRESULT res;
-	struct _IO_FILE *fp;
+static int file_close(struct SHELL_FILE *fp);
+static size_t file_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t file_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t file_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int file_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t file_readable(struct SHELL_FILE *fp);
+static bool_t file_writable(struct SHELL_FILE *fp);
+static void file_delete(struct SHELL_FILE *fp);
+
+static int dir_close(struct SHELL_FILE *fp);
+static size_t dir_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t dir_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t dir_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t dir_readable(struct SHELL_FILE *fp);
+static bool_t dir_writable(struct SHELL_FILE *fp);
+static void dir_delete(struct SHELL_FILE *fp);
+
+IO_TYPE IO_TYPE_FILE = { file_close, file_read, file_write, file_seek, file_ioctl, file_readable, file_writable, file_delete };
+IO_TYPE IO_TYPE_DIR = { dir_close, dir_read, dir_write, dir_seek, dir_ioctl, dir_readable, dir_writable, dir_delete };
+
+int shell_open(const char *path, int flags, void *arg)
+{
+	FRESULT res;
+	struct SHELL_FILE *fp;
 
 	if (flags & O_DIRECTORY) {
-		fp = new_dir_fd(0);
+		fp = new_fp(&IO_TYPE_DIR, 0, 0);
 		if (fp == NULL)
 			return -ENOMEM;
 
-		FATFS_DIR *dir = &fp->dir;
-		FRESULT res;
+		fp->exinf = malloc(sizeof(struct SHELL_DIR));
+		memset(fp->exinf, 0, sizeof(struct SHELL_DIR));
+
+		FATFS_DIR *dir = &((struct SHELL_DIR *)fp->exinf)->dir;
 		if ((res = f_opendir(dir, path)) != FR_OK) {
+			delete_fp(fp);
 			return fresult2errno(res);
 		}
@@ -108,7 +126,10 @@
 	}
 
-	fp = new_file_fd(0);
+	fp = new_fp(&IO_TYPE_FILE, 0, 1);
 	if (fp == NULL)
 		return -ENOMEM;
+
+	fp->exinf = malloc(sizeof(FIL));
+	memset(fp->exinf, 0, sizeof(FIL));
 
 	BYTE fmd = 0;
@@ -146,17 +167,18 @@
 	}
 
-	if ((res = f_open(&fp->file, path, fmd)) == FR_OK) {
+	if ((res = f_open((FIL *)fp->exinf, path, fmd)) == FR_OK) {
 		fp->handle = fp->fd;
 		return fp->fd;
 	}
 
+	delete_fp(fp);
 	return fresult2errno(res);
 }
 
-int file_close(struct _IO_FILE *fp)
-{
-	FRESULT res;
-
-	if ((res = f_close(&fp->file)) == FR_OK) {
+int file_close(struct SHELL_FILE *fp)
+{
+	FRESULT res;
+
+	if ((res = f_close((FIL *)fp->exinf)) == FR_OK) {
 		return 0;
 	}
@@ -165,10 +187,10 @@
 }
 
-size_t file_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
+size_t file_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
 {
 	unsigned int ret = 0;
 	FRESULT res;
 
-	if ((res = f_read(&fp->file, data, len, &ret)) != FR_OK)
+	if ((res = f_read((FIL *)fp->exinf, data, len, &ret)) != FR_OK)
 		return -EIO;
 
@@ -176,10 +198,10 @@
 }
 
-size_t file_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
+size_t file_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
 {
 	unsigned int ret = 0;
 	FRESULT res;
 
-	if ((res = f_write(&fp->file, data, len, &ret)) != FR_OK)
+	if ((res = f_write((FIL *)fp->exinf, data, len, &ret)) != FR_OK)
 		return -EIO;
 
@@ -187,5 +209,5 @@
 }
 
-off_t file_seek(struct _IO_FILE *fp, off_t ptr, int dir)
+off_t file_seek(struct SHELL_FILE *fp, off_t ptr, int dir)
 {
 	switch (dir) {
@@ -204,15 +226,15 @@
 
 	FRESULT res;
-	if ((res = f_seek(&fp->file, ptr, dir)) != FR_OK)
+	if ((res = f_seek((FIL *)fp->exinf, ptr, dir)) != FR_OK)
 		return -EIO;
 
-	return fp->file.fptr;
-}
-
-int file_ioctl(struct _IO_FILE *fp, int req, void *arg)
+	return ((FIL *)fp->exinf)->fptr;
+}
+
+int file_ioctl(struct SHELL_FILE *fp, int req, void *arg)
 {
 	DRESULT res;
 
-	if ((res = disk_ioctl(fp->file.fs->drv, req, arg) != RES_OK))
+	if ((res = disk_ioctl(((FIL *)fp->exinf)->fs->drv, req, arg) != RES_OK))
 		return -EINVAL;
 
@@ -220,78 +242,23 @@
 }
 
-int shell_close(int fd)
-{
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	return fp->close(fp);
-}
-
-ssize_t shell_read(int fd, void *data, size_t len)
-{
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	return fp->read(fp, (unsigned char *)data, len);
-}
-
-int shell_readv(int fd, const struct iovec *iov, int iovcnt)
-{
-	int result = 0;
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	const struct iovec *end = &iov[iovcnt];
-	for (; iov < end; iov++) {
-		result += fp->read(fp, (unsigned char *)iov->iov_base, iov->iov_len);
-	}
-
-	return result;
-}
-
-ssize_t shell_write(int fd, const void *data, size_t len)
-{
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	return fp->write(fp, (unsigned char *)data, len);
-}
-
-int shell_writev(int fd, const struct iovec *iov, int iovcnt)
-{
-	int result = 0;
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	const struct iovec *end = &iov[iovcnt];
-	for (; iov < end; iov++) {
-		result += fp->write(fp, (unsigned char *)iov->iov_base, iov->iov_len);
-	}
-
-	return result;
-}
-
-int shell_llseek(int fd, off_t ptr, off_t *result, int dir)
-{
-	struct _IO_FILE *fp = fd_to_fp(fd);
-	if (fp == NULL)
-		return -EBADF;
-
-	off_t ret = fp->seek(fp, ptr, dir);
-	if (ret < 0)
-		return ret;
-
-	*result = ret;
-	return 0;
+bool_t file_readable(struct SHELL_FILE *fp)
+{
+	return fp->readevt_w != fp->readevt_r;
+}
+
+bool_t file_writable(struct SHELL_FILE *fp)
+{
+	return fp->writable && (fp->writeevt_w == fp->writeevt_r);
+}
+
+void file_delete(struct SHELL_FILE *fp)
+{
+	free((FIL *)fp->exinf);
+	fp->exinf = NULL;
 }
 
 int shell_fstat(int fd, struct stat * st)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
@@ -305,5 +272,5 @@
 int shell_fsync(int fd)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
@@ -313,10 +280,10 @@
 int shell_ftruncate(int fd, off_t length)
 {
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
 
 	FRESULT res;
-	if ((res = f_truncate(&fp->file)) != FR_OK)
+	if ((res = f_truncate((FIL *)fp->exinf)) != FR_OK)
 		return fresult2errno(res);
 
@@ -329,77 +296,5 @@
 }
 
-int sio_tcgetattr(int fd, struct termios *termios)
-{
-	extern ntstdio_t ntstdio;
-
-	if (fd == STDIN_FILENO) {
-		memset(termios, 0, sizeof(*termios));
-
-		if (ntstdio.option & NTSTDIO_OPTION_LINE_ECHO) {
-			termios->c_lflag |= ECHO;
-		}
-		else {
-			termios->c_lflag &= ~ECHO;
-		}
-		if (ntstdio.option & NTSTDIO_OPTION_CANON) {
-			termios->c_lflag |= ICANON;
-		}
-		else {
-			termios->c_lflag &= ~ICANON;
-		}
-		if (ntstdio.option & NTSTDIO_OPTION_LF_CR) {
-			termios->c_iflag |= INLCR;
-		}
-		else {
-			termios->c_iflag &= ~INLCR;
-		}
-		if (ntstdio.option & NTSTDIO_OPTION_LF_CRLF) {
-			termios->c_oflag |= ONLCR;
-		}
-		else {
-			termios->c_oflag &= ~ONLCR;
-		}
-		return 0;
-	}
-	shell_abort();
-	return 0;
-}
-
-int sio_tcsetattr(int fd, int optional_actions, const struct termios *termios)
-{
-	extern ntstdio_t ntstdio;
-
-	if ((fd == STDIN_FILENO) && (optional_actions == TCSANOW)) {
-		if (termios->c_lflag & ECHO) {
-			ntstdio.option |= NTSTDIO_OPTION_LINE_ECHO;
-		}
-		else {
-			ntstdio.option &= ~NTSTDIO_OPTION_LINE_ECHO;
-		}
-		if (termios->c_lflag & ICANON) {
-			ntstdio.option |= NTSTDIO_OPTION_CANON;
-		}
-		else {
-			ntstdio.option &= ~NTSTDIO_OPTION_CANON;
-		}
-		if (termios->c_iflag & INLCR) {
-			ntstdio.option |= NTSTDIO_OPTION_LF_CR;
-		}
-		else{
-			ntstdio.option &= ~NTSTDIO_OPTION_LF_CR;
-		}
-		if (termios->c_oflag & ONLCR) {
-			ntstdio.option |= NTSTDIO_OPTION_LF_CRLF;
-		}
-		else {
-			ntstdio.option &= ~NTSTDIO_OPTION_LF_CRLF;
-		}
-		return 0;
-	}
-	shell_abort();
-	return 0;
-}
-
-int shell_stat(const char *__restrict path, struct stat *__restrict st)
+int shell_stat(const char *restrict path, struct stat *restrict st)
 {
 	FILINFO fi;
@@ -434,6 +329,6 @@
 	st->st_size = fi.fsize;
 	st->st_mtim.tv_nsec = 0;
-	st->st_mtim.tv_sec = fi.fdate + fi.ftime;
-	st->st_mode  = (S_IRUSR | S_IRGRP | S_IROTH);
+	st->st_mtim.tv_sec = (time_t)fi.fdate + (time_t)fi.ftime;
+	st->st_mode = (S_IRUSR | S_IRGRP | S_IROTH);
 	st->st_mode |= (fi.fattrib & AM_RDO) ? 0 : (S_IWUSR | S_IWGRP | S_IWOTH);
 	st->st_mode |= (fi.fattrib & (AM_DIR | AM_VOL)) ? S_IFDIR : S_IFREG;
@@ -442,5 +337,5 @@
 }
 
-int shell_lstat(const char *__restrict path, struct stat *__restrict st)
+int shell_lstat(const char *restrict path, struct stat *restrict st)
 {
 	return shell_stat(path, st);
@@ -494,6 +389,6 @@
 	BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID
 
-	if(mode & S_IREAD) {
-		if((mode & S_IWRITE) == 0) {
+	if (mode & S_IREAD) {
+		if ((mode & S_IWRITE) == 0) {
 			attr |= AM_RDO;
 		}
@@ -503,5 +398,5 @@
 	}
 
-	if((res = f_chmod(path, attr, mask)) != FR_OK) {
+	if ((res = f_chmod(path, attr, mask)) != FR_OK) {
 		return fresult2errno(res);
 	}
@@ -516,6 +411,6 @@
 	BYTE mask = AM_RDO | AM_SYS; // AM_ARC, AM_HID
 
-	if(mode & S_IREAD) {
-		if((mode & S_IWRITE) == 0) {
+	if (mode & S_IREAD) {
+		if ((mode & S_IWRITE) == 0) {
 			attr |= AM_RDO;
 		}
@@ -525,5 +420,5 @@
 	}
 
-	if((res = f_chmod(path, attr, mask)) != FR_OK) {
+	if ((res = f_chmod(path, attr, mask)) != FR_OK) {
 		return fresult2errno(res);
 	}
@@ -535,5 +430,5 @@
 {
 	FRESULT ret;
-	if((ret = f_getcwd(buf, size)) != FR_OK) {
+	if ((ret = f_getcwd(buf, size)) != FR_OK) {
 		return NULL;
 	}
@@ -558,8 +453,8 @@
 }
 
-int dir_close(struct _IO_FILE *fp)
-{
-	FRESULT res;
-	if ((res = f_closedir(&fp->dir)) != FR_OK) {
+int dir_close(struct SHELL_FILE *fp)
+{
+	FRESULT res;
+	if ((res = f_closedir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) {
 		return fresult2errno(res);
 	}
@@ -573,5 +468,5 @@
 		return -EINVAL;
 
-	struct _IO_FILE *fp = fd_to_fp(fd);
+	struct SHELL_FILE *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
@@ -584,5 +479,5 @@
 #endif
 	FRESULT res;
-	if ((res = f_readdir(&fp->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
+	if ((res = f_readdir(&((struct SHELL_DIR *)fp->exinf)->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
 		return fresult2errno(res);
 	}
@@ -598,15 +493,15 @@
 }
 
-size_t dir_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
+size_t dir_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
 {
 	return -EPERM;
 }
 
-size_t dir_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
+size_t dir_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
 {
 	return -EPERM;
 }
 
-off_t dir_seek(struct _IO_FILE *fp, off_t ptr, int dir)
+off_t dir_seek(struct SHELL_FILE *fp, off_t ptr, int dir)
 {
 	FRESULT res;
@@ -616,5 +511,5 @@
 
 	if (ptr == 0) {
-		if ((res = f_rewinddir(&fp->dir)) != FR_OK) {
+		if ((res = f_rewinddir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) {
 			return fresult2errno(res);
 		}
@@ -627,10 +522,10 @@
 		fno.lfsize = sizeof lfn;
 #endif
-		if ((res = f_rewinddir(&fp->dir)) != FR_OK) {
+		if ((res = f_rewinddir(&((struct SHELL_DIR *)fp->exinf)->dir)) != FR_OK) {
 			return fresult2errno(res);
 		}
 
 		for (int i = 0; i < ptr; i++) {
-			if ((res = f_readdir(&fp->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
+			if ((res = f_readdir(&((struct SHELL_DIR *)fp->exinf)->dir, &fno)) != FR_OK || fno.fname[0] == '\0') {
 				return fresult2errno(res);
 			}
@@ -641,7 +536,23 @@
 }
 
-int dir_ioctl(struct _IO_FILE *fp, int req, void *arg)
+int dir_ioctl(struct SHELL_FILE *fp, int req, void *arg)
 {
 	return -EINVAL;
+}
+
+bool_t dir_readable(struct SHELL_FILE *fp)
+{
+	return fp->readevt_w != fp->readevt_r;
+}
+
+bool_t dir_writable(struct SHELL_FILE *fp)
+{
+	return false;
+}
+
+void dir_delete(struct SHELL_FILE *fp)
+{
+	free((struct SHELL_DIR *)fp->exinf);
+	fp->exinf = NULL;
 }
 
@@ -662,38 +573,2 @@
 	return 0;
 }
-
-//#include "../musl-1.1.18/include/bits/limits.h"
-#define PAGE_SIZE 4096
-
-uint32_t  __CmdBase;
-uint32_t  __CmdLimit;
-
-void *shell_brk(void *addr)
-{
-	if (addr == 0) {
-		return (void *)((intptr_t)&__CmdBase + 0x20000);
-	}
-	if ((addr >= (intptr_t)&__CmdBase + 0x20000) && (addr < &__CmdLimit)) {
-		return addr;
-	}
-	return (void *)-1;
-}
-
-void *shell_mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)
-{
-	if (fd != -1)
-		return -EINVAL;
-
-	if ((length >= 0) && (length <= (intptr_t)&__CmdLimit - (intptr_t)&__CmdBase - 0x20000)) {
-		return &__CmdBase + 0x20000;
-	}
-	return (void *)-1;
-}
-
-int shell_mprotect(void *addr, size_t len, int prot)
-{
-	//if ((addr >= (intptr_t)&__CmdBase + 0x20000) && ((intptr_t)addr + len < &__CmdLimit)) {
-		return 0;
-	//}
-	//return -1;
-}
Index: /EcnlProtoTool/trunk/ntshell/src/main.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/main.c	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/main.c	(revision 441)
@@ -48,7 +48,9 @@
 #include "syssvc/serial.h"
 #include "syssvc/syslog.h"
+#include "target_syssvc.h"
 #include "kernel_cfg.h"
 #include "main.h"
-#include "rza1.h"
+#include "fdtable.h"
+#ifndef NTSHELL_NO_SOCKET
 #include <tinet_config.h>
 #include <netinet/in.h>
@@ -70,27 +72,14 @@
 #include "usrcmd.h"
 #include "util/ntopt.h"
-#include "fdtable.h"
-#include "target_syssvc.h"
+#include "netapp/dhcp4_cli.h"
+#include "ntp_cli.h"
+#include "netcmd.h"
+#endif
 
 ID ws_api_mailboxid = MAIN_DATAQUEUE;
 ID ws_mempoolid = MPF_NET_BUF_256;
+extern ntstdio_t *ntstdio;
 
 char command[NTOPT_TEXT_MAXLEN];
-ntstdio_t ntstdio;
-
-unsigned char ntstdio_xi(struct ntstdio_t *handle)
-{
-	char buf[1];
-	if(serial_rea_dat(SIO_PORTID, buf, 1) != 1)
-		return -EIO;
-	return buf[0];
-}
-
-void ntstdio_xo(struct ntstdio_t *handle, unsigned char c)
-{
-	char buf[1];
-	buf[0] = c;
-	serial_wri_dat(SIO_PORTID, buf, 1);
-}
 
 const uint8_t mac_addr[6] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC};
@@ -101,5 +90,5 @@
 	"3.5.0",
 	TARGET_NAME,
-    "toppers.jp"
+	"toppers.jp"
 };
 
@@ -113,25 +102,50 @@
 	main_state_start,
 	main_state_idle,
+#ifndef NTSHELL_NO_SOCKET
+	main_state_start_dhcp,
+#endif
+	main_state_servey_cmd,
 };
 
 struct main_obj_t {
 	ntshell_t ntshell;
-	TMO timer;
+	int timer;
 	enum main_state_t state;
 	SYSTIM prev, now;
-	WS_FBS_ID rcvmsg;
-	T_WS_FBS_QUEUE wbs_queue;
-	WS_FBS_ID sndmsg;
+	task_base_t **tasks;
+	int task_count;
+#ifndef NTSHELL_NO_SOCKET
+	uint8_t link;
+	uint8_t link_up;
+	uint8_t up;
+	uint8_t dhcp;
+	uint8_t ntp;
+	ntp_cli_state_t ntp_state;
+#endif
+	bool_t exec;
+	int event_req, event_res;
 };
 struct main_obj_t main_obj;
 
-static void main_change_netif_link(T_IFNET *ether);
+#ifndef NTSHELL_NO_SOCKET
+static void netif_link_callback(T_IFNET *ether);
+static void main_change_netif_link(uint8_t link_up, uint8_t up);
+#endif
 static void main_initialize(struct main_obj_t *obj);
-static TMO main_get_timer(struct main_obj_t *obj);
-static void main_progress(struct main_obj_t *obj, TMO elapse);
-static void main_timeout(struct main_obj_t *obj);
-extern int execute_command(int wait);
+static void main_finalize(struct main_obj_t *obj);
+static int main_get_timer(struct main_obj_t *obj);
+static void main_progress(struct main_obj_t *obj, int elapse);
+static void main_timeout(struct main_obj_t *obj, bool_t wakeup);
+static int execute_command(struct main_obj_t *obj, int wait);
 static int usrcmd_ntopt_callback(long *args, void *extobj);
-
+#ifndef NTSHELL_NO_SOCKET
+static void ntp_cli_state_changed(ntp_cli_state_t state);
+#endif
+
+void stdio_open(ID portid);
+void stdio_input(unsigned char c);
+
+bool_t dhcp_enable;
+int ntshell_exit;
 int shellcmd_exit_code;
 volatile int shellcmd_state;
@@ -139,7 +153,61 @@
 jmp_buf shellcmd_exit;
 
+void main_task_init(task_base_t **tasks, int task_count)
+{
+	main_obj.tasks = tasks;
+	main_obj.task_count = task_count;
+}
+
 int uart_read(char *buf, int cnt, void *extobj)
 {
-	return serial_rea_dat(SIO_PORTID, (char *)buf, cnt);
+	struct main_obj_t *obj = (struct main_obj_t *)extobj;
+	int result;
+	ER ret;
+	int timer;
+	bool_t wakeup = false;
+
+	obj->prev = obj->now;
+
+	if (obj->event_req != obj->event_res) {
+		obj->event_res = obj->event_req;
+		wakeup = true;
+#ifndef NTSHELL_NO_SOCKET
+		if (obj->dhcp) {
+			obj->dhcp = 0;
+			obj->state = main_state_start_dhcp;
+		}
+#endif
+		obj->timer = 0;
+	}
+
+	/* タイマー取得 */
+	timer = main_get_timer(obj);
+
+	/* 待ち */
+	ret = serial_trea_dat(SIO_PORTID, buf, cnt, timer);
+	if ((ret < 0) && (ret != E_OK) && (ret != E_TMOUT) && (ret != E_RLWAI)) {
+		syslog(LOG_NOTICE, "tslp_tsk ret: %s %d", itron_strerror(ret), timer);
+		ntshell_exit = 1;
+		return -1;
+	}
+	if (ret != E_TMOUT)
+		wakeup = true;
+	result = (int)ret;
+
+	ret = get_tim(&obj->now);
+	if (ret != E_OK) {
+		syslog(LOG_NOTICE, "get_tim ret: %s", itron_strerror(ret));
+		ntshell_exit = 1;
+		return -1;
+	}
+
+	/* 時間経過 */
+	int elapse = obj->now - obj->prev;
+	main_progress(obj, elapse);
+
+	/* タイムアウト処理 */
+	main_timeout(obj, wakeup);
+
+	return result;
 }
 
@@ -162,13 +230,37 @@
 	}
 
-	return execute_command(tskid == MAIN_TASK);
-}
+	return execute_command(&main_obj, tskid == MAIN_TASK);
+}
+
+gpio_t led_blue, led_green, led_red, sw;
 
 /*
- * メインタスク
+ *  メインタスク
  */
 void main_task(intptr_t exinf)
 {
 	struct main_obj_t *obj = (struct main_obj_t *)&main_obj;
+
+	gpio_init_out(&led_blue, LED_BLUE);
+	gpio_init_out(&led_green, LED_GREEN);
+	gpio_init_out(&led_red, LED_RED);
+	gpio_init_in(&sw, USER_BUTTON0);
+
+	obj->exec = gpio_read(&sw) == 1;
+
+	gpio_write(&led_blue, 1);
+	gpio_write(&led_green, obj->exec ? 1 : 0);
+	gpio_write(&led_red, 0);
+
+	ether_set_link_callback(main_change_netif_link);
+
+	/* 初期化 */
+	ffarch_init();
+
+	stdio_open(SIO_PORTID);
+
+#ifndef NTSHELL_NO_SOCKET
+	ntp_cli_set_state_changed_cb(ntp_cli_state_changed);
+#endif
 
 	main_initialize(obj);
@@ -177,4 +269,6 @@
 	ntshell_set_prompt(&obj->ntshell, "NTShell>");
 	ntshell_execute(&obj->ntshell);
+
+	main_finalize(obj);
 }
 
@@ -184,54 +278,26 @@
 static void main_initialize(struct main_obj_t *obj)
 {
-	FILINFO fno;
-#if FF_USE_LFN
-	char lfn[FF_MAX_LFN + 1];
-	fno.lfname = lfn;
-	fno.lfsize = FF_MAX_LFN + 1;
-#endif
 	ER ret;
-
-	ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo);
-
-	obj->timer = TMO_FEVR;
+	ID tskid = 0;
+
+	ret = get_tid(&tskid);
+	if (ret != E_OK) {
+		syslog(LOG_ERROR, "get_tid %d", ret);
+		return;
+	}
+
+	obj->timer = 100000;
 	obj->state = main_state_start;
 
-	gpio_t led_blue, led_green, led_red, sw;
-	gpio_init_out(&led_blue, LED_BLUE);
-	gpio_init_out(&led_green, LED_GREEN);
-	gpio_init_out(&led_red, LED_RED);
-	gpio_init_in(&sw, USER_BUTTON0);
-
-	bool_t exec = gpio_read(&sw) == 1;
-
-	gpio_write(&led_blue, 1);
-	gpio_write(&led_green, exec ? 1 : 0);
-	gpio_write(&led_red, 0);
-
-	ether_set_link_callback(main_change_netif_link);
-
-	/* 初期化 */
-	if (mruby_arduino_init() == 0) {
-		gpio_write(&led_blue, 0);
-	}
-	else {
-		gpio_write(&led_blue, 0);
-		gpio_write(&led_red, 1);
-	}
-
+	for (int i = 0; i < obj->task_count; i++) {
+		task_base_t *task = obj->tasks[i];
+		task->on_start(task, tskid);
+	}
+
+	gpio_write(&led_blue, 0);
 	gpio_write(&led_green, 0);
 
 	act_tsk(HTTPD1_TASK);
 	act_tsk(HTTPD2_TASK);
-
-	if (f_stat("1:/upload/main.mrb", &fno) != FR_OK) {
-		exec = false;
-	}
-
-	if (exec) {
-		ntlibc_strlcpy(command, "mruby -b 1:/upload/main.mrb", sizeof(command));
-
-		execute_command(1);
-	}
 
 	ret = get_tim(&obj->now);
@@ -243,10 +309,25 @@
 }
 
+static void main_finalize(struct main_obj_t *obj)
+{
+	for (int i = 0; i < obj->task_count; i++) {
+		task_base_t *task = obj->tasks[i];
+		task->on_end(task);
+	}
+}
+
 /*
  * タイマー取得
  */
-static TMO main_get_timer(struct main_obj_t *obj)
-{
-	TMO timer = obj->timer;
+static int main_get_timer(struct main_obj_t *obj)
+{
+	int timer = obj->timer;
+
+	for (int i = 0; i < obj->task_count; i++) {
+		task_base_t *task = obj->tasks[i];
+		int timer2 = task->get_timer(task);
+		if ((timer == -1) || ((timer2 != -1) && (timer > timer2)))
+			timer = timer2;
+	}
 
 	return timer;
@@ -256,5 +337,5 @@
  * 時間経過
  */
-static void main_progress(struct main_obj_t *obj, TMO elapse)
+static void main_progress(struct main_obj_t *obj, int elapse)
 {
 	if (obj->timer != TMO_FEVR) {
@@ -264,4 +345,9 @@
 		}
 	}
+
+	for (int i = 0; i < obj->task_count; i++) {
+		task_base_t *task = obj->tasks[i];
+		task->progress(task, elapse);
+	}
 }
 
@@ -269,10 +355,82 @@
  * タイムアウト処理
  */
-static void main_timeout(struct main_obj_t *obj)
-{
-	//if (obj->timer == 0) {
-	//}
-}
-
+static void main_timeout(struct main_obj_t *obj, bool_t wakeup)
+{
+	ER ret;
+	uint32_t event = wakeup ? MAIN_EVENT_WAKEUP : 0;
+
+	if (!wakeup && (obj->timer != 0))
+		return;
+
+	switch (obj->state) {
+	case main_state_start:
+#ifndef NTSHELL_NO_SOCKET
+		ether_set_link_callback(netif_link_callback);
+#endif
+		{
+			FILINFO fno;
+#if FF_USE_LFN
+			char lfn[FF_MAX_LFN + 1];
+			fno.lfname = lfn;
+			fno.lfsize = FF_MAX_LFN + 1;
+#endif
+			if (f_stat("1:/upload/main.mrb", &fno) != FR_OK) {
+				obj->exec = false;
+			}
+
+			if (obj->exec) {
+				cmd_execute("mruby -b 1:/upload/main.mrb", obj);
+			}
+		}
+		obj->state = main_state_idle;
+		obj->timer = TMO_FEVR;
+		break;
+#ifndef NTSHELL_NO_SOCKET
+	case main_state_start_dhcp:
+		ret = dhcp4c_renew_info();
+		if (ret == E_OK) {
+			obj->state = main_state_idle;
+			obj->timer = TMO_FEVR;
+		}
+		else {
+			obj->state = main_state_start_dhcp;
+			obj->timer = 1000000;
+		}
+		break;
+#endif
+	default:
+		obj->state = main_state_idle;
+		obj->timer = TMO_FEVR;
+		break;
+	}
+#ifndef NTSHELL_NO_SOCKET
+	if (obj->link) {
+		obj->link = 0;
+		event |= MAIN_EVENT_NETIF_CHANGED;
+		if (obj->link_up)
+			event |= MAIN_EVENT_LINK_UP;
+		if (obj->up)
+			event |= MAIN_EVENT_UP;
+
+		if (obj->link_up && obj->up)
+			ntp_cli_execute();
+
+		main_change_netif_link(obj->link_up, obj->up);
+	}
+	if (obj->ntp) {
+		obj->ntp = 0;
+		if (obj->ntp_state != NTP_CLI_STATE_SYNC)
+			event |= MAIN_EVENT_NTP_ASYNC;
+		else
+			event |= MAIN_EVENT_NTP_SYNC;
+	}
+#endif
+	for (int i = 0; i < obj->task_count; i++) {
+		task_base_t *task = obj->tasks[i];
+		task->process(task, event);
+	}
+}
+
+#ifndef NTSHELL_NO_SOCKET
 /* MACアドレスの設定時に呼ばれる */
 void mbed_mac_address(char *mac)
@@ -281,5 +439,5 @@
 }
 
-static void main_change_netif_link(T_IFNET *ether)
+void main_change_netif_link(uint8_t link_up, uint8_t up)
 {
 	FLGPTN flgptn;
@@ -295,4 +453,56 @@
 	set_flg(FLG_SELECT_WAIT, flgptn);
 }
+
+void netif_link_callback(T_IFNET *ether)
+{
+	struct main_obj_t *obj = (struct main_obj_t *)&main_obj;
+	uint8_t link_up = (ether->flags & IF_FLAG_LINK_UP) != 0;
+	uint8_t up = (ether->flags & IF_FLAG_UP) != 0;
+	bool_t wake = false;
+
+	if (dhcp_enable) {
+		if (!link_up)
+			dhcp4c_rel_info();
+		else if (!up) {
+			wake = dhcp4c_renew_info() != E_OK;
+			if (wake) {
+				obj->dhcp = 1;
+			}
+		}
+	}
+	else {
+		up = link_up;
+	}
+
+	if ((obj->link_up != link_up) || (obj->up != up)) {
+		obj->link = 1;
+		wake = true;
+	}
+
+	obj->link_up = link_up;
+	obj->up = up;
+
+	if (wake && (obj->event_req == obj->event_res)) {
+		obj->event_req++;
+		rel_wai(MAIN_TASK);
+	}
+}
+
+void ntp_cli_state_changed(ntp_cli_state_t state)
+{
+	struct main_obj_t *obj = (struct main_obj_t *)&main_obj;
+	bool_t wake = obj->ntp_state != state;
+
+	if (wake) {
+		obj->ntp_state = state;
+		obj->ntp = 1;
+
+		if (obj->event_req == obj->event_res) {
+			obj->event_req++;
+			rel_wai(MAIN_TASK);
+		}
+	}
+}
+#endif
 
 /*
@@ -302,5 +512,12 @@
 {
 	shellcmd_state = 1;
-	shellcmd_exit_code = ntopt_parse(command, usrcmd_ntopt_callback, NULL);
+
+	if (setjmp(shellcmd_exit) == 0) {
+		shellcmd_exit_code = ntopt_parse(command, usrcmd_ntopt_callback, NULL);
+	}
+
+	//fflush(stdout);
+	clean_fd();
+
 	shellcmd_state = 2;
 }
@@ -315,4 +532,10 @@
 	{"hexdump", "Hex dump", usrcmd_hexdump},
 	{"date", "print date and time", usrcmd_date},
+#ifndef NTSHELL_NO_SOCKET
+	{"ping", "ping", usrcmd_ping},
+	{"dhcpc", "DHCP Client rel/renew/info", usrcmd_dhcp4c},
+	{"dnsc", "DNS client", usrcmd_dnsc },
+	{"ntpc", "NTP client", usrcmd_ntpc },
+#endif
 	{"info", "This is a description text string for info command.", usrcmd_info},
 	{"exit", "Exit Natural Tiny Shell", usrcmd_exit},
@@ -330,17 +553,25 @@
 
 	if (ntlibc_strcmp((const char *)args[1], "help") == 0) {
-		usrcmd_help(args[0], (char **)&args[1]);
+		found = 1;
+		result = usrcmd_help(args[0], (char **)&args[1]);
 	}
 	else for (int i = 0; i < cmd_table_info.count; i++) {
 		if (ntlibc_strcmp((const char *)args[1], p->cmd) == 0) {
-			return p->func(args[0], (char **)&args[1]);
+			found = 1;
+			result = p->func(args[0], (char **)&args[1]);
+			break;
 		}
 		p++;
 	}
-	if (setjmp(shellcmd_exit) == 0) {
-		(*((PowerOn_Reset_t *)0x18220000))(args);
-	}
-	clean_fd();
-	return 0;
+
+	if ((found == 0) && setjmp(shellcmd_exit) == 0) {
+		found = 1;
+		(*((PowerOn_Reset_t *)0x18200000))(args);
+	}
+
+	if ((found == 0) && (((const char *)args[1])[0] != '\0'))
+		ntstdio_printf(ntstdio, "Unknown command found. %s \n", (const char *)args[1]);
+
+	return result;
 }
 
@@ -349,8 +580,8 @@
 	const cmd_table_t *p = cmd_table_info.table;
 	for (int i = 0; i < cmd_table_info.count; i++) {
-		ntstdio_puts(&ntstdio, p->cmd);
-		ntstdio_puts(&ntstdio, "\t:");
-		ntstdio_puts(&ntstdio, p->desc);
-		ntstdio_puts(&ntstdio, "\n");
+		ntstdio_puts(ntstdio, p->cmd);
+		ntstdio_puts(ntstdio, "\t:");
+		ntstdio_puts(ntstdio, p->desc);
+		ntstdio_puts(ntstdio, "\n");
 		p++;
 	}
@@ -372,6 +603,4 @@
 void shell_abort()
 {
-	asm("bkpt #0");
-
 	shellcmd_exit_code = -1;
 	longjmp(shellcmd_exit, 1);
@@ -390,6 +619,7 @@
 }
 
-int execute_command(int wait)
-{
+int execute_command(struct main_obj_t *obj, int wait)
+{
+	T_RTSK rtsk;
 	ER ret;
 
@@ -399,5 +629,6 @@
 	}
 
-	tslp_tsk(100000);
+	if (ret == E_OK)
+		tslp_tsk(100000);
 
 	clean_fd();
@@ -413,7 +644,36 @@
 
 	do {
-		tslp_tsk(100000);
+		obj->state = main_state_servey_cmd;
+		obj->timer = 100000;
+
+		char c;
+		if (obj->ntshell.func_read(&c, sizeof(c), obj->ntshell.extobj) == 1) {
+			// Ctrl+Cが押された場合
+			if (c == 0x03) {
+				// コマンドタスクを終了
+				ret = ter_tsk(SHELLCMD_TASK);
+				if (ret != E_OK) {
+					syslog(LOG_ERROR, "ter_tsk => %d", ret);
+				}
+				shellcmd_exit_code = -1;
+				shellcmd_state = 4;
+				if (ret == E_OK)
+					tslp_tsk(100000);
+				break;
+			}
+
+			stdio_input(c);
+		}
+
+		ret = ref_tsk(SHELLCMD_TASK, &rtsk);
+		if ((ret != E_OK) || (rtsk.tskstat == TTS_DMT))
+			shellcmd_state = 3;
 	} while(shellcmd_state == 1);
 
+	obj->state = main_state_idle;
+	obj->timer = TMO_FEVR;
+
+	clean_fd();
+
 	return shellcmd_exit_code;
 }
@@ -421,5 +681,5 @@
 int shell_clock_getres(clockid_t clk_id, struct timespec *res)
 {
-	if (clk_id != CLOCK_REALTIME)
+	if ((clk_id != CLOCK_REALTIME) && (clk_id != CLOCK_MONOTONIC))
 		return -EINVAL;
 
@@ -434,5 +694,5 @@
 	SYSTIM now = 0;
 
-	if (clk_id != CLOCK_REALTIME)
+	if ((clk_id != CLOCK_REALTIME) && (clk_id != CLOCK_MONOTONIC))
 		return -EINVAL;
 
@@ -446,8 +706,16 @@
 int shell_clock_settime(clockid_t clk_id, const struct timespec *tp)
 {
-	if (clk_id != CLOCK_REALTIME)
+	if ((clk_id != CLOCK_REALTIME) && (clk_id != CLOCK_MONOTONIC))
 		return -EINVAL;
 
-	rtc_write(tp->tv_sec);
+	SYSTIM time;
+	ER ret;
+
+	time = (tp->tv_sec * 1000000ll) + (tp->tv_nsec / 1000ll);
+
+	ret = set_tim(time);
+	if (ret != E_OK) {
+		return -EPERM;
+	}
 
 	return 0;
@@ -482,9 +750,18 @@
 }
 
-struct sigaction sigtable[6];
-
-int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
-{
-	struct sigaction *sat;
+// musl-1.1.18\src\internal\ksigaction.h
+struct k_sigaction {
+	void(*handler)(int);
+	unsigned long flags;
+	void(*restorer)(void);
+	unsigned mask[2];
+};
+
+struct k_sigaction sigtable[7];
+
+int shell_sigaction(int sig, const struct k_sigaction *restrict sa,
+	struct k_sigaction *restrict old, size_t size)
+{
+	struct k_sigaction *sat;
 
 	switch(sig){
@@ -507,4 +784,7 @@
 		sat = &sigtable[5];
 		break;
+	case SIGPIPE:
+		sat = &sigtable[6];
+		break;
 	default:
 		return -EINVAL;
@@ -512,7 +792,7 @@
 
 	if (old != NULL)
-		memcpy(old, sat, sizeof(struct sigaction));
-
-	memcpy(sat, sa, sizeof(struct sigaction));
+		memcpy(old, sat, offsetof(struct k_sigaction, mask) + size);
+
+	memcpy(sat, sa, offsetof(struct k_sigaction, mask) + size);
 
 	return 0;
@@ -524,81 +804,124 @@
 }
 
-int stdio_close(struct _IO_FILE *fp)
-{
-	return -EPERM;
-}
-
-size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-size_t stdin_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
-{
-	int i = 0;
-	while (i < len) {
-		int c = ntstdio_getc(&ntstdio);
-		data[i++] = c;
-		if ((c == EOF) || (c == '\n'))
-			break;
-	}
-	return i;
-}
-
-size_t stdout_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
-{
-	for (int i = 0; i < len; i++) {
-		ntstdio_putc(&ntstdio, data[i]);
-	}
-	return len;
-}
-
-size_t stderr_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
-{
-	for (int i = 0; i < len; i++) {
-		ntstdio_putc(&ntstdio, data[i]);
-	}
-	return len;
-}
-
-int sio_close(struct _IO_FILE *fp)
-{
-	return -EPERM;
-}
-
-size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
-{
-	return -EPERM;
-}
-
-off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org)
-{
-	return -EPERM;
-}
-
-int sio_ioctl(struct _IO_FILE *fp, int request, void *arg)
-{
-	switch (request) {
-	case TIOCGWINSZ:
+int shell_gettid()
+{
+	ID tskid;
+	ER ret;
+
+	ret = get_tid(&tskid);
+	if (ret != E_OK)
+		return -1;
+
+	return tskid;
+}
+
+int shell_tkill(int tid, int sig)
+{
+	if ((tid == SHELLCMD_TASK) && (sig == SIGABRT)) {
+		shell_abort();
+	}
+
+	no_implement("tkill");
+	return -1;
+}
+
+int shell_kill(int pid, int sig)
+{
+	DebugBreak();
+	return -1;
+}
+
+int shell_gettimeofday(struct timeval *tv, void *tzvp)
+{
+	SYSTIM time;
+	if (!tv) return 0;
+	get_tim(&time);
+	tv->tv_sec = time / 1000000;
+	tv->tv_usec = time - (tv->tv_sec * 1000000);
+	return 0;
+}
+
+int shell_nanosleep(const struct timespec *req, struct timespec *rem)
+{
+	ER ret;
+	TMO tmo;
+	SYSTIM prev, now, diff;
+
+	if ((req == NULL) || (req->tv_nsec < 0) || (req->tv_nsec >= 1000000000))
+		return -EINVAL;
+
+	get_tim(&prev);
+
+	tmo = req->tv_sec * 1000000 + req->tv_nsec / 1000;
+	ret = tslp_tsk(tmo);
+	if (ret == E_OK) {
+		if (rem != NULL) {
+			get_tim(&now);
+			diff = now - prev;
+			rem->tv_sec = diff / 1000000ll;
+			rem->tv_nsec = (diff - (rem->tv_sec * 1000000ll)) * 1000ll;
+		}
 		return 0;
-	case TCGETS:
-		return sio_tcgetattr(fp->fd, (struct termios *)arg);
-	case TCSETS + TCSANOW:
-	case TCSETS + TCSADRAIN:
-	case TCSETS + TCSAFLUSH:
-		return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);
-	}
-
-	return -EINVAL;
-}
-
+	}
+	else if (ret == E_TMOUT) {
+		if (rem != NULL) {
+			rem->tv_sec = 0;
+			rem->tv_nsec = 0;
+		}
+		return 0;
+	}
+
+	return -EFAULT;
+}
+
+ssize_t shell_getrandom(void *buf, size_t buflen, unsigned int flags)
+{
+	SYSTIM now;
+	int32_t i;
+	int *output = (int *)buf;
+	size_t sz = buflen / 4;
+
+	get_tim(&now);
+	srand(now);
+
+	for (i = 0; i < sz; i++)
+		output[i] = rand();
+
+	for (i = 4 * sz; i < buflen; i++)
+		((char *)buf)[i] = rand();
+
+	return buflen;
+}
+
+extern uint32_t  __CmdBase;
+extern uint32_t  __CmdLimit;
+
+void *shell_brk(void *addr)
+{
+	if (addr == 0) {
+		return (void *)((intptr_t)&__CmdBase + 0x40000);
+	}
+	if ((addr >= (intptr_t)&__CmdBase + 0x40000) && (addr < &__CmdLimit)) {
+		return addr;
+	}
+	return (void *)-1;
+}
+
+void *shell_mmap2(void *start, size_t length, int prot, int flags, int fd, off_t pgoffset)
+{
+	if (fd != -1)
+		return -EINVAL;
+
+	if ((length >= 0) && (length <= (intptr_t)&__CmdLimit - ((intptr_t)&__CmdBase + 0x40000))) {
+		return &__CmdBase + 0x40000;
+	}
+	return (void *)-1;
+}
+
+int shell_mprotect(void *addr, size_t len, int prot)
+{
+	//if ((addr >= (intptr_t)&__CmdBase + 0x40000) && ((intptr_t)addr + len < &__CmdLimit)) {
+		return 0;
+	//}
+	//return -1;
+}
Index: /EcnlProtoTool/trunk/ntshell/src/main.cdl
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/main.cdl	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/main.cdl	(revision 441)
@@ -1,5 +1,41 @@
 /*
- *		サンプルプログラム(1)のコンポーネント記述ファイル
- *
+ *  TOPPERS/ASP Kernel
+ *      Toyohashi Open Platform for Embedded Real-Time Systems/
+ *      Advanced Standard Profile Kernel
+ * 
+ *  Copyright (C) 2015 by Ushio Laboratory
+ *              Graduate School of Engineering Science, Osaka Univ., JAPAN
+ *  Copyright (C) 2015,2016 by Embedded and Real-Time Systems Laboratory
+ *              Graduate School of Information Science, Nagoya Univ., JAPAN
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
  *  $Id$
  */
@@ -19,8 +55,41 @@
 import("syssvc/tBanner.cdl");
 
+import_C("target_syssvc.h");
+
 /*
- *  ターゲット依存部の取り込み
+ *  タスクのスタックサイズのデフォルト
  */
-import("target.cdl");
+const size_t DefaultTaskStackSize = 1024;		/* スタックサイズ（1KB）*/
+
+/*
+ *  システムログタスクのスタックサイズの定義
+ */
+const size_t LogTaskStackSize = DefaultTaskStackSize;
+
+/*
+ *  カーネル起動メッセージに関する定義
+ */
+const char *const BannerTargetName = C_EXP("TARGET_NAME");		/* ターゲット名 */
+const char *const BannerCopyrightNotice = "";			/* 著作権表示 */
+
+/*
+ *  ターゲット依存のセルタイプの定義
+ */
+import("syssvc/tPutLogSIOPort.cdl");
+import("tSIOPortNTShell.cdl");
+
+/*
+ *  シリアルインタフェースドライバのターゲット依存部の組み上げ記述
+ */
+cell tSIOPortNTShell SIOPortTarget1 {
+};
+
+/*
+ *  低レベル出力の組み上げ記述
+ */
+cell tPutLogSIOPort PutLogTarget {
+	/* SIOドライバとの結合 */
+	cSIOPort = SIOPortTarget1.eSIOPort;
+};
 
 /*
Index: /EcnlProtoTool/trunk/ntshell/src/main.cfg
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/main.cfg	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/main.cfg	(revision 441)
@@ -48,9 +48,29 @@
 #include <net/if6_var.h>
 
+ATT_INI({ TA_NULL, 0, sys_init });
+
 INCLUDE("tecsgen.cfg");
 INCLUDE("tinet/tinet_asp.cfg");
 INCLUDE("tinet_main.cfg");
-/*#include "netapp/dhcp4_cli.h"*/
-/*INCLUDE("netapp/dhcp4_cli_asp.cfg");*/
+
+/* DHCP クライアント */
+#include "netapp/dhcp4_cli.h"
+//INCLUDE("netapp/dhcp4_cli_asp.cfg");
+INCLUDE("netapp/tinet_dhcp4_cli.cfg");
+
+/* DNSクライアント */
+#include "netapp/resolver.h"
+INCLUDE("netapp/resolver_asp.cfg");
+INCLUDE("netapp/tinet_resolver.cfg");
+
+/* NTPクライアント */
+#include "ntp_cli.h"
+//INCLUDE("ntp_cli.cfg");
+INCLUDE("tinet_ntp_cli.cfg");
+
+#include "net_misc.h"
+INCLUDE("net_misc.cfg");
+
+/* FatFs */
 INCLUDE("ffarch.cfg");
 INCLUDE("httpd.cfg");
@@ -59,6 +79,6 @@
 CRE_TSK(MAIN_TASK, { TA_ACT, 0, main_task, MAIN_PRIORITY, MAIN_STACK_SIZE, NULL });
 CRE_DTQ(MAIN_DATAQUEUE, { TA_TFIFO, NUM_MAIN_DATAQUEUE, NULL });
-CRE_SEM(SEM_FILESYSTEM, { TA_TPRI, 1, 1 });
 
-CRE_TSK(SHELLCMD_TASK, { TA_NULL, 0, shellcmd_task, SHELLCMD_PRIORITY, SHELLCMD_STACK_SIZE, (void *)0x20100000 });
+CRE_TSK(SHELLCMD_TASK, { TA_FPU, 0, shellcmd_task, SHELLCMD_PRIORITY, SHELLCMD_STACK_SIZE, (void *)0x20100000 });
 CRE_FLG(FLG_SELECT_WAIT, { TA_WMUL, 0x00 });
+CRE_SEM(SEM_FILEDESC, { TA_TPRI, 1, 1 });
Index: /EcnlProtoTool/trunk/ntshell/src/main.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/main.h	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/main.h	(revision 441)
@@ -56,11 +56,11 @@
 
 #define MAIN_PRIORITY	5			/* メインタスクの優先度 */
-#define SHELLCMD_PRIORITY	4		/* shellcmdタスクの優先度 */
+#define SHELLCMD_PRIORITY	8		/* shellcmdタスクの優先度 */
 
-#define MAIN_STACK_SIZE		2048	/* メインタスクのスタック領域のサイズ */
+#define MAIN_STACK_SIZE	2048		/* メインタスクのスタック領域のサイズ */
 #define SHELLCMD_STACK_SIZE	0x00800000	/* shellcmdタスクのスタック領域のサイズ */
 
 #define NUM_MAIN_DATAQUEUE	1		/* メインタスクで待ち受けているデータキューのサイズ */
-#define NUM_SHELLCMD_DATAQUEUE	1	/* shellcmdタスクで待ち受けているデータキューのサイズ */
+
 
 /*
@@ -69,4 +69,14 @@
 #ifndef TOPPERS_MACRO_ONLY
 
+typedef struct task_base_t {
+	void (*on_start)(struct task_base_t *task, ID tskid);
+	void (*on_end)(struct task_base_t *task);
+	int (*get_timer)(struct task_base_t *task);
+	void (*progress)(struct task_base_t *task, int elapse);
+	void (*process)(struct task_base_t *task, uint32_t event);
+	int timer;
+	void *exinf;
+} task_base_t;
+
 typedef struct
 {
@@ -74,4 +84,19 @@
 	int count;
 } cmd_table_info_t;
+
+extern cmd_table_info_t cmd_table_info;
+
+/* ntshellの初期化 */
+void sys_init(intptr_t exinf);
+
+#define MAIN_EVENT_WAKEUP		0x00000001
+#define MAIN_EVENT_NETIF_CHANGED	0x00000002
+#define MAIN_EVENT_LINK_UP		0x00000004
+#define MAIN_EVENT_UP			0x00000008
+#define MAIN_EVENT_NTP_ASYNC		0x00000010
+#define MAIN_EVENT_NTP_SYNC		0x00000020
+
+/* メインタスク初期化 */
+void main_task_init(task_base_t **tasks, int task_count);
 
 /* メインタスク */
Index: /EcnlProtoTool/trunk/ntshell/src/mbedcall.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/mbedcall.c	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/mbedcall.c	(revision 441)
@@ -375,5 +375,5 @@
 		break;
 	default:
-		asm("bkpt #0");
+		DebugBreak();
 		break;
 	}
Index: /EcnlProtoTool/trunk/ntshell/src/net_misc.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/net_misc.c	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/net_misc.c	(revision 441)
@@ -0,0 +1,146 @@
+/*
+ *  TOPPERS PROJECT Home Network Working Group Software
+ * 
+ *  Copyright (C) 2018-2019 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+
+#include <kernel.h>
+#include <sil.h>
+#include <t_syslog.h>
+#include <t_stdlib.h>
+
+#include <tinet_defs.h>
+#include <tinet_config.h>
+
+#include <net/if.h>
+#include <net/ethernet.h>
+
+#include <net/net.h>
+#include <net/net_endian.h>
+#include <net/net_var.h>
+#include <net/net_timer.h>
+
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+
+#include "netapp/dhcp4_cli.h"
+#include "netapp/dhcp4_cli_var.h"
+#include "ntp_cli.h"
+#include "kernel_cfg.h"
+#include "tinet_cfg.h"
+#include <stdio.h>
+
+T_DHCP4_CLI_CONTEXT *dhcp4_cli_initialize(ID tskid, ID cepid);
+int dhcp4_cli_get_timer(T_DHCP4_CLI_CONTEXT *ct);
+void dhcp4_cli_progress(T_DHCP4_CLI_CONTEXT *ct, int elapse);
+void dhcp4_cli_wakeup(T_DHCP4_CLI_CONTEXT *ct);
+void dhcp4_cli_timeout(T_DHCP4_CLI_CONTEXT *ct);
+
+int net_misc_get_timer(T_DHCP4_CLI_CONTEXT *ct, T_NTP_CLI_CONTEXT *nc)
+{
+	int timer = dhcp4_cli_get_timer(ct);
+
+	if ((nc->timer != TMO_FEVR) && ((timer == TMO_FEVR) || (timer > nc->timer))) {
+		timer = nc->timer;
+	}
+
+	return timer;
+}
+
+extern T_NTP_CLI_CONTEXT ntp_cli;
+
+/*
+ *  DHCP, NTP クライアント タスク
+ */
+
+void
+net_misc_task (intptr_t exinf)
+{
+	T_DHCP4_CLI_CONTEXT *ct;
+	T_NTP_CLI_CONTEXT *nc = &ntp_cli;
+	ER		error = E_OK, ret;
+	SYSTIM		prev, time;
+	int timer;
+
+	get_tid(&nc->tskid);
+	syslog(LOG_NOTICE, "[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf);
+
+	/* 初期化 */
+	ct = dhcp4_cli_initialize(nc->tskid, UDP4_DHCP_CLI_CEPID);
+	ntp_cli_initialize(nc, NTP_CLI_CEPID);
+
+	ret = get_tim(&time);
+	if (ret != E_OK) {
+		syslog(LOG_NOTICE, "[NET MISC,%d] get_tim error: %7lu,%s",
+			nc->cepid, time / SYSTIM_HZ, itron_strerror(ret));
+		return;
+	}
+
+	while (true) {
+		prev = time;
+
+		/* タイマー取得 */
+		timer = net_misc_get_timer(ct, nc);
+
+		/* 待ち */
+		error = tslp_tsk(timer);
+		if ((error != E_OK) && (error != E_TMOUT)) {
+			syslog(LOG_NOTICE, "[NET MISC,%d] tslp_tsk error: %s %d",
+				nc->cepid, itron_strerror(error), timer);
+			break;
+		}
+
+		ret = get_tim(&time);
+		if (ret != E_OK) {
+			syslog(LOG_NOTICE, "[NET MISC,%d] get_tim error: %s",
+				nc->cepid, itron_strerror(ret));
+			break;
+		}
+
+		/* 時間経過 */
+		int elapse = time - prev;
+		dhcp4_cli_progress(ct, elapse);
+		ntp_cli_progress(nc, elapse);
+
+		/* 起こされた場合 */
+		if (error == E_OK) {
+			dhcp4_cli_wakeup(ct);
+			ntp_cli_wakeup(nc);
+		}
+
+		/* タイムアウト処理 */
+		dhcp4_cli_timeout(ct);
+		ntp_cli_timeout(nc);
+	}
+}
Index: /EcnlProtoTool/trunk/ntshell/src/net_misc.cfg
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/net_misc.cfg	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/net_misc.cfg	(revision 441)
@@ -0,0 +1,65 @@
+/*
+ *  TOPPERS PROJECT Home Network Working Group Software
+ * 
+ *  Copyright (C) 2018-2019 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+
+/*
+ *  DHCP, NTP クライアントのシステムコンフィギュレーションファイル
+ */
+
+/* セマフォ */
+
+CRE_SEM(SEM_DHCP4_CLI_LOCK,	{ TA_TPRI, 1, 1 });
+
+/* 送受信バッファ */
+
+CRE_MPF(MPF_DHCP4_CLI_MSG, {
+	TA_TFIFO,
+	NUM_MPF_DHCP4_CLI_MSG,
+	sizeof(T_DHCP4_CLI_MSG),
+	NULL,
+	NULL
+	});
+
+/* タスク */
+
+CRE_TSK(NET_MISC_TASK, {
+	TA_HLNG|TA_ACT,
+	0,
+	net_misc_task,
+	NET_MISC_MAIN_PRIORITY,
+	NET_MISC_STACK_SIZE,
+	NULL
+	});
Index: /EcnlProtoTool/trunk/ntshell/src/net_misc.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/net_misc.h	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/net_misc.h	(revision 441)
@@ -0,0 +1,53 @@
+/*
+ *  TOPPERS PROJECT Home Network Working Group Software
+ * 
+ *  Copyright (C) 2018-2019 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+
+#ifndef _NET_MISC_H_
+#define _NET_MISC_H_
+
+/* スタックサイズ */
+
+#define NET_MISC_STACK_SIZE	2048		/* NTP クライアントタスク（IPv4）のスタックサイズ	*/
+
+/* 優先度 */
+
+#define NET_MISC_MAIN_PRIORITY	5		/* NTP クライアントタスク（IPv4）の優先度		*/
+
+/* タスク */
+
+extern void	net_misc_task(intptr_t exinf);
+
+#endif	/* of #ifndef _NET_MISC_H_ */
Index: /EcnlProtoTool/trunk/ntshell/src/netcmd.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/netcmd.c	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/netcmd.c	(revision 441)
@@ -0,0 +1,672 @@
+/*
+ *  TINET (TCP/IP Protocol Stack)
+ * 
+ *  Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
+ *                   Tomakomai National College of Technology, JAPAN
+ *
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ *
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ *
+ *  @(#) $Id$
+ */
+#include "shellif.h"
+#include <kernel.h>
+#include <t_stdlib.h>
+#include <sil.h>
+#include <string.h>
+#include "syssvc/serial.h"
+#include "syssvc/syslog.h"
+#include <tinet_config.h>
+#include <netinet/in.h>
+#include <netinet/in_itron.h>
+#include <tinet_nic_defs.h>
+#include <tinet_cfg.h>
+#include <netinet/in_var.h>
+#include <net/ethernet.h>
+#include <net/if6_var.h>
+#include <net/net.h>
+#include <net/if_var.h>
+#include <netinet/udp_var.h>
+#include <netapp/netapp_var.h>
+#include <netapp/netapp.h>
+#include <netapp/dhcp4_cli.h>
+#include <netapp/resolver.h>
+#include "core/ntlibc.h"
+#include "util/ntstdio.h"
+#include <stdio.h>
+#include "ntp_cli.h"
+#include "kernel_cfg.h"
+
+#if defined(SUPPORT_INET6)
+#define DEFAULT_API_PROTO	API_PROTO_IPV6
+#else
+#define DEFAULT_API_PROTO	API_PROTO_IPV4
+#endif
+extern void ping6(T_IN6_ADDR *addr, uint_t tmo, uint_t len);
+extern void ping4(T_IN4_ADDR *addr, uint_t tmo, uint_t len);
+extern ntstdio_t *ntstdio;
+
+/*
+ *  str_num -- cons_printf の数値変換
+ */
+
+static void
+str_chr(char *text, int *pos, int size, char c)
+{
+	if (*pos >= size)
+		return;
+	text[*pos] = c;
+	*pos = *pos + 1;
+}
+
+/*
+ *  str_num -- cons_printf の数値変換
+ */
+
+static int
+str_num(char *text, int *pos, int size, ulong_t 	val, int radix,
+         const char *radchar, int width, bool_t minus, char padchar)
+{
+	char	digits[24];
+	int	ix, pad, pchars;
+	bool_t	left;
+
+	if (width < 0) {
+		width = -width;
+		left = true;
+	}
+	else
+		left = false;
+
+	ix = 0;
+	do {
+		digits[ix ++] = radchar[val % radix];
+		val /= radix;
+	} while (val != 0);
+
+	if (minus)
+		digits[ix ++] = '-';
+
+	if (width > ix)
+		pchars = width;
+	else
+		pchars = ix;
+
+	pad = ix;
+	if (!left)	/* 右詰め */
+		for ( ; pad < width; pad ++)
+			str_chr(text, pos, size, padchar);
+
+	while (ix -- > 0)
+		str_chr(text, pos, size, digits[ix]);
+
+	if (left)	/* 左詰め */
+		for ( ; pad < width; pad ++)
+			str_chr(text, pos, size, padchar);
+
+	return pchars;
+}
+
+/*
+ *  str_ipv4addr -- IPv4 アドレス出力
+ */
+
+int
+str_ipv4addr (char *text, int size, T_IN4_ADDR *addr, int width)
+{
+	int len = 3, pos = 0;	/* 3 は '.' の文字数 */
+
+	len += str_num(text, &pos, size, (*addr >> 24) & 0xff, 10, radhex, 0, false, ' '); 
+	str_chr(text, &pos, size, '.');
+	len += str_num(text, &pos, size, (*addr >> 16) & 0xff, 10, radhex, 0, false, ' '); 
+	str_chr(text, &pos, size, '.');
+	len += str_num(text, &pos, size, (*addr >>  8) & 0xff, 10, radhex, 0, false, ' '); 
+	str_chr(text, &pos, size, '.');
+	len += str_num(text, &pos, size,  *addr        & 0xff, 10, radhex, 0, false, ' '); 
+
+	for ( ; len < width; len ++)
+		str_chr(text, &pos, size, ' ');
+
+	return len;
+}
+
+/*
+ *  ipv6addr -- IPv6 アドレス出力
+ */
+
+int
+str_ipv6addr (char *text, int size, const T_IN6_ADDR *addr, int width)
+{
+	int	len = 0, ix, len6, pos = 0;
+	bool_t	omit = false, zero = false;
+
+	if (addr == NULL || IN6_IS_ADDR_UNSPECIFIED(addr)) {
+		str_chr(text, &pos, size, '0');
+		str_chr(text, &pos, size, ':');
+		str_chr(text, &pos, size, ':');
+		str_chr(text, &pos, size, '0');
+		len = 4;
+	}
+	else {
+		if (in6_is_addr_ipv4mapped(addr))
+			len6 = sizeof(T_IN6_ADDR) / 2 - 2;
+		else
+			len6 = sizeof(T_IN6_ADDR) / 2;
+		for (ix = 0; ix < len6; ix ++) {
+			if (omit) {
+				len += str_num(text, &pos, size, ntohs(addr->s6_addr16[ix]), 16, radhex, 0, false, ' '); 
+				if (ix < 7) {
+					str_chr(text, &pos, size, ':');
+					len ++;
+				}
+			}
+			else if (ix > 0 && ix < 7 && addr->s6_addr16[ix] == 0)
+				zero = true;
+			else {
+				if (zero) {
+					omit = true;
+					str_chr(text, &pos, size, ':');
+					len ++;
+				}
+				len += str_num(text, &pos, size, ntohs(addr->s6_addr16[ix]), 16, radhex, 0, false, ' '); 
+				if (ix < 7) {
+					str_chr(text, &pos, size, ':');
+					len ++;
+				}
+			}
+		}
+
+		if (len6 == sizeof(T_IN6_ADDR) / 2 - 2) {
+			T_IN4_ADDR ip4addr;
+
+			ip4addr = ntohl(addr->s6_addr32[3]);
+			len += str_ipv4addr(&text[len], size - len, &ip4addr, 0);
+		}
+
+		for ( ; len < width; len ++)
+			str_chr(text, &pos, size, ' ');
+	}
+	return len;
+}
+
+/*
+ *  str_macaddr -- MAC アドレス出力
+ */
+
+int
+str_macaddr (char *text, int size, uint8_t *mac, int width)
+{
+	int oct, len, pos = 0;
+
+	for (oct = 5; oct -- > 0; ) {
+		str_num(text, &pos, size, *mac ++, 16, radhex, 2, false, '0'); 
+		str_chr(text, &pos, size, ':');
+	}
+	str_num(text, &pos, size, *mac, 16, radhex, 2, false, '0'); 
+
+	for (len = 17; len < width; len ++)
+		str_chr(text, &pos, size, ' ');
+
+	return len;
+}
+
+int usrcmd_ping(int argc, char **argv)
+{
+	int tmo = 3, size = 64;
+	char apip = DEFAULT_API_PROTO;
+	char *line = argv[1];
+#if defined(SUPPORT_INET6)
+	T_IN6_ADDR	addr;
+#if defined(SUPPORT_INET4)
+	T_IN4_ADDR	addr4;
+#endif
+#else
+	T_IN4_ADDR	addr;
+#endif
+	static const char i6rlp_pmtu_str1[] = " FF1E::1:2 1 1452";
+	static const char i6rlp_pmtu_str2[] = " FF1E::1:2 1 1352";
+	static const char i6rlp_pmtu_str3[] = " fe80::0200:00ff:fe00:0100 1 2";
+
+	if (apip == '1')
+		ntlibc_strcpy(line, i6rlp_pmtu_str1);
+	else if (apip == '2')
+		ntlibc_strcpy(line, i6rlp_pmtu_str2);
+	else if (apip == '3')
+		ntlibc_strcpy(line, i6rlp_pmtu_str3);
+
+#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
+	if (argc <= 2)
+		return 0;
+
+	if ('0' <= *line && *line <= '9') {
+		if (*line == '6')
+			apip = API_PROTO_IPV6;
+		if (*line == '4')
+			apip = API_PROTO_IPV4;
+		line++;
+	}
+
+	line = argv[2];
+#else
+	if (argc <= 1)
+		return 0;
+#endif	/* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
+
+	if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) {
+		ntstdio_printf(ntstdio, "[PING] unknown host.\n");
+		return 0;
+	}
+
+	if (argc > 2) {
+		line = argv[2];
+		if ('0' <= *line && *line <= '9')
+			line = get_int(&tmo, line);
+
+		if (argc > 3) {
+			line = argv[3];
+			if ('0' <= *line && *line <= '9')
+				line = get_int(&size, line);
+		}
+	}
+
+#if defined(SUPPORT_INET6)
+#if defined(SUPPORT_INET4)
+	if (apip == API_PROTO_IPV6) {
+		ntstdio_printf(ntstdio, "[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
+		ping6(&addr, (uint_t)tmo, (uint_t)size);
+	}
+	else {
+		addr4 = ntohl(addr.s6_addr32[3]);
+		ntstdio_printf(ntstdio, "[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr4));
+		ping4(&addr4, (uint_t)tmo, (uint_t)size);
+	}
+#else /* of #if defined(SUPPORT_INET4) */
+	ntstdio_printf(ntstdio, "[PING6] size: %d, tmo: %d, host: %s\n", size, tmo, ipv62str(NULL, &addr));
+	ping6(&addr, (uint_t)tmo, (uint_t)size);
+#endif	/* of #if defined(SUPPORT_INET4) */
+#else	/* of #if defined(SUPPORT_INET6) */
+	ntstdio_printf(ntstdio, "[PING4] size: %d, tmo: %d, host: %s\n", size, tmo, ip2str(NULL, &addr));
+	ping4(&addr, (uint_t)tmo, (uint_t)size);
+#endif	/* of #if defined(SUPPORT_INET6) */
+
+	return 0;
+}
+
+static void dhcp4c_info()
+{
+	T_IN4_ADDR svaddr;
+	SYSTIM bind_start;
+	ER ret;
+	uint32_t expire, renew, rebind;
+	char temp[30];
+	int pos;
+
+	if ((ret = dhcp4c_get_info(&svaddr, &expire, &renew, &rebind, &bind_start)) == E_OK) {
+		pos = str_ipv4addr(temp, sizeof(temp), &svaddr, 0);
+		temp[pos] = '\0';
+		ntstdio_printf(ntstdio, "DHCPv4 server: %s,\n", temp);
+		ntstdio_printf(ntstdio, "  Renew:       %u:%02u:%02u,\n",
+			renew / 3600, (renew / 60) % 60, renew % 60);
+		ntstdio_printf(ntstdio, "  Rebind:      %u:%02u:%02u, Expire:   %u:%02u:%02u.\n",
+			rebind / 3600, (rebind / 60) % 60, rebind % 60,
+			expire / 3600, (expire / 60) % 60, expire % 60);
+	}
+	else if (ret == E_OBJ)
+		ntstdio_printf(ntstdio, "DHCPv4 server: not available.\n");
+}
+
+int usrcmd_dhcp4c(int argc, char **argv)
+{
+	ER ret;
+
+	if (argc < 2)
+		return 0;
+
+	if (ntlibc_strcmp(argv[1], "rel") == 0) {
+		ret = dhcp4c_rel_info();
+		ntstdio_printf(ntstdio, "dhcp4c_rel_info %d\n", ret);
+	}
+	else if (ntlibc_strcmp(argv[1], "renew") == 0) {
+		ret = dhcp4c_renew_info();
+		ntstdio_printf(ntstdio, "dhcp4c_renew_info %d\n", ret);
+	}
+	else {
+		dhcp4c_info();
+	}
+
+	return 0;
+}
+
+/*
+*  s_show_dns_domain_name -- DNS のドメイン名を表示する。
+*/
+
+static uint_t
+s_show_dns_domain_name(uint8_t *hdr, uint_t offset)
+{
+	uint8_t	*ptr;
+	uint_t	c;
+
+	ptr = hdr + offset;
+	while (*ptr) {
+		if ((*ptr & DNS_MSG_COMP_MARK) == DNS_MSG_COMP_MARK) {
+			s_show_dns_domain_name(hdr, (*ptr & ~DNS_MSG_COMP_MARK) << 8 | *(ptr + 1));
+			ptr += 2;
+			break;
+		}
+		else {
+			for (c = 1; c <= *ptr; c++)
+				ntstdio_printf(ntstdio, "%c", *(ptr + c));
+			ptr += *ptr + 1;
+			if (*ptr)
+				ntstdio_printf(ntstdio, ".");
+		}
+	}
+	return ptr - hdr;
+}
+
+/*
+ *  show_dns_soa -- DNS の SOA RDATA を表示する。
+ */
+
+static ER_UINT
+show_dns_soa(uint8_t *msg, ER_UINT length, uint_t offset)
+{
+	T_RSLV_SOA	soa;
+	ER_UINT		error;
+	uint_t		rn_offset;
+
+	if ((error = dns_analyze_soa(&soa, offset, msg, length)) < 0)
+		return error;
+
+	ntstdio_printf(ntstdio, "    mname:   ");
+	rn_offset = s_show_dns_domain_name(msg, offset);
+	putchar('\n');
+	ntstdio_printf(ntstdio, "    rname:   ");
+	s_show_dns_domain_name(msg, rn_offset);
+	putchar('\n');
+
+	ntstdio_printf(ntstdio, "    serial:  %d\n", soa.serial);
+	ntstdio_printf(ntstdio, "    refresh: %d\n", soa.refresh);
+	ntstdio_printf(ntstdio, "    retry:   %d\n", soa.retry);
+	ntstdio_printf(ntstdio, "    expirel: %d\n", soa.expire);
+	ntstdio_printf(ntstdio, "    minimum: %d\n", soa.minimum);
+
+	return E_OK;
+}
+
+/*
+ *  show_dns_qdsection -- DNS の Question セクションを表示する。
+ */
+
+static ER_UINT
+show_dns_qdsection(uint8_t *msg, ER_UINT length, T_RSLV_DNS_MSG *rslv)
+{
+	T_RSLV_QD	qd;
+	ER_UINT		offset, error;
+	int		scount;
+
+	ntstdio_printf(ntstdio, "question   section: %d\n", rslv->dns_hdr.qdcount);
+	offset = rslv->qd_offset;
+	for (scount = 1; scount <= rslv->dns_hdr.qdcount; scount++) {
+		if ((error = dns_analyze_qd(&qd, offset, msg, length)) < 0)
+			return error;
+
+		ntstdio_printf(ntstdio, "%2d: ", scount);
+		s_show_dns_domain_name(msg, offset);
+		ntstdio_printf(ntstdio, "\n    type: %-4s, class: %2s\n", dns_strtype(qd.type), dns_strclass(qd.class));
+		offset = error;
+	}
+
+	return E_OK;
+}
+
+/*
+ *  show_dns_section -- DNS の各セクションを表示する。
+ */
+
+static ER_UINT
+show_dns_section(uint8_t *msg, ER_UINT length, uint_t scount, uint_t offset, char *title)
+{
+	T_RSLV_RR	rr;
+	T_IN4_ADDR	in4_addr;
+	ER_UINT		error;
+	int		count, dcount, col;
+	T_IN6_ADDR	in6_addr;
+	char temp[30];
+	int pos;
+
+	ntstdio_printf(ntstdio, "%10s section: %d\n", title, scount);
+	for (count = 1; count <= scount; count++) {
+		if ((error = dns_analyze_rr(&rr, offset, msg, length)) < 0)
+			return error;
+
+		ntstdio_printf(ntstdio, "%2d: ", count);
+		s_show_dns_domain_name(msg, offset);
+		ntstdio_printf(ntstdio, "\n    type: %-4s, class: %2s, TTL: %2d, len: %3d, offset: 0x%02x\n",
+			dns_strtype(rr.type), dns_strclass(rr.class), rr.ttl, rr.rdlength, rr.rdata_offset);
+
+		switch (rr.type) {
+		case DNS_TYPE_A:
+			memcpy((void*)&in4_addr, (void*)(msg + rr.rdata_offset), sizeof(in4_addr));
+			in4_addr = ntohl(in4_addr);
+			pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0);
+			temp[pos] = '\0';
+			ntstdio_printf(ntstdio, "    IPv4 addr: %s\n", temp);
+			break;
+		case DNS_TYPE_NS:
+			ntstdio_printf(ntstdio, "    host: ");
+			s_show_dns_domain_name(msg, rr.rdata_offset);
+			putchar('\n');
+			break;
+		case DNS_TYPE_CNAME:
+			ntstdio_printf(ntstdio, "    host: ");
+			s_show_dns_domain_name(msg, rr.rdata_offset);
+			putchar('\n');
+			break;
+		case DNS_TYPE_SOA:
+			show_dns_soa(msg, length, rr.rdata_offset);
+			break;
+		case DNS_TYPE_PTR:
+			ntstdio_printf(ntstdio, "     PTR: ");
+			s_show_dns_domain_name(msg, rr.rdata_offset);
+			putchar('\n');
+			break;
+		case DNS_TYPE_AAAA:
+			memcpy((void*)&in6_addr, (void*)(msg + rr.rdata_offset), sizeof(in6_addr));
+			pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0);
+			temp[pos] = '\0';
+			ntstdio_printf(ntstdio, "    IPv6 addr: %s\n", temp);
+			break;
+		default:
+			ntstdio_printf(ntstdio, "    data: ");
+			col = 32;
+			for (dcount = 0; dcount < rr.rdlength; dcount++) {
+				ntstdio_printf(ntstdio, "%02x", *(msg + rr.rdata_offset + dcount));
+				if (--col == 0) {
+					ntstdio_printf(ntstdio, "\n          ");
+					col = 32;
+				}
+			}
+			putchar('\n');
+			break;
+		}
+	}
+
+	return E_OK;
+}
+/*
+ *  dns_info -- DNS 情報の表示
+ */
+
+static void dns_info()
+{
+#if defined(SUPPORT_INET6)
+	T_IN6_ADDR	in6_addr;
+#endif
+#if defined(SUPPORT_INET4)
+	T_IN4_ADDR	in4_addr;
+#endif
+	char temp[30];
+	int pos;
+
+#if defined(SUPPORT_INET6)
+
+	ntstdio_printf(ntstdio, "domain name:     %s\n", dns_in6_get_dname());
+
+#else	/* of #if defined(SUPPORT_INET6) */
+
+	ntstdio_printf(ntstdio, "domain name:     %s\n", dns_in4_get_dname());
+
+#endif	/* of #if defined(SUPPORT_INET6) */
+
+#if defined(SUPPORT_INET6)
+	dns_in6_get_addr(&in6_addr);
+	ntstdio_printf(ntstdio, "IPv6 DNS server: ");
+	if (IN6_IS_ADDR_UNSPECIFIED(&in6_addr))
+		ntstdio_printf(ntstdio, "not available.\n");
+	else {
+		pos = str_ipv6addr(temp, sizeof(temp), &in6_addr, 0);
+		temp[pos] = '\0';
+		ntstdio_printf(ntstdio, "%s.\n", temp);
+	}
+#endif	/* of #if defined(SUPPORT_INET6) */
+
+#if defined(SUPPORT_INET4)
+	dns_in4_get_addr(&in4_addr);
+	ntstdio_printf(ntstdio, "IPv4 DNS server: ");
+	if (in4_addr == IPV4_ADDRANY)
+		ntstdio_printf(ntstdio, "not available.\n");
+	else {
+		pos = str_ipv4addr(temp, sizeof(temp), &in4_addr, 0);
+		temp[pos] = '\0';
+		ntstdio_printf(ntstdio, "%s.\n", temp);
+	}
+#endif	/* of #if defined(SUPPORT_INET4) */
+}
+
+/*
+ *  name_lookup -- ホスト名－IP アドレス変換
+ */
+
+const char *rcode_str[] = {
+	"no error",
+	"format error",
+	"server error",
+	"name error",
+	"not implement",
+	"refused",
+};
+
+int usrcmd_dnsc(int argc, char **argv)
+{
+	char *line = argv[1];
+	static char hostname[DBG_LINE_SIZE + 1];
+
+	T_RSLV_DNS_MSG	rslv;
+	ER_UINT		length, offset;
+	ER		error;
+	uint_t		flags = 0;
+	uint8_t 	*msg;
+
+	if (ntlibc_strcmp(line, "info") == 0) {
+		dns_info();
+		return 0;
+	}
+
+	/* コマンドのオプションを設定する。*/
+	line = skip_blanks(resolv_options(&flags, line, DEFAULT_API_PROTO));
+	if ((flags & (DNS_LUP_FLAGS_PROTO_IPV6 | DNS_LUP_FLAGS_PROTO_IPV4)) == 0) {
+		ntstdio_printf(ntstdio, "DNS server not available.\n");
+		return 0;
+	}
+
+	/* 照会するホスト名・IP アドレスを解析する。*/
+	resolv_hoststr(&flags, hostname, sizeof(hostname), line);
+
+	/* 正引きでも逆引きでもプロトコル上は正引きを指定する。*/
+	flags |= DNS_LUP_OPCODE_FORWARD;
+
+	/* IPv6 アドレス、または IPv4 アドレスが指定された時は、照会タイプは PTR に設定する。*/
+	if (((flags & DNS_LUP_FLAGS_NAME_MASK) == DNS_LUP_FLAGS_NAME_IPV6) ||
+		((flags & DNS_LUP_FLAGS_NAME_MASK) == DNS_LUP_FLAGS_NAME_IPV4))
+		flags = (flags & ~DNS_LUP_FLAGS_QTYPE_MASK) | DNS_LUP_FLAGS_QTYPE_PTR;
+
+	if ((error = tget_mpf(MPF_RSLV_SRBUF, (void*)&msg, TMO_FEVR)) != E_OK) {
+		ntstdio_printf(ntstdio, "get buffer error: %s.\n", itron_strerror(error));
+		return 0;
+	}
+
+	if ((length = dns_lookup_host(flags | DNS_LUP_FLAGS_MSG, line, msg, DNS_UDP_MSG_LENGTH, &rslv)) < 0) {
+		//ntstdio_printf(ntstdio, "error: %s.\n", itron_strerror(length));
+		goto err_ret;
+	}
+
+	dly_tsk(1 * 1000);
+	ntstdio_printf(ntstdio, "DNS header: flags: ");
+	if (rslv.dns_hdr.code & (DNS_QR_RESPONSE | DNS_AUTHORITATIVE |
+		DNS_TRUN_CATION | DNS_RECURSION_DESIRED | DNS_RECURSION_AVAILABLE)) {
+		ntstdio_printf(ntstdio, (rslv.dns_hdr.code & DNS_QR_RESPONSE) ? "QR," : "");
+		ntstdio_printf(ntstdio, (rslv.dns_hdr.code & DNS_AUTHORITATIVE) ? "AA," : "");
+		ntstdio_printf(ntstdio, (rslv.dns_hdr.code & DNS_TRUN_CATION) ? "TC," : "");
+		ntstdio_printf(ntstdio, (rslv.dns_hdr.code & DNS_RECURSION_DESIRED) ? "RD," : "");
+		ntstdio_printf(ntstdio, (rslv.dns_hdr.code & DNS_RECURSION_AVAILABLE) ? "RA," : "");
+		ntstdio_printf(ntstdio, " ");
+	}
+	ntstdio_printf(ntstdio, "opcode: ");
+	ntstdio_printf(ntstdio, (rslv.dns_hdr.code & DNS_OPCODE_REVERSE) ? "RV" : "FW");
+	ntstdio_printf(ntstdio, (rslv.dns_hdr.code & DNS_OPCODE_STATUS) ? ",ST" : "");
+	ntstdio_printf(ntstdio, ", rcode: %s.\n",
+		(rslv.dns_hdr.code & DNS_RCODE_MASK) > DNS_RCODE_REFUSED
+		? "6" : rcode_str[rslv.dns_hdr.code & DNS_RCODE_MASK]);
+
+	if ((offset = show_dns_qdsection(msg, length, &rslv)) < 0) {
+		ntstdio_printf(ntstdio, "msg error: %s.\n", itron_strerror(offset));
+	}
+	if ((offset = show_dns_section(msg, length, rslv.dns_hdr.ancount, rslv.an_offset, "answer")) < 0) {
+		ntstdio_printf(ntstdio, "msg error: %s.\n", itron_strerror(offset));
+	}
+	if ((offset = show_dns_section(msg, length, rslv.dns_hdr.nscount, rslv.ns_offset, "authority")) < 0) {
+		ntstdio_printf(ntstdio, "msg error: %s.\n", itron_strerror(offset));
+	}
+	if ((offset = show_dns_section(msg, length, rslv.dns_hdr.arcount, rslv.ar_offset, "additional")) < 0) {
+		ntstdio_printf(ntstdio, "msg error: %s.\n", itron_strerror(offset));
+	}
+
+err_ret:
+	if ((error = rel_mpf(MPF_RSLV_SRBUF, msg)) != E_OK)
+		ntstdio_printf(ntstdio, "release buffer error: %s.\n", itron_strerror(error));
+	return 0;
+}
+
+int usrcmd_ntpc(int argc, char **argv)
+{
+	ntp_cli_execute();
+	return 0;
+}
Index: /EcnlProtoTool/trunk/ntshell/src/netcmd.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/netcmd.h	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/netcmd.h	(revision 441)
@@ -0,0 +1,49 @@
+/*
+ *  TOPPERS PROJECT Home Network Working Group Software
+ * 
+ *  Copyright (C) 2018-2019 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+#ifndef _NETCMD_H_
+#define _NETCMD_H_
+
+int str_ipv4addr(char *text, int size, T_IN4_ADDR *addr, int width);
+int str_ipv6addr(char *text, int size, const T_IN6_ADDR *addr, int width);
+int str_macaddr(char *text, int size, uint8_t *mac, int width);
+
+int usrcmd_ping(int argc, char **argv);
+int usrcmd_dhcp4c(int argc, char **argv);
+int usrcmd_dnsc(int argc, char **argv);
+int usrcmd_ntpc(int argc, char **argv);
+
+#endif /* _NETCMD_H_ */
Index: /EcnlProtoTool/trunk/ntshell/src/ntp_cli.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/ntp_cli.c	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/ntp_cli.c	(revision 441)
@@ -0,0 +1,575 @@
+/*
+ *  TOPPERS PROJECT Home Network Working Group Software
+ * 
+ *  Copyright (C) 2018-2019 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+
+/* 
+ *  NTP クライアント
+ */
+
+#include <string.h>
+#include <string.h>
+#include <time.h>
+
+#if defined(TARGET_KERNEL_ASP)
+
+#include <kernel.h>
+#include <sil.h>
+#include <t_syslog.h>
+#include "kernel_cfg.h"
+#include <stdio.h>
+
+#endif	/* of #if defined(TARGET_KERNEL_ASP) */
+
+#if defined(TARGET_KERNEL_JSP)
+
+#include <t_services.h>
+#include "kernel_id.h"
+#include "tinet_id.h"
+
+#endif	/* of #if defined(TARGET_KERNEL_JSP) */
+
+#include <netinet/in.h>
+#include <netinet/in_itron.h>
+
+#include <netapp/netapp.h>
+#include <netapp/netapp_var.h>
+#include "ntp_cli.h"
+
+/* NTP サーバのポート番号 */
+
+#define NTP_SRV_PORTNO		UINT_C(123)
+
+/* NTP サーバのURL */
+
+#define NTP_SRV_URL		"ntp.nict.jp"
+
+/* 送信間隔 */
+
+#define SLP_ITV		(60*SYSTIM_HZ)
+
+/* 関数 */
+
+void ntp_cli_update_time(T_NTP_CLI_CONTEXT *nc);
+ER ntp_cli_time_synchronization(T_NTP_CLI_CONTEXT *nc, ntp_mode_t mode);
+void ntp_cli_read_time(T_NTP_CLI_CONTEXT *nc, struct timespec *tp);
+void ntp_cli_write_time(T_NTP_CLI_CONTEXT *nc, struct timespec *tp);
+void ntp_cli_read_data(T_NTP_CLI_CONTEXT *nc);
+
+/*
+ *  全域変数
+ */
+
+T_NTP_CLI_CONTEXT ntp_cli;
+
+/* UNIX:1970/1/1 - NTP:1900/1/1 */
+#define TIME_OFS (25567ll * 24 * 60 * 60)
+
+void set_systime_to_ntptime(struct timespec *tp, T_NTP_TIMESTAMP *timestamp)
+{
+	timestamp->integer = htonl((uint32_t)(tp->tv_sec + TIME_OFS));
+	timestamp->fraction = htonl((((unsigned long long)tp->tv_nsec) << 32) / 1000000000ll);
+}
+
+void set_ntptime_to_systime(struct timespec *tp, T_NTP_TIMESTAMP *timestamp)
+{
+	tp->tv_sec = ntohl(timestamp->integer) - TIME_OFS;
+	tp->tv_nsec = ((unsigned long long)(ntohl(timestamp->fraction) * 1000000000ll)) >> 32;
+}
+
+void add_timestamp(T_NTP_TIMESTAMP *dst, T_NTP_TIMESTAMP *a, T_NTP_TIMESTAMP *b)
+{
+	uint32_t ai = ntohl(a->integer);
+	uint32_t af = ntohl(a->fraction);
+	uint32_t bi = ntohl(b->integer);
+	uint32_t bf = ntohl(b->fraction);
+	uint32_t f = af + bf;
+	uint32_t o = ((f < af) || (f < bf)) ? 1u : 0;
+	uint32_t i = ai + bi + o;
+	dst->integer = htonl(i);
+	dst->fraction = htonl(f);
+}
+
+void sub_timestamp(T_NTP_TIMESTAMP *dst, T_NTP_TIMESTAMP *a, T_NTP_TIMESTAMP *b)
+{
+	uint32_t ai = ntohl(a->integer);
+	uint32_t af = ntohl(a->fraction);
+	uint32_t bi = ntohl(b->integer);
+	uint32_t bf = ntohl(b->fraction);
+	uint32_t o = (af < bf) ? 1u : 0u;
+	uint32_t f = af - bf;
+	uint32_t i = ai - bi - o;
+	dst->integer = htonl(i);
+	dst->fraction = htonl(f);
+}
+
+void div2_timestamp(T_NTP_TIMESTAMP *a)
+{
+	uint32_t ai = ntohl(a->integer);
+	uint32_t af = ntohl(a->fraction);
+
+	if ((ai & 1) != 0) {
+		ai >>= 1;
+		af >>= 1;
+		af |= 0x80000000u;
+	}
+	else {
+		ai >>= 1;
+		af >>= 1;
+	}
+
+	a->integer = htonl(ai);
+	a->fraction = htonl(af);
+}
+
+#define NTP_POLL_ASYNC 10		// 1024秒毎に時刻問い合わせ
+#define NTP_POLL_NORMAL 16		// 65536秒毎に時刻問い合わせ
+
+void ntp_cli_initialize(T_NTP_CLI_CONTEXT *nc, ID cepid)
+{
+	nc->cepid = cepid;
+	nc->state = NTP_CLI_STATE_ASYNC;
+	nc->timer = TMO_FEVR;
+	nc->snd_rmt.portno = NTP_SRV_PORTNO;
+	nc->snd_rmt.ipaddr = IPV4_ADDRANY;
+	nc->rcv_rmt.portno = 0;
+	nc->rcv_rmt.ipaddr = IPV4_ADDRANY;
+}
+
+void ntp_cli_set_state_changed_cb(ntp_cli_state_changed_cb_t state_changed_cb)
+{
+	ntp_cli.state_changed_cb = state_changed_cb;
+}
+
+void ntp_cli_execute()
+{
+	ntp_cli.exe_flag = 1;
+	syscall(wup_tsk(ntp_cli.tskid));
+}
+
+void ntp_cli_wakeup(T_NTP_CLI_CONTEXT *nc)
+{
+	int rcv_flag = nc->rcv_flag;
+	nc->rcv_flag = 0;
+
+	if (rcv_flag > 0) {
+		ntp_cli_read_data(nc);
+		return;
+	}
+
+	if (nc->exe_flag != 0) {
+		nc->exe_flag = 0;
+
+		nc->state = NTP_CLI_STATE_ASYNC;
+		nc->timer = 0;
+	}
+}
+
+void ntp_cli_read_data(T_NTP_CLI_CONTEXT *nc)
+{
+	struct timespec tp;
+	T_NTP_MSG *ntp = &nc->ntp_msg;
+
+	// NTP時刻応答の場合
+	if ((ntp->mode == NTP_MODE_SERVER) || (ntp->mode == NTP_MODE_BROADCAST)) {
+		switch (nc->state) {
+		case NTP_CLI_STATE_RESOLVE_ADDR:
+		case NTP_CLI_STATE_ASYNC:
+			break;
+		case NTP_CLI_STATE_REQUEST:
+			// サーバーからの応答時刻を取得
+			memcpy(&nc->receive_timestamp, &ntp->receive_timestamp, sizeof(nc->receive_timestamp));
+			memcpy(&nc->transmit_timestamp, &ntp->transmit_timestamp, sizeof(nc->transmit_timestamp));
+
+			// 現在時刻取得
+			ntp_cli_read_time(nc, &tp);
+
+			// NTP参照時刻に現在時刻を設定
+			set_systime_to_ntptime(&tp, &nc->recv_resp_timestamp);
+
+			// 時刻を更新
+			ntp_cli_update_time(nc);
+			if (nc->state_changed_cb != NULL) {
+				nc->state_changed_cb(NTP_CLI_STATE_SYNC);
+			}
+
+			nc->state = NTP_CLI_STATE_SYNC;
+			nc->poll = NTP_POLL_NORMAL;
+			nc->timer = (1 << nc->poll) * 1000 * 1000;
+			break;
+		case NTP_CLI_STATE_SYNC:
+			break;
+		}
+	}
+	// NTP時刻要求の場合
+	else if (ntp->mode == NTP_MODE_CLIENT) {
+		// 現在時刻取得
+		ntp_cli_read_time(nc, &tp);
+
+		// NTP受信・送信時刻に現在時刻を設定
+		set_systime_to_ntptime(&tp, &nc->receive_timestamp);
+		set_systime_to_ntptime(&tp, &nc->transmit_timestamp);
+
+		// NTPパケット送信
+		ntp_cli_time_synchronization(nc, NTP_MODE_SERVER);
+	}
+}
+
+void ntp_cli_update_time(T_NTP_CLI_CONTEXT *nc)
+{
+	struct timespec tp;
+	T_NTP_TIMESTAMP dt1, dt2, ofs;
+
+	sub_timestamp(&dt1, &nc->receive_timestamp, &nc->originate_timestamp);
+	sub_timestamp(&dt2, &nc->recv_resp_timestamp, &nc->transmit_timestamp);
+	sub_timestamp(&ofs, &dt1, &dt2);
+	div2_timestamp(&ofs);
+
+	// 差が大きい場合はサーバーの送信時間を設定
+	if (ntohl(ofs.integer) > 2) {
+		memcpy(&nc->reference_timestamp, &nc->transmit_timestamp, sizeof(nc->transmit_timestamp));
+	}
+	else {
+		add_timestamp(&nc->reference_timestamp, &nc->recv_resp_timestamp, &ofs);
+	}
+
+	set_ntptime_to_systime(&tp, &nc->reference_timestamp);
+
+	ntp_cli_write_time(nc, &tp);
+
+	nc->buf[0] = '\0';
+#ifdef __NEED_struct_timespec
+	if (ctime_r(&tp.tv_sec, nc->buf) != NULL)
+#else
+	if (ctime_s(nc->buf, sizeof(nc->buf), &tp.tv_sec) == 0)
+#endif
+	{
+		/* 改行コードの削除 */
+		int len = strnlen(nc->buf, sizeof(nc->buf) - 1);
+		nc->buf[len - 1] = '\0';
+	}
+	else {
+		nc->buf[0] = '\0';
+	}
+
+	syslog(LOG_NOTICE, "[NTP CLI,%d] recv time: %s .%09u",
+		nc->cepid, nc->buf, tp.tv_nsec);
+}
+
+int ntp_cli_get_timer(T_NTP_CLI_CONTEXT *nc)
+{
+	return nc->timer;
+}
+
+void ntp_cli_progress(T_NTP_CLI_CONTEXT *nc, TMO elapse)
+{
+	if (nc->timer <= 0)
+		return;
+
+	nc->timer -= elapse;
+	if (nc->timer < 0)
+		nc->timer = 0;
+}
+
+void ntp_cli_timeout(T_NTP_CLI_CONTEXT *nc)
+{
+	struct timespec tp;
+	char *line;
+
+	if (nc->timer != 0)
+		return;
+
+	switch (nc->state) {
+	case NTP_CLI_STATE_ASYNC:
+#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
+		line = lookup_ipaddr(&nc->ipaddr6, NTP_SRV_URL, API_PROTO_IPV4);
+		if (line == NULL || !in6_is_addr_ipv4mapped(&nc->ipaddr6)) {
+			syslog(LOG_NOTICE, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
+				nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
+			nc->timer = SLP_ITV;
+			break;
+		}
+		nc->snd_rmt.ipaddr = ntohl(nc->ipaddr6.s6_addr32[3]);
+#else	/* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
+		if ((line = lookup_ipaddr(&nc->snd_rmt.ipaddr, NTP_SRV_URL, DEFAULT_API_PROTO)) == NULL) {
+			syslog(LOG_NOTICE, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
+				nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
+			nc->timer = SLP_ITV;
+			break;
+		}
+#endif	/* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
+		nc->state = NTP_CLI_STATE_RESOLVE_ADDR;
+		nc->timer = 1000;
+		/* through */
+	case NTP_CLI_STATE_RESOLVE_ADDR:
+		// 現在時刻取得
+		ntp_cli_read_time(nc, &tp);
+
+		// NTP開始時刻に現在時刻を設定
+		set_systime_to_ntptime(&tp, &nc->originate_timestamp);
+		memset(&nc->receive_timestamp, 0, sizeof(nc->receive_timestamp));
+		memset(&nc->transmit_timestamp, 0, sizeof(nc->transmit_timestamp));
+
+		// NTPパケット送信
+		ntp_cli_time_synchronization(nc, NTP_MODE_CLIENT);
+
+		// NTP応答待ちに遷移、500msでリトライ
+		nc->retry = 0;
+		nc->state = NTP_CLI_STATE_REQUEST;
+		nc->timer = 500 * 1000;
+		break;
+	case NTP_CLI_STATE_REQUEST:
+		nc->retry++;
+		if (nc->retry > 3) {
+			if (nc->state_changed_cb != NULL) {
+				nc->state_changed_cb(NTP_CLI_STATE_ASYNC);
+			}
+			nc->state = NTP_CLI_STATE_ASYNC;
+			nc->poll = NTP_POLL_ASYNC;
+			nc->timer = (1 << nc->poll) * 1000 * 1000;  // 1024秒後に時刻同期
+			break;
+		}
+		// 現在時刻取得
+		ntp_cli_read_time(nc, &tp);
+
+		// NTP開始時刻に現在時刻を設定
+		set_systime_to_ntptime(&tp, &nc->originate_timestamp);
+		memset(&nc->receive_timestamp, 0, sizeof(nc->receive_timestamp));
+		memset(&nc->transmit_timestamp, 0, sizeof(nc->transmit_timestamp));
+
+		// NTPパケット送信
+		ntp_cli_time_synchronization(nc, NTP_MODE_CLIENT);
+
+		// NTP応答待ちに遷移、500msでリトライ
+		nc->state = NTP_CLI_STATE_REQUEST;
+		nc->timer = 500 * 1000;
+		break;
+	case NTP_CLI_STATE_SYNC:
+		// 現在時刻取得
+		ntp_cli_read_time(nc, &tp);
+
+		// NTP開始時刻に現在時刻を設定
+		set_systime_to_ntptime(&tp, &nc->originate_timestamp);
+		memset(&nc->receive_timestamp, 0, sizeof(nc->receive_timestamp));
+		memset(&nc->transmit_timestamp, 0, sizeof(nc->transmit_timestamp));
+
+		// NTPパケット送信
+		ntp_cli_time_synchronization(nc, NTP_MODE_CLIENT);
+
+		// NTP応答待ちに遷移、500msでリトライ
+		nc->state = NTP_CLI_STATE_REQUEST;
+		nc->timer = 500 * 1000;
+		break;
+	}
+}
+
+ER ntp_cli_time_synchronization(T_NTP_CLI_CONTEXT *nc, ntp_mode_t mode)
+{
+	ER_UINT	len = sizeof(nc->ntp_msg);
+	T_NTP_MSG *ntp = &nc->ntp_msg;
+	ER error;
+
+	memset(ntp, 0, len);
+
+	ntp->leap_indicator = 0;
+	ntp->version_number = 4;
+	ntp->mode = mode;
+	ntp->stratum = (mode == NTP_MODE_CLIENT) ? 2 : 1;
+	ntp->poll = nc->poll;
+	ntp->precision = 0xfa;   // 精度は10^-6(1μs)
+	ntp->root_delay = htonl(0);
+	ntp->root_dispersion = htonl(0);
+	// 同期のための外部的な手段のないサブネット
+	ntp->reference_identifier[0] = 'L';
+	ntp->reference_identifier[1] = 'O';
+	ntp->reference_identifier[2] = 'C';
+	ntp->reference_identifier[3] = 'L';
+	// 参照タイムスタンプ
+	memcpy(&ntp->reference_timestamp, &nc->reference_timestamp, sizeof(ntp->reference_timestamp));
+	// 開始タイムスタンプ
+	memcpy(&ntp->originate_timestamp, &nc->originate_timestamp, sizeof(ntp->originate_timestamp));
+	// 受信タイムスタンプ
+	memcpy(&ntp->receive_timestamp, &nc->receive_timestamp, sizeof(ntp->receive_timestamp));
+	// 送信タイムスタンプ
+	memcpy(&ntp->transmit_timestamp, &nc->transmit_timestamp, sizeof(ntp->transmit_timestamp));
+	// 鍵識別子
+	ntp->key_identifier[0] = 0x08;
+	ntp->key_identifier[1] = 0x18;
+	ntp->key_identifier[2] = 0x00;
+	ntp->key_identifier[3] = 0x00;
+
+	if ((error = udp_snd_dat(nc->cepid, &nc->snd_rmt, ntp, len, TMO_NBLK)) != E_WBLK) {
+		syslog(LOG_NOTICE, "[NTP CLI,%d] udp_snd_dat error: %s",
+			nc->cepid, itron_strerror(error));
+		return error;
+	}
+	else
+		syslog(LOG_DEBUG, "[NTP CLI,%d] udp_snd_dat: to: %s.%d",
+			nc->cepid, ip2str(NULL, &nc->snd_rmt.ipaddr), nc->snd_rmt.portno);
+
+	return E_OK;
+}
+
+void ntp_cli_read_time(T_NTP_CLI_CONTEXT *nc, struct timespec *tp)
+{
+	SYSTIM time;
+	ER ret;
+
+	ret = get_tim(&time);
+	if (ret != E_OK) {
+		syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %s",
+			nc->cepid, itron_strerror(ret));
+		tp->tv_sec = 0;
+		tp->tv_nsec = 0;
+		return;
+	}
+
+	tp->tv_sec = time / 1000000ll;
+	tp->tv_nsec = (time % 1000000ll) * 1000ll;
+}
+
+void ntp_cli_write_time(T_NTP_CLI_CONTEXT *nc, struct timespec *tp)
+{
+	SYSTIM time;
+	ER ret;
+
+	time = (tp->tv_sec * 1000000ll) + (tp->tv_nsec / 1000ll);
+
+	ret = set_tim(time);
+	if (ret != E_OK) {
+		syslog(LOG_NOTICE, "[NTP CLI,%d] set_tim error: %s",
+			nc->cepid, itron_strerror(ret));
+	}
+}
+
+/*
+ *  ノンブロッキングコールのコールバック関数
+ */
+
+ER
+callback_nblk_ntp_cli (ID cepid, FN fncd, void *p_parblk)
+{
+	T_NTP_CLI_CONTEXT *nc = &ntp_cli;
+	ER_UINT len;
+
+	len = *(ER_UINT*)p_parblk;
+	if (len < 0 && len != E_RLWAI) {
+		/* E_RLWAI 以外で、0 以下の場合は、エラーを意味している。*/
+		syslog(LOG_NOTICE, "[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid,
+			itron_strerror(len), in_strtfn(fncd));
+	}
+	else {
+		if (fncd == TEV_UDP_RCV_DAT) {
+			if ((len = udp_rcv_dat(nc->cepid, &nc->rcv_rmt, &nc->ntp_msg, len, TMO_POL)) < 0)
+			{
+				syslog(LOG_NOTICE, "[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid,
+					itron_strerror(len));
+			}
+			else
+				syslog(LOG_DEBUG, "[NTP CLI,%d] udp_rcv_dat len: %d", nc->cepid, len);
+
+			if (len >= sizeof(nc->ntp_msg))
+				nc->rcv_flag = len;
+			else
+				nc->rcv_flag = 0;
+		}
+		syscall(wup_tsk(nc->tskid));
+	}
+
+	return E_OK;
+}
+
+#ifdef NTP_CLI_TASK
+
+/*
+ *  NTP クライアント送信タスク
+ */
+
+void
+ntp_cli_task (intptr_t exinf)
+{
+	T_NTP_CLI_CONTEXT *nc = &ntp_cli;
+	ER		error, ret;
+	SYSTIM		prev, time;
+	int timer;
+
+	get_tid(&nc->tskid);
+	syslog(LOG_NOTICE, "[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf);
+
+	/* 初期化 */
+	ntp_cli_initialize(nc, (ID)exinf);
+
+	ret = get_tim(&time);
+	if (ret != E_OK) {
+		syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %7lu,%s",
+			nc->cepid, time / SYSTIM_HZ, itron_strerror(ret));
+		return;
+	}
+
+	while (true) {
+		prev = time;
+
+		/* タイマー取得 */
+		timer = ntp_cli_get_timer(nc);
+
+		/* 待ち */
+		error = tslp_tsk(timer);
+		if ((error != E_OK) && (error != E_TMOUT)) {
+			syslog(LOG_NOTICE, "[NTP CLI,%d] tslp_tsk error: %s %d",
+				nc->cepid, itron_strerror(error), timer);
+			break;
+		}
+
+		ret = get_tim(&time);
+		if (ret != E_OK) {
+			syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %s",
+				nc->cepid, itron_strerror(ret));
+			break;
+		}
+
+		/* 時間経過 */
+		ntp_cli_progress(nc, time - prev);
+
+		/* 起こされた場合 */
+		if (error == E_OK) {
+			ntp_cli_wakeup(nc);
+		}
+
+		/* タイムアウト処理 */
+		ntp_cli_timeout(nc);
+	}
+}
+
+#endif
Index: /EcnlProtoTool/trunk/ntshell/src/ntp_cli.cfg
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/ntp_cli.cfg	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/ntp_cli.cfg	(revision 441)
@@ -0,0 +1,51 @@
+/*
+ *  TOPPERS PROJECT Home Network Working Group Software
+ * 
+ *  Copyright (C) 2018-2019 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+
+/*
+ *  NTP クライアントのシステムコンフィギュレーションファイル
+ */
+
+/* タスク */
+
+CRE_TSK(NTP_CLI_TASK, {
+	TA_HLNG|TA_ACT,
+	NTP_CLI_CEPID,
+	ntp_cli_task,
+	NTP_CLI_MAIN_PRIORITY,
+	NTP_CLI_STACK_SIZE,
+	NULL
+	});
Index: /EcnlProtoTool/trunk/ntshell/src/ntp_cli.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/ntp_cli.h	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/ntp_cli.h	(revision 441)
@@ -0,0 +1,136 @@
+/*
+ *  TOPPERS PROJECT Home Network Working Group Software
+ * 
+ *  Copyright (C) 2018-2019 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+
+#ifndef _NTP_CLI_H_
+#define _NTP_CLI_H_
+
+/* スタックサイズ */
+
+#define NTP_CLI_STACK_SIZE	1024		/* NTP クライアントタスク（IPv4）のスタックサイズ	*/
+
+/* 優先度 */
+
+#define NTP_CLI_MAIN_PRIORITY	5		/* NTP クライアントタスク（IPv4）の優先度		*/
+
+/* タスク */
+
+extern void	ntp_cli_task(intptr_t exinf);
+
+/* NTPタイムスタンプ */
+typedef struct ntp_timestamp {
+	uint32_t integer;
+	uint32_t fraction;
+} __attribute__((packed)) T_NTP_TIMESTAMP;
+
+/* NTPパケット */
+typedef struct ntp_msg {
+	uint8_t mode : 3;
+	uint8_t version_number : 3;
+	uint8_t leap_indicator : 2;
+	uint8_t stratum;
+	uint8_t poll;
+	uint8_t precision;
+	uint32_t root_delay;
+	uint32_t root_dispersion;
+	uint8_t reference_identifier[4];
+	T_NTP_TIMESTAMP reference_timestamp;
+	T_NTP_TIMESTAMP originate_timestamp;
+	T_NTP_TIMESTAMP receive_timestamp;
+	T_NTP_TIMESTAMP transmit_timestamp;
+	uint8_t key_identifier[4];
+	uint8_t message_digest[16];
+} __attribute__((packed)) T_NTP_MSG;
+
+typedef enum ntp_mode {
+	NTP_MODE_RESERVED,
+	NTP_MODE_SYMMETRIC_ACTIVE,
+	NTP_MODE_SYMMETRIC_PASSIVE,
+	NTP_MODE_CLIENT,
+	NTP_MODE_SERVER,
+	NTP_MODE_BROADCAST,
+	NTP_MODE_NTP_CONTROL_MESSAGE,
+	NTP_MODE_RESERVED_FOR_PRIVATE_USER
+} ntp_mode_t;
+
+/* NTPクライアント状態 */
+typedef enum ntp_cli_state {
+	NTP_CLI_STATE_ASYNC,
+	NTP_CLI_STATE_RESOLVE_ADDR,
+	NTP_CLI_STATE_REQUEST,
+	NTP_CLI_STATE_SYNC,
+} ntp_cli_state_t;
+
+typedef void (* ntp_cli_state_changed_cb_t)(ntp_cli_state_t state);
+
+typedef struct ntp_cli {
+	ntp_cli_state_t state;
+	int timer;
+	int retry;
+#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
+	T_IN6_ADDR	ipaddr6;
+#endif
+	uint16_t portno;
+	ID tskid;
+	ID cepid;
+	T_NTP_MSG ntp_msg;
+	T_IPV4EP snd_rmt;
+	T_IPV4EP rcv_rmt;
+	uint8_t poll;
+	T_NTP_TIMESTAMP reference_timestamp;
+	T_NTP_TIMESTAMP originate_timestamp;
+	T_NTP_TIMESTAMP receive_timestamp;
+	T_NTP_TIMESTAMP transmit_timestamp;
+	T_NTP_TIMESTAMP recv_resp_timestamp;
+	char buf[30];
+	int rcv_flag;
+	int exe_flag;
+	ntp_cli_state_changed_cb_t state_changed_cb;
+} T_NTP_CLI_CONTEXT;
+
+/* 関数 */
+
+void ntp_cli_initialize(T_NTP_CLI_CONTEXT *nc, ID cepid);
+int ntp_cli_get_timer(T_NTP_CLI_CONTEXT *nc);
+void ntp_cli_progress(T_NTP_CLI_CONTEXT *nc, TMO elapse);
+void ntp_cli_wakeup(T_NTP_CLI_CONTEXT *nc);
+void ntp_cli_timeout(T_NTP_CLI_CONTEXT *nc);
+ER callback_nblk_ntp_cli(ID cepid, FN fncd, void *p_parblk);
+
+void ntp_cli_set_state_changed_cb(ntp_cli_state_changed_cb_t state_changed_cb);
+void ntp_cli_execute();
+
+#endif	/* of #ifndef _NTP_CLI_H_ */
Index: /EcnlProtoTool/trunk/ntshell/src/pipe_stub.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/pipe_stub.c	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/pipe_stub.c	(revision 441)
@@ -0,0 +1,143 @@
+/*
+ *  TOPPERS PROJECT Home Network Working Group Software
+ * 
+ *  Copyright (C) 2017-2019 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+#include "shellif.h"
+#include <stdint.h>
+#include <kernel.h>
+#include <t_syslog.h>
+#include <t_stdlib.h>
+#include <sil.h>
+#include "syssvc/serial.h"
+#include "syssvc/syslog.h"
+#include "target_syssvc.h"
+#include "fdtable.h"
+#include "kernel_cfg.h"
+#include <string.h>
+#include "util/ntstdio.h"
+#include "hal/serial_api.h"
+
+#ifdef _DEBUG
+static const char THIS_FILE[] = __FILE__;
+#endif
+
+static int pipe_close(struct SHELL_FILE *fp);
+static size_t pipe_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t pipe_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t pipe_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int pipe_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t pipe_readable(struct SHELL_FILE *fp);
+static bool_t pipe_writable(struct SHELL_FILE *fp);
+static void pipe_delete(struct SHELL_FILE *fp);
+
+IO_TYPE IO_TYPE_PIPE = { pipe_close, pipe_read, pipe_write, pipe_seek, pipe_ioctl, pipe_readable, pipe_writable, pipe_delete };
+
+struct SHELL_PIPE {
+	unsigned int flags;
+	struct SHELL_PIPE *pair;
+	unsigned char buff[64];
+};
+
+int shell_pipe(int *fds)
+{
+	struct SHELL_FILE *fp1 = new_fp(&IO_TYPE_PIPE, 0, 0);
+	if (fp1 == NULL)
+		return -ENOMEM;
+	fp1->exinf = calloc(1, sizeof(struct SHELL_PIPE));
+
+	struct SHELL_FILE *fp2 = new_fp(&IO_TYPE_PIPE, 0, 0);
+	if (fp2 == NULL) {
+		delete_fp(fp1);
+		return -ENOMEM;
+	}
+	fp2->exinf = calloc(1, sizeof(struct SHELL_PIPE));
+	((struct SHELL_PIPE *)fp2->exinf)->pair = fp1;
+	((struct SHELL_PIPE *)fp1->exinf)->pair = fp2;
+
+	fds[0] = fp1->fd;
+	fds[1] = fp2->fd;
+
+	return 0;
+}
+
+int pipe_close(struct SHELL_FILE *fp)
+{
+	return -ENOSYS;
+}
+
+size_t pipe_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
+{
+	return -ENOSYS;
+}
+
+size_t pipe_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	return -ENOSYS;
+}
+
+off_t pipe_seek(struct SHELL_FILE *fp, off_t ofs, int org)
+{
+	return -ENOSYS;
+}
+
+int pipe_ioctl(struct SHELL_FILE *fp, int req, void *arg)
+{
+	switch (req) {
+	case F_GETFD:
+		*(unsigned int *)arg = ((struct SHELL_PIPE *)fp->exinf)->flags;
+		return 0;
+	case F_SETFD:
+		((struct SHELL_PIPE *)fp->exinf)->flags = (unsigned int)arg;
+		return 0;
+	}
+
+	return -ENOSYS;
+}
+
+bool_t pipe_readable(struct SHELL_FILE *fp)
+{
+	return false;
+}
+
+bool_t pipe_writable(struct SHELL_FILE *fp)
+{
+	return false;
+}
+
+void pipe_delete(struct SHELL_FILE *fp)
+{
+	free((struct SHELL_PIPE *)fp->exinf);
+	fp->exinf = NULL;
+}
Index: /EcnlProtoTool/trunk/ntshell/src/shellif.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/shellif.h	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/shellif.h	(revision 441)
@@ -50,9 +50,9 @@
  *  @(#) $Id$
  */
-#ifndef SHELLIF_H
-#define SHELLIF_H
+#ifndef _SHELLIF_H_
+#define _SHELLIF_H_
 
 #ifdef _MSC_VER
-#include <time.h>
+#undef NULL
 #endif
 
@@ -92,7 +92,5 @@
 #include "../musl-1.1.18/include/bits/stat.h"
 #include "../musl-1.1.18/include/sys/select.h"
-#ifndef _MSC_VER
 #include "../musl-1.1.18/include/time.h"
-#endif
 #include "../musl-1.1.18/include/signal.h"
 #include "../musl-1.1.18/include/stdio.h"
@@ -107,6 +105,13 @@
 #include <stdarg.h>
 
+#define DebugBreak()	asm("bkpt #0")
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 // time.h
 #define CLOCK_REALTIME 0
+int shell_nanosleep(const struct timespec *req, struct timespec *rem);
 
 // dirent.h
@@ -154,27 +159,29 @@
 // signal.h
 int shell_sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old);
-int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old);
+struct k_sigaction;
+int shell_sigaction(int sig, const struct k_sigaction *restrict sa,
+	struct k_sigaction *restrict old, size_t size);
 // socket.h
 int shell_socket(int, int, int);
 int shell_connect(int, const struct sockaddr *, socklen_t);
-ssize_t shell_send(int, const void *, size_t, int);
 ssize_t shell_sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
 ssize_t shell_sendmsg(int, const struct msghdr *, int);
 int shell_bind(int, const struct sockaddr *, socklen_t);
 int shell_listen(int, int);
-int shell_accept(int, struct sockaddr *__restrict, socklen_t *__restrict);
-ssize_t shell_recv(int, void *, size_t, int);
-ssize_t shell_recvfrom(int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict);
+int shell_accept(int, struct sockaddr *restrict, socklen_t *restrict);
+ssize_t shell_recvfrom(int, void *restrict, size_t, int, struct sockaddr *restrict, socklen_t *restrict);
 ssize_t shell_recvmsg(int, struct msghdr *, int);
-int shell_getsockopt(int, int, int, void *__restrict, socklen_t *__restrict);
+int shell_getsockopt(int, int, int, void *restrict, socklen_t *restrict);
 int shell_setsockopt(int, int, int, const void *, socklen_t);
 int shell_shutdown(int, int);
+int shell_getpeername(int fd, struct sockaddr *restrict addr, socklen_t *restrict len);
+int shell_getsockname(int fd, struct sockaddr *restrict addr, socklen_t *restrict len);
 // select.h
-int shell_select(int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict);
+int shell_select(int, fd_set *restrict, fd_set *restrict, fd_set *restrict, struct timeval *restrict);
 // syslog.h
 void vsyslog (int, const char *, va_list);
 // termios.h
-int sio_tcgetattr (int, struct termios *);
-int sio_tcsetattr(int, int, const struct termios *);
+int tcgetattr (int, struct termios *);
+int tcsetattr(int, int, const struct termios *);
 // fcntl.h
 int shell_open(const char *, int, void *arg);
@@ -196,7 +203,7 @@
 int shell_chmod(const char *, mode_t);
 int shell_mkdir(const char *, mode_t);
-int shell_stat(const char *__restrict, struct stat *__restrict);
+int shell_stat(const char *restrict, struct stat *restrict);
 int shell_fstat(int, struct stat *);
-int shell_lstat(const char *__restrict, struct stat *__restrict);
+int shell_lstat(const char *restrict, struct stat *restrict);
 
 int shell_clock_getres(clockid_t clk_id, struct timespec *res);
@@ -215,6 +222,38 @@
 int shell_mprotect(void *addr, size_t len, int prot);
 // TODO
+int shell_clone(int, int);
+int shell_dup2(int, int);
+int shell_execve(const char *, char *const [], char *const []);
+int shell_faccessat(int, const char *, int, int);
+int shell_fchmodat(int, const char *, mode_t, int);
+int shell_flock(int, int);
+int shell_fork();
+int shell_futex(volatile int *, int, int, void *);
+int shell_futimesat(int, const char *, struct timeval *);
+int shell_getegid();
+int shell_geteuid();
+int shell_getgid();
+int shell_gettid();
+int shell_getuid();
 int shell_madvise(void *, size_t, int);
+int shell_mremap(void *, size_t, size_t, int, void *);
+int shell_munmap(void *, size_t);
+int shell_pipe(int [2]);
+int shell_pipe2(int [2], int);
+int shell_ppoll(struct pollfd *, nfds_t, const struct timespec *,const sigset_t *);
+int shell_pselect6(int, fd_set *restrict, fd_set *restrict,
+	fd_set *restrict, const struct timespec *restrict, const sigset_t *restrict);
+int shell_setpgid(pid_t, pid_t);
+int shell_setsid();
+int shell_symlink(const char *, const char *);
+int shell_tkill(int, int);
+int shell_umask(mode_t);
 int shell_uname(struct utsname *);
+int shell_utimensat(int, const char *, const struct timespec [2], int);
+int shell_utimes(const char *, struct timeval *);
+// sys/resource.h
+struct rusage;
+int shell_wait4(pid_t, int *, int, struct rusage *);
+ssize_t shell_getrandom(void *buf, size_t buflen, unsigned int flags);
 // âââmusl
 
@@ -239,11 +278,24 @@
 void __mbedcall_cp_asm();
 
+#include "ff.h"
+WCHAR Utf8_to_Utf16(const char *, int *); /* in ff.c */
+void Utf16_to_Utf8(unsigned char *, int *, UINT); /* in ff.c */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
-void Kernel_StartExternal(int argc, char **argv);
+int Kernel_StartExternal(int argc, char **argv);
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* SHELLIF_H */
+void *malloc(size_t size);
+void *calloc(size_t size, size_t count);
+void *realloc(void *ptr, size_t size);
+void free(void *ptr);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SHELLIF_H_ */
Index: /EcnlProtoTool/trunk/ntshell/src/socket_stub.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/socket_stub.c	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/socket_stub.c	(revision 441)
@@ -39,9 +39,11 @@
 #include <t_syslog.h>
 #include <t_stdlib.h>
-//#include <string.h>
+#include <string.h>
 #include <sil.h>
-#include <setjmp.h>
 #include "syssvc/syslog.h"
+#include <tinet_defs.h>
 #include <tinet_config.h>
+#include <net/net.h>
+#include <net/net_endian.h>
 #include <netinet/in.h>
 #include <netinet/in_itron.h>
@@ -54,10 +56,143 @@
 #include <net/if_var.h>
 #include <netinet/udp_var.h>
-//#include <netinet/tcp_var.h>
-extern const ID tmax_tcp_cepid;
-#include "ff.h"
+#include <net/net_buf.h>
+#include <netinet/udp.h>
+#include <netinet/udp_var.h>
+#include <netinet/tcp.h>
+#include <netinet/tcp_var.h>
+#include <netapp/resolver.h>
 #include "fdtable.h"
+#include "kernel_cfg.h"
+
+#ifdef _DEBUG
+static const char THIS_FILE[] = __FILE__;
+#endif
 
 #define SOCKET_TIMEOUT 2000000
+#define TCP_SOCKET_BUF_SIZE 512
+
+struct addrinfo {
+	int ai_flags;
+	int ai_family;
+	int ai_socktype;
+	int ai_protocol;
+	socklen_t ai_addrlen;
+	struct sockaddr *ai_addr;
+	char *ai_canonname;
+	struct addrinfo *ai_next;
+};
+
+typedef uint16_t in_port_t;
+typedef uint32_t in_addr_t;
+struct in_addr { in_addr_t s_addr; };
+
+struct sockaddr_in {
+	sa_family_t sin_family;
+	in_port_t sin_port;
+	struct in_addr sin_addr;
+	uint8_t sin_zero[8];
+};
+
+struct in6_addr
+{
+	union {
+		uint8_t __s6_addr[16];
+		uint16_t __s6_addr16[8];
+		uint32_t __s6_addr32[4];
+	} __in6_union;
+};
+//#define s6_addr __in6_union.__s6_addr
+//#define s6_addr16 __in6_union.__s6_addr16
+//#define s6_addr32 __in6_union.__s6_addr32
+
+struct sockaddr_in6
+{
+	sa_family_t     sin6_family;
+	in_port_t       sin6_port;
+	uint32_t        sin6_flowinfo;
+	struct in6_addr sin6_addr;
+	uint32_t        sin6_scope_id;
+};
+
+typedef struct socket_t {
+	int family;
+	int type;
+	int protocol;
+	int cepid;
+	int repid;
+	int backlog;
+	unsigned int flags;
+	union {
+		struct sockaddr_in laddr4;
+		struct sockaddr_in6 laddr6;
+	};
+	union {
+		struct sockaddr_in raddr4;
+		struct sockaddr_in6 raddr6;
+	};
+	int buf_size;
+	unsigned char *buf;
+	void *input;
+	int len;
+} socket_t;
+
+#define tcp6_cre_cep tcp_cre_cep
+#define tcp6_del_cep tcp_del_cep
+#define tcp6_del_rep tcp_del_rep
+#define tcp6_can_cep tcp_can_cep
+#define tcp6_sht_cep tcp_sht_cep
+#define tcp6_cls_cep tcp_cls_cep
+#define tcp6_snd_oob tcp_snd_oob
+#define tcp6_snd_dat tcp_snd_dat
+#define tcp6_rcv_oob tcp_rcv_oob
+#define tcp6_rcv_buf tcp_rcv_buf
+#define tcp6_rel_buf tcp_rel_buf
+#define tcp6_get_opt tcp_get_opt
+#define tcp6_set_opt tcp_set_opt
+
+#define udp6_can_cep udp_can_cep
+
+#ifndef SUPPORT_INET6
+
+ER	tcp6_cre_rep (ID repid, T_TCP6_CREP *pk_crep) { return E_SYS; }
+ER	tcp6_acp_cep (ID cepid, ID repid, T_IPV6EP *p_dstaddr, TMO tmout) { return E_SYS; }
+ER	tcp6_con_cep (ID cepid, T_IPV6EP *p_myaddr, T_IPV6EP *p_dstaddr, TMO tmout) { return E_SYS; }
+
+ER	udp6_cre_cep (ID cepid, T_UDP6_CCEP *pk_ccep) { return E_SYS; }
+ER	udp6_del_cep (ID cepid) { return E_SYS; }
+ER_UINT	udp6_snd_dat (ID cepid, T_IPV6EP *p_dstaddr, void *data, int_t len, TMO tmout) { return E_SYS; }
+ER_UINT	udp6_rcv_dat (ID cepid, T_IPV6EP *p_dstaddr, void *data, int_t len, TMO tmout) { return E_SYS; }
+ER	udp6_set_opt (ID cepid, int_t optname, void *optval, int_t optlen) { return E_SYS; }
+ER	udp6_get_opt (ID cepid, int_t optname, void *optval, int_t optlen) { return E_SYS; }
+
+const T_IN6_ADDR *in6_get_ifaddr (int_t index) { return NULL; }
+
+#endif
+
+ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk);
+ER socket_tcp6_callback(ID cepid, FN fncd, void *p_parblk);
+ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk);
+ER socket_udp6_callback(ID cepid, FN fncd, void *p_parblk);
+
+static int tcp_fd_close(struct SHELL_FILE *fp);
+static size_t tcp_fd_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t tcp_fd_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t tcp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t tcp_fd_readable(struct SHELL_FILE *fp);
+static bool_t tcp_fd_writable(struct SHELL_FILE *fp);
+static void tcp_fd_delete(struct SHELL_FILE *fp);
+
+static int udp_fd_close(struct SHELL_FILE *fp);
+static size_t udp_fd_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t udp_fd_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t udp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t udp_fd_readable(struct SHELL_FILE *fp);
+static bool_t udp_fd_writable(struct SHELL_FILE *fp);
+static void udp_fd_delete(struct SHELL_FILE *fp);
+
+IO_TYPE IO_TYPE_TCP = { tcp_fd_close, tcp_fd_read, tcp_fd_write, tcp_fd_seek, tcp_fd_ioctl, tcp_fd_readable, tcp_fd_writable, tcp_fd_delete };
+IO_TYPE IO_TYPE_UDP = { udp_fd_close, udp_fd_read, udp_fd_write, udp_fd_seek, udp_fd_ioctl, udp_fd_readable, udp_fd_writable, udp_fd_delete };
 
 typedef struct id_table_t {
@@ -72,7 +207,35 @@
 
 id_table_t tcp_cepid_table[] = {
-	{0, USR_TCP_CEP1}, {0, USR_TCP_CEP2}, {0, USR_TCP_CEP3}, {0, USR_TCP_CEP4}, {0, USR_TCP_CEP5}, {0, USR_TCP_CEP6}, {0, USR_TCP_CEP7}, {0, USR_TCP_CEP8}
+	{0, USR_TCP_CEP1}, {0, USR_TCP_CEP2}, {0, USR_TCP_CEP3}, {0, USR_TCP_CEP4},
+#ifndef TOPPERS_GRSAKURA
+	{0, USR_TCP_CEP5}, {0, USR_TCP_CEP6}, {0, USR_TCP_CEP7}, {0, USR_TCP_CEP8}
+#endif
 };
 #define tcp_cepid_table_count (sizeof(tcp_cepid_table) / sizeof(tcp_cepid_table[0]))
+
+#ifdef SUPPORT_INET6
+
+id_table_t tcp6_repid_table[] = {
+	{0, USR_TCP6_REP1}, {0, USR_TCP6_REP2}, {0, USR_TCP6_REP3}, {0, USR_TCP6_REP4}
+};
+#define tcp6_repid_table_count (sizeof(tcp6_repid_table) / sizeof(tcp6_repid_table[0]))
+
+id_table_t tcp6_cepid_table[] = {
+	{0, USR_TCP6_CEP1}, {0, USR_TCP6_CEP2}, {0, USR_TCP6_CEP3}, {0, USR_TCP6_CEP4},
+#ifndef TOPPERS_GRSAKURA
+	{0, USR_TCP6_CEP5}, {0, USR_TCP6_CEP6}, {0, USR_TCP6_CEP7}, {0, USR_TCP6_CEP8}
+#endif
+};
+#define tcp6_cepid_table_count (sizeof(tcp6_cepid_table) / sizeof(tcp6_cepid_table[0]))
+
+#else
+
+#define tcp6_repid_table NULL
+#define tcp6_repid_table_count 0
+
+#define tcp6_cepid_table NULL
+#define tcp6_cepid_table_count 0
+
+#endif
 
 id_table_t udp_cepid_table[] = {
@@ -81,4 +244,29 @@
 #define udp_cepid_table_count (sizeof(udp_cepid_table) / sizeof(udp_cepid_table[0]))
 
+#ifdef SUPPORT_INET6
+
+id_table_t udp6_cepid_table[] = {
+	{0, USR_UDP6_CEP1}, {0, USR_UDP6_CEP2}, {0, USR_UDP6_CEP3}, {0, USR_UDP6_CEP4}
+};
+#define udp6_cepid_table_count (sizeof(udp6_cepid_table) / sizeof(udp6_cepid_table[0]))
+
+#else
+
+#define udp6_cepid_table NULL
+#define udp6_cepid_table_count 0
+
+#endif
+
+void addrcpy(void *_dst, const void *_src, int len)
+{
+#if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
+	memcpy(_dst, _src, len);
+#else
+	uint8_t *dst = (uint8_t *)_dst, *src = &((uint8_t *)_src)[len];
+	while (src != _src)
+		*dst++ = *--src;
+#endif
+}
+
 ID new_id(id_table_t *table, int count)
 {
@@ -108,25 +296,5 @@
 }
 
-int delete_tcp_rep(int repid)
-{
-	return delete_tcp_fd(tmax_tcp_cepid + repid);
-}
-
-unsigned char tcp_buf[tcp_cepid_table_count][2 * 512];
-
-unsigned char *id_to_buff(ID id)
-{
-	for (int i = 0; i < tcp_cepid_table_count; i++) {
-		id_table_t *item = &tcp_cepid_table[i];
-		if ((item->used == 0) || (item->id != id))
-			continue;
-
-		return tcp_buf[i];
-	}
-
-	return NULL;
-}
-
-typedef struct _IO_FILE SOCKET;
+typedef struct SHELL_FILE SOCKET;
 
 int shell_socket(int family, int type, int protocol)
@@ -148,8 +316,18 @@
 	switch (type) {
 	case SOCK_STREAM:
-		fp = new_tcp_fd(0);
+		fp = new_fp(&IO_TYPE_TCP, 0, 0);
+		if (fp == NULL)
+			return -ENOMEM;
+
+		fp->exinf = malloc(sizeof(socket_t));
+		memset(fp->exinf, 0, sizeof(socket_t));
 		break;
 	case SOCK_DGRAM:
-		fp = new_udp_fd(0);
+		fp = new_fp(&IO_TYPE_UDP, 0, 1);
+		if (fp == NULL)
+			return -ENOMEM;
+
+		fp->exinf = malloc(sizeof(socket_t));
+		memset(fp->exinf, 0, sizeof(socket_t));
 		break;
 	default:
@@ -157,12 +335,9 @@
 	}
 
-	if (fp == NULL) {
-		return -ENOMEM;
-	}
-
-	fp->socket.family = family;
-	fp->socket.type = type;
-	fp->socket.protocol = protocol;
-	fp->socket.flags = flags;
+	socket_t *socket = (socket_t *)fp->exinf;
+	socket->family = family;
+	socket->type = type;
+	socket->protocol = protocol;
+	socket->flags = flags;
 
 	return fp->fd;
@@ -174,5 +349,6 @@
 	if (fp == NULL)
 		return -EBADF;
-	if (fp->socket.family != addr->sa_family)
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->family != addr->sa_family)
 		return -EINVAL;
 
@@ -184,6 +360,6 @@
 		}
 		struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
-		memcpy(&fp->socket.laddr4, addr, len);
-		switch (fp->socket.type) {
+		memcpy(&socket->laddr4, addr, len);
+		switch (socket->type) {
 		case SOCK_STREAM: {
 			ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
@@ -191,14 +367,20 @@
 				return -ENOMEM;
 
-			fp->socket.buf_size = 512 + 512;
-			fp->socket.buf = id_to_buff(cepid);
-			T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, (FP)socket_tcp_callback };
+			socket->buf_size = TCP_SOCKET_BUF_SIZE + TCP_SOCKET_BUF_SIZE;
+			socket->buf = malloc(socket->buf_size);
+#ifdef _DEBUG
+			memset(socket->buf, 0, socket->buf_size);
+#endif
+			T_TCP_CCEP ccep = { 0, socket->buf, TCP_SOCKET_BUF_SIZE, &socket->buf[TCP_SOCKET_BUF_SIZE], TCP_SOCKET_BUF_SIZE, (FP)socket_tcp_callback };
 			ret = tcp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
+				free(socket->buf);
+				socket->buf = NULL;
+				socket->buf_size = 0;
 				delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
 				return -ENOMEM;
 			}
 			fp->handle = cepid;
-			fp->socket.cepid = cepid;
+			socket->cepid = cepid;
 			break;
 		}
@@ -215,5 +397,5 @@
 			}
 			fp->handle = cepid;
-			fp->socket.cepid = cepid;
+			socket->cepid = cepid;
 			break;
 		}
@@ -227,7 +409,52 @@
 			return -EINVAL;
 		}
-		memcpy(&fp->socket.laddr4, addr, len);
-		break;
-	}
+		struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)addr;
+		memcpy(&socket->laddr6, addr, len);
+		switch (socket->type) {
+		case SOCK_STREAM: {
+			ID cepid = new_id(tcp6_cepid_table, tcp6_cepid_table_count);
+			if (cepid < 0)
+				return -ENOMEM;
+
+			socket->buf_size = TCP_SOCKET_BUF_SIZE + TCP_SOCKET_BUF_SIZE;
+			socket->buf = malloc(socket->buf_size);
+#ifdef _DEBUG
+			memset(socket->buf, 0, socket->buf_size);
+#endif
+			T_TCP6_CCEP ccep = { 0, socket->buf, TCP_SOCKET_BUF_SIZE, &socket->buf[TCP_SOCKET_BUF_SIZE], TCP_SOCKET_BUF_SIZE, (FP)socket_tcp6_callback };
+			ret = tcp6_cre_cep(cepid, &ccep);
+			if (ret != E_OK) {
+				free(socket->buf);
+				socket->buf = NULL;
+				socket->buf_size = 0;
+				delete_id(tcp6_cepid_table, tcp6_cepid_table_count, cepid);
+				return -ENOMEM;
+			}
+			fp->handle = cepid;
+			socket->cepid = cepid;
+			break;
+		}
+		case SOCK_DGRAM: {
+			ID cepid = new_id(udp6_cepid_table, udp6_cepid_table_count);
+			if (cepid < 0)
+				return -ENOMEM;
+
+			T_UDP6_CCEP ccep = { 0, { { ntohl(addr_in6->sin6_addr.__in6_union.__s6_addr) }, ntohs(addr_in6->sin6_port)}, (FP)socket_udp6_callback };
+			ret = udp6_cre_cep(cepid, &ccep);
+			if (ret != E_OK) {
+				delete_id(udp6_cepid_table, udp6_cepid_table_count, cepid);
+				return -ENOMEM;
+			}
+			fp->handle = cepid;
+			socket->cepid = cepid;
+			break;
+		}
+		default:
+			return -ENOPROTOOPT;
+		}
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
 	}
 
@@ -240,11 +467,12 @@
 	if (fp == NULL)
 		return -EBADF;
-	if (fp->socket.type != SOCK_STREAM)
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->type != SOCK_STREAM)
 		return -EINVAL;
 
-	fp->socket.backlog = backlog;
+	socket->backlog = backlog;
 
 	ER ret;
-	switch (fp->socket.family) {
+	switch (socket->family) {
 	case AF_INET: {
 		ID repid = new_id(tcp_repid_table, tcp_repid_table_count);
@@ -252,5 +480,5 @@
 			return -ENOMEM;
 
-		struct sockaddr_in *laddr = &fp->socket.laddr4;
+		struct sockaddr_in *laddr = &socket->laddr4;
 		T_TCP_CREP crep = { 0, {ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port)} };
 		ret = tcp_cre_rep(repid, &crep);
@@ -259,10 +487,24 @@
 			return -ENOMEM;
 		}
-		fp->socket.repid = repid;
+		socket->repid = repid;
 		break;
 	}
 	case AF_INET6: {
-		break;
-	}
+		ID repid = new_id(tcp6_repid_table, tcp6_repid_table_count);
+		if (repid < 0)
+			return -ENOMEM;
+
+		struct sockaddr_in6 *laddr = &socket->laddr6;
+		T_TCP6_CREP crep = { 0, { { ntohl(laddr->sin6_addr.__in6_union.__s6_addr) }, ntohs(laddr->sin6_port)} };
+		ret = tcp6_cre_rep(repid, &crep);
+		if (ret != E_OK) {
+			delete_id(tcp6_repid_table, tcp6_repid_table_count, repid);
+			return -ENOMEM;
+		}
+		socket->repid = repid;
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
 	}
 
@@ -270,42 +512,52 @@
 }
 
-int shell_connect(int fd, const struct sockaddr *addr, socklen_t len)
+int shell_connect(int fd, const struct sockaddr *addr, socklen_t alen)
 {
 	SOCKET *fp = fd_to_fp(fd);
 	if (fp == NULL)
 		return -EBADF;
-	if (fp->socket.type != SOCK_STREAM)
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->type != SOCK_STREAM)
 		return -EINVAL;
 
 	ER ret;
-	switch (fp->socket.family) {
+	switch (socket->family) {
 	case AF_INET: {
-		if (len < 8) {
+		if (alen < sizeof(struct sockaddr_in)) {
 			return -EINVAL;
 		}
-		if (fp->socket.cepid == 0) {
+		if (socket->cepid == 0) {
 			ID cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
 			if (cepid < 0)
 				return -ENOMEM;
 
-			fp->socket.buf_size = 512 + 512;
-			fp->socket.buf = id_to_buff(cepid);
-			T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, (FP)socket_tcp_callback };
+			socket->buf_size = TCP_SOCKET_BUF_SIZE + TCP_SOCKET_BUF_SIZE;
+			socket->buf = malloc(socket->buf_size);
+#ifdef _DEBUG
+			memset(socket->buf, 0, socket->buf_size);
+#endif
+			T_TCP_CCEP ccep = { 0, socket->buf, TCP_SOCKET_BUF_SIZE, &socket->buf[TCP_SOCKET_BUF_SIZE], TCP_SOCKET_BUF_SIZE, (FP)socket_tcp_callback };
 			ret = tcp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
+				free(socket->buf);
+				socket->buf = NULL;
+				socket->buf_size = 0;
 				delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
 				return -ENOMEM;
 			}
 			fp->handle = cepid;
-			fp->socket.cepid = cepid;
-		}
-		struct sockaddr_in *laddr = &fp->socket.laddr4;
-		struct sockaddr_in *raddr = &fp->socket.raddr4;
-		memset(raddr, 0, sizeof(*raddr));
-		memcpy(raddr, addr, len);
+			fp->writable = 1;
+			socket->cepid = cepid;
+		}
+		struct sockaddr_in *laddr = &socket->laddr4;
+		struct sockaddr_in *raddr = &socket->raddr4;
+		memcpy(raddr, addr, sizeof(struct sockaddr_in));
 		T_IPV4EP lep = { ntohl(laddr->sin_addr.s_addr), ntohs(laddr->sin_port) };
 		T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
-		ret = tcp_con_cep(fp->socket.cepid, &lep, &rep, SOCKET_TIMEOUT);
-		if (ret < 0) {
+		ret = tcp_con_cep(socket->cepid, &lep, &rep, SOCKET_TIMEOUT);
+		if (ret == E_TMOUT) {
+			return -ETIMEDOUT;
+		}
+		else if (ret < 0) {
 			return -EHOSTUNREACH;
 		}
@@ -313,86 +565,201 @@
 	}
 	case AF_INET6: {
-		break;
-	}
-	}
+		if (alen < sizeof(struct sockaddr_in6)) {
+			return -EINVAL;
+		}
+		if (socket->cepid == 0) {
+			ID cepid = new_id(tcp6_cepid_table, tcp6_cepid_table_count);
+			if (cepid < 0)
+				return -ENOMEM;
+
+			socket->buf_size = TCP_SOCKET_BUF_SIZE + TCP_SOCKET_BUF_SIZE;
+			socket->buf = malloc(socket->buf_size);
+#ifdef _DEBUG
+			memset(socket->buf, 0, socket->buf_size);
+#endif
+			T_TCP6_CCEP ccep = { 0, socket->buf, TCP_SOCKET_BUF_SIZE, &socket->buf[TCP_SOCKET_BUF_SIZE], TCP_SOCKET_BUF_SIZE, (FP)socket_tcp6_callback };
+			ret = tcp6_cre_cep(cepid, &ccep);
+			if (ret != E_OK) {
+				free(socket->buf);
+				socket->buf = NULL;
+				socket->buf_size = 0;
+				delete_id(tcp6_cepid_table, tcp6_cepid_table_count, cepid);
+				return -ENOMEM;
+			}
+			fp->handle = cepid;
+			fp->writable = 1;
+			socket->cepid = cepid;
+		}
+		struct sockaddr_in6 *laddr = &socket->laddr6;
+		struct sockaddr_in6 *raddr = &socket->raddr6;
+		memcpy(raddr, addr, sizeof(struct sockaddr_in6));
+		T_IPV6EP lep;
+		addrcpy(&lep.ipaddr, &laddr->sin6_addr, 16);
+		lep.portno = ntohs(laddr->sin6_port);
+		T_IPV6EP rep;
+		addrcpy(&rep.ipaddr, &raddr->sin6_addr, 16);
+		rep.portno = ntohs(raddr->sin6_port);
+		ret = tcp6_con_cep(socket->cepid, &lep, &rep, SOCKET_TIMEOUT);
+		if (ret == E_TMOUT) {
+			return -ETIMEDOUT;
+		}
+		else if (ret < 0) {
+			return -EHOSTUNREACH;
+		}
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
+	}
+
+	if (fp->writeevt_w != fp->writeevt_r) fp->writeevt_r++;
 
 	return 0;
 }
 
-int shell_accept(int fd, struct sockaddr *__restrict addr, socklen_t *__restrict len)
+int shell_accept(int fd, struct sockaddr *restrict addr, socklen_t *restrict alen)
 {
 	SOCKET *lfp = fd_to_fp(fd);
 	if (lfp == NULL)
 		return -EBADF;
-	if (lfp->socket.type != SOCK_STREAM)
+	if (((socket_t *)lfp->exinf)->type != SOCK_STREAM)
 		return -EINVAL;
 
-	SOCKET *fp = new_tcp_fd(0);
-	if (fp == NULL) {
+	SOCKET *fp = new_fp(&IO_TYPE_TCP, 0, 0);
+	if (fp == NULL)
 		return -ENOMEM;
-	}
-
-	memcpy(&fp->socket, &lfp->socket, sizeof(fp->socket));
+
+	fp->exinf = malloc(sizeof(socket_t));
+	memset(fp->exinf, 0, sizeof(socket_t));
+
+	memcpy(fp->exinf, lfp->exinf, offsetof(socket_t, buf_size));
 
 	ER ret;
-	switch (fp->socket.family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
 		ID cepid;
-		if (fp->socket.cepid == 0) {
+		if (socket->cepid == 0) {
 			cepid = new_id(tcp_cepid_table, tcp_cepid_table_count);
 			if (cepid < 0)
 				return -ENOMEM;
 
-			fp->socket.buf_size = 512 + 512;
-			fp->socket.buf = id_to_buff(cepid);
-			T_TCP_CCEP ccep = { 0, fp->socket.buf, 512, &fp->socket.buf[512], 512, (FP)socket_tcp_callback };
+			socket->buf_size = TCP_SOCKET_BUF_SIZE + TCP_SOCKET_BUF_SIZE;
+			socket->buf = malloc(socket->buf_size);
+#ifdef _DEBUG
+			memset(socket->buf, 0, socket->buf_size);
+#endif
+			T_TCP_CCEP ccep = { 0, socket->buf, TCP_SOCKET_BUF_SIZE, &socket->buf[TCP_SOCKET_BUF_SIZE], TCP_SOCKET_BUF_SIZE, (FP)socket_tcp_callback };
 			ret = tcp_cre_cep(cepid, &ccep);
 			if (ret != E_OK) {
+				free(socket->buf);
+				socket->buf = NULL;
+				socket->buf_size = 0;
 				delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
 				return -ENOMEM;
 			}
 			fp->handle = cepid;
-			fp->socket.cepid = cepid;
+			fp->writable = 1;
+			socket->cepid = cepid;
 		}
 		else {
-			cepid = lfp->socket.cepid;
-			lfp->handle = tmax_tcp_cepid + lfp->socket.repid;
-			lfp->socket.cepid = 0;
-			lfp->socket.buf_size = 0;
-			lfp->socket.buf = 0;
+			cepid = ((socket_t *)lfp->exinf)->cepid;
+			fp->handle = cepid;
+			fp->writable = 1;
+			lfp->handle = tmax_tcp_cepid + ((socket_t *)lfp->exinf)->repid;
+			((socket_t *)lfp->exinf)->cepid = 0;
+			((socket_t *)lfp->exinf)->buf_size = 0;
+			((socket_t *)lfp->exinf)->buf = 0;
 		}
 		T_IPV4EP rep = { 0, 0 };
-		ret = tcp_acp_cep(fp->socket.cepid, fp->socket.repid, &rep, TMO_FEVR);
+		ret = tcp_acp_cep(socket->cepid, socket->repid, &rep, TMO_FEVR);
 		if (ret < 0) {
 			return -ENOMEM;
 		}
-		struct sockaddr_in *raddr = &fp->socket.raddr4;
-		memset(raddr, 0, sizeof(*raddr));
+		struct sockaddr_in *raddr = &socket->raddr4;
+		memset(raddr, 0, sizeof(struct sockaddr_in));
 		raddr->sin_family = AF_INET;
 		raddr->sin_port = htons(rep.portno);
 		raddr->sin_addr.s_addr = htonl(rep.ipaddr);
+
+		if (addr != NULL && alen != NULL) {
+			int sz = *alen;
+			if (sz < sizeof(struct sockaddr_in)) {
+				return -EINVAL;
+			}
+			if (sz > sizeof(struct sockaddr_in))
+				sz = sizeof(struct sockaddr_in);
+			memcpy(addr, raddr, sz);
+			*alen = sz;
+		}
 		break;
 	}
 	case AF_INET6: {
-		return -EAFNOSUPPORT;
-	}
-	}
-
-	if (addr != NULL && len != NULL) {
-		int sz = *len;
-		if (sz < 8) {
-			return -EINVAL;
-		}
-		struct sockaddr_in *raddr = &fp->socket.raddr4;
-		if (sz > sizeof(*raddr))
-			sz = sizeof(*raddr);
-		memcpy(addr, raddr, sz);
-		*len = sizeof(*raddr);
-	}
+		ID cepid;
+		if (socket->cepid == 0) {
+			cepid = new_id(tcp6_cepid_table, tcp6_cepid_table_count);
+			if (cepid < 0)
+				return -ENOMEM;
+
+			socket->buf_size = TCP_SOCKET_BUF_SIZE + TCP_SOCKET_BUF_SIZE;
+			socket->buf = malloc(socket->buf_size);
+#ifdef _DEBUG
+			memset(socket->buf, 0, socket->buf_size);
+#endif
+			T_TCP6_CCEP ccep = { 0, socket->buf, TCP_SOCKET_BUF_SIZE, &socket->buf[TCP_SOCKET_BUF_SIZE], TCP_SOCKET_BUF_SIZE, (FP)socket_tcp6_callback };
+			ret = tcp6_cre_cep(cepid, &ccep);
+			if (ret != E_OK) {
+				free(socket->buf);
+				socket->buf = NULL;
+				socket->buf_size = 0;
+				delete_id(tcp6_cepid_table, tcp6_cepid_table_count, cepid);
+				return -ENOMEM;
+			}
+			fp->handle = cepid;
+			fp->writable = 1;
+			socket->cepid = cepid;
+		}
+		else {
+			cepid = ((socket_t *)lfp->exinf)->cepid;
+			fp->handle = cepid;
+			fp->writable = 1;
+			lfp->handle = tmax_tcp6_cepid + ((socket_t *)lfp->exinf)->repid;
+			((socket_t *)lfp->exinf)->cepid = 0;
+			((socket_t *)lfp->exinf)->buf_size = 0;
+			((socket_t *)lfp->exinf)->buf = 0;
+		}
+		T_IPV6EP rep = { { 0 }, 0 };
+		ret = tcp6_acp_cep(socket->cepid, socket->repid, &rep, TMO_FEVR);
+		if (ret < 0) {
+			return -ENOMEM;
+		}
+		struct sockaddr_in6 *raddr = &socket->raddr6;
+		memset(raddr, 0, sizeof(struct sockaddr_in6));
+		raddr->sin6_family = AF_INET;
+		raddr->sin6_port = htons(rep.portno);
+		addrcpy(&raddr->sin6_addr, &rep.ipaddr, 16);
+
+		if (addr != NULL && alen != NULL) {
+			int sz = *alen;
+			if (sz < sizeof(struct sockaddr_in6)) {
+				return -EINVAL;
+			}
+			if (sz > sizeof(struct sockaddr_in6))
+				sz = sizeof(struct sockaddr_in6);
+			memcpy(addr, raddr, sz);
+			*alen = sz;
+		}
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
+	}
+
+	if (fp->writeevt_w != fp->writeevt_r) fp->writeevt_r++;
 
 	return fp->fd;
 }
 
-ssize_t shell_send(int fd, const void *buf, size_t len, int flags)
+ssize_t shell_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
 {
 	SOCKET *fp = fd_to_fp(fd);
@@ -402,10 +769,15 @@
 
 	int ret = 0;
-	switch (fp->socket.family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->socket.type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
+			if ((addr != NULL) || (alen != 0)) {
+				return -EISCONN;
+			}
+
 			if (flags & MSG_OOB) {
-				ret = tcp_snd_oob(fp->socket.cepid, (void *)buf, len, SOCKET_TIMEOUT);
+				ret = tcp_snd_oob(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
 				if (ret < 0) {
 					return -ECOMM;
@@ -413,26 +785,100 @@
 			}
 			else {
-				ret = tcp_snd_dat(fp->socket.cepid, (void *)buf, len, SOCKET_TIMEOUT);
+				int temp = len;
+				for (;;) {
+					ret = tcp_snd_dat(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
+					if (ret < 0) {
+						return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
+					}
+					len -= ret;
+					if (len <= 0)
+						break;
+					buf = (const void *)&((uint8_t *)buf)[ret];
+				} 
+				ret = temp;
+			}
+			break;
+		}
+		case SOCK_DGRAM: {
+			if ((addr == NULL) || (alen < sizeof(struct sockaddr_in))) {
+				return -EINVAL;
+			}
+			struct sockaddr_in *raddr = &socket->raddr4;
+			memcpy(raddr, addr, sizeof(struct sockaddr_in));
+			T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
+			ret = udp_snd_dat(socket->cepid, &rep, (void *)buf, len,
+				(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
+			if (ret < 0) {
+				return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
+			}
+			break;
+		}
+		}
+		break;
+	}
+	case AF_INET6: {
+		switch (socket->type) {
+		case SOCK_STREAM: {
+			if ((addr != NULL) || (alen != 0)) {
+				return -EISCONN;
+			}
+
+			if (flags & MSG_OOB) {
+				ret = tcp6_snd_oob(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
 				if (ret < 0) {
 					return -ECOMM;
 				}
 			}
+			else {
+				int temp = len;
+				for (;;) {
+					ret = tcp6_snd_dat(socket->cepid, (void *)buf, len, SOCKET_TIMEOUT);
+					if (ret < 0) {
+						return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
+					}
+					len -= ret;
+					if (len <= 0)
+						break;
+					buf = (const void *)&((uint8_t *)buf)[ret];
+				}
+				ret = temp;
+			}
 			break;
 		}
 		case SOCK_DGRAM: {
-			return -EINVAL;
-		}
-		}
-		break;
-	}
-	case AF_INET6: {
-		return -EAFNOSUPPORT;
-	}
-	}
+			if ((addr == NULL) || (alen < sizeof(struct sockaddr_in6))) {
+				return -EINVAL;
+			}
+			struct sockaddr_in6 *raddr = &socket->raddr6;
+			memcpy(raddr, addr, sizeof(struct sockaddr_in6));
+			T_IPV6EP rep;
+			addrcpy(&rep.ipaddr, &raddr->sin6_addr, 16);
+			rep.portno = ntohs(raddr->sin6_port);
+			ret = udp6_snd_dat(socket->cepid, &rep, (void *)buf, len,
+				(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
+			if (ret < 0) {
+				return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
+			}
+			break;
+		}
+		}
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
+	}
+
+	if (fp->writeevt_w != fp->writeevt_r) fp->writeevt_r++;
 
 	return ret;
 }
 
-ssize_t shell_sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
+ssize_t shell_sendmsg(int fd, const struct msghdr *msg, int flags)
+{
+	no_implement("sendmsg\n");
+	return -ENOSYS;
+}
+
+ssize_t shell_recvfrom(int fd, void *restrict buf, size_t len, int flags, struct sockaddr *restrict addr, socklen_t *restrict alen)
 {
 	SOCKET *fp = fd_to_fp(fd);
@@ -442,60 +888,297 @@
 
 	int ret = 0;
-	switch (fp->socket.family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->socket.type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
-			if ((addr != NULL) && (alen != 0)) {
-				return -EINVAL;
-			}
-
 			if (flags & MSG_OOB) {
-				ret = tcp_snd_oob(fp->socket.cepid, (void *)buf, len, SOCKET_TIMEOUT);
+				ret = tcp_rcv_oob(socket->cepid, buf, len);
 				if (ret < 0) {
+					syslog(LOG_ERROR, "tcp_rcv_oob => %d", ret);
 					return -ECOMM;
 				}
 			}
 			else {
-				ret = tcp_snd_dat(fp->socket.cepid, (void *)buf, len, SOCKET_TIMEOUT);
+				int rsz, tmp;
+				if (socket->input == NULL) {
+					ret = wai_sem(SEM_FILEDESC);
+					if (ret < 0) {
+						syslog(LOG_ERROR, "wai_sem => %d", ret);
+					}
+					socket->len = 0;
+					ret = sig_sem(SEM_FILEDESC);
+					if (ret < 0) {
+						syslog(LOG_ERROR, "sig_sem => %d", ret);
+					}
+					ret = tcp_rcv_buf(socket->cepid, &socket->input,
+						(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
+					if (ret < 0) {
+						if ((socket->flags & O_NONBLOCK) == 0)
+							syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
+						return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
+					}
+					rsz = ret;
+				}
+				else
+					rsz = socket->len;
+				tmp = rsz;
+				if (rsz > len)
+					rsz = len;
+				if (rsz > 0) {
+					memcpy(buf, socket->input, rsz);
+					ret = wai_sem(SEM_FILEDESC);
+					if (ret < 0) {
+						syslog(LOG_ERROR, "wai_sem => %d", ret);
+					}
+					socket->len = tmp - rsz;
+					ret = sig_sem(SEM_FILEDESC);
+					if (ret < 0) {
+						syslog(LOG_ERROR, "sig_sem => %d", ret);
+					}
+					if (tmp - rsz == 0) {
+						socket->input = NULL;
+					}
+					else
+						socket->input = (void *)&((uint8_t *)socket->input)[rsz];
+					ret = tcp_rel_buf(socket->cepid, rsz);
+					if ((ret != E_OBJ) && (ret < 0)) {
+						syslog(LOG_ERROR, "tcp_rel_buf => %d", ret);
+						//return -ECOMM;
+					}
+				}
+				else {
+					syslog(LOG_ERROR, "shell_recvfrom => %d", rsz);
+				}
+				ret = rsz;
+			}
+			break;
+		}
+		case SOCK_DGRAM: {
+			struct sockaddr_in *raddr = &socket->raddr4;
+			int rsz;
+			ret = wai_sem(SEM_FILEDESC);
+			if (ret < 0) {
+				syslog(LOG_ERROR, "wai_sem => %d", ret);
+			}
+			T_NET_BUF *input = socket->input;
+			if (input == NULL) {
+				ret = sig_sem(SEM_FILEDESC);
 				if (ret < 0) {
+					syslog(LOG_ERROR, "sig_sem => %d", ret);
+				}
+
+				T_IPV4EP rep = { 0, 0 };
+				ret = udp_rcv_dat(socket->cepid, &rep, buf, len,
+					(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
+				if (ret < 0) {
+					if ((socket->flags & O_NONBLOCK) == 0)
+						syslog(LOG_ERROR, "udp_rcv_buf => %d", ret);
+					return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
+				}
+				rsz = ret;
+				if ((addr != NULL) && (alen != NULL)) {
+					ret = wai_sem(SEM_FILEDESC);
+					if (ret < 0) {
+						syslog(LOG_ERROR, "wai_sem => %d", ret);
+					}
+					int sz = *alen;
+					memset(raddr, 0, sizeof(struct sockaddr_in));
+					raddr->sin_family = AF_INET;
+					raddr->sin_port = htons(rep.portno);
+					raddr->sin_addr.s_addr = htonl(rep.ipaddr);
+					if (sz > sizeof(struct sockaddr_in))
+						sz = sizeof(struct sockaddr_in);
+					memcpy(addr, raddr, sz);
+					*alen = sz;
+					ret = sig_sem(SEM_FILEDESC);
+					if (ret < 0) {
+						syslog(LOG_ERROR, "sig_sem => %d", ret);
+					}
+				}
+			}
+			else {
+				rsz = socket->len;
+				void *pbuf = socket->buf;
+				socket->input = NULL;
+				socket->len = 0;
+				socket->buf = NULL;
+				if ((addr != NULL) && (alen != NULL)) {
+					int sz = *alen;
+					if (sz > sizeof(struct sockaddr_in))
+						sz = sizeof(struct sockaddr_in);
+					memcpy(addr, raddr, sz);
+					*alen = sz;
+				}
+				ret = sig_sem(SEM_FILEDESC);
+				if (ret < 0) {
+					syslog(LOG_ERROR, "sig_sem => %d", ret);
+				}
+				if (rsz > len)
+					rsz = len;
+				memcpy(buf, pbuf, rsz);
+				ret = rel_net_buf(input);
+				if (ret < 0) {
+					syslog(LOG_ERROR, "rel_net_buf => %d", ret);
+					//return -ECOMM;
+				}
+			}
+			ret = rsz;
+		}
+		}
+		break;
+	}
+	case AF_INET6: {
+		switch (socket->type) {
+		case SOCK_STREAM: {
+			if (flags & MSG_OOB) {
+				ret = tcp6_rcv_oob(socket->cepid, buf, len);
+				if (ret < 0) {
+					syslog(LOG_ERROR, "tcp6_rcv_oob => %d", ret);
 					return -ECOMM;
 				}
 			}
+			else {
+				int rsz, tmp;
+				if (socket->input == NULL) {
+					ret = wai_sem(SEM_FILEDESC);
+					if (ret < 0) {
+						syslog(LOG_ERROR, "wai_sem => %d", ret);
+					}
+					socket->len = 0;
+					ret = sig_sem(SEM_FILEDESC);
+					if (ret < 0) {
+						syslog(LOG_ERROR, "sig_sem => %d", ret);
+					}
+					ret = tcp6_rcv_buf(socket->cepid, &socket->input,
+						(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
+					if (ret < 0) {
+						if ((socket->flags & O_NONBLOCK) == 0)
+							syslog(LOG_ERROR, "tcp6_rcv_buf => %d", ret);
+						return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
+					}
+					rsz = ret;
+				}
+				else
+					rsz = socket->len;
+				tmp = rsz;
+				if (rsz > len)
+					rsz = len;
+				if (rsz >= 0) {
+					memcpy(buf, socket->input, rsz);
+					ret = wai_sem(SEM_FILEDESC);
+					if (ret < 0) {
+						syslog(LOG_ERROR, "wai_sem => %d", ret);
+					}
+					socket->len = tmp - rsz;
+					ret = sig_sem(SEM_FILEDESC);
+					if (ret < 0) {
+						syslog(LOG_ERROR, "sig_sem => %d", ret);
+					}
+					if (tmp - rsz == 0) {
+						socket->input = NULL;
+					}
+					else
+						socket->input = (void *)&((uint8_t *)socket->input)[rsz];
+					ret = tcp6_rel_buf(socket->cepid, rsz);
+					if ((ret != E_OBJ) && (ret < 0)) {
+						syslog(LOG_ERROR, "tcp6_rel_buf => %d", ret);
+						//return -ECOMM;
+					}
+				}
+				ret = rsz;
+			}
 			break;
 		}
 		case SOCK_DGRAM: {
-			int sz = alen;
-			if (sz < 8) {
-				return -EINVAL;
-			}
-			struct sockaddr_in *raddr = &fp->socket.raddr4;
-			memset(raddr, 0, sizeof(*raddr));
-			memcpy(raddr, addr, sz);
-			T_IPV4EP rep = { ntohl(raddr->sin_addr.s_addr), ntohs(raddr->sin_port) };
-			ret = udp_snd_dat(fp->socket.cepid, &rep, (void *)buf, len,
-				(fp->socket.flags & O_NONBLOCK) ? 0 : SOCKET_TIMEOUT);
+			struct sockaddr_in6 *raddr = &socket->raddr6;
+			int rsz;
+			ret = wai_sem(SEM_FILEDESC);
 			if (ret < 0) {
-				return -ECOMM;
-			}
-			break;
-		}
-		}
-		break;
-	}
-	case AF_INET6: {
-		return -EAFNOSUPPORT;
-	}
-	}
+				syslog(LOG_ERROR, "wai_sem => %d", ret);
+			}
+			T_NET_BUF *input = socket->input;
+			if (input == NULL) {
+				ret = sig_sem(SEM_FILEDESC);
+				if (ret < 0) {
+					syslog(LOG_ERROR, "sig_sem => %d", ret);
+				}
+
+				T_IPV6EP rep = { { 0 }, 0 };
+				ret = udp6_rcv_dat(socket->cepid, &rep, buf, len,
+					(socket->flags & O_NONBLOCK) ? TMO_POL : SOCKET_TIMEOUT);
+				if (ret < 0) {
+					if ((socket->flags & O_NONBLOCK) == 0)
+						syslog(LOG_ERROR, "udp6_rcv_buf => %d", ret);
+					return (ret == E_TMOUT) ? -EAGAIN : -ECOMM;
+				}
+				rsz = ret;
+				if ((addr != NULL) && (alen != NULL)) {
+					ret = wai_sem(SEM_FILEDESC);
+					if (ret < 0) {
+						syslog(LOG_ERROR, "wai_sem => %d", ret);
+					}
+					int sz = *alen;
+					memset(raddr, 0, sizeof(struct sockaddr_in6));
+					raddr->sin6_family = AF_INET;
+					raddr->sin6_port = htons(rep.portno);
+					addrcpy(&raddr->sin6_addr, &rep.ipaddr, 16);
+					if (sz > sizeof(struct sockaddr_in6))
+						sz = sizeof(struct sockaddr_in6);
+					memcpy(addr, raddr, sz);
+					*alen = sz;
+					ret = sig_sem(SEM_FILEDESC);
+					if (ret < 0) {
+						syslog(LOG_ERROR, "sig_sem => %d", ret);
+					}
+				}
+			}
+			else {
+				rsz = socket->len;
+				void *pbuf = socket->buf;
+				socket->input = NULL;
+				socket->len = 0;
+				socket->buf = NULL;
+				if ((addr != NULL) && (alen != NULL)) {
+					int sz = *alen;
+					if (sz > sizeof(struct sockaddr_in6))
+						sz = sizeof(struct sockaddr_in6);
+					memcpy(addr, raddr, sz);
+					*alen = sz;
+				}
+				ret = sig_sem(SEM_FILEDESC);
+				if (ret < 0) {
+					syslog(LOG_ERROR, "sig_sem => %d", ret);
+				}
+				if (rsz > len)
+					rsz = len;
+				memcpy(buf, pbuf, rsz);
+				ret = rel_net_buf(input);
+				if (ret < 0) {
+					syslog(LOG_ERROR, "rel_net_buf => %d", ret);
+					//return -ECOMM;
+				}
+			}
+			ret = rsz;
+		}
+		}
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
+	}
+
+	if (fp->readevt_w != fp->readevt_r) fp->readevt_r++;
 
 	return ret;
 }
 
-ssize_t shell_sendmsg(int fd, const struct msghdr *msg, int flags)
-{
-	no_implement("sendmsg\n");
+ssize_t shell_recvmsg(int fd, struct msghdr *msg, int flags)
+{
+	no_implement("recvmsg\n");
 	return -ENOSYS;
 }
 
-ssize_t shell_recv(int fd, void *buf, size_t len, int flags)
+int shell_shutdown(int fd, int how)
 {
 	SOCKET *fp = fd_to_fp(fd);
@@ -504,29 +1187,15 @@
 	}
 
-	int ret = 0;
-	switch (fp->socket.family) {
+	ER ret;
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->socket.type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
-			if (flags & MSG_OOB) {
-				ret = tcp_rcv_oob(fp->socket.cepid, buf, len);
-				if (ret < 0) {
-					return -ECOMM;
-				}
-			}
-			else {
-				ret = tcp_rcv_dat(fp->socket.cepid, buf, len, TMO_FEVR);
-				if (ret < 0) {
-					return -ECOMM;
-				}
-			}
-			break;
-		}
-		case SOCK_DGRAM: {
-			T_IPV4EP rep = { 0, 0 };
-			ret = udp_rcv_dat(fp->socket.cepid, &rep, buf, len, (fp->socket.flags & O_NONBLOCK) ? 0 : TMO_FEVR);
+			ret = tcp_sht_cep(socket->cepid);
 			if (ret < 0) {
 				return -ECOMM;
 			}
+			break;
 		}
 		}
@@ -534,12 +1203,23 @@
 	}
 	case AF_INET6: {
-		return -EAFNOSUPPORT;
-	}
-	}
-
-	return ret;
-}
-
-ssize_t shell_recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *__restrict addr, socklen_t *__restrict alen)
+		switch (socket->type) {
+		case SOCK_STREAM: {
+			ret = tcp6_sht_cep(socket->cepid);
+			if (ret < 0) {
+				return -ECOMM;
+			}
+			break;
+		}
+		}
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
+	}
+
+	return 0;
+}
+
+int shell_getsockopt(int fd, int level, int optname, void *optval, socklen_t *restrict optlen)
 {
 	SOCKET *fp = fd_to_fp(fd);
@@ -548,57 +1228,131 @@
 	}
 
-	int ret = 0;
-	switch (fp->socket.family) {
+	ER ret;
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->socket.type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
-			if (flags & MSG_OOB) {
-				ret = tcp_rcv_oob(fp->socket.cepid, buf, len);
+			switch (level) {
+			case SOL_SOCKET:
+				switch (optname) {
+				case SO_REUSEADDR:
+					if (socket->flags & SO_REUSEADDR) {
+						*(bool *)optval = true;
+					}
+					else {
+						*(bool *)optval = false;
+					}
+					break;
+				case SO_KEEPALIVE:
+					if (socket->flags & SO_KEEPALIVE) {
+						*(bool *)optval = true;
+					}
+					else {
+						*(bool *)optval = false;
+					}
+					break;
+				case SO_ERROR:
+					*(int *)optval = 0;
+					break;
+				default:
+					return -EINVAL;
+				}
+				break;
+			case IPPROTO_TCP:
+				ret = tcp_get_opt(socket->cepid, optname, (void *)optval, *optlen);
 				if (ret < 0) {
-					return -ECOMM;
-				}
-			}
-			else {
-				ret = tcp_rcv_dat(fp->socket.cepid, buf, len, TMO_FEVR);
+					return -EINVAL;
+				}
+				*optlen = ret;
+				break;
+			default:
+				return -EINVAL;
+			}
+			break;
+		}
+		case SOCK_DGRAM: {
+			switch (level) {
+			case IPPROTO_UDP:
+				ret = udp_get_opt(socket->cepid, optname, (void *)optval, *optlen);
 				if (ret < 0) {
-					return -ECOMM;
-				}
+					return -EINVAL;
+				}
+				*optlen = ret;
+				break;
+			default:
+				return -EINVAL;
 			}
 			break;
 		}
+		}
+		break;
+	}
+	case AF_INET6: {
+		switch (socket->type) {
+		case SOCK_STREAM: {
+			switch (level) {
+			case SOL_SOCKET:
+				switch (optname) {
+				case SO_REUSEADDR:
+					if (socket->flags & SO_REUSEADDR) {
+						*(bool *)optval = true;
+					}
+					else {
+						*(bool *)optval = false;
+					}
+					break;
+				case SO_KEEPALIVE:
+					if (socket->flags & SO_KEEPALIVE) {
+						*(bool *)optval = true;
+					}
+					else {
+						*(bool *)optval = false;
+					}
+					break;
+				case SO_ERROR:
+					*(int *)optval = 0;
+					break;
+				default:
+					return -EINVAL;
+				}
+				break;
+			case IPPROTO_TCP:
+				ret = tcp6_get_opt(socket->cepid, optname, (void *)optval, *optlen);
+				if (ret < 0) {
+					return -EINVAL;
+				}
+				*optlen = ret;
+				break;
+			default:
+				return -EINVAL;
+			}
+			break;
+		}
 		case SOCK_DGRAM: {
-			T_IPV4EP rep = { 0, 0 };
-			ret = udp_rcv_dat(fp->socket.cepid, &rep, buf, len, TMO_FEVR);
-			if (ret < 0) {
-				return -ECOMM;
-			}
-			int sz = *alen;
-			struct sockaddr_in raddr;
-			memset(&raddr, 0, sizeof(raddr));
-			raddr.sin_family = AF_INET;
-			raddr.sin_port = htons(rep.portno);
-			raddr.sin_addr.s_addr = htonl(rep.ipaddr);
-			if (sz > sizeof(raddr))
-				sz = sizeof(raddr);
-			memcpy(addr, &raddr, sz);
-		}
-		}
-		break;
-	}
-	case AF_INET6: {
-		return -EAFNOSUPPORT;
-	}
-	}
-
-	return ret;
-}
-
-ssize_t shell_recvmsg(int fd, struct msghdr *msg, int flags)
-{
-	no_implement("recvmsg\n");
-	return -ENOSYS;
-}
-
-int shell_shutdown(int fd, int how)
+			switch (level) {
+			case IPPROTO_UDP:
+				ret = udp6_get_opt(socket->cepid, optname, (void *)optval, *optlen);
+				if (ret < 0) {
+					return -EINVAL;
+				}
+				*optlen = ret;
+				break;
+			default:
+				return -EINVAL;
+			}
+			break;
+		}
+		}
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
+	}
+
+	return 0;
+}
+
+int shell_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
 {
 	SOCKET *fp = fd_to_fp(fd);
@@ -608,20 +1362,114 @@
 
 	ER ret;
-	switch (fp->socket.family) {
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->socket.type) {
+		switch (socket->type) {
 		case SOCK_STREAM: {
-			ret = tcp_sht_cep(fp->socket.cepid);
-			if (ret < 0) {
-				return -ECOMM;
+			switch (level){
+			case SOL_SOCKET:
+				switch (optname) {
+				case SO_REUSEADDR:
+					if (*(bool *)optval) {
+						socket->flags |= SO_REUSEADDR;
+					}
+					else {
+						socket->flags &= ~SO_REUSEADDR;
+					}
+					break;
+				case SO_KEEPALIVE:
+					if (*(bool *)optval) {
+						socket->flags |= SO_KEEPALIVE;
+					}
+					else {
+						socket->flags &= ~SO_KEEPALIVE;
+					}
+					break;
+				default:
+					return -EINVAL;
+				}
+				break;
+			case IPPROTO_TCP:
+				ret = tcp_set_opt(socket->cepid, optname, (void *)optval, optlen);
+				if (ret < 0) {
+					return -EINVAL;
+				}
+				break;
+			default:
+				return -EINVAL;
 			}
 			break;
 		}
+		case SOCK_DGRAM: {
+			switch (level){
+			case IPPROTO_UDP:
+				ret = udp_set_opt(socket->cepid, optname, (void *)optval, optlen);
+				if (ret < 0) {
+					return -EINVAL;
+				}
+				break;
+			default:
+				return -EINVAL;
+			}
+			break;
+		}
 		}
 		break;
 	}
 	case AF_INET6: {
-		return -EAFNOSUPPORT;
-	}
+		switch (socket->type) {
+		case SOCK_STREAM: {
+			switch (level){
+			case SOL_SOCKET:
+				switch (optname) {
+				case SO_REUSEADDR:
+					if (*(bool *)optval) {
+						socket->flags |= SO_REUSEADDR;
+					}
+					else {
+						socket->flags &= ~SO_REUSEADDR;
+					}
+					break;
+				case SO_KEEPALIVE:
+					if (*(bool *)optval) {
+						socket->flags |= SO_KEEPALIVE;
+					}
+					else {
+						socket->flags &= ~SO_KEEPALIVE;
+					}
+					break;
+				default:
+					return -EINVAL;
+				}
+				break;
+			case IPPROTO_TCP:
+				ret = tcp6_set_opt(socket->cepid, optname, (void *)optval, optlen);
+				if (ret < 0) {
+					return -EINVAL;
+				}
+				break;
+			default:
+				return -EINVAL;
+			}
+			break;
+		}
+		case SOCK_DGRAM: {
+			switch (level){
+			case IPPROTO_UDP:
+				ret = udp6_set_opt(socket->cepid, optname, (void *)optval, optlen);
+				if (ret < 0) {
+					return -EINVAL;
+				}
+				break;
+			default:
+				return -EINVAL;
+			}
+			break;
+		}
+		}
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
 	}
 
@@ -629,5 +1477,5 @@
 }
 
-int shell_getsockopt(int fd, int level, int optname, void *optval, socklen_t *__restrict optlen)
+int shell_getpeername(int fd, struct sockaddr *restrict addr, socklen_t *restrict len)
 {
 	SOCKET *fp = fd_to_fp(fd);
@@ -635,43 +1483,29 @@
 		return -EBADF;
 	}
-
-	ER ret;
-	switch (fp->socket.family) {
+	if (len == NULL) {
+		return -EINVAL;
+	}
+
+	socklen_t size = *len;
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->socket.type) {
-		case SOCK_STREAM: {
-			switch (optname) {
-			case SO_REUSEADDR:
-				if (fp->socket.flags & SO_REUSEADDR) {
-					*(bool *)optval = true;
-				}
-				else {
-					*(bool *)optval = false;
-				}
-				break;
-			default:
-				ret = tcp_get_opt(fp->socket.cepid, optname, (void *)optval, *optlen);
-				if (ret < 0) {
-					return -EINVAL;
-				}
-				*optlen = ret;
-				break;
-			}
-			break;
-		}
-		case SOCK_DGRAM: {
-			ret = udp_get_opt(fp->socket.cepid, optname, (void *)optval, *optlen);
-			if (ret < 0) {
-				return -EINVAL;
-			}
-			*optlen = ret;
-			break;
-		}
-		}
+		struct sockaddr_in *raddr = &socket->raddr4;
+		*len = sizeof(struct sockaddr_in);
+		if (size > sizeof(struct sockaddr_in))
+			size = sizeof(struct sockaddr_in);
+		memcpy(addr, raddr, size);
 		break;
 	}
 	case AF_INET6: {
-		return -EAFNOSUPPORT;
-	}
+		struct sockaddr_in6 *raddr = &socket->raddr6;
+		*len = sizeof(struct sockaddr_in6);
+		if (size > sizeof(struct sockaddr_in6))
+			size = sizeof(struct sockaddr_in6);
+		memcpy(addr, raddr, size);
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
 	}
 
@@ -679,5 +1513,5 @@
 }
 
-int shell_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
+int shell_getsockname(int fd, struct sockaddr *restrict addr, socklen_t *restrict len)
 {
 	SOCKET *fp = fd_to_fp(fd);
@@ -685,41 +1519,38 @@
 		return -EBADF;
 	}
-
-	ER ret;
-	switch (fp->socket.family) {
+	if (len == NULL) {
+		return -EINVAL;
+	}
+
+	socklen_t size = *len;
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		switch (fp->socket.type) {
-		case SOCK_STREAM: {
-			switch (optname) {
-			case SO_REUSEADDR:
-				if (*(bool *)optval) {
-					fp->socket.flags |= SO_REUSEADDR;
-				}
-				else {
-					fp->socket.flags &= ~SO_REUSEADDR;
-				}
-				break;
-			default:
-				ret = tcp_set_opt(fp->socket.cepid, optname, (void *)optval, optlen);
-				if (ret < 0) {
-					return -EINVAL;
-				}
-				break;
-			}
-			break;
-		}
-		case SOCK_DGRAM: {
-			ret = udp_set_opt(fp->socket.cepid, optname, (void *)optval, optlen);
-			if (ret < 0) {
-				return -EINVAL;
-			}
-			break;
-		}
-		}
+		const T_IN4_ADDR *laddr4 = in4_get_ifaddr(0);
+		struct sockaddr_in laddr;
+		laddr.sin_family = AF_INET;
+		laddr.sin_addr.s_addr = htonl(*laddr4);
+		laddr.sin_port = socket->laddr4.sin_port;
+		memset(&laddr.sin_zero, 0, sizeof(laddr.sin_zero));
+		*len = sizeof(struct sockaddr_in);
+		if (size > sizeof(struct sockaddr_in))
+			size = sizeof(struct sockaddr_in);
+		memcpy(addr, &laddr, size);
 		break;
 	}
 	case AF_INET6: {
-		return -EAFNOSUPPORT;
-	}
+		const T_IN6_ADDR *laddr6 = in6_get_ifaddr(0);
+		struct sockaddr_in6 laddr;
+		laddr.sin6_family = AF_INET;
+		addrcpy(&laddr.sin6_addr, laddr6, 16);
+		laddr.sin6_port = socket->laddr6.sin6_port;
+		*len = sizeof(struct sockaddr_in6);
+		if (size > sizeof(struct sockaddr_in6))
+			size = sizeof(struct sockaddr_in6);
+		memcpy(addr, &laddr, size);
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
 	}
 
@@ -727,30 +1558,36 @@
 }
 
-int tcp_fd_close(struct _IO_FILE *fp)
-{
-	ER ret;
-	switch (fp->socket.family) {
+int tcp_fd_close(struct SHELL_FILE *fp)
+{
+	ER ret, ret2;
+
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		if (fp->socket.cepid != 0) {
-			ID cepid = fp->socket.cepid;
+		if (socket->cepid != 0) {
+			ID cepid = socket->cepid;
+			ret = tcp_can_cep(cepid, TFN_TCP_ALL);
+			if ((ret < 0) && (ret != E_OBJ)) {
+				syslog(LOG_ERROR, "tcp_can_cep => %d", ret);
+			}
 			ret = tcp_sht_cep(cepid);
-			if (ret < 0) {
-				//return -1;
-			}
-			ret = tcp_cls_cep(cepid, (fp->socket.repid != 0) ? 0 : SOCKET_TIMEOUT);
-			if (ret < 0) {
-				//return -1;
-			}
-			ret = tcp_del_cep(cepid);
-			delete_tcp_fd(cepid);
+			if ((ret < 0) && (ret != E_OBJ)) {
+				syslog(LOG_ERROR, "tcp_sht_cep => %d", ret);
+			}
+			ret = tcp_cls_cep(cepid, (socket->repid != 0) ? 0 : SOCKET_TIMEOUT);
+			ret2 = tcp_del_cep(cepid);
+			if (ret2 < 0) {
+				syslog(LOG_ERROR, "tcp_del_cep => %d", ret2);
+			}
+			//delete_fd_by_id(&IO_TYPE_TCP, cepid);
 			delete_id(tcp_cepid_table, tcp_cepid_table_count, cepid);
-			if (ret < 0) {
-				return -EINVAL;
-			}
-		}
-		else if (fp->socket.repid != 0) {
-			ID repid = fp->socket.repid;
+			if ((ret < 0) || (ret2 < 0)) {
+				return (ret == E_TMOUT) ? -ETIMEDOUT : -EIO;
+			}
+		}
+		else if (socket->repid != 0) {
+			ID repid = socket->repid;
 			ret = tcp_del_rep(repid);
-			delete_tcp_fd(tmax_tcp_cepid + repid);
+			//delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + repid);
 			delete_id(tcp_repid_table, tcp_repid_table_count, repid);
 			if (ret < 0) {
@@ -764,6 +1601,41 @@
 	}
 	case AF_INET6: {
-		return -EAFNOSUPPORT;
-	}
+		if (socket->cepid != 0) {
+			ID cepid = socket->cepid;
+			ret = tcp6_can_cep(cepid, TFN_TCP_ALL);
+			if ((ret < 0) && (ret != E_OBJ)) {
+				syslog(LOG_ERROR, "tcp_can_cep => %d", ret);
+			}
+			ret = tcp6_sht_cep(cepid);
+			if ((ret < 0) && (ret != E_OBJ)) {
+				syslog(LOG_ERROR, "tcp6_sht_cep => %d", ret);
+			}
+			ret = tcp6_cls_cep(cepid, (socket->repid != 0) ? 0 : SOCKET_TIMEOUT);
+			ret2 = tcp6_del_cep(cepid);
+			if (ret2 < 0) {
+				syslog(LOG_ERROR, "tcp6_del_cep => %d", ret2);
+			}
+			//delete_fd_by_id(&IO_TYPE_TCP, cepid);
+			delete_id(tcp6_cepid_table, tcp6_cepid_table_count, cepid);
+			if ((ret < 0) || (ret2 < 0)) {
+				return (ret == E_TMOUT) ? -ETIMEDOUT : -EIO;
+			}
+		}
+		else if (socket->repid != 0) {
+			ID repid = socket->repid;
+			ret = tcp6_del_rep(repid);
+			//delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp6_cepid + repid);
+			delete_id(tcp6_repid_table, tcp6_repid_table_count, repid);
+			if (ret < 0) {
+				return -EINVAL;
+			}
+		}
+		else {
+			return -EINVAL;
+		}
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
 	}
 
@@ -771,33 +1643,261 @@
 }
 
-size_t tcp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
-{
-	return shell_recv(fp->fd, dst, dstsz, 0);
-}
-
-size_t tcp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
-{
-	return shell_send(fp->fd, src, srcsz, 0);
-}
-
-off_t tcp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
+size_t tcp_fd_read(struct SHELL_FILE *fp, unsigned char *dst, size_t dstsz)
+{
+	return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL);
+}
+
+size_t tcp_fd_write(struct SHELL_FILE *fp, const unsigned char *src, size_t srcsz)
+{
+	return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0);
+}
+
+off_t tcp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org)
 {
 	return -EPERM;
 }
 
-int tcp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
-{
+int tcp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg)
+{
+	socket_t *socket = (socket_t *)fp->exinf;
+
+	switch (req) {
+	case F_GETFL:
+		return socket->flags;
+	case F_SETFL:
+		socket->flags = (unsigned int)arg;
+		return 0;
+	}
+
 	return -EINVAL;
 }
 
-int udp_fd_close(struct _IO_FILE *fp)
+bool_t tcp_fd_readable(struct SHELL_FILE *fp)
+{
+	ER ret;
+
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->cepid != 0) {
+		if (socket->len == 0) {
+			ret = tcp_rcv_buf(socket->cepid, &socket->input, TMO_NBLK);
+			if ((ret != E_WBLK) && (ret != E_OBJ) && (ret < 0)) {
+				syslog(LOG_ERROR, "tcp_rcv_buf => %d", ret);
+				//return ret;
+			}
+			if (ret > 0) {
+				ret = wai_sem(SEM_FILEDESC);
+				if (ret < 0) {
+					syslog(LOG_ERROR, "wai_sem => %d", ret);
+				}
+				socket->len += ret;
+				ret = sig_sem(SEM_FILEDESC);
+				if (ret < 0) {
+					syslog(LOG_ERROR, "sig_sem => %d", ret);
+				}
+			}
+		}
+		else ret = 1;
+		if (ret > 0) {
+			return true;
+		}
+	}
+
+	return false;
+}
+
+bool_t tcp_fd_writable(struct SHELL_FILE *fp)
+{
+	//socket_t *socket = (socket_t *)fp->exinf;
+
+	return /*fp->writable &&*/ (fp->writeevt_w == fp->writeevt_r);
+}
+
+void tcp_fd_delete(struct SHELL_FILE *fp)
+{
+	socket_t *socket = (socket_t *)fp->exinf;
+	free(socket->buf);
+	socket->buf = NULL;
+	free(fp->exinf);
+	fp->exinf = NULL;
+}
+
+ER socket_tcp_callback(ID cepid, FN fncd, void *p_parblk)
+{
+	struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_TCP, cepid);
+	FLGPTN flgptn = 0;
+	ER ret;
+	int len;
+
+	if (fp == NULL)
+		return E_PAR;
+
+	socket_t *socket = (socket_t *)fp->exinf;
+	int fd = fp->fd;
+	FD_SET(fd, (fd_set *)&flgptn);
+
+	switch (fncd) {
+	case TFN_TCP_RCV_BUF:
+		len = *(int *)p_parblk;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		ret = wai_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "wai_sem => %d", ret);
+		}
+		socket->len += len;
+		ret = sig_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "sig_sem => %d", ret);
+		}
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_RCV_DAT:
+		len = *(int *)p_parblk;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		ret = wai_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "wai_sem => %d", ret);
+		}
+		socket->len += len;
+		ret = sig_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "sig_sem => %d", ret);
+		}
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_SND_DAT:
+		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_CAN_CEP:
+		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_DEL_REP:
+		delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + cepid);
+		return E_OK;
+
+	case TFN_TCP_DEL_CEP:
+		delete_fd_by_id(&IO_TYPE_TCP, cepid);
+		return E_OK;
+
+	default:
+		return E_OK;
+	}
+}
+
+ER socket_tcp6_callback(ID cepid, FN fncd, void *p_parblk)
+{
+	struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_TCP, cepid);
+	FLGPTN flgptn = 0;
+	ER ret;
+	int len;
+
+	if (fp == NULL)
+		return E_PAR;
+
+	socket_t *socket = (socket_t *)fp->exinf;
+	int fd = fp->fd;
+	FD_SET(fd, (fd_set *)&flgptn);
+
+	switch (fncd) {
+	case TFN_TCP_RCV_BUF:
+		len = *(int *)p_parblk;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		ret = wai_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "wai_sem => %d", ret);
+		}
+		socket->len += len;
+		ret = sig_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "sig_sem => %d", ret);
+		}
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_RCV_DAT:
+		len = *(int *)p_parblk;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		ret = wai_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "wai_sem => %d", ret);
+		}
+		socket->len += len;
+		ret = sig_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "sig_sem => %d", ret);
+		}
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_SND_DAT:
+		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_CAN_CEP:
+		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_TCP_DEL_REP:
+		delete_fd_by_id(&IO_TYPE_TCP, tmax_tcp_cepid + cepid);
+		return E_OK;
+
+	case TFN_TCP_DEL_CEP:
+		delete_fd_by_id(&IO_TYPE_TCP, cepid);
+		return E_OK;
+
+	default:
+		return E_OK;
+	}
+}
+
+int udp_fd_close(struct SHELL_FILE *fp)
 {
 	ER ret;
 	ID cepid;
-	switch (fp->socket.family) {
+
+	socket_t *socket = (socket_t *)fp->exinf;
+	switch (socket->family) {
 	case AF_INET: {
-		cepid = fp->socket.cepid;
+		cepid = socket->cepid;
+		ret = udp_can_cep(cepid, TFN_UDP_ALL);
+		if ((ret < 0) && (ret != E_OBJ)) {
+			syslog(LOG_ERROR, "udp_can_cep => %d", ret);
+		}
 		ret = udp_del_cep(cepid);
-		delete_udp_fd(cepid);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "udp_del_cep => %d", ret);
+		}
+		//delete_fd_by_id(&IO_TYPE_UDP, cepid);
 		delete_id(udp_cepid_table, udp_cepid_table_count, cepid);
 		if (ret < 0) {
@@ -807,6 +1907,22 @@
 	}
 	case AF_INET6: {
-		return -EAFNOSUPPORT;
-	}
+		cepid = socket->cepid;
+		ret = udp6_can_cep(cepid, TFN_UDP_ALL);
+		if ((ret < 0) && (ret != E_OBJ)) {
+			syslog(LOG_ERROR, "udp6_can_cep => %d", ret);
+		}
+		ret = udp6_del_cep(cepid);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "udp6_del_cep => %d", ret);
+		}
+		//delete_fd_by_id(&IO_TYPE_UDP, cepid);
+		delete_id(udp6_cepid_table, udp6_cepid_table_count, cepid);
+		if (ret < 0) {
+			return -EINVAL;
+		}
+		break;
+	}
+	default:
+		return -ENOPROTOOPT;
 	}
 
@@ -814,22 +1930,216 @@
 }
 
-size_t udp_fd_read(struct _IO_FILE *fp, unsigned char *dst, size_t dstsz)
-{
-	return shell_recv(fp->fd, dst, dstsz, 0);
-}
-
-size_t udp_fd_write(struct _IO_FILE *fp, const unsigned char *src, size_t srcsz)
-{
-	return shell_send(fp->fd, src, srcsz, 0);
-}
-
-off_t udp_fd_seek(struct _IO_FILE *fp, off_t ofs, int org)
+size_t udp_fd_read(struct SHELL_FILE *fp, unsigned char *dst, size_t dstsz)
+{
+	return shell_recvfrom(fp->fd, dst, dstsz, 0, NULL, NULL);
+}
+
+size_t udp_fd_write(struct SHELL_FILE *fp, const unsigned char *src, size_t srcsz)
+{
+	return shell_sendto(fp->fd, src, srcsz, 0, NULL, 0);
+}
+
+off_t udp_fd_seek(struct SHELL_FILE *fp, off_t ofs, int org)
 {
 	return -EPERM;
 }
 
-int udp_fd_ioctl(struct _IO_FILE *fp, int req, void *arg)
+int udp_fd_ioctl(struct SHELL_FILE *fp, int req, void *arg)
 {
 	return -EINVAL;
+}
+
+bool_t udp_fd_readable(struct SHELL_FILE *fp)
+{
+	socket_t *socket = (socket_t *)fp->exinf;
+	if (socket->cepid != 0) {
+		if (socket->input != NULL) {
+			return true;
+		}
+	}
+
+	return false;
+}
+
+bool_t udp_fd_writable(struct SHELL_FILE *fp)
+{
+	//socket_t *socket = (socket_t *)fp->exinf;
+
+	return fp->writable && (fp->writeevt_w == fp->writeevt_r);
+}
+
+void udp_fd_delete(struct SHELL_FILE *fp)
+{
+	//socket_t *socket = (socket_t *)fp->exinf;
+	//free(socket->buf);
+	//socket->buf = NULL;
+	free(fp->exinf);
+	fp->exinf = NULL;
+}
+
+ER socket_udp_callback(ID cepid, FN fncd, void *p_parblk)
+{
+	struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_UDP, cepid);
+	FLGPTN flgptn = 0;
+	int len;
+
+	if (fp == NULL)
+		return E_PAR;
+
+	int fd = fp->fd;
+	FD_SET(fd, (fd_set *)&flgptn);
+
+	switch (fncd) {
+	case TEV_UDP_RCV_DAT:
+	{
+		T_UDP_RCV_DAT_PARA *udppara = (T_UDP_RCV_DAT_PARA *)p_parblk;
+		len = udppara->len;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		ER ret = wai_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "wai_sem => %d", ret);
+		}
+		socket_t *socket = (socket_t *)fp->exinf;
+		socket->len = len;
+		if (socket->input != NULL) {
+			ret = rel_net_buf(socket->input);
+			if (ret < 0) {
+				syslog(LOG_ERROR, "rel_net_buf => %d", ret);
+			}
+		}
+		socket->input = udppara->input;
+		socket->buf = GET_UDP_SDU(udppara->input, udppara->off);
+		memset(&socket->raddr4, 0, sizeof(struct sockaddr_in));
+		socket->raddr4.sin_family = AF_INET;
+		socket->raddr4.sin_port = htons(udppara->rep4.portno);
+		socket->raddr4.sin_addr.s_addr = htonl(udppara->rep4.ipaddr);
+		udppara->input->flags |= NB_FLG_NOREL_IFOUT;
+		ret = sig_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "sig_sem => %d", ret);
+		}
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+	}
+	case TFN_UDP_CRE_CEP:
+		return E_OK;
+
+	case TFN_UDP_RCV_DAT:
+		len = *(int *)p_parblk;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_UDP_SND_DAT:
+		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_UDP_CAN_CEP:
+		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_UDP_DEL_CEP:
+		delete_fd_by_id(&IO_TYPE_UDP, cepid);
+		return E_OK;
+
+	default:
+		return E_OK;
+	}
+}
+
+ER socket_udp6_callback(ID cepid, FN fncd, void *p_parblk)
+{
+	struct SHELL_FILE *fp = id_to_fd(&IO_TYPE_UDP, cepid);
+	FLGPTN flgptn = 0;
+	int len;
+
+	if (fp == NULL)
+		return E_PAR;
+
+	int fd = fp->fd;
+	FD_SET(fd, (fd_set *)&flgptn);
+
+	switch (fncd) {
+	case TEV_UDP_RCV_DAT:
+	{
+		T_UDP_RCV_DAT_PARA *udppara = (T_UDP_RCV_DAT_PARA *)p_parblk;
+		len = udppara->len;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		ER ret = wai_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "wai_sem => %d", ret);
+		}
+		socket_t *socket = (socket_t *)fp->exinf;
+		socket->len = len;
+		if (socket->input != NULL) {
+			ret = rel_net_buf(socket->input);
+			if (ret < 0) {
+				syslog(LOG_ERROR, "rel_net_buf => %d", ret);
+			}
+		}
+		socket->input = udppara->input;
+		socket->buf = GET_UDP_SDU(udppara->input, udppara->off);
+		memset(&socket->raddr6, 0, sizeof(struct sockaddr_in6));
+		socket->raddr6.sin6_family = AF_INET;
+		socket->raddr6.sin6_port = htons(udppara->rep6.portno);
+		addrcpy(&socket->raddr6.sin6_addr, &udppara->rep6.ipaddr, 16);
+		udppara->input->flags |= NB_FLG_NOREL_IFOUT;
+		ret = sig_sem(SEM_FILEDESC);
+		if (ret < 0) {
+			syslog(LOG_ERROR, "sig_sem => %d", ret);
+		}
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+	}
+	case TFN_UDP_CRE_CEP:
+		return E_OK;
+
+	case TFN_UDP_RCV_DAT:
+		len = *(int *)p_parblk;
+		if ((len <= 0) || (fp->exinf == NULL))
+			return E_OK;
+
+		if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_UDP_SND_DAT:
+		if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_UDP_CAN_CEP:
+		if (fp->errorevt_w == fp->errorevt_r) fp->errorevt_w++;
+
+		set_flg(FLG_SELECT_WAIT, flgptn);
+		return E_OK;
+
+	case TFN_UDP_DEL_CEP:
+		delete_fd_by_id(&IO_TYPE_UDP, cepid);
+		return E_OK;
+
+	default:
+		return E_OK;
+	}
 }
 
@@ -904,2 +2214,48 @@
 }
 #endif
+
+// musl-1.1.18/network/lookup.h
+struct address {
+	int family;
+	unsigned scopeid;
+	uint8_t addr[16];
+	int sortkey;
+};
+
+#define MAXNS 3
+
+struct resolvconf {
+	struct address ns[MAXNS];
+	unsigned nns, attempts, ndots;
+	unsigned timeout;
+};
+
+// musl-1.1.18/network/resolvconf.c
+int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
+{
+	int nns = 0;
+
+	conf->ndots = 1;
+	conf->timeout = 5;
+	conf->attempts = 2;
+	if (search) *search = 0;
+
+#if defined(SUPPORT_INET4)
+	T_IN4_ADDR	in4_addr;
+	conf->ns[nns].family = AF_INET;
+	conf->ns[nns].scopeid = 0;
+	dns_in4_get_addr(&in4_addr);
+	*(uint32_t *)conf->ns[nns].addr = ntohl(in4_addr);
+	nns++;
+#endif
+
+#if defined(SUPPORT_INET6)
+	conf->ns[nns].family = AF_INET6;
+	conf->ns[nns].scopeid = 0;
+	dns_in6_get_addr((T_IN6_ADDR *)conf->ns[nns].addr);
+	nns++;
+#endif
+	conf->nns = nns;
+
+	return 0;
+}
Index: /EcnlProtoTool/trunk/ntshell/src/stdio_stub.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/stdio_stub.c	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/stdio_stub.c	(revision 441)
@@ -0,0 +1,666 @@
+/*
+ *  TOPPERS PROJECT Home Network Working Group Software
+ * 
+ *  Copyright (C) 2017-2019 Cores Co., Ltd. Japan
+ * 
+ *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+#include "shellif.h"
+#include <stdint.h>
+#include <kernel.h>
+#include <t_syslog.h>
+#include <t_stdlib.h>
+#include <sil.h>
+#include "syssvc/serial.h"
+#include "syssvc/syslog.h"
+#include "target_syssvc.h"
+#include "fdtable.h"
+#include "kernel_cfg.h"
+#include <string.h>
+#include <errno.h>
+#include "util/ntstdio.h"
+#include "hal/serial_api.h"
+#include "target_rename.h"
+#include "target_kernel_impl.h"
+#include "syssvc/siofd.h"
+
+#ifdef _DEBUG
+static const char THIS_FILE[] = __FILE__;
+#endif
+
+int shell_errno;
+
+extern bool_t sio_isr_snd(ID siopid);
+extern bool_t sio_isr_rcv(ID siopid, char c);
+
+static unsigned char stdio_xi(struct ntstdio_t *handle);
+static void stdio_xo(struct ntstdio_t *handle, unsigned char c);
+static void stdio_serial_irq_handler(uint32_t id, SerialIrq event);
+
+static int stdio_close(struct SHELL_FILE *fp);
+static size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static void stdio_delete(struct SHELL_FILE *fp);
+
+static unsigned char sio_xi(struct ntstdio_t *handle);
+static void sio_xo(struct ntstdio_t *handle, unsigned char c);
+static void sio_serial_irq_handler(uint32_t id, SerialIrq event);
+
+static int sio_close(struct SHELL_FILE *fp);
+static size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len);
+static size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len);
+static off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org);
+static int sio_ioctl(struct SHELL_FILE *fp, int req, void *arg);
+static bool_t sio_readable(struct SHELL_FILE *fp);
+static bool_t sio_writable(struct SHELL_FILE *fp);
+static void sio_delete(struct SHELL_FILE *fp);
+
+IO_TYPE IO_TYPE_STDIN = { stdio_close, sio_read, stdio_write, sio_seek, sio_ioctl, sio_readable, sio_writable, stdio_delete };
+IO_TYPE IO_TYPE_STDOUT = { stdio_close, stdio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_writable, stdio_delete };
+IO_TYPE IO_TYPE_STDERR = { stdio_close, stdio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_writable, stdio_delete };
+IO_TYPE IO_TYPE_SIO = { sio_close, sio_read, sio_write, sio_seek, sio_ioctl, sio_readable, sio_writable, sio_delete };
+
+#define STDIO_UART_BUF_SZ 256
+
+typedef struct stdio_sio_t {
+	serial_t serial;
+	ntstdio_t ntstdio;
+	struct SHELL_FILE *fp;
+	unsigned char tx_buf[STDIO_UART_BUF_SZ];
+	int tx_pos_w;
+	int tx_pos_r;
+	unsigned char rx_buf[STDIO_UART_BUF_SZ];
+	int rx_pos_w;
+	int rx_pos_r;
+} stdio_sio_t;
+
+stdio_sio_t stdio_sio;
+ntstdio_t *ntstdio = &stdio_sio.ntstdio;
+
+void sys_init(intptr_t exinf)
+{
+	serial_t *serial = &stdio_sio.serial;
+	ntstdio_t *ntstdio = &stdio_sio.ntstdio;
+
+	serial_init(serial, STDIO_UART_TX, STDIO_UART_RX);
+	serial_baud(serial, UART_BAUDRATE);
+	serial_format(serial, 8, ParityNone, 1);
+
+	ntstdio_init(ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, stdio_xi, stdio_xo);
+	ntstdio->exinf = (void *)&stdio_sio;
+
+	struct SHELL_FILE *fp;
+
+	fp = fd_to_fp(STDIN_FILENO);
+	fp->handle = SIO_PORTID;
+	fp->exinf = (void *)ntstdio;
+
+	fp = fd_to_fp(STDOUT_FILENO);
+	fp->handle = SIO_PORTID;
+	fp->exinf = (void *)ntstdio;
+
+	fp = fd_to_fp(STDERR_FILENO);
+	fp->handle = SIO_PORTID;
+	fp->exinf = (void *)ntstdio;
+
+	serial_irq_handler(&stdio_sio.serial, stdio_serial_irq_handler, 0);
+
+	serial_irq_set(serial, RxIrq, true);
+}
+
+void stdio_open(ID portid)
+{
+	struct SHELL_FILE *fp;
+
+	serial_ctl_por(portid, IOCTL_CRLF | IOCTL_FCSND | IOCTL_FCRCV);
+
+	fp = fd_to_fp(STDIN_FILENO);
+	fp->handle = portid;
+
+	fp = fd_to_fp(STDOUT_FILENO);
+	fp->handle = portid;
+
+	fp = fd_to_fp(STDERR_FILENO);
+	fp->handle = portid;
+}
+
+int stdio_close(struct SHELL_FILE *fp)
+{
+	return -EPERM;
+}
+
+size_t stdio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
+{
+	return -EPERM;
+}
+
+size_t stdio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	return -EPERM;
+}
+
+void stdio_delete(struct SHELL_FILE *fp)
+{
+}
+
+int sio_close(struct SHELL_FILE *fp)
+{
+	return -EPERM;
+}
+
+size_t sio_read(struct SHELL_FILE *fp, unsigned char *data, size_t len)
+{
+	int i = 0;
+	while (i < len) {
+		int c = ntstdio_getc((struct ntstdio_t *)fp->exinf);
+		data[i++] = c;
+		if ((c == EOF) || (c == '\n'))
+			break;
+	}
+	return i;
+}
+
+size_t sio_write(struct SHELL_FILE *fp, const unsigned char *data, size_t len)
+{
+	for (int i = 0; i < len; i++) {
+		ntstdio_putc((struct ntstdio_t *)fp->exinf, data[i]);
+	}
+	return len;
+}
+
+off_t sio_seek(struct SHELL_FILE *fp, off_t ofs, int org)
+{
+	return -EPERM;
+}
+
+int sio_tcgetattr(struct SHELL_FILE *fp, struct termios *termios)
+{
+	ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;
+
+	memset(termios, 0, sizeof(*termios));
+
+	if (ntstdio->option & NTSTDIO_OPTION_LINE_ECHO) {
+		termios->c_lflag |= ECHO;
+	}
+	else {
+		termios->c_lflag &= ~ECHO;
+	}
+	if (ntstdio->option & NTSTDIO_OPTION_CANON) {
+		termios->c_lflag |= ICANON;
+	}
+	else {
+		termios->c_lflag &= ~ICANON;
+	}
+	if (ntstdio->option & NTSTDIO_OPTION_LF_CR) {
+		termios->c_iflag |= INLCR;
+	}
+	else {
+		termios->c_iflag &= ~INLCR;
+	}
+	if (ntstdio->option & NTSTDIO_OPTION_LF_CRLF) {
+		termios->c_oflag |= ONLCR;
+	}
+	else {
+		termios->c_oflag &= ~ONLCR;
+	}
+
+	return 0;
+}
+
+int sio_tcsetattr(struct SHELL_FILE *fp, int optional_actions, const struct termios *termios)
+{
+	ntstdio_t *ntstdio = (ntstdio_t *)fp->exinf;
+
+	if (optional_actions == TCSANOW) {
+		if (termios->c_lflag & ECHO) {
+			ntstdio->option |= NTSTDIO_OPTION_LINE_ECHO;
+		}
+		else {
+			ntstdio->option &= ~NTSTDIO_OPTION_LINE_ECHO;
+		}
+		if (termios->c_lflag & ICANON) {
+			ntstdio->option |= NTSTDIO_OPTION_CANON;
+		}
+		else {
+			ntstdio->option &= ~NTSTDIO_OPTION_CANON;
+		}
+		if (termios->c_iflag & INLCR) {
+			ntstdio->option |= NTSTDIO_OPTION_LF_CR;
+		}
+		else {
+			ntstdio->option &= ~NTSTDIO_OPTION_LF_CR;
+		}
+		if (termios->c_oflag & ONLCR) {
+			ntstdio->option |= NTSTDIO_OPTION_LF_CRLF;
+		}
+		else {
+			ntstdio->option &= ~NTSTDIO_OPTION_LF_CRLF;
+		}
+		return 0;
+	}
+
+	//shell_abort();
+	return 0;
+}
+
+int sio_ioctl(struct SHELL_FILE *fp, int request, void *arg)
+{
+	switch (request) {
+	case TIOCGWINSZ:
+		return 0;
+	case TCGETS:
+		return sio_tcgetattr(fp, (struct termios *)arg);
+	case TCSETS + TCSANOW:
+	case TCSETS + TCSADRAIN:
+	case TCSETS + TCSAFLUSH:
+		return sio_tcsetattr(fp, request - TCSETS, (const struct termios *)arg);
+	}
+
+	return -EINVAL;
+}
+
+bool_t sio_readable(struct SHELL_FILE *fp)
+{
+	struct ntstdio_t *ntstdio = (struct ntstdio_t *)fp->exinf;
+	stdio_sio_t *uart = (stdio_sio_t *)ntstdio->exinf;
+
+	return uart->rx_pos_r != uart->rx_pos_w;
+}
+
+bool_t sio_writable(struct SHELL_FILE *fp)
+{
+	if (!fp->writable)
+		return false;
+
+	struct ntstdio_t *ntstdio = (struct ntstdio_t *)fp->exinf;
+	stdio_sio_t *uart = (stdio_sio_t *)ntstdio->exinf;
+
+	int tx_pos_w = uart->tx_pos_w + 1;
+	if (tx_pos_w >= sizeof(uart->tx_buf))
+		tx_pos_w = 0;
+	return uart->tx_pos_r != tx_pos_w;
+}
+
+void sio_delete(struct SHELL_FILE *fp)
+{
+	free((stdio_sio_t *)((struct ntstdio_t *)fp->exinf)->exinf);
+	((struct ntstdio_t *)fp->exinf)->exinf = NULL;
+	free((struct ntstdio_t *)fp->exinf);
+	fp->exinf = NULL;
+}
+
+static unsigned char ntstdio_xi(struct ntstdio_t *handle, struct SHELL_FILE *fp)
+{
+	stdio_sio_t *uart = (stdio_sio_t *)handle->exinf;
+	ER ret;
+	unsigned char c;
+
+	bool_t lock = sense_lock();
+	if (lock)
+		unl_cpu();
+
+	while (uart->rx_pos_w == uart->rx_pos_r) {
+		FLGPTN flgptn = 0, waitptn = 0;
+		FD_SET(fp->fd, (fd_set *)&waitptn);
+
+		ret = wai_flg(FLG_SELECT_WAIT, waitptn, TWF_ORW, &flgptn);
+		if (ret != E_OK) {
+			if (lock)
+				loc_cpu();
+			syslog(LOG_ERROR, "wai_flg => %d", ret);
+			return 0;
+		}
+
+		ret = clr_flg(FLG_SELECT_WAIT, ~(flgptn & waitptn));
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "clr_flg => %d", ret);
+		}
+	}
+
+	if (lock)
+		unl_cpu();
+
+	c = uart->rx_buf[uart->rx_pos_r++];
+	if (uart->rx_pos_r >= sizeof(uart->rx_buf))
+		uart->rx_pos_r = 0;
+
+	if ((uart->rx_pos_r == uart->rx_pos_w)
+		&& (fp->readevt_w != fp->readevt_r))
+		fp->readevt_r++;
+
+	return c;
+}
+
+void stdio_input(unsigned char c)
+{
+	struct SHELL_FILE *fp = fd_to_fp(STDIN_FILENO);
+	stdio_sio_t *uart = (stdio_sio_t *)((struct ntstdio_t *)fp->exinf)->exinf;
+	serial_t *serial = (serial_t *)&uart->serial;
+	ER ret;
+	FLGPTN flgptn = 0;
+
+	uart->rx_buf[uart->rx_pos_w++] = c;
+	if (uart->rx_pos_w >= sizeof(uart->rx_buf))
+		uart->rx_pos_w = 0;
+
+	if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+	FD_SET(STDIN_FILENO, (fd_set *)&flgptn);
+
+	ret = set_flg(FLG_SELECT_WAIT, flgptn);
+	if (ret != E_OK) {
+		syslog(LOG_ERROR, "set_flg => %d", ret);
+	}
+}
+
+static void serial_rx_irq_handler(int fd)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	stdio_sio_t *uart = (stdio_sio_t *)((struct ntstdio_t *)fp->exinf)->exinf;
+	serial_t *serial = (serial_t *)&uart->serial;
+
+	if (serial_readable(serial)) {
+		unsigned char c = (unsigned char)serial_getc(serial);
+
+		if (fd != STDIN_FILENO) {
+			ER ret;
+			FLGPTN flgptn = 0;
+
+			uart->rx_buf[uart->rx_pos_w++] = c;
+			if (uart->rx_pos_w >= sizeof(uart->rx_buf))
+				uart->rx_pos_w = 0;
+
+			if (fp->readevt_w == fp->readevt_r) fp->readevt_w++;
+
+			FD_SET(fd, (fd_set *)&flgptn);
+
+			ret = set_flg(FLG_SELECT_WAIT, flgptn);
+			if (ret != E_OK) {
+				syslog(LOG_ERROR, "set_flg => %d", ret);
+			}
+		}
+		else
+			sio_isr_rcv(fp->handle, c);
+	}
+}
+
+static void ntstdio_xo(struct ntstdio_t *handle, struct SHELL_FILE *fp, unsigned char c)
+{
+	stdio_sio_t *uart = (stdio_sio_t *)handle->exinf;
+	serial_t *serial = (serial_t *)&uart->serial;
+	ER ret;
+
+	// タスクコンテキストでない場合
+	if (sense_context()) {
+		// 送信可能になるまで待ち
+		while (!serial_writable(serial));
+		// 送信する
+		serial_putc(serial, c);
+		return;
+	}
+
+	// 送信バッファが空で
+	if (uart->tx_pos_w == uart->tx_pos_r) {
+		// 送信可能なら
+		if (serial_writable(serial)) {
+			// 送信する
+			serial_putc(serial, c);
+			return;
+		}
+	}
+
+	// 送信バッファに追加する
+	uart->tx_buf[uart->tx_pos_w++] = c;
+	if (uart->tx_pos_w >= sizeof(uart->tx_buf))
+		uart->tx_pos_w = 0;
+
+	// 送信可能になったら割り込みをもらうよう設定
+	serial_irq_set(serial, TxIrq, true);
+
+	bool_t lock = sense_lock();
+	if (lock)
+		unl_cpu();
+
+	// 送信バッファが一杯なら
+	int tx_pos_w = uart->tx_pos_w + 1;
+	if (tx_pos_w >= sizeof(uart->tx_buf))
+		tx_pos_w = 0;
+	while (tx_pos_w == uart->tx_pos_r) {
+		FLGPTN flgptn = 0, waitptn = 0;
+		FD_SET(fp->fd, (fd_set *)&waitptn);
+
+		// 送信完了割り込みまで待つ
+		ret = twai_flg(FLG_SELECT_WAIT, waitptn, TWF_ORW, &flgptn, 1000);
+		if ((ret != E_OK) && (ret != E_TMOUT)) {
+			syslog(LOG_ERROR, "wai_flg => %d", ret);
+			break;
+		}
+
+		ret = clr_flg(FLG_SELECT_WAIT, ~(flgptn & waitptn));
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "clr_flg => %d", ret);
+		}
+	}
+
+	if (fp->writeevt_w != fp->writeevt_r) fp->writeevt_r++;
+
+	if (lock)
+		loc_cpu();
+}
+
+static void serial_tx_irq_handler(int fd)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	stdio_sio_t *uart = (stdio_sio_t *)((struct ntstdio_t *)fp->exinf)->exinf;
+	serial_t *serial = (serial_t *)&uart->serial;
+	ER ret;
+	unsigned char c;
+
+	if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
+
+	FLGPTN flgptn = 0;
+	FD_SET(fd, (fd_set *)&flgptn);
+
+	ret = set_flg(FLG_SELECT_WAIT, flgptn);
+	if (ret != E_OK) {
+		syslog(LOG_ERROR, "set_flg => %d", ret);
+	}
+
+	// 送信バッファが空なら
+	if (uart->tx_pos_w == uart->tx_pos_r) {
+		// SIOドライバの送信
+		sio_isr_snd(fp->handle);
+		// やっぱり送信バッファが空なら
+		if (uart->tx_pos_w == uart->tx_pos_r) {
+			// 送信割り込み停止
+			serial_irq_set(serial, TxIrq, false);
+			return;
+		}
+	}
+
+	c = uart->tx_buf[uart->tx_pos_r++];
+	if (uart->tx_pos_r >= sizeof(uart->tx_buf))
+		uart->tx_pos_r = 0;
+
+	// 送信する
+	serial_putc(serial, c);
+}
+
+void stdio_serial_irq_handler(uint32_t id, SerialIrq event)
+{
+	switch (event) {
+	case RxIrq:
+		serial_rx_irq_handler(STDIN_FILENO);
+		break;
+	case TxIrq:
+		serial_tx_irq_handler(STDOUT_FILENO);
+		break;
+	}
+}
+
+void sio_serial_irq_handler(uint32_t id, SerialIrq event)
+{
+	struct SHELL_FILE *fp = fd_to_fp(id);
+	if ((fp == NULL) || (fp->type != &IO_TYPE_SIO))
+		return;
+
+	switch (event) {
+	case RxIrq:
+		serial_rx_irq_handler(id);
+		break;
+	case TxIrq:
+		serial_tx_irq_handler(id);
+		break;
+	}
+}
+
+unsigned char stdio_xi(struct ntstdio_t *handle)
+{
+	return ntstdio_xi(handle, fd_to_fp(STDIN_FILENO));
+}
+
+void stdio_xo(struct ntstdio_t *handle, unsigned char c)
+{
+	ntstdio_xo(handle, fd_to_fp(STDOUT_FILENO), c);
+}
+
+unsigned char sio_xi(struct ntstdio_t *handle)
+{
+	return ntstdio_xi(handle, ((stdio_sio_t *)handle->exinf)->fp);
+}
+
+void sio_xo(struct ntstdio_t *handle, unsigned char c)
+{
+	ntstdio_xo(handle, ((stdio_sio_t *)handle->exinf)->fp, c);
+}
+
+int siofd_open(const char *path, int flags, ...)
+{
+	return -1;
+}
+
+int siofd_close(int fd)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || (fp->type != &IO_TYPE_SIO)) {
+		shell_errno = EBADF;
+		return -1;
+	}
+
+	shell_errno = sio_close(fp);
+	if (shell_errno != 0)
+		return 1;
+	return 0;
+}
+
+ssize_t siofd_read(int fd, void *data, size_t len)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || ((fp->type != &IO_TYPE_STDIN) && (fp->type != &IO_TYPE_SIO))) {
+		shell_errno = EBADF;
+		return -1;
+	}
+	char *pos, *end;
+
+	for (pos = (char *)data, end = &pos[len]; pos < end; pos++) {
+		*pos = ntstdio_xi((struct ntstdio_t *)fp->exinf, fp);
+	}
+
+	return pos - (char *)data;
+}
+
+ssize_t siofd_write(int fd, const void *data, size_t len)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || ((fp->type != &IO_TYPE_STDOUT) && (fp->type != &IO_TYPE_STDERR)
+		&& (fp->type != &IO_TYPE_SIO))) {
+		shell_errno = EBADF;
+		return -1;
+	}
+	const char *pos, *end;
+
+	for (pos = (const char *)data, end = &pos[len]; pos < end; pos++) {
+		ntstdio_xo((struct ntstdio_t *)fp->exinf, fp, *pos);
+	}
+
+	return pos - (char *)data;
+}
+
+int siofd_tcsetattr(int fd, int act, const struct termios *tio)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || ((fp->type != &IO_TYPE_STDIN) && (fp->type != &IO_TYPE_STDOUT)
+		&& (fp->type != &IO_TYPE_STDERR) && (fp->type != &IO_TYPE_SIO))) {
+		shell_errno = EBADF;
+		return -1;
+	}
+
+	shell_errno = sio_tcsetattr(fp, act, tio);
+	if (shell_errno != 0)
+		return 1;
+	return 0;
+}
+
+int siofd_tcgetattr(int fd, struct termios *tio)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || ((fp->type != &IO_TYPE_STDIN) && (fp->type != &IO_TYPE_STDOUT)
+		&& (fp->type != &IO_TYPE_STDERR) && (fp->type != &IO_TYPE_SIO))) {
+		shell_errno = EBADF;
+		return -1;
+	}
+
+	shell_errno = sio_tcgetattr(fp, tio);
+	if (shell_errno != 0)
+		return 1;
+	return 0;
+}
+
+int siofd_fcntl(int fd, int cmd, ...)
+{
+	struct SHELL_FILE *fp = fd_to_fp(fd);
+	if ((fp == NULL) || ((fp->type != &IO_TYPE_STDIN) && (fp->type != &IO_TYPE_STDOUT)
+		&& (fp->type != &IO_TYPE_STDERR) && (fp->type != &IO_TYPE_SIO))) {
+		shell_errno = EBADF;
+		return -1;
+	}
+	void *arg;
+	va_list ap;
+	va_start(ap, cmd);
+	arg = va_arg(ap, void *);
+	va_end(ap);
+
+	shell_errno = sio_ioctl(fp, cmd, arg);
+	if (shell_errno != 0)
+		return 1;
+	return 0;
+}
Index: /EcnlProtoTool/trunk/ntshell/src/syscall.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/syscall.c	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/syscall.c	(revision 441)
@@ -101,5 +101,5 @@
 	switch (r->n) {
 	case SYS__llseek:
-		return shell_llseek(r->a, (((off_t)r->b) << 32) + (off_t)r->c, (off_t *)r->d, r->e);
+		ret = shell_llseek(r->a, (((off_t)r->b) << 32) + (off_t)r->c, (off_t *)r->d, r->e);
 	case SYS__newselect:
 		ret = shell_select(r->a, (fd_set *)r->b, (fd_set *)r->c, (fd_set *)r->d, (struct timeval *)r->e);
@@ -359,5 +359,5 @@
 		break;
 	case SYS_gettid:
-		no_implement("gettid\n");
+		ret = shell_gettid();
 		break;
 	case SYS_gettimeofday:
@@ -439,5 +439,5 @@
 		break;
 	case SYS_lstat64:
-		ret = shell_lstat((const char *__restrict)r->a, (struct stat *__restrict)r->b);
+		ret = shell_lstat((const char *restrict)r->a, (struct stat *restrict)r->b);
 		break;
 	case SYS_madvise:
@@ -472,5 +472,5 @@
 		break;
 	case SYS_mprotect:
-		return shell_mprotect((void *)r->a, (size_t)r->b, r->c);
+		ret = shell_mprotect((void *)r->a, (size_t)r->b, r->c);
 		break;
 	case SYS_mq_getsetattr:
@@ -520,5 +520,5 @@
 		break;
 	case SYS_nanosleep:
-		no_implement("nanosleep\n");
+		ret = shell_nanosleep((const struct timespec *)r->a, (struct timespec *)r->b);
 		break;
 	case SYS_nice:
@@ -538,5 +538,5 @@
 		break;
 	case SYS_pipe:
-		no_implement("pipe\n");
+		ret = shell_pipe((int *)r->a);
 		break;
 	case SYS_pipe2:
@@ -601,11 +601,8 @@
 		break;
 	case SYS_recv:
-		ret = shell_recv(r->a, (void *)r->b, (size_t)r->c, r->d);
+		ret = shell_recvfrom(r->a, (void *)r->b, (size_t)r->c, r->d, NULL, NULL);
 		break;
 	case SYS_recvfrom:
-		if (r->e == 0)
-			ret = shell_recv(r->a, (void *)r->b, (size_t)r->c, r->d);
-		else
-			ret = shell_recvfrom(r->a, (void *)r->b, (size_t)r->c, r->d, (struct sockaddr *)r->e, (socklen_t *)r->f);
+		ret = shell_recvfrom(r->a, (void *)r->b, (size_t)r->c, r->d, (struct sockaddr *)r->e, (socklen_t *)r->f);
 		break;
 	case SYS_recvmsg:
@@ -634,5 +631,5 @@
 		break;
 	case SYS_rt_sigaction:
-		ret = shell_sigaction(r->a, (const struct sigaction *)r->b, (struct sigaction *)r->c);
+		ret = shell_sigaction(r->a, (const struct sigaction *)r->b, (struct sigaction *)r->c, (size_t)r->d);
 		break;
 	case SYS_rt_sigpending:
@@ -652,5 +649,5 @@
 		break;
 	case SYS_send:
-		ret = shell_send(r->a, (const void *)r->b, (size_t)r->c, r->d);
+		ret = shell_sendto(r->a, (const void *)r->b, (size_t)r->c, r->d, NULL, 0);
 		break;
 	case SYS_sendmsg:
@@ -658,8 +655,5 @@
 		break;
 	case SYS_sendto:
-		if (r->e == 0)
-			ret = shell_send(r->a, (const void *)r->b, (size_t)r->c, r->d);
-		else
-			ret = shell_sendto(r->a, (const void *)r->b, (size_t)r->c, r->d, (const struct sockaddr *)r->e, (socklen_t)r->f);
+		ret = shell_sendto(r->a, (const void *)r->b, (size_t)r->c, r->d, (const struct sockaddr *)r->e, (socklen_t)r->f);
 		break;
 	case SYS_setsockopt:
@@ -869,5 +863,5 @@
 		break;
 	case SYS_tkill:
-		no_implement("tkill\n");
+		ret = shell_tkill((int)r->a, (int)r->b);
 		break;
 	case SYS_truncate64:
@@ -918,4 +912,16 @@
 	case SYS_writev:
 		ret = shell_writev((int)r->a, (const struct iovec *)r->b, (size_t)r->c);
+		break;
+	case SYS_getpeername:
+		ret = shell_getpeername((int)r->a, (struct sockaddr *)r->b, (socklen_t *)r->c);
+		break;
+	case SYS_getsockname:
+		ret = shell_getsockname((int)r->a, (struct sockaddr *)r->b, (socklen_t *)r->c);
+		break;
+	case SYS_sigprocmask:
+		ret = shell_sigprocmask((int)r->a, (const sigset_t *)r->b, (sigset_t *)r->c);
+		break;
+	case SYS_sigaction:
+		ret = shell_sigaction((int)r->a, (const struct k_sigaction *)r->b, (struct k_sigaction *)r->c, (size_t)r->d);
 		break;
 	default:
Index: /EcnlProtoTool/trunk/ntshell/src/tSIOPortNTShell.cdl
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/tSIOPortNTShell.cdl	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/tSIOPortNTShell.cdl	(revision 441)
@@ -0,0 +1,119 @@
+/*
+ *  TOPPERS/ASP Kernel
+ *      Toyohashi Open Platform for Embedded Real-Time Systems/
+ *      Advanced Standard Profile Kernel
+ * 
+ *  Copyright (C) 2015 by Ushio Laboratory
+ *              Graduate School of Engineering Science, Osaka Univ., JAPAN
+ *  Copyright (C) 2015,2016 by Embedded and Real-Time Systems Laboratory
+ *              Graduate School of Information Science, Nagoya Univ., JAPAN
+ * 
+ *  上記著作権者は，以下の(1)〜(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  $Id$
+ */
+
+/*
+ *		シリアルインタフェースドライバのターゲット依存部（NTShell用）
+ *		のコンポーネント記述
+ */
+
+/*
+ *  NTShell に関する定義
+ */
+import_C("termios.h");
+
+/*
+ *  SIOドライバの本体のセルタイプ
+ */
+celltype tSIOPortNTShellMain {
+	/*
+	 *  シリアルインタフェースドライバとの結合
+	 */
+	entry				sSIOPort		eSIOPort;
+	[optional] call		siSIOCBR		ciSIOCBR;
+
+	/*
+	 *  終了処理ルーチン
+	 */
+	entry	sRoutineBody	eTerminate;
+
+	attr {
+		const char	*path;				/* パス名 */
+	};
+
+	var {
+		bool_t			opened = false;	/* オープン済みフラグ */
+		struct termios	saved_term;		/* 元の端末制御情報 */
+		int_t			read_fd;		/* 読出し用ファイルディスクリプタ */
+		bool_t			rcv_flag;		/* 受信文字バッファ有効フラグ */
+		char			rcv_buf;		/* 受信文字バッファ */
+		bool_t			rcv_rdy;		/* 受信通知コールバック許可フラグ */
+		int_t			write_fd;		/* 書込み用ファイルディスクリプタ */
+		bool_t			snd_flag;		/* 送信文字バッファ有効フラグ */
+		char			snd_buf;		/* 送信文字バッファ */
+		bool_t			snd_rdy;		/* 送信通知コールバック許可フラグ */
+	};
+};
+
+/*
+ *  SIOドライバ（複合コンポーネント）のセルタイプ
+ */
+[active]
+composite tSIOPortNTShell {
+	/*
+	 *  シリアルインタフェースドライバとの結合
+	 */
+	entry				sSIOPort	eSIOPort;
+	[optional] call		siSIOCBR	ciSIOCBR;
+
+	/*
+	 *  属性の定義
+	 */
+	attr {
+		const char	*path = C_EXP("NULL");		/* パス名 */
+	};
+
+	/*
+	 *  SIOドライバの本体
+	 */
+	cell tSIOPortNTShellMain SIOPortMain {
+		path     = composite.path;
+		ciSIOCBR => composite.ciSIOCBR;
+	};
+	composite.eSIOPort => SIOPortMain.eSIOPort;
+
+	/*
+	 *  SIOドライバの終了処理ルーチン
+	 */
+	cell tTerminateRoutine TerminateSIO {
+		cTerminateRoutineBody = SIOPortMain.eTerminate;
+	};
+};
Index: /EcnlProtoTool/trunk/ntshell/src/tSIOPortNTShellMain.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/tSIOPortNTShellMain.c	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/tSIOPortNTShellMain.c	(revision 441)
@@ -0,0 +1,257 @@
+/*
+ *  TOPPERS/ASP Kernel
+ *      Toyohashi Open Platform for Embedded Real-Time Systems/
+ *      Advanced Standard Profile Kernel
+ * 
+ *  Copyright (C) 2006-2018 by Embedded and Real-Time Systems Laboratory
+ *              Graduate School of Information Science, Nagoya Univ., JAPAN
+ * 
+ *  上記著作権者は，以下の(1)〜(4)の条件を満たす場合に限り，本ソフトウェ
+ *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
+ *  変・再配布（以下，利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次のいずれかの条件を満たすこ
+ *      と．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *    (b) 再配布の形態を，別に定める方法によって，TOPPERSプロジェクトに
+ *        報告すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *      また，本ソフトウェアのユーザまたはエンドユーザからのいかなる理
+ *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
+ *      免責すること．
+ * 
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
+ *  に対する適合性も含めて，いかなる保証も行わない．また，本ソフトウェ
+ *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
+ *  の責任を負わない．
+ * 
+ *  $Id$
+ */
+
+/*
+ *		シリアルインタフェースドライバのターゲット依存部（NTShell用）
+ */
+
+#include <t_stddef.h>
+#include <t_syslog.h>
+#include <errno.h> 
+#include <termios.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include "tSIOPortNTShellMain_tecsgen.h"
+#include "syssvc/siofd.h"
+ 
+extern int shell_errno;
+
+/*
+ *  SIOポートのオープン
+ */
+void
+eSIOPort_open(CELLIDX idx)
+{
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+	int_t	fd;
+	struct	termios term;
+
+	if (!VAR_opened) {
+		/*
+		 *  既にオープンしている場合は、二重にオープンしない．
+		 */
+		if (ATTR_path != NULL) {
+			fd = siofd_open(ATTR_path, O_RDWR, 0777);
+			assert(fd >= 0);
+			VAR_read_fd = fd;
+			VAR_write_fd = fd;
+		}
+		else {
+			fd = STDIN_FILENO;				/* 標準入出力を使う */
+			VAR_read_fd = STDIN_FILENO;
+			VAR_write_fd = STDOUT_FILENO;
+		}
+		siofd_fcntl(fd, F_SETOWN, getpid());
+		siofd_fcntl(fd, F_SETFL, (O_NONBLOCK | O_ASYNC));
+
+		siofd_tcgetattr(fd, &VAR_saved_term);
+		term = VAR_saved_term;
+		term.c_lflag &= ~(ECHO | ICANON);
+		siofd_tcsetattr(fd, TCSAFLUSH, &term);
+
+		VAR_rcv_flag = false;
+		VAR_rcv_rdy = false;
+		VAR_snd_flag = false;
+		VAR_snd_rdy = false;
+		VAR_opened = true;
+	}
+}
+
+/*
+ *  SIOポートのクローズ
+ */
+void
+eSIOPort_close(CELLIDX idx)
+{
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+	int_t	fd;
+
+	if (VAR_opened) {
+		fd = VAR_read_fd;
+		siofd_tcsetattr(fd, TCSAFLUSH, &VAR_saved_term);
+		siofd_fcntl(fd, F_SETFL, 0);
+
+		if (ATTR_path != NULL) {
+			siofd_close(VAR_read_fd);
+		}
+		VAR_opened = false;
+	}
+}
+
+/*
+ *  SIOポートへの文字送信
+ */
+bool_t
+eSIOPort_putChar(CELLIDX idx, char c)
+{
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+	int_t	n;
+
+	if (!VAR_snd_flag) {
+		if ((n = siofd_write(VAR_write_fd, &c, 1)) > 0) {
+			return(true);
+		}
+		else {
+			assert(n < 0 && shell_errno == EAGAIN);
+			VAR_snd_flag = true;
+			VAR_snd_buf = c;
+			return(true);
+		}
+	}
+	else {
+		return(false);
+	}
+}
+
+/*
+ *  SIOポートからの文字受信
+ */
+int_t
+eSIOPort_getChar(CELLIDX idx)
+{
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+	char	c;
+	int_t	n;
+
+	if (VAR_rcv_flag) {
+		VAR_rcv_flag = false;
+		return((int_t)(uint8_t)(VAR_rcv_buf));
+	}
+	else if ((n = siofd_read(VAR_read_fd, &c, 1)) > 0) {
+		return((int_t)(uint8_t) c);
+	}
+	else {
+		assert(n < 0 && shell_errno == EAGAIN);
+		return(-1);
+	}
+}
+
+/*
+ *  SIOポートからのコールバックの許可
+ */
+void
+eSIOPort_enableCBR(CELLIDX idx, uint_t cbrtn)
+{
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+
+	switch (cbrtn) {
+	case SIOSendReady:
+		VAR_snd_rdy = true;
+		break;
+	case SIOReceiveReady:
+		VAR_rcv_rdy = true;
+		break;
+	}
+}
+
+/*
+ *  SIOポートからのコールバックの禁止
+ */
+void
+eSIOPort_disableCBR(CELLIDX idx, uint_t cbrtn)
+{
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+
+	switch (cbrtn) {
+	case SIOSendReady:
+		VAR_snd_rdy = false;
+		break;
+	case SIOReceiveReady:
+		VAR_rcv_rdy = false;
+		break;
+	}
+}
+
+/*
+ *  SIOの割込みサービスルーチン
+ */
+bool_t
+sio_isr_snd(ID siopid)
+{
+	if (!(1 <= siopid && siopid <= tSIOPortNTShellMain_N_CELL))
+		return false;
+	CELLIDX idx = &tSIOPortNTShellMain_CB_tab[siopid - 1];
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+	int_t	n;
+
+	if (VAR_snd_flag) {
+		if ((n = siofd_write(VAR_write_fd, &(VAR_snd_buf), 1)) > 0) {
+			VAR_snd_flag = false;
+			if (VAR_snd_rdy) {
+				ciSIOCBR_readySend();
+				return VAR_snd_rdy;
+			}
+		}
+	}
+
+	return false;
+}
+
+/*
+ *  SIOの割込みサービスルーチン
+ */
+bool_t
+sio_isr_rcv(ID siopid, char c)
+{
+	if (!(1 <= siopid && siopid <= tSIOPortNTShellMain_N_CELL))
+		return false;
+	CELLIDX idx = &tSIOPortNTShellMain_CB_tab[siopid - 1];
+	CELLCB	*p_cellcb = GET_CELLCB(idx);
+
+	if (!VAR_rcv_flag) {
+		VAR_rcv_buf = c;
+		VAR_rcv_flag = true;
+		if (VAR_rcv_rdy) {
+			ciSIOCBR_readyReceive();
+			return VAR_rcv_rdy;
+		}
+	}
+
+	return false;
+}
+
+/*
+ *  SIOドライバの終了処理
+ */
+void
+eTerminate_main(CELLIDX idx)
+{
+	eSIOPort_close(idx);
+}
Index: /EcnlProtoTool/trunk/ntshell/src/tinet_app_config.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/tinet_app_config.h	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/tinet_app_config.h	(revision 441)
@@ -285,17 +285,7 @@
 #ifdef SUPPORT_ETHER
 
-#ifdef DHCP4_CLI_CFG
-
-#define IPV4_ADDR_LOCAL			MAKE_IPV4_ADDR(0,0,0,0)
-#define IPV4_ADDR_LOCAL_MASK		MAKE_IPV4_ADDR(0,0,0,0)
-#define IPV4_ADDR_DEFAULT_GW		MAKE_IPV4_ADDR(0,0,0,0)
-
-#else	/* of #ifdef DHCP4_CLI_CFG */
-
 #define IPV4_ADDR_LOCAL			MAKE_IPV4_ADDR(192,168,137,110)
-#define IPV4_ADDR_LOCAL_MASK		MAKE_IPV4_ADDR(255,255,255,0)
-#define IPV4_ADDR_DEFAULT_GW		MAKE_IPV4_ADDR(192,168,137,1)
-
-#endif	/* of #ifdef DHCP4_CLI_CFG */
+#define IPV4_ADDR_LOCAL_MASK	MAKE_IPV4_ADDR(255,255,255,0)
+#define IPV4_ADDR_DEFAULT_GW	MAKE_IPV4_ADDR(192,168,137,1)
 
 #define NUM_IN4_STATIC_ROUTE_ENTRY	3
Index: /EcnlProtoTool/trunk/ntshell/src/tinet_main.cfg
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/tinet_main.cfg	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/src/tinet_main.cfg	(revision 441)
@@ -2,5 +2,5 @@
  *  TOPPERS PROJECT Home Network Working Group Software
  * 
- *  Copyright (C) 2017-2019 Cores Co., Ltd. Japan
+ *  Copyright (C) 2014-2019 Cores Co., Ltd. Japan
  * 
  *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
Index: /EcnlProtoTool/trunk/ntshell/src/tinet_ntp_cli.cfg
===================================================================
--- /EcnlProtoTool/trunk/ntshell/src/tinet_ntp_cli.cfg	(revision 441)
+++ /EcnlProtoTool/trunk/ntshell/src/tinet_ntp_cli.cfg	(revision 441)
@@ -0,0 +1,45 @@
+/*
+ *  TINET (UDP/IP Protocol Stack)
+ * 
+ *  Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
+ *                   Tomakomai National College of Technology, JAPAN
+ *
+ *  上記著作権者は，以下の (1)～(4) の条件か，Free Software Foundation 
+ *  によって公表されている GNU General Public License の Version 2 に記
+ *  述されている条件を満たす場合に限り，本ソフトウェア（本ソフトウェア
+ *  を改変したものを含む．以下同じ）を使用・複製・改変・再配布（以下，
+ *  利用と呼ぶ）することを無償で許諾する．
+ *  (1) 本ソフトウェアをソースコードの形で利用する場合には，上記の著作
+ *      権表示，この利用条件および下記の無保証規定が，そのままの形でソー
+ *      スコード中に含まれていること．
+ *  (2) 本ソフトウェアを，ライブラリ形式など，他のソフトウェア開発に使
+ *      用できる形で再配布する場合には，再配布に伴うドキュメント（利用
+ *      者マニュアルなど）に，上記の著作権表示，この利用条件および下記
+ *      の無保証規定を掲載すること．
+ *  (3) 本ソフトウェアを，機器に組み込むなど，他のソフトウェア開発に使
+ *      用できない形で再配布する場合には，次の条件を満たすこと．
+ *    (a) 再配布に伴うドキュメント（利用者マニュアルなど）に，上記の著
+ *        作権表示，この利用条件および下記の無保証規定を掲載すること．
+ *  (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
+ *      害からも，上記著作権者およびTOPPERSプロジェクトを免責すること．
+ *
+ *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
+ *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，その適用可能性も
+ *  含めて，いかなる保証も行わない．また，本ソフトウェアの利用により直
+ *  接的または間接的に生じたいかなる損害に関しても，その責任を負わない．
+ * 
+ *  @(#) $Id$
+ */
+
+/*
+ *  NTP クライアント
+ *  TCP/IP コンフィギュレーションファイル
+ */
+
+/* UDP 通信端点 */
+
+UDP_CRE_CEP (NTP_CLI_CEPID, {
+	0,
+	{ IPV4_ADDRANY, UDP_PORTANY },
+	callback_nblk_ntp_cli
+	} );
Index: /EcnlProtoTool/trunk/ntshell/webserver/httpd-fs.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/webserver/httpd-fs.c	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/webserver/httpd-fs.c	(revision 441)
@@ -63,5 +63,5 @@
 #endif /* NULL */
 
-extern ntstdio_t ntstdio;
+extern ntstdio_t *ntstdio;
 
 /*-----------------------------------------------------------------------------------*/
@@ -89,5 +89,5 @@
 			}
 			else {
-				ntstdio_printf(&ntstdio, "%s/%s\n", path, fn);
+				ntstdio_printf(ntstdio, "%s/%s\n", path, fn);
 			}
 		}
@@ -114,10 +114,10 @@
 	if ((res = f_open(fd, name, FA_OPEN_EXISTING | FA_READ)) != FR_OK) {
 		if ((res = f_opendir(&dir, name)) != FR_OK) {
-			ntstdio_printf(&ntstdio, "f_opendir(%s) => %d\n", name, res);
+			ntstdio_printf(ntstdio, "f_opendir(%s) => %d\n", name, res);
 			return 0;
 		}
 
 		if ((res = f_readdir(&dir, &fno)) != FR_OK) {
-			ntstdio_printf(&ntstdio, "f_readdir(%s) => %d\n", name, res);
+			ntstdio_printf(ntstdio, "f_readdir(%s) => %d\n", name, res);
 			return 0;
 		}
@@ -132,5 +132,5 @@
 
 		if (res != FR_OK) {
-			ntstdio_printf(&ntstdio, "f_open(%s) => %d %x\n", name, res, fno.fattrib);
+			ntstdio_printf(ntstdio, "f_open(%s) => %d %x\n", name, res, fno.fattrib);
 			return 0;
 		}
@@ -139,5 +139,5 @@
 	file->len = fd->fsize;
 
-	//ntstdio_printf(&ntstdio, "httpd_fs_open(%s) %d\n", name, file->len);
+	//ntstdio_printf(ntstdio, "httpd_fs_open(%s) %d\n", name, file->len);
 
 	return 1;
@@ -158,5 +158,5 @@
 
 	if ((res = f_open(fd, name, FA_CREATE_ALWAYS | FA_WRITE)) != FR_OK) {
-		ntstdio_printf(&ntstdio, "f_open(%s) => %d\n", name, res);
+		ntstdio_printf(ntstdio, "f_open(%s) => %d\n", name, res);
 		return 0;
 	}
@@ -165,5 +165,5 @@
 	file->len = 0;
 
-	//ntstdio_printf(&ntstdio, "httpd_fs_create(%s) %d\n", file->name, file->len);
+	//ntstdio_printf(ntstdio, "httpd_fs_create(%s) %d\n", file->name, file->len);
 
 	return 1;
@@ -179,18 +179,18 @@
 
 	if ((ret = f_lseek(fd, file->pos)) != FR_OK) {
-		ntstdio_printf(&ntstdio, "f_lseek(%s, %d) => %d\n", file->name, file->pos, ret);
+		ntstdio_printf(ntstdio, "f_lseek(%s, %d) => %d\n", file->name, file->pos, ret);
 		return 0;
 	}
 
 	if (file->pos != fd->fptr) {
-		ntstdio_printf(&ntstdio, "f_lseek(%s, %d) != %d\n", file->name, file->pos, fd->fptr);
+		ntstdio_printf(ntstdio, "f_lseek(%s, %d) != %d\n", file->name, file->pos, fd->fptr);
 	}
 
 	if ((ret = f_read(fd, dst, len, &rlen)) != FR_OK) {
-		ntstdio_printf(&ntstdio, "f_read(%s, 0x%p, %d) => %d\n", file->name, dst, len, ret);
-		return 0;
-	}
-
-	//ntstdio_printf(&ntstdio, "httpd_fs_read(%s, %d, %d) => %d\n", file->name, file->pos, len, rlen);
+		ntstdio_printf(ntstdio, "f_read(%s, 0x%p, %d) => %d\n", file->name, dst, len, ret);
+		return 0;
+	}
+
+	//ntstdio_printf(ntstdio, "httpd_fs_read(%s, %d, %d) => %d\n", file->name, file->pos, len, rlen);
 
 	return rlen;
@@ -206,14 +206,14 @@
 
 	if ((ret = f_lseek(fd, file->pos)) != FR_OK) {
-		ntstdio_printf(&ntstdio, "f_lseek(%s, %d) => %d\n", file->name, file->pos, ret);
+		ntstdio_printf(ntstdio, "f_lseek(%s, %d) => %d\n", file->name, file->pos, ret);
 		return 0;
 	}
 
 	if (file->pos != fd->fptr) {
-		ntstdio_printf(&ntstdio, "f_lseek(%s, %d) != %d\n", file->name, file->pos, fd->fptr);
+		ntstdio_printf(ntstdio, "f_lseek(%s, %d) != %d\n", file->name, file->pos, fd->fptr);
 	}
 
 	if ((ret = f_write(fd, src, len, &rlen)) != FR_OK) {
-		ntstdio_printf(&ntstdio, "f_write(%s, 0x%p, %d) => %d\n", file->name, src, len, ret);
+		ntstdio_printf(ntstdio, "f_write(%s, 0x%p, %d) => %d\n", file->name, src, len, ret);
 		return 0;
 	}
@@ -222,5 +222,5 @@
 	file->len += rlen;
 
-	//ntstdio_printf(&ntstdio, "httpd_fs_write(%s, %d, %d) => %d\n", file->name, file->pos, len, rlen);
+	//ntstdio_printf(ntstdio, "httpd_fs_write(%s, %d, %d) => %d\n", file->name, file->pos, len, rlen);
 
 	return rlen;
@@ -234,5 +234,5 @@
 
 	if ((ret = f_close(fd)) != FR_OK) {
-		ntstdio_printf(&ntstdio, "f_close(%s) => %d\n", file->name, ret);
+		ntstdio_printf(ntstdio, "f_close(%s) => %d\n", file->name, ret);
 		return 0;
 	}
Index: /EcnlProtoTool/trunk/ntshell/webserver/httpd.c
===================================================================
--- /EcnlProtoTool/trunk/ntshell/webserver/httpd.c	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/webserver/httpd.c	(revision 441)
@@ -59,5 +59,5 @@
 #define FALSE 0
 
-extern ntstdio_t ntstdio;
+extern ntstdio_t *ntstdio;
 SYSTIM httpd_time;
 struct httpd_state *uploding;
@@ -65,8 +65,17 @@
 
 /*  TCP 送受信ウィンドバッファ  */
+#ifdef SUPPORT_INET6
+uint8_t tcp6_swbuf1[TCP_SWBUF_SIZE];
+uint8_t tcp6_rwbuf1[TCP_RWBUF_SIZE];
+uint8_t tcp6_swbuf2[TCP_SWBUF_SIZE];
+uint8_t tcp6_rwbuf2[TCP_RWBUF_SIZE];
+#endif
+
+#ifdef SUPPORT_INET4
 uint8_t tcp_swbuf1[TCP_SWBUF_SIZE];
 uint8_t tcp_rwbuf1[TCP_RWBUF_SIZE];
 uint8_t tcp_swbuf2[TCP_SWBUF_SIZE];
 uint8_t tcp_rwbuf2[TCP_RWBUF_SIZE];
+#endif
 
 #define ISO_nl      0x0a
@@ -325,5 +334,5 @@
 			// アップロード先はSDカード
 			s->filename[0] = '1';
-			ntstdio_printf(&ntstdio, "create:    %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);
+			ntstdio_printf(ntstdio, "create:    %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);
 			if (!httpd_fs_create(s->filename, &s->file)) {
 				goto error;
@@ -333,5 +342,5 @@
 		}
 		else if (ntlibc_strcmp(s->filename, uploding->filename) == 0) {
-			ntstdio_printf(&ntstdio, "collision: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);
+			ntstdio_printf(ntstdio, "collision: %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);
 			goto error;
 		}
@@ -365,5 +374,5 @@
 
 	if (s->message.body_is_final) {
-		ntstdio_printf(&ntstdio, "\n\n *** Error http_body_is_final() should return 1 \n"
+		ntstdio_printf(ntstdio, "\n\n *** Error http_body_is_final() should return 1 \n"
 			"on last on_body callback call "
 			"but it doesn't! ***\n\n");
@@ -378,5 +387,5 @@
 
 	if (s->message.body_is_final) {
-		ntstdio_printf(&ntstdio, "close:     %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);
+		ntstdio_printf(ntstdio, "close:     %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);
 		httpd_fs_close(&s->file);
 		memset(&s->file, 0, sizeof(s->file));
@@ -403,5 +412,5 @@
 	struct httpd_state *s = get_context(p);
 	if (s->message.should_keep_alive != http_should_keep_alive(p)) {
-		ntstdio_printf(&ntstdio, "\n\n *** Error http_should_keep_alive() should have same \n"
+		ntstdio_printf(ntstdio, "\n\n *** Error http_should_keep_alive() should have same \n"
 			"value in both on_message_complete and on_headers_complete "
 			"but it doesn't! ***\n\n");
@@ -412,5 +421,5 @@
 		http_body_is_final(p) &&
 		!s->message.body_is_final) {
-		ntstdio_printf(&ntstdio, "\n\n *** Error http_body_is_final() should return 1 \n"
+		ntstdio_printf(ntstdio, "\n\n *** Error http_body_is_final() should return 1 \n"
 			"on last on_body callback call "
 			"but it doesn't! ***\n\n");
@@ -484,5 +493,5 @@
 		slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR);
 		if (slen < 0) {
-			ntstdio_printf(&ntstdio, "send_file#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
+			ntstdio_printf(ntstdio, "send_file#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
 			s->state = STATE_CLOSING;
 			break;
@@ -497,5 +506,5 @@
 		len = httpd_fs_read(&s->file, buf, len);
 		if (len <= 0) {
-			ntstdio_printf(&ntstdio, "send_file#httpd_fs_read(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, len);
+			ntstdio_printf(ntstdio, "send_file#httpd_fs_read(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, len);
 			break;
 		}
@@ -505,5 +514,5 @@
 
 		if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) {
-			ntstdio_printf(&ntstdio, "send_file#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
+			ntstdio_printf(ntstdio, "send_file#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
 			s->state = STATE_CLOSING;
 			break;
@@ -511,5 +520,5 @@
 	}
 
-	ntstdio_printf(&ntstdio, "close:     %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);
+	ntstdio_printf(ntstdio, "close:     %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);
 	httpd_fs_close(&s->file);
 	s->file.len = 0;
@@ -527,5 +536,5 @@
 		slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR);
 		if (slen < 0) {
-			ntstdio_printf(&ntstdio, "send_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
+			ntstdio_printf(ntstdio, "send_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
 			s->state = STATE_CLOSING;
 			break;
@@ -544,5 +553,5 @@
 
 		if ((slen = tcp_snd_buf(s->cepid, len)) != E_OK) {
-			ntstdio_printf(&ntstdio, "send_data#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
+			ntstdio_printf(ntstdio, "send_data#tcp_snd_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
 			s->state = STATE_CLOSING;
 			break;
@@ -690,5 +699,5 @@
 		break;
 	case OUT_STATE_OPEN_GET_FILE:
-		ntstdio_printf(&ntstdio, "open:      %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);
+		ntstdio_printf(ntstdio, "open:      %s.%d %s\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->filename);
 		if (!httpd_fs_open(s->filename, sizeof(s->message.request_url), &s->file)) {
 			s->filename = NULL;
@@ -704,26 +713,26 @@
 		break;
 	case OUT_STATE_WAIT_POST_BODY:
-		//ntstdio_printf(&ntstdio, "wait post body\n");
+		//ntstdio_printf(ntstdio, "wait post body\n");
 		s->out.wait = true;
 		break;
 	case OUT_STATE_BODY_RECEIVED:
-		//ntstdio_printf(&ntstdio, "body received\n");
+		//ntstdio_printf(ntstdio, "body received\n");
 		s->out.statushdr = http_header_200;
 		s->out.state = OUT_STATE_SEND_HEADER;
 		break;
 	case OUT_STATE_SEND_HEADER:
-		//ntstdio_printf(&ntstdio, "send header\n");
+		//ntstdio_printf(ntstdio, "send header\n");
 		send_headers(s, s->out.statushdr);
 		break;
 	case OUT_STATE_SEND_FILE:
-		//ntstdio_printf(&ntstdio, "send file %d\n", s->file.len);
+		//ntstdio_printf(ntstdio, "send file %d\n", s->file.len);
 		send_file(s);
 		break;
 	case OUT_STATE_SEND_DATA:
-		//ntstdio_printf(&ntstdio, "send data %d\n", s->response_len);
+		//ntstdio_printf(ntstdio, "send data %d\n", s->response_len);
 		send_data(s);
 		break;
 	case OUT_STATE_SEND_END:
-		//ntstdio_printf(&ntstdio, "send end\n");
+		//ntstdio_printf(ntstdio, "send end\n");
 		s->out.wait = true;
 		if (s->message.should_keep_alive && s->reset == 0) {
@@ -783,5 +792,5 @@
 	slen = tcp_get_buf(s->cepid, (void **)&buf, TMO_FEVR);
 	if (slen < 0) {
-		ntstdio_printf(&ntstdio, "send_ws_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
+		ntstdio_printf(ntstdio, "send_ws_data#tcp_get_buf(%s.%d) => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, slen);
 		return;
 	}
@@ -847,5 +856,5 @@
 				//}
 			}
-			ntstdio_printf(&ntstdio, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len);
+			ntstdio_printf(ntstdio, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len);
 			uploding = NULL;
 			s->state = STATE_CLOSING;
@@ -855,5 +864,5 @@
 		tcp_rel_buf(s->cepid, done);
 		if (s->parser.http_errno != HPE_OK) {
-			ntstdio_printf(&ntstdio, "http_parser error %s.%d => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->parser.http_errno);
+			ntstdio_printf(ntstdio, "http_parser error %s.%d => %d\n", s->addr, ((T_IPV4EP *)s->dst)->portno, s->parser.http_errno);
 			uploding = NULL;
 			s->state = STATE_CLOSING;
@@ -880,5 +889,5 @@
 					break;
 				}
-				ntstdio_printf(&ntstdio, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len);
+				ntstdio_printf(ntstdio, "handle_input#tcp_rcv_buf#%d(%s.%d) => %d\n", s->in.state, s->addr, ((T_IPV4EP *)s->dst)->portno, len);
 				s->state = STATE_CLOSING;
 				break;
@@ -918,7 +927,7 @@
 
 	if (s == NULL)
-		ntstdio_printf(&ntstdio, "callback_nblk_tcp(%d, %d)\n", fncd, cepid);
+		ntstdio_printf(ntstdio, "callback_nblk_tcp(%d, %d)\n", fncd, cepid);
 	else
-		ntstdio_printf(&ntstdio, "callback_nblk_tcp(%d, %s.%d)\n", fncd, s->addr, ((T_IPV4EP *)s->dst)->portno);
+		ntstdio_printf(ntstdio, "callback_nblk_tcp(%d, %s.%d)\n", fncd, s->addr, ((T_IPV4EP *)s->dst)->portno);
 
 	return E_PAR;
@@ -936,5 +945,5 @@
 		ret2 = get_tim(&httpd_time);
 		if (ret2 != E_OK) {
-			ntstdio_printf(&ntstdio, "get_tim\n");
+			ntstdio_printf(ntstdio, "get_tim\n");
 			return;
 		}
@@ -944,5 +953,5 @@
 			memset(&s->dst, 0, sizeof(s->dst));
 			if ((ret = tcp_acp_cep(s->cepid, TCP_REPID, (T_IPV4EP *)s->dst, TMO_FEVR)) != E_OK) {
-				ntstdio_printf(&ntstdio, "tcp_acp_cep(%d) => %d\n", s->cepid, ret);
+				ntstdio_printf(ntstdio, "tcp_acp_cep(%d) => %d\n", s->cepid, ret);
 				tslp_tsk(100 * 1000);	// TODO
 				s->state = STATE_CLOSING;
@@ -950,5 +959,5 @@
 			}
 			IP2STR(s->addr, &((T_IPV4EP *)s->dst)->ipaddr);
-			ntstdio_printf(&ntstdio, "connected: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno);
+			ntstdio_printf(ntstdio, "connected: %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno);
 			memset(&s->in, 0, sizeof(s->in));
 			memset(&s->out, 0, sizeof(s->out));
@@ -965,5 +974,5 @@
 			break;
 		case STATE_CLOSING:
-			ntstdio_printf(&ntstdio, "close:     %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno);
+			ntstdio_printf(ntstdio, "close:     %s.%d\n", s->addr, ((T_IPV4EP *)s->dst)->portno);
 			tcp_sht_cep(s->cepid);
 			tcp_cls_cep(s->cepid, TMO_FEVR);
Index: /EcnlProtoTool/trunk/ntshell/webserver/httpd.h
===================================================================
--- /EcnlProtoTool/trunk/ntshell/webserver/httpd.h	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/webserver/httpd.h	(revision 441)
@@ -57,6 +57,6 @@
  /*  TCP 送受信ウィンドバッファサイズ  */
 
-#define TCP_SWBUF_SIZE	512
-#define TCP_RWBUF_SIZE	512
+#define TCP_SWBUF_SIZE	1024
+#define TCP_RWBUF_SIZE	1024
 
 /*
@@ -66,9 +66,17 @@
 
  /*  TCP 送受信ウィンドバッファ  */
-
+#ifdef SUPPORT_INET6
+extern uint8_t tcp6_swbuf1[];
+extern uint8_t tcp6_rwbuf1[];
+extern uint8_t tcp6_swbuf2[];
+extern uint8_t tcp6_rwbuf2[];
+#endif
+
+#ifdef SUPPORT_INET4
 extern uint8_t tcp_swbuf1[];
 extern uint8_t tcp_rwbuf1[];
 extern uint8_t tcp_swbuf2[];
 extern uint8_t tcp_rwbuf2[];
+#endif
 
 /* HTTPサーバータスク */
Index: /EcnlProtoTool/trunk/ntshell/webserver/tinet_httpd.cfg
===================================================================
--- /EcnlProtoTool/trunk/ntshell/webserver/tinet_httpd.cfg	(revision 440)
+++ /EcnlProtoTool/trunk/ntshell/webserver/tinet_httpd.cfg	(revision 441)
@@ -62,7 +62,7 @@
 TCP6_CRE_CEP (TCP6_CEPID1, {
 	0,
-	tcp_swbuf1,
+	tcp6_swbuf1,
 	TCP_SWBUF_SIZE,
-	tcp_rwbuf1,
+	tcp6_rwbuf1,
 	TCP_RWBUF_SIZE,
 	(FP)callback_nblk_tcp
@@ -71,7 +71,7 @@
 TCP6_CRE_CEP (TCP6_CEPID2, {
 	0,
-	tcp_swbuf2,
+	tcp6_swbuf2,
 	TCP_SWBUF_SIZE,
-	tcp_rwbuf2,
+	tcp6_rwbuf2,
 	TCP_RWBUF_SIZE,
 	(FP)callback_nblk_tcp
Index: /EcnlProtoTool/trunk/prototool/src/linker_scriptDebug.ld
===================================================================
--- /EcnlProtoTool/trunk/prototool/src/linker_scriptDebug.ld	(revision 440)
+++ /EcnlProtoTool/trunk/prototool/src/linker_scriptDebug.ld	(revision 441)
@@ -8,6 +8,6 @@
 
 MEMORY {
-	BOOT_LOADER (rx) : ORIGIN = 0x18000000, LENGTH = 0x00220000
-	ROM (rx)         : ORIGIN = 0x18220000, LENGTH = 0x005E0000
+	BOOT_LOADER (rx) : ORIGIN = 0x18000000, LENGTH = 0x00200000
+	ROM (rx)         : ORIGIN = 0x18200000, LENGTH = 0x00600000
 	RAM (xrw)        : ORIGIN = 0x20100000, LENGTH = 8M
 }
