dnsclient

package
v0.0.0-...-4a2bce8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package dnsclient contains general DNS-related functionality.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNoAddr is an error for when trying to do a remote operation with a
	// [Client] without supplying an address, either to the method or with
	// [WithRemote].
	ErrNoAddr = errors.New("no address")
)

Functions

This section is empty.

Types

type AXFROption

type AXFROption struct {
	// contains filtered or unexported fields
}

AXFROption is an optional configuration of an AXFR.

func AXFRWithMsg

func AXFRWithMsg(f func(*dns.Msg) error) AXFROption

AXFRWithMsg sets a function to call that can modify the AXFR query before it is sent.

func AXFRWithTsig

func AXFRWithTsig(key *tsig.Key) AXFROption

AXFRWithTsig sets a TSIG key.

func AXFRWithTsigProvider

func AXFRWithTsigProvider(tsigProvider dns.TsigProvider) AXFROption

AXFRWithTsigProvider sets a TSIG provider.

func AXFRWithTsigSecret

func AXFRWithTsigSecret(tsigSecret map[string]string) AXFROption

AXFRWithTsigSecret sets a map of TSIG keys.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a DNS client. It wraps github.com/miekg/dns.Client with some higher-level functionality.

func New

func New(options ...Option) *Client

New returns a new client.

func (*Client) AXFR

func (c *Client) AXFR(
	ctx context.Context,
	addr netip.AddrPort,
	domain dnse.Name,
	options ...AXFROption,
) (serial uint32, rrs iter.Seq2[dns.RR, error], err error)

AXFR performs an AXFR and returns an iterator over the received records. The initial SOA is iterated, but should the initial and final SOA records not be in their correct places then the iterator will return an error (possibly after returning some records).

AXFR is always done over TCP, even if the Client was set up to use UDP.

The address is the address of the remote name server, but if the Client was set up with a remote (see WithRemote) the address is not used.

func (*Client) Exchange

func (c *Client) Exchange(
	ctx context.Context,
	addr netip.AddrPort,
	req *dns.Msg,
) (resp *dns.Msg, rtt time.Duration, err error)

Exchange exchanges a DNS message with the remote name server.

The address is the address of the remote name server. A zero address can be used to use the remote set with WithRemote. WithAlwaysRemote always discards the address passed here.

See github.com/miekg/dns.Exchange.

func (*Client) Notify

func (c *Client) Notify(
	ctx context.Context,
	addr netip.AddrPort,
	name dnse.Name,
) (r *dns.Msg, rtt time.Duration, err error)

Notify sends a DNS NOTIFY message (RFC 1996) to the remote name server.

The address is the address of the remote name server. A zero address can be used to use the remote set with WithRemote. WithAlwaysRemote always discards the address passed here.

func (*Client) Query

func (c *Client) Query(
	ctx context.Context,
	addr netip.AddrPort,
	name dnse.Name,
	class dns.Class,
	typ dns.Type,
) ([]dns.RR, error)

Query queries the remote name server with a single question.

The address is the address of the remote name server. A zero address can be used to use the remote set with WithRemote. WithAlwaysRemote always discards the address passed here.

func (Client) Remote

func (c Client) Remote() *nameserver.Remote

Remote returns the client’s remote name server, if it has one.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is a way to configure a Client.

func WithAlwaysRemote

func WithAlwaysRemote(remote nameserver.Remote) Option

WithAlwaysRemote is a Client option that sets a permanent remote nameserver to use, discarding any address passed to methods such as Client.Exchange.

func WithNet

func WithNet(n string) Option

WithNet sets the type of network the Client uses, e.g. “tcp”. See github.com/miekg/dns.Client.Net.

func WithRemote

func WithRemote(remote nameserver.Remote) Option

WithRemote is a Client option that sets a default remote nameserver to use, if an address passed to a method such as Client.Exchange is invalid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL