1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 05:53:49 +01:00

Merge pull request #14267 from fengelhardt/feature_posix_sockets_netif

posix_sockets: use sin6_scope_id of struct sockaddr_in6
This commit is contained in:
Martine Lenders 2020-06-19 12:32:19 +02:00 committed by GitHub
commit 782d76d2a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -33,6 +33,11 @@
#include <sys/socket.h>
#include <unistd.h>
#ifdef SOCK_HAS_IPV6
#include "net/ipv6/addr.h" /* for interface parsing */
#include "net/netif.h" /* for resolving ipv6 scope */
#endif /* SOCK_HAS_IPV6 */
#include "thread.h"
#define SERVER_MSG_QUEUE_SIZE (8)
@ -98,6 +103,20 @@ static int udp_send(char *addr_str, char *port_str, char *data, unsigned int num
src.sin6_family = AF_INET6;
dst.sin6_family = AF_INET6;
memset(&src.sin6_addr, 0, sizeof(src.sin6_addr));
/* parse interface id */
#ifdef SOCK_HAS_IPV6
char *iface;
iface = ipv6_addr_split_iface(addr_str); /* also removes interface id */
if (iface) {
netif_t *netif = netif_get_by_name(iface);
if (netif) {
dst.sin6_scope_id = (uint32_t) netif_get_id(netif);
}
else {
printf("unknown network interface %s\n", iface);
}
}
#endif /* SOCK_HAS_IPV6 */
/* parse destination address */
if (inet_pton(AF_INET6, addr_str, &dst.sin6_addr) != 1) {
puts("Error: unable to parse destination address");

View File

@ -238,6 +238,9 @@ static int _sockaddr_to_ep(const struct sockaddr *address, socklen_t address_len
out->family = AF_INET6;
memcpy(&out->addr.ipv6, &in6_addr->sin6_addr, sizeof(out->addr.ipv6));
out->port = ntohs(in6_addr->sin6_port);
if (in6_addr->sin6_scope_id != 0) {
out->netif = (uint16_t) in6_addr->sin6_scope_id;
}
break;
#endif
default: