From 49479c7573ec4d5161eba1b19b8274c46556d245 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 21 Feb 2022 14:37:45 +0400 Subject: [PATCH] fix parsing of IP addresses for zeroconf initialization (#1338) manet.DialArgs returns ip{4,6} for /dns addresses. The address returned in that case is a domain name, not an IP address. --- p2p/discovery/mdns/mdns.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/p2p/discovery/mdns/mdns.go b/p2p/discovery/mdns/mdns.go index f8f50bba20..a84cf807ea 100644 --- a/p2p/discovery/mdns/mdns.go +++ b/p2p/discovery/mdns/mdns.go @@ -5,7 +5,6 @@ import ( "errors" "io" "math/rand" - "net" "strings" "sync" @@ -86,18 +85,14 @@ func (s *mdnsService) Close() error { func (s *mdnsService) getIPs(addrs []ma.Multiaddr) ([]string, error) { var ip4, ip6 string for _, addr := range addrs { - network, hostport, err := manet.DialArgs(addr) - if err != nil { + first, _ := ma.SplitFirst(addr) + if first == nil { continue } - host, _, err := net.SplitHostPort(hostport) - if err != nil { - continue - } - if ip4 == "" && (network == "udp4" || network == "tcp4") { - ip4 = host - } else if ip6 == "" && (network == "udp6" || network == "tcp6") { - ip6 = host + if ip4 == "" && first.Protocol().Code == ma.P_IP4 { + ip4 = first.Value() + } else if ip6 == "" && first.Protocol().Code == ma.P_IP6 { + ip6 = first.Value() } } ips := make([]string, 0, 2)