Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the MDNS darwin fix. #1

Merged
merged 2 commits into from
Nov 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/platform/Darwin/DnssdImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,6 @@ static CHIP_ERROR GetAddrInfo(void * context, DnssdResolveCallback callback, uin
}
else
{
// -1 is the local only interface. In this case, we can use localhost ::1
CHIP_ERROR chip_err = MdnsContexts::GetInstance().Add(sdCtx, sdRef);
if (chip_err != CHIP_NO_ERROR)
{
// TODO: Above doesn't check the error return, but it does seem like we want to trigger the callback if this fails.
CheckForSuccess(sdCtx, __func__, kDNSServiceErr_Unknown, true);
return chip_err;
}

sockaddr_in6 sockaddr;
memset(&sockaddr, 0, sizeof(sockaddr));
sockaddr.sin6_len = sizeof(sockaddr);
Expand All @@ -477,9 +468,18 @@ static CHIP_ERROR GetAddrInfo(void * context, DnssdResolveCallback callback, uin
sockaddr.sin6_port = htons((unsigned short) port);
uint32_t ttl = 120; // default TTL for records with hostnames is 120 seconds
uint32_t interface = 0; // Set interface to ANY (0) - network stack can decide how to route this.
OnGetAddrInfo(sdRef, 0 /* flags */, 0, kDNSServiceErr_NoError, hostname, reinterpret_cast<sockaddr *>(&sockaddr), ttl,
sdCtx);
return err;
OnGetAddrInfo(nullptr, 0 /* flags */, interface, kDNSServiceErr_NoError, hostname, reinterpret_cast<struct sockaddr *>(&sockaddr),
ttl, sdCtx);

// Don't leak memory.
std::vector<TextEntry>::iterator textEntry;
for (textEntry = sdCtx->textEntries.begin(); textEntry != sdCtx->textEntries.end(); textEntry++)
{
free(const_cast<char *>(textEntry->mKey));
free(const_cast<uint8_t *>(textEntry->mData));
}

return CHIP_NO_ERROR;
}
}

Expand Down