Fix scopeid parsing from avahi -> QHostAddress
This commit is contained in:
parent
a429d92add
commit
8849f4f57c
@ -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());
|
||||
}
|
||||
|
@ -14,7 +14,17 @@
|
||||
#include <QSize>
|
||||
#include <QtEndian>
|
||||
|
||||
extern "C" {
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
}
|
||||
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user