Documentation
¶
Overview ¶
Package dnscoretest contains fake servers to test dnscore.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ExampleComAddrA = net.IPv4(93, 184, 215, 14)
ExampleComAddrA is the A address of example.com.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler interface {
Handle(rw ResponseWriter, rawQuery []byte)
}
Handler is a function that handles a DNS query.
func NewExampleComHandler ¶
func NewExampleComHandler() Handler
NewExampleComHandler returns a handler that responds with a valid DNS response for example.com.
type HandlerFunc ¶
type HandlerFunc func(rw ResponseWriter, rawQuery []byte)
HandlerFunc is an adapter to allow the use of ordinary functions as DNS handlers.
func (HandlerFunc) Handle ¶
func (hf HandlerFunc) Handle(rw ResponseWriter, rawQuery []byte)
Handle implements Handler.
type ResponseWriter ¶
ResponseWriter allows writing raw DNS responses.
type Server ¶
type Server struct { // Addr is the address of the server for DNS-over-UDP, // DNS-over-TCP, and DNS-over-TLS. Addr string // Listen is an optional func to override the default // function used to create a [net.Listener]. Listen func(network, address string) (net.Listener, error) // ListenPacket is an optional func to override the default // function used to create a listening [net.PacketConn]. ListenPacket func(network, address string) (net.PacketConn, error) // ListenTLS is an optional func to override the default // function used to listen using TLS. ListenTLS func(network, address string, config *tls.Config) (net.Listener, error) // RootCAs contains the cert pool the client should use // for DNS-over-TLS and DNS-over-HTTPS. RootCAs *x509.CertPool // URL is the URL for DNS-over-HTTPS. URL string // contains filtered or unexported fields }
Server is a fake DNS server.
The zero value is a valid server.
Example (Udp) ¶
package main import ( "fmt" "log" "slices" "strings" "github.com/miekg/dns" "github.com/rbmk-project/dnscore/dnscoretest" ) func main() { // Create a fake UDP server using the example.com handler server := &dnscoretest.Server{} handler := dnscoretest.NewExampleComHandler() <-server.StartUDP(handler) defer server.Close() // Create a DNS client client := &dns.Client{Net: "udp"} query := new(dns.Msg) query.SetQuestion("example.com.", dns.TypeA) // Send the query to the fake server resp, _, err := client.Exchange(query, server.Addr) if err != nil { log.Fatal(err) } // print the results var addrs []string for _, rr := range resp.Answer { switch rr := rr.(type) { case *dns.A: addrs = append(addrs, rr.A.String()) } } slices.Sort(addrs) fmt.Printf("%s\n", strings.Join(addrs, "\n")) }
Output: 93.184.215.14
func (*Server) StartHTTPS ¶
StartHTTPS starts an HTTPS server and handles incoming DNS queries.
This method panics in case of failure.
func (*Server) StartTCP ¶
StartTCP starts a TCP listener and listens for incoming DNS queries.
This method panics in case of failure.