Merge pull request #10834 from tymoteuszblochmobica/udp

Fixed UDP sendto if IP version not match
pull/10896/head
Martin Kojtal 2019-06-25 11:03:03 +01:00 committed by GitHub
commit 4b438ac1de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -34,6 +34,7 @@
#include "lwip/dns.h"
#include "lwip/udp.h"
#include "lwip/raw.h"
#include "lwip/netif.h"
#include "lwip/lwip_errno.h"
#include "lwip-sys/arch/sys_arch.h"
@ -493,7 +494,16 @@ nsapi_size_or_error_t LWIP::socket_sendto(nsapi_socket_t handle, const SocketAdd
if (!convert_mbed_addr_to_lwip(&ip_addr, &addr)) {
return NSAPI_ERROR_PARAMETER;
}
struct netif *netif_ = netif_get_by_index(s->conn->pcb.ip->netif_idx);
if (!netif_) {
netif_ = &default_interface->netif;
}
if (netif_) {
if ((addr.version == NSAPI_IPv4 && !get_ipv4_addr(netif_)) ||
(addr.version == NSAPI_IPv6 && !get_ipv6_addr(netif_))) {
return NSAPI_ERROR_PARAMETER;
}
}
struct netbuf *buf = netbuf_new();
err_t err = netbuf_ref(buf, data, (u16_t)size);

View File

@ -59,9 +59,10 @@ nsapi_error_t LWIP::err_remap(err_t err)
}
}
#if LWIP_IPV4
const ip_addr_t *LWIP::get_ipv4_addr(const struct netif *netif)
{
#if LWIP_IPV4
if (!netif_is_up(netif)) {
return NULL;
}
@ -69,14 +70,13 @@ const ip_addr_t *LWIP::get_ipv4_addr(const struct netif *netif)
if (!ip4_addr_isany(netif_ip4_addr(netif))) {
return netif_ip_addr4(netif);
}
#endif
return NULL;
}
#endif
#if LWIP_IPV6
const ip_addr_t *LWIP::get_ipv6_addr(const struct netif *netif)
{
#if LWIP_IPV6
if (!netif_is_up(netif)) {
return NULL;
}
@ -87,10 +87,9 @@ const ip_addr_t *LWIP::get_ipv6_addr(const struct netif *netif)
return netif_ip_addr6(netif, i);
}
}
#endif
return NULL;
}
#endif
bool LWIP::is_local_addr(const ip_addr_t *ip_addr)
{