diff --git a/libqcp/qcpmodel.cpp b/libqcp/qcpmodel.cpp index 08ed258..8ac41cf 100644 --- a/libqcp/qcpmodel.cpp +++ b/libqcp/qcpmodel.cpp @@ -14,9 +14,7 @@ namespace QCP { case 0: return m_service.hostname(); case 1: if (m_service.address().protocol() == QAbstractSocket::IPv6Protocol) { - QString scope = m_service.address().scopeId(); - if (!scope.isEmpty()) scope = "%" + scope; - return QString("[%1%2]:%3").arg(m_service.address().toString(), scope).arg(m_service.port()); + return QString("[%1]:%2").arg(m_service.address().toString()).arg(m_service.port()); } else { return QString("%1:%2").arg(m_service.address().toString()).arg(m_service.port()); } diff --git a/libqtavahi/qtavahi.cpp b/libqtavahi/qtavahi.cpp index 8de9ed7..f10f2f0 100644 --- a/libqtavahi/qtavahi.cpp +++ b/libqtavahi/qtavahi.cpp @@ -14,7 +14,17 @@ #include #include +extern "C" { #include +#include +} + +static QString ifidx2name(unsigned int ifindex) { + char buf[IF_NAMESIZE]; + char *n = ::if_indextoname(ifindex, buf); + if (!n) return QString(); + return QString::fromUtf8(n, qstrnlen(n, IF_NAMESIZE)); +} namespace Avahi { @@ -23,12 +33,9 @@ namespace Avahi { case AVAHI_PROTO_INET: return QHostAddress(qFromBigEndian((quint32) address->data.ipv4.address)); case AVAHI_PROTO_INET6: { - struct sockaddr_in6 a; - memset(&a, 0, sizeof(a)); - a.sin6_family = AF_INET6; - a.sin6_scope_id = interface; - memcpy(a.sin6_addr.s6_addr, address->data.ipv6.address, 16); - return QHostAddress((const sockaddr*) &a); + QHostAddress addr((quint8*) address->data.ipv6.address); + if (interface >= 0) addr.setScopeId(ifidx2name(interface)); + return addr; } case AVAHI_PROTO_UNSPEC: return QHostAddress();