Resolve zeroconf uses bogus IPs #4091
This commit is contained in:
parent
8d7f6e146d
commit
fa1092d665
|
@ -27,6 +27,12 @@
|
|||
#include <stdint.h>
|
||||
#include <dns_sd.h>
|
||||
|
||||
static const QStringList preferedIPAddress(
|
||||
QStringList() <<
|
||||
"192.168." <<
|
||||
"10." <<
|
||||
"172.");
|
||||
|
||||
const char* ZeroconfService:: m_ServerServiceName = "_synergyServerZeroconf._tcp";
|
||||
const char* ZeroconfService:: m_ClientServiceName = "_synergyClientZeroconf._tcp";
|
||||
|
||||
|
@ -100,10 +106,22 @@ void ZeroconfService::errorHandle(DNSServiceErrorType errorCode)
|
|||
|
||||
QString ZeroconfService::getLocalIPAddresses()
|
||||
{
|
||||
QStringList addresses;
|
||||
foreach (const QHostAddress& address, QNetworkInterface::allAddresses()) {
|
||||
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost))
|
||||
return address.toString();
|
||||
if (address.protocol() == QAbstractSocket::IPv4Protocol &&
|
||||
address != QHostAddress(QHostAddress::LocalHost)) {
|
||||
addresses.append(address.toString());
|
||||
}
|
||||
}
|
||||
|
||||
foreach (const QString& preferedIP, preferedIPAddress) {
|
||||
foreach (const QString& address, addresses) {
|
||||
if (address.startsWith(preferedIP)) {
|
||||
return address;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -121,10 +139,19 @@ bool ZeroconfService::registerService(bool server)
|
|||
else {
|
||||
m_pZeroconfRegister = new ZeroconfRegister(this);
|
||||
if (server) {
|
||||
m_pZeroconfRegister->registerService(
|
||||
ZeroconfRecord(tr("%1").arg(getLocalIPAddresses()),
|
||||
QLatin1String(m_ServerServiceName), QString()),
|
||||
m_zeroconfServer.serverPort());
|
||||
QString localIP = getLocalIPAddresses();
|
||||
if (localIP.isEmpty()) {
|
||||
QMessageBox::warning(m_pMainWindow, tr("Synergy"),
|
||||
tr("Failed to get local IP address. "
|
||||
"Please manually type in server address "
|
||||
"on your clients"));
|
||||
}
|
||||
else {
|
||||
m_pZeroconfRegister->registerService(
|
||||
ZeroconfRecord(tr("%1").arg(localIP),
|
||||
QLatin1String(m_ServerServiceName), QString()),
|
||||
m_zeroconfServer.serverPort());
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_pZeroconfRegister->registerService(
|
||||
|
|
Loading…
Reference in New Issue