github.com/yaling888/clash@v1.53.0/component/dhcp/conn.go (about) 1 package dhcp 2 3 import ( 4 "context" 5 "net" 6 "runtime" 7 8 "github.com/yaling888/clash/component/dialer" 9 ) 10 11 func ListenDHCPClient(ctx context.Context, ifaceName string) (net.PacketConn, error) { 12 listenAddr := "0.0.0.0:68" 13 if runtime.GOOS == "linux" || runtime.GOOS == "android" { 14 listenAddr = "255.255.255.255:68" 15 } 16 17 options := []dialer.Option{ 18 dialer.WithInterface(ifaceName), 19 dialer.WithAddrReuse(true), 20 } 21 22 if runtime.GOOS == "windows" { 23 options = append(options, dialer.WithFallbackBind(true)) 24 } 25 26 return dialer.ListenPacket(ctx, "udp4", listenAddr, options...) 27 }