add isc_buffer_getuint{16,32}

This commit is contained in:
Bob Halley
1999-01-07 02:06:48 +00:00
parent 4b1c5cc4ee
commit 63bd57250e
2 changed files with 89 additions and 1 deletions

View File

@@ -226,3 +226,49 @@ isc_buffer_compact(isc_buffer_t *b) {
b->current = 0;
b->used = length;
}
isc_uint16_t
isc_buffer_getuint16(isc_buffer_t *b) {
unsigned char *cp;
isc_uint16_t result;
/*
* Read an unsigned 16-bit integer in network byte order from 'b',
* convert it to host byte order, and return it.
*/
REQUIRE(VALID_BUFFER(b));
REQUIRE(b->used - b->current >= 2);
cp = b->base;
cp += b->current;
b->current += 2;
result = ((unsigned int)(cp[0])) << 8;
result |= ((unsigned int)(cp[1]));
return (result);
}
isc_uint32_t
isc_buffer_getuint32(isc_buffer_t *b) {
unsigned char *cp;
isc_uint32_t result;
/*
* Read an unsigned 32-bit integer in network byte order from 'b',
* convert it to host byte order, and return it.
*/
REQUIRE(VALID_BUFFER(b));
REQUIRE(b->used - b->current >= 4);
cp = b->base;
cp += b->current;
b->current += 4;
result = ((unsigned int)(cp[0])) << 24;
result |= ((unsigned int)(cp[1])) << 16;
result |= ((unsigned int)(cp[2])) << 8;
result |= ((unsigned int)(cp[3]));
return (result);
}

View File

@@ -75,7 +75,7 @@
***/
#include <isc/region.h>
#include <isc/int.h>
/***
*** Types
@@ -313,4 +313,46 @@ isc_buffer_compact(isc_buffer_t *b);
* are those of the remaining region (as it was before the call).
*/
isc_uint16_t
isc_buffer_getuint16(isc_buffer_t *b);
/*
* Read an unsigned 16-bit integer in network byte order from 'b', convert
* it to host byte order, and return it.
*
* Requires:
*
* 'b' is a valid buffer.
*
* The length of the available region of 'b' is at least 2.
*
* Ensures:
*
* The current pointer in 'b' is advanced by 2.
*
* Returns:
*
* A 16-bit unsigned integer.
*/
isc_uint32_t
isc_buffer_getuint32(isc_buffer_t *b);
/*
* Read an unsigned 32-bit integer in network byte order from 'b', convert
* it to host byte order, and return it.
*
* Requires:
*
* 'b' is a valid buffer.
*
* The length of the available region of 'b' is at least 2.
*
* Ensures:
*
* The current pointer in 'b' is advanced by 2.
*
* Returns:
*
* A 32-bit unsigned integer.
*/
#endif /* ISC_BUFFER_H */