Fix NSID (or OPT option code 3)
This commit is contained in:
parent
0f7bbd73e6
commit
6e403621e1
5
dns.go
5
dns.go
|
@ -230,6 +230,11 @@ func zoneMatch(pattern, zone string) (ok bool) {
|
||||||
|
|
||||||
// DnameLength returns the length of a packed dname.
|
// DnameLength returns the length of a packed dname.
|
||||||
func DomainNameLength(s string) int { // TODO better name
|
func DomainNameLength(s string) int { // TODO better name
|
||||||
|
// Special case for '.'
|
||||||
|
if s == "." {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
// Add trailing dot to canonicalize name.
|
// Add trailing dot to canonicalize name.
|
||||||
if n := len(s); n == 0 || s[n-1] != '.' {
|
if n := len(s); n == 0 || s[n-1] != '.' {
|
||||||
return n + 1
|
return n + 1
|
||||||
|
|
7
msg.go
7
msg.go
|
@ -320,18 +320,13 @@ func packStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok bool)
|
||||||
// Length of the entire option section
|
// Length of the entire option section
|
||||||
for j := 0; j < val.Field(i).Len(); j++ {
|
for j := 0; j < val.Field(i).Len(); j++ {
|
||||||
element := val.Field(i).Index(j)
|
element := val.Field(i).Index(j)
|
||||||
code := uint16(element.Field(0).Uint())
|
|
||||||
// for each code we should do something else
|
// for each code we should do something else
|
||||||
h, e := hex.DecodeString(string(element.Field(1).String()))
|
h, e := hex.DecodeString(string(element.Field(1).String()))
|
||||||
if e != nil {
|
if e != nil {
|
||||||
//fmt.Fprintf(os.Stderr, "dns: failure packing OTP")
|
//fmt.Fprintf(os.Stderr, "dns: failure packing OTP")
|
||||||
return lenmsg, false
|
return lenmsg, false
|
||||||
}
|
}
|
||||||
// Option Code
|
code := uint16(element.Field(0).Uint())
|
||||||
// the rdlength needs to be set somehow
|
|
||||||
println("code ", code)
|
|
||||||
println("length ", len(string(h)))
|
|
||||||
println("off ", off)
|
|
||||||
msg[off], msg[off+1] = packUint16(code)
|
msg[off], msg[off+1] = packUint16(code)
|
||||||
// Length
|
// Length
|
||||||
msg[off+2], msg[off+3] = packUint16(uint16(len(string(h))))
|
msg[off+2], msg[off+3] = packUint16(uint16(len(string(h))))
|
||||||
|
|
|
@ -4,17 +4,14 @@
|
||||||
|
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
/* Function defined in this subpackage work on []byte and but still
|
// Function defined in this subpackage work on []byte and but still
|
||||||
* provide some higher level functions
|
// provide some higher level functions.
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// SetRdlength sets the length of the length of the rdata
|
// SetRdlength sets the length of the length of the rdata
|
||||||
// directly at the correct position in the buffer buf.
|
// directly at the correct position in the buffer buf.
|
||||||
// If buf does not look like a DNS message false is returned,
|
// If buf does not look like a DNS message false is returned,
|
||||||
// otherwise true.
|
// otherwise true.
|
||||||
func (h *RR_Header) RawSetRdlength(buf []byte, off int) bool {
|
func (h *RR_Header) RawSetRdlength(buf []byte, off int) bool {
|
||||||
// TODO double check DomainNameLength
|
|
||||||
off1 := DomainNameLength(h.Name)
|
off1 := DomainNameLength(h.Name)
|
||||||
if off1 == 0 || len(buf) < off+off1+2+2+4+1 {
|
if off1 == 0 || len(buf) < off+off1+2+2+4+1 {
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in New Issue