conn: change OutboundIP to return string

This commit is contained in:
nadoo 2018-01-13 14:34:49 +08:00
parent 950ed2b426
commit 21935fc6b9
2 changed files with 5 additions and 7 deletions

10
conn.go
View File

@ -3,7 +3,6 @@ package main
import ( import (
"bufio" "bufio"
"io" "io"
"log"
"net" "net"
"time" "time"
) )
@ -82,14 +81,13 @@ func timedCopy(dst net.PacketConn, target net.Addr, src net.PacketConn, timeout
} }
// OutboundIP returns preferred outbound ip of this machine // OutboundIP returns preferred outbound ip of this machine
func OutboundIP() net.IP { func OutboundIP() string {
conn, err := net.Dial("udp", "8.8.8.8:80") conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil { if err != nil {
log.Fatal(err) logf("get outbound ip error: %s", err)
return ""
} }
defer conn.Close() defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr) return conn.LocalAddr().(*net.UDPAddr).IP.String()
return localAddr.IP
} }

View File

@ -37,7 +37,7 @@ func NewHTTP(addr, user, pass, rawQuery string, cDialer Dialer, sDialer Dialer)
user: user, user: user,
password: pass, password: pass,
xff: false, xff: false,
selfip: OutboundIP().String(), selfip: OutboundIP(),
} }
p, _ := url.ParseQuery(rawQuery) p, _ := url.ParseQuery(rawQuery)