Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sa: add support for interface suffix for IPv6ll
Browse files Browse the repository at this point in the history
cspiel1 committed Jun 28, 2021
1 parent f6db77d commit 427de35
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/sa/sa.c
Original file line number Diff line number Diff line change
@@ -12,6 +12,9 @@
#include <arpa/inet.h>
#endif
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <re_types.h>
#include <re_fmt.h>
#include <re_list.h>
@@ -68,7 +71,11 @@ int sa_set(struct sa *sa, const struct pl *addr, uint16_t port)
*/
int sa_pton(const char *addr, struct sa *sa)
{
if (!addr)
struct addrinfo *res, *res0 = NULL;
struct addrinfo hints;
int err = 0;

if (!addr || !sa)
return EINVAL;

if (inet_pton(AF_INET, addr, &sa->u.in.sin_addr) > 0) {
@@ -86,12 +93,31 @@ int sa_pton(const char *addr, struct sa *sa)
sa->u.in6.sin6_family = AF_INET6;
}
}
else if (!strncmp(addr, "fe80:", 5) && strchr(addr, '%')) {
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG | AI_NUMERICHOST;

if (getaddrinfo(addr, NULL, &hints, &res0))
return EADDRNOTAVAIL;

for (res = res0; res; res = res->ai_next) {

err = sa_set_sa(sa, res->ai_addr);
if (err)
continue;

break;
}

freeaddrinfo(res0);
}
#endif
else {
return EINVAL;
}

return 0;
return err;
}


0 comments on commit 427de35

Please sign in to comment.