diff options
author | Steven Barth <steven@midlink.org> | 2015-08-20 11:33:23 +0200 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2015-08-20 11:33:23 +0200 |
commit | 5b12eeba475a3301c362cf59f138ec7aa60d2dd9 (patch) | |
tree | f0e0e4a98f4585e7c2e514e5020e30a9fa17fabd /src/odhcpd.c | |
parent | 2fd5d19525699f19186daca9b246dd37a0f547a0 (diff) |
router/dhcpv6: use link-local addresses for DNS
Diffstat (limited to 'src/odhcpd.c')
-rw-r--r-- | src/odhcpd.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/odhcpd.c b/src/odhcpd.c index 5774a4f..9c7f27c 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -254,24 +254,21 @@ ssize_t odhcpd_get_interface_addresses(int ifindex, return ret; } -int odhcpd_get_preferred_interface_address(int ifindex, struct in6_addr *addr) +int odhcpd_get_linklocal_interface_address(int ifindex, struct in6_addr *lladdr) { - struct odhcpd_ipaddr ipaddrs[8]; - ssize_t ip_cnt = odhcpd_get_interface_addresses(ifindex, ipaddrs, ARRAY_SIZE(ipaddrs)); - uint32_t preferred = 0; - int ret = 0; - - for (ssize_t i = 0; i < ip_cnt; i++) { - struct odhcpd_ipaddr *ipaddr = &ipaddrs[i]; - - if (ipaddr->preferred > preferred || !preferred) { - preferred = ipaddr->preferred; - *addr = ipaddr->addr; - ret = 1; + int status = -1; + struct sockaddr_in6 addr = {AF_INET6, 0, 0, ALL_IPV6_ROUTERS, ifindex}; + socklen_t alen = sizeof(addr); + int sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); + + if (!connect(sock, (struct sockaddr*)&addr, sizeof(addr)) && + !getsockname(sock, (struct sockaddr*)&addr, &alen)) { + *lladdr = addr.sin6_addr; + status = 0; } - } - return ret; + close(sock); + return status; } void odhcpd_setup_route(const struct in6_addr *addr, int prefixlen, |