diff --git a/src/platform/Darwin/DnssdImpl.cpp b/src/platform/Darwin/DnssdImpl.cpp index abc933a1a03abb..4088b245964e39 100644 --- a/src/platform/Darwin/DnssdImpl.cpp +++ b/src/platform/Darwin/DnssdImpl.cpp @@ -409,12 +409,23 @@ static void OnGetAddrInfo(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t i service.mTextEntrySize = sdCtx->textEntries.empty() ? 0 : sdCtx->textEntries.size(); chip::Inet::IPAddress ip; CHIP_ERROR status = chip::Inet::IPAddress::GetIPAddressFromSockAddr(*address, ip); - service.mAddress.SetValue(ip); + if (status == CHIP_NO_ERROR) + { + service.mAddress.SetValue(ip); + } Platform::CopyString(service.mName, sdCtx->name); Platform::CopyString(service.mHostName, hostname); service.mInterface = Inet::InterfaceId(sdCtx->interfaceId); + sdCtx->services.push_back(service); + + if (flags & kDNSServiceFlagsMoreComing) + { + // Wait for that. + return; + } - sdCtx->callback(sdCtx->context, Span(&service, 1), status); + // TODO: Does it really make sense to pass in the status from our last "get the IP address" operation? + sdCtx->callback(sdCtx->context, Span(sdCtx->services.data(), sdCtx->services.size()), status); MdnsContexts::GetInstance().Remove(sdCtx); } @@ -512,6 +523,9 @@ static void OnResolve(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t inter GetAddrInfo(sdCtx->context, sdCtx->callback, interfaceId, sdCtx->addressType, sdCtx->name, hostname, ntohs(port), txtLen, txtRecord); + + // TODO: If flags & kDNSServiceFlagsMoreComing should we keep waiting to see + // what else we resolve instead of calling Remove() here? MdnsContexts::GetInstance().Remove(sdCtx); } diff --git a/src/platform/Darwin/DnssdImpl.h b/src/platform/Darwin/DnssdImpl.h index a0f1bdc4be78cb..56fe7fc12ac629 100644 --- a/src/platform/Darwin/DnssdImpl.h +++ b/src/platform/Darwin/DnssdImpl.h @@ -91,6 +91,7 @@ struct ResolveContext : public GenericContext struct GetAddrInfoContext : public GenericContext { DnssdResolveCallback callback; + std::vector services; std::vector textEntries; char name[Common::kInstanceNameMaxLength + 1]; uint32_t interfaceId;