diff --git a/src/core/raw.c b/src/core/raw.c index f692c9c2..e4ea13c1 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -209,7 +209,7 @@ raw_input(struct pbuf *p, struct netif *inp) err_t raw_bind(struct raw_pcb *pcb, const ip_addr_t *ipaddr) { - if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr)) { + if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) { return ERR_VAL; } ip_addr_set_ipaddr(&pcb->local_ip, ipaddr); @@ -320,7 +320,13 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr) } } - netif = ip_route(&pcb->local_ip, ipaddr); + if(IP_IS_ANY_TYPE_VAL(pcb->local_ip)) { + /* Don't call ip_route() with IP_ANY_TYPE */ + netif = ip_route(IP46_ADDR_ANY(IP_GET_TYPE(ipaddr)), ipaddr); + } else { + netif = ip_route(&pcb->local_ip, ipaddr); + } + if (netif == NULL) { LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: No route to ")); ip_addr_debug_print(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ipaddr); diff --git a/src/core/tcp.c b/src/core/tcp.c index 1d700980..eac05fbe 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -551,7 +551,7 @@ tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) #endif /* LWIP_IPV4 */ /* still need to check for ipaddr == NULL in IPv6 only case */ - if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr)) { + if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) { return ERR_VAL; } diff --git a/src/core/udp.c b/src/core/udp.c index e0ab1863..8c3a3ce5 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -571,7 +571,12 @@ udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, #endif /* LWIP_IPV6 || (LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS) */ /* find the outgoing network interface for this packet */ - netif = ip_route(&pcb->local_ip, dst_ip_route); + if(IP_IS_ANY_TYPE_VAL(pcb->local_ip)) { + /* Don't call ip_route() with IP_ANY_TYPE */ + netif = ip_route(IP46_ADDR_ANY(IP_GET_TYPE(dst_ip_route)), dst_ip_route); + } else { + netif = ip_route(&pcb->local_ip, dst_ip_route); + } /* no outgoing network interface could be found? */ if (netif == NULL) { @@ -912,7 +917,7 @@ udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) #endif /* LWIP_IPV4 */ /* still need to check for ipaddr == NULL in IPv6 only case */ - if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr)) { + if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) { return ERR_VAL; } @@ -1002,7 +1007,7 @@ udp_connect(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) { struct udp_pcb *ipcb; - if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr)) { + if ((pcb == NULL) || (ipaddr == NULL) || !IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr)) { return ERR_VAL; } diff --git a/src/include/lwip/ip_addr.h b/src/include/lwip/ip_addr.h index 26ab916e..127d4144 100644 --- a/src/include/lwip/ip_addr.h +++ b/src/include/lwip/ip_addr.h @@ -226,6 +226,8 @@ int ipaddr_aton(const char *cp, ip_addr_t *addr); #define unmap_ipv6_mapped_ipv4(ip4addr, ip6addr) \ (ip4addr)->addr = (ip6addr)->addr[3]; +#define IP46_ADDR_ANY(type) (((type) == IPADDR_TYPE_V6)? IP6_ADDR_ANY : IP4_ADDR_ANY) + #else /* LWIP_IPV4 && LWIP_IPV6 */ #define IP_ADDR_PCB_VERSION_MATCH(addr, pcb) 1 @@ -274,6 +276,8 @@ typedef ip4_addr_t ip_addr_t; #define IPADDR_STRLEN_MAX IP4ADDR_STRLEN_MAX +#define IP46_ADDR_ANY(type) (IP4_ADDR_ANY) + #else /* LWIP_IPV4 */ typedef ip6_addr_t ip_addr_t; @@ -315,6 +319,8 @@ typedef ip6_addr_t ip_addr_t; #define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX +#define IP46_ADDR_ANY(type) (IP6_ADDR_ANY) + #endif /* LWIP_IPV4 */ #endif /* LWIP_IPV4 && LWIP_IPV6 */