include hostname in zeroconf_name (fixes #387)

expand %h to the system hostname and default to a zeroconf string that
contains %h
This commit is contained in:
Florian Schlichting
2018-10-31 17:54:45 +01:00
parent 2148d4bb31
commit d1f85240a2
4 changed files with 15 additions and 5 deletions

View File

@@ -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