From d0887eabba1c86a91138b39a53aeb03b4e99e2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 12 Dec 2024 22:37:13 +0800 Subject: [PATCH] Fix set gateway --- tun.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tun.go b/tun.go index a2cae52..c953943 100644 --- a/tun.go +++ b/tun.go @@ -103,10 +103,12 @@ func (o *Options) Inet4GatewayAddr() netip.Addr { 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() + if !o.InterfaceScope { + if HasNextAddress(o.Inet4Address[0], 1) { + return o.Inet4Address[0].Addr().Next() + } else { + return o.Inet4Address[0].Addr() + } } } } @@ -127,10 +129,12 @@ func (o *Options) Inet6GatewayAddr() netip.Addr { 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() + if !o.InterfaceScope { + if HasNextAddress(o.Inet6Address[0], 1) { + return o.Inet6Address[0].Addr().Next() + } else { + return o.Inet6Address[0].Addr() + } } } }