[ldns-users] Programmatically creating a zone

Ray Bellis Ray.Bellis at nominet.org.uk
Thu Sep 2 19:43:23 UTC 2010


>> Is the real issue figuring how to create an "ldns_rr"?
> 
> Yes, I think that is the main difficulty.
> 
> ldns_rr_new_frm_str_internal() is what I've been looking at as the
> template for creating my own ldns_rr.  It looks like it has all the
> init, and assignment code that I would need. 
> 
> It seems like this function is the most like what I want.

Well, that depends on what the source of your RRs is.

I've used ldns_rr_new_frm_str() before (not the _internal variant):

  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")

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].

Ray





More information about the ldns-users mailing list