c9943dff38
This pull request started as a draft to enable users to see CNAME answers. It contained several patches which we merged separately (see https://github.com/ooni/probe-cli/pull/873#issuecomment-1222406732 and 2301a30630...60b7d1f87b
for details on what has actually changed, which is based on patches originally part of this PR). In its final form, however, this PR only deals with exposing more low-level DNS fields to the archival data format.
Closes: https://github.com/ooni/probe/issues/2228
Related PR spec: https://github.com/ooni/spec/pull/256
42 lines
1012 B
Go
42 lines
1012 B
Go
package netxlite
|
|
|
|
import "errors"
|
|
|
|
// ErrGetaddrinfo represents a getaddrinfo failure.
|
|
type ErrGetaddrinfo struct {
|
|
// Err is the error proper.
|
|
Underlying error
|
|
|
|
// Code is getaddrinfo's return code.
|
|
Code int64
|
|
}
|
|
|
|
// newErrGetaddrinfo creates a new instance of the ErrGetaddrinfo type.
|
|
func newErrGetaddrinfo(code int64, err error) *ErrGetaddrinfo {
|
|
return &ErrGetaddrinfo{
|
|
Underlying: err,
|
|
Code: code,
|
|
}
|
|
}
|
|
|
|
// Error returns the underlying error's string.
|
|
func (err *ErrGetaddrinfo) Error() string {
|
|
return err.Underlying.Error()
|
|
}
|
|
|
|
// Unwrap allows to get the underlying error value.
|
|
func (err *ErrGetaddrinfo) Unwrap() error {
|
|
return err.Underlying
|
|
}
|
|
|
|
// ErrorToGetaddrinfoRetvalOrZero converts an arbitrary error to
|
|
// the return value of getaddrinfo. If err is nil or is not
|
|
// an instance of ErrGetaddrinfo, we just return zero.
|
|
func ErrorToGetaddrinfoRetvalOrZero(err error) int64 {
|
|
var aierr *ErrGetaddrinfo
|
|
if err != nil && errors.As(err, &aierr) {
|
|
return aierr.Code
|
|
}
|
|
return 0
|
|
}
|