begin touching up a DNS Client implementation; internal.GetIP/SetIP refactor

This commit is contained in:
soypat
2025-06-21 01:29:38 -03:00
parent 48f1fa9103
commit 1fcde05284
9 changed files with 209 additions and 29 deletions
+11 -2
View File
@@ -66,7 +66,10 @@ func (m *Message) Decode(msg []byte) (_ uint16, incompleteButOK bool, err error)
return 0, false, errResTooLong
}
m.Reset()
hdr := NewFrame(msg)
hdr, err := NewFrame(msg)
if err != nil {
return 0, false, err
}
nq := int(hdr.QDCount())
off := uint16(SizeHeader)
// Return tooManyErr if found to flag to the caller that the message was
@@ -175,7 +178,10 @@ func (m *Message) AppendTo(buf []byte, txid uint16, flags HeaderFlags) (_ []byte
nauth := uint16(len(m.Authorities))
nadd := uint16(len(m.Additionals))
var hdr [SizeHeader]byte
f := NewFrame(hdr[:])
f, err := NewFrame(hdr[:])
if err != nil {
return buf, err
}
f.SetTxID(txid)
f.SetFlags(flags)
f.SetQDCount(nq)
@@ -406,6 +412,9 @@ func NewName(domain string) (Name, error) {
// Len returns the length over-the-wire of the encoded Name.
func (n *Name) Len() uint16 {
if len(n.data) > math.MaxUint16 {
panic("size of DNS name data overflows 16bits")
}
return uint16(len(n.data))
}