From 921a40c6841951fc6b744751f39c1a0dcf1b94ed Mon Sep 17 00:00:00 2001 From: walker0643 <> Date: Tue, 13 Mar 2018 12:11:17 -0400 Subject: [PATCH] silence avahi's bonjour warning --- src/gui/src/ZeroconfService.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/gui/src/ZeroconfService.cpp b/src/gui/src/ZeroconfService.cpp index 56618e44..02902ee5 100644 --- a/src/gui/src/ZeroconfService.cpp +++ b/src/gui/src/ZeroconfService.cpp @@ -27,6 +27,13 @@ #include #include +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#else +#include +#endif + static const QStringList preferedIPAddress( QStringList() << "192.168." << @@ -36,12 +43,29 @@ static const QStringList preferedIPAddress( const char* ZeroconfService:: m_ServerServiceName = "_barrierServerZeroconf._tcp"; const char* ZeroconfService:: m_ClientServiceName = "_barrierClientZeroconf._tcp"; +static void silence_avahi_warning() +{ + // the libavahi folks seemingly find Apple's bonjour API distasteful + // and are quite liberal in taking it out on users...unless we set + // this environmental variable before calling the avahi library. + // additionally, Microsoft does not give us a POSIX setenv() so + // we use their OS-specific API instead + const char *name = "AVAHI_COMPAT_NOWARN"; + const char *value = "1"; +#ifdef _WIN32 + SetEnvironmentVariable(name, value); +#else + setenv(name, value, 1); +#endif +} + ZeroconfService::ZeroconfService(MainWindow* mainWindow) : m_pMainWindow(mainWindow), m_pZeroconfBrowser(0), m_pZeroconfRegister(0), m_ServiceRegistered(false) { + silence_avahi_warning(); if (m_pMainWindow->barrierType() == MainWindow::barrierServer) { if (registerService(true)) { m_pZeroconfBrowser = new ZeroconfBrowser(this);