zeroconf works with IPv6

This commit is contained in:
badaix 2018-02-17 22:23:04 +01:00
parent e9ff66e78b
commit b34f8a6e00
5 changed files with 57 additions and 38 deletions

View file

@ -226,33 +226,33 @@ bool BrowseBonjour::browse(const string& serviceName, mDNSResult& result, int ti
{
resultCollection[i].port_ = resolve.port;
CHECKED(DNSServiceGetAddrInfo(service.get(), kDNSServiceFlagsLongLivedQuery, 0, kDNSServiceProtocol_IPv4, resolve.fullName.c_str(),
[](DNSServiceRef service,
DNSServiceFlags flags,
uint32_t interfaceIndex,
DNSServiceErrorType errorCode,
const char* hostname,
const sockaddr* address,
uint32_t ttl,
void* context)
{
auto result = static_cast<mDNSResult*>(context);
[](DNSServiceRef service,
DNSServiceFlags flags,
uint32_t interfaceIndex,
DNSServiceErrorType errorCode,
const char* hostname,
const sockaddr* address,
uint32_t ttl,
void* context)
{
auto result = static_cast<mDNSResult*>(context);
result->host_ = string(hostname);
result->proto_ = address->sa_family;
result->host = string(hostname);
result->ip_version = (address->sa_family == AF_INET)?(IPVersion::IPv4):(IPVersion::IPv6);
result->iface_idx = static_cast<int>(interfaceIndex);
char hostIP[NI_MAXHOST];
char hostService[NI_MAXSERV];
if (getnameinfo(address, sizeof(*address),
hostIP, sizeof(hostIP),
hostService, sizeof(hostService),
NI_NUMERICHOST|NI_NUMERICSERV) == 0)
result->ip_ = string(hostIP);
else
return;
result->valid_ = true;
}, &resultCollection[i++]));
char hostIP[NI_MAXHOST];
char hostService[NI_MAXSERV];
if (getnameinfo(address, sizeof(*address),
hostIP, sizeof(hostIP),
hostService, sizeof(hostService),
NI_NUMERICHOST|NI_NUMERICSERV) == 0)
result->ip_ = string(hostIP);
else
return;
result->valid_ = true;
}, &resultCollection[i++]));
}
runService(service);
}