Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed UDP sendto if IP version not match #10834

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion features/lwipstack/LWIPStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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_)) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, I didn't consider V4/V6-only compilation - it looks like these get_ipvx_addr aren't defined if LWIP_IPVX isn't enabled. You should probably fiddle them to have them defined and return constant NULL in that case - will be neater than adding ifdefs here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed get_ipvx_addr LWIP_IPV4/6

(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);
Expand Down
11 changes: 5 additions & 6 deletions features/lwipstack/lwip_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,24 @@ 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;
}

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;
}
Expand All @@ -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)
{
Expand Down