Skip to content

Commit

Permalink
Instance: implement Zeroconf publisher
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Oct 22, 2023
1 parent 478a07d commit 823be7f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Instance.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,23 @@ Instance::AddListener(const ListenerConfig &config)
listeners.emplace_front(*this, config.Create(SOCK_STREAM));

#ifdef HAVE_AVAHI
// TODO
auto &listener = listeners.front();

if (!config.zeroconf_service.empty()) {
/* ask the kernel for the effective address via
getsockname(), because it may have changed, e.g. if
the kernel has selected a port for us */
const auto local_address = listener.GetLocalAddress();
if (local_address.IsDefined()) {
const char *const interface = config.interface.empty()
? nullptr
: config.interface.c_str();

avahi_services.emplace_front(config.zeroconf_service.c_str(),
interface, local_address,
config.v6only);
}
}
#endif // HAVE_AVAHI
}

Expand Down
4 changes: 4 additions & 0 deletions src/Main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ try {
for (const auto &i : config.listeners)
instance.AddListener(i);

#ifdef HAVE_AVAHI
instance.EnableZeroconf();
#endif // HAVE_AVAHI

#ifdef HAVE_LIBSYSTEMD
/* tell systemd we're ready */
sd_notify(0, "READY=1");
Expand Down

0 comments on commit 823be7f

Please sign in to comment.