[ldns-users] Programmatically creating a zone

W.C.A. Wijngaards wouter at NLnetLabs.nl
Mon Sep 6 14:35:12 UTC 2010

Hash: SHA1

Hi Ray, Bryan,

On 09/02/2010 09:43 PM, Ray Bellis wrote:
>   ldns_rr *rr;
>   ldns_rdf *origin = ldns_dname_new_frm_str(origin_str);
>   ldns_rr_new_frm_str(&rr, rr_str, ttl, origin, NULL);
> (where "origin_str" is $ORIGIN and "rr_str" is the RR in the form "@ RTYPE RDATA")

Yes that is easier than the method below.

> Alternatively, it's possible (but tedious) to create it one field at a time:
>   ldns_rr *rr = ldns_rr_new();
>   ldns_rdf *owner = ldns_dname_new_frm_str(owner_str);
>   ldns_rr_set_owner(rr, owner);
>   ldns_rr_set_ttl(rr, ttl);
>   ldns_rr_set_type(rr, rtype);
>   ...
> [not sure how to set the RDATA yet, the _frm_str method is probably easier in many cases, but this method is probably faster if you have the RDATA already in wire format instead of ASCII].

You add the rdata one field at a time, by creating ldns_rdf's for every
RDATA field, and pushing it ldns_rr_push_rdf() onto the rdf.  To create
the rdata for an A record you would do:
ldns_str2rdf_a() or
ldns_rdf_new_frm_str(LDNS_RDF_TYPE_A, "") or
ldns_rdf_new_frm_data(LDNS_RDF_TYPE_A, 4, pointer to 4-octet ipv4 in
wire format)
For other types you need the correct rdf fields, ldns_rr_descript() can
tell you what rdf fields are needed.  Anyway ldns_rr_new_frm_str handles
that for you.

Best regards,
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/


More information about the ldns-users mailing list