595d0744db
In https://github.com/ooni/probe/issues/2029#issuecomment-1140805266, we explained why calling it "netgo" would be incorrect. In other words, we can get the platform's `getaddrinfo` as long as we're not cross compiling. We do cross compile `ooniprobe`, actually it's not even possible to cross compile it. For increased accuracy, we should stop cross compiling `miniooni` as well, so it would also directly use `getaddrinfo`. This diff fixes at the same time ooni/probe-cli and ooni/spec and we'll open two pull requests in parallel.
39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
//go:build !cgo
|
|
|
|
package netxlite
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
)
|
|
|
|
// getaddrinfoResolverNetwork returns the "network" that is actually
|
|
// been used to implement the getaddrinfo resolver.
|
|
//
|
|
// This is the CGO_ENABLED=0 implementation of this function, which
|
|
// always returns the string "go", because in this scenario we are actually
|
|
// using whatever resolver is used under the hood by the stdlib.
|
|
//
|
|
// See https://github.com/ooni/probe/issues/2029#issuecomment-1140805266
|
|
// for an explanation of why calling this resolver "netgo" is wrong.
|
|
func getaddrinfoResolverNetwork() string {
|
|
return "go"
|
|
}
|
|
|
|
// getaddrinfoLookupANY attempts to perform an ANY lookup using getaddrinfo.
|
|
//
|
|
// This is the CGO_ENABLED=0 implementation of this function.
|
|
//
|
|
// Arguments:
|
|
//
|
|
// - ctx is the context for deadline/timeout/cancellation
|
|
//
|
|
// - domain is the domain to lookup
|
|
//
|
|
// This function returns the list of looked up addresses, an always-empty
|
|
// CNAME, and the error that occurred. On error, the list of addresses is empty.
|
|
func getaddrinfoLookupANY(ctx context.Context, domain string) ([]string, string, error) {
|
|
al, err := net.DefaultResolver.LookupHost(ctx, domain)
|
|
return al, "", err
|
|
}
|