Handle both IPv4 and IPv6
use net.JoinHostPort(minerIP, minerPort) to handle both IPv4 and IPv6 addresses.
This commit is contained in:
parent
65638ae0c1
commit
8c30e06eb6
@ -806,13 +806,8 @@ func extractRoutableIP(timeout time.Duration) (string, error) {
|
|||||||
}
|
}
|
||||||
minerPort, _ := maddr.ValueForProtocol(multiaddr.P_TCP)
|
minerPort, _ := maddr.ValueForProtocol(multiaddr.P_TCP)
|
||||||
|
|
||||||
// Check if the IP is IPv6 and format the address appropriately
|
// Format the address appropriately
|
||||||
var addressToDial string
|
addressToDial := net.JoinHostPort(minerIP, minerPort)
|
||||||
if ip := net.ParseIP(minerIP); ip.To4() == nil && ip.To16() != nil {
|
|
||||||
addressToDial = "[" + minerIP + "]:" + minerPort
|
|
||||||
} else {
|
|
||||||
addressToDial = minerIP + ":" + minerPort
|
|
||||||
}
|
|
||||||
|
|
||||||
conn, err := net.DialTimeout("tcp", addressToDial, timeout)
|
conn, err := net.DialTimeout("tcp", addressToDial, timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user