1 /******************************************************************************
2 Utility to convert a LTP flow to a TCP flow for LTP analysis via tcptrace.
3 LTP Header manipulation functions
5 Copyright (C) 2013 Samuel Jero <sj323707@ohio.edu>
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 Author: Samuel Jero <sj323707@ohio.edu>
24 1)Only handles one LTP "connection". There isn't a good way to separate
25 different LTP "connections" from new sessions of the same "connection".
26 Use Tcpdump filters to separate connections. Libpcap filtering could also
28 2)Uses some special types from Linux (u_char, u_int32_t)
29 ******************************************************************************/
34 * SDNV has a zero in high-order bit position of last byte. The high-order
35 * bit of all preceding bytes is set to one. This returns the numeric value
36 * in an integer and sets the value of the second argument to the number of
37 * bytes used to code the SDNV. A -1 is returned if the evaluation fails
38 * (value exceeds maximum for signed integer). 0 is an acceptable value.
41 #define SDNV_MASK 0x7f
43 /*2rd arg is number of bytes in field (returned)*/
44 int evaluate_sdnv(const u_char* loc, int *bytecount)
52 * Get 1st byte and continue to get them while high-order bit is 1
55 while((curbyte = *(loc++)) & ~SDNV_MASK) {
56 if(*bytecount >= (int) sizeof(int)) {
61 value |= (curbyte & SDNV_MASK);
66 * Add in the byte whose high-order bit is 0 (last one)
70 value |= (curbyte & SDNV_MASK);
75 /* Special Function to evaluate 64 bit SDNVs */
76 long long evaluate_sdnv_64(const u_char* loc, int *bytecount)
84 * Get 1st byte and continue to get them while high-order bit is 1
87 while((curbyte = *(loc++)) & ~SDNV_MASK) {
88 if(*bytecount >= (int) sizeof(long long)) {
93 value |= (curbyte & SDNV_MASK);
98 * Add in the byte whose high-order bit is 0 (last one)
102 value |= (curbyte & SDNV_MASK);