Index: EcnlProtoTool/trunk/asp3_dcre/tinet/netinet/ip_input.c
===================================================================
--- EcnlProtoTool/trunk/asp3_dcre/tinet/netinet/ip_input.c	(revision 321)
+++ EcnlProtoTool/trunk/asp3_dcre/tinet/netinet/ip_input.c	(revision 331)
@@ -2,5 +2,5 @@
  *  TINET (TCP/IP Protocol Stack)
  * 
- *  Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
+ *  Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
  *                   Tomakomai National College of Technology, JAPAN
  *
@@ -77,4 +77,5 @@
 #include <t_syslog.h>
 #include "kernel_cfg.h"
+#include "tinet_cfg.h"
 
 #endif	/* of #ifdef TARGET_KERNEL_ASP */
@@ -85,4 +86,5 @@
 #include <t_services.h>
 #include "kernel_id.h"
+#include "tinet_id.h"
 
 #endif	/* of #ifdef TARGET_KERNEL_JSP */
@@ -97,4 +99,5 @@
 #include <net/ppp_ipcp.h>
 #include <net/net.h>
+#include <net/net_endian.h>
 #include <net/net_buf.h>
 #include <net/net_count.h>
@@ -107,8 +110,8 @@
 #include <netinet/ip_icmp.h>
 #include <netinet/tcp.h>
-#include <netinet/tcp_timer.h>
 #include <netinet/tcp_var.h>
 #include <netinet/udp.h>
 #include <netinet/udp_var.h>
+#include <netinet/ip_igmp.h>
 
 #if defined(SUPPORT_IPSEC)
@@ -122,4 +125,6 @@
 
 #include <net/if_var.h>
+
+#if defined(_IP4_CFG)
 
 /*
@@ -345,14 +350,16 @@
 ip_remove_options (T_NET_BUF *nbuf)
 {
-	T_IP_HDR	*iph;
-
-	iph  = GET_IP_HDR(nbuf);
-
-	if (GET_IP_HDR_SIZE(iph) > IP4_HDR_SIZE) {
-		memmove((char *)iph + IP4_HDR_SIZE, GET_IP_SDU(nbuf),
-		        (size_t)(iph->len - GET_IP_HDR_SIZE(iph)));
+	T_IP4_HDR	*iph;
+	uint_t		hdr_size;
+
+	iph  = GET_IP4_HDR(nbuf);
+	hdr_size = GET_IP4_HDR_SIZE(nbuf);
+
+	if (hdr_size > IP4_HDR_SIZE) {
+		memmove((char *)iph + IP4_HDR_SIZE, GET_IP4_SDU(nbuf),
+		        (size_t)(iph->len - hdr_size));
 		iph->vhl   = IP4_MAKE_VHL(IPV4_VERSION, IP4_HDR_SIZE >> 2);
-		iph->len  -= (uint16_t)(GET_IP_HDR_SIZE(iph) - IP4_HDR_SIZE);
-		nbuf->len -= (uint16_t)(GET_IP_HDR_SIZE(iph) - IP4_HDR_SIZE);
+		iph->len  -= (uint16_t)(hdr_size - IP4_HDR_SIZE);
+		nbuf->len -= (uint16_t)(hdr_size - IP4_HDR_SIZE);
 		}
 
@@ -389,6 +396,6 @@
 		}
 
-	ip4h  = GET_IP4_HDR(input);
-	hlen = GET_IP4_HDR_SIZE(ip4h);
+	ip4h = GET_IP4_HDR(input);
+	hlen = GET_IP4_HDR_SIZE(input);
 
 	/* バージョンをチェックする。*/
@@ -429,5 +436,5 @@
 	/* 送信元アドレスをチェックする。*/
 	src = ntohl(ip4h->src);
-	bc  = (ifp->in_ifaddr.addr & ifp->in_ifaddr.mask) | ~ifp->in_ifaddr.mask;
+	bc  = (ifp->in4_ifaddr.addr & ifp->in4_ifaddr.mask) | ~ifp->in4_ifaddr.mask;
 
 #ifdef SUPPORT_LOOP
@@ -441,5 +448,5 @@
 #else	/* of #ifdef SUPPORT_LOOP */
 
