Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix parsing of IP addresses for zeroconf initialization #1338

Merged
merged 1 commit into from Feb 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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