Maintained by: NLnet Labs

[Unbound-users] C based code sample for DNSMessage construction

Seetharaman Ramasubramani
Wed Feb 27 02:02:44 CET 2013


Hi,

  I am build C based code modules to be plugged into Unbound. I am looking
for code samples in C to construct DNS Message responses to queries.
Basically, code to do something very similar to the python code in
examples/resgen.py,as below:

            #create instance of DNS message (packet) with given parameters
            msg = DNSMessage(qstate.qinfo.qname_str, RR_TYPE_A,
RR_CLASS_IN, PKT_QR | PKT_RA | PKT_AA)
            #append RR
            if (qstate.qinfo.qtype == RR_TYPE_A) or (qstate.qinfo.qtype ==
RR_TYPE_ANY):
                msg.answer.append("%s 10 IN A 127.0.0.1" %
qstate.qinfo.qname_str)
            #set qstate.return_msg
            if not msg.set_return_msg(qstate):
                qstate.ext_state[id] = MODULE_ERROR
                return True

            #we don't need validation, result is valid
            qstate.return_msg.rep.security = 2

            qstate.return_rcode = RCODE_NOERROR
            qstate.ext_state[id] = MODULE_FINISHED

Thanks much
Mani
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://unbound.nlnetlabs.nl/pipermail/unbound-users/attachments/20130226/202a2221/attachment.html>