Open 0x5e opened 1 year ago
Hi @brutella , Thanks for this great project at first :)
I'm testing this project running on my MBP and found a small issue: When iPhone connects the usb cable with MBP, the camera live stream usually not working in Home App.
And I found when usb cable connected, iPhone sometimes request hap server directly from the wired network, not via wifi. https://github.com/brutella/hkcam/blob/959d66471bc0d76859a82d429e9077061f4dde9f/setup.go#L89-L98
The iface value is en14 instead of en0. then the server failed to get ip of en14 because it only have a ipv6 address.
iface
en14
en0
Instead of get localIP from r.Context().Value(http.LocalAddrContextKey), my solution is like this:
localIP
r.Context().Value(http.LocalAddrContextKey)
remoteIP
req.ControllerAddr.IPAddr
net.Interfaces()
func FindLocalIPForRemoteIP(remoteIP string) string { ifaces, _ := net.Interfaces() for _, iface := range ifaces { addrs, _ := iface.Addrs() for _, addr := range addrs { ip, subnet, _ := net.ParseCIDR(addr.String()) if subnet.Contains(net.ParseIP(remoteIP)) { return ip.String() } } } return "" } localIP := util.FindLocalIPForRemoteIP(req.ControllerAddr.IPAddr) if localIP == "" { log.Debug.Println("Failed to get localIP") return }
Sounds good to me. Happy to accept a pull request. 😉
Hi @brutella , Thanks for this great project at first :)
I'm testing this project running on my MBP and found a small issue: When iPhone connects the usb cable with MBP, the camera live stream usually not working in Home App.
And I found when usb cable connected, iPhone sometimes request hap server directly from the wired network, not via wifi. https://github.com/brutella/hkcam/blob/959d66471bc0d76859a82d429e9077061f4dde9f/setup.go#L89-L98
The
iface
value isen14
instead ofen0
. then the server failed to get ip ofen14
because it only have a ipv6 address.Instead of get
localIP
fromr.Context().Value(http.LocalAddrContextKey)
, my solution is like this:remoteIP
fromreq.ControllerAddr.IPAddr
net.Interfaces()
, find the proper subnet that containsremoteIP
, return the ip of this interface.