mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
Update urlv4.go
Add "net.LookupIP()" function to support hostname when we add enode by hostname:port
This commit is contained in:
parent
2209fede4e
commit
9040b4c284
1 changed files with 7 additions and 1 deletions
|
|
@ -124,8 +124,14 @@ func parseComplete(rawurl string) (*Node, error) {
|
||||||
return nil, fmt.Errorf("invalid host: %v", err)
|
return nil, fmt.Errorf("invalid host: %v", err)
|
||||||
}
|
}
|
||||||
if ip = net.ParseIP(host); ip == nil {
|
if ip = net.ParseIP(host); ip == nil {
|
||||||
|
// 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")
|
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.
|
// Ensure the IP is 4 bytes long for IPv4 addresses.
|
||||||
if ipv4 := ip.To4(); ipv4 != nil {
|
if ipv4 := ip.To4(); ipv4 != nil {
|
||||||
ip = ipv4
|
ip = ipv4
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue