1 /******************************************************************************
6 Description: LTP Header manipulation functions
8 ******************************************************************************/
13 * SDNV has a zero in high-order bit position of last byte. The high-order
14 * bit of all preceding bytes is set to one. This returns the numeric value
15 * in an integer and sets the value of the second argument to the number of
16 * bytes used to code the SDNV. A -1 is returned if the evaluation fails
17 * (value exceeds maximum for signed integer). 0 is an acceptable value.
20 #define SDNV_MASK 0x7f
22 /*2rd arg is number of bytes in field (returned)*/
23 int evaluate_sdnv(const u_char* loc, int *bytecount)
31 * Get 1st byte and continue to get them while high-order bit is 1
34 while((curbyte = *(loc++)) & ~SDNV_MASK) {
35 if(*bytecount >= (int) sizeof(int)) {
40 value |= (curbyte & SDNV_MASK);
45 * Add in the byte whose high-order bit is 0 (last one)
49 value |= (curbyte & SDNV_MASK);
54 /* Special Function to evaluate 64 bit SDNVs */
55 long long evaluate_sdnv_64(const u_char* loc, int *bytecount)
63 * Get 1st byte and continue to get them while high-order bit is 1
66 while((curbyte = *(loc++)) & ~SDNV_MASK) {
67 if(*bytecount >= (int) sizeof(long long)) {
72 value |= (curbyte & SDNV_MASK);
77 * Add in the byte whose high-order bit is 0 (last one)
81 value |= (curbyte & SDNV_MASK);