Skip to content

Commit 4b438ac

Browse files
authored
Merge pull request ARMmbed#10834 from tymoteuszblochmobica/udp
Fixed UDP sendto if IP version not match
2 parents 63d1ea3 + b272c5f commit 4b438ac

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

features/lwipstack/LWIPStack.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "lwip/dns.h"
3535
#include "lwip/udp.h"
3636
#include "lwip/raw.h"
37+
#include "lwip/netif.h"
3738
#include "lwip/lwip_errno.h"
3839
#include "lwip-sys/arch/sys_arch.h"
3940

@@ -493,7 +494,16 @@ nsapi_size_or_error_t LWIP::socket_sendto(nsapi_socket_t handle, const SocketAdd
493494
if (!convert_mbed_addr_to_lwip(&ip_addr, &addr)) {
494495
return NSAPI_ERROR_PARAMETER;
495496
}
496-
497+
struct netif *netif_ = netif_get_by_index(s->conn->pcb.ip->netif_idx);
498+
if (!netif_) {
499+
netif_ = &default_interface->netif;
500+
}
501+
if (netif_) {
502+
if ((addr.version == NSAPI_IPv4 && !get_ipv4_addr(netif_)) ||
503+
(addr.version == NSAPI_IPv6 && !get_ipv6_addr(netif_))) {
504+
return NSAPI_ERROR_PARAMETER;
505+
}
506+
}
497507
struct netbuf *buf = netbuf_new();
498508

499509
err_t err = netbuf_ref(buf, data, (u16_t)size);

features/lwipstack/lwip_tools.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,24 @@ nsapi_error_t LWIP::err_remap(err_t err)
5959
}
6060
}
6161

62-
#if LWIP_IPV4
62+
6363
const ip_addr_t *LWIP::get_ipv4_addr(const struct netif *netif)
6464
{
65+
#if LWIP_IPV4
6566
if (!netif_is_up(netif)) {
6667
return NULL;
6768
}
6869

6970
if (!ip4_addr_isany(netif_ip4_addr(netif))) {
7071
return netif_ip_addr4(netif);
7172
}
72-
73+
#endif
7374
return NULL;
7475
}
75-
#endif
7676

77-
#if LWIP_IPV6
7877
const ip_addr_t *LWIP::get_ipv6_addr(const struct netif *netif)
7978
{
79+
#if LWIP_IPV6
8080
if (!netif_is_up(netif)) {
8181
return NULL;
8282
}
@@ -87,10 +87,9 @@ const ip_addr_t *LWIP::get_ipv6_addr(const struct netif *netif)
8787
return netif_ip_addr6(netif, i);
8888
}
8989
}
90-
90+
#endif
9191
return NULL;
9292
}
93-
#endif
9493

9594
bool LWIP::is_local_addr(const ip_addr_t *ip_addr)
9695
{

0 commit comments

Comments
 (0)