Skip to content

Commit

Permalink
fix parsing of IP addresses for zeroconf initialization (#1338)
Browse files Browse the repository at this point in the history
manet.DialArgs returns ip{4,6} for /dns addresses. The address returned in that
case is a domain name, not an IP address.
  • Loading branch information
marten-seemann committed Feb 21, 2022
1 parent ccdd17f commit 49479c7
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions p2p/discovery/mdns/mdns.go
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"io"
"math/rand"
"net"
"strings"
"sync"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 49479c7

Please sign in to comment.