resolv

package module
v0.0.0-...-7f96e8f Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2015 License: MIT Imports: 9 Imported by: 0

README

Resolv Travis CI GoDoc

A context aware DNS library based on Miek's library. It's goal to offer a simple API to most common DNS operations while preserving access to low level data.

Installation

$ go get -u github.com/vitalie/resolv

Usage

package main

import (
    "fmt"
    "log"

    "github.com/miekg/dns"
    "golang.org/x/net/context"
    "github.com/vitalie/resolv"
)

func main() {
    r := resolv.NewResolver()

    // Issue an UDP request using default options.
    req := resolv.NewRequest("ns1.luadns.net", "cherpec.com", dns.TypeA)
    resp := <-r.Resolve(req)
    if resp.Err != nil {
        log.Fatalln("error:", resp.Err)
    }
    fmt.Println(resp)

    // Create a request factory.
    fact := resolv.NewRequestFactory()

    // Query multiple types.
    reqs := fact.FromTypes("ns1.luadns.net", "cherpec.com", dns.TypeA, dns.TypeNS, dns.TypeMX)
    for resp := range r.FanIn(context.Background(), reqs...) {
      fmt.Println(resp)
    }

    // Query multiple names.
    reqs = fact.FromNames("ns1.luadns.net", dns.TypeA, "cherpec.com", "www.cherpec.com")
    for resp := range r.FanIn(context.Background(), reqs...) {
      fmt.Println(resp)
    }
}

TODO

  • Cache responses
  • Retry queries on timeout
  • Don't query local resolver
  • Switch to TCP on truncated responses

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Documentation

Index

Constants

View Source
const (
	DefaultPort   = "53"
	MaxDepth      = 16
	MaxIterations = 32
)

Variables

View Source
var RootServers = []string{
	"a.root-servers.net.",
	"b.root-servers.net.",
	"c.root-servers.net.",
	"d.root-servers.net.",
	"e.root-servers.net.",
	"f.root-servers.net.",
	"g.root-servers.net.",
	"h.root-servers.net.",
	"i.root-servers.net.",
	"j.root-servers.net.",
	"k.root-servers.net.",
	"l.root-servers.net.",
	"m.root-servers.net.",
}

Functions

func SetCHAOSClass

func SetCHAOSClass(req *Request)

SetCHAOSClass sets the class to CHAOS for a request.

func SetRD

func SetRD(req *Request)

SetRD enables recursion for a request.

func SetTCPMode

func SetTCPMode(req *Request)

SetTCPMode configures the query to run in TCP mode.

Types

type DNSError

type DNSError struct {
	Err   string
	Name  string
	Type  uint16
	Class uint16
	Addr  string

	IsNameError bool
	IsTimeout   bool
}

func NewDNSError

func NewDNSError(err string, req *Request) *DNSError

func (*DNSError) Error

func (e *DNSError) Error() string

func (*DNSError) NameError

func (e *DNSError) NameError() bool

func (*DNSError) Temporary

func (e *DNSError) Temporary() bool

func (*DNSError) Timeout

func (e *DNSError) Timeout() bool

type Iterator

type Iterator struct {
	Debug bool
	// contains filtered or unexported fields
}

Iterator represents an iterative DNS query.

func NewIterator

func NewIterator(r *Resolver) *Iterator

NewIterator initializes an Iterator structure.

func (*Iterator) Delegation

func (it *Iterator) Delegation(ctx context.Context, name string) (string, []*net.NS, error)

Delegation looks up the delegation returning the parent name and the DNS NS records for a given name.

func (*Iterator) LookupIP

func (it *Iterator) LookupIP(ctx context.Context, host string) ([]net.IP, error)

LookupIP looks up the IPv4 and IPv6 addresses for the host.

func (*Iterator) LookupIPv4

func (it *Iterator) LookupIPv4(ctx context.Context, host string) ([]net.IP, error)

LookupIPv4 looks up the IPv4 addresses for the host.

func (*Iterator) LookupIPv6

func (it *Iterator) LookupIPv6(ctx context.Context, host string) ([]net.IP, error)

LookupIPv6 looks up the IPv6 addresses for the host.

func (*Iterator) LookupNS

func (it *Iterator) LookupNS(ctx context.Context, host string) ([]*net.NS, error)

LookupNS looks up the DNS NS records for the given name.

func (*Iterator) Resolve

func (it *Iterator) Resolve(ctx context.Context, name string, type_ uint16) <-chan *Response

Resolve looks up the name starting from root servers following referals.

type Request

type Request struct {
	Addr    string // Remote host:port
	Mode    string // Mode tcp/udp
	Name    string // Query name
	Type    uint16 // Query type
	Class   uint16 // Query class
	Recurse bool   // Recursion desired
}

Request represents a DNS request.

func NewRequest

func NewRequest(addr, name string, type_ uint16, options ...RequestOption) *Request

type RequestFactory

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

RequestFactory creates multiple requests using custom options.

func NewRequestFactory

func NewRequestFactory(opts ...RequestOption) *RequestFactory

NewRequestFactory creates a factory using custom options.

func (*RequestFactory) FromNames

func (f *RequestFactory) FromNames(addr string, type_ uint16, names ...string) []*Request

FromNames creates multiple requests using different names.

func (*RequestFactory) FromTypes

func (f *RequestFactory) FromTypes(addr, name string, types ...uint16) []*Request

FromTypes creates multiple requests using different types.

type RequestOption

type RequestOption func(*Request)

RequestOption represents an option function.

type Resolver

type Resolver struct {
}

Resolver represents an resolver, an application can have multiple resolvers.

func NewResolver

func NewResolver() *Resolver

NewResolver creates a new resolver with default options.

func (*Resolver) FanIn

func (r *Resolver) FanIn(ctx context.Context, reqs ...*Request) <-chan *Response

FanIn issues multiple requests and serializes the responses through the returned channel.

func (*Resolver) Resolve

func (r *Resolver) Resolve(req *Request) <-chan *Response

Resolve issue the DNS request returning immediately, it returns the response through a channel which is closed automatically when the request is finished.

type Response

type Response struct {
	Addr  string
	Name  string
	Type  uint16
	Class uint16
	Msg   *dns.Msg
	Rtt   time.Duration
	Err   error
}

func NewResponse

func NewResponse(req *Request) *Response

func (*Response) Host

func (r *Response) Host() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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