mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 15:05:23 +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;
|
dns_rdata_t rdata;
|
||||||
isc_region_t r;
|
isc_region_t r;
|
||||||
dns_rdataclass_t rclass;
|
|
||||||
dns_rdatatype_t rtype;
|
|
||||||
dns_ttl_t rttl;
|
|
||||||
dns_result_t result;
|
dns_result_t result;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -290,27 +287,15 @@ dns_rdataset_towire(dns_rdataset_t *rdataset,
|
|||||||
+ sizeof(dns_ttl_t)
|
+ sizeof(dns_ttl_t)
|
||||||
+ 2)) /* XXX 2? it's for the rdata length */
|
+ 2)) /* XXX 2? it's for the rdata length */
|
||||||
return (DNS_R_NOSPACE);
|
return (DNS_R_NOSPACE);
|
||||||
rtype = rdataset->type;
|
isc_buffer_putuint16(target, rdataset->type);
|
||||||
r.base[0] = (rtype & 0xff00) >> 8;
|
isc_buffer_putuint16(target, rdataset->class);
|
||||||
r.base[1] = (rtype & 0xff);
|
isc_buffer_putuint32(target, rdataset->ttl);
|
||||||
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
|
* copy out the rdata length
|
||||||
*/
|
*/
|
||||||
dns_rdataset_current(rdataset, &rdata);
|
dns_rdataset_current(rdataset, &rdata);
|
||||||
r.base[8] = (rdata.length & 0xff00) >> 8;
|
isc_buffer_putuint16(target, rdata.length);
|
||||||
r.base[9] = (rdata.length & 0x00ff);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* copy out the rdata
|
* copy out the rdata
|
||||||
|
@@ -294,6 +294,21 @@ isc_buffer_getuint16(isc_buffer_t *b) {
|
|||||||
return (result);
|
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_uint32_t
|
||||||
isc_buffer_getuint32(isc_buffer_t *b) {
|
isc_buffer_getuint32(isc_buffer_t *b) {
|
||||||
unsigned char *cp;
|
unsigned char *cp;
|
||||||
@@ -317,3 +332,20 @@ isc_buffer_getuint32(isc_buffer_t *b) {
|
|||||||
|
|
||||||
return (result);
|
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.
|
* 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_uint32_t
|
||||||
isc_buffer_getuint32(isc_buffer_t *b);
|
isc_buffer_getuint32(isc_buffer_t *b);
|
||||||
/*
|
/*
|
||||||
@@ -387,4 +402,19 @@ isc_buffer_getuint32(isc_buffer_t *b);
|
|||||||
* A 32-bit unsigned integer.
|
* 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 */
|
#endif /* ISC_BUFFER_H */
|
||||||
|
Reference in New Issue
Block a user