Commit 76883e8c authored by Michael Graff's avatar Michael Graff
Browse files

implement dns_rdataset_towire()

parent edd4f79b
......@@ -261,6 +261,12 @@ dns_rdataset_towire(dns_rdataset_t *rdataset,
dns_compress_t *cctx,
isc_buffer_t *target)
{
dns_rdata_t rdata;
isc_region_t r;
dns_rdataclass_t rclass;
dns_rdatatype_t rtype;
dns_ttl_t rttl;
dns_result_t result;
/*
* Convert 'rdataset' to wire format, compressing names as specified
......@@ -268,11 +274,56 @@ dns_rdataset_towire(dns_rdataset_t *rdataset,
*/
REQUIRE(DNS_RDATASET_VALID(rdataset));
result = dns_rdataset_first(rdataset);
REQUIRE(result == DNS_R_SUCCESS);
/* XXX stop warnings. */
owner_name = NULL;
cctx = NULL;
target = NULL;
do {
/*
* copy out the name, type, class, ttl.
*/
result = dns_name_towire(owner_name, cctx, target);
if (result != DNS_R_SUCCESS)
return (result);
isc_buffer_available(target, &r);
if (r.length < (sizeof(dns_rdataclass_t)
+ sizeof(dns_rdatatype_t)
+ sizeof(dns_ttl_t)
+ 2)) /* XXX 2? it's for the rdata length */
return (DNS_R_NOSPACE);
rtype = rdataset->type;
r.base[0] = (rtype & 0xff00) >> 8;
r.base[1] = (rtype & 0xff);
rclass = rdataset->class;
r.base[2] = (rclass & 0xff00) >> 8;
r.base[3] = (rclass & 0x00ff);
rttl = rdataset->ttl;
r.base[4] = (rttl & 0xff000000) >> 24;
r.base[5] = (rttl & 0x00ff0000) >> 16;
r.base[6] = (rttl & 0x0000ff00) >> 8;
r.base[7] = (rttl & 0x000000ff);
isc_buffer_add(target, (sizeof(dns_rdataclass_t)
+ sizeof(dns_rdatatype_t)
+ sizeof(dns_ttl_t)
+ 2)); /* XXX see XXX above */
/*
* copy out the rdata length
*/
dns_rdataset_current(rdataset, &rdata);
r.base[8] = (rdata.length & 0xff00) >> 8;
r.base[9] = (rdata.length & 0x00ff);
return (DNS_R_NOTIMPLEMENTED);
/*
* copy out the rdata
*/
result = dns_rdata_towire(&rdata, cctx, target);
if (result != DNS_R_SUCCESS)
return (result);
result = dns_rdataset_next(rdataset);
} while (result == DNS_R_SUCCESS);
if (result != DNS_R_NOMORE)
return (result);
return (DNS_R_SUCCESS);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment