dnsforwarder

package module
v0.0.0-...-213afb2 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2015 License: MPL-2.0 Imports: 9 Imported by: 1

README

dnsforwarder GoDoc Coverage Status Codeship Status for d2g/dnsforwarder

DNS Forwarder With Cache

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Configuration

type Configuration struct {
	ReadTimeout  int
	WriteTimeout int
	NameServers  []net.TCPAddr
	TTL          uint32
}

func (Configuration) MarshalJSON

func (t Configuration) MarshalJSON() ([]byte, error)

func (*Configuration) UnmarshalJSON

func (t *Configuration) UnmarshalJSON(data []byte) (err error)

type Hijacker

type Hijacker func(dns.ResponseWriter, *dns.Msg) (bool, error)

The Implementation of the Hijacker interface must write the message to the writer. It returns weather the message was hijacked (true) or not (false). With any errors.

type Server

type Server struct {
	Configuration *Configuration
	Cache         cache.Cache
	Hosts         hosts.Hosts
	Hijacker
}
Example

Example DNS Forwarding Server

configuration := Configuration{}
configuration.ReadTimeout = 10
configuration.WriteTimeout = 10
configuration.TTL = 600

configuration.NameServers = []net.TCPAddr{net.TCPAddr{IP: net.IPv4(208, 67, 222, 222), Port: 53}, net.TCPAddr{IP: net.IPv4(208, 67, 220, 220), Port: 53}}

cache := memorycache.Memory{}
cache.Cache = make(map[string]memorycache.MemoryCacheRecord)

hosts := memoryhosts.Memory{}
hosts.Devices = make(map[string]net.IP)
hosts.Add("raspberrypi", net.IPv4(192, 168, 1, 201))

server := Server{}
server.Configuration = &configuration
server.Cache = &cache
server.Hosts = &hosts

go func() {
	err := server.ListenAndServeUDP(net.UDPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 53})
	if err != nil {
		log.Fatalf("UDP Error:%s\n", err.Error())
	}
}()

err := server.ListenAndServeTCP(net.TCPAddr{IP: net.IPv4(0, 0, 0, 0), Port: 53})
if err != nil {
	log.Fatalf("TCP Error:%s\n", err.Error())
}
Output:

func (*Server) ListenAndServeTCP

func (this *Server) ListenAndServeTCP(address net.TCPAddr) error

Listen for incoming TCP Connections

func (*Server) ListenAndServeUDP

func (this *Server) ListenAndServeUDP(address net.UDPAddr) error

Listen for incoming UDP Connections

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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