Skip to content

Commit

Permalink
Fix gateway select
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Nov 8, 2024
1 parent d95423e commit b2b56ff
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,20 @@ func (o *Options) Inet4GatewayAddr() netip.Addr {
return o.Inet4Gateway
}
if len(o.Inet4Address) > 0 {
if HasNextAddress(o.Inet4Address[0], 1) {
return o.Inet4Address[0].Addr().Next()
} else if runtime.GOOS != "linux" {
switch runtime.GOOS {
case "android":
case "linux":
if HasNextAddress(o.Inet4Address[0], 1) {
return o.Inet4Address[0].Addr().Next()
}
case "darwin":
return o.Inet4Address[0].Addr()
default:
if HasNextAddress(o.Inet4Address[0], 1) {
return o.Inet4Address[0].Addr().Next()
} else {
return o.Inet4Address[0].Addr()
}
}
}
return netip.IPv4Unspecified()
Expand All @@ -103,10 +113,20 @@ func (o *Options) Inet6GatewayAddr() netip.Addr {
return o.Inet6Gateway
}
if len(o.Inet6Address) > 0 {
if HasNextAddress(o.Inet6Address[0], 1) {
return o.Inet6Address[0].Addr().Next()
} else if runtime.GOOS != "linux" {
switch runtime.GOOS {
case "android":
case "linux":
if HasNextAddress(o.Inet6Address[0], 1) {
return o.Inet6Address[0].Addr().Next()
}
case "darwin":
return o.Inet6Address[0].Addr()
default:
if HasNextAddress(o.Inet6Address[0], 1) {
return o.Inet6Address[0].Addr().Next()
} else {
return o.Inet6Address[0].Addr()
}
}
}
return netip.IPv6Unspecified()
Expand Down

0 comments on commit b2b56ff

Please sign in to comment.