Fix DHCPv4 listen address

This commit is contained in:
世界 2023-09-27 18:25:23 +08:00
parent af791db01f
commit 2f1b2199c5
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
1 changed files with 6 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import (
"net/netip"
"net/url"
"os"
"runtime"
"strings"
"sync"
"time"
@ -176,7 +177,11 @@ func (t *Transport) fetchServers0(ctx context.Context, iface *net.Interface) err
var listener net.ListenConfig
listener.Control = control.Append(listener.Control, control.BindToInterface(t.router.InterfaceFinder(), iface.Name, iface.Index))
listener.Control = control.Append(listener.Control, control.ReuseAddr())
packetConn, err := listener.ListenPacket(t.ctx, "udp4", "0.0.0.0:68")
listenAddr := "0.0.0.0:68"
if runtime.GOOS == "linux" || runtime.GOOS == "android" {
listenAddr = "255.255.255.255:68"
}
packetConn, err := listener.ListenPacket(t.ctx, "udp4", listenAddr)
if err != nil {
return err
}