Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify advertised IP for dnssd #199

Open
dbarrosop opened this issue May 23, 2021 · 2 comments
Open

specify advertised IP for dnssd #199

dbarrosop opened this issue May 23, 2021 · 2 comments

Comments

@dbarrosop
Copy link

Hello,
in some cases it is necessary to advertise a different IP to the one belonging to the host where the service is running. For instance if you are running the service in a docker container without using host networking or if you need the service outside of the connected network but routing isn't an option and you need to rely on NAT instead.

Currently, dnssd supports specifying an arbitrary IP and hc actually sets the necessary parameter if you set the configuration option Config.IP. This works great, however, Config.IP's documentation states it is a deprecated option. As I think running an hc service inside docker is probably a common use case I'd suggest removing the deprecation notice in the Config.IP option. Alternatively, allowing a custom dnssd configuration but I don't think there are any other parameters that might be worth overriding so the first option seems more convenient. A third option would be to allow specifying a dns entry and resolve it instead of passing an IP address, this would keep things dynamic while allowing you to override the advertised IP.

Thanks for the awesome work :)

Regards
David

@brutella
Copy link
Owner

brutella commented Mar 2, 2022

FYI I've refactored hc and made a new library out of it. The new library is available as hap.

In hap you can specify the the ip and port of the hap server.

s, err := hap.NewServer(...)
s.Addr = "192.168.0.10:12345"
...

https://pkg.go.dev/github.com/brutella/hap#Server

Does this resolve your issue?

@dbarrosop
Copy link
Author

I don't think it's the same, based on the docstring:

        // Addr specifies the tcp address for the server
	// to listen to in form of "host:port".
	// If empty, a random port is used.

What I was suggesting (which was already possible) was decoupling the ip:port you are binding to and the ip:port you are advertising. Simplest use case is running inside a docker container (without using networking in host mode), in which case, you'd probably be binding to 0.0.0.0:12345 but you'd want to announce the IP of the host machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants