Fix set gateway

This commit is contained in:
世界 2024-12-12 22:37:13 +08:00
parent edabb6d7ba
commit d0887eabba
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

4
tun.go
View file

@ -103,6 +103,7 @@ func (o *Options) Inet4GatewayAddr() netip.Addr {
case "darwin": case "darwin":
return o.Inet4Address[0].Addr() return o.Inet4Address[0].Addr()
default: default:
if !o.InterfaceScope {
if HasNextAddress(o.Inet4Address[0], 1) { if HasNextAddress(o.Inet4Address[0], 1) {
return o.Inet4Address[0].Addr().Next() return o.Inet4Address[0].Addr().Next()
} else { } else {
@ -110,6 +111,7 @@ func (o *Options) Inet4GatewayAddr() netip.Addr {
} }
} }
} }
}
return netip.IPv4Unspecified() return netip.IPv4Unspecified()
} }
@ -127,6 +129,7 @@ func (o *Options) Inet6GatewayAddr() netip.Addr {
case "darwin": case "darwin":
return o.Inet6Address[0].Addr() return o.Inet6Address[0].Addr()
default: default:
if !o.InterfaceScope {
if HasNextAddress(o.Inet6Address[0], 1) { if HasNextAddress(o.Inet6Address[0], 1) {
return o.Inet6Address[0].Addr().Next() return o.Inet6Address[0].Addr().Next()
} else { } else {
@ -134,6 +137,7 @@ func (o *Options) Inet6GatewayAddr() netip.Addr {
} }
} }
} }
}
return netip.IPv6Unspecified() return netip.IPv6Unspecified()
} }