mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-19 00:56:16 +00:00
fix: resolve interface names for web bind address
Fixes #264 Signed-off-by: mehmet turac <mehmetturac@gmail.com>
This commit is contained in:
committed by
Tobias Gesellchen
parent
8ee15bb034
commit
413ae74315
@@ -6,6 +6,7 @@ import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
@@ -47,7 +48,7 @@ func main() {
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
port := c.String("port")
|
||||
bindAddr := c.String("bind")
|
||||
bindAddr := resolveBindAddr(c.String("bind"))
|
||||
ifaceName := c.String("interface")
|
||||
|
||||
addr := ":" + port
|
||||
@@ -101,6 +102,35 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func resolveBindAddr(bindAddr string) string {
|
||||
iface, err := net.InterfaceByName(bindAddr)
|
||||
if err != nil {
|
||||
return bindAddr
|
||||
}
|
||||
|
||||
addrs, err := iface.Addrs()
|
||||
if err != nil {
|
||||
return bindAddr
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
|
||||
switch v := addr.(type) {
|
||||
case *net.IPNet:
|
||||
ip = v.IP
|
||||
case *net.IPAddr:
|
||||
ip = v.IP
|
||||
}
|
||||
|
||||
if ipv4 := ip.To4(); ipv4 != nil {
|
||||
return ipv4.String()
|
||||
}
|
||||
}
|
||||
|
||||
return bindAddr
|
||||
}
|
||||
|
||||
func setupRoutes(app *handlers.WebApp, discoveryService *discovery.UnifiedDiscoveryService) *chi.Mux {
|
||||
r := chi.NewRouter()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user