From ed7fbcbb5065a37c5331aadf798e431d6beb9e5a Mon Sep 17 00:00:00 2001 From: e1732a364fed <75717694+e1732a364fed@users.noreply.github.com> Date: Sat, 1 Jan 2000 00:00:00 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8dial=E4=B8=AD=E5=9C=A8localAddr?= =?UTF-8?q?=E6=8C=87=E6=98=8E=E6=97=B6,=E5=8C=BA=E5=88=86v4=E5=92=8Cv6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/install.md | 2 +- netLayer/dial.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/install.md b/docs/install.md index b14680d..b3aa4d6 100644 --- a/docs/install.md +++ b/docs/install.md @@ -68,7 +68,7 @@ sudo cp examples/vlesss.server.toml server.toml 如果你不愿意使用linux的“后台服务”,只是想手动去令它在后台运行,那么实际上,在verysimple所在位置运行如下一段命令即可。 ``` -nohup ./verysimple_linux_amd64 -c server.toml >/dev/null & +nohup ./verysimple -c server.toml >/dev/null & ``` 这里将它的标准输出舍弃了,因为一般来说我们会在toml配置文件中 配置好日志文件名称;如果不舍弃输出的话,就会多一个输出(到控制台),增加系统负担。 diff --git a/netLayer/dial.go b/netLayer/dial.go index 15b2e15..53a0797 100644 --- a/netLayer/dial.go +++ b/netLayer/dial.go @@ -147,6 +147,29 @@ func (a Addr) DialWithOpt(sockopt *Sockopt, localAddr net.Addr) (net.Conn, error } if localAddr != nil { dialer.LocalAddr = localAddr + + //localAddr一般用于指定ipv4或者ipv6出站,所以我们这里标注一下。 + switch a.Network { + case "tcp": + if ta, ok := localAddr.(*net.TCPAddr); ok { + + //ipv6 + if ta.IP.To4() == nil { + a.Network = "tcp6" + } else { + a.Network = "tcp4" + } + } + case "udp": + if ta, ok := localAddr.(*net.UDPAddr); ok { + + if ta.IP.To4() == nil { + a.Network = "udp6" + } else { + a.Network = "udp4" + } + } + } } if sockopt != nil { dialer.Control = func(network, address string, c syscall.RawConn) error {