more consistent naming

This commit is contained in:
Miek Gieben 2012-05-31 19:33:12 +02:00
parent 5bc0c4df68
commit 29365cc9d8
3 changed files with 23 additions and 23 deletions

35
edns.go
View File

@ -9,10 +9,10 @@ import (
// EDNS0 Option codes.
const (
_ = iota
OptionLLQ // not used
OptionUL // not used
OptionNSID // NSID, RFC5001
OptionSUBNET = 0x50fa // client-subnet draft
EDNS0LLQ // not used
EDNS0UL // not used
EDNS0NSID // NSID, RFC5001
EDNS0SUBNET = 0x50fa // client-subnet draft
_DO = 1 << 7 // dnssec ok
)
@ -50,7 +50,7 @@ func (rr *RR_OPT) String() string {
switch o.(type) {
case *EDNS0_NSID:
s += "\n; NSID: " + o.String()
h, e := o.Bytes()
h, e := o.Pack()
var r string
if e == nil {
for _, c := range h {
@ -66,7 +66,7 @@ func (rr *RR_OPT) String() string {
func (rr *RR_OPT) Len() int {
l := rr.Hdr.Len()
for i := 0; i < len(rr.Option); i++ {
lo, _ := rr.Option[i].Bytes()
lo, _ := rr.Option[i].Pack()
l += 2 + len(lo)
}
return l
@ -120,25 +120,25 @@ func (rr *RR_OPT) SetDo() {
type EDNS0 interface {
// Option return the option code for the option.
Option() uint16
// Bytes returns the bytes of the option data.
Bytes() ([]byte, error)
// Pack returns the bytes of the option data.
Pack() ([]byte, error)
// Unpack sets the data as found in the packet. Is also sets
// the length of the slice as the length of the option data.
Unpack([]byte)
// String returns the string representation of the option.
String() string
// SetBytes sets the data as found in the packet. Is also sets
// the length of the slice as the length of the option data.
SetBytes([]byte)
}
type EDNS0_NSID struct {
Code uint16
Nsid string // This string must be encoded as Hex
Nsid string // This string needs to be hex encoded
}
func (e *EDNS0_NSID) Option() uint16 {
return e.Code
}
func (e *EDNS0_NSID) Bytes() ([]byte, error) {
func (e *EDNS0_NSID) Pack() ([]byte, error) {
h, err := hex.DecodeString(e.Nsid)
if err != nil {
return nil, err
@ -146,13 +146,12 @@ func (e *EDNS0_NSID) Bytes() ([]byte, error) {
return h, nil
}
func (e *EDNS0_NSID) String() string {
return string(e.Nsid)
func (e *EDNS0_NSID) Unpack(b []byte) {
e.Nsid = hex.EncodeToString(b)
}
func (e *EDNS0_NSID) SetBytes(b []byte) {
e.Code = OptionNSID
e.Nsid = hex.EncodeToString(b)
func (e *EDNS0_NSID) String() string {
return string(e.Nsid)
}
type EDNS0_SUBNET struct {

View File

@ -173,7 +173,8 @@ Flags:
if *nsid {
// Ask for it
e := new(dns.EDNS0_NSID)
e.SetBytes([]byte(""))
e.Nsid = ""
e.Code = dns.EDNS0NSID
o.Option = append(o.Option, e)
}
m.Extra = append(m.Extra, o)

8
msg.go
View File

@ -402,7 +402,7 @@ func packStructValue(val reflect.Value, msg []byte, off int, compression map[str
case "opt": // edns
for j := 0; j < val.Field(i).Len(); j++ {
element := val.Field(i).Index(j).Interface()
b, e := element.(EDNS0).Bytes()
b, e := element.(EDNS0).Pack()
if e != nil {
println("dns: failure packing OTP")
return lenmsg, false
@ -701,12 +701,12 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
return lenmsg, false
}
switch code {
case OptionNSID:
case EDNS0NSID:
e := new(EDNS0_NSID)
e.SetBytes(msg[off1 : off1+int(optlen)])
e.Unpack(msg[off1 : off1+int(optlen)])
edns = append(edns, e)
off = off1 + int(optlen)
case OptionSUBNET:
case EDNS0SUBNET:
// ..
}
fv.Set(reflect.ValueOf(edns))