chore: import improved bogons handling code (#723)
This diff imports improved bogons handling code from websteps
winter 2022 edition's repository.
See https://github.com/ooni/probe/issues/2095
See a65f3e8579/internal/netxlite/bogon.go
This commit is contained in:
parent
1776ea1288
commit
0efd4ff130
5 changed files with 148 additions and 24 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
|
|
@ -208,6 +209,23 @@ func (r *resolverShortCircuitIPAddr) LookupHost(ctx context.Context, hostname st
|
|||
return r.Resolver.LookupHost(ctx, hostname)
|
||||
}
|
||||
|
||||
// IsIPv6 returns true if the given candidate is a valid IP address
|
||||
// representation and such representation is IPv6.
|
||||
func IsIPv6(candidate string) (bool, error) {
|
||||
if net.ParseIP(candidate) == nil {
|
||||
return false, ErrInvalidIP
|
||||
}
|
||||
return isIPv6(candidate), nil
|
||||
}
|
||||
|
||||
// isIPv6 returns true if the given IP address is IPv6.
|
||||
func isIPv6(candidate string) bool {
|
||||
// This check for identifying IPv6 is discussed
|
||||
// at https://stackoverflow.com/questions/22751035
|
||||
// and seems good-enough for our purposes.
|
||||
return strings.Contains(candidate, ":")
|
||||
}
|
||||
|
||||
// ErrNoResolver is the type of error returned by "without resolver"
|
||||
// dialer when asked to dial for and endpoint containing a domain name,
|
||||
// since they can only dial for endpoints containing IP addresses.
|
||||
|
|
|
|||
Loading…
Reference in a new issue