1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-30 19:15:08 +01:00

Add ipv6 to windows mdns.

This commit is contained in:
Andreas 2013-03-09 12:04:17 +01:00
parent 9fb46f0d29
commit e09da09d31
2 changed files with 48 additions and 11 deletions

View File

@ -1,6 +1,7 @@
#include "tinysvcmdns.h"
extern "C" {
#include "mdns.h"
#include "mdnsd.h"
}
@ -10,10 +11,50 @@ extern "C" {
#include "core/logging.h"
TinySVCMDNS::TinySVCMDNS() {
TinySVCMDNS::CreateMdnsd(uint32_t ipv4, QString ipv6) {
// Get our hostname
QString host = QHostInfo::localHostName();
// Start the service
mdnsd* mdnsd = mdnsd_start_bind(ipv4);
// Set our hostname
mdnsd_set_hostname(
mdnsd,
QString(host + ".local").toUtf8().constData(),
ipv4);
// Add entry for ipv4
struct rr_entry *a2_e = NULL;
a2_e = rr_create_a(create_nlabel(hostname), ipv4);
mdnsd_add_rr(mdnsd, a2_e);
// Add entry for ipv6
struct rr_entry *aaaa_e = NULL;
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET6;
hints.ai_flags = AI_NUMERICHOST;
struct addrinfo* results;
getaddrinfo(
ipv6.toStdString().c_str(),
NULL,
&hints,
&results);
struct sockaddr_in6* addr = (struct sockaddr_in6*)results->ai_addr;
struct in6_addr v6addr = addr->sin6_addr;
freeaddrinfo(results);
aaaa_e = rr_create_aaaa(create_nlabel(hostname), &v6addr);
mdnsd_add_rr(mdnsd, aaaa_e);
// Add to the list
mdnsd_.append(mdnsd);
}
TinySVCMDNS::TinySVCMDNS() {
// Get all network interfaces
QList<QNetworkInterface> network_interfaces = QNetworkInterface::allInterfaces();
foreach (QNetworkInterface network_interface, network_interfaces) {
@ -22,6 +63,7 @@ TinySVCMDNS::TinySVCMDNS() {
&& !network_interface.flags().testFlag(network_interface.IsLoopBack))
{
uint32_t ipv4 = 0;
QString ipv6;
// Now check all network addresses for this device
QList<QNetworkAddressEntry> network_address_entries = network_interface.addressEntries();
@ -30,19 +72,13 @@ TinySVCMDNS::TinySVCMDNS() {
QHostAddress host_address = network_address_entry.ip();
if (host_address.protocol() == QAbstractSocket::IPv4Protocol) {
ipv4 = qToBigEndian(host_address.toIPv4Address());
} else if (host_address.protocol() == QAbstractSocket::IPv6Protocol) {
ipv6 = host_address.toString();
}
}
// Now start the service
mdnsd* mdnsd = mdnsd_start_bind(ipv4);
mdnsd_set_hostname(
mdnsd,
QString(host + ".local").toUtf8().constData(),
ipv4);
// Add to the list
mdnsd_.append(mdnsd);
CreateMdnsd(ipv4, ipv6);
}
}
}

View File

@ -19,6 +19,7 @@ class TinySVCMDNS : public Zeroconf {
quint16 port);
private:
void CreateMdnsd(uint32_t ipv4, QString ipv6);
QList<mdnsd*> mdnsd_;
};