rename the examples dir

Make it *not* show up in godoc
This commit is contained in:
Miek Gieben 2010-12-30 14:13:28 +01:00
parent 15dd65171b
commit bcf320aad4
10 changed files with 65 additions and 75 deletions

View File

@ -1,7 +1,7 @@
# Copyright 2009 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
.PHONY: dnssec resolver examples
.PHONY: examples
include $(GOROOT)/src/Make.inc
@ -26,3 +26,6 @@ dnstest:
gotest
gomake -C dnssec test
gomake -C resolver test
examples:
gomake -C _examples

14
dns.go
View File

@ -5,19 +5,14 @@
// Package dns implements a full featured interface to the DNS.
// Supported RFCs and features include:
// * 1982 - Serial Arithmetic
// * 1034/1035
// * 2671 - EDNS
// * 4033/4034/4035 - DNSSEC + validation functions
// * 1982 - Serial Arithmetic
// * 5011 - NSID
// * IP6 support
// The package allows full control over what is send out to the DNS.
//
// Basic usage pattern for creating new Resource Record:
//
// r := new(RR_TXT)
// r.TXT = "This is the content of the TXT record"
// r.Hdr = RR_Header{Name: "a.miek.nl", Rrtype: TypeTXT, Class: ClassINET, Ttl: 3600}
//
package dns
import ( "strconv")
@ -72,7 +67,7 @@ func (h *RR_Header) String() string {
// Or expose the pack/unpack functions??
// Return the rdata of the RR in wireform.
// Return the wiredata of rdata portion of a RR.
func WireRdata(r RR) ([]byte, bool) {
buf := make([]byte, 4096) // Too large, need to FIX TODO(mg)
off1, ok := packRR(r, buf, 0)
@ -85,7 +80,7 @@ func WireRdata(r RR) ([]byte, bool) {
return buf, true
}
// Return the wiredata of a domainname (sans compressions)
// Return the wiredata of a domainname (sans compressions).
func WireDomainName(s string) ([]byte, bool) {
buf := make([]byte, 255)
off, ok := packDomainName(s, buf, 0)
@ -96,6 +91,7 @@ func WireDomainName(s string) ([]byte, bool) {
return buf, ok
}
// Return the wiredata of a complete Resource Record.
func WireRR(r RR) ([]byte, bool) {
buf := make([]byte, 4096)
off, ok := packRR(r, buf, 0)

View File

@ -1,3 +1,5 @@
// Package dnssec implements all client side DNSSEC function, like
// validation, keytag/DS calculation.
package dnssec
import (

View File

@ -4,12 +4,11 @@ import (
"strconv"
)
// EDNS0 option codes
// EDNS0 Options and Do bit
const (
OptionCodeLLQ = 1 // Not used
OptionCodeUL = 2 // Not used
OptionCodeNSID = 3 // NSID, RFC5001
// EDNS flag bits (put in Z section)
_DO = 1 << 7 // dnssec ok
)
@ -58,12 +57,12 @@ func (rr *RR_OPT) String() string {
return s
}
// Set the version of edns, currently only 0 is there
// Set the version of edns
func (rr *RR_OPT) Version(v uint8, set bool) uint8 {
return 0
}
// when set is true, set the size otherwise get it
// Set/Get the UDP buffer size
func (rr *RR_OPT) UDPSize(size uint16, set bool) uint16 {
if set {
rr.Hdr.Class = size
@ -71,7 +70,7 @@ func (rr *RR_OPT) UDPSize(size uint16, set bool) uint16 {
return rr.Hdr.Class
}
// when set is true, set the Do bit, otherwise get it
// Set/Getthe DoBit
func (rr *RR_OPT) DoBit(do, set bool) bool {
// rr.TTL last 2 bytes, left most bit
// See line 239 in msg.go for TTL encoding

101
msg.go
View File

@ -267,12 +267,12 @@ func packStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int, o
return len(msg), false
}
case "hex":
// There is no length encoded here, for DS at least
h, e := hex.DecodeString(s)
if e != nil {
return len(msg), false
}
copy(msg[off:off+hex.DecodedLen(len(s))], h)
// There is no length encoded here, for DS at least
h, e := hex.DecodeString(s)
if e != nil {
return len(msg), false
}
copy(msg[off:off+hex.DecodedLen(len(s))], h)
case "":
// Counted string: 1 byte length.
if len(s) > 255 || off+1+len(s) > len(msg) {
@ -331,18 +331,18 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
fv.Set(reflect.NewValue(b).(*reflect.SliceValue))
off += net.IPv6len
case "OPT": // edns
// check rdlength, if more, then more options
// TODO(mg) checking
// for now: allow only 1. TODO(mg)
/*
opt := make([]Option, 1)
opt[0].Code, off = unpackUint16(msg, off)
length := uint16(msg[off])<<8 | uint16(msg[off+1])
off += 2
opt[0].Data = string(msg[off:off+int(length)])
off += int(length)
//opt
*/
// check rdlength, if more, then more options
// TODO(mg) checking
// for now: allow only 1. TODO(mg)
/*
opt := make([]Option, 1)
opt[0].Code, off = unpackUint16(msg, off)
length := uint16(msg[off])<<8 | uint16(msg[off+1])
off += 2
opt[0].Data = string(msg[off:off+int(length)])
off += int(length)
//opt
*/
}
case *reflect.StructValue:
off, ok = unpackStructValue(fv, msg, off)
@ -358,7 +358,7 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
fv.Set(uint64(i))
off++
case reflect.Uint16:
var i uint16
var i uint16
if off+2 > len(msg) {
return len(msg), false
}
@ -438,9 +438,9 @@ func unpackStructValue(val *reflect.StructValue, msg []byte, off int) (off1 int,
// Helper function for unpacking
func unpackUint16(msg []byte, off int) (v uint16, off1 int) {
v = uint16(msg[off])<<8 | uint16(msg[off+1])
off1 = off+2
return
v = uint16(msg[off])<<8 | uint16(msg[off+1])
off1 = off + 2
return
}
func unpackStruct(any interface{}, msg []byte, off int) (off1 int, ok bool) {
@ -462,9 +462,9 @@ func packRR(rr RR, msg []byte, off int) (off2 int, ok bool) {
return len(msg), false
}
// DEBUG TODO(mg)
// println("Header", off1)
// println("Rest", off2)
// DEBUG TODO(mg)
// println("Header", off1)
// println("Rest", off2)
// TODO make this quicker?
// pack a third time; redo header with correct data length
@ -505,21 +505,20 @@ func unpackRR(msg []byte, off int) (rr RR, off1 int, ok bool) {
// A manually-unpacked version of (id, bits).
// This is in its own struct for easy printing.
type MsgHdr struct {
Id uint16
Response bool
Opcode int
Authoritative bool
Truncated bool
Recursion_desired bool
Recursion_available bool
Z bool // or just zero??
Authenticated_data bool
Checking_disabled bool
Rcode int
Id uint16
Response bool
Opcode int
Authoritative bool
Truncated bool
RecursionDesired bool
RecursionAvailable bool
Zero bool
AuthenticatedData bool
CheckingDisabled bool
Rcode int
}
// Convert a MsgHdr to a string, mimic the way dig displays
// headers:
// Convert a MsgHdr to a string, mimic the way Dig displays headers:
//;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48404
//;; flags: qr aa rd ra;
func (h *MsgHdr) String() string {
@ -541,19 +540,19 @@ func (h *MsgHdr) String() string {
if h.Truncated {
s += "tc "
}
if h.Recursion_desired {
if h.RecursionDesired {
s += "rd "
}
if h.Recursion_available {
if h.RecursionAvailable {
s += "ra "
}
if h.Z {
if h.Zero { // Hmm
s += "z "
}
if h.Authenticated_data {
if h.AuthenticatedData {
s += "ad "
}
if h.Checking_disabled {
if h.CheckingDisabled {
s += "cd "
}
@ -586,19 +585,19 @@ func (dns *Msg) Pack() (msg []byte, ok bool) {
if dns.Truncated {
dh.Bits |= _TC
}
if dns.Recursion_desired {
if dns.RecursionDesired {
dh.Bits |= _RD
}
if dns.Recursion_available {
if dns.RecursionAvailable {
dh.Bits |= _RA
}
if dns.Z {
if dns.Zero {
dh.Bits |= _Z
}
if dns.Authenticated_data {
if dns.AuthenticatedData {
dh.Bits |= _AD
}
if dns.Checking_disabled {
if dns.CheckingDisabled {
dh.Bits |= _CD
}
@ -652,8 +651,8 @@ func (dns *Msg) Unpack(msg []byte) bool {
dns.Opcode = int(dh.Bits>>11) & 0xF
dns.Authoritative = (dh.Bits & _AA) != 0
dns.Truncated = (dh.Bits & _TC) != 0
dns.Recursion_desired = (dh.Bits & _RD) != 0
dns.Recursion_available = (dh.Bits & _RA) != 0
dns.RecursionDesired = (dh.Bits & _RD) != 0
dns.RecursionAvailable = (dh.Bits & _RA) != 0
dns.Rcode = int(dh.Bits & 0xF)
// Arrays.
@ -683,7 +682,7 @@ func (dns *Msg) Unpack(msg []byte) bool {
return true
}
// Convert a complete message to a string. Again use dig-like output
// Convert a complete message to a string, use dig-like output.
func (dns *Msg) String() string {
if dns == nil {
return "<nil> MsgHdr"

View File

@ -3,15 +3,6 @@
// license that can be found in the LICENSE file.
// Extended and bugfixes by Miek Gieben
// Package dns implements a full featured interface to the DNS.
// Supported RFCs and features include:
// * 1034/1035
// * 2671 - EDNS
// * 4033/4034/4035 - DNSSEC + validation functions
// * 1982 - Serial Arithmetic
// * IP6 support
// The package allows full control over what is send out to the DNS.
//
// Basic usage pattern for creating new Resource Record:
//
// r := new(RR_TXT)