diff --git a/lib/dns/rdataset.c b/lib/dns/rdataset.c index 3e2e433129..48a2ea3efa 100644 --- a/lib/dns/rdataset.c +++ b/lib/dns/rdataset.c @@ -263,9 +263,6 @@ dns_rdataset_towire(dns_rdataset_t *rdataset, { dns_rdata_t rdata; isc_region_t r; - dns_rdataclass_t rclass; - dns_rdatatype_t rtype; - dns_ttl_t rttl; dns_result_t result; /* @@ -290,27 +287,15 @@ dns_rdataset_towire(dns_rdataset_t *rdataset, + 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 */ + isc_buffer_putuint16(target, rdataset->type); + isc_buffer_putuint16(target, rdataset->class); + isc_buffer_putuint32(target, rdataset->ttl); + /* * copy out the rdata length */ dns_rdataset_current(rdataset, &rdata); - r.base[8] = (rdata.length & 0xff00) >> 8; - r.base[9] = (rdata.length & 0x00ff); + isc_buffer_putuint16(target, rdata.length); /* * copy out the rdata diff --git a/lib/isc/buffer.c b/lib/isc/buffer.c index 62f16304d4..f8ed735cdc 100644 --- a/lib/isc/buffer.c +++ b/lib/isc/buffer.c @@ -294,6 +294,21 @@ isc_buffer_getuint16(isc_buffer_t *b) { return (result); } +void +isc_buffer_putuint16(isc_buffer_t *b, isc_uint16_t val) +{ + unsigned char *cp; + + REQUIRE(VALID_BUFFER(b)); + REQUIRE(b->used + 2 <= b->length); + + cp = b->base; + cp += b->used; + b->used += 2; + cp[0] = (val & 0xff00) >> 8; + cp[1] = (val & 0x00ff); +} + isc_uint32_t isc_buffer_getuint32(isc_buffer_t *b) { unsigned char *cp; @@ -317,3 +332,20 @@ isc_buffer_getuint32(isc_buffer_t *b) { return (result); } + +void +isc_buffer_putuint32(isc_buffer_t *b, isc_uint32_t val) +{ + unsigned char *cp; + + REQUIRE(VALID_BUFFER(b)); + REQUIRE(b->used + 4 <= b->length); + + cp = b->base; + cp += b->used; + b->used += 4; + cp[0] = (val & 0xff000000) >> 24; + cp[1] = (val & 0x00ff0000) >> 16; + cp[2] = (val & 0x0000ff00) >> 8; + cp[3] = (val & 0x000000ff); +} diff --git a/lib/isc/include/isc/buffer.h b/lib/isc/include/isc/buffer.h index d2e126fd5f..7f6d43974f 100644 --- a/lib/isc/include/isc/buffer.h +++ b/lib/isc/include/isc/buffer.h @@ -366,6 +366,21 @@ isc_buffer_getuint16(isc_buffer_t *b); * A 16-bit unsigned integer. */ +void +isc_buffer_putuint16(isc_buffer_t *b, isc_uint16_t val); +/* + * Store an unsigned 16-bit integer in host byte order from 'val' + * into 'b' in network byte order. + * + * Requires: + * 'b' is a valid buffer. + * + * The length of the unused region of 'b' is at least 2. + * + * Ensures: + * The used pointer in 'b' is advanced by 2. + */ + isc_uint32_t isc_buffer_getuint32(isc_buffer_t *b); /* @@ -387,4 +402,19 @@ isc_buffer_getuint32(isc_buffer_t *b); * A 32-bit unsigned integer. */ +void +isc_buffer_putuint32(isc_buffer_t *b, isc_uint32_t val); +/* + * Store an unsigned 32-bit integer in host byte order from 'val' + * into 'b' in network byte order. + * + * Requires: + * 'b' is a valid buffer. + * + * The length of the unused region of 'b' is at least 4. + * + * Ensures: + * The used pointer in 'b' is advanced by 4. + */ + #endif /* ISC_BUFFER_H */