- for (struct nlmsghdr *nh = (struct nlmsghdr*)buf; NLMSG_OK(nh, (size_t)len);
- nh = NLMSG_NEXT(nh, len)) {
- struct ifaddrmsg *ifa = NLMSG_DATA(nh);
- struct in6_addr *addr = NULL;
- if (NLMSG_PAYLOAD(nh, 0) < sizeof(*ifa) || ifa->ifa_index != if_index ||
- (nh->nlmsg_type == RTM_NEWADDR && !(ifa->ifa_flags & IFA_F_DADFAILED)) ||
- (nh->nlmsg_type == RTM_DELADDR && !(ifa->ifa_flags & IFA_F_TENTATIVE)) ||
- (nh->nlmsg_type != RTM_NEWADDR && nh->nlmsg_type != RTM_DELADDR))
- continue;
-
- ssize_t alen = NLMSG_PAYLOAD(nh, sizeof(*ifa));
- for (struct rtattr *rta = (struct rtattr*)&ifa[1]; RTA_OK(rta, alen);
- rta = RTA_NEXT(rta, alen))
- if (rta->rta_type == IFA_ADDRESS && RTA_PAYLOAD(rta) >= sizeof(*addr))
- addr = RTA_DATA(rta);
-
- if (addr) {
- char ipbuf[INET6_ADDRSTRLEN];
- inet_ntop(AF_INET6, addr, ipbuf, sizeof(ipbuf));
- syslog(LOG_WARNING, "duplicate address detected: %s (code: %u:%x)",
- ipbuf, (unsigned)nh->nlmsg_type, (unsigned)ifa->ifa_flags);
- found |= ra_deduplicate(addr, ifa->ifa_prefixlen);
+ if (IN6_IS_ADDR_UNSPECIFIED(&lladdr)) {
+ // Autodetect interface-id if not specified
+ FILE *fp = fopen("/proc/net/if_inet6", "r");
+ if (fp) {
+ char addrbuf[33], ifbuf[16];
+ while (fscanf(fp, "%32s %*x %*x %*x %*x %15s", addrbuf, ifbuf) == 2) {
+ if (!strcmp(ifbuf, if_name)) {
+ script_unhexlify((uint8_t*)&lladdr, sizeof(lladdr), addrbuf);
+ break;
+ }