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 errors in IPv6 environment. #5

Merged
merged 1 commit into from
Mar 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,21 @@ func safeAddr(ctx context.Context, resolver *net.Resolver, hostport string) (str
if err != nil || len(addrs) <= 0 {
return "", err
}
safeAddrs := make([]net.IPAddr, 0, len(addrs))
for _, addr := range addrs {
if addr.IP.To4() != nil && isBadIPv4(addr.IP) {
// only support IPv4 address
if addr.IP.To4() == nil {
continue
}
if isBadIPv4(addr.IP) {
return "", fmt.Errorf("bad ip is detected: %v", addr.IP)
}
safeAddrs = append(safeAddrs, addr)
}
if len(safeAddrs) == 0 {
return "", fmt.Errorf("fail to lookup ip addr: %v", host)
}
return net.JoinHostPort(addrs[0].IP.String(), port), nil
return net.JoinHostPort(safeAddrs[0].IP.String(), port), nil
}

// NewDialer returns a dialer function which only allows IPv4 connections.
Expand Down