summaryrefslogtreecommitdiff
path: root/src/zeroconf
diff options
context:
space:
mode:
authorFlorian Schlichting <fsfs@debian.org>2018-10-31 17:54:45 +0100
committerFlorian Schlichting <fsfs@debian.org>2018-10-31 17:54:45 +0100
commitd1f85240a20d83d211b17bf82fa40f77cecae6ca (patch)
tree2a9db8ae3f978973d45cbd3cfd4be97f8a39b0bd /src/zeroconf
parent2148d4bb31cde4751d7be42e2d8c7cd9ac4e0ff4 (diff)
include hostname in zeroconf_name (fixes #387)
expand %h to the system hostname and default to a zeroconf string that contains %h
Diffstat (limited to 'src/zeroconf')
-rw-r--r--src/zeroconf/ZeroconfGlue.cxx10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/zeroconf/ZeroconfGlue.cxx b/src/zeroconf/ZeroconfGlue.cxx
index 21b9403d0..c0fb122b1 100644
--- a/src/zeroconf/ZeroconfGlue.cxx
+++ b/src/zeroconf/ZeroconfGlue.cxx
@@ -27,13 +27,16 @@
#include "util/Domain.hxx"
#include "Log.hxx"
#include "util/Compiler.h"
+#include <unistd.h>
+#include <limits.h>
+#include <regex>
static constexpr Domain zeroconf_domain("zeroconf");
/* The default service name to publish
* (overridden by 'zeroconf_name' config parameter)
*/
-#define SERVICE_NAME "Music Player"
+#define SERVICE_NAME "Music Player @ %h"
#define DEFAULT_ZEROCONF_ENABLED 1
@@ -59,6 +62,11 @@ ZeroconfInit(const ConfigData &config, gcc_unused EventLoop &loop)
serviceName = config.GetString(ConfigOption::ZEROCONF_NAME,
SERVICE_NAME);
+ char hostname[HOST_NAME_MAX+1];
+ gethostname(hostname, HOST_NAME_MAX);
+ std::string sName = std::regex_replace(serviceName, std::regex("%h"), hostname);
+ serviceName = sName.c_str();
+
#ifdef HAVE_AVAHI
AvahiInit(loop, serviceName);
#endif