diff --git a/lib/dns/include/dns/rdataset.h b/lib/dns/include/dns/rdataset.h index 581c52937d..a7b2ed45f2 100644 --- a/lib/dns/include/dns/rdataset.h +++ b/lib/dns/include/dns/rdataset.h @@ -207,7 +207,8 @@ dns_result_t dns_rdataset_towire(dns_rdataset_t *rdataset, dns_name_t *owner_name, dns_compress_t *cctx, - isc_buffer_t *target); + isc_buffer_t *target, + unsigned int *countp); /* * Convert 'rdataset' to wire format, compressing names as specified * in cctx, and storing the result in 'target'. @@ -215,16 +216,23 @@ dns_rdataset_towire(dns_rdataset_t *rdataset, * Notes: * The rdata cursor position will be changed. * + * The number of RRs added to target will be added to *countp. + * * Requires: * 'rdataset' is a valid rdataset. * * 'rdataset' is not empty. * + * 'countp' is a valid pointer. + * * Ensures: * On a return of DNS_R_SUCCESS, 'target' contains a wire format * for the data contained in 'rdataset'. Any error return leaves * the buffer in an undefined state. * + * *countp has been incremented by the number of RRs added to + * target. + * * Returns: * DNS_R_SUCCESS - all ok * DNS_R_NOSPACE - 'target' doesn't have enough room diff --git a/lib/dns/rdataset.c b/lib/dns/rdataset.c index a1791d8a1a..ecf056b4ba 100644 --- a/lib/dns/rdataset.c +++ b/lib/dns/rdataset.c @@ -265,11 +265,13 @@ dns_result_t dns_rdataset_towire(dns_rdataset_t *rdataset, dns_name_t *owner_name, dns_compress_t *cctx, - isc_buffer_t *target) + isc_buffer_t *target, + unsigned int *countp) { dns_rdata_t rdata; isc_region_t r; dns_result_t result; + unsigned int count; /* * Convert 'rdataset' to wire format, compressing names as specified @@ -279,7 +281,9 @@ dns_rdataset_towire(dns_rdataset_t *rdataset, REQUIRE(DNS_RDATASET_VALID(rdataset)); result = dns_rdataset_first(rdataset); REQUIRE(result == DNS_R_SUCCESS); + REQUIRE(countp != NULL); + count = 0; do { /* * copy out the name, type, class, ttl. @@ -310,11 +314,15 @@ dns_rdataset_towire(dns_rdataset_t *rdataset, if (result != DNS_R_SUCCESS) return (result); + count++; + result = dns_rdataset_next(rdataset); } while (result == DNS_R_SUCCESS); if (result != DNS_R_NOMORE) return (result); + *countp += count; + return (DNS_R_SUCCESS); }