"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "example_test.go" between
dns-1.1.48.tar.gz and dns-1.1.49.tar.gz

About: GO DNS implements a DNS library in Go.

example_test.go  (dns-1.1.48):example_test.go  (dns-1.1.49)
skipping to change at line 19 skipping to change at line 19
"github.com/miekg/dns" "github.com/miekg/dns"
) )
// Retrieve the MX records for miek.nl. // Retrieve the MX records for miek.nl.
func ExampleMX() { func ExampleMX() {
config, _ := dns.ClientConfigFromFile("/etc/resolv.conf") config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
c := new(dns.Client) c := new(dns.Client)
m := new(dns.Msg) m := new(dns.Msg)
m.SetQuestion("miek.nl.", dns.TypeMX) m.SetQuestion("miek.nl.", dns.TypeMX)
m.RecursionDesired = true m.RecursionDesired = true
r, _, err := c.Exchange(m, config.Servers[0]+":"+config.Port) r, _, err := c.Exchange(m, net.JoinHostPort(config.Servers[0], config.Por t))
if err != nil { if err != nil {
return return
} }
if r.Rcode != dns.RcodeSuccess { if r.Rcode != dns.RcodeSuccess {
return return
} }
for _, a := range r.Answer { for _, a := range r.Answer {
if mx, ok := a.(*dns.MX); ok { if mx, ok := a.(*dns.MX); ok {
fmt.Printf("%s\n", mx.String()) fmt.Printf("%s\n", mx.String())
} }
skipping to change at line 42 skipping to change at line 42
// Retrieve the DNSKEY records of a zone and convert them // Retrieve the DNSKEY records of a zone and convert them
// to DS records for SHA1, SHA256 and SHA384. // to DS records for SHA1, SHA256 and SHA384.
func ExampleDS() { func ExampleDS() {
config, _ := dns.ClientConfigFromFile("/etc/resolv.conf") config, _ := dns.ClientConfigFromFile("/etc/resolv.conf")
c := new(dns.Client) c := new(dns.Client)
m := new(dns.Msg) m := new(dns.Msg)
zone := "miek.nl" zone := "miek.nl"
m.SetQuestion(dns.Fqdn(zone), dns.TypeDNSKEY) m.SetQuestion(dns.Fqdn(zone), dns.TypeDNSKEY)
m.SetEdns0(4096, true) m.SetEdns0(4096, true)
r, _, err := c.Exchange(m, config.Servers[0]+":"+config.Port) r, _, err := c.Exchange(m, net.JoinHostPort(config.Servers[0], config.Por t))
if err != nil { if err != nil {
return return
} }
if r.Rcode != dns.RcodeSuccess { if r.Rcode != dns.RcodeSuccess {
return return
} }
for _, k := range r.Answer { for _, k := range r.Answer {
if key, ok := k.(*dns.DNSKEY); ok { if key, ok := k.(*dns.DNSKEY); ok {
for _, alg := range []uint8{dns.SHA1, dns.SHA256, dns.SHA 384} { for _, alg := range []uint8{dns.SHA1, dns.SHA256, dns.SHA 384} {
fmt.Printf("%s; %d\n", key.ToDS(alg).String(), ke y.Flags) fmt.Printf("%s; %d\n", key.ToDS(alg).String(), ke y.Flags)
skipping to change at line 67 skipping to change at line 67
const TypeAPAIR = 0x0F99 const TypeAPAIR = 0x0F99
type APAIR struct { type APAIR struct {
addr [2]net.IP addr [2]net.IP
} }
func NewAPAIR() dns.PrivateRdata { return new(APAIR) } func NewAPAIR() dns.PrivateRdata { return new(APAIR) }
func (rd *APAIR) String() string { return rd.addr[0].String() + " " + rd.addr[1] .String() } func (rd *APAIR) String() string { return rd.addr[0].String() + " " + rd.addr[1] .String() }
func (rd *APAIR) Parse(txt []string) error { func (rd *APAIR) Parse(txt []string) error {
if len(txt) != 2 { if len(txt) != 2 {
return errors.New("two addresses required for APAIR") return errors.New("two addresses required for APAIR")
} }
for i, s := range txt { for i, s := range txt {
ip := net.ParseIP(s) ip := net.ParseIP(s)
if ip == nil { if ip == nil {
return errors.New("invalid IP in APAIR text representatio n") return errors.New("invalid IP in APAIR text representatio n")
} }
rd.addr[i] = ip rd.addr[i] = ip
skipping to change at line 124 skipping to change at line 125
return nil return nil
} }
func (rd *APAIR) Len() int { func (rd *APAIR) Len() int {
return net.IPv4len * 2 return net.IPv4len * 2
} }
func ExamplePrivateHandle() { func ExamplePrivateHandle() {
dns.PrivateHandle("APAIR", TypeAPAIR, NewAPAIR) dns.PrivateHandle("APAIR", TypeAPAIR, NewAPAIR)
defer dns.PrivateHandleRemove(TypeAPAIR) defer dns.PrivateHandleRemove(TypeAPAIR)
var oldId = dns.Id
dns.Id = func() uint16 { return 3 }
defer func() { dns.Id = oldId }()
rr, err := dns.NewRR("miek.nl. APAIR (1.2.3.4 1.2.3.5)") rr, err := dns.NewRR("miek.nl. APAIR (1.2.3.4 1.2.3.5)")
if err != nil { if err != nil {
log.Fatal("could not parse APAIR record: ", err) log.Fatal("could not parse APAIR record: ", err)
} }
fmt.Println(rr) fmt.Println(rr) // see first line of Output below
// Output: miek.nl. 3600 IN APAIR 1.2.3.4 1.2.3.5
m := new(dns.Msg) m := new(dns.Msg)
m.Id = 12345
m.SetQuestion("miek.nl.", TypeAPAIR) m.SetQuestion("miek.nl.", TypeAPAIR)
m.Answer = append(m.Answer, rr) m.Answer = append(m.Answer, rr)
fmt.Println(m) fmt.Println(m)
// ;; opcode: QUERY, status: NOERROR, id: 12345 // Output: miek.nl. 3600 IN APAIR 1.2.3.4 1.2.3.5
// ;; opcode: QUERY, status: NOERROR, id: 3
// ;; flags: rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 // ;; flags: rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
// //
// ;; QUESTION SECTION: // ;; QUESTION SECTION:
// ;miek.nl. IN APAIR // ;miek.nl. IN APAIR
// //
// ;; ANSWER SECTION: // ;; ANSWER SECTION:
// miek.nl. 3600 IN APAIR 1.2.3.4 1.2.3.5 // miek.nl. 3600 IN APAIR 1.2.3.4 1.2.3.5
} }
 End of changes. 7 change blocks. 
6 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)