From 9124917dca3fb9ee32f2fcc77afff78b2ae91b64 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 7 Sep 2021 18:43:39 -0400 Subject: [PATCH] Propagate the interface id from avahi in the Linux MDNS impl. (#9484) Without this resolving something to a link-local IP won't work right. Fixes https://github.com/project-chip/connectedhomeip/issues/8232 Co-authored-by: Abdul Samad --- src/platform/Linux/MdnsImpl.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/platform/Linux/MdnsImpl.cpp b/src/platform/Linux/MdnsImpl.cpp index eb41783248b204..e1a303c910c975 100644 --- a/src/platform/Linux/MdnsImpl.cpp +++ b/src/platform/Linux/MdnsImpl.cpp @@ -605,8 +605,13 @@ void MdnsAvahi::HandleBrowse(AvahiServiceBrowser * browser, AvahiIfIndex interfa Platform::CopyString(service.mName, name); CopyTypeWithoutProtocol(service.mType, type); - service.mProtocol = GetProtocolInType(type); - service.mAddressType = ToAddressType(protocol); + service.mProtocol = GetProtocolInType(type); + service.mAddressType = ToAddressType(protocol); + service.mInterface = INET_NULL_INTERFACEID; + if (interface != AVAHI_IF_UNSPEC) + { + service.mInterface = static_cast(interface); + } service.mType[kMdnsTypeMaxSize] = 0; context->mServices.push_back(service); } @@ -686,6 +691,11 @@ void MdnsAvahi::HandleResolve(AvahiServiceResolver * resolver, AvahiIfIndex inte result.mProtocol = GetProtocolInType(type); result.mPort = port; result.mAddressType = ToAddressType(protocol); + result.mInterface = INET_NULL_INTERFACEID; + if (interface != AVAHI_IF_UNSPEC) + { + result.mInterface = static_cast(interface); + } Platform::CopyString(result.mHostName, host_name); // Returned value is full QName, want only host part. char * dot = strchr(result.mHostName, '.');