Respond with NS record
This commit is contained in:
13
lib/dns.nim
13
lib/dns.nim
@@ -61,7 +61,7 @@ type
|
||||
header*: DnsHeader
|
||||
questions*: seq[DnsQuestion]
|
||||
answer*: seq[DnsRecord]
|
||||
authroity*: seq[DnsRecord]
|
||||
authority*: seq[DnsRecord]
|
||||
additional*: seq[DnsRecord]
|
||||
|
||||
func parseNameField*(data: string, startOffset: uint16): (seq[string], uint16) =
|
||||
@@ -164,7 +164,7 @@ func packResourceRecord*(data: DnsRecord): string =
|
||||
record.add(uint16ToString(data.class.uint16))
|
||||
record.add(uint32ToString(data.ttl.uint32))
|
||||
record.add(uint16ToString(data.rdlength.uint16))
|
||||
record.add(data.rdata)
|
||||
record.add((if data.rtype == DnsType.NS: packNameField(data.rdata) else: data.rdata))
|
||||
|
||||
return record
|
||||
|
||||
@@ -186,6 +186,9 @@ func packMessage*(message: DnsMessage): string =
|
||||
for answer in message.answer:
|
||||
encoded.add(packResourceRecord(answer))
|
||||
|
||||
for authroity in message.authority:
|
||||
encoded.add(packResourceRecord(authroity))
|
||||
|
||||
return encoded
|
||||
|
||||
func mkRecord*(rtype: DnsType, question: string, answer: string): DnsRecord =
|
||||
@@ -198,14 +201,16 @@ func mkRecord*(rtype: DnsType, question: string, answer: string): DnsRecord =
|
||||
rdata: (if rtype == DnsType.TXT: chr(len(answer)) & answer else: answer)
|
||||
)
|
||||
|
||||
func mkResponse*(id: uint16, question: DnsQuestion, answer: seq[string]): DnsMessage =
|
||||
func mkResponse*(id: uint16, question: DnsQuestion, answer: seq[string], authority: string, base: string): DnsMessage =
|
||||
return DnsMessage(
|
||||
header: DnsHeader(
|
||||
id: id,
|
||||
qr: DnsQr.RESPONSE,
|
||||
aa: true,
|
||||
rcode: Rcode.NO_ERROR,
|
||||
ancount: len(answer).uint16
|
||||
ancount: len(answer).uint16,
|
||||
nscount: 1
|
||||
),
|
||||
authority: @[mkRecord(DnsType.NS, base, authority)],
|
||||
answer: answer.map(proc (a: string): DnsRecord = mkRecord(question.qtype, question.qname, a))
|
||||
)
|
||||
Reference in New Issue
Block a user