From 6822f90004ff612484e5563fbf6475d68c423a9c Mon Sep 17 00:00:00 2001 From: Martine Lenders <m.lenders@fu-berlin.de> Date: Tue, 4 Sep 2018 15:55:03 +0200 Subject: [PATCH] lwip_sock: adapt for address zoning --- pkg/lwip/contrib/sock/ip/lwip_sock_ip.c | 2 +- pkg/lwip/contrib/sock/lwip_sock.c | 33 ++++++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/pkg/lwip/contrib/sock/ip/lwip_sock_ip.c b/pkg/lwip/contrib/sock/ip/lwip_sock_ip.c index 0a8d6b32f6..fde43b4d43 100644 --- a/pkg/lwip/contrib/sock/ip/lwip_sock_ip.c +++ b/pkg/lwip/contrib/sock/ip/lwip_sock_ip.c @@ -92,7 +92,7 @@ static uint16_t _ip6_addr_to_netif(const ip6_addr_p_t *_addr) ip6_addr_t addr; assert(_addr != NULL); - ip6_addr_copy(addr, *_addr); + ip6_addr_copy_from_packed(addr, *_addr); if (!ip6_addr_isany_val(addr)) { for (struct netif *netif = netif_list; netif != NULL; netif = netif->next) { if (netif_get_ip6_addr_match(netif, &addr) >= 0) { diff --git a/pkg/lwip/contrib/sock/lwip_sock.c b/pkg/lwip/contrib/sock/lwip_sock.c index dba775c17d..40b4a10305 100644 --- a/pkg/lwip/contrib/sock/lwip_sock.c +++ b/pkg/lwip/contrib/sock/lwip_sock.c @@ -151,6 +151,23 @@ static bool _addr_on_netif(int family, int netif_num, const ip_addr_t *addr) p = (ep)->port; #endif +static void _convert_ip_addr(ip_addr_t *lwip_addr, int family, + const void *sock_addr, size_t sock_addr_size) +{ + memcpy(lwip_addr, sock_addr, sock_addr_size); +#if LWIP_IPV6 && LWIP_IPV4 + if (family == AF_INET6) { + ip6_addr_clear_zone(&lwip_addr->u_addr.ip6); + } + lwip_addr->type = lwip_af_to_ip_addr_type(family); +#elif LWIP_IPV6 + (void)family; + ip6_addr_clear_zone(lwip_addr); +#else + (void)family; +#endif +} + static int _sock_ep_to_netconn_pars(const struct _sock_tl_ep *local, const struct _sock_tl_ep *remote, ip_addr_t *local_addr, u16_t *local_port, @@ -193,10 +210,8 @@ static int _sock_ep_to_netconn_pars(const struct _sock_tl_ep *local, netif = remote->netif; } family = remote->family; - memcpy(remote_addr, &remote->addr, sizeof(remote->addr)); -#if LWIP_IPV6 && LWIP_IPV4 - remote_addr->type = lwip_af_to_ip_addr_type(family); -#endif + _convert_ip_addr(remote_addr, family, &remote->addr, + sizeof(remote->addr)); if (ip_addr_isany(remote_addr)) { return -EINVAL; } @@ -224,7 +239,8 @@ static int _sock_ep_to_netconn_pars(const struct _sock_tl_ep *local, /* case (local == NULL) is included in _ep_isany() */ /* cast to ip_addr_t alright, since type field is never used */ else if (_addr_on_netif(family, netif, (ip_addr_t *)&local->addr)) { - memcpy(local_addr, &local->addr, sizeof(local->addr)); + _convert_ip_addr(local_addr, family, &local->addr, + sizeof(local->addr)); res = 1; } else { @@ -232,14 +248,9 @@ static int _sock_ep_to_netconn_pars(const struct _sock_tl_ep *local, } } else if (local != NULL) { - memcpy(local_addr, &local->addr, sizeof(local->addr)); + _convert_ip_addr(local_addr, family, &local->addr, sizeof(local->addr)); res = 1; } -#if LWIP_IPV6 && LWIP_IPV4 - if (local_addr != NULL) { - local_addr->type = lwip_af_to_ip_addr_type(family); - } -#endif return res; } -- GitLab