mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #10834 from tymoteuszblochmobica/udp
Fixed UDP sendto if IP version not matchpull/10896/head
commit
4b438ac1de
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue