Skip to content

Commit

Permalink
Fix isIPv4 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cevatbarisyilmaz committed Nov 7, 2019
1 parent 0c967d1 commit 177335a
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ type Dialer struct {
// See func net.Dial for a description of the network and address
// parameters.
func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
var addresses []string
host, port, err := net.SplitHostPort(address)
if err != nil {
return nil, err
}
var addresses []string
ip := net.ParseIP(host)
if ip != nil {
addresses = []string{address}
Expand All @@ -156,10 +156,7 @@ func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.
} else {
c, err = d.dialSerial(ctx, network, primaries)
}
if err != nil {
return nil, err
}
return c, nil
return c, err
}

func (d *Dialer) resolver() Resolver {
Expand Down Expand Up @@ -348,5 +345,5 @@ func partition(addresses []string) (primaries []string, fallbacks []string) {
// isIPv4 reports whether addr contains an IPv4 address.
func isIPv4(addr string) bool {
tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
return err == nil && tcpAddr.IP.To16() == nil
return err == nil && tcpAddr.IP.To4() != nil
}

0 comments on commit 177335a

Please sign in to comment.