mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
implement and use isc_buffer_putuint{16,32}()
This commit is contained in:
@@ -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
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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 */
|
||||
|
Reference in New Issue
Block a user