Skip to content

Commit a231814

Browse files
committed
dns_sd_windows: Fix discovery on IPv6 once again
The getnameinfo() function already returned the interface number appended to the IPv6 address in ip_address_to_string(); the problem was that the interface number was not properly specified in the sockaddr argument. Now, the sin6_scope_id field (which contains the interface number on Windows) is correctly set, to the interface number of the "from" sockaddr argument. From what I understand, one problem was that the IPv6 address was discovered twice; once with the mDNS socket on IPv6, and once with the mDNS socket on IPv4. The AAAA entry discovered from the IPv4 socket would override the one obtained from the IPv6 socket, but wouldn't contain information about the interface number. Address this issue by only handling AAAA entries on the IPv6 interface. Signed-off-by: Paul Cercueil <[email protected]>
1 parent 99cd3ac commit a231814

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

dns_sd_windows.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,7 @@ static mdns_string_t ip_address_to_string(char *buffer, size_t capacity,
8585
if (addr->sa_family == AF_INET6) {
8686
if (addr6->sin6_port != 0
8787
&& strncmp(service, MDNS_PORT_STR, sizeof(MDNS_PORT_STR))) {
88-
if (IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr)) {
89-
len = snprintf(buffer, capacity, "[%s%%%lu]:%s",
90-
host, addr6->sin6_scope_id, service);
91-
} else {
92-
len = snprintf(buffer, capacity, "[%s]:%s", host, service);
93-
}
94-
} else if (IN6_IS_ADDR_LINKLOCAL(&addr6->sin6_addr)) {
95-
len = snprintf(buffer, capacity, "%s%%%lu",
96-
host, addr6->sin6_scope_id);
88+
len = snprintf(buffer, capacity, "[%s]:%s", host, service);
9789
} else {
9890
len = snprintf(buffer, capacity, "%s", host);
9991
}
@@ -233,6 +225,11 @@ static int query_callback(int sock, const struct sockaddr *from, size_t addrlen,
233225
rtype != MDNS_RECORDTYPE_AAAA)
234226
goto quit;
235227

228+
#ifdef HAVE_IPV6
229+
if (rtype == MDNS_RECORDTYPE_AAAA && from->sa_family != AF_INET6)
230+
goto quit;
231+
#endif
232+
236233
if (entry != MDNS_ENTRYTYPE_ANSWER)
237234
goto quit;
238235

@@ -326,6 +323,7 @@ static int query_callback(int sock, const struct sockaddr *from, size_t addrlen,
326323
struct sockaddr_in6 addr;
327324

328325
mdns_record_parse_aaaa(data, size, record_offset, record_length, &addr);
326+
addr.sin6_scope_id = ((struct sockaddr_in6 *)from)->sin6_scope_id;
329327
addrstr = ip_address_to_string(namebuffer, sizeof(namebuffer),
330328
(struct sockaddr *) &addr, sizeof(addr));
331329
IIO_DEBUG("%.*s : %.*s AAAA %.*s\n", MDNS_STRING_FORMAT(fromaddrstr),

0 commit comments

Comments
 (0)