Resolve zeroconf uses bogus IPs #4091
This commit is contained in:
parent
8d7f6e146d
commit
fa1092d665
|
@ -27,6 +27,12 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <dns_sd.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_ServerServiceName = "_synergyServerZeroconf._tcp";
|
||||||
const char* ZeroconfService:: m_ClientServiceName = "_synergyClientZeroconf._tcp";
|
const char* ZeroconfService:: m_ClientServiceName = "_synergyClientZeroconf._tcp";
|
||||||
|
|
||||||
|
@ -100,10 +106,22 @@ void ZeroconfService::errorHandle(DNSServiceErrorType errorCode)
|
||||||
|
|
||||||
QString ZeroconfService::getLocalIPAddresses()
|
QString ZeroconfService::getLocalIPAddresses()
|
||||||
{
|
{
|
||||||
|
QStringList addresses;
|
||||||
foreach (const QHostAddress& address, QNetworkInterface::allAddresses()) {
|
foreach (const QHostAddress& address, QNetworkInterface::allAddresses()) {
|
||||||
if (address.protocol() == QAbstractSocket::IPv4Protocol && address != QHostAddress(QHostAddress::LocalHost))
|
if (address.protocol() == QAbstractSocket::IPv4Protocol &&
|
||||||
return address.toString();
|
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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,11 +139,20 @@ bool ZeroconfService::registerService(bool server)
|
||||||
else {
|
else {
|
||||||
m_pZeroconfRegister = new ZeroconfRegister(this);
|
m_pZeroconfRegister = new ZeroconfRegister(this);
|
||||||
if (server) {
|
if (server) {
|
||||||
|
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(
|
m_pZeroconfRegister->registerService(
|
||||||
ZeroconfRecord(tr("%1").arg(getLocalIPAddresses()),
|
ZeroconfRecord(tr("%1").arg(localIP),
|
||||||
QLatin1String(m_ServerServiceName), QString()),
|
QLatin1String(m_ServerServiceName), QString()),
|
||||||
m_zeroconfServer.serverPort());
|
m_zeroconfServer.serverPort());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
m_pZeroconfRegister->registerService(
|
m_pZeroconfRegister->registerService(
|
||||||
ZeroconfRecord(tr("%1").arg(m_pMainWindow->getScreenName()),
|
ZeroconfRecord(tr("%1").arg(m_pMainWindow->getScreenName()),
|
||||||
|
|
Loading…
Reference in New Issue