nim-ndns icon indicating copy to clipboard operation
nim-ndns copied to clipboard

How do I get CNAME record?

Open pptx704 opened this issue 1 year ago • 1 comments

As I understand, I can only fetch A, AAAA and RDNS records. Is there a way to get CNAME records? i.e. through dnsQuery function?

pptx704 avatar Dec 30 '23 00:12 pptx704

Types of queries that do not have their own procedure can be made using procedures dnsAsyncQuery and dnsQuery or dnsAsyncTcpQuery and dnsTcpQuery. To see the types of queries currently supported, see the dnsprotocol package.

Here is a basic example using what is in the readme:

import ndns

let
  header = initHeader(randId(), rd = true)
  question = initQuestion("irc.vircio.org", QType.CNAME, QClass.IN)
  msg = initMessage(header, @[question])
  client = initDnsClient()
  rmsg = dnsQuery(client, msg)

if rmsg.header.flags.rcode == RCode.NoError:
  for rr in rmsg.answers:
    if rr.name != msg.questions[0].qname or rr.`type` != Type.CNAME or
      rr.class != Class.IN: continue

    echo "Canonical name: ", cast[RDataCNAME](rr.rdata).cname

This should return: Canonical name: irc.vircio.net.

rockcavera avatar Dec 30 '23 05:12 rockcavera