-	if (src == ifp->in_ifaddr.addr || src == bc || src == IPV4_ADDR_BROADCAST || src == IPV4_ADDRANY) {
+	if (src == ifp->in4_ifaddr.addr || src == bc || src == IPV4_ADDR_BROADCAST || src == IPV4_ADDRANY) {
 		NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
 		NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
@@ -459,16 +466,27 @@
 	 */
 
-	if ((ifp->in_ifaddr.addr != IPV4_ADDRANY) &&
-	    (!(dst == ifp->in_ifaddr.addr || dst == bc ||
-	       dst == IPV4_ADDR_BROADCAST || dst == IPV4_ADDRANY))) {
+#if defined(ETHER_CFG_MULTICAST)
+	if ((ifp->in4_ifaddr.addr != IPV4_ADDRANY) &&
+		(!(dst == ifp->in4_ifaddr.addr || dst == bc ||
+		   dst == IPV4_ADDR_BROADCAST  || dst == IPV4_ADDRANY ||
+		  IN4_IS_ADDR_MULTICAST(dst)))) {
 		NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
 		NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
 		goto buf_rel;
 		}
+#else
+	if ((ifp->in4_ifaddr.addr != IPV4_ADDRANY) &&
+	    (!(dst == ifp->in4_ifaddr.addr || dst == bc ||
+	       dst == IPV4_ADDR_BROADCAST  || dst == IPV4_ADDRANY))) {
+		NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
+		NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
+		goto buf_rel;
+		}
+#endif
 
 #else	/* of #ifdef DHCP_CFG */
 
 #if defined(ETHER_CFG_MULTICAST)
-	if (!(dst == ifp->in_ifaddr.addr || dst == bc ||
+	if (!(dst == ifp->in4_ifaddr.addr || dst == bc ||
 		  dst == IPV4_ADDR_BROADCAST || dst == IPV4_ADDRANY ||
 		  IN4_IS_ADDR_MULTICAST(dst))) {
@@ -478,6 +496,6 @@
 		}
 #else
-	if (!(dst == ifp->in_ifaddr.addr || dst == bc ||
-	      dst == IPV4_ADDR_BROADCAST || dst == IPV4_ADDRANY)) {
+	if (!(dst == ifp->in4_ifaddr.addr || dst == bc ||
+	      dst == IPV4_ADDR_BROADCAST  || dst == IPV4_ADDRANY)) {
 		NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
 		NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
@@ -525,13 +543,5 @@
 	switch (ip4h->proto) {
 
-#ifdef SUPPORT_UDP
-	case IPPROTO_UDP:
-		NET_COUNT_MIB(ip_stats.ipInDelivers, 1);
-		udp_input(&input, &off, NULL);
-		return;
-		break;
-#endif	/* of #ifdef SUPPORT_UDP */
-
-#ifdef SUPPORT_TCP
+#if defined(SUPPORT_TCP)
 	case IPPROTO_TCP:
 		NET_COUNT_MIB(ip_stats.ipInDelivers, 1);
@@ -539,5 +549,14 @@
 		return;
 		break;
-#endif	/* of #ifdef SUPPORT_UDP */
+#endif	/* of #if defined(SUPPORT_TCP) */
+
+#if defined(SUPPORT_UDP) && ( (TNUM_UDP4_CEPID > 0) || \
+                             ((TNUM_UDP6_CEPID > 0) && defined(API_CFG_IP4MAPPED_ADDR)))
+	case IPPROTO_UDP:
+		NET_COUNT_MIB(ip_stats.ipInDelivers, 1);
+		udp4_input(&input, &off, NULL);
+		return;
+		break;
+#endif	/* of #if defined(SUPPORT_UDP) && TNUM_UDP4_CEPID > 0 */
 
 	case IPPROTO_ICMP:
@@ -546,4 +565,12 @@
 		return;
 		break;
+
+#if defined(SUPPORT_IGMP)
+	case IPPROTO_IGMP:
+		NET_COUNT_MIB(ip_stats.ipInDelivers, 1);
+		igmp_input(&input, &off, NULL);
+		return;
+		break;
+#endif /* of #ifdef UDP_CFG_EXTENTIONS */
 
 #if defined(SUPPORT_IPSEC)
@@ -560,5 +587,5 @@
 
 		/* ローカル IP アドレスに届いたデータグラムのみ ICMP エラーを通知する。*/
-		if (dst == ifp->in_ifaddr.addr) {
+		if (dst == ifp->in4_ifaddr.addr) {
 			T_IN4_ADDR	src;
 
@@ -578,2 +605,4 @@
 	syscall(rel_net_buf(input));
 	}
+
+#endif	/* of #if defined(_IP4_CFG) */
