Ver Fonte

Fixed: use LookupIP, which handles both domain name and IP address hosts

Rod Hynes há 11 anos atrás
pai
commit
15672dfed4
1 ficheiros alterados com 7 adições e 3 exclusões
  1. 7 3
      psiphon/directConn_unix.go

+ 7 - 3
psiphon/directConn_unix.go

@@ -84,12 +84,16 @@ func interruptibleDial(
 	if err != nil {
 	if err != nil {
 		return nil, ContextError(err)
 		return nil, ContextError(err)
 	}
 	}
-	ipAddr, err := net.ResolveIPAddr("ip", host)
+	// TODO: IPv6 support
+	var ip [4]byte
+	ipAddrs, err := net.LookupIP(host)
 	if err != nil {
 	if err != nil {
 		return nil, ContextError(err)
 		return nil, ContextError(err)
 	}
 	}
-	var ip [4]byte
-	copy(ip[:], ipAddr.IP)
+	if len(ipAddrs) < 1 {
+		return nil, ContextError(errors.New("no ip address"))
+	}
+	copy(ip[:], ipAddrs[0].To4())
 	// Connect the socket
 	// Connect the socket
 	sockAddr := syscall.SockaddrInet4{Addr: ip, Port: port}
 	sockAddr := syscall.SockaddrInet4{Addr: ip, Port: port}
 	if connectTimeout != 0 {
 	if connectTimeout != 0 {