1 | /* |
---|
2 | * This file is part of libtrace |
---|
3 | * |
---|
4 | * Copyright (c) 2007,2008 The University of Waikato, Hamilton, New Zealand. |
---|
5 | * Authors: Daniel Lawson |
---|
6 | * Perry Lorier |
---|
7 | * |
---|
8 | * All rights reserved. |
---|
9 | * |
---|
10 | * This code has been developed by the University of Waikato WAND |
---|
11 | * research group. For further information please see http://www.wand.net.nz/ |
---|
12 | * |
---|
13 | * libtrace is free software; you can redistribute it and/or modify |
---|
14 | * it under the terms of the GNU General Public License as published by |
---|
15 | * the Free Software Foundation; either version 2 of the License, or |
---|
16 | * (at your option) any later version. |
---|
17 | * |
---|
18 | * libtrace is distributed in the hope that it will be useful, |
---|
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | * GNU General Public License for more details. |
---|
22 | * |
---|
23 | * You should have received a copy of the GNU General Public License |
---|
24 | * along with libtrace; if not, write to the Free Software |
---|
25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
26 | * |
---|
27 | * $Id: libtrace.h 773 2006-05-01 12:58:09Z perry $ |
---|
28 | * |
---|
29 | */ |
---|
30 | |
---|
31 | #ifndef LIBTRACE_H |
---|
32 | #define LIBTRACE_H |
---|
33 | |
---|
34 | /** @file |
---|
35 | * |
---|
36 | * @brief Trace file processing library header |
---|
37 | * |
---|
38 | * @author Daniel Lawson |
---|
39 | * @author Perry Lorier |
---|
40 | * |
---|
41 | * @version $Id: libtrace.h 773 2006-05-01 12:58:09Z perry $ |
---|
42 | * |
---|
43 | * This library provides a per packet interface into a trace file, or a live |
---|
44 | * captures. It supports ERF, DAG cards, WAG cards, WAG's event format, |
---|
45 | * pcap etc. |
---|
46 | * |
---|
47 | * @par Usage |
---|
48 | * See the example/ directory in the source distribution for some simple examples |
---|
49 | * @par Linking |
---|
50 | * To use this library you need to link against libtrace by passing -ltrace |
---|
51 | * to your linker. You may also need to link against a version of libpcap |
---|
52 | * and of zlib which are compiled for largefile support (if you wish to access |
---|
53 | * traces larger than 2 GB). This is left as an exercise for the reader. Debian |
---|
54 | * Woody, at least, does not support large file offsets. |
---|
55 | * |
---|
56 | */ |
---|
57 | |
---|
58 | #include <sys/types.h> |
---|
59 | #ifndef WIN32 |
---|
60 | #include <sys/time.h> |
---|
61 | #endif |
---|
62 | |
---|
63 | #ifdef _MSC_VER |
---|
64 | /* define the following from MSVC's internal types */ |
---|
65 | typedef __int8 int8_t; |
---|
66 | typedef __int16 int16_t; |
---|
67 | typedef __int32 int32_t; |
---|
68 | typedef __int64 int64_t; |
---|
69 | typedef unsigned __int8 uint8_t; |
---|
70 | typedef unsigned __int16 uint16_t; |
---|
71 | typedef unsigned __int32 uint32_t; |
---|
72 | typedef unsigned __int64 uint64_t; |
---|
73 | #ifdef BUILDING_DLL |
---|
74 | #define DLLEXPORT __declspec(dllexport) |
---|
75 | #else |
---|
76 | #define DLLEXPORT __declspec(dllimport) |
---|
77 | #endif |
---|
78 | #define DLLLOCAL |
---|
79 | /* Windows pads bitfields out to to the size of their parent type |
---|
80 | * however gcc warns that this doesn't meet with the iso C specification |
---|
81 | * so produces warnings for this behaviour. sigh. |
---|
82 | */ |
---|
83 | #define LT_BITFIELD8 uint8_t |
---|
84 | #define LT_BITFIELD16 uint16_t |
---|
85 | #define LT_BITFIELD32 uint32_t |
---|
86 | #define LT_BITFIELD64 uint64_t |
---|
87 | #else |
---|
88 | #ifdef HAVE_STDINT_H |
---|
89 | # include <stdint.h> |
---|
90 | #endif |
---|
91 | #ifdef HAVE_GCCVISIBILITYPATCH |
---|
92 | #define DLLEXPORT __attribute__ (visibility("default")) |
---|
93 | #define DLLLOCAL __attribute__ (visibility("hidden")) |
---|
94 | #else |
---|
95 | #define DLLEXPORT |
---|
96 | #define DLLLOCAL |
---|
97 | #endif |
---|
98 | /* GCC warns if the bitfield type is not "unsigned int", however windows |
---|
99 | * generates incorrect code for this (see above), so we define these |
---|
100 | * macros. How Hidious. So much for C's portability. |
---|
101 | */ |
---|
102 | #define LT_BITFIELD8 unsigned int |
---|
103 | #define LT_BITFIELD16 unsigned int |
---|
104 | #define LT_BITFIELD32 unsigned int |
---|
105 | #define LT_BITFIELD64 unsigned int |
---|
106 | #endif |
---|
107 | |
---|
108 | #ifdef WIN32 |
---|
109 | # include <winsock2.h> |
---|
110 | # include <ws2tcpip.h> |
---|
111 | typedef short sa_family_t; |
---|
112 | /* Make up for a lack of stdbool.h */ |
---|
113 | # define bool signed char |
---|
114 | # define false 0 |
---|
115 | # define true 1 |
---|
116 | # if !defined(ssize_t) |
---|
117 | /* XXX: Not 64-bit safe! */ |
---|
118 | # define ssize_t int |
---|
119 | # endif |
---|
120 | #else |
---|
121 | # include <netinet/in.h> |
---|
122 | |
---|
123 | #ifndef __cplusplus |
---|
124 | # include <stdbool.h> |
---|
125 | #endif |
---|
126 | |
---|
127 | # include <sys/types.h> |
---|
128 | # include <sys/socket.h> |
---|
129 | #endif |
---|
130 | |
---|
131 | /** API version as 2 byte hex digits, eg 0xXXYYZZ */ |
---|
132 | #define LIBTRACE_API_VERSION \ |
---|
133 | ((@LIBTRACE_MAJOR@<<16)|(@LIBTRACE_MID@<<8)|(@LIBTRACE_MINOR@)) |
---|
134 | |
---|
135 | #define LIBTRACE_SVN_REVISION 0 |
---|
136 | #define DAG_DRIVER_V "@DAG_VERSION_NUM@" |
---|
137 | |
---|
138 | #ifdef __cplusplus |
---|
139 | extern "C" { |
---|
140 | #endif |
---|
141 | |
---|
142 | /* Function does not depend on anything but its |
---|
143 | * parameters, used to hint gcc's optimisations |
---|
144 | */ |
---|
145 | #if __GNUC__ >= 3 |
---|
146 | # define DEPRECATED __attribute__((deprecated)) |
---|
147 | # define SIMPLE_FUNCTION __attribute__((pure)) |
---|
148 | # define UNUSED __attribute__((unused)) |
---|
149 | # define PACKED __attribute__((packed)) |
---|
150 | # define PRINTF(formatpos,argpos) __attribute__((format(printf,formatpos,argpos))) |
---|
151 | #else |
---|
152 | # define DEPRECATED |
---|
153 | # define SIMPLE_FUNCTION |
---|
154 | # define UNUSED |
---|
155 | # define PACKED |
---|
156 | # define PRINTF(formatpos,argpos) |
---|
157 | #endif |
---|
158 | |
---|
159 | /** Opaque structure holding information about an output trace */ |
---|
160 | typedef struct libtrace_out_t libtrace_out_t; |
---|
161 | |
---|
162 | /** Opaque structure holding information about a trace */ |
---|
163 | typedef struct libtrace_t libtrace_t; |
---|
164 | |
---|
165 | /** Opaque structure holding information about a bpf filter */ |
---|
166 | typedef struct libtrace_filter_t libtrace_filter_t; |
---|
167 | |
---|
168 | /** If a packet has memory allocated |
---|
169 | * If the packet has allocated it's own memory it's buffer_control should |
---|
170 | * be TRACE_CTRL_PACKET, when the packet is destroyed it's memory will be |
---|
171 | * free()'d. If it's doing zerocopy out of memory owned by something else |
---|
172 | * it should be TRACE_CTRL_EXTERNAL. |
---|
173 | * @note the letters p and e are magic numbers used to detect if the packet |
---|
174 | * wasn't created properly |
---|
175 | */ |
---|
176 | typedef enum { |
---|
177 | TRACE_CTRL_PACKET='p', |
---|
178 | TRACE_CTRL_EXTERNAL='e' |
---|
179 | } buf_control_t; |
---|
180 | /** The size of a packet's buffer when managed by libtrace */ |
---|
181 | #define LIBTRACE_PACKET_BUFSIZE 65536 |
---|
182 | |
---|
183 | /** libtrace error information */ |
---|
184 | typedef struct trace_err_t{ |
---|
185 | int err_num; /**< error code */ |
---|
186 | char problem[255]; /**< the format, uri etc that caused the error for reporting purposes */ |
---|
187 | } libtrace_err_t; |
---|
188 | |
---|
189 | /** Enumeration of error codes */ |
---|
190 | enum { |
---|
191 | /** No Error has occured.... yet. */ |
---|
192 | TRACE_ERR_NOERROR = 0, |
---|
193 | /** The URI passed to trace_create() is unsupported, or badly formed */ |
---|
194 | TRACE_ERR_BAD_FORMAT = -1, |
---|
195 | /** The trace failed to initialise */ |
---|
196 | TRACE_ERR_INIT_FAILED = -2, |
---|
197 | /** Unknown config option */ |
---|
198 | TRACE_ERR_UNKNOWN_OPTION= -3, |
---|
199 | /** This output uri cannot write packets of this type */ |
---|
200 | TRACE_ERR_NO_CONVERSION = -4, |
---|
201 | /** This packet is corrupt, or unusable for the action required */ |
---|
202 | TRACE_ERR_BAD_PACKET = -5, |
---|
203 | /** Option known, but unsupported by this format */ |
---|
204 | TRACE_ERR_OPTION_UNAVAIL= -6, |
---|
205 | /** This feature is unsupported */ |
---|
206 | TRACE_ERR_UNSUPPORTED = -7, |
---|
207 | /** Illegal use of the API */ |
---|
208 | TRACE_ERR_BAD_STATE = -8 |
---|
209 | }; |
---|
210 | |
---|
211 | /** Enumeration of DLT supported by libtrace |
---|
212 | */ |
---|
213 | typedef enum { |
---|
214 | TRACE_DLT_NULL = 0, |
---|
215 | TRACE_DLT_EN10MB = 1, |
---|
216 | TRACE_DLT_PPP = 9, |
---|
217 | TRACE_DLT_ATM_RFC1483 = 11, |
---|
218 | /* Sigh. This is handled in files with LINKTYPE's */ |
---|
219 | #ifdef __OpenBSD__ |
---|
220 | TRACE_DLT_RAW = 14, |
---|
221 | #else |
---|
222 | TRACE_DLT_RAW = 12, |
---|
223 | #endif |
---|
224 | TRACE_DLT_LINKTYPE_RAW = 101, |
---|
225 | TRACE_DLT_C_HDLC = 104, |
---|
226 | TRACE_DLT_IEEE802_11 = 105, |
---|
227 | TRACE_DLT_LINUX_SLL = 113, |
---|
228 | TRACE_DLT_PFLOG = 117, |
---|
229 | TRACE_DLT_IEEE802_11_RADIO = 127 /**< Radiotap */ |
---|
230 | } libtrace_dlt_t ; |
---|
231 | |
---|
232 | /** Enumeration of link layer types supported by libtrace */ |
---|
233 | typedef enum { |
---|
234 | /* TRACE_TYPE_LEGACY = 0 Obsolete */ |
---|
235 | TRACE_TYPE_HDLC_POS = 1, |
---|
236 | TRACE_TYPE_ETH = 2, /**< 802.3 style Ethernet */ |
---|
237 | TRACE_TYPE_ATM = 3, /**< ATM frame */ |
---|
238 | TRACE_TYPE_80211 = 4, /**< 802.11 frames */ |
---|
239 | TRACE_TYPE_NONE = 5, /**< Raw IP frames */ |
---|
240 | TRACE_TYPE_LINUX_SLL = 6, /**< Linux "null" framing */ |
---|
241 | TRACE_TYPE_PFLOG = 7, /**< FreeBSD's PFlug */ |
---|
242 | /* TRACE_TYPE_LEGACY_DEFAULT Obsolete */ |
---|
243 | TRACE_TYPE_POS = 9, |
---|
244 | /* TRACE_TYPE_LEGACY_ATM Obsolete */ |
---|
245 | /* TRACE_TYPE_LEGACY_ETH Obsolete */ |
---|
246 | TRACE_TYPE_80211_PRISM = 12, |
---|
247 | TRACE_TYPE_AAL5 = 13, |
---|
248 | TRACE_TYPE_DUCK = 14, /**< Pseudo link layer for DUCK packets */ |
---|
249 | TRACE_TYPE_80211_RADIO = 15, /**< Radiotap + 802.11 */ |
---|
250 | TRACE_TYPE_LLCSNAP = 16, /**< Raw LLC/SNAP */ |
---|
251 | TRACE_TYPE_PPP = 17, /**< PPP frames */ |
---|
252 | TRACE_TYPE_METADATA = 18 /**< WDCAP-style meta-data */ |
---|
253 | |
---|
254 | } libtrace_linktype_t; |
---|
255 | |
---|
256 | /** RT protocol base format identifiers |
---|
257 | * This is used to say what kind of packet is being sent over the rt protocol |
---|
258 | */ |
---|
259 | enum base_format_t { |
---|
260 | TRACE_FORMAT_ERF =1, |
---|
261 | TRACE_FORMAT_PCAP =2, |
---|
262 | TRACE_FORMAT_PCAPFILE =3, |
---|
263 | TRACE_FORMAT_WAG =4, |
---|
264 | TRACE_FORMAT_RT =5, |
---|
265 | TRACE_FORMAT_LEGACY_ATM =6, |
---|
266 | TRACE_FORMAT_LEGACY_POS =7, |
---|
267 | TRACE_FORMAT_LEGACY_ETH =8, |
---|
268 | TRACE_FORMAT_LINUX_NATIVE =9, |
---|
269 | TRACE_FORMAT_DUCK =10, |
---|
270 | TRACE_FORMAT_BPF =11, |
---|
271 | TRACE_FORMAT_TSH =12, |
---|
272 | TRACE_FORMAT_ATMHDR =13, |
---|
273 | TRACE_FORMAT_LEGACY_NZIX =14 |
---|
274 | }; |
---|
275 | |
---|
276 | /* RT protocol packet types */ |
---|
277 | typedef enum { |
---|
278 | TRACE_RT_HELLO =1, /**< Connection accepted */ |
---|
279 | TRACE_RT_START =2, /**< Request for data transmission to begin |
---|
280 | */ |
---|
281 | TRACE_RT_ACK =3, /**< Data acknowledgement */ |
---|
282 | TRACE_RT_STATUS =4, /**< Fifo status packet */ |
---|
283 | TRACE_RT_DUCK =5, /**< Dag duck info packet */ |
---|
284 | TRACE_RT_END_DATA =6, /**< Server is exiting message */ |
---|
285 | TRACE_RT_CLOSE =7, /**< Client is exiting message */ |
---|
286 | TRACE_RT_DENY_CONN =8, /**< Connection has been denied */ |
---|
287 | TRACE_RT_PAUSE =9, /**< Request server to suspend sending data |
---|
288 | */ |
---|
289 | TRACE_RT_PAUSE_ACK =10,/**< Server is paused message */ |
---|
290 | TRACE_RT_OPTION =11,/**< Option request */ |
---|
291 | TRACE_RT_KEYCHANGE =12,/**< Anonymisation key has changed */ |
---|
292 | TRACE_RT_DUCK_2_4 =13,/**< Dag 2.4 Duck */ |
---|
293 | TRACE_RT_DUCK_2_5 =14,/**< Dag 2.5 Duck */ |
---|
294 | TRACE_RT_LOSTCONN =15,/**< Lost connection to server */ |
---|
295 | TRACE_RT_SERVERSTART =16,/**< Reliable server has been restarted */ |
---|
296 | TRACE_RT_CLIENTDROP =17,/**< Reliable client was lost */ |
---|
297 | TRACE_RT_METADATA =18,/**< Packet contains server meta-data */ |
---|
298 | |
---|
299 | TRACE_RT_DATA_SIMPLE = 1000, /**< Trace types that know their link |
---|
300 | * type |
---|
301 | */ |
---|
302 | TRACE_RT_DATA_ERF =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_ERF, |
---|
303 | TRACE_RT_DATA_WAG =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_WAG, |
---|
304 | TRACE_RT_DATA_LEGACY_ATM=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LEGACY_ATM, |
---|
305 | TRACE_RT_DATA_LEGACY_POS=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LEGACY_POS, |
---|
306 | TRACE_RT_DATA_LEGACY_ETH=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LEGACY_ETH, |
---|
307 | TRACE_RT_DATA_LINUX_NATIVE=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LINUX_NATIVE, |
---|
308 | TRACE_RT_DATA_BPF =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_BPF, |
---|
309 | TRACE_RT_DATA_TSH =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_TSH, |
---|
310 | |
---|
311 | TRACE_RT_DATA_ATMHDR = TRACE_RT_DATA_SIMPLE + TRACE_FORMAT_ATMHDR, |
---|
312 | TRACE_RT_DATA_LEGACY_NZIX=TRACE_RT_DATA_SIMPLE + TRACE_FORMAT_LEGACY_NZIX, |
---|
313 | TRACE_RT_DATA_DLT = 2000, /**< Pcap doesn't store the |
---|
314 | * linktype per packet, and |
---|
315 | * thus we have to store it |
---|
316 | * in here. sigh. |
---|
317 | */ |
---|
318 | TRACE_RT_DLT_NULL =TRACE_RT_DATA_DLT+TRACE_DLT_NULL, |
---|
319 | TRACE_RT_DLT_EN10MB =TRACE_RT_DATA_DLT+TRACE_DLT_EN10MB, |
---|
320 | TRACE_RT_DLT_IEEE802_11 =TRACE_RT_DATA_DLT+TRACE_DLT_IEEE802_11, |
---|
321 | TRACE_RT_DLT_LINUX_SLL =TRACE_RT_DATA_DLT+TRACE_DLT_LINUX_SLL, |
---|
322 | TRACE_RT_DLT_PFLOG =TRACE_RT_DATA_DLT+TRACE_DLT_PFLOG, |
---|
323 | TRACE_RT_DLT_ATM_RFC1483 =TRACE_RT_DATA_DLT+TRACE_DLT_ATM_RFC1483, |
---|
324 | TRACE_RT_DATA_DLT_END = 2999, |
---|
325 | TRACE_RT_LAST = (2<<31) |
---|
326 | } libtrace_rt_types_t; |
---|
327 | |
---|
328 | /** The libtrace packet structure, applications shouldn't be |
---|
329 | * meddling around in here |
---|
330 | */ |
---|
331 | typedef struct libtrace_packet_t { |
---|
332 | struct libtrace_t *trace; /**< pointer to the trace */ |
---|
333 | void *header; /**< pointer to the framing header */ |
---|
334 | void *payload; /**< pointer to the link layer */ |
---|
335 | void *buffer; /**< allocated buffer */ |
---|
336 | libtrace_rt_types_t type; /**< rt protocol type for the packet */ |
---|
337 | buf_control_t buf_control; /**< who owns the memory */ |
---|
338 | int capture_length; /**< Cached capture length */ |
---|
339 | void *l3_header; /**< Cached l3 header */ |
---|
340 | uint16_t l3_ethertype; /**< Cached l3 ethertype */ |
---|
341 | } libtrace_packet_t; |
---|
342 | |
---|
343 | |
---|
344 | /** Trace directions |
---|
345 | * Note that these are the directions used by convention, more directions |
---|
346 | * are possible, not just these 3, and that they may not conform to this |
---|
347 | * convention. |
---|
348 | */ |
---|
349 | typedef enum { |
---|
350 | TRACE_DIR_OUTGOING = 0, /**< Packets originating "inside" */ |
---|
351 | TRACE_DIR_INCOMING = 1, /**< Packets originating "outside" */ |
---|
352 | TRACE_DIR_OTHER = 2 /**< Packets with an unknown direction, or one that's unknown */ |
---|
353 | } libtrace_direction_t; |
---|
354 | |
---|
355 | /** Enumeration of Radiotap fields */ |
---|
356 | typedef enum { |
---|
357 | TRACE_RADIOTAP_TSFT = 0, /**< Timer synchronisation function, in microseconds (uint64) */ |
---|
358 | TRACE_RADIOTAP_FLAGS = 1, /**< Wireless flags (uint8) */ |
---|
359 | TRACE_RADIOTAP_RATE = 2, /**< Bitrate in units of 500kbps (uint8) */ |
---|
360 | TRACE_RADIOTAP_CHANNEL = 3, /**< Frequency in MHz (uint16) and channel flags (uint16) */ |
---|
361 | TRACE_RADIOTAP_FHSS = 4, /**< FHSS hop set (uint8) and hopping pattern (uint8) */ |
---|
362 | TRACE_RADIOTAP_DBM_ANTSIGNAL = 5, /**< Signal power in dBm (int8) */ |
---|
363 | TRACE_RADIOTAP_DBM_ANTNOISE = 6, /**< Noise power in dBm (int8) */ |
---|
364 | TRACE_RADIOTAP_LOCK_QUALITY = 7, /**< Barker Code lock quality (uint16) */ |
---|
365 | TRACE_RADIOTAP_TX_ATTENUATION = 8, /**< TX attenuation as unitless distance from max power (uint16) */ |
---|
366 | TRACE_RADIOTAP_DB_TX_ATTENUATION = 9, /**< TX attenutation as dB from max power (uint16) */ |
---|
367 | TRACE_RADIOTAP_DBM_TX_POWER = 10, /**< TX Power in dBm (int8) */ |
---|
368 | TRACE_RADIOTAP_ANTENNA = 11, /**< Antenna frame was rx'd or tx'd on (uint8) */ |
---|
369 | TRACE_RADIOTAP_DB_ANTSIGNAL = 12, /**< Signal power in dB from a fixed reference (uint8) */ |
---|
370 | TRACE_RADIOTAP_DB_ANTNOISE = 13, /**< Noise power in dB from a fixed reference (uint8) */ |
---|
371 | TRACE_RADIOTAP_RX_FLAGS = 14, /** Properties of received frame (uint16) */ |
---|
372 | TRACE_RADIOTAP_TX_FLAGS = 15, /** Properties of transmitted frame (uint16) */ |
---|
373 | TRACE_RADIOTAP_RTS_RETRIES = 16, /** Number of rts retries frame used (uint8) */ |
---|
374 | TRACE_RADIOTAP_DATA_RETRIES = 17, /** Number of unicast retries a transmitted frame used (uint8) */ |
---|
375 | TRACE_RADIOTAP_EXT = 31 |
---|
376 | } libtrace_radiotap_field_t; |
---|
377 | |
---|
378 | |
---|
379 | /** @name Protocol structures |
---|
380 | * These convenience structures are here as they are portable ways of dealing |
---|
381 | * with various protocols. |
---|
382 | * @{ |
---|
383 | */ |
---|
384 | |
---|
385 | #ifdef WIN32 |
---|
386 | #pragma pack(push) |
---|
387 | #pragma pack(1) |
---|
388 | #endif |
---|
389 | |
---|
390 | /** Generic IP header structure */ |
---|
391 | typedef struct libtrace_ip |
---|
392 | { |
---|
393 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
394 | LT_BITFIELD8 ip_hl:4; /**< Header Length */ |
---|
395 | LT_BITFIELD8 ip_v:4; /**< Version */ |
---|
396 | #elif BYTE_ORDER == BIG_ENDIAN |
---|
397 | LT_BITFIELD8 ip_v:4; /**< Version */ |
---|
398 | LT_BITFIELD8 ip_hl:4; /**< Header Length */ |
---|
399 | #else |
---|
400 | # error "Adjust your <bits/endian.h> defines" |
---|
401 | #endif |
---|
402 | uint8_t ip_tos; /**< Type of Service */ |
---|
403 | uint16_t ip_len; /**< Total Length */ |
---|
404 | int16_t ip_id; /**< Identification */ |
---|
405 | uint16_t ip_off; /**< IP Fragment offset (and flags) */ |
---|
406 | uint8_t ip_ttl; /**< Time to Live */ |
---|
407 | uint8_t ip_p; /**< Protocol */ |
---|
408 | uint16_t ip_sum; /**< Checksum */ |
---|
409 | struct in_addr ip_src; /**< Source Address */ |
---|
410 | struct in_addr ip_dst; /**< Destination Address */ |
---|
411 | } PACKED libtrace_ip_t; |
---|
412 | |
---|
413 | /** IPv6 header extension structure */ |
---|
414 | typedef struct libtrace_ip6_ext |
---|
415 | { |
---|
416 | uint8_t nxt; |
---|
417 | uint8_t len; |
---|
418 | } PACKED libtrace_ip6_ext_t; |
---|
419 | |
---|
420 | /** Generic IPv6 header structure */ |
---|
421 | typedef struct libtrace_ip6 |
---|
422 | { |
---|
423 | uint32_t flow; |
---|
424 | uint16_t plen; /**< Payload length */ |
---|
425 | uint8_t nxt; /**< Next header */ |
---|
426 | uint8_t hlim; /**< Hop limit */ |
---|
427 | struct in6_addr ip_src; /**< source address */ |
---|
428 | struct in6_addr ip_dst; /**< dest address */ |
---|
429 | } PACKED libtrace_ip6_t; |
---|
430 | |
---|
431 | /** Generic TCP header structure */ |
---|
432 | typedef struct libtrace_tcp |
---|
433 | { |
---|
434 | uint16_t source; /**< Source Port */ |
---|
435 | uint16_t dest; /**< Destination port */ |
---|
436 | uint32_t seq; /**< Sequence number */ |
---|
437 | uint32_t ack_seq; /**< Acknowledgement Number */ |
---|
438 | # if BYTE_ORDER == LITTLE_ENDIAN |
---|
439 | LT_BITFIELD8 res1:4; /**< Reserved bits */ |
---|
440 | LT_BITFIELD8 doff:4; /**< Data Offset */ |
---|
441 | LT_BITFIELD8 fin:1; /**< FIN */ |
---|
442 | LT_BITFIELD8 syn:1; /**< SYN flag */ |
---|
443 | LT_BITFIELD8 rst:1; /**< RST flag */ |
---|
444 | LT_BITFIELD8 psh:1; /**< PuSH flag */ |
---|
445 | LT_BITFIELD8 ack:1; /**< ACK flag */ |
---|
446 | LT_BITFIELD8 urg:1; /**< URG flag */ |
---|
447 | LT_BITFIELD8 res2:2; /**< Reserved */ |
---|
448 | # elif BYTE_ORDER == BIG_ENDIAN |
---|
449 | LT_BITFIELD8 doff:4; /**< Data offset */ |
---|
450 | LT_BITFIELD8 res1:4; /**< Reserved bits */ |
---|
451 | LT_BITFIELD8 res2:2; /**< Reserved */ |
---|
452 | LT_BITFIELD8 urg:1; /**< URG flag */ |
---|
453 | LT_BITFIELD8 ack:1; /**< ACK flag */ |
---|
454 | LT_BITFIELD8 psh:1; /**< PuSH flag */ |
---|
455 | LT_BITFIELD8 rst:1; /**< RST flag */ |
---|
456 | LT_BITFIELD8 syn:1; /**< SYN flag */ |
---|
457 | LT_BITFIELD8 fin:1; /**< FIN flag */ |
---|
458 | # else |
---|
459 | # error "Adjust your <bits/endian.h> defines" |
---|
460 | # endif |
---|
461 | uint16_t window; /**< Window Size */ |
---|
462 | uint16_t check; /**< Checksum */ |
---|
463 | uint16_t urg_ptr; /**< Urgent Pointer */ |
---|
464 | } PACKED libtrace_tcp_t; |
---|
465 | |
---|
466 | /** Generic UDP header structure */ |
---|
467 | typedef struct libtrace_udp { |
---|
468 | uint16_t source; /**< Source port */ |
---|
469 | uint16_t dest; /**< Destination port */ |
---|
470 | uint16_t len; /**< Length */ |
---|
471 | uint16_t check; /**< Checksum */ |
---|
472 | } PACKED libtrace_udp_t; |
---|
473 | |
---|
474 | /** Generic ICMP header structure */ |
---|
475 | typedef struct libtrace_icmp |
---|
476 | { |
---|
477 | uint8_t type; /**< Message Type */ |
---|
478 | uint8_t code; /**< Type Sub-code */ |
---|
479 | uint16_t checksum; /**< Checksum */ |
---|
480 | union |
---|
481 | { |
---|
482 | struct |
---|
483 | { |
---|
484 | uint16_t id; |
---|
485 | uint16_t sequence; |
---|
486 | } echo; /**< Echo Datagram */ |
---|
487 | uint32_t gateway; /**< Gateway Address */ |
---|
488 | struct |
---|
489 | { |
---|
490 | uint16_t unused; |
---|
491 | uint16_t mtu; |
---|
492 | } frag; /**< Path MTU Discovery */ |
---|
493 | } un; /**< Union for Payloads of Various ICMP Codes */ |
---|
494 | } PACKED libtrace_icmp_t; |
---|
495 | |
---|
496 | /** Generic LLC/SNAP header structure */ |
---|
497 | typedef struct libtrace_llcsnap |
---|
498 | { |
---|
499 | /* LLC */ |
---|
500 | uint8_t dsap; /**< Destination Service Access Point */ |
---|
501 | uint8_t ssap; /**< Source Service Access Point */ |
---|
502 | uint8_t control; |
---|
503 | /* SNAP */ |
---|
504 | LT_BITFIELD32 oui:24; /**< Organisationally Unique Identifier (scope)*/ |
---|
505 | uint16_t type; /**< Protocol within OUI */ |
---|
506 | } PACKED libtrace_llcsnap_t; |
---|
507 | |
---|
508 | /** 802.3 frame */ |
---|
509 | typedef struct libtrace_ether |
---|
510 | { |
---|
511 | uint8_t ether_dhost[6]; /**< Destination Ether Addr */ |
---|
512 | uint8_t ether_shost[6]; /**< Source Ether Addr */ |
---|
513 | uint16_t ether_type; /**< Packet Type ID Field (next-header) */ |
---|
514 | } PACKED libtrace_ether_t; |
---|
515 | |
---|
516 | /** 802.1Q frame */ |
---|
517 | typedef struct libtrace_8021q |
---|
518 | { |
---|
519 | LT_BITFIELD16 vlan_pri:3; /**< VLAN User Priority */ |
---|
520 | LT_BITFIELD16 vlan_cfi:1; /**< VLAN Format Indicator, |
---|
521 | * 0 for ethernet, 1 for token ring */ |
---|
522 | LT_BITFIELD16 vlan_id:12; /**< VLAN Id */ |
---|
523 | uint16_t vlan_ether_type; /**< VLAN Sub-packet Type ID Field |
---|
524 | * (next-header)*/ |
---|
525 | } PACKED libtrace_8021q_t; |
---|
526 | |
---|
527 | /** ATM User Network Interface (UNI) Cell. */ |
---|
528 | typedef struct libtrace_atm_cell |
---|
529 | { |
---|
530 | LT_BITFIELD32 gfc:4; /**< Generic Flow Control */ |
---|
531 | LT_BITFIELD32 vpi:8; /**< Virtual Path Identifier */ |
---|
532 | LT_BITFIELD32 vci:16; /**< Virtual Channel Identifier */ |
---|
533 | LT_BITFIELD32 pt:3; /**< Payload Type */ |
---|
534 | LT_BITFIELD32 clp:1; /**< Cell Loss Priority */ |
---|
535 | LT_BITFIELD32 hec:8; /**< Header Error Control */ |
---|
536 | } PACKED libtrace_atm_cell_t; |
---|
537 | |
---|
538 | /** ATM Network Node/Network Interface (NNI) Cell. */ |
---|
539 | typedef struct libtrace_atm_nni_cell |
---|
540 | { |
---|
541 | LT_BITFIELD32 vpi:12; /**< Virtual Path Identifier */ |
---|
542 | LT_BITFIELD32 vci:16; /**< Virtual Channel Identifier */ |
---|
543 | LT_BITFIELD32 pt:3; /**< Payload Type */ |
---|
544 | LT_BITFIELD32 clp:1; /**< Cell Loss Priority */ |
---|
545 | LT_BITFIELD32 hec:8; /**< Header Error Control */ |
---|
546 | } PACKED libtrace_atm_nni_cell_t; |
---|
547 | |
---|
548 | /** Captured UNI cell. |
---|
549 | * |
---|
550 | * Endance don't capture the HEC, presumably to keep alignment. This |
---|
551 | * version of the \ref libtrace_atm_cell is used when dealing with dag |
---|
552 | * captures of uni cells. |
---|
553 | * |
---|
554 | */ |
---|
555 | typedef struct libtrace_atm_capture_cell |
---|
556 | { |
---|
557 | LT_BITFIELD32 gfc:4; /**< Generic Flow Control */ |
---|
558 | LT_BITFIELD32 vpi:8; /**< Virtual Path Identifier */ |
---|
559 | LT_BITFIELD32 vci:16; /**< Virtual Channel Identifier */ |
---|
560 | LT_BITFIELD32 pt:3; /**< Payload Type */ |
---|
561 | LT_BITFIELD32 clp:1; /**< Cell Loss Priority */ |
---|
562 | } PACKED libtrace_atm_capture_cell_t; |
---|
563 | |
---|
564 | /** Captured NNI cell. |
---|
565 | * |
---|
566 | * Endance don't capture the HEC, presumably to keep alignment. This |
---|
567 | * version of the \ref libtrace_atm_nni_cell is used when dealing with dag |
---|
568 | * captures of nni cells. |
---|
569 | * |
---|
570 | */ |
---|
571 | typedef struct libtrace_atm_nni_capture_cell |
---|
572 | { |
---|
573 | LT_BITFIELD32 vpi:12; /**< Virtual Path Identifier */ |
---|
574 | LT_BITFIELD32 vci:16; /**< Virtual Channel Identifier */ |
---|
575 | LT_BITFIELD32 pt:3; /**< Payload Type */ |
---|
576 | LT_BITFIELD32 clp:1; /**< Cell Loss Priority */ |
---|
577 | LT_BITFIELD32 hec:8; /**< Header Error Control */ |
---|
578 | } PACKED libtrace_atm_nni_capture_cell_t; |
---|
579 | |
---|
580 | /** PPP header */ |
---|
581 | typedef struct libtrace_ppp |
---|
582 | { |
---|
583 | /* I can't figure out where the hell these two variables come from. They're |
---|
584 | * definitely not in RFC 1661 which defines PPP. Probably some weird thing |
---|
585 | * relating to the lack of distinction between PPP, HDLC and CHDLC */ |
---|
586 | |
---|
587 | /* uint8_t address; */ /**< PPP Address (0xFF - All stations) */ |
---|
588 | /* uint8_t header; */ /**< PPP Control (0x03 - Unnumbered info) */ |
---|
589 | uint16_t protocol; /**< PPP Protocol (htons(0x0021) - IPv4 */ |
---|
590 | } PACKED libtrace_ppp_t; |
---|
591 | |
---|
592 | /** PPPoE header */ |
---|
593 | typedef struct libtrace_pppoe |
---|
594 | { |
---|
595 | LT_BITFIELD8 version:4; /**< Protocol version number */ |
---|
596 | LT_BITFIELD8 type:4; /**< PPPoE Type */ |
---|
597 | uint8_t code; /**< PPPoE Code */ |
---|
598 | uint16_t session_id; /**< Session Identifier */ |
---|
599 | uint16_t length; /**< Total Length of the PPP packet */ |
---|
600 | } PACKED libtrace_pppoe_t; |
---|
601 | |
---|
602 | /** 802.11 header */ |
---|
603 | typedef struct libtrace_80211_t { |
---|
604 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
605 | LT_BITFIELD32 protocol:2; |
---|
606 | LT_BITFIELD32 type:2; |
---|
607 | LT_BITFIELD32 subtype:4; |
---|
608 | #else |
---|
609 | LT_BITFIELD32 subtype:4; |
---|
610 | LT_BITFIELD32 type:2; |
---|
611 | LT_BITFIELD32 protocol:2; |
---|
612 | #endif |
---|
613 | |
---|
614 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
615 | LT_BITFIELD32 to_ds:1; /**< Packet to Distribution Service */ |
---|
616 | LT_BITFIELD32 from_ds:1; /**< Packet from Distribution Service */ |
---|
617 | LT_BITFIELD32 more_frag:1; /**< Packet has more fragments */ |
---|
618 | LT_BITFIELD32 retry:1; /**< Packet is a retry */ |
---|
619 | LT_BITFIELD32 power:1; |
---|
620 | LT_BITFIELD32 more_data:1; |
---|
621 | LT_BITFIELD32 wep:1; |
---|
622 | LT_BITFIELD32 order:1; |
---|
623 | #else |
---|
624 | LT_BITFIELD32 order:1; |
---|
625 | LT_BITFIELD32 wep:1; |
---|
626 | LT_BITFIELD32 more_data:1; |
---|
627 | LT_BITFIELD32 power:1; |
---|
628 | LT_BITFIELD32 retry:1; /**< Packet is a retry */ |
---|
629 | LT_BITFIELD32 more_frag:1; /**< Packet has more fragments */ |
---|
630 | LT_BITFIELD32 from_ds:1; /**< Packet from Distribution Service */ |
---|
631 | LT_BITFIELD32 to_ds:1; /**< Packet to Distribution Service */ |
---|
632 | #endif |
---|
633 | uint16_t duration; |
---|
634 | uint8_t mac1[6]; |
---|
635 | uint8_t mac2[6]; |
---|
636 | uint8_t mac3[6]; |
---|
637 | uint16_t SeqCtl; |
---|
638 | uint8_t mac4[6]; |
---|
639 | } PACKED libtrace_80211_t; |
---|
640 | |
---|
641 | /** The Radiotap header pre-amble |
---|
642 | * |
---|
643 | * All Radiotap headers start with this pre-amble, followed by the fields |
---|
644 | * specified in the it_present bitmask. If bit 31 of it_present is set, then |
---|
645 | * another bitmask follows. |
---|
646 | * @note All of the radiotap data fields are in little-endian byte-order. |
---|
647 | */ |
---|
648 | typedef struct libtrace_radiotap_t { |
---|
649 | uint8_t it_version; /**< Radiotap version */ |
---|
650 | uint8_t it_pad; /**< Padding for natural alignment */ |
---|
651 | uint16_t it_len; /**< Length in bytes of the entire Radiotap header */ |
---|
652 | uint32_t it_present; /**< Which Radiotap fields are present */ |
---|
653 | } PACKED libtrace_radiotap_t; |
---|
654 | |
---|
655 | |
---|
656 | #ifdef WIN32 |
---|
657 | #pragma pack(pop) |
---|
658 | #endif |
---|
659 | |
---|
660 | |
---|
661 | /*@}*/ |
---|
662 | |
---|
663 | /** Prints help information for libtrace |
---|
664 | * |
---|
665 | * Function prints out some basic help information regarding libtrace, |
---|
666 | * and then prints out the help() function registered with each input module |
---|
667 | */ |
---|
668 | DLLEXPORT void trace_help(void); |
---|
669 | |
---|
670 | /** @name Trace management |
---|
671 | * These members deal with creating, configuring, starting, pausing and |
---|
672 | * cleaning up a trace object |
---|
673 | *@{ |
---|
674 | */ |
---|
675 | |
---|
676 | /** Create a trace file from a URI |
---|
677 | * |
---|
678 | * @param uri containing a valid libtrace URI |
---|
679 | * @return an opaque pointer to a libtrace_t |
---|
680 | * |
---|
681 | * Valid URI's are: |
---|
682 | * - erf:/path/to/erf/file |
---|
683 | * - erf:- (stdin) |
---|
684 | * - dag:/dev/dagcard |
---|
685 | * - pcapint:pcapinterface (eg: pcap:eth0) |
---|
686 | * - pcap:/path/to/pcap/file |
---|
687 | * - pcap:- |
---|
688 | * - rt:hostname |
---|
689 | * - rt:hostname:port |
---|
690 | * - rtclient:hostname (deprecated) |
---|
691 | * - rtclient:hostname:port (deprecated) |
---|
692 | * |
---|
693 | * If an error occured when attempting to open the trace file, an error |
---|
694 | * trace is returned and trace_get_error should be called to find out |
---|
695 | * if an error occured, and what that error was. The trace is created in the |
---|
696 | * configuration state, you must call trace_start to start the capture. |
---|
697 | */ |
---|
698 | DLLEXPORT libtrace_t *trace_create(const char *uri); |
---|
699 | |
---|
700 | /** Creates a "dummy" trace file that has only the format type set. |
---|
701 | * |
---|
702 | * @return an opaque pointer to a (sparsely initialised) libtrace_t |
---|
703 | * |
---|
704 | * IMPORTANT: Do not attempt to call trace_read_packet or other such functions |
---|
705 | * with the dummy trace. Its intended purpose is to act as a packet->trace for |
---|
706 | * libtrace_packet_t's that are not associated with a libtrace_t structure. |
---|
707 | */ |
---|
708 | DLLEXPORT libtrace_t *trace_create_dead(const char *uri); |
---|
709 | |
---|
710 | /** Creates a trace output file from a URI. |
---|
711 | * |
---|
712 | * @param uri the uri string describing the output format and destination |
---|
713 | * @return an opaque pointer to a libtrace_output_t |
---|
714 | * |
---|
715 | * Valid URI's are: |
---|
716 | * - erf:/path/to/erf/file |
---|
717 | * - pcap:/path/to/pcap/file |
---|
718 | * - wtf:/path/to/wtf/file |
---|
719 | * |
---|
720 | * If an error occured when attempting to open the output trace, NULL is returned |
---|
721 | * and trace_errno is set. Use trace_perror_output() to get more information |
---|
722 | */ |
---|
723 | DLLEXPORT libtrace_out_t *trace_create_output(const char *uri); |
---|
724 | |
---|
725 | /** Start the capture |
---|
726 | * @param libtrace The trace to start |
---|
727 | * @return 0 on success, -1 on failure |
---|
728 | * |
---|
729 | * This does the actual work with starting the trace capture, and applying |
---|
730 | * all the config options. This may fail. |
---|
731 | */ |
---|
732 | DLLEXPORT int trace_start(libtrace_t *libtrace); |
---|
733 | |
---|
734 | /** Pause the capture |
---|
735 | * @param libtrace The trace to pause |
---|
736 | * @return 0 on success, -1 on failure |
---|
737 | * |
---|
738 | * This stops a capture in progress and returns you to the configuration |
---|
739 | * state. Any packets that arrive after trace_pause() has been called |
---|
740 | * will be discarded. To resume capture, call trace_start(). |
---|
741 | */ |
---|
742 | DLLEXPORT int trace_pause(libtrace_t *libtrace); |
---|
743 | |
---|
744 | /** Start an output trace |
---|
745 | * @param libtrace The trace to start |
---|
746 | * @return 0 on success, -1 on failure |
---|
747 | * |
---|
748 | * This does the actual work with starting a trace for write. This generally |
---|
749 | * creates the file. |
---|
750 | */ |
---|
751 | DLLEXPORT int trace_start_output(libtrace_out_t *libtrace); |
---|
752 | |
---|
753 | /** Valid trace capture options */ |
---|
754 | typedef enum { |
---|
755 | TRACE_OPTION_SNAPLEN, /**< Number of bytes captured */ |
---|
756 | TRACE_OPTION_PROMISC, /**< Capture packets to other hosts */ |
---|
757 | TRACE_OPTION_FILTER, /**< Apply this filter to all packets */ |
---|
758 | TRACE_OPTION_META_FREQ, /**< Frequency of meta-data information, e.g. DUCK packets */ |
---|
759 | /** trace_event ignores gaps between packets when reading traces off disk */ |
---|
760 | TRACE_OPTION_EVENT_REALTIME |
---|
761 | } trace_option_t; |
---|
762 | |
---|
763 | /** Sets an input config option |
---|
764 | * @param libtrace the trace object to apply the option to |
---|
765 | * @param option the option to set |
---|
766 | * @param value the value to set the option to |
---|
767 | * @return -1 if option configuration failed, 0 otherwise |
---|
768 | * This should be called after trace_create, and before trace_start |
---|
769 | */ |
---|
770 | DLLEXPORT int trace_config(libtrace_t *libtrace, |
---|
771 | trace_option_t option, |
---|
772 | void *value); |
---|
773 | |
---|
774 | typedef enum { |
---|
775 | TRACE_OPTION_OUTPUT_FILEFLAGS, /**< File flags to open the trace file |
---|
776 | * with. eg O_APPEND |
---|
777 | */ |
---|
778 | TRACE_OPTION_OUTPUT_COMPRESS /**< Compression level, eg 6. */ |
---|
779 | } trace_option_output_t; |
---|
780 | |
---|
781 | /** Sets an output config option |
---|
782 | * |
---|
783 | * @param libtrace the output trace object to apply the option to |
---|
784 | * @param option the option to set |
---|
785 | * @param value the value to set the option to |
---|
786 | * @return -1 if option configuration failed, 0 otherwise |
---|
787 | * This should be called after trace_create_output, and before |
---|
788 | * trace_start_output |
---|
789 | */ |
---|
790 | DLLEXPORT int trace_config_output(libtrace_out_t *libtrace, |
---|
791 | trace_option_output_t option, |
---|
792 | void *value |
---|
793 | ); |
---|
794 | |
---|
795 | /** Close a trace file, freeing up any resources it may have been using |
---|
796 | * |
---|
797 | */ |
---|
798 | DLLEXPORT void trace_destroy(libtrace_t *trace); |
---|
799 | |
---|
800 | /** Close a trace file, freeing up any resources it may have been using |
---|
801 | * @param trace trace file to be destroyed |
---|
802 | */ |
---|
803 | DLLEXPORT void trace_destroy_dead(libtrace_t *trace); |
---|
804 | |
---|
805 | /** Close a trace output file, freeing up any resources it may have been using |
---|
806 | * @param trace the output trace file to be destroyed |
---|
807 | */ |
---|
808 | DLLEXPORT void trace_destroy_output(libtrace_out_t *trace); |
---|
809 | |
---|
810 | /** Check (and clear) the current error state of an input trace |
---|
811 | * @param trace the trace file to check the error state on |
---|
812 | * @return Error report |
---|
813 | * This reads and returns the current error state and sets the current error |
---|
814 | * to "no error". |
---|
815 | */ |
---|
816 | DLLEXPORT libtrace_err_t trace_get_err(libtrace_t *trace); |
---|
817 | |
---|
818 | /** Return if there is an error |
---|
819 | * @param trace the trace file to check the error state on |
---|
820 | * This does not clear the error status, and only returns true or false. |
---|
821 | */ |
---|
822 | DLLEXPORT bool trace_is_err(libtrace_t *trace); |
---|
823 | |
---|
824 | /** Output an error message to stderr and clear the error status. |
---|
825 | * @param trace the trace with the error to output |
---|
826 | * @param msg the message to prefix to the error |
---|
827 | * This function does clear the error status. |
---|
828 | */ |
---|
829 | DLLEXPORT void trace_perror(libtrace_t *trace, const char *msg,...) PRINTF(2,3); |
---|
830 | |
---|
831 | /** Check (and clear) the current error state of an output trace |
---|
832 | * @param trace the output trace file to check the error state on |
---|
833 | * @return Error report |
---|
834 | * This reads and returns the current error state and sets the current error |
---|
835 | * to "no error". |
---|
836 | */ |
---|
837 | DLLEXPORT libtrace_err_t trace_get_err_output(libtrace_out_t *trace); |
---|
838 | |
---|
839 | /** Return if there is an error |
---|
840 | * @param trace the trace file to check the error state on |
---|
841 | * This does not clear the error status, and only returns true or false. |
---|
842 | */ |
---|
843 | DLLEXPORT bool trace_is_err_output(libtrace_out_t *trace); |
---|
844 | |
---|
845 | /** Output an error message to stderr and clear the error status. |
---|
846 | * @param trace the trace with the error to output |
---|
847 | * @param msg the message to prefix to the error |
---|
848 | * This function does clear the error status. |
---|
849 | */ |
---|
850 | DLLEXPORT void trace_perror_output(libtrace_out_t *trace, const char *msg,...) |
---|
851 | PRINTF(2,3); |
---|
852 | |
---|
853 | /** Return the number of captured packets |
---|
854 | * Includes the number of packets counted as early as possible, before |
---|
855 | * filtering, and includes dropped packets. |
---|
856 | * |
---|
857 | * @param trace Trace to examine |
---|
858 | * @returns number of packets seen at the capture point before filtering. |
---|
859 | * |
---|
860 | * If this is not known, this will return UINT64_MAX |
---|
861 | */ |
---|
862 | uint64_t trace_get_received_packets(libtrace_t *trace); |
---|
863 | |
---|
864 | /** Return the number of filtered packets |
---|
865 | * Returns the number of packets that were captured, but discarded for not |
---|
866 | * matching a trace filter. This includes packets |
---|
867 | * |
---|
868 | * @param trace Trace file to examine |
---|
869 | * @returns the number of packets that were successfully captured, but filtered |
---|
870 | * |
---|
871 | * If this is not known, this will return UINT64_MAX |
---|
872 | */ |
---|
873 | uint64_t trace_get_filtered_packets(libtrace_t *trace); |
---|
874 | |
---|
875 | /** Return the number of packets that have been dropped for lack of packets |
---|
876 | * @param trace Trace file to examine |
---|
877 | * @returns The number of packets captured, but dropped due to buffer overruns |
---|
878 | */ |
---|
879 | uint64_t trace_get_dropped_packets(libtrace_t *trace); |
---|
880 | |
---|
881 | /** Return the number of packets that have been returned to library user |
---|
882 | * @param trace Trace file to examine |
---|
883 | * @returns The number of packets returned to the user of the library. |
---|
884 | */ |
---|
885 | uint64_t trace_get_accepted_packets(libtrace_t *trace); |
---|
886 | |
---|
887 | |
---|
888 | /*@}*/ |
---|
889 | |
---|
890 | /** @name Reading/Writing packets |
---|
891 | * These members deal with creating, reading and writing packets |
---|
892 | * |
---|
893 | * @{ |
---|
894 | */ |
---|
895 | |
---|
896 | /** Create a new packet object |
---|
897 | * |
---|
898 | * @return a pointer to an initialised libtrace_packet_t object |
---|
899 | */ |
---|
900 | DLLEXPORT libtrace_packet_t *trace_create_packet(void); |
---|
901 | |
---|
902 | /** Copy a packet |
---|
903 | * @param packet the source packet to copy |
---|
904 | * @return a new packet which has the same content as the source packet |
---|
905 | * @note This always involves a copy, which can be slow. Use of this |
---|
906 | * function should be avoided where possible. |
---|
907 | * @par The reason you would want to use this function is that a zerocopied |
---|
908 | * packet from a device is using the devices memory which may be a limited |
---|
909 | * resource. Copying the packet will cause it to be copied into the systems |
---|
910 | * memory. |
---|
911 | */ |
---|
912 | DLLEXPORT libtrace_packet_t *trace_copy_packet(const libtrace_packet_t *packet); |
---|
913 | |
---|
914 | /** Destroy a packet object |
---|
915 | * |
---|
916 | * sideeffect: sets packet to NULL |
---|
917 | */ |
---|
918 | DLLEXPORT void trace_destroy_packet(libtrace_packet_t *packet); |
---|
919 | |
---|
920 | |
---|
921 | /** Read one packet from the trace |
---|
922 | * |
---|
923 | * @param trace the libtrace opaque pointer |
---|
924 | * @param packet the packet opaque pointer |
---|
925 | * @return 0 on EOF, negative value on error, number of bytes read when |
---|
926 | * successful. |
---|
927 | * |
---|
928 | * @note the number of bytes read is usually (but not always) the same as |
---|
929 | * trace_get_framing_length()+trace_get_capture_length() depending on the |
---|
930 | * trace format. |
---|
931 | * @note the trace must have been started with trace_start before calling |
---|
932 | * this function |
---|
933 | */ |
---|
934 | DLLEXPORT int trace_read_packet(libtrace_t *trace, libtrace_packet_t *packet); |
---|
935 | |
---|
936 | /** Event types |
---|
937 | * see \ref libtrace_eventobj_t and \ref trace_event |
---|
938 | */ |
---|
939 | typedef enum { |
---|
940 | TRACE_EVENT_IOWAIT, /**< Need to block on fd */ |
---|
941 | TRACE_EVENT_SLEEP, /**< Sleep for some time */ |
---|
942 | TRACE_EVENT_PACKET, /**< packet has arrived */ |
---|
943 | TRACE_EVENT_TERMINATE /**< End of trace */ |
---|
944 | } libtrace_event_t; |
---|
945 | |
---|
946 | /** Structure returned by libtrace_event explaining what the current event is */ |
---|
947 | typedef struct libtrace_eventobj_t { |
---|
948 | libtrace_event_t type; /**< event type (iowait,sleep,packet) */ |
---|
949 | int fd; /**< if IOWAIT, the fd to sleep on */ |
---|
950 | double seconds; /**< if SLEEP, the amount of time to sleep for |
---|
951 | */ |
---|
952 | int size; /**< if PACKET, the value returned from |
---|
953 | * trace_read_packet |
---|
954 | */ |
---|
955 | } libtrace_eventobj_t; |
---|
956 | |
---|
957 | /** Processes the next libtrace event |
---|
958 | * @param trace the libtrace opaque pointer |
---|
959 | * @param packet the libtrace_packet opaque pointer |
---|
960 | * @return libtrace_event struct containing the type, and potential |
---|
961 | * fd or seconds to sleep on |
---|
962 | * |
---|
963 | * Type can be: |
---|
964 | * TRACE_EVENT_IOWAIT Waiting on I/O on fd |
---|
965 | * TRACE_EVENT_SLEEP Next event in seconds |
---|
966 | * TRACE_EVENT_PACKET Packet arrived in buffer with size size |
---|
967 | * TRACE_EVENT_TERMINATE Trace terminated (perhaps with an error condition) |
---|
968 | */ |
---|
969 | DLLEXPORT libtrace_eventobj_t trace_event(libtrace_t *trace, |
---|
970 | libtrace_packet_t *packet); |
---|
971 | |
---|
972 | |
---|
973 | /** Write one packet out to the output trace |
---|
974 | * |
---|
975 | * @param trace the libtrace_out opaque pointer |
---|
976 | * @param packet the packet opaque pointer |
---|
977 | * @return the number of bytes written out, if zero or negative then an error has occured. |
---|
978 | */ |
---|
979 | DLLEXPORT int trace_write_packet(libtrace_out_t *trace, libtrace_packet_t *packet); |
---|
980 | /*@}*/ |
---|
981 | |
---|
982 | /** @name Protocol decodes |
---|
983 | * These functions locate and return a pointer to various headers inside a |
---|
984 | * packet |
---|
985 | * @{ |
---|
986 | */ |
---|
987 | |
---|
988 | |
---|
989 | /** Gets a pointer to the first byte of the packet as it was captured and |
---|
990 | * returns its corresponding linktype and capture length. |
---|
991 | * |
---|
992 | * Use this function instead of the deprecated trace_get_link(). |
---|
993 | * |
---|
994 | * @param packet the packet pointer |
---|
995 | * @param[out] linktype the linktype of the returned pointer |
---|
996 | * @param[out] remaining the capture length (the number of captured bytes from |
---|
997 | * the returned pointer) |
---|
998 | * @return a pointer to the first byte of the packet |
---|
999 | */ |
---|
1000 | DLLEXPORT void *trace_get_packet_buffer(const libtrace_packet_t *packet, |
---|
1001 | libtrace_linktype_t *linktype, uint32_t *remaining); |
---|
1002 | |
---|
1003 | /** get a pointer to the link layer |
---|
1004 | * @param packet the packet opaque pointer |
---|
1005 | * |
---|
1006 | * @return a pointer to the link layer, or NULL if there is no link layer |
---|
1007 | * |
---|
1008 | * @deprecated This function is deprecated: Use trace_get_packet_buffer() or |
---|
1009 | * one of the trace_get_layer*() functions instead. |
---|
1010 | * @note you should call trace_get_link_type to find out what type of link |
---|
1011 | * layer this is |
---|
1012 | */ |
---|
1013 | DLLEXPORT SIMPLE_FUNCTION DEPRECATED |
---|
1014 | void *trace_get_link(const libtrace_packet_t *packet); |
---|
1015 | |
---|
1016 | /** get a pointer to the IPv4 header (if any) |
---|
1017 | * @param packet the packet opaque pointer |
---|
1018 | * |
---|
1019 | * @return a pointer to the IPv4 header, or NULL if there is no IPv4 header |
---|
1020 | * |
---|
1021 | * You should consider using \ref trace_get_layer3 instead of this function. |
---|
1022 | */ |
---|
1023 | DLLEXPORT SIMPLE_FUNCTION |
---|
1024 | libtrace_ip_t *trace_get_ip(libtrace_packet_t *packet); |
---|
1025 | |
---|
1026 | /** get a pointer to the IPv6 header (if any) |
---|
1027 | * @param packet the packet opaque pointer |
---|
1028 | * |
---|
1029 | * @return a pointer to the IPv6 header, or NULL if there is no IPv6 header |
---|
1030 | * |
---|
1031 | * You should consider using \ref trace_get_layer3 instead of this function. |
---|
1032 | */ |
---|
1033 | DLLEXPORT SIMPLE_FUNCTION |
---|
1034 | libtrace_ip6_t *trace_get_ip6(libtrace_packet_t *packet); |
---|
1035 | |
---|
1036 | /** Return a pointer to the first metadata header in a packet, if present. |
---|
1037 | * |
---|
1038 | * This function takes a pointer to a libtrace packet and if any metadata |
---|
1039 | * headers exist, returns a pointer to the first one, along with its |
---|
1040 | * corresponding linktype. |
---|
1041 | * |
---|
1042 | * If no metadata headers exist in the packet, NULL is returned. |
---|
1043 | * |
---|
1044 | * A metadata header is a header that was prepended by the capturing device, |
---|
1045 | * such as a Linux SLL header, or a Radiotap wireless monitoring header. |
---|
1046 | * Subsequent metadata headers may be accessed with the |
---|
1047 | * trace_get_payload_from_meta(...) function. |
---|
1048 | * |
---|
1049 | * @param packet the libtrace packet |
---|
1050 | * @param[out] linktype the linktype of the returned metadata header |
---|
1051 | * @param[out] remaining the number of bytes captured after the returned |
---|
1052 | * pointer. |
---|
1053 | * @return a pointer to the first metadata header, or NULL if there are no |
---|
1054 | * metadata headers present. |
---|
1055 | * |
---|
1056 | * remaining may be NULL, however linktype must be provided. |
---|
1057 | */ |
---|
1058 | DLLEXPORT void *trace_get_packet_meta(const libtrace_packet_t *packet, |
---|
1059 | libtrace_linktype_t *linktype, |
---|
1060 | uint32_t *remaining); |
---|
1061 | |
---|
1062 | /** Returns the payload of a metadata header. |
---|
1063 | * |
---|
1064 | * This function takes a pointer to the start of a metadata header (either |
---|
1065 | * obtained via trace_get_packet_meta(...) or by a previous call to |
---|
1066 | * trace_get_payload_from_meta(...)) along with its corresponding linktype and |
---|
1067 | * returns the payload, i.e. the next header. It will also update the linktype |
---|
1068 | * parameter to indicate the type of payload. |
---|
1069 | * |
---|
1070 | * If the linktype indicates that the header passed in is not a metadata |
---|
1071 | * header, the function returns NULL to indicate this. The linktype remains |
---|
1072 | * unchanged in this case. |
---|
1073 | * |
---|
1074 | * This function allows the user to iterate through metadata headers which are |
---|
1075 | * sometimes present before the actual packet as it was received on the wire. |
---|
1076 | * Examples of metadata headers include the Linux SLL header and the Radiotap |
---|
1077 | * wireless monitoring header. |
---|
1078 | * |
---|
1079 | * @param[in] meta a pointer to a header |
---|
1080 | * @param[in,out] linktype the linktype of meta (updated to indicate the |
---|
1081 | * linktype of the returned header if applicable). |
---|
1082 | * @param[in,out] remaining the number of bytes after the meta pointer. |
---|
1083 | * @return a pointer to the payload of the metadata header. If meta is not a |
---|
1084 | * pointer to a metadata header, NULL is returned and linktype remains |
---|
1085 | * unchanged. |
---|
1086 | * |
---|
1087 | * All parameters are mandatory. NULL will be returned if any are NULL. |
---|
1088 | */ |
---|
1089 | DLLEXPORT void *trace_get_payload_from_meta(const void *meta, |
---|
1090 | libtrace_linktype_t *linktype, |
---|
1091 | uint32_t *remaining); |
---|
1092 | |
---|
1093 | |
---|
1094 | /** Get a pointer to the layer 2 header. Generally this is the first byte of the |
---|
1095 | * packet as it was seen on the wire. |
---|
1096 | * |
---|
1097 | * This function takes a libtrace packet and skips over any metadata headers if |
---|
1098 | * present (such as Linux SLL or Radiotap) and returns a pointer to the first |
---|
1099 | * byte of the packet that was actually received by the network interface. |
---|
1100 | * |
---|
1101 | * @param packet the libtrace packet |
---|
1102 | * @param[out] linktype the linktype of the returned layer 2 header |
---|
1103 | * @param[out] remaining the number of bytes left in the packet after the |
---|
1104 | * returned pointer. |
---|
1105 | * @return a pointer to the first byte of the packet as it was seen on the |
---|
1106 | * wire. |
---|
1107 | * |
---|
1108 | * remaining may be NULL, otherwise it will be filled in by the function. |
---|
1109 | */ |
---|
1110 | DLLEXPORT void *trace_get_layer2(const libtrace_packet_t *packet, |
---|
1111 | libtrace_linktype_t *linktype, |
---|
1112 | uint32_t *remaining); |
---|
1113 | |
---|
1114 | /** Gets a pointer to the next header given a pointer to a layer2 header |
---|
1115 | * |
---|
1116 | * @param l2 The pointer to the current layer2 header |
---|
1117 | * @param linktype The type of the layer2 header |
---|
1118 | * @param[out] ethertype An optional output variable of the ethernet type |
---|
1119 | * @param[in,out] remaining Optionally updated with the length remaining |
---|
1120 | * |
---|
1121 | * @return a pointer to the transport layer header, or NULL if header isn't |
---|
1122 | * present. |
---|
1123 | * |
---|
1124 | * type may be NULL if not needed. |
---|
1125 | * |
---|
1126 | * Remaining may be NULL. If Remaining is not NULL it must point to the number |
---|
1127 | * of bytes captured of the layer2 header and beyond. It will be decremented |
---|
1128 | * by the number of bytes skipped to find the payload. |
---|
1129 | * |
---|
1130 | */ |
---|
1131 | DLLEXPORT void *trace_get_payload_from_layer2(void *l2, |
---|
1132 | libtrace_linktype_t linktype, |
---|
1133 | uint16_t *ethertype, |
---|
1134 | uint32_t *remaining); |
---|
1135 | |
---|
1136 | |
---|
1137 | /** Get a pointer to the layer 3 header. |
---|
1138 | * @param packet The packet opaque pointer |
---|
1139 | * @param[out] ethertype The ethertype of the layer 3 header |
---|
1140 | * @param[out] remaining The amount of space available after this header |
---|
1141 | * has been removed. |
---|
1142 | * |
---|
1143 | * @return a pointer to the layer 3 header. |
---|
1144 | * remaining may be NULL, otherwise it will be set to the number of captured |
---|
1145 | * bytes after the pointer returned. |
---|
1146 | */ |
---|
1147 | DLLEXPORT |
---|
1148 | void *trace_get_layer3(const libtrace_packet_t *packet, |
---|
1149 | uint16_t *ethertype, uint32_t *remaining); |
---|
1150 | |
---|
1151 | /** Gets a pointer to the transport layer header (if any) |
---|
1152 | * @param packet a pointer to a libtrace_packet structure |
---|
1153 | * @param[out] proto transport layer protocol |
---|
1154 | * |
---|
1155 | * @return a pointer to the transport layer header, or NULL if there is no |
---|
1156 | * header |
---|
1157 | * |
---|
1158 | * @note proto may be NULL if proto is unneeded. |
---|
1159 | */ |
---|
1160 | DLLEXPORT void *trace_get_transport(const libtrace_packet_t *packet, |
---|
1161 | uint8_t *proto, uint32_t *remaining); |
---|
1162 | |
---|
1163 | /** Gets a pointer to the payload given a pointer to the IP header |
---|
1164 | * @param ip The IP Header |
---|
1165 | * @param[out] proto An output variable of the IP protocol |
---|
1166 | * @param[in,out] remaining Updated with the number of bytes remaining |
---|
1167 | * |
---|
1168 | * @return a pointer to the transport layer header, or NULL if header isn't |
---|
1169 | * present. |
---|
1170 | * |
---|
1171 | * Remaining may be NULL. If Remaining is not NULL it must point to the number |
---|
1172 | * of bytes captured of the IP header and beyond. It will be decremented by |
---|
1173 | * the length of the IPv4 header (including any options). |
---|
1174 | * |
---|
1175 | * proto may be NULL if not needed. |
---|
1176 | * |
---|
1177 | * @note This is similar to trace_get_transport_from_ip in libtrace2 |
---|
1178 | */ |
---|
1179 | DLLEXPORT void *trace_get_payload_from_ip(libtrace_ip_t *ip, uint8_t *proto, |
---|
1180 | uint32_t *remaining); |
---|
1181 | |
---|
1182 | /** Gets a pointer to the payload given a pointer to the IPv6 header |
---|
1183 | * @param ipptr The IPv6 Header |
---|
1184 | * @param[out] proto An output variable of the protocol of the next header |
---|
1185 | * @param[in,out] remaining Updated with the number of bytes remaining |
---|
1186 | * |
---|
1187 | * @return a pointer to the transport layer header, or NULL if the IPv6 header |
---|
1188 | * isn't complete. |
---|
1189 | * |
---|
1190 | * Remaining may be NULL. If Remaining is not NULL it must point to the number |
---|
1191 | * of bytes captured of the IP header and beyond. It will be decremented by |
---|
1192 | * this function by the length of the IPV6 header. |
---|
1193 | * |
---|
1194 | * proto may be NULL if not needed. |
---|
1195 | * |
---|
1196 | */ |
---|
1197 | DLLEXPORT void *trace_get_payload_from_ip6(libtrace_ip6_t *ipptr, |
---|
1198 | uint8_t *prot, uint32_t *remaining); |
---|
1199 | |
---|
1200 | /** Gets a pointer to the payload given a pointer to the link header |
---|
1201 | * @param ip The link pointer |
---|
1202 | * @param[out] type An output variable of the ethernet type |
---|
1203 | * @param[in,out] remaining Updated with the number of bytes remaining |
---|
1204 | * |
---|
1205 | * @return a pointer to the transport layer header, or NULL if header isn't |
---|
1206 | * present. |
---|
1207 | * |
---|
1208 | * Remaining may be NULL. If Remaining is not NULL it must point to the number |
---|
1209 | * of bytes captured of the linklayer and beyond. It will be updated after |
---|
1210 | * this function to the number of bytes remaining after the IP header (and any |
---|
1211 | * IP options) have been removed. |
---|
1212 | * |
---|
1213 | * type may be NULL if not needed. |
---|
1214 | * |
---|
1215 | */ |
---|
1216 | DLLEXPORT void *trace_get_payload_from_link(void *linkptr, |
---|
1217 | libtrace_linktype_t linktype, |
---|
1218 | uint16_t *type, uint32_t *remaining); |
---|
1219 | |
---|
1220 | /** Skips over any 802.1q headers, if present. |
---|
1221 | * @param vlan A pointer to the vlan header |
---|
1222 | * @param[in,out] type The ethernet type, replaced with the vlan ether type |
---|
1223 | * @param[in,out] remaining Updated with the number of bytes remaining |
---|
1224 | * |
---|
1225 | * @return a pointer to the header beyond the vlan header, if present. |
---|
1226 | * Otherwise, returns NULL |
---|
1227 | * |
---|
1228 | * Remaining may be NULL. If Remaining is not NULL it must point to the number |
---|
1229 | * of bytes captured past (but not including) the link layer. This function |
---|
1230 | * will decrement it by the length of the 802.1q headers if present. |
---|
1231 | * |
---|
1232 | * Type must point to the value of the ethernet type. Libtrace will assert |
---|
1233 | * fail if type is NULL. |
---|
1234 | * |
---|
1235 | */ |
---|
1236 | DLLEXPORT void *trace_get_payload_from_vlan( |
---|
1237 | void *vlan, uint16_t *type, uint32_t *remaining); |
---|
1238 | |
---|
1239 | /** Skips over any MPLS headers, if present. |
---|
1240 | * @param mpls A pointer to the mpls header |
---|
1241 | * @param[in,out] type The ethernet type, replaced by the ether type of the |
---|
1242 | * following header - 0x0000 if an Ethernet header is deemed to be next |
---|
1243 | * @param[in,out] remaining Updated with the number of bytes remaining |
---|
1244 | * |
---|
1245 | * @return a pointer to the header beyond the MPLS label, if present. Will |
---|
1246 | * return NULL if there is not enough bytes remaining to skip past the MPLS |
---|
1247 | * label or if the ether type is not MPLS. |
---|
1248 | * |
---|
1249 | * Remaining may be NULL. If remaining is not NULL it must point to the number |
---|
1250 | * of bytes captured past (but not including) the link layer. This function |
---|
1251 | * will decrement it by the length of the topmost MPLS label if present. |
---|
1252 | * |
---|
1253 | * Type must point to the value of the ethernet type. Libtrace will assert |
---|
1254 | * fail if type is NULL. |
---|
1255 | * |
---|
1256 | * NOTE that this function will only remove one MPLS label at a time - the type |
---|
1257 | * will be set to 0x8847 if there is another MPLS label after the one |
---|
1258 | * removed by this function. |
---|
1259 | * |
---|
1260 | */ |
---|
1261 | DLLEXPORT void *trace_get_payload_from_mpls( |
---|
1262 | void *mpls, uint16_t *type, uint32_t *remaining); |
---|
1263 | |
---|
1264 | /** Gets a pointer to the payload given a pointer to a tcp header |
---|
1265 | * @param tcp The tcp Header |
---|
1266 | * @param[in,out] remaining Updated with the number of bytes remaining |
---|
1267 | * |
---|
1268 | * @return a pointer to the tcp payload, or NULL if the payload isn't present. |
---|
1269 | * |
---|
1270 | * Remaining may be NULL. If remaining is not NULL it must point to the number |
---|
1271 | * of bytes captured of the TCP header and beyond. It will be decremented by |
---|
1272 | * this function by the length of the TCP header (including any options). |
---|
1273 | * |
---|
1274 | */ |
---|
1275 | DLLEXPORT void *trace_get_payload_from_tcp(libtrace_tcp_t *tcp, |
---|
1276 | uint32_t *remaining); |
---|
1277 | |
---|
1278 | /** Gets a pointer to the payload given a pointer to a udp header |
---|
1279 | * @param udp The udp Header |
---|
1280 | * @param[in,out] remaining Updated with the number of bytes remaining |
---|
1281 | * |
---|
1282 | * @return a pointer to the udp payload, or NULL if the payload isn't present. |
---|
1283 | * |
---|
1284 | * Remaining may be NULL. If Remaining is not NULL it must point to the number |
---|
1285 | * of bytes captured of the UDP header and beyond. It will be decremented by |
---|
1286 | * this function to the number of bytes remaining after the UDP header. |
---|
1287 | * |
---|
1288 | */ |
---|
1289 | DLLEXPORT void *trace_get_payload_from_udp(libtrace_udp_t *udp, uint32_t *remaining); |
---|
1290 | |
---|
1291 | /** Gets a pointer to the payload given a pointer to a icmp header |
---|
1292 | * @param icmp The icmp Header |
---|
1293 | * @param[in,out] remaining Updated with the number of bytes remaining |
---|
1294 | * |
---|
1295 | * @return a pointer to the icmp payload, or NULL if the payload isn't present. |
---|
1296 | * |
---|
1297 | * Remaining may be NULL. If remaining is not NULL it must point to the number |
---|
1298 | * of bytes captured of the ICMP header and beyond. It will be decremented |
---|
1299 | * by the number of bytes in the ICMP header. |
---|
1300 | * |
---|
1301 | */ |
---|
1302 | DLLEXPORT void *trace_get_payload_from_icmp(libtrace_icmp_t *icmp, |
---|
1303 | uint32_t *remaining); |
---|
1304 | |
---|
1305 | /** get a pointer to the TCP header (if any) |
---|
1306 | * @param packet the packet opaque pointer |
---|
1307 | * |
---|
1308 | * @return a pointer to the TCP header, or NULL if there is not a TCP packet |
---|
1309 | * |
---|
1310 | * @note you should probably use trace_get_transport() |
---|
1311 | */ |
---|
1312 | DLLEXPORT SIMPLE_FUNCTION |
---|
1313 | libtrace_tcp_t *trace_get_tcp(libtrace_packet_t *packet); |
---|
1314 | |
---|
1315 | /** get a pointer to the TCP header (if any) given a pointer to the IP header |
---|
1316 | * @param ip The IP header |
---|
1317 | * @param[in,out] remaining Updated with the number of bytes remaining |
---|
1318 | * |
---|
1319 | * @return a pointer to the TCP header, or NULL if this is not a TCP packet |
---|
1320 | * |
---|
1321 | * Remaining may be NULL. If Remaining is not NULL it must point to the number |
---|
1322 | * of bytes captured of the TCP header and beyond. It will be decremented by |
---|
1323 | * the number of bytes in the TCP header (including any TCP options). |
---|
1324 | * |
---|
1325 | * @note The last parameter has changed from libtrace2 |
---|
1326 | */ |
---|
1327 | DLLEXPORT SIMPLE_FUNCTION |
---|
1328 | libtrace_tcp_t *trace_get_tcp_from_ip(libtrace_ip_t *ip, uint32_t *remaining); |
---|
1329 | |
---|
1330 | /** get a pointer to the UDP header (if any) |
---|
1331 | * @param packet the packet opaque pointer |
---|
1332 | * |
---|
1333 | * @return a pointer to the UDP header, or NULL if this is not a UDP packet |
---|
1334 | */ |
---|
1335 | DLLEXPORT SIMPLE_FUNCTION |
---|
1336 | libtrace_udp_t *trace_get_udp(libtrace_packet_t *packet); |
---|
1337 | |
---|
1338 | /** get a pointer to the UDP header (if any) given a pointer to the IP header |
---|
1339 | * @param ip The IP header |
---|
1340 | * @param[in,out] remaining Updated with the number of bytes remaining |
---|
1341 | * |
---|
1342 | * @return a pointer to the UDP header, or NULL if this is not an UDP packet |
---|
1343 | * |
---|
1344 | * Remaining may be NULL. If Remaining is not NULL it must point to the number |
---|
1345 | * of bytes captured of the UDP header and beyond. This function will |
---|
1346 | * decremented it by the length of the UDP header. |
---|
1347 | * |
---|
1348 | * @note Beware the change from libtrace2 from skipped to remaining |
---|
1349 | */ |
---|
1350 | DLLEXPORT SIMPLE_FUNCTION |
---|
1351 | libtrace_udp_t *trace_get_udp_from_ip(libtrace_ip_t *ip,uint32_t *remaining); |
---|
1352 | |
---|
1353 | /** get a pointer to the ICMP header (if any) |
---|
1354 | * @param packet the packet opaque pointer |
---|
1355 | * |
---|
1356 | * @return a pointer to the ICMP header, or NULL if this is not a ICMP packet |
---|
1357 | */ |
---|
1358 | DLLEXPORT SIMPLE_FUNCTION |
---|
1359 | libtrace_icmp_t *trace_get_icmp(libtrace_packet_t *packet); |
---|
1360 | |
---|
1361 | /** get a pointer to the ICMP header (if any) given a pointer to the IP header |
---|
1362 | * @param ip The IP header |
---|
1363 | * @param[in,out] remaining Updated with the number of bytes remaining |
---|
1364 | * |
---|
1365 | * @return a pointer to the ICMP header, or NULL if this is not an ICMP packet |
---|
1366 | * |
---|
1367 | * Remaining may be NULL. If Remaining is not NULL it must point to the number |
---|
1368 | * of bytes captured of the ICMP header and beyond. It will be decremented by |
---|
1369 | * the length of the ICMP head in bytes. |
---|
1370 | * |
---|
1371 | * @note Beware the change from libtrace2 from skipped to remaining |
---|
1372 | */ |
---|
1373 | DLLEXPORT SIMPLE_FUNCTION |
---|
1374 | libtrace_icmp_t *trace_get_icmp_from_ip(libtrace_ip_t *ip,uint32_t *remaining); |
---|
1375 | |
---|
1376 | /** Get the destination MAC address |
---|
1377 | * @param packet the packet opaque pointer |
---|
1378 | * @return a pointer to the destination mac, (or NULL if there is no |
---|
1379 | * destination MAC) |
---|
1380 | */ |
---|
1381 | DLLEXPORT SIMPLE_FUNCTION |
---|
1382 | uint8_t *trace_get_destination_mac(libtrace_packet_t *packet); |
---|
1383 | |
---|
1384 | /** Get the source MAC address |
---|
1385 | * @param packet the packet opaque pointer |
---|
1386 | * @return a pointer to the source mac, (or NULL if there is no source MAC) |
---|
1387 | */ |
---|
1388 | DLLEXPORT SIMPLE_FUNCTION |
---|
1389 | uint8_t *trace_get_source_mac(libtrace_packet_t *packet); |
---|
1390 | |
---|
1391 | /** Get the source IP address |
---|
1392 | * @param packet the packet opaque pointer |
---|
1393 | * @param addr a pointer to a sockaddr to store the address in, or NULL to use |
---|
1394 | * static storage. |
---|
1395 | * @return NULL if there is no source address, or a sockaddr holding a v4 or v6 |
---|
1396 | * address |
---|
1397 | */ |
---|
1398 | DLLEXPORT SIMPLE_FUNCTION |
---|
1399 | struct sockaddr *trace_get_source_address(const libtrace_packet_t *packet, |
---|
1400 | struct sockaddr *addr); |
---|
1401 | |
---|
1402 | /** Get the destination IP address |
---|
1403 | * @param packet the packet opaque pointer |
---|
1404 | * @param addr a pointer to a sockaddr to store the address in, or NULL to use |
---|
1405 | * static storage. |
---|
1406 | * @return NULL if there is no destination address, or a sockaddr holding a v4 |
---|
1407 | * or v6 address |
---|
1408 | */ |
---|
1409 | DLLEXPORT SIMPLE_FUNCTION |
---|
1410 | struct sockaddr *trace_get_destination_address(const libtrace_packet_t *packet, |
---|
1411 | struct sockaddr *addr); |
---|
1412 | |
---|
1413 | /*@}*/ |
---|
1414 | |
---|
1415 | /** parse an ip or tcp option |
---|
1416 | * @param[in,out] ptr the pointer to the current option |
---|
1417 | * @param[in,out] len the length of the remaining buffer |
---|
1418 | * @param[out] type the type of the option |
---|
1419 | * @param[out] optlen the length of the option |
---|
1420 | * @param[out] data the data of the option |
---|
1421 | * |
---|
1422 | * @return bool true if there is another option (and the fields are filled in) |
---|
1423 | * or false if this was the last option. |
---|
1424 | * |
---|
1425 | * This updates ptr to point to the next option after this one, and updates |
---|
1426 | * len to be the number of bytes remaining in the options area. Type is updated |
---|
1427 | * to be the code of this option, and data points to the data of this option, |
---|
1428 | * with optlen saying how many bytes there are. |
---|
1429 | * |
---|
1430 | * @note Beware of fragmented packets. |
---|
1431 | */ |
---|
1432 | DLLEXPORT int trace_get_next_option(unsigned char **ptr,int *len, |
---|
1433 | unsigned char *type, |
---|
1434 | unsigned char *optlen, |
---|
1435 | unsigned char **data); |
---|
1436 | |
---|
1437 | |
---|
1438 | /** @name Time |
---|
1439 | * These functions deal with time that a packet arrived and return it |
---|
1440 | * in various formats |
---|
1441 | * @{ |
---|
1442 | */ |
---|
1443 | /** Get the current time in DAG time format |
---|
1444 | * @param packet the packet opaque pointer |
---|
1445 | * |
---|
1446 | * @return a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds |
---|
1447 | * past 1970-01-01, the lower 32bits are partial seconds) |
---|
1448 | */ |
---|
1449 | DLLEXPORT SIMPLE_FUNCTION |
---|
1450 | uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet); |
---|
1451 | |
---|
1452 | /** Get the current time in struct timeval |
---|
1453 | * @param packet the packet opaque pointer |
---|
1454 | * |
---|
1455 | * @return time that this packet was seen in a struct timeval |
---|
1456 | */ |
---|
1457 | DLLEXPORT SIMPLE_FUNCTION |
---|
1458 | struct timeval trace_get_timeval(const libtrace_packet_t *packet); |
---|
1459 | |
---|
1460 | /** Get the current time in floating point seconds |
---|
1461 | * @param packet the packet opaque pointer |
---|
1462 | * |
---|
1463 | * @return time that this packet was seen in 64bit floating point seconds from |
---|
1464 | * the unix epoch (1970-01-01 00:00:00 UTC). |
---|
1465 | */ |
---|
1466 | DLLEXPORT SIMPLE_FUNCTION |
---|
1467 | double trace_get_seconds(const libtrace_packet_t *packet); |
---|
1468 | |
---|
1469 | /** Seek within a trace |
---|
1470 | * @param trace trace to seek |
---|
1471 | * @param seconds time to seek to |
---|
1472 | * @return 0 on success. |
---|
1473 | * Make the next packet read to be the first packet to occur at or after the |
---|
1474 | * time searched for. This must be called in the configuration state (ie, |
---|
1475 | * before trace_start() or after trace_pause(). |
---|
1476 | * @note This function may be extremely slow. |
---|
1477 | */ |
---|
1478 | DLLEXPORT int trace_seek_seconds(libtrace_t *trace, double seconds); |
---|
1479 | |
---|
1480 | /** Seek within a trace |
---|
1481 | * @param trace trace to seek |
---|
1482 | * @param tv time to seek to |
---|
1483 | * @return 0 on success. |
---|
1484 | * Make the next packet read to be the first packet to occur at or after the |
---|
1485 | * time searched for. This must be called in the configuration state (ie, |
---|
1486 | * before trace_start() or after trace_pause(). |
---|
1487 | * @note This function may be extremely slow. |
---|
1488 | */ |
---|
1489 | DLLEXPORT int trace_seek_timeval(libtrace_t *trace, struct timeval tv); |
---|
1490 | |
---|
1491 | /** Seek within a trace |
---|
1492 | * @param trace trace to seek |
---|
1493 | * @param ts erf timestamp |
---|
1494 | * @return 0 on success. |
---|
1495 | * Make the next packet read to be the first packet to occur at or after the |
---|
1496 | * time searched for. This must be called in the configuration state (ie, |
---|
1497 | * before trace_start() or after trace_pause(). |
---|
1498 | * @note This function may be extremely slow. |
---|
1499 | */ |
---|
1500 | DLLEXPORT int trace_seek_erf_timestamp(libtrace_t *trace, uint64_t ts); |
---|
1501 | |
---|
1502 | /*@}*/ |
---|
1503 | |
---|
1504 | /** @name Sizes |
---|
1505 | * This section deals with finding or setting the various different lengths |
---|
1506 | * a packet can have |
---|
1507 | * @{ |
---|
1508 | */ |
---|
1509 | /** Get the size of the packet in the trace (in bytes) |
---|
1510 | * @param packet the packet opaque pointer |
---|
1511 | * @return the size of the packet in the trace |
---|
1512 | * @note Due to this being a header capture, or anonymisation, this may not |
---|
1513 | * be the same size as the original packet. See get_wire_length() for the |
---|
1514 | * original size of the packet. |
---|
1515 | * @note This can (and often is) different for different packets in a trace! |
---|
1516 | * @note This is sometimes called the "snaplen". |
---|
1517 | * @note The return size refers to the network-level payload of the packet and |
---|
1518 | * does not include any capture framing headers. For example, an Ethernet |
---|
1519 | * packet with an empty TCP packet will return sizeof(ethernet_header) + |
---|
1520 | * sizeof(ip_header) + sizeof(tcp_header), but not the capture file |
---|
1521 | * (pcap/erf/etc) header. |
---|
1522 | */ |
---|
1523 | DLLEXPORT SIMPLE_FUNCTION |
---|
1524 | size_t trace_get_capture_length(const libtrace_packet_t *packet); |
---|
1525 | |
---|
1526 | /** Get the size of the packet as it was seen on the wire (in bytes). |
---|
1527 | * @param packet the packet opaque pointer |
---|
1528 | * @return the size of the packet as it was on the wire. |
---|
1529 | * @note Due to the trace being a header capture, or anonymisation this may |
---|
1530 | * not be the same as the Capture Len. |
---|
1531 | * @note trace_getwire_length \em{includes} FCS. |
---|
1532 | * @note The return size refers to the network-level payload of the packet and |
---|
1533 | * does not include any capture framing headers. For example, an Ethernet |
---|
1534 | * packet with an empty TCP packet will return sizeof(ethernet_header) + |
---|
1535 | * sizeof(ip_header) + sizeof(tcp_header), but not the capture file |
---|
1536 | * (pcap/erf/etc) header. |
---|
1537 | */ |
---|
1538 | DLLEXPORT SIMPLE_FUNCTION |
---|
1539 | size_t trace_get_wire_length(const libtrace_packet_t *packet); |
---|
1540 | |
---|
1541 | /** Get the length of the capture framing headers (in bytes). |
---|
1542 | * @param packet the packet opaque pointer |
---|
1543 | * @return the size of the packet as it was on the wire. |
---|
1544 | * @note this length corresponds to the difference between the size of a |
---|
1545 | * captured packet in memory, and the captured length of the packet |
---|
1546 | */ |
---|
1547 | DLLEXPORT SIMPLE_FUNCTION |
---|
1548 | size_t trace_get_framing_length(const libtrace_packet_t *packet); |
---|
1549 | |
---|
1550 | /** Truncate ("snap") the packet at the suggested length |
---|
1551 | * @param packet the packet opaque pointer |
---|
1552 | * @param size the new length of the packet (in bytes) |
---|
1553 | * @return the new capture length of the packet, or the original capture |
---|
1554 | * length of the packet if unchanged |
---|
1555 | */ |
---|
1556 | DLLEXPORT size_t trace_set_capture_length(libtrace_packet_t *packet, size_t size); |
---|
1557 | |
---|
1558 | /*@}*/ |
---|
1559 | |
---|
1560 | |
---|
1561 | /** Get the type of the link layer |
---|
1562 | * @param packet the packet opaque pointer |
---|
1563 | * @return libtrace_linktype_t |
---|
1564 | */ |
---|
1565 | DLLEXPORT SIMPLE_FUNCTION |
---|
1566 | libtrace_linktype_t trace_get_link_type(const libtrace_packet_t *packet); |
---|
1567 | |
---|
1568 | /** Set the direction flag, if it has one |
---|
1569 | * @param packet the packet opaque pointer |
---|
1570 | * @param direction the new direction |
---|
1571 | * @returns -1 on error, or the direction that was set. |
---|
1572 | */ |
---|
1573 | DLLEXPORT libtrace_direction_t trace_set_direction(libtrace_packet_t *packet, libtrace_direction_t direction); |
---|
1574 | |
---|
1575 | /** Get the direction flag, if it has one |
---|
1576 | * @param packet the packet opaque pointer |
---|
1577 | * @return a value containing the direction flag, or -1 if this is not supported |
---|
1578 | * The direction is defined as 0 for packets originating locally (ie, outbound) |
---|
1579 | * and 1 for packets originating remotely (ie, inbound). |
---|
1580 | * Other values are possible, which might be overloaded to mean special things |
---|
1581 | * for a special trace. |
---|
1582 | */ |
---|
1583 | DLLEXPORT SIMPLE_FUNCTION |
---|
1584 | libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet); |
---|
1585 | |
---|
1586 | /** @name BPF |
---|
1587 | * This section deals with using Berkley Packet Filters |
---|
1588 | * @{ |
---|
1589 | */ |
---|
1590 | /** setup a BPF filter |
---|
1591 | * @param filterstring a char * containing the bpf filter string |
---|
1592 | * @return opaque pointer pointer to a libtrace_filter_t object |
---|
1593 | * @note The filter is not actually compiled at this point, so no correctness |
---|
1594 | * tests are performed here. trace_create_filter will always return ok, but |
---|
1595 | * if the filter is poorly constructed an error will be generated when the |
---|
1596 | * filter is actually used |
---|
1597 | */ |
---|
1598 | DLLEXPORT SIMPLE_FUNCTION |
---|
1599 | libtrace_filter_t *trace_create_filter(const char *filterstring); |
---|
1600 | |
---|
1601 | /** Setup a BPF filter based on pre-compiled byte-code. |
---|
1602 | * @param bf_insns A pointer to the start of the byte-code |
---|
1603 | * @param bf_len The number of BPF instructions |
---|
1604 | * @returns an opaque pointer to a libtrace_filter_t object |
---|
1605 | * @note The supplied byte-code is not checked for correctness. |
---|
1606 | * @author Scott Raynel |
---|
1607 | */ |
---|
1608 | DLLEXPORT libtrace_filter_t * |
---|
1609 | trace_create_filter_from_bytecode(void *bf_insns, unsigned int bf_len); |
---|
1610 | |
---|
1611 | /** Apply a BPF filter to a packet |
---|
1612 | * @param filter the filter opaque pointer |
---|
1613 | * @param packet the packet opaque pointer |
---|
1614 | * @return >0 if the filter matches, 0 if it doesn't, -1 on error. |
---|
1615 | * @note Due to the way BPF filters are built, the filter is not actually |
---|
1616 | * compiled until the first time trace_create_filter is called. If your filter |
---|
1617 | * is incorrect, it will generate an error message and assert, exiting the |
---|
1618 | * program. This behaviour may change to more graceful handling of this error |
---|
1619 | * in the future. |
---|
1620 | */ |
---|
1621 | DLLEXPORT int trace_apply_filter(libtrace_filter_t *filter, |
---|
1622 | const libtrace_packet_t *packet); |
---|
1623 | |
---|
1624 | /** Destroy a BPF filter |
---|
1625 | * @param filter the filter opaque pointer |
---|
1626 | * Deallocate all the resources associated with a BPF filter |
---|
1627 | */ |
---|
1628 | DLLEXPORT void trace_destroy_filter(libtrace_filter_t *filter); |
---|
1629 | /*@}*/ |
---|
1630 | |
---|
1631 | /** @name Portability |
---|
1632 | * This section has functions that causes annoyances to portability for one |
---|
1633 | * reason or another. |
---|
1634 | * @{ |
---|
1635 | */ |
---|
1636 | |
---|
1637 | /** Convert an ethernet address to a string |
---|
1638 | * @param addr Ethernet address in network byte order |
---|
1639 | * @param buf Buffer to store the ascii representation, or NULL |
---|
1640 | * @return buf, or if buf is NULL then a statically allocated buffer. |
---|
1641 | * |
---|
1642 | * This function is similar to the GNU ether_ntoa_r function, with a few |
---|
1643 | * minor differences. if NULL is passed as buf, then the function will |
---|
1644 | * use an internal static buffer, if NULL isn't passed then the function |
---|
1645 | * will use that buffer instead. |
---|
1646 | * |
---|
1647 | * @note the type of addr isn't struct ether_addr as it is with ether_ntoa_r, |
---|
1648 | * however it is bit compatible so that a cast will work. |
---|
1649 | */ |
---|
1650 | DLLEXPORT char *trace_ether_ntoa(const uint8_t *addr, char *buf); |
---|
1651 | |
---|
1652 | /** Convert a string to an ethernet address |
---|
1653 | * @param buf Ethernet address in hex format delimited with :'s. |
---|
1654 | * @param addr buffer to store the binary representation, or NULL |
---|
1655 | * @return addr, or if addr is NULL, then a statically allocated buffer. |
---|
1656 | * |
---|
1657 | * This function is similar to the GNU ether_aton_r function, with a few |
---|
1658 | * minor differences. if NULL is passed as addr, then the function will |
---|
1659 | * use an internal static buffer, if NULL isn't passed then the function will |
---|
1660 | * use that buffer instead. |
---|
1661 | * |
---|
1662 | * @note the type of addr isn't struct ether_addr as it is with ether_aton_r, |
---|
1663 | * however it is bit compatible so that a cast will work. |
---|
1664 | */ |
---|
1665 | DLLEXPORT uint8_t *trace_ether_aton(const char *buf, uint8_t *addr); |
---|
1666 | |
---|
1667 | /*@}*/ |
---|
1668 | |
---|
1669 | |
---|
1670 | /** Which port is the server port */ |
---|
1671 | typedef enum { |
---|
1672 | USE_DEST, /**< Destination port is the server port */ |
---|
1673 | USE_SOURCE /**< Source port is the server port */ |
---|
1674 | } serverport_t; |
---|
1675 | |
---|
1676 | /** Get the source port |
---|
1677 | * @param packet the packet to read from |
---|
1678 | * @return a port in \em HOST byte order, or equivalent to ports for this |
---|
1679 | * protocol, or 0 if this protocol has no ports. |
---|
1680 | */ |
---|
1681 | DLLEXPORT SIMPLE_FUNCTION |
---|
1682 | uint16_t trace_get_source_port(const libtrace_packet_t *packet); |
---|
1683 | |
---|
1684 | /** Get the destination port |
---|
1685 | * @param packet the packet to read from |
---|
1686 | * @return a port in \em HOST byte order, or equivilent to ports for this |
---|
1687 | * protocol, or 0 if this protocol has no ports. |
---|
1688 | */ |
---|
1689 | DLLEXPORT SIMPLE_FUNCTION |
---|
1690 | uint16_t trace_get_destination_port(const libtrace_packet_t *packet); |
---|
1691 | |
---|
1692 | /** hint at the server port in specified protocol |
---|
1693 | * @param protocol the IP layer protocol, eg 6 (tcp), 17 (udp) |
---|
1694 | * @param source the source port from the packet |
---|
1695 | * @param dest the destination port from the packet |
---|
1696 | * @return one of USE_SOURCE or USE_DEST depending on which one you should use |
---|
1697 | * @note ports must be in \em HOST byte order! |
---|
1698 | */ |
---|
1699 | DLLEXPORT SIMPLE_FUNCTION |
---|
1700 | int8_t trace_get_server_port(uint8_t protocol, uint16_t source, uint16_t dest); |
---|
1701 | |
---|
1702 | /** Takes a uri and splits it into a format and uridata component. |
---|
1703 | * @param uri the uri to be parsed |
---|
1704 | * @param format destination location for the format component of the uri |
---|
1705 | * @return 0 if an error occured, otherwise return the uridata component |
---|
1706 | */ |
---|
1707 | DLLEXPORT const char *trace_parse_uri(const char *uri, char **format); |
---|
1708 | |
---|
1709 | /** Gets the format type for a given packet. |
---|
1710 | * @param packet the packet opaque pointer |
---|
1711 | * @return the format of the packet |
---|
1712 | */ |
---|
1713 | DLLEXPORT |
---|
1714 | enum base_format_t trace_get_format(struct libtrace_packet_t *packet); |
---|
1715 | |
---|
1716 | /** Construct a packet from a buffer. |
---|
1717 | * @param packet[in,out] Libtrace Packet object to update with the new |
---|
1718 | * data. |
---|
1719 | * @param linktype The linktype of the packet. |
---|
1720 | * @param[in] data The packet data (including linklayer) |
---|
1721 | * @param len Length of packet data |
---|
1722 | */ |
---|
1723 | DLLEXPORT |
---|
1724 | void trace_construct_packet(libtrace_packet_t *packet, |
---|
1725 | libtrace_linktype_t linktype, const void *data, uint16_t len); |
---|
1726 | |
---|
1727 | /*@}*/ |
---|
1728 | |
---|
1729 | /** @name Wireless trace support |
---|
1730 | * Functions to access wireless information from packets that have wireless |
---|
1731 | * monitoring headers such as Radiotap or Prism. |
---|
1732 | * |
---|
1733 | * The trace_get_wireless_* functions provide an abstract interface for |
---|
1734 | * retrieving information from wireless traces. They take a pointer to the |
---|
1735 | * wireless monitoring header (usually found with trace_get_link(packet)) and |
---|
1736 | * the linktype of the header passed in. |
---|
1737 | * |
---|
1738 | * All of the trace_get_wireless_* functions return false if the requested |
---|
1739 | * information was unavailable, or true if it was. The actual data is stored |
---|
1740 | * in an output variable supplied by the caller. Values returned into the |
---|
1741 | * output variable will always be returned in host byte order. |
---|
1742 | * @{ |
---|
1743 | */ |
---|
1744 | |
---|
1745 | |
---|
1746 | #ifndef ARPHRD_80211_RADIOTAP |
---|
1747 | /* libc doesn't define this yet, but it seems to be what everyone is using |
---|
1748 | */ |
---|
1749 | #define ARPHRD_80211_RADIOTAP 803 |
---|
1750 | #endif |
---|
1751 | |
---|
1752 | /** Get the wireless Timer Syncronisation Function |
---|
1753 | * |
---|
1754 | * Gets the value of the timer syncronisation function for this frame, which |
---|
1755 | * is a value in microseconds indicating the time that the first bit of the |
---|
1756 | * MPDU was received by the MAC. |
---|
1757 | * |
---|
1758 | * @param link the wireless header |
---|
1759 | * @param linktype the linktype of the wireless header passed in |
---|
1760 | * @param[out] tsft the value of the timer syncronisation function. |
---|
1761 | * @return true if the field was available, false if not. |
---|
1762 | */ |
---|
1763 | DLLEXPORT bool trace_get_wireless_tsft(void *linkptr, |
---|
1764 | libtrace_linktype_t linktype, uint64_t *tsft); |
---|
1765 | |
---|
1766 | /** Get the wireless rate |
---|
1767 | * @param link the wireless header |
---|
1768 | * @param linktype the linktype of the wireless header passed in |
---|
1769 | * @param[out] rate the data-rate of the frame in units of 500kbps |
---|
1770 | * @return true if the field was available, false if not. |
---|
1771 | */ |
---|
1772 | DLLEXPORT bool trace_get_wireless_rate(void *linkptr, |
---|
1773 | libtrace_linktype_t linktype, uint8_t *rate); |
---|
1774 | |
---|
1775 | /** Get the wireless channel frequency |
---|
1776 | * @param link the wireless header |
---|
1777 | * @param linktype the linktype of the wireless header passed in |
---|
1778 | * @param[out] freq the frequency in MHz of the channel the frame was transmitted |
---|
1779 | * or received on. |
---|
1780 | * @return true if the field was available, false if not. |
---|
1781 | */ |
---|
1782 | DLLEXPORT bool trace_get_wireless_freq(void *linkptr, |
---|
1783 | libtrace_linktype_t linktype, uint16_t *freq); |
---|
1784 | |
---|
1785 | /** Get the wireless signal strength in dBm |
---|
1786 | * @param link the wireless header |
---|
1787 | * @param linktype the linktype of the wireless header passed in |
---|
1788 | * @param[out] strength the RF signal power at the antenna, in dB difference |
---|
1789 | * from 1mW. |
---|
1790 | * @return true if the field was available, false if not. |
---|
1791 | */ |
---|
1792 | DLLEXPORT bool trace_get_wireless_signal_strength_dbm(void *linkptr, |
---|
1793 | libtrace_linktype_t linktype, int8_t *strength); |
---|
1794 | |
---|
1795 | /** Get the wireless noise strength in dBm |
---|
1796 | * @param link the wireless header |
---|
1797 | * @param linktype the linktype of the wireless header passed in |
---|
1798 | * @param[out] strength the RF noise power at the antenna, in dB difference |
---|
1799 | * from 1mW. |
---|
1800 | * @return true if the field was available, false if not. |
---|
1801 | */ |
---|
1802 | DLLEXPORT bool trace_get_wireless_noise_strength_dbm(void *linkptr, |
---|
1803 | libtrace_linktype_t linktype, int8_t *strength); |
---|
1804 | |
---|
1805 | /** Get the wireless signal strength in dB |
---|
1806 | * @param link the wireless header |
---|
1807 | * @param linktype the linktype of the wireless header passed in |
---|
1808 | * @param[out] strength the RF signal power at the antenna,in dB difference |
---|
1809 | * from a fixed reference. |
---|
1810 | * @return true if the field was available, false if not. |
---|
1811 | */ |
---|
1812 | DLLEXPORT bool trace_get_wireless_signal_strength_db(void *linkptr, |
---|
1813 | libtrace_linktype_t linktype, uint8_t *strength); |
---|
1814 | |
---|
1815 | /** Get the wireless noise strength in dB |
---|
1816 | * @param link the wireless header |
---|
1817 | * @param linktype the linktype of the wireless header passed in |
---|
1818 | * @param[out] strength the RF noise power at the antenna, in dB difference |
---|
1819 | * from a fixed reference. |
---|
1820 | * @return true if the field was available, false if not. |
---|
1821 | */ |
---|
1822 | DLLEXPORT bool trace_get_wireless_noise_strength_db(void *linkptr, |
---|
1823 | libtrace_linktype_t linktype, uint8_t *strength); |
---|
1824 | |
---|
1825 | /** Get the wireless transmit attenuation |
---|
1826 | * @param link the wireless header |
---|
1827 | * @param linktype the linktype of the wireless header passed in |
---|
1828 | * @param[out] attenuation the transmit power as a unitless distance from maximum |
---|
1829 | * power set at factory calibration. 0 indicates maximum transmission power. |
---|
1830 | * @return true if the field was available, false if not. |
---|
1831 | */ |
---|
1832 | DLLEXPORT bool trace_get_wireless_tx_attenuation(void *linkptr, |
---|
1833 | libtrace_linktype_t linktype, uint16_t *attenuation); |
---|
1834 | |
---|
1835 | /** Get the wireless transmit attenuation in dB |
---|
1836 | * @param link the wireless header |
---|
1837 | * @param linktype the linktype of the wireless header passed in |
---|
1838 | * @param[out] attenuation the transmit power as dB difference from maximum power |
---|
1839 | * set at factory calibration. 0 indicates maximum power. |
---|
1840 | * @return true if the field was available, false if not. |
---|
1841 | */ |
---|
1842 | DLLEXPORT bool trace_get_wireless_tx_attenuation_db(void *linkptr, |
---|
1843 | libtrace_linktype_t linktype, uint16_t *attenuation); |
---|
1844 | |
---|
1845 | /** Get the wireless transmit power in dBm @param link the wireless header |
---|
1846 | * @param linktype the linktype of the wireless header passed in |
---|
1847 | * @param[out] txpower the transmit power as dB from a 1mW reference. This is the absolute power level measured at the antenna port. |
---|
1848 | * @return true if the field was available, false if not. |
---|
1849 | */ |
---|
1850 | DLLEXPORT bool trace_get_wireless_tx_power_dbm(void *linkptr, libtrace_linktype_t |
---|
1851 | linktype, int8_t *txpower); |
---|
1852 | |
---|
1853 | /** Get the wireless antenna |
---|
1854 | * @param link the wireless header |
---|
1855 | * @param linktype the linktype of the wireless header passed in |
---|
1856 | * @param[out] antenna which antenna was used to transmit or receive the frame. |
---|
1857 | * @return true if the field was available, false if not. |
---|
1858 | */ |
---|
1859 | DLLEXPORT bool trace_get_wireless_antenna(void *linkptr, |
---|
1860 | libtrace_linktype_t linktype, uint8_t *antenna); |
---|
1861 | |
---|
1862 | /*@}*/ |
---|
1863 | |
---|
1864 | #ifdef __cplusplus |
---|
1865 | } /* extern "C" */ |
---|
1866 | #endif /* #ifdef __cplusplus */ |
---|
1867 | #endif /* LIBTRACE_H_ */ |
---|