--- /root/@@@/radvd-2.20/device-common.c	Sat Dec 28 08:27:47 2024
+++ /device-common.c	Thu Feb 26 18:55:04 2026
@@ -106,6 +106,7 @@
 	struct ifaddrs *addresses = 0;
 	int link_local_set = 0;
 	int i = 0;
+	char addr_str[INET6_ADDRSTRLEN];
 
 	if (getifaddrs(&addresses) != 0) {
 		flog(LOG_ERR, "getifaddrs failed on %s: %s", name, strerror(errno));
@@ -124,18 +125,18 @@
 			if (strcmp(ifa->ifa_name, name) != 0)
 				continue;
 
+			/* Сохраняем все адреса */
 			*if_addrs = realloc(*if_addrs, (i + 1) * sizeof(struct in6_addr));
 			(*if_addrs)[i++] = a6->sin6_addr;
 
-			/* Skip if it is not a linklocal address or link locak address already found*/
-			uint8_t const ll_prefix[] = {0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
-			if (link_local_set || 0 != memcmp(&(a6->sin6_addr), ll_prefix, sizeof(ll_prefix)))
-				continue;
-
-			if (if_addr)
-				memcpy(if_addr, &(a6->sin6_addr), sizeof(struct in6_addr));
-
-			link_local_set = 1;
+			/* Ищем link-local адрес, а не просто первый адрес */
+			if (!link_local_set && IN6_IS_ADDR_LINKLOCAL(&a6->sin6_addr)) {
+				if (if_addr)
+					memcpy(if_addr, &(a6->sin6_addr), sizeof(struct in6_addr));
+				link_local_set = 1;
+				inet_ntop(AF_INET6, &a6->sin6_addr, addr_str, sizeof(addr_str));
+				dlog(LOG_DEBUG, 4, "Found link-local address: %s", addr_str);
+			}
 		}
 	}
 
@@ -149,8 +150,10 @@
 	/* Sort the addresses so the output is predictable. */
 	qsort(*if_addrs, i, sizeof(struct in6_addr), cmp_iface_addrs);
 
-	if (!link_local_set)
+	if (!link_local_set) {
+		dlog(LOG_DEBUG, 4, "No link-local address found on %s", name);
 		return -1;
+	}
 
 	return i;
 }
