Update urlv4.go

Add "net.LookupIP()" function to support hostname when we add enode by hostname:port
This commit is contained in:
dipingxian2 2019-01-26 16:53:05 +08:00 committed by GitHub
parent 2209fede4e
commit 9040b4c284
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -124,7 +124,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 {