Use screen name instead of IP address to announce server through zeroconf, same way it is done for client
This commit is contained in:
parent
55ec310590
commit
f2cc582f9f
2 changed files with 4 additions and 36 deletions
|
|
@ -101,27 +101,6 @@ void ZeroconfService::errorHandle(DNSServiceErrorType errorCode)
|
||||||
tr("Error code: %1.").arg(errorCode));
|
tr("Error code: %1.").arg(errorCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ZeroconfService::getLocalIPAddresses()
|
|
||||||
{
|
|
||||||
QStringList addresses;
|
|
||||||
foreach (const QHostAddress& address, QNetworkInterface::allAddresses()) {
|
|
||||||
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 "";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ZeroconfService::registerService(bool server)
|
bool ZeroconfService::registerService(bool server)
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
@ -137,20 +116,10 @@ bool ZeroconfService::registerService(bool server)
|
||||||
else {
|
else {
|
||||||
m_pZeroconfRegister = new ZeroconfRegister(this);
|
m_pZeroconfRegister = new ZeroconfRegister(this);
|
||||||
if (server) {
|
if (server) {
|
||||||
QString localIP = getLocalIPAddresses();
|
m_pZeroconfRegister->registerService(
|
||||||
if (localIP.isEmpty()) {
|
ZeroconfRecord(tr("%1").arg(m_pMainWindow->getScreenName()),
|
||||||
QMessageBox::warning(
|
QLatin1String(m_ServerServiceName), QString()),
|
||||||
m_pMainWindow, tr("Synergy Auto Config"),
|
m_zeroconfServer.serverPort());
|
||||||
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 {
|
else {
|
||||||
m_pZeroconfRegister->registerService(
|
m_pZeroconfRegister->registerService(
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@ private slots:
|
||||||
void errorHandle(DNSServiceErrorType errorCode);
|
void errorHandle(DNSServiceErrorType errorCode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString getLocalIPAddresses();
|
|
||||||
bool registerService(bool server);
|
bool registerService(bool server);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue