tcpflow  1.6.1
About: tcpflow is a TCP/IP packet demultiplexer that captures data transmitted as part of TCP connections (flows), and stores the data in a way that is convenient for protocol analysis and debugging.
  Fossies Dox: tcpflow-1.6.1.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

sbuf_stream.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 #include "config.h"
3 #include "bulk_extractor_i.h"
4 #include "sbuf_stream.h"
5 
6 /*
7  * Stream interfaces
8  */
9 sbuf_stream::sbuf_stream(const sbuf_t &sbuf_): sbuf(sbuf_),offset(0) {
10 }
11 
13 }
14 
15 void sbuf_stream::seek(size_t offset_) {
16  offset = offset_;
17 }
18 
20  return offset;
21 }
22 
23 /*
24  * unsigned integers, default little endian
25  */
27  uint8_t value = sbuf.get8u(offset);
28  offset++;
29  return value;
30 }
32  uint16_t value = sbuf.get16u(offset);
33  offset+=2;
34  return value;
35 }
37  uint32_t value = sbuf.get32u(offset);
38  offset+=4;
39  return value;
40 }
41 uint64_t sbuf_stream::get64u() {
42  uint64_t value = sbuf.get64u(offset);
43  offset+=8;
44  return value;
45 }
46 
47 /*
48  * unsigned integers, big endian
49  */
51  uint8_t value = sbuf.get8uBE(offset);
52  offset++;
53  return value;
54 }
56  uint16_t value = sbuf.get16uBE(offset);
57  offset+=2;
58  return value;
59 }
61  uint32_t value = sbuf.get32uBE(offset);
62  offset+=4;
63  return value;
64 }
66  uint64_t value = sbuf.get64uBE(offset);
67  offset+=8;
68  return value;
69 }
70 
71 /*
72  * unsigned integers, byte order specified
73  */
75  uint8_t value = sbuf.get8u(offset, bo);
76  offset++;
77  return value;
78 }
80  uint16_t value = sbuf.get16u(offset, bo);
81  offset+=2;
82  return value;
83 }
85  uint32_t value = sbuf.get32u(offset, bo);
86  offset+=4;
87  return value;
88 }
90  uint64_t value = sbuf.get64u(offset, bo);
91  offset+=8;
92  return value;
93 }
94 
95 /*
96  * signed integers, default little endian
97  */
99  int8_t value = sbuf.get8i(offset);
100  offset++;
101  return value;
102 }
104  int16_t value = sbuf.get16i(offset);
105  offset+=2;
106  return value;
107 }
109  int32_t value = sbuf.get32i(offset);
110  offset+=4;
111  return value;
112 }
114  int64_t value = sbuf.get64i(offset);
115  offset+=8;
116  return value;
117 }
118 
119 /*
120  * signed integers, big endian
121  */
123  int8_t value = sbuf.get8iBE(offset);
124  offset++;
125  return value;
126 }
128  int16_t value = sbuf.get16iBE(offset);
129  offset+=2;
130  return value;
131 }
133  int32_t value = sbuf.get32iBE(offset);
134  offset+=4;
135  return value;
136 }
138  int64_t value = sbuf.get64iBE(offset);
139  offset+=8;
140  return value;
141 }
142 
143 /*
144  * signed integers, byte order specified
145  */
147  uint8_t value = sbuf.get8i(offset, bo);
148  offset++;
149  return value;
150 }
152  uint16_t value = sbuf.get16i(offset, bo);
153  offset+=2;
154  return value;
155 }
157  uint32_t value = sbuf.get32i(offset, bo);
158  offset+=4;
159  return value;
160 }
162  uint64_t value = sbuf.get64i(offset, bo);
163  offset+=8;
164  return value;
165 }
166 
167 /*
168  * string readers
169  */
170 void sbuf_stream::getUTF8(size_t num_octets_requested, string &utf8_string) {
171  sbuf.getUTF8(num_octets_requested, utf8_string);
172  offset += utf8_string.length();
173  return;
174 }
175 void sbuf_stream::getUTF8(string &utf8_string) {
176  sbuf.getUTF8(offset, utf8_string);
177  size_t num_bytes = utf8_string.length();
178  if (num_bytes > 0) {
179  // if anything was read then also skip \0
180  num_bytes ++;
181  }
182  offset += num_bytes;
183  return;
184 }
185 
186 void sbuf_stream::getUTF16(size_t code_units_requested, wstring &utf16_string) {
187  sbuf.getUTF16(offset, code_units_requested, utf16_string);
188  offset += utf16_string.length() * 2;
189  return;
190 }
191 void sbuf_stream::getUTF16(wstring &utf16_string) {
192  sbuf.getUTF16(offset, utf16_string);
193  size_t num_bytes = utf16_string.length() * 2;
194  if (num_bytes > 0) {
195  // if anything was read then also skip \U0000
196  num_bytes += 2;
197  }
198  offset += num_bytes;
199  return;
200 }
201 
202 
Definition: sbuf.h:221
int8_t get8i(size_t i) const
Definition: sbuf_private.h:108
int64_t get64iBE()
int8_t get8i()
Definition: sbuf_stream.cpp:98
int8_t get8iBE()
int32_t get32iBE()
uint64_t get64u()
Definition: sbuf_stream.cpp:41
int32_t get32i(size_t i) const
Definition: sbuf_private.h:110
byte_order_t
Definition: sbuf.h:482
uint16_t get16u()
Definition: sbuf_stream.cpp:31
uint8_t get8u(size_t i) const
Definition: sbuf_private.h:20
uint16_t get16uBE()
Definition: sbuf_stream.cpp:55
uint8_t get8u()
Definition: sbuf_stream.cpp:26
size_t offset
Definition: sbuf_stream.h:30
uint32_t get32u(size_t i) const
Definition: sbuf_private.h:32
void getUTF8(string &utf8_string)
int16_t get16iBE()
void getUTF8(size_t i, size_t num_octets_requested, std::string &utf8_string) const
Definition: sbuf.cpp:257
uint8_t get8uBE()
Definition: sbuf_stream.cpp:50
uint32_t get32uBE(size_t i) const
Definition: sbuf_private.h:66
void getUTF16(wstring &utf16_string)
uint64_t get64uBE()
Definition: sbuf_stream.cpp:65
void getUTF16(size_t i, size_t num_code_units_requested, std::wstring &utf16_string) const
Definition: sbuf.cpp:297
uint64_t get64u(size_t i) const
Definition: sbuf_private.h:41
uint8_t get8uBE(size_t i) const
Definition: sbuf_private.h:54
size_t tell()
Definition: sbuf_stream.cpp:19
uint32_t get32uBE()
Definition: sbuf_stream.cpp:60
int8_t get8iBE(size_t i) const
Definition: sbuf_private.h:112
uint64_t get64uBE(size_t i) const
Definition: sbuf_private.h:75
int16_t get16iBE(size_t i) const
Definition: sbuf_private.h:113
int64_t get64i()
const sbuf_t sbuf
Definition: sbuf_stream.h:29
sbuf_stream(const sbuf_t &sbuf_)
Definition: sbuf_stream.cpp:9
uint16_t get16u(size_t i) const
Definition: sbuf_private.h:25
int32_t get32i()
int64_t get64iBE(size_t i) const
Definition: sbuf_private.h:115
int32_t get32iBE(size_t i) const
Definition: sbuf_private.h:114
int64_t get64i(size_t i) const
Definition: sbuf_private.h:111
void seek(size_t offset)
Definition: sbuf_stream.cpp:15
uint32_t get32u()
Definition: sbuf_stream.cpp:36
int16_t get16i(size_t i) const
Definition: sbuf_private.h:109
uint16_t get16uBE(size_t i) const
Definition: sbuf_private.h:59
int16_t get16i()
unsigned int uint32_t
Definition: core.h:40
unsigned short uint16_t
Definition: util.h:7
unsigned char uint8_t
Definition: util.h:6