Skip to content

Commit dd19139

Browse files
committed
fixed mdns ip issue
sometimes instead of local ip it was advertising the docker ip
1 parent edac003 commit dd19139

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

wap/cmd/mdns/mdns.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package mdns
33
import (
44
"context"
55
"encoding/base64"
6+
"net"
67
"os"
8+
"strings"
79

810
"github.com/functionland/go-fula/wap/pkg/config"
911
wifi "github.com/functionland/go-fula/wap/pkg/wifi"
@@ -145,6 +147,35 @@ func StartServer(ctx context.Context, port int) *MDNSServer {
145147
return server
146148
}
147149

150+
// getLANInterfaces returns network interfaces excluding Docker/virtual bridges.
151+
// Returns nil (all interfaces) as fallback if no physical interfaces found.
152+
func getLANInterfaces() []net.Interface {
153+
ifaces, err := net.Interfaces()
154+
if err != nil {
155+
return nil
156+
}
157+
158+
var filtered []net.Interface
159+
for _, iface := range ifaces {
160+
// Skip down or loopback interfaces
161+
if iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 {
162+
continue
163+
}
164+
// Skip Docker bridges and virtual ethernet pairs
165+
if iface.Name == "docker0" ||
166+
strings.HasPrefix(iface.Name, "br-") ||
167+
strings.HasPrefix(iface.Name, "veth") {
168+
continue
169+
}
170+
filtered = append(filtered, iface)
171+
}
172+
173+
if len(filtered) == 0 {
174+
return nil // fallback: let library use all interfaces
175+
}
176+
return filtered
177+
}
178+
148179
func NewZeroConfService(port int) (*MDNSServer, error) {
149180
meta := createInfo()
150181
log.Debugw("mdns meta created", "meta", meta)
@@ -155,7 +186,7 @@ func NewZeroConfService(port int) (*MDNSServer, error) {
155186
"local.", // service domain
156187
port, // service port
157188
meta, // service metadata
158-
nil, // register on all network interfaces
189+
getLANInterfaces(), // only physical/LAN interfaces
159190
)
160191

161192
if err != nil {

0 commit comments

Comments
 (0)