look up IP if host is FQDN (#544)

Fixes #147
This commit is contained in:
Poh Zi How 2018-10-03 04:38:20 +08:00 committed by Samer Falah
parent 2ad2e0b4bf
commit 05f6cf9bb2
1 changed files with 8 additions and 2 deletions

View File

@ -145,7 +145,7 @@ var incompleteNodeURL = regexp.MustCompile("(?i)^(?:enode://)?([0-9a-f]+)$")
//
// For complete nodes, the node ID is encoded in the username portion
// of the URL, separated from the host by an @ sign. The hostname can
// only be given as an IP address, DNS domain names are not allowed.
// be given as an IP address or a DNS domain name.
// The port in the host name section is the TCP listening port. If the
// TCP and UDP (discovery) ports differ, the UDP port is specified as
// query parameter "discport".
@ -192,7 +192,13 @@ func parseComplete(rawurl string) (*Node, error) {
return nil, fmt.Errorf("invalid host: %v", err)
}
if ip = net.ParseIP(host); ip == nil {
return nil, errors.New("invalid IP address")
// attempt to look up IP addresses if host is a FQDN
lookupIPs, err := net.LookupIP(host)
if err != nil {
return nil, errors.New("invalid IP address")
}
// set to first ip by default
ip = lookupIPs[0]
}
// Ensure the IP is 4 bytes long for IPv4 addresses.
if ipv4 := ip.To4(); ipv4 != nil {