diff --git a/include/nuttx/net/ip.h b/include/nuttx/net/ip.h index e0cc84f337..59088d9059 100644 --- a/include/nuttx/net/ip.h +++ b/include/nuttx/net/ip.h @@ -219,11 +219,6 @@ extern "C" /* Well-known IP addresses */ -#ifdef CONFIG_NET_IPv4 -EXTERN const in_addr_t g_ipv4_alloneaddr; /* An address of all ones */ -EXTERN const in_addr_t g_ipv4_allzeroaddr; /* An address of all zeroes */ -#endif - #ifdef CONFIG_NET_IPv6 EXTERN const net_ipv6addr_t g_ipv6_alloneaddr; /* An address of all ones */ EXTERN const net_ipv6addr_t g_ipv6_allzeroaddr; /* An address of all zeroes */ diff --git a/net/arp/arp_send.c b/net/arp/arp_send.c index 1e5ed4ab16..fbb6bdd6ae 100644 --- a/net/arp/arp_send.c +++ b/net/arp/arp_send.c @@ -232,7 +232,7 @@ int arp_send(in_addr_t ipaddr) /* Get the device that can route this request */ #ifdef CONFIG_NETDEV_MULTINIC - dev = netdev_findby_ipv4addr(g_ipv4_allzeroaddr, ipaddr); + dev = netdev_findby_ipv4addr(INADDR_ANY, ipaddr); #else dev = netdev_findby_ipv4addr(ipaddr); #endif diff --git a/net/devif/devif_initialize.c b/net/devif/devif_initialize.c index 1b7f7abd23..58fcd8cd03 100644 --- a/net/devif/devif_initialize.c +++ b/net/devif/devif_initialize.c @@ -69,19 +69,11 @@ struct net_stats_s g_netstats; uint16_t g_ipid; -#ifdef CONFIG_NET_IPv4 - -const in_addr_t g_ipv4_alloneaddr = 0xffffffff; -const in_addr_t g_ipv4_allzeroaddr = 0x00000000; - +#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_TCP_REASSEMBLY) /* Reassembly timer (units: deci-seconds) */ -#ifdef CONFIG_NET_TCP_REASSEMBLY - uint8_t g_reassembly_timer; - -#endif /* CONFIG_NET_TCP_REASSEMBLY */ -#endif /* CONFIG_NET_IPv4 */ +#endif #ifdef CONFIG_NET_IPv6 diff --git a/net/devif/ipv4_input.c b/net/devif/ipv4_input.c index badd165464..919471a3e5 100644 --- a/net/devif/ipv4_input.c +++ b/net/devif/ipv4_input.c @@ -85,6 +85,7 @@ #include #include +#include #include #include @@ -377,16 +378,16 @@ int ipv4_input(FAR struct net_driver_s *dev) #endif /* CONFIG_NET_TCP_REASSEMBLY */ } +#if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP) /* If IP broadcast support is configured, we check for a broadcast * UDP packet, which may be destined to us (even if there is no IP * address yet assigned to the device as is the case when we are * negotiating over DHCP for an address). */ -#if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP) if (pbuf->proto == IP_PROTO_UDP && net_ipv4addr_cmp(net_ip4addr_conv32(pbuf->destipaddr), - g_ipv4_alloneaddr)) + INADDR_BROADCAST)) { return udp_ipv4_input(dev); } @@ -399,14 +400,14 @@ int ipv4_input(FAR struct net_driver_s *dev) else #endif #ifdef CONFIG_NET_ICMP - if (net_ipv4addr_cmp(dev->d_ipaddr, g_ipv4_allzeroaddr)) + if (net_ipv4addr_cmp(dev->d_ipaddr, INADDR_ANY)) { +#ifdef CONFIG_NET_PINGADDRCONF /* If we are configured to use ping IP address configuration and * hasn't been assigned an IP address yet, we accept all ICMP * packets. */ -#ifdef CONFIG_NET_PINGADDRCONF if (pbuf->proto == IP_PROTO_ICMP) { nlldbg("Possible ping config packet received\n"); @@ -476,17 +477,17 @@ int ipv4_input(FAR struct net_driver_s *dev) break; #endif +#ifdef CONFIG_NET_ICMP /* Check for ICMP input */ -#ifdef CONFIG_NET_ICMP case IP_PROTO_ICMP: /* ICMP input */ icmp_input(dev); break; #endif +#ifdef CONFIG_NET_IGMP /* Check for IGMP input */ -#ifdef CONFIG_NET_IGMP case IP_PROTO_IGMP: /* IGMP input */ igmp_input(dev); break; diff --git a/net/icmp/icmp_ping.c b/net/icmp/icmp_ping.c index 91bc80f9f6..879089e014 100644 --- a/net/icmp/icmp_ping.c +++ b/net/icmp/icmp_ping.c @@ -47,6 +47,7 @@ #include #include +#include #include #include @@ -350,7 +351,7 @@ int icmp_ping(in_addr_t addr, uint16_t id, uint16_t seqno, uint16_t datalen, /* Get the device that will be used to route this ICMP ECHO request */ #ifdef CONFIG_NETDEV_MULTINIC - dev = netdev_findby_ipv4addr(g_ipv4_allzeroaddr, addr); + dev = netdev_findby_ipv4addr(INADDR_ANY, addr); #else dev = netdev_findby_ipv4addr(addr); #endif diff --git a/net/netdev/netdev_findbyaddr.c b/net/netdev/netdev_findbyaddr.c index f7ba9de73f..56fc0368b8 100644 --- a/net/netdev/netdev_findbyaddr.c +++ b/net/netdev/netdev_findbyaddr.c @@ -45,6 +45,8 @@ #include #include +#include + #include #include @@ -219,12 +221,12 @@ FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t ripaddr) /* First, check if this is the broadcast IP address */ - if (net_ipv4addr_cmp(ripaddr, g_ipv4_alloneaddr)) + if (net_ipv4addr_cmp(ripaddr, INADDR_BROADCAST)) { #ifdef CONFIG_NETDEV_MULTINIC /* Yes.. Check the local, bound address. Is it INADDR_ANY? */ - if (net_ipv4addr_cmp(lipaddr, g_ipv4_allzeroaddr)) + if (net_ipv4addr_cmp(lipaddr, INADDR_ANY)) { /* Yes.. In this case, I think we are supposed to send the * broadcast packet out ALL local networks. I am not sure diff --git a/net/route/net_router.c b/net/route/net_router.c index c004bf6a14..d0bd3eb0b2 100644 --- a/net/route/net_router.c +++ b/net/route/net_router.c @@ -43,6 +43,8 @@ #include #include +#include + #include #include "devif/devif.h" @@ -177,7 +179,7 @@ int net_ipv4_router(in_addr_t target, FAR in_addr_t *router) /* Do not route the special broadcast IP address */ - if (net_ipv4addr_cmp(target, g_ipv4_alloneaddr)) + if (net_ipv4addr_cmp(target, INADDR_BROADCAST)) { return -ENOENT; } diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index 3b5305a584..9997e9a987 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -49,6 +49,8 @@ #include #include +#include + #include #include @@ -395,7 +397,7 @@ static inline FAR struct tcp_conn_s * tcp->destport == conn->lport && tcp->srcport == conn->rport && #ifdef CONFIG_NETDEV_MULTINIC - (net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_allzeroaddr) || + (net_ipv4addr_cmp(conn->u.ipv4.laddr, INADDR_ANY) || net_ipv4addr_cmp(destipaddr, conn->u.ipv4.laddr)) && #endif net_ipv4addr_cmp(srcipaddr, conn->u.ipv4.raddr)) diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c index af28a72359..fbc8c8c9c8 100644 --- a/net/udp/udp_conn.c +++ b/net/udp/udp_conn.c @@ -50,6 +50,8 @@ #include #include +#include + #include #include @@ -305,12 +307,12 @@ static inline FAR struct udp_conn_s * if (conn->lport != 0 && udp->destport == conn->lport && (conn->rport == 0 || udp->srcport == conn->rport) && #ifdef CONFIG_NETDEV_MULTINIC - (net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_allzeroaddr) || - net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_alloneaddr) || + (net_ipv4addr_cmp(conn->u.ipv4.laddr, INADDR_ANY) || + net_ipv4addr_cmp(conn->u.ipv4.laddr, INADDR_BROADCAST) || net_ipv4addr_hdrcmp(ip->destipaddr, &conn->u.ipv4.laddr)) && #endif - (net_ipv4addr_cmp(conn->u.ipv4.raddr, g_ipv4_allzeroaddr) || - net_ipv4addr_cmp(conn->u.ipv4.raddr, g_ipv4_alloneaddr) || + (net_ipv4addr_cmp(conn->u.ipv4.raddr, INADDR_ANY) || + net_ipv4addr_cmp(conn->u.ipv4.raddr, INADDR_BROADCAST) || net_ipv4addr_hdrcmp(ip->srcipaddr, &conn->u.ipv4.raddr))) { /* Matching connection found.. return a reference to it */ @@ -746,7 +748,7 @@ int udp_connect(FAR struct udp_conn_s *conn, FAR const struct sockaddr *addr) if (conn->domain == PF_INET) #endif { - net_ipv4addr_copy(conn->u.ipv4.raddr, g_ipv4_allzeroaddr); + net_ipv4addr_copy(conn->u.ipv4.raddr, INADDR_ANY); } #endif /* CONFIG_NET_IPv4 */ diff --git a/net/udp/udp_finddev.c b/net/udp/udp_finddev.c index f02b0e8f77..73f5e8cc18 100644 --- a/net/udp/udp_finddev.c +++ b/net/udp/udp_finddev.c @@ -87,7 +87,7 @@ FAR struct net_driver_s *udp_find_ipv4_device(FAR struct udp_conn_s *conn, * sendto(). */ - if (ipv4addr == INADDR_ANY) + if ((net_ipv4addr_cmp(ipv4addr, INADDR_ANY)) { return NULL; } @@ -139,7 +139,7 @@ FAR struct net_driver_s *udp_find_ipv6_device(FAR struct udp_conn_s *conn, * sendto(). */ - if (net_ipv4addr_cmp(conn->u.ipv4.laddr, g_ipv4_allzeroaddr)) + if (net_ipv6addr_cmp(ipv6addr, g_ipv6_allzeroaddr)) { return NULL; }