Make the edns api more Go like

Split the set/get function to a SetX() and X()
This commit is contained in:
Miek Gieben 2011-01-06 10:24:00 +01:00
parent b57613e8d8
commit 08b6220c67
1 changed files with 37 additions and 26 deletions

63
edns.go
View File

@ -40,13 +40,13 @@ func (rr *RR_OPT) Header() *RR_Header {
} }
func (rr *RR_OPT) String() string { func (rr *RR_OPT) String() string {
s := ";; EDNS: version " + strconv.Itoa(int(rr.Version(0, false))) + "; " s := ";; EDNS: version " + strconv.Itoa(int(rr.Version())) + "; "
if rr.DoBit(false, false) { if rr.Do() {
s += "flags: do; " s += "flags: do; "
} else { } else {
s += "flags: ; " s += "flags: ; "
} }
s += "udp: " + strconv.Itoa(int(rr.UDPSize(0, false))) + ";" s += "udp: " + strconv.Itoa(int(rr.UDPSize())) + ";"
for _, o := range rr.Option { for _, o := range rr.Option {
switch o.Code { switch o.Code {
@ -57,17 +57,24 @@ func (rr *RR_OPT) String() string {
return s return s
} }
// Get the version
func (rr *RR_OPT) Version() uint8 {
return 0
}
// Set the version of edns // Set the version of edns
func (rr *RR_OPT) Version(v uint8, set bool) uint8 { func (rr *RR_OPT) SetVersion(v uint8) {
return 0 return
}
// Get the UDP buffer size
func (rr *RR_OPT) UDPSize() uint16 {
return rr.Hdr.Class
} }
// Set/Get the UDP buffer size // Set/Get the UDP buffer size
func (rr *RR_OPT) UDPSize(size uint16, set bool) uint16 { func (rr *RR_OPT) SetUDPSize(size uint16) {
if set { rr.Hdr.Class = size
rr.Hdr.Class = size
}
return rr.Hdr.Class
} }
@ -80,24 +87,28 @@ func (rr *RR_OPT) UDPSize(size uint16, set bool) uint16 {
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
*/ */
// Set/Get the DoBit // Get the do bit
func (rr *RR_OPT) DoBit(do, set bool) bool { func (rr *RR_OPT) Do() bool {
if set { return byte(rr.Hdr.Ttl >> 8) &_DO == _DO
b1 := byte(rr.Hdr.Ttl >> 24)
b2 := byte(rr.Hdr.Ttl >> 16)
b3 := byte(rr.Hdr.Ttl >> 8)
b4 := byte(rr.Hdr.Ttl)
b3 |= _DO // Set it
rr.Hdr.Ttl = uint32(b1)<<24 | uint32(b2)<<16 | uint32(b3)<<8 | uint32(b4)
return true
} else {
return byte(rr.Hdr.Ttl >> 8) &_DO == _DO
}
return true // dead code, bug in Go
} }
// when set is true, set the nsid, otherwise get it // Set the do bit
func (rr *RR_OPT) Nsid(nsid string, set bool) string { func (rr *RR_OPT) SetDo() {
b1 := byte(rr.Hdr.Ttl >> 24)
b2 := byte(rr.Hdr.Ttl >> 16)
b3 := byte(rr.Hdr.Ttl >> 8)
b4 := byte(rr.Hdr.Ttl)
b3 |= _DO // Set it
rr.Hdr.Ttl = uint32(b1)<<24 | uint32(b2)<<16 | uint32(b3)<<8 | uint32(b4)
}
// Return the NSID as hex string
func (rr *RR_OPT) Nsid(nsid string) string {
// RR.Option[0] to be set // RR.Option[0] to be set
return "" return ""
} }
// Set the NSID
func (rr *RR_OPT) SetNsid(nsid string) {
}