Skip to content

Commit

Permalink
sa: add support for interface suffix for IPv6ll
Browse files Browse the repository at this point in the history
  • Loading branch information
cspiel1 committed Jun 23, 2021
1 parent 6381740 commit fbb54ee
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/sa/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
#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>
#include <re_sa.h>
#include <re_net.h>


#define DEBUG_MODULE "sa"
Expand Down Expand Up @@ -68,7 +72,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) {
Expand All @@ -86,12 +94,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;
}


Expand Down

0 comments on commit fbb54ee

Please sign in to comment.