Просмотр исходного кода

Merge pull request #45 from rod-hynes/master

Fix: bindLookupIP now simply echos back its input when it's already an IP address
Rod Hynes 11 лет назад
Родитель
Сommit
4eb580f266
1 измененных файлов с 9 добавлено и 2 удалено
  1. 9 2
      psiphon/LookupIP.go

+ 9 - 2
psiphon/LookupIP.go

@@ -33,7 +33,7 @@ import (
 const DNS_PORT = 53
 
 // LookupIP resolves a hostname. When BindToDevice is not required, it
-// simply uses net.LookuIP.
+// simply uses net.LookupIP.
 // When BindToDevice is required, LookupIP explicitly creates a UDP
 // socket, binds it to the device, and makes an explicit DNS request
 // to the specified DNS resolver.
@@ -49,6 +49,13 @@ func LookupIP(host string, config *DialConfig) (addrs []net.IP, err error) {
 // The sequence of syscalls in this implementation are taken from:
 // https://code.google.com/p/go/issues/detail?id=6966
 func bindLookupIP(host string, config *DialConfig) (addrs []net.IP, err error) {
+
+	// When the input host is an IP address, echo it back
+	ipAddr := net.ParseIP(host)
+	if ipAddr != nil {
+		return []net.IP{ipAddr}, nil
+	}
+
 	socketFd, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, 0)
 	if err != nil {
 		return nil, ContextError(err)
@@ -59,7 +66,7 @@ func bindLookupIP(host string, config *DialConfig) (addrs []net.IP, err error) {
 	config.BindToDeviceProvider.BindToDevice(socketFd)
 
 	// config.BindToDeviceDnsServer must be an IP address
-	ipAddr := net.ParseIP(config.BindToDeviceDnsServer)
+	ipAddr = net.ParseIP(config.BindToDeviceDnsServer)
 	if ipAddr == nil {
 		return nil, ContextError(errors.New("invalid IP address"))
 	}