mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-12-24 13:27:56 +08:00
fix #76 , ipv6 有时会在vs运行后才获得.
This commit is contained in:
@@ -241,7 +241,7 @@ func mainFunc() (result int) {
|
||||
return -1
|
||||
}
|
||||
|
||||
netLayer.Prepare()
|
||||
//netLayer.PrepareInterfaces() //发现有时, ipv6不是程序刚运行时就有的, 所以不应默认 预读网卡。主要是 openwrt等设备 在使用 DHCPv6 获取ipv6 等情况时。
|
||||
|
||||
fmt.Printf("Log Level:%d\n", utils.LogLevel)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ func (a *Addr) Dial() (net.Conn, error) {
|
||||
case "udp", "udp4", "udp6":
|
||||
ua := a.ToUDPAddr()
|
||||
|
||||
if !machineCanConnectToIpv6 && a.IP.To4() == nil {
|
||||
if weKnowThatWeDontHaveIPV6 && a.IP.To4() == nil {
|
||||
return nil, ErrMachineCantConnectToIpv6
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ tcp:
|
||||
|
||||
if a.IP != nil {
|
||||
if a.IP.To4() == nil {
|
||||
if !machineCanConnectToIpv6 {
|
||||
if weKnowThatWeDontHaveIPV6 {
|
||||
return nil, ErrMachineCantConnectToIpv6
|
||||
} else {
|
||||
|
||||
|
||||
@@ -29,16 +29,16 @@ import (
|
||||
|
||||
var (
|
||||
// 如果机器没有ipv6地址, 就无法联通ipv6, 此时可以在dial时更快拒绝ipv6地址,
|
||||
// 避免打印过多错误输出
|
||||
machineCanConnectToIpv6 bool
|
||||
// 避免打印过多错误输出.
|
||||
weKnowThatWeDontHaveIPV6 bool
|
||||
|
||||
ErrMachineCantConnectToIpv6 = errors.New("ErrMachineCanConnectToIpv6")
|
||||
ErrTimeout = errors.New("timeout")
|
||||
)
|
||||
|
||||
//做一些网络层的资料准备工作, 可以优化本包其它函数的调用。
|
||||
func Prepare() {
|
||||
machineCanConnectToIpv6 = HasIpv6Interface()
|
||||
func PrepareInterfaces() {
|
||||
weKnowThatWeDontHaveIPV6 = !HasIpv6Interface()
|
||||
}
|
||||
|
||||
//c.SetDeadline(time.Time{})
|
||||
|
||||
Reference in New Issue
Block a user