Skip to content

Commit f8cd118

Browse files
Fixed LWIPStack socket_sendto member to fail if interface IP4/6 version differ from destination adress IP version
1 parent fc645bc commit f8cd118

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
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);

0 commit comments

Comments
 (0)