1 | /* |
---|
2 | * This file is part of libtrace |
---|
3 | * |
---|
4 | * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton, |
---|
5 | * New Zealand. |
---|
6 | * |
---|
7 | * Authors: Daniel Lawson |
---|
8 | * Perry Lorier |
---|
9 | * Shane Alcock |
---|
10 | * |
---|
11 | * All rights reserved. |
---|
12 | * |
---|
13 | * This code has been developed by the University of Waikato WAND |
---|
14 | * research group. For further information please see http://www.wand.net.nz/ |
---|
15 | * |
---|
16 | * libtrace is free software; you can redistribute it and/or modify |
---|
17 | * it under the terms of the GNU General Public License as published by |
---|
18 | * the Free Software Foundation; either version 2 of the License, or |
---|
19 | * (at your option) any later version. |
---|
20 | * |
---|
21 | * libtrace is distributed in the hope that it will be useful, |
---|
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
24 | * GNU General Public License for more details. |
---|
25 | * |
---|
26 | * You should have received a copy of the GNU General Public License |
---|
27 | * along with libtrace; if not, write to the Free Software |
---|
28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
29 | * |
---|
30 | * $Id$ |
---|
31 | * |
---|
32 | */ |
---|
33 | |
---|
34 | #ifndef LIBTRACE_H |
---|
35 | #define LIBTRACE_H |
---|
36 | |
---|
37 | /** @file |
---|
38 | * |
---|
39 | * @brief Trace file processing library header |
---|
40 | * |
---|
41 | * @author Daniel Lawson |
---|
42 | * @author Perry Lorier |
---|
43 | * @author Shane Alcock |
---|
44 | * |
---|
45 | * @version $Id$ |
---|
46 | * |
---|
47 | * This library provides a per packet interface into a trace file, or a live |
---|
48 | * captures. It supports ERF, DAG cards, PCAP, Linux and BSD native sockets, |
---|
49 | * legacy ERF formats etc. |
---|
50 | * |
---|
51 | * @par Usage |
---|
52 | * See the example/ directory in the source distribution for some simple |
---|
53 | * examples |
---|
54 | * |
---|
55 | * @par Linking |
---|
56 | * To use this library you need to link against libtrace by passing -ltrace |
---|
57 | * to your linker. You may also need to link against a version of libpcap |
---|
58 | * and of zlib which are compiled for largefile support (if you wish to access |
---|
59 | * traces larger than 2 GB). This is left as an exercise for the reader. Debian |
---|
60 | * Woody, at least, does not support large file offsets. |
---|
61 | * |
---|
62 | */ |
---|
63 | |
---|
64 | #include <sys/types.h> |
---|
65 | #ifndef WIN32 |
---|
66 | #include <sys/time.h> |
---|
67 | #endif |
---|
68 | |
---|
69 | #ifdef _MSC_VER |
---|
70 | /* define the following from MSVC's internal types */ |
---|
71 | typedef __int8 int8_t; |
---|
72 | typedef __int16 int16_t; |
---|
73 | typedef __int32 int32_t; |
---|
74 | typedef __int64 int64_t; |
---|
75 | typedef unsigned __int8 uint8_t; |
---|
76 | typedef unsigned __int16 uint16_t; |
---|
77 | typedef unsigned __int32 uint32_t; |
---|
78 | typedef unsigned __int64 uint64_t; |
---|
79 | #ifdef LT_BUILDING_DLL |
---|
80 | #define DLLEXPORT __declspec(dllexport) |
---|
81 | #else |
---|
82 | #define DLLEXPORT __declspec(dllimport) |
---|
83 | #endif |
---|
84 | #define DLLLOCAL |
---|
85 | /* Windows pads bitfields out to to the size of their parent type |
---|
86 | * however gcc warns that this doesn't meet with the iso C specification |
---|
87 | * so produces warnings for this behaviour. sigh. |
---|
88 | */ |
---|
89 | #define LT_BITFIELD8 uint8_t |
---|
90 | #define LT_BITFIELD16 uint16_t |
---|
91 | #define LT_BITFIELD32 uint32_t |
---|
92 | #define LT_BITFIELD64 uint64_t |
---|
93 | #else |
---|
94 | #ifdef HAVE_STDINT_H |
---|
95 | # include <stdint.h> |
---|
96 | #endif |
---|
97 | #if __GNUC__ >= 4 |
---|
98 | #ifdef LT_BUILDING_DLL |
---|
99 | #define DLLEXPORT __attribute__ ((visibility("default"))) |
---|
100 | #define DLLLOCAL __attribute__ ((visibility("hidden"))) |
---|
101 | #else |
---|
102 | #define DLLEXPORT |
---|
103 | #define DLLLOCAL |
---|
104 | #endif |
---|
105 | #else |
---|
106 | #define DLLEXPORT |
---|
107 | #define DLLLOCAL |
---|
108 | #endif |
---|
109 | /* GCC warns if the bitfield type is not "unsigned int", however windows |
---|
110 | * generates incorrect code for this (see above), so we define these |
---|
111 | * macros. How Hideous. So much for C's portability. |
---|
112 | */ |
---|
113 | #define LT_BITFIELD8 unsigned int |
---|
114 | #define LT_BITFIELD16 unsigned int |
---|
115 | #define LT_BITFIELD32 unsigned int |
---|
116 | #define LT_BITFIELD64 unsigned int |
---|
117 | #endif |
---|
118 | |
---|
119 | #ifdef WIN32 |
---|
120 | # include <winsock2.h> |
---|
121 | # include <ws2tcpip.h> |
---|
122 | typedef short sa_family_t; |
---|
123 | /* Make up for a lack of stdbool.h */ |
---|
124 | # define bool signed char |
---|
125 | # define false 0 |
---|
126 | # define true 1 |
---|
127 | # if !defined(ssize_t) |
---|
128 | /* XXX: Not 64-bit safe! */ |
---|
129 | # define ssize_t int |
---|
130 | # endif |
---|
131 | #else |
---|
132 | # include <netinet/in.h> |
---|
133 | |
---|
134 | #ifndef __cplusplus |
---|
135 | # include <stdbool.h> |
---|
136 | #endif |
---|
137 | |
---|
138 | # include <sys/types.h> |
---|
139 | # include <sys/socket.h> |
---|
140 | #endif |
---|
141 | |
---|
142 | /** API version as 2 byte hex digits, eg 0xXXYYZZ */ |
---|
143 | #define LIBTRACE_API_VERSION \ |
---|
144 | ((@LIBTRACE_MAJOR@<<16)|(@LIBTRACE_MID@<<8)|(@LIBTRACE_MINOR@)) |
---|
145 | |
---|
146 | /** Replaced with the current SVN revision number when 'make dist' is invoked |
---|
147 | * to create a distributable tarball */ |
---|
148 | #define LIBTRACE_SVN_REVISION 0 |
---|
149 | |
---|
150 | /** DAG driver version installed on the current system */ |
---|
151 | #define DAG_DRIVER_V "@DAG_VERSION_NUM@" |
---|
152 | |
---|
153 | #ifdef __cplusplus |
---|
154 | extern "C" { |
---|
155 | #endif |
---|
156 | |
---|
157 | /* Function does not depend on anything but its |
---|
158 | * parameters, used to hint gcc's optimisations |
---|
159 | */ |
---|
160 | #if __GNUC__ >= 3 |
---|
161 | # define DEPRECATED __attribute__((deprecated)) |
---|
162 | # define SIMPLE_FUNCTION __attribute__((pure)) |
---|
163 | # define UNUSED __attribute__((unused)) |
---|
164 | # define PACKED __attribute__((packed)) |
---|
165 | # define PRINTF(formatpos,argpos) __attribute__((format(printf,formatpos,argpos))) |
---|
166 | #else |
---|
167 | # define DEPRECATED |
---|
168 | # define SIMPLE_FUNCTION |
---|
169 | # define UNUSED |
---|
170 | # define PACKED |
---|
171 | # define PRINTF(formatpos,argpos) |
---|
172 | #endif |
---|
173 | |
---|
174 | /** Opaque structure holding information about an output trace */ |
---|
175 | typedef struct libtrace_out_t libtrace_out_t; |
---|
176 | |
---|
177 | /** Opaque structure holding information about a trace */ |
---|
178 | typedef struct libtrace_t libtrace_t; |
---|
179 | |
---|
180 | /** Opaque structure holding information about a bpf filter */ |
---|
181 | typedef struct libtrace_filter_t libtrace_filter_t; |
---|
182 | |
---|
183 | /** If the packet has allocated its own memory the buffer_control should be |
---|
184 | * set to TRACE_CTRL_PACKET, so that the memory will be freed when the packet |
---|
185 | * is destroyed. If the packet has been zerocopied out of memory owned by |
---|
186 | * something else, e.g. a DAG card, it should be TRACE_CTRL_EXTERNAL. |
---|
187 | * |
---|
188 | * @note The letters p and e are magic numbers used to detect if the packet |
---|
189 | * wasn't created properly. |
---|
190 | */ |
---|
191 | typedef enum { |
---|
192 | TRACE_CTRL_PACKET='p', /**< Buffer memory is owned by the packet */ |
---|
193 | TRACE_CTRL_EXTERNAL='e' /**< Buffer memory is owned by an external source */ |
---|
194 | } buf_control_t; |
---|
195 | |
---|
196 | /** The size of a packet's buffer when managed by libtrace */ |
---|
197 | #define LIBTRACE_PACKET_BUFSIZE 65536 |
---|
198 | |
---|
199 | /** Libtrace error information */ |
---|
200 | typedef struct trace_err_t{ |
---|
201 | int err_num; /**< error code */ |
---|
202 | char problem[255]; /**< the format, uri etc that caused the error for reporting purposes */ |
---|
203 | } libtrace_err_t; |
---|
204 | |
---|
205 | /** Enumeration of error codes */ |
---|
206 | enum { |
---|
207 | /** No Error has occured.... yet. */ |
---|
208 | TRACE_ERR_NOERROR = 0, |
---|
209 | /** The URI passed to trace_create() is unsupported, or badly formed */ |
---|
210 | TRACE_ERR_BAD_FORMAT = -1, |
---|
211 | /** The trace failed to initialise */ |
---|
212 | TRACE_ERR_INIT_FAILED = -2, |
---|
213 | /** Unknown config option */ |
---|
214 | TRACE_ERR_UNKNOWN_OPTION= -3, |
---|
215 | /** This output uri cannot write packets of this type */ |
---|
216 | TRACE_ERR_NO_CONVERSION = -4, |
---|
217 | /** This packet is corrupt, or unusable for the action required */ |
---|
218 | TRACE_ERR_BAD_PACKET = -5, |
---|
219 | /** Option known, but unsupported by this format */ |
---|
220 | TRACE_ERR_OPTION_UNAVAIL= -6, |
---|
221 | /** This feature is unsupported */ |
---|
222 | TRACE_ERR_UNSUPPORTED = -7, |
---|
223 | /** Illegal use of the API */ |
---|
224 | TRACE_ERR_BAD_STATE = -8, |
---|
225 | /** Failed to compile a BPF filter */ |
---|
226 | TRACE_ERR_BAD_FILTER = -9, |
---|
227 | /** RT communication breakdown */ |
---|
228 | TRACE_ERR_RT_FAILURE = -10, |
---|
229 | /** Compression format unsupported */ |
---|
230 | TRACE_ERR_UNSUPPORTED_COMPRESS = -11 |
---|
231 | }; |
---|
232 | |
---|
233 | /** Enumeration of DLTs supported by libtrace |
---|
234 | */ |
---|
235 | typedef enum { |
---|
236 | /** pcap documents this as having the Address Family value in host byte order as the |
---|
237 | * framing. Ugly? Yes. |
---|
238 | */ |
---|
239 | TRACE_DLT_NULL = 0, |
---|
240 | TRACE_DLT_EN10MB = 1, |
---|
241 | TRACE_DLT_PPP = 9, |
---|
242 | TRACE_DLT_ATM_RFC1483 = 11, |
---|
243 | |
---|
244 | /** Ok, so OpenBSD has a different value for DLT_RAW as the rest of the planet, so detect |
---|
245 | * this. When reading to/from files we should be using TRACE_DLT_LINKTYPE_RAW instead. |
---|
246 | * When talking about DLT's inside libtrace tho, we should be using /these/ DLT's. |
---|
247 | */ |
---|
248 | #ifdef __OpenBSD__ |
---|
249 | TRACE_DLT_RAW = 14, |
---|
250 | #else |
---|
251 | TRACE_DLT_RAW = 12, |
---|
252 | #endif |
---|
253 | TRACE_DLT_PPP_SERIAL = 50, |
---|
254 | TRACE_DLT_LINKTYPE_RAW = 101, /**< See TRACE_DLT_RAW for explainations of pain. */ |
---|
255 | TRACE_DLT_C_HDLC = 104, |
---|
256 | TRACE_DLT_IEEE802_11 = 105, |
---|
257 | TRACE_DLT_OPENBSD_LOOP = 108, |
---|
258 | TRACE_DLT_LINUX_SLL = 113, |
---|
259 | TRACE_DLT_PFLOG = 117, |
---|
260 | TRACE_DLT_IEEE802_11_RADIO = 127 /**< Radiotap */ |
---|
261 | } libtrace_dlt_t ; |
---|
262 | |
---|
263 | /** Enumeration of link layer types supported by libtrace */ |
---|
264 | typedef enum { |
---|
265 | /* TRACE_TYPE_LEGACY = 0 Obsolete */ |
---|
266 | TRACE_TYPE_HDLC_POS = 1, /**< HDLC over POS */ |
---|
267 | TRACE_TYPE_ETH = 2, /**< 802.3 style Ethernet */ |
---|
268 | TRACE_TYPE_ATM = 3, /**< ATM frame */ |
---|
269 | TRACE_TYPE_80211 = 4, /**< 802.11 frames */ |
---|
270 | TRACE_TYPE_NONE = 5, /**< Raw IP frames */ |
---|
271 | TRACE_TYPE_LINUX_SLL = 6, /**< Linux "null" framing */ |
---|
272 | TRACE_TYPE_PFLOG = 7, /**< FreeBSD's PFlog */ |
---|
273 | /* TRACE_TYPE_LEGACY_DEFAULT Obsolete */ |
---|
274 | TRACE_TYPE_POS = 9, /**< Packet-over-SONET */ |
---|
275 | /* TRACE_TYPE_LEGACY_ATM Obsolete */ |
---|
276 | /* TRACE_TYPE_LEGACY_ETH Obsolete */ |
---|
277 | TRACE_TYPE_80211_PRISM = 12, /**< 802.11 Prism frames */ |
---|
278 | TRACE_TYPE_AAL5 = 13, /**< ATM Adaptation Layer 5 frames */ |
---|
279 | TRACE_TYPE_DUCK = 14, /**< Pseudo link layer for DUCK packets */ |
---|
280 | TRACE_TYPE_80211_RADIO = 15, /**< Radiotap + 802.11 */ |
---|
281 | TRACE_TYPE_LLCSNAP = 16, /**< Raw LLC/SNAP */ |
---|
282 | TRACE_TYPE_PPP = 17, /**< PPP frames */ |
---|
283 | TRACE_TYPE_METADATA = 18, /**< WDCAP-style meta-data */ |
---|
284 | TRACE_TYPE_NONDATA = 19, /**< Not a data packet */ |
---|
285 | TRACE_TYPE_OPENBSD_LOOP = 20 /**< OpenBSD loopback */ |
---|
286 | } libtrace_linktype_t; |
---|
287 | |
---|
288 | /** RT protocol base format identifiers. |
---|
289 | * This is used to describe the capture format of the packet is being sent |
---|
290 | * using the RT protocol. |
---|
291 | */ |
---|
292 | enum base_format_t { |
---|
293 | TRACE_FORMAT_ERF =1, /**< ERF (DAG capture format) */ |
---|
294 | TRACE_FORMAT_PCAP =2, /**< Live PCAP capture */ |
---|
295 | TRACE_FORMAT_PCAPFILE =3, /**< PCAP trace file */ |
---|
296 | TRACE_FORMAT_WAG =4, /**< WAG live capture (Obsolete) */ |
---|
297 | TRACE_FORMAT_RT =5, /**< RT network protocol */ |
---|
298 | TRACE_FORMAT_LEGACY_ATM =6, /**< Legacy ERF for ATM capture */ |
---|
299 | TRACE_FORMAT_LEGACY_POS =7, /**< Legacy ERF for POS capture */ |
---|
300 | TRACE_FORMAT_LEGACY_ETH =8, /**< Legacy ERF for ETH capture */ |
---|
301 | TRACE_FORMAT_LINUX_NATIVE =9, /**< Linux native interface capture */ |
---|
302 | TRACE_FORMAT_DUCK =10, /**< DAG Clock information */ |
---|
303 | TRACE_FORMAT_BPF =11, /**< BSD native interface capture */ |
---|
304 | TRACE_FORMAT_TSH =12, /**< TSH trace format */ |
---|
305 | TRACE_FORMAT_ATMHDR =13, /**< Legacy ATM header capture */ |
---|
306 | TRACE_FORMAT_LEGACY_NZIX =14, /**< Legacy format used for NZIX traces */ |
---|
307 | TRACE_FORMAT_LINUX_RING =15 /**< Linux native interface capture PACKET_MMAP */ |
---|
308 | }; |
---|
309 | |
---|
310 | /** RT protocol packet types */ |
---|
311 | typedef enum { |
---|
312 | TRACE_RT_HELLO =1, /**< Connection accepted */ |
---|
313 | TRACE_RT_START =2, /**< Request for data transmission to begin |
---|
314 | */ |
---|
315 | TRACE_RT_ACK =3, /**< Data acknowledgement */ |
---|
316 | TRACE_RT_STATUS =4, /**< Fifo status packet */ |
---|
317 | TRACE_RT_DUCK =5, /**< Dag duck info packet */ |
---|
318 | TRACE_RT_END_DATA =6, /**< Server is exiting message */ |
---|
319 | TRACE_RT_CLOSE =7, /**< Client is exiting message */ |
---|
320 | TRACE_RT_DENY_CONN =8, /**< Connection has been denied */ |
---|
321 | TRACE_RT_PAUSE =9, /**< Request server to suspend sending data |
---|
322 | */ |
---|
323 | TRACE_RT_PAUSE_ACK =10,/**< Server is paused message */ |
---|
324 | TRACE_RT_OPTION =11,/**< Option request */ |
---|
325 | TRACE_RT_KEYCHANGE =12,/**< Anonymisation key has changed */ |
---|
326 | TRACE_RT_DUCK_2_4 =13,/**< Dag 2.4 Duck */ |
---|
327 | TRACE_RT_DUCK_2_5 =14,/**< Dag 2.5 Duck */ |
---|
328 | TRACE_RT_LOSTCONN =15,/**< Lost connection to server */ |
---|
329 | TRACE_RT_SERVERSTART =16,/**< Reliable server has been restarted */ |
---|
330 | TRACE_RT_CLIENTDROP =17,/**< Reliable client was lost */ |
---|
331 | TRACE_RT_METADATA =18,/**< Packet contains server meta-data */ |
---|
332 | |
---|
333 | /** Not actually used - all DATA types begin from this value */ |
---|
334 | TRACE_RT_DATA_SIMPLE = 1000, |
---|
335 | |
---|
336 | /** RT is encapsulating an ERF capture record */ |
---|
337 | TRACE_RT_DATA_ERF =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_ERF, |
---|
338 | /** RT is encapsulating a WAG capture record */ |
---|
339 | TRACE_RT_DATA_WAG =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_WAG, |
---|
340 | /** RT is encapsulating a Legacy ATM capture record */ |
---|
341 | TRACE_RT_DATA_LEGACY_ATM=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LEGACY_ATM, |
---|
342 | /** RT is encapsulating a Legacy POS capture record */ |
---|
343 | TRACE_RT_DATA_LEGACY_POS=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LEGACY_POS, |
---|
344 | /** RT is encapsulating a Legacy ETH capture record */ |
---|
345 | TRACE_RT_DATA_LEGACY_ETH=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LEGACY_ETH, |
---|
346 | /** RT is encapsulating a Linux native capture record */ |
---|
347 | TRACE_RT_DATA_LINUX_NATIVE=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LINUX_NATIVE, |
---|
348 | /** RT is encapsulating a BSD native capture record */ |
---|
349 | //TRACE_RT_DATA_BPF =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_BPF, |
---|
350 | /** RT is encapsulating a TSH capture record */ |
---|
351 | TRACE_RT_DATA_TSH =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_TSH, |
---|
352 | /** RT is encapsulating an ATM header capture record */ |
---|
353 | TRACE_RT_DATA_ATMHDR = TRACE_RT_DATA_SIMPLE + TRACE_FORMAT_ATMHDR, |
---|
354 | /** RT is encapsulating a Legacy NZIX capture record */ |
---|
355 | TRACE_RT_DATA_LEGACY_NZIX=TRACE_RT_DATA_SIMPLE + TRACE_FORMAT_LEGACY_NZIX, |
---|
356 | /** RT is encapsulating a Linux native PACKET_MMAP capture record */ |
---|
357 | TRACE_RT_DATA_LINUX_RING=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LINUX_RING, |
---|
358 | |
---|
359 | /** As PCAP does not store the linktype with the packet, we need to |
---|
360 | * create a separate RT type for each supported DLT, starting from |
---|
361 | * this value */ |
---|
362 | TRACE_RT_DATA_DLT = 2000, |
---|
363 | /** RT is encapsulating a PCAP capture record with a NULL linktype */ |
---|
364 | TRACE_RT_DLT_NULL =TRACE_RT_DATA_DLT+TRACE_DLT_NULL, |
---|
365 | /** RT is encapsulating a PCAP capture record with an Ethernet |
---|
366 | * linktype */ |
---|
367 | TRACE_RT_DLT_EN10MB =TRACE_RT_DATA_DLT+TRACE_DLT_EN10MB, |
---|
368 | /** RT is encapsulating a PCAP capture record with an 802.11 |
---|
369 | * linktype */ |
---|
370 | TRACE_RT_DLT_IEEE802_11 =TRACE_RT_DATA_DLT+TRACE_DLT_IEEE802_11, |
---|
371 | /** RT is encapsulating a PCAP capture record with a Linux SLL |
---|
372 | * linktype */ |
---|
373 | TRACE_RT_DLT_LINUX_SLL =TRACE_RT_DATA_DLT+TRACE_DLT_LINUX_SLL, |
---|
374 | /** RT is encapsulating a PCAP capture record with a PFlog linktype */ |
---|
375 | TRACE_RT_DLT_PFLOG =TRACE_RT_DATA_DLT+TRACE_DLT_PFLOG, |
---|
376 | /** RT is encapsulating a PCAP capture record with an AAL5 linktype */ |
---|
377 | TRACE_RT_DLT_ATM_RFC1483 =TRACE_RT_DATA_DLT+TRACE_DLT_ATM_RFC1483, |
---|
378 | /** Unused value marking the end of the valid range for PCAP RT |
---|
379 | * encapsulation */ |
---|
380 | TRACE_RT_DATA_DLT_END = 2999, |
---|
381 | /** BPF does not store the linktype with the packet, so we need a |
---|
382 | * separate RT type for each supported DLT. This value represents the |
---|
383 | * starting point */ |
---|
384 | TRACE_RT_DATA_BPF = 3000, |
---|
385 | |
---|
386 | TRACE_RT_BPF_NULL = TRACE_RT_DATA_BPF+TRACE_DLT_NULL, |
---|
387 | TRACE_RT_BPF_EN10MB = TRACE_RT_DATA_BPF+TRACE_DLT_EN10MB, |
---|
388 | TRACE_RT_BPF_IEEE802_11 = TRACE_RT_DATA_BPF+TRACE_DLT_IEEE802_11, |
---|
389 | TRACE_RT_BPF_PFLOG =TRACE_RT_DATA_BPF+TRACE_DLT_PFLOG, |
---|
390 | TRACE_RT_BPF_ATM_RFC1483 =TRACE_RT_DATA_BPF+TRACE_DLT_ATM_RFC1483, |
---|
391 | |
---|
392 | TRACE_RT_DATA_BPF_END = 3999, |
---|
393 | /** Unused value marking the end of the valid range for all RT packet |
---|
394 | * types */ |
---|
395 | TRACE_RT_LAST = 4000 |
---|
396 | } libtrace_rt_types_t; |
---|
397 | |
---|
398 | /** IP Protocol values */ |
---|
399 | typedef enum { |
---|
400 | TRACE_IPPROTO_IP = 0, /**< IP pseudo protocol number */ |
---|
401 | TRACE_IPPROTO_ICMP = 1, /**< Internet Control Message protocol */ |
---|
402 | TRACE_IPPROTO_IGMP = 2, /**< Internet Group Management Protocol */ |
---|
403 | TRACE_IPPROTO_IPIP = 4, /**< IP encapsulated in IP */ |
---|
404 | TRACE_IPPROTO_TCP = 6, /**< Transmission Control Protocol */ |
---|
405 | TRACE_IPPROTO_UDP = 17, /**< User Datagram Protocol */ |
---|
406 | TRACE_IPPROTO_IPV6 = 41, /**< IPv6 over IPv4 */ |
---|
407 | TRACE_IPPROTO_ROUTING = 43, /**< IPv6 Routing header */ |
---|
408 | TRACE_IPPROTO_FRAGMENT = 44, /**< IPv6 Fragmentation header */ |
---|
409 | TRACE_IPPROTO_RSVP = 46, /**< Resource Reservation Protocol */ |
---|
410 | TRACE_IPPROTO_GRE = 47, /**< General Routing Encapsulation */ |
---|
411 | TRACE_IPPROTO_ESP = 50, /**< Encapsulated Security Payload [RFC2406] */ |
---|
412 | TRACE_IPPROTO_AH = 51, /**< Authentication Header [RFC2402] */ |
---|
413 | TRACE_IPPROTO_ICMPV6 = 58, /**< ICMPv6 */ |
---|
414 | TRACE_IPPROTO_NONE = 59, /**< IPv6 no next header */ |
---|
415 | TRACE_IPPROTO_DSTOPTS = 60, /**< IPv6 destination options */ |
---|
416 | TRACE_IPPROTO_OSPF = 89, /**< Open Shortest Path First routing protocol */ |
---|
417 | TRACE_IPPROTO_PIM = 103, /**< Protocol Independant Multicast */ |
---|
418 | TRACE_IPPROTO_SCTP = 132 /**< Stream Control Transmission Protocol */ |
---|
419 | } libtrace_ipproto_t; |
---|
420 | |
---|
421 | /** Ethertypes supported by Libtrace */ |
---|
422 | typedef enum { |
---|
423 | /* Numbers <=1500 are of course, LLC/SNAP */ |
---|
424 | TRACE_ETHERTYPE_LOOPBACK= 0x0060, /**< Ethernet Loopback */ |
---|
425 | TRACE_ETHERTYPE_IP = 0x0800, /**< IPv4 */ |
---|
426 | TRACE_ETHERTYPE_ARP = 0x0806, /**< Address resolution protocol */ |
---|
427 | TRACE_ETHERTYPE_RARP = 0x8035, /**< Reverse ARP */ |
---|
428 | TRACE_ETHERTYPE_8021Q = 0x8100, /**< 802.1q VLAN Extended Header */ |
---|
429 | TRACE_ETHERTYPE_IPV6 = 0x86DD, /**< IPv6 */ |
---|
430 | TRACE_ETHERTYPE_MPLS = 0x8847, /**< MPLS Unicast traffic */ |
---|
431 | TRACE_ETHERTYPE_MPLS_MC = 0x8848, /**< MPLS Multicast traffic */ |
---|
432 | TRACE_ETHERTYPE_PPP_DISC= 0x8863, /**< PPPoE Service Discovery */ |
---|
433 | TRACE_ETHERTYPE_PPP_SES = 0x8864 /**< PPPoE Session Messages */ |
---|
434 | } libtrace_ethertype_t; |
---|
435 | |
---|
436 | /** The libtrace packet structure. Applications shouldn't be |
---|
437 | * meddling around in here |
---|
438 | */ |
---|
439 | typedef struct libtrace_packet_t { |
---|
440 | struct libtrace_t *trace; /**< Pointer to the trace */ |
---|
441 | void *header; /**< Pointer to the framing header */ |
---|
442 | void *payload; /**< Pointer to the link layer */ |
---|
443 | void *buffer; /**< Allocated buffer */ |
---|
444 | libtrace_rt_types_t type; /**< RT protocol type for the packet */ |
---|
445 | buf_control_t buf_control; /**< Describes memory ownership */ |
---|
446 | int capture_length; /**< Cached capture length */ |
---|
447 | int wire_length; /**< Cached wire length */ |
---|
448 | int payload_length; /**< Cached payload length */ |
---|
449 | void *l2_header; /**< Cached link header */ |
---|
450 | libtrace_linktype_t link_type; /**< Cached link type */ |
---|
451 | uint32_t l2_remaining; /**< Cached link remaining */ |
---|
452 | void *l3_header; /**< Cached l3 header */ |
---|
453 | uint16_t l3_ethertype; /**< Cached l3 ethertype */ |
---|
454 | uint32_t l3_remaining; /**< Cached l3 remaining */ |
---|
455 | void *l4_header; /**< Cached transport header */ |
---|
456 | uint8_t transport_proto; /**< Cached transport protocol */ |
---|
457 | uint32_t l4_remaining; /**< Cached transport remaining */ |
---|
458 | } libtrace_packet_t; |
---|
459 | |
---|
460 | |
---|
461 | /** Trace directions. |
---|
462 | * Note that these are the directions used by convention. More directions |
---|
463 | * are possible, not just these 3, and that they may not conform to this |
---|
464 | * convention. |
---|
465 | */ |
---|
466 | typedef enum { |
---|
467 | TRACE_DIR_OUTGOING = 0, /**< Packets originating "inside" */ |
---|
468 | TRACE_DIR_INCOMING = 1, /**< Packets originating "outside" */ |
---|
469 | TRACE_DIR_OTHER = 2 /**< Packets with an unknown direction, or one that's unknown */ |
---|
470 | } libtrace_direction_t; |
---|
471 | |
---|
472 | /** Enumeration of Radiotap fields */ |
---|
473 | typedef enum { |
---|
474 | TRACE_RADIOTAP_TSFT = 0, /**< Timer synchronisation function, in microseconds (uint64) */ |
---|
475 | TRACE_RADIOTAP_FLAGS = 1, /**< Wireless flags (uint8) */ |
---|
476 | TRACE_RADIOTAP_RATE = 2, /**< Bitrate in units of 500kbps (uint8) */ |
---|
477 | TRACE_RADIOTAP_CHANNEL = 3, /**< Frequency in MHz (uint16) and channel flags (uint16) */ |
---|
478 | TRACE_RADIOTAP_FHSS = 4, /**< FHSS hop set (uint8) and hopping pattern (uint8) */ |
---|
479 | TRACE_RADIOTAP_DBM_ANTSIGNAL = 5, /**< Signal power in dBm (int8) */ |
---|
480 | TRACE_RADIOTAP_DBM_ANTNOISE = 6, /**< Noise power in dBm (int8) */ |
---|
481 | TRACE_RADIOTAP_LOCK_QUALITY = 7, /**< Barker Code lock quality (uint16) */ |
---|
482 | TRACE_RADIOTAP_TX_ATTENUATION = 8, /**< TX attenuation as unitless distance from max power (uint16) */ |
---|
483 | TRACE_RADIOTAP_DB_TX_ATTENUATION = 9, /**< TX attenutation as dB from max power (uint16) */ |
---|
484 | TRACE_RADIOTAP_DBM_TX_POWER = 10, /**< TX Power in dBm (int8) */ |
---|
485 | TRACE_RADIOTAP_ANTENNA = 11, /**< Antenna frame was rx'd or tx'd on (uint8) */ |
---|
486 | TRACE_RADIOTAP_DB_ANTSIGNAL = 12, /**< Signal power in dB from a fixed reference (uint8) */ |
---|
487 | TRACE_RADIOTAP_DB_ANTNOISE = 13, /**< Noise power in dB from a fixed reference (uint8) */ |
---|
488 | TRACE_RADIOTAP_RX_FLAGS = 14, /** Properties of received frame (uint16) */ |
---|
489 | TRACE_RADIOTAP_TX_FLAGS = 15, /** Properties of transmitted frame (uint16) */ |
---|
490 | TRACE_RADIOTAP_RTS_RETRIES = 16, /** Number of rts retries frame used (uint8) */ |
---|
491 | TRACE_RADIOTAP_DATA_RETRIES = 17, /** Number of unicast retries a transmitted frame used (uint8) */ |
---|
492 | TRACE_RADIOTAP_EXT = 31 |
---|
493 | } libtrace_radiotap_field_t; |
---|
494 | |
---|
495 | |
---|
496 | /** @name Protocol structures |
---|
497 | * These convenience structures provide portable versions of the headers |
---|
498 | * for a variety of protocols. |
---|
499 | * @{ |
---|
500 | */ |
---|
501 | |
---|
502 | #ifdef WIN32 |
---|
503 | #pragma pack(push) |
---|
504 | #pragma pack(1) |
---|
505 | #endif |
---|
506 | |
---|
507 | /** Generic IP header structure */ |
---|
508 | typedef struct libtrace_ip |
---|
509 | { |
---|
510 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
511 | LT_BITFIELD8 ip_hl:4; /**< Header Length */ |
---|
512 | LT_BITFIELD8 ip_v:4; /**< Version */ |
---|
513 | #elif BYTE_ORDER == BIG_ENDIAN |
---|
514 | LT_BITFIELD8 ip_v:4; /**< Version */ |
---|
515 | LT_BITFIELD8 ip_hl:4; /**< Header Length */ |
---|
516 | #else |
---|
517 | # error "Adjust your <bits/endian.h> defines" |
---|
518 | #endif |
---|
519 | uint8_t ip_tos; /**< Type of Service */ |
---|
520 | uint16_t ip_len; /**< Total Length */ |
---|
521 | int16_t ip_id; /**< Identification */ |
---|
522 | uint16_t ip_off; /**< IP Fragment offset (and flags) */ |
---|
523 | uint8_t ip_ttl; /**< Time to Live */ |
---|
524 | uint8_t ip_p; /**< Protocol */ |
---|
525 | uint16_t ip_sum; /**< Checksum */ |
---|
526 | struct in_addr ip_src; /**< Source Address */ |
---|
527 | struct in_addr ip_dst; /**< Destination Address */ |
---|
528 | } PACKED libtrace_ip_t; |
---|
529 | |
---|
530 | /** IPv6 header extension structure */ |
---|
531 | typedef struct libtrace_ip6_ext |
---|
532 | { |
---|
533 | uint8_t nxt; /**< Next header */ |
---|
534 | uint8_t len; /**< Length of the current header */ |
---|
535 | } PACKED libtrace_ip6_ext_t; |
---|
536 | |
---|
537 | typedef struct libtrace_ip6_frag |
---|
538 | { |
---|
539 | uint8_t nxt; /**< Next header */ |
---|
540 | uint8_t res; /**< Reserved */ |
---|
541 | uint16_t frag_off; /**< Fragment Offset (includes M flag) */ |
---|
542 | uint32_t ident; /** Fragment identification */ |
---|
543 | } PACKED libtrace_ip6_frag_t; |
---|
544 | |
---|
545 | /** Generic IPv6 header structure |
---|
546 | * |
---|
547 | * @note The flow label field also includes the Version and Traffic Class |
---|
548 | * fields, because we haven't figured out a nice way to deal with fields |
---|
549 | * crossing byte boundaries on both Big and Little Endian machines */ |
---|
550 | typedef struct libtrace_ip6 |
---|
551 | { |
---|
552 | uint32_t flow; /**< Flow label */ |
---|
553 | uint16_t plen; /**< Payload length */ |
---|
554 | uint8_t nxt; /**< Next header */ |
---|
555 | uint8_t hlim; /**< Hop limit */ |
---|
556 | struct in6_addr ip_src; /**< Source address */ |
---|
557 | struct in6_addr ip_dst; /**< Destination address */ |
---|
558 | } PACKED libtrace_ip6_t; |
---|
559 | |
---|
560 | /** Generic TCP header structure */ |
---|
561 | typedef struct libtrace_tcp |
---|
562 | { |
---|
563 | uint16_t source; /**< Source Port */ |
---|
564 | uint16_t dest; /**< Destination port */ |
---|
565 | uint32_t seq; /**< Sequence number */ |
---|
566 | uint32_t ack_seq; /**< Acknowledgement Number */ |
---|
567 | # if BYTE_ORDER == LITTLE_ENDIAN |
---|
568 | LT_BITFIELD8 ecn_ns:1; /**< ECN Nonce Sum */ |
---|
569 | LT_BITFIELD8 res1:3; /**< Reserved bits */ |
---|
570 | LT_BITFIELD8 doff:4; /**< Data Offset */ |
---|
571 | LT_BITFIELD8 fin:1; /**< FIN */ |
---|
572 | LT_BITFIELD8 syn:1; /**< SYN flag */ |
---|
573 | LT_BITFIELD8 rst:1; /**< RST flag */ |
---|
574 | LT_BITFIELD8 psh:1; /**< PuSH flag */ |
---|
575 | LT_BITFIELD8 ack:1; /**< ACK flag */ |
---|
576 | LT_BITFIELD8 urg:1; /**< URG flag */ |
---|
577 | LT_BITFIELD8 ece:1; /**< ECN Echo */ |
---|
578 | LT_BITFIELD8 cwr:1; /**< ECN CWR */ |
---|
579 | # elif BYTE_ORDER == BIG_ENDIAN |
---|
580 | LT_BITFIELD8 doff:4; /**< Data offset */ |
---|
581 | LT_BITFIELD8 res1:3; /**< Reserved bits */ |
---|
582 | LT_BITFIELD8 ecn_ns:1; /**< ECN Nonce Sum */ |
---|
583 | LT_BITFIELD8 cwr:1; /**< ECN CWR */ |
---|
584 | LT_BITFIELD8 ece:1; /**< ECN Echo */ |
---|
585 | LT_BITFIELD8 urg:1; /**< URG flag */ |
---|
586 | LT_BITFIELD8 ack:1; /**< ACK flag */ |
---|
587 | LT_BITFIELD8 psh:1; /**< PuSH flag */ |
---|
588 | LT_BITFIELD8 rst:1; /**< RST flag */ |
---|
589 | LT_BITFIELD8 syn:1; /**< SYN flag */ |
---|
590 | LT_BITFIELD8 fin:1; /**< FIN flag */ |
---|
591 | # else |
---|
592 | # error "Adjust your <bits/endian.h> defines" |
---|
593 | # endif |
---|
594 | uint16_t window; /**< Window Size */ |
---|
595 | uint16_t check; /**< Checksum */ |
---|
596 | uint16_t urg_ptr; /**< Urgent Pointer */ |
---|
597 | } PACKED libtrace_tcp_t; |
---|
598 | |
---|
599 | /** Generic UDP header structure */ |
---|
600 | typedef struct libtrace_udp { |
---|
601 | uint16_t source; /**< Source port */ |
---|
602 | uint16_t dest; /**< Destination port */ |
---|
603 | uint16_t len; /**< Length */ |
---|
604 | uint16_t check; /**< Checksum */ |
---|
605 | } PACKED libtrace_udp_t; |
---|
606 | |
---|
607 | /** Generic ICMP header structure */ |
---|
608 | typedef struct libtrace_icmp |
---|
609 | { |
---|
610 | uint8_t type; /**< Message Type */ |
---|
611 | uint8_t code; /**< Type Sub-code */ |
---|
612 | uint16_t checksum; /**< Checksum */ |
---|
613 | union |
---|
614 | { |
---|
615 | struct |
---|
616 | { |
---|
617 | uint16_t id; /**< ID of the Echo request */ |
---|
618 | uint16_t sequence; /**< Sequence number of the Echo request */ |
---|
619 | } echo; /**< Echo Datagram */ |
---|
620 | uint32_t gateway; /**< Gateway Address */ |
---|
621 | struct |
---|
622 | { |
---|
623 | uint16_t unused; /**< Unused */ |
---|
624 | uint16_t mtu; /**< Next-hop MTU */ |
---|
625 | } frag; /**< Path MTU Discovery */ |
---|
626 | } un; /**< Union for Payloads of Various ICMP Codes */ |
---|
627 | } PACKED libtrace_icmp_t; |
---|
628 | |
---|
629 | typedef struct libtrace_icmp6 { |
---|
630 | uint8_t type; /**< Message Type */ |
---|
631 | uint8_t code; /**< Type Sub-code */ |
---|
632 | uint16_t checksum; /**< Checksum */ |
---|
633 | |
---|
634 | union { |
---|
635 | struct { |
---|
636 | uint8_t length; /**< Length of original datagram content in 64 bit words */ |
---|
637 | uint8_t unused; /**< Unused */ |
---|
638 | uint8_t unused1; /**< Unused */ |
---|
639 | } extend; /**< Extensions added in RFC 4884 for Time Exceeded and Destination Unreachable Messages */ |
---|
640 | |
---|
641 | uint32_t mtu; /**< MTU from Packet Too Big Message */ |
---|
642 | uint32_t pointer; /**< Pointer from Parameter Problem Message */ |
---|
643 | struct { |
---|
644 | uint16_t id; /**< Echo Identifier */ |
---|
645 | uint16_t sequence; /**< Echo Sequence Number */ |
---|
646 | } echo; /**< Data required for Echo Request and Reply messages */ |
---|
647 | } un; |
---|
648 | } PACKED libtrace_icmp6_t; |
---|
649 | |
---|
650 | /** Generic LLC/SNAP header structure */ |
---|
651 | typedef struct libtrace_llcsnap |
---|
652 | { |
---|
653 | /* LLC */ |
---|
654 | uint8_t dsap; /**< Destination Service Access Point */ |
---|
655 | uint8_t ssap; /**< Source Service Access Point */ |
---|
656 | uint8_t control; /**< Control field */ |
---|
657 | /* SNAP */ |
---|
658 | LT_BITFIELD32 oui:24; /**< Organisationally Unique Identifier (scope)*/ |
---|
659 | uint16_t type; /**< Protocol within OUI */ |
---|
660 | } PACKED libtrace_llcsnap_t; |
---|
661 | |
---|
662 | /** 802.3 frame */ |
---|
663 | typedef struct libtrace_ether |
---|
664 | { |
---|
665 | uint8_t ether_dhost[6]; /**< Destination Ether Addr */ |
---|
666 | uint8_t ether_shost[6]; /**< Source Ether Addr */ |
---|
667 | uint16_t ether_type; /**< Packet Type ID Field (next-header) */ |
---|
668 | } PACKED libtrace_ether_t; |
---|
669 | |
---|
670 | /** 802.1Q frame */ |
---|
671 | typedef struct libtrace_8021q |
---|
672 | { |
---|
673 | LT_BITFIELD16 vlan_pri:3; /**< VLAN User Priority */ |
---|
674 | LT_BITFIELD16 vlan_cfi:1; /**< VLAN Format Indicator, |
---|
675 | * 0 for ethernet, 1 for token ring */ |
---|
676 | LT_BITFIELD16 vlan_id:12; /**< VLAN Id */ |
---|
677 | uint16_t vlan_ether_type; /**< VLAN Sub-packet Type ID Field |
---|
678 | * (next-header)*/ |
---|
679 | } PACKED libtrace_8021q_t; |
---|
680 | |
---|
681 | /** ATM User Network Interface (UNI) Cell. */ |
---|
682 | typedef struct libtrace_atm_cell |
---|
683 | { |
---|
684 | LT_BITFIELD32 gfc:4; /**< Generic Flow Control */ |
---|
685 | LT_BITFIELD32 vpi:8; /**< Virtual Path Identifier */ |
---|
686 | LT_BITFIELD32 vci:16; /**< Virtual Channel Identifier */ |
---|
687 | LT_BITFIELD32 pt:3; /**< Payload Type */ |
---|
688 | LT_BITFIELD32 clp:1; /**< Cell Loss Priority */ |
---|
689 | LT_BITFIELD32 hec:8; /**< Header Error Control */ |
---|
690 | } PACKED libtrace_atm_cell_t; |
---|
691 | |
---|
692 | /** ATM Network Node/Network Interface (NNI) Cell. */ |
---|
693 | typedef struct libtrace_atm_nni_cell |
---|
694 | { |
---|
695 | LT_BITFIELD32 vpi:12; /**< Virtual Path Identifier */ |
---|
696 | LT_BITFIELD32 vci:16; /**< Virtual Channel Identifier */ |
---|
697 | LT_BITFIELD32 pt:3; /**< Payload Type */ |
---|
698 | LT_BITFIELD32 clp:1; /**< Cell Loss Priority */ |
---|
699 | LT_BITFIELD32 hec:8; /**< Header Error Control */ |
---|
700 | } PACKED libtrace_atm_nni_cell_t; |
---|
701 | |
---|
702 | /** Captured UNI cell. |
---|
703 | * |
---|
704 | * Endace don't capture the HEC, presumably to keep alignment. This |
---|
705 | * version of the \ref libtrace_atm_cell is used when dealing with DAG |
---|
706 | * captures of uni cells. |
---|
707 | * |
---|
708 | */ |
---|
709 | typedef struct libtrace_atm_capture_cell |
---|
710 | { |
---|
711 | LT_BITFIELD32 gfc:4; /**< Generic Flow Control */ |
---|
712 | LT_BITFIELD32 vpi:8; /**< Virtual Path Identifier */ |
---|
713 | LT_BITFIELD32 vci:16; /**< Virtual Channel Identifier */ |
---|
714 | LT_BITFIELD32 pt:3; /**< Payload Type */ |
---|
715 | LT_BITFIELD32 clp:1; /**< Cell Loss Priority */ |
---|
716 | } PACKED libtrace_atm_capture_cell_t; |
---|
717 | |
---|
718 | /** Captured NNI cell. |
---|
719 | * |
---|
720 | * Endace don't capture the HEC, presumably to keep alignment. This |
---|
721 | * version of the \ref libtrace_atm_nni_cell is used when dealing with DAG |
---|
722 | * captures of nni cells. |
---|
723 | * |
---|
724 | */ |
---|
725 | typedef struct libtrace_atm_nni_capture_cell |
---|
726 | { |
---|
727 | LT_BITFIELD32 vpi:12; /**< Virtual Path Identifier */ |
---|
728 | LT_BITFIELD32 vci:16; /**< Virtual Channel Identifier */ |
---|
729 | LT_BITFIELD32 pt:3; /**< Payload Type */ |
---|
730 | LT_BITFIELD32 clp:1; /**< Cell Loss Priority */ |
---|
731 | LT_BITFIELD32 hec:8; /**< Header Error Control */ |
---|
732 | } PACKED libtrace_atm_nni_capture_cell_t; |
---|
733 | |
---|
734 | /** PPP header */ |
---|
735 | typedef struct libtrace_ppp |
---|
736 | { |
---|
737 | /* I can't figure out where the hell these two variables come from. They're |
---|
738 | * definitely not in RFC 1661 which defines PPP. Probably some weird thing |
---|
739 | * relating to the lack of distinction between PPP, HDLC and CHDLC */ |
---|
740 | |
---|
741 | /* uint8_t address; */ /**< PPP Address (0xFF - All stations) */ |
---|
742 | /* uint8_t header; */ /**< PPP Control (0x03 - Unnumbered info) */ |
---|
743 | uint16_t protocol; /**< PPP Protocol (htons(0x0021) - IPv4 */ |
---|
744 | } PACKED libtrace_ppp_t; |
---|
745 | |
---|
746 | /** PPPoE header */ |
---|
747 | typedef struct libtrace_pppoe |
---|
748 | { |
---|
749 | LT_BITFIELD8 version:4; /**< Protocol version number */ |
---|
750 | LT_BITFIELD8 type:4; /**< PPPoE Type */ |
---|
751 | uint8_t code; /**< PPPoE Code */ |
---|
752 | uint16_t session_id; /**< Session Identifier */ |
---|
753 | uint16_t length; /**< Total Length of the PPP packet */ |
---|
754 | } PACKED libtrace_pppoe_t; |
---|
755 | |
---|
756 | /** 802.11 header */ |
---|
757 | typedef struct libtrace_80211_t { |
---|
758 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
759 | LT_BITFIELD32 protocol:2; /**< Protocol Version */ |
---|
760 | LT_BITFIELD32 type:2; /**< Frame Type */ |
---|
761 | LT_BITFIELD32 subtype:4; /**< Frame Subtype */ |
---|
762 | #else |
---|
763 | LT_BITFIELD32 subtype:4; /**< Frame Subtype */ |
---|
764 | LT_BITFIELD32 type:2; /**< Frame Type */ |
---|
765 | LT_BITFIELD32 protocol:2; /**< Protocol Version */ |
---|
766 | #endif |
---|
767 | |
---|
768 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
769 | LT_BITFIELD32 to_ds:1; /**< Packet to Distribution Service */ |
---|
770 | LT_BITFIELD32 from_ds:1; /**< Packet from Distribution Service */ |
---|
771 | LT_BITFIELD32 more_frag:1; /**< Packet has more fragments */ |
---|
772 | LT_BITFIELD32 retry:1; /**< Packet is a retry */ |
---|
773 | LT_BITFIELD32 power:1; /**< Power Management mode */ |
---|
774 | LT_BITFIELD32 more_data:1; /**< More data is buffered at station */ |
---|
775 | LT_BITFIELD32 wep:1; /**< WEP encryption indicator */ |
---|
776 | LT_BITFIELD32 order:1; /**< Strictly-Ordered class indicator */ |
---|
777 | #else |
---|
778 | LT_BITFIELD32 order:1; /**< Strictly-Ordered class indicator */ |
---|
779 | LT_BITFIELD32 wep:1; /**< WEP encryption indicator */ |
---|
780 | LT_BITFIELD32 more_data:1; /**< More data is buffered at station */ |
---|
781 | LT_BITFIELD32 power:1; /**< Power Management mode */ |
---|
782 | LT_BITFIELD32 retry:1; /**< Packet is a retry */ |
---|
783 | LT_BITFIELD32 more_frag:1; /**< Packet has more fragments */ |
---|
784 | LT_BITFIELD32 from_ds:1; /**< Packet from Distribution Service */ |
---|
785 | LT_BITFIELD32 to_ds:1; /**< Packet to Distribution Service */ |
---|
786 | #endif |
---|
787 | |
---|
788 | uint16_t duration; /**< Duration value for NAV calculation */ |
---|
789 | uint8_t mac1[6]; /**< MAC Address 1 */ |
---|
790 | uint8_t mac2[6]; /**< MAC Address 2 */ |
---|
791 | uint8_t mac3[6]; /**< MAC Address 3 */ |
---|
792 | uint16_t SeqCtl; /**< Sequence Control */ |
---|
793 | uint8_t mac4[6]; /**< MAC Address 4 */ |
---|
794 | } PACKED libtrace_80211_t; |
---|
795 | |
---|
796 | /** The Radiotap header pre-amble |
---|
797 | * |
---|
798 | * All Radiotap headers start with this pre-amble, followed by the fields |
---|
799 | * specified in the it_present bitmask. If bit 31 of it_present is set, then |
---|
800 | * another bitmask follows. |
---|
801 | * @note All of the radiotap data fields are in little-endian byte-order. |
---|
802 | */ |
---|
803 | typedef struct libtrace_radiotap_t { |
---|
804 | uint8_t it_version; /**< Radiotap version */ |
---|
805 | uint8_t it_pad; /**< Padding for natural alignment */ |
---|
806 | uint16_t it_len; /**< Length in bytes of the entire Radiotap header */ |
---|
807 | uint32_t it_present; /**< Which Radiotap fields are present */ |
---|
808 | } PACKED libtrace_radiotap_t; |
---|
809 | |
---|
810 | /** OSPF header */ |
---|
811 | typedef struct libtrace_ospf_v2_t |
---|
812 | { |
---|
813 | uint8_t ospf_v; /**< OSPF Version, should be 2 */ |
---|
814 | uint8_t type; /**< OSPF Packet Type */ |
---|
815 | uint16_t len; /**< Packet length, including OSPF header */ |
---|
816 | struct in_addr router; /**< Router ID of the packet source */ |
---|
817 | struct in_addr area; /**< Area the packet belongs to */ |
---|
818 | uint16_t sum; /**< Checksum */ |
---|
819 | uint16_t au_type; /**< Authentication procedure */ |
---|
820 | uint16_t zero; /**< Always zero */ |
---|
821 | uint8_t au_key_id; /**< Authentication Key ID */ |
---|
822 | uint8_t au_data_len; /**< Authentication Data Length */ |
---|
823 | uint32_t au_seq_num; /**< Cryptographic Sequence Number */ |
---|
824 | } PACKED libtrace_ospf_v2_t; |
---|
825 | |
---|
826 | /** Options Field present in some OSPFv2 packets */ |
---|
827 | typedef struct libtrace_ospf_options_t { |
---|
828 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
829 | LT_BITFIELD8 unused1:1; |
---|
830 | LT_BITFIELD8 e_bit:1; |
---|
831 | LT_BITFIELD8 mc_bit:1; |
---|
832 | LT_BITFIELD8 np_bit:1; |
---|
833 | LT_BITFIELD8 ea_bit:1; |
---|
834 | LT_BITFIELD8 dc_bit:1; |
---|
835 | LT_BITFIELD8 unused2:2; |
---|
836 | #elif BYTE_ORDER == BIG_ENDIAN |
---|
837 | LT_BITFIELD8 unused2:2; |
---|
838 | LT_BITFIELD8 dc_bit:1; |
---|
839 | LT_BITFIELD8 ea_bit:1; |
---|
840 | LT_BITFIELD8 np_bit:1; |
---|
841 | LT_BITFIELD8 mc_bit:1; |
---|
842 | LT_BITFIELD8 e_bit:1; |
---|
843 | LT_BITFIELD8 unused1:1; |
---|
844 | #endif |
---|
845 | } PACKED libtrace_ospf_options_t; |
---|
846 | |
---|
847 | /** LSA Header for OSPFv2 */ |
---|
848 | typedef struct libtrace_ospf_lsa_v2_t |
---|
849 | { |
---|
850 | uint16_t age; /**< Time in seconds since LSA originated */ |
---|
851 | libtrace_ospf_options_t lsa_options; /**< Options */ |
---|
852 | uint8_t lsa_type; /**< LSA type */ |
---|
853 | struct in_addr ls_id; /**< Link State ID */ |
---|
854 | struct in_addr adv_router; /**< Router that originated this LSA */ |
---|
855 | uint32_t seq; /**< LS sequence number */ |
---|
856 | uint16_t checksum; /**< Checksum */ |
---|
857 | uint16_t length; /**< Length of the LSA including LSA header */ |
---|
858 | } PACKED libtrace_ospf_lsa_v2_t; |
---|
859 | |
---|
860 | /** OSPFv2 Hello Packet */ |
---|
861 | typedef struct libtrace_ospf_hello_v2_t |
---|
862 | { |
---|
863 | struct in_addr mask; /**< Network mask for this interface */ |
---|
864 | uint16_t interval; /**< Interval between Hello packets (secs) */ |
---|
865 | libtrace_ospf_options_t hello_options; /**< Options */ |
---|
866 | uint8_t priority; /**< Router Priority */ |
---|
867 | uint32_t deadint; /**< Interval before declaring a router down */ |
---|
868 | struct in_addr designated; /**< Designated router for the network */ |
---|
869 | struct in_addr backup; /**< Backup designated router */ |
---|
870 | |
---|
871 | /** Neighbors follow from here, but there can be anywhere from 1 to N |
---|
872 | * neighbors so I can't include that here */ |
---|
873 | } PACKED libtrace_ospf_hello_v2_t; |
---|
874 | |
---|
875 | /** OSPFv2 Database Description packet */ |
---|
876 | typedef struct libtrace_ospf_db_desc_v2_t |
---|
877 | { |
---|
878 | uint16_t mtu; /**< Interface MTU */ |
---|
879 | libtrace_ospf_options_t db_desc_options; /**< Options */ |
---|
880 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
881 | LT_BITFIELD8 db_desc_ms:1; /**< If set, this router is the master */ |
---|
882 | LT_BITFIELD8 db_desc_m:1; /**< If set, more packets to follow */ |
---|
883 | LT_BITFIELD8 db_desc_i:1; /**< If set, this is the first packet in sequence */ |
---|
884 | LT_BITFIELD8 zero:5; |
---|
885 | #elif BYTE_ORDER == BIG_ENDIAN |
---|
886 | LT_BITFIELD8 zero:5; |
---|
887 | LT_BITFIELD8 db_desc_i:1; /**< If set, this is the first packet in sequence */ |
---|
888 | LT_BITFIELD8 db_desc_m:1; /**< If set, more packets to follow */ |
---|
889 | LT_BITFIELD8 db_desc_ms:1; /**< If set, this router is the master */ |
---|
890 | #endif |
---|
891 | uint32_t seq; /**< Sequence number for DD packets */ |
---|
892 | } PACKED libtrace_ospf_db_desc_v2_t; |
---|
893 | |
---|
894 | /** OSPF Link State Request Packet */ |
---|
895 | typedef struct libtrace_ospf_ls_req_t |
---|
896 | { |
---|
897 | uint32_t ls_type; /**< Link State Type */ |
---|
898 | uint32_t ls_id; /**< Link State Id */ |
---|
899 | uint32_t advertising_router; /**< Advertising Router */ |
---|
900 | } PACKED libtrace_ospf_ls_req_t; |
---|
901 | |
---|
902 | /** OSPF Link State Update Packet */ |
---|
903 | typedef struct libtrace_ospf_ls_update_t |
---|
904 | { |
---|
905 | uint32_t ls_num_adv; /**< Number of LSAs in this packet */ |
---|
906 | |
---|
907 | /* Followed by LSAs, use API functions to access these */ |
---|
908 | } PACKED libtrace_ospf_ls_update_t; |
---|
909 | |
---|
910 | /** OSPFv2 AS External LSA Body */ |
---|
911 | typedef struct libtrace_ospf_as_external_lsa_t |
---|
912 | { |
---|
913 | struct in_addr netmask; /**< Netmask for the destination */ |
---|
914 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
915 | LT_BITFIELD8 tos:7; |
---|
916 | LT_BITFIELD8 e:1; /**< If set, metric is Type 2. Else, Type 1 */ |
---|
917 | #elif BYTE_ORDER == BIG_ENDIAN |
---|
918 | LT_BITFIELD8 e:1; /**< If set, metric is Type 2. Else, Type 1 */ |
---|
919 | LT_BITFIELD8 tos:7; |
---|
920 | #endif |
---|
921 | uint8_t metric_a; /**< Byte 1 of the Metric field */ |
---|
922 | uint8_t metric_b; /**< Byte 2 of the Metric field */ |
---|
923 | uint8_t metric_c; /**< Byte 3 of the Metric field */ |
---|
924 | struct in_addr forwarding; /**< Forwarding address */ |
---|
925 | uint32_t external_tag; /**< External Route Tag */ |
---|
926 | } PACKED libtrace_ospf_as_external_lsa_v2_t; |
---|
927 | |
---|
928 | /** OSPFv2 Summary LSA Body */ |
---|
929 | typedef struct libtrace_ospf_summary_lsa |
---|
930 | { |
---|
931 | struct in_addr netmask; /**< Netmask for the destination */ |
---|
932 | uint8_t zero; /**< Always zero */ |
---|
933 | uint8_t metric_a; /**< Byte 1 of the Metric field */ |
---|
934 | uint8_t metric_b; /**< Byte 2 of the Metric field */ |
---|
935 | uint8_t metric_c; /**< Byte 3 of the Metric field */ |
---|
936 | |
---|
937 | } PACKED libtrace_ospf_summary_lsa_v2_t; |
---|
938 | |
---|
939 | /** OSPFv2 Network LSA Body */ |
---|
940 | typedef struct libtrace_ospf_network_lsa_t |
---|
941 | { |
---|
942 | struct in_addr netmask; /**< Netmask for the network */ |
---|
943 | /* Followed by IDs of attached routers */ |
---|
944 | } PACKED libtrace_ospf_network_lsa_v2_t; |
---|
945 | |
---|
946 | /** OSPFv2 Router Link structure */ |
---|
947 | typedef struct libtrace_ospf_link_t |
---|
948 | { |
---|
949 | struct in_addr link_id; /**< Object that link connects to */ |
---|
950 | struct in_addr link_data; /**< Link Data field */ |
---|
951 | uint8_t type; /**< Link Type */ |
---|
952 | uint8_t num_tos; /**< Number of TOS metrics */ |
---|
953 | uint16_t tos_metric; /**< Cost of router link */ |
---|
954 | } PACKED libtrace_ospf_link_v2_t; |
---|
955 | |
---|
956 | /** OSPFv2 Router LSA */ |
---|
957 | typedef struct libtrace_ospf_router_lsa_t |
---|
958 | { |
---|
959 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
960 | LT_BITFIELD8 b:1; /**< Area Border Router Flag */ |
---|
961 | LT_BITFIELD8 e:1; /**< External Router Flag */ |
---|
962 | LT_BITFIELD8 v:1; /**< Virtual Endpoint Flag */ |
---|
963 | LT_BITFIELD8 zero:5; |
---|
964 | #elif BYTE_ORDER == BIG_ENDIAN |
---|
965 | LT_BITFIELD8 zero:5; |
---|
966 | LT_BITFIELD8 v:1; /**< Virtual Endpoint Flag */ |
---|
967 | LT_BITFIELD8 e:1; /**< External Router Flag */ |
---|
968 | LT_BITFIELD8 b:1; /**< Area Border Router Flag */ |
---|
969 | #endif |
---|
970 | uint8_t zero2; /**< Always zero */ |
---|
971 | uint16_t num_links; /**< Number of links in LSA */ |
---|
972 | } PACKED libtrace_ospf_router_lsa_v2_t; |
---|
973 | |
---|
974 | typedef enum { |
---|
975 | TRACE_OSPF_HELLO = 1, /**< OSPF Hello */ |
---|
976 | TRACE_OSPF_DATADESC = 2, /**< OSPF Database Description */ |
---|
977 | TRACE_OSPF_LSREQ = 3, /**< OSPF Link State Request */ |
---|
978 | TRACE_OSPF_LSUPDATE = 4, /**< OSPF Link State Update */ |
---|
979 | TRACE_OSPF_LSACK = 5 /**< OSPF Link State Acknowledgement */ |
---|
980 | } libtrace_ospf_types_t; |
---|
981 | |
---|
982 | typedef enum { |
---|
983 | TRACE_OSPF_LS_ROUTER = 1, /**< OSPF Router LSA */ |
---|
984 | TRACE_OSPF_LS_NETWORK = 2, /**< OSPF Network LSA */ |
---|
985 | TRACE_OSPF_LS_SUMMARY = 3, /**< OSPF Summary LSA */ |
---|
986 | TRACE_OSPF_LS_ASBR_SUMMARY = 4, /**< OSPF Summary LSA (ASBR) */ |
---|
987 | TRACE_OSPF_LS_EXTERNAL = 5 /**< OSPF AS External LSA */ |
---|
988 | } libtrace_ospf_ls_types_t; |
---|
989 | |
---|
990 | /** A local definition of an SLL header */ |
---|
991 | typedef struct libtrace_sll_header_t { |
---|
992 | uint16_t pkttype; /**< Packet type */ |
---|
993 | uint16_t hatype; /**< Link-layer address type */ |
---|
994 | uint16_t halen; /**< Link-layer address length */ |
---|
995 | unsigned char addr[8]; /**< Link-layer address */ |
---|
996 | uint16_t protocol; /**< Protocol */ |
---|
997 | } libtrace_sll_header_t; |
---|
998 | |
---|
999 | |
---|
1000 | /* SLL packet types */ |
---|
1001 | |
---|
1002 | /** Packet was addressed for the local host */ |
---|
1003 | #define TRACE_SLL_HOST 0 |
---|
1004 | /** Packet was addressed for a broadcast address */ |
---|
1005 | #define TRACE_SLL_BROADCAST 1 |
---|
1006 | /** Packet was addressed for a multicast address */ |
---|
1007 | #define TRACE_SLL_MULTICAST 2 |
---|
1008 | /** Packet was addressed for another host but was captured by a promiscuous |
---|
1009 | * device */ |
---|
1010 | #define TRACE_SLL_OTHERHOST 3 |
---|
1011 | /** Packet originated from the local host */ |
---|
1012 | #define TRACE_SLL_OUTGOING 4 |
---|
1013 | |
---|
1014 | |
---|
1015 | #ifdef WIN32 |
---|
1016 | #pragma pack(pop) |
---|
1017 | #endif |
---|
1018 | |
---|
1019 | |
---|
1020 | /*@}*/ |
---|
1021 | |
---|
1022 | /** Prints help information for libtrace |
---|
1023 | * |
---|
1024 | * Function prints out some basic help information regarding libtrace, |
---|
1025 | * and then prints out the help() function registered with each input module |
---|
1026 | */ |
---|
1027 | DLLEXPORT void trace_help(void); |
---|
1028 | |
---|
1029 | /** Causes a libtrace reader to stop blocking whilst waiting on new packets |
---|
1030 | * and immediately return EOF. |
---|
1031 | * |
---|
1032 | * This function is useful if you are handling signals within your libtrace |
---|
1033 | * program. If a live source is not receiving any packets (or they are being |
---|
1034 | * filtered), a call to trace_read_packet will result in an infinite loop as |
---|
1035 | * it will block until a packet is received. Normally, a SIGINT would cause the |
---|
1036 | * program to end and thus break the loop, but if you are handling the signal |
---|
1037 | * yourself then that signal will never reach libtrace. |
---|
1038 | * |
---|
1039 | * Instead this function sets a global variable within libtrace that will |
---|
1040 | * cause a blocking live capture to break on the next internal timeout, |
---|
1041 | * allowing control to be returned to the user and their own signal handling |
---|
1042 | * to kick in. |
---|
1043 | */ |
---|
1044 | DLLEXPORT void trace_interrupt(void); |
---|
1045 | |
---|
1046 | /** @name Trace management |
---|
1047 | * These members deal with creating, configuring, starting, pausing and |
---|
1048 | * cleaning up a trace object |
---|
1049 | *@{ |
---|
1050 | */ |
---|
1051 | |
---|
1052 | /** Takes a uri and splits it into a format and uridata component. |
---|
1053 | * @param uri The uri to be parsed |
---|
1054 | * @param [out] format A pointer that will be updated to point to an allocated |
---|
1055 | * string holding the format component of the URI |
---|
1056 | * @return NULL if an error occured, otherwise return a pointer to the uridata |
---|
1057 | * component |
---|
1058 | * |
---|
1059 | * @note The format component is strdup'd by this function, so be sure to free |
---|
1060 | * it when you are done with the split URI. Similarly, do not pass a pointer |
---|
1061 | * to an allocated string into this function as the 'format' parameter, as |
---|
1062 | * that memory will be leaked and replaced with the strdup'd format. |
---|
1063 | */ |
---|
1064 | DLLEXPORT const char *trace_parse_uri(const char *uri, char **format); |
---|
1065 | |
---|
1066 | /** Create an input trace from a URI |
---|
1067 | * |
---|
1068 | * @param uri A valid libtrace URI to be opened |
---|
1069 | * @return An opaque pointer to a libtrace_t |
---|
1070 | * |
---|
1071 | * Some valid URI's are: |
---|
1072 | * - erf:/path/to/erf/file |
---|
1073 | * - erf:- (stdin) |
---|
1074 | * - dag:/dev/dagcard |
---|
1075 | * - pcapint:pcapinterface (eg: pcap:eth0) |
---|
1076 | * - pcap:/path/to/pcap/file |
---|
1077 | * - pcap:- |
---|
1078 | * - rt:hostname |
---|
1079 | * - rt:hostname:port |
---|
1080 | * |
---|
1081 | * If an error occured when attempting to open the trace file, a |
---|
1082 | * trace is still returned so trace_is_err() should be called to find out |
---|
1083 | * if an error occured. The trace is created in the configuration state, you |
---|
1084 | * must call trace_start before attempting to read packets from the trace. |
---|
1085 | */ |
---|
1086 | DLLEXPORT libtrace_t *trace_create(const char *uri); |
---|
1087 | |
---|
1088 | /** Creates a "dummy" trace file that has only the format type set. |
---|
1089 | * |
---|
1090 | * @param uri A valid (but fake) URI indicating the format of the dummy trace that is to be created. |
---|
1091 | * @return An opaque pointer to a (sparsely initialised) libtrace_t |
---|
1092 | * |
---|
1093 | * Only the format portion of the uri parameter matters - the 'file' being |
---|
1094 | * opened does not have to exist. |
---|
1095 | * |
---|
1096 | * @note IMPORTANT: Do not attempt to call trace_read_packet or other such |
---|
1097 | * functions with the dummy trace. Its intended purpose is to provide access |
---|
1098 | * to the format functions where the original trace may no longer exist or is |
---|
1099 | * not the correct format, e.g. reading ERF packets from an RT input. |
---|
1100 | */ |
---|
1101 | DLLEXPORT libtrace_t *trace_create_dead(const char *uri); |
---|
1102 | |
---|
1103 | /** Creates a trace output file from a URI. |
---|
1104 | * |
---|
1105 | * @param uri The uri string describing the output format and destination |
---|
1106 | * @return An opaque pointer to a libtrace_output_t |
---|
1107 | * |
---|
1108 | * Valid URIs include: |
---|
1109 | * - erf:/path/to/erf/file |
---|
1110 | * - pcap:/path/to/pcap/file |
---|
1111 | * |
---|
1112 | * If an error occured when attempting to open the output trace, a trace is |
---|
1113 | * still returned but trace_errno will be set. Use trace_is_err_out() and |
---|
1114 | * trace_perror_output() to get more information. |
---|
1115 | */ |
---|
1116 | DLLEXPORT libtrace_out_t *trace_create_output(const char *uri); |
---|
1117 | |
---|
1118 | /** Start an input trace |
---|
1119 | * @param libtrace The trace to start |
---|
1120 | * @return 0 on success, -1 on failure |
---|
1121 | * |
---|
1122 | * This does the actual work of starting the input trace and applying |
---|
1123 | * all the config options. This may fail, returning -1. The libtrace error |
---|
1124 | * handling functions can be used to get more information about what |
---|
1125 | * specifically went wrong. |
---|
1126 | */ |
---|
1127 | DLLEXPORT int trace_start(libtrace_t *libtrace); |
---|
1128 | |
---|
1129 | /** Pauses an input trace |
---|
1130 | * @param libtrace The trace to pause |
---|
1131 | * @return 0 on success, -1 on failure |
---|
1132 | * |
---|
1133 | * This stops an input trace that is in progress and returns you to the |
---|
1134 | * configuration state. Any packets that arrive on a live capture after |
---|
1135 | * trace_pause() has been called will be discarded. To resume the trace, call |
---|
1136 | * trace_start(). |
---|
1137 | */ |
---|
1138 | DLLEXPORT int trace_pause(libtrace_t *libtrace); |
---|
1139 | |
---|
1140 | /** Start an output trace |
---|
1141 | * @param libtrace The trace to start |
---|
1142 | * @return 0 on success, -1 on failure |
---|
1143 | * |
---|
1144 | * This does the actual work with starting a trace capable of writing packets. |
---|
1145 | * This generally creates the output file. |
---|
1146 | */ |
---|
1147 | DLLEXPORT int trace_start_output(libtrace_out_t *libtrace); |
---|
1148 | |
---|
1149 | /** Valid configuration options for input traces */ |
---|
1150 | typedef enum { |
---|
1151 | /** Maximum number of bytes to be captured for any given packet */ |
---|
1152 | TRACE_OPTION_SNAPLEN, |
---|
1153 | |
---|
1154 | /** If enabled, places a live capture interface into promiscuous mode */ |
---|
1155 | TRACE_OPTION_PROMISC, |
---|
1156 | |
---|
1157 | /** Apply this filter to all packets read from this trace */ |
---|
1158 | TRACE_OPTION_FILTER, |
---|
1159 | |
---|
1160 | /** Defines the frequency of meta-data reporting, e.g. DUCK packets */ |
---|
1161 | TRACE_OPTION_META_FREQ, |
---|
1162 | |
---|
1163 | /** If enabled, the libtrace event API will ignore time gaps between |
---|
1164 | * packets when reading from a trace file */ |
---|
1165 | TRACE_OPTION_EVENT_REALTIME |
---|
1166 | } trace_option_t; |
---|
1167 | |
---|
1168 | /** Sets an input config option |
---|
1169 | * @param libtrace The trace object to apply the option to |
---|
1170 | * @param option The option to set |
---|
1171 | * @param value The value to set the option to |
---|
1172 | * @return -1 if option configuration failed, 0 otherwise |
---|
1173 | * This should be called after trace_create, and before trace_start |
---|
1174 | */ |
---|
1175 | DLLEXPORT int trace_config(libtrace_t *libtrace, |
---|
1176 | trace_option_t option, |
---|
1177 | void *value); |
---|
1178 | |
---|
1179 | /** Valid compression types |
---|
1180 | * Note, this must be kept in sync with WANDIO_COMPRESS_* numbers in wandio.h |
---|
1181 | */ |
---|
1182 | typedef enum { |
---|
1183 | TRACE_OPTION_COMPRESSTYPE_NONE = 0, /**< No compression */ |
---|
1184 | TRACE_OPTION_COMPRESSTYPE_ZLIB = 1, /**< GZip Compression */ |
---|
1185 | TRACE_OPTION_COMPRESSTYPE_BZ2 = 2, /**< BZip2 Compression */ |
---|
1186 | TRACE_OPTION_COMPRESSTYPE_LZO = 3 /**< LZO Compression */ |
---|
1187 | } trace_option_compresstype_t; |
---|
1188 | |
---|
1189 | /** Valid configuration options for output traces */ |
---|
1190 | typedef enum { |
---|
1191 | /** File flags to use when opening an output file, e.g. O_APPEND */ |
---|
1192 | TRACE_OPTION_OUTPUT_FILEFLAGS, |
---|
1193 | /** Compression level: 0 = no compression, 1 = faster compression, |
---|
1194 | * 9 = better compression */ |
---|
1195 | TRACE_OPTION_OUTPUT_COMPRESS, |
---|
1196 | /** Compression type, see trace_option_compresstype_t */ |
---|
1197 | TRACE_OPTION_OUTPUT_COMPRESSTYPE |
---|
1198 | } trace_option_output_t; |
---|
1199 | |
---|
1200 | /** Sets an output config option |
---|
1201 | * |
---|
1202 | * @param libtrace The output trace object to apply the option to |
---|
1203 | * @param option The option to set |
---|
1204 | * @param value The value to set the option to |
---|
1205 | * @return -1 if option configuration failed, 0 otherwise |
---|
1206 | * This should be called after trace_create_output, and before |
---|
1207 | * trace_start_output |
---|
1208 | */ |
---|
1209 | DLLEXPORT int trace_config_output(libtrace_out_t *libtrace, |
---|
1210 | trace_option_output_t option, |
---|
1211 | void *value |
---|
1212 | ); |
---|
1213 | |
---|
1214 | /** Close an input trace, freeing up any resources it may have been using |
---|
1215 | * |
---|
1216 | * @param trace The input trace to be destroyed |
---|
1217 | * |
---|
1218 | */ |
---|
1219 | DLLEXPORT void trace_destroy(libtrace_t *trace); |
---|
1220 | |
---|
1221 | /** Close a dummy trace file, freeing up any resources it may have been using |
---|
1222 | * @param trace The dummy trace to be destroyed |
---|
1223 | */ |
---|
1224 | DLLEXPORT void trace_destroy_dead(libtrace_t *trace); |
---|
1225 | |
---|
1226 | /** Close an output trace, freeing up any resources it may have been using |
---|
1227 | * @param trace The output trace to be destroyed |
---|
1228 | */ |
---|
1229 | DLLEXPORT void trace_destroy_output(libtrace_out_t *trace); |
---|
1230 | |
---|
1231 | /** Check (and clear) the current error state of an input trace |
---|
1232 | * @param trace The input trace to check the error state on |
---|
1233 | * @return The current error status and message |
---|
1234 | * |
---|
1235 | * This reads and returns the current error state and sets the current error |
---|
1236 | * to "no error". |
---|
1237 | */ |
---|
1238 | DLLEXPORT libtrace_err_t trace_get_err(libtrace_t *trace); |
---|
1239 | |
---|
1240 | /** Indicate if there has been an error on an input trace |
---|
1241 | * @param trace The input trace to check the error state on |
---|
1242 | * @return true if an error has occurred, false otherwise |
---|
1243 | * |
---|
1244 | * @note This does not clear the error status, and only returns true or false. |
---|
1245 | */ |
---|
1246 | DLLEXPORT bool trace_is_err(libtrace_t *trace); |
---|
1247 | |
---|
1248 | /** Outputs the error message for an input trace to stderr and clear the error |
---|
1249 | * status. |
---|
1250 | * @param trace The input trace with the error to output |
---|
1251 | * @param msg The message to prepend to the error |
---|
1252 | * |
---|
1253 | * This function does clear the error status. |
---|
1254 | */ |
---|
1255 | DLLEXPORT void trace_perror(libtrace_t *trace, const char *msg,...) PRINTF(2,3); |
---|
1256 | |
---|
1257 | /** Checks (and clears) the current error state for an output trace |
---|
1258 | * @param trace The output trace to check the error state on |
---|
1259 | * @return The current error status and message |
---|
1260 | * |
---|
1261 | * This reads and returns the current error state and sets the current error |
---|
1262 | * to "no error". |
---|
1263 | */ |
---|
1264 | DLLEXPORT libtrace_err_t trace_get_err_output(libtrace_out_t *trace); |
---|
1265 | |
---|
1266 | /** Indicates if there is an error on an output trace |
---|
1267 | * @param trace The output trace to check the error state on |
---|
1268 | * @return true if an error has occurred, false otherwise. |
---|
1269 | * |
---|
1270 | * This does not clear the error status, and only returns true or false. |
---|
1271 | */ |
---|
1272 | DLLEXPORT bool trace_is_err_output(libtrace_out_t *trace); |
---|
1273 | |
---|
1274 | /** Outputs the error message for an output trace to stderr and clear the error |
---|
1275 | * status. |
---|
1276 | * @param trace The output trace with the error to output |
---|
1277 | * @param msg The message to prepend to the error |
---|
1278 | * This function does clear the error status. |
---|
1279 | */ |
---|
1280 | DLLEXPORT void trace_perror_output(libtrace_out_t *trace, const char *msg,...) |
---|
1281 | PRINTF(2,3); |
---|
1282 | |
---|
1283 | /** Returns the number of packets observed on an input trace. |
---|
1284 | * Includes the number of packets counted as early as possible, before |
---|
1285 | * filtering, and includes dropped packets. |
---|
1286 | * |
---|
1287 | * @param trace The input trace to examine |
---|
1288 | * @returns The number of packets seen at the capture point before filtering. |
---|
1289 | * |
---|
1290 | * If the number is not known, this function will return UINT64_MAX |
---|
1291 | */ |
---|
1292 | DLLEXPORT |
---|
1293 | uint64_t trace_get_received_packets(libtrace_t *trace); |
---|
1294 | |
---|
1295 | /** Returns the number of packets that were captured, but discarded for not |
---|
1296 | * matching a provided filter. |
---|
1297 | * |
---|
1298 | * @param trace The input trace to examine |
---|
1299 | * @returns The number of packets that were successfully captured, but filtered |
---|
1300 | * |
---|
1301 | * If the number is not known, this function will return UINT64_MAX |
---|
1302 | */ |
---|
1303 | DLLEXPORT |
---|
1304 | uint64_t trace_get_filtered_packets(libtrace_t *trace); |
---|
1305 | |
---|
1306 | /** Returns the number of packets that have been dropped on an input trace due |
---|
1307 | * to lack of buffer space on the capturing device. |
---|
1308 | * |
---|
1309 | * @param trace The input trace to examine |
---|
1310 | * @returns The number of packets captured, but dropped due to buffer overruns |
---|
1311 | * |
---|
1312 | * If the number is not known, this function will return UINT64_MAX |
---|
1313 | */ |
---|
1314 | DLLEXPORT |
---|
1315 | uint64_t trace_get_dropped_packets(libtrace_t *trace); |
---|
1316 | |
---|
1317 | /** Returns the number of packets that have been read from the input trace using |
---|
1318 | * trace_read_packet(). |
---|
1319 | * |
---|
1320 | * @param trace The input trace to examine |
---|
1321 | * @returns The number of packets that have been read by the libtrace user. |
---|
1322 | * |
---|
1323 | * If the number is not known, this function will return UINT64_MAX |
---|
1324 | */ |
---|
1325 | DLLEXPORT |
---|
1326 | uint64_t trace_get_accepted_packets(libtrace_t *trace); |
---|
1327 | |
---|
1328 | |
---|
1329 | /*@}*/ |
---|
1330 | |
---|
1331 | /** @name Reading / Writing packets |
---|
1332 | * These members deal with creating, reading and writing packets |
---|
1333 | * |
---|
1334 | * @{ |
---|
1335 | */ |
---|
1336 | |
---|
1337 | /** Create a new packet object |
---|
1338 | * |
---|
1339 | * @return A pointer to an initialised libtrace_packet_t object |
---|
1340 | */ |
---|
1341 | DLLEXPORT libtrace_packet_t *trace_create_packet(void); |
---|
1342 | |
---|
1343 | /** Copy a packet object |
---|
1344 | * @param packet The source packet to copy |
---|
1345 | * @return A new packet which has the same content as the source packet |
---|
1346 | * |
---|
1347 | * @note This always involves a copy, which can be slow. Use of this |
---|
1348 | * function should be avoided where possible. |
---|
1349 | * |
---|
1350 | * @par The reason you would want to use this function is that a zerocopied |
---|
1351 | * packet from a device will be stored using memory owned by the device which |
---|
1352 | * may be a limited resource. Copying the packet will ensure that the packet |
---|
1353 | * is now stored in memory owned and managed by libtrace. |
---|
1354 | */ |
---|
1355 | DLLEXPORT libtrace_packet_t *trace_copy_packet(const libtrace_packet_t *packet); |
---|
1356 | |
---|
1357 | /** Destroy a packet object |
---|
1358 | * @param packet The packet to be destroyed |
---|
1359 | * |
---|
1360 | */ |
---|
1361 | DLLEXPORT void trace_destroy_packet(libtrace_packet_t *packet); |
---|
1362 | |
---|
1363 | |
---|
1364 | /** Read the next packet from an input trace |
---|
1365 | * |
---|
1366 | * @param trace The libtrace opaque pointer for the input trace |
---|
1367 | * @param packet The packet opaque pointer |
---|
1368 | * @return 0 on EOF, negative value on error, number of bytes read when successful. |
---|
1369 | * |
---|
1370 | * @note The number of bytes read is usually (but not always) the same as |
---|
1371 | * trace_get_framing_length()+trace_get_capture_length() depending on the |
---|
1372 | * trace format. |
---|
1373 | * |
---|
1374 | * @note The trace must have been started with trace_start before calling |
---|
1375 | * this function |
---|
1376 | * |
---|
1377 | * @note When reading from a live capture, this function will block until a |
---|
1378 | * packet is observed on the capture interface. The libtrace event API |
---|
1379 | * (e.g. trace_event()) should be used if non-blocking operation is required. |
---|
1380 | */ |
---|
1381 | DLLEXPORT int trace_read_packet(libtrace_t *trace, libtrace_packet_t *packet); |
---|
1382 | |
---|
1383 | /** Event types |
---|
1384 | * see \ref libtrace_eventobj_t and \ref trace_event |
---|
1385 | */ |
---|
1386 | typedef enum { |
---|
1387 | TRACE_EVENT_IOWAIT, /**< Wait on the given file descriptor */ |
---|
1388 | TRACE_EVENT_SLEEP, /**< Sleep for the given amount of time */ |
---|
1389 | TRACE_EVENT_PACKET, /**< Packet has been read from input trace */ |
---|
1390 | TRACE_EVENT_TERMINATE /**< End of input trace */ |
---|
1391 | } libtrace_event_t; |
---|
1392 | |
---|
1393 | /** Structure returned by libtrace_event explaining what the current event is */ |
---|
1394 | typedef struct libtrace_eventobj_t { |
---|
1395 | libtrace_event_t type; /**< Event type (iowait,sleep,packet) */ |
---|
1396 | |
---|
1397 | /** If the event is IOWAIT, the file descriptor to wait on */ |
---|
1398 | int fd; |
---|
1399 | /** If the event is SLEEP, the amount of time to sleep for in seconds */ |
---|
1400 | double seconds; |
---|
1401 | /** If the event is PACKET, the value returned by trace_read_packet() */ |
---|
1402 | int size; |
---|
1403 | } libtrace_eventobj_t; |
---|
1404 | |
---|
1405 | /** Processes the next libtrace event from an input trace. |
---|
1406 | * @param trace The libtrace opaque pointer for the input trace |
---|
1407 | * @param packet The libtrace_packet opaque pointer to use for reading packets |
---|
1408 | * @return A libtrace_event struct containing the event type and details of the event. |
---|
1409 | * |
---|
1410 | * Type can be: |
---|
1411 | * TRACE_EVENT_IOWAIT Waiting on I/O on a file descriptor |
---|
1412 | * TRACE_EVENT_SLEEP Wait a specified amount of time for the next event |
---|
1413 | * TRACE_EVENT_PACKET Packet was read from the trace |
---|
1414 | * TRACE_EVENT_TERMINATE Trace terminated (perhaps with an error condition) |
---|
1415 | */ |
---|
1416 | DLLEXPORT libtrace_eventobj_t trace_event(libtrace_t *trace, |
---|
1417 | libtrace_packet_t *packet); |
---|
1418 | |
---|
1419 | |
---|
1420 | /** Write one packet out to the output trace |
---|
1421 | * |
---|
1422 | * @param trace The libtrace_out opaque pointer for the output trace |
---|
1423 | * @param packet The packet opaque pointer of the packet to be written |
---|
1424 | * @return The number of bytes written out, if zero or negative then an error has occured. |
---|
1425 | */ |
---|
1426 | DLLEXPORT int trace_write_packet(libtrace_out_t *trace, libtrace_packet_t *packet); |
---|
1427 | |
---|
1428 | /** Gets the capture format for a given packet. |
---|
1429 | * @param packet The packet to get the capture format for. |
---|
1430 | * @return The capture format of the packet |
---|
1431 | * |
---|
1432 | * @note Due to ability to convert packets between formats relatively easily |
---|
1433 | * in Libtrace, the format of the packet right now may not be the format that |
---|
1434 | * the packet was originally captured with. |
---|
1435 | */ |
---|
1436 | DLLEXPORT |
---|
1437 | enum base_format_t trace_get_format(struct libtrace_packet_t *packet); |
---|
1438 | |
---|
1439 | /** Construct a libtrace packet from a buffer containing the packet payload. |
---|
1440 | * @param[in,out] packet Libtrace Packet object to update with the new |
---|
1441 | * data. |
---|
1442 | * @param linktype The linktype of the packet data. |
---|
1443 | * @param[in] data The packet data (including linklayer). |
---|
1444 | * @param len Length of packet data provided in the buffer. |
---|
1445 | * |
---|
1446 | * @note The constructed packet will be in the PCAP format. |
---|
1447 | * |
---|
1448 | * @note To be useful, the provided buffer must start with the layer 2 header |
---|
1449 | * (or a metadata header, if desired). |
---|
1450 | */ |
---|
1451 | DLLEXPORT |
---|
1452 | void trace_construct_packet(libtrace_packet_t *packet, |
---|
1453 | libtrace_linktype_t linktype, const void *data, uint16_t len); |
---|
1454 | |
---|
1455 | /*@}*/ |
---|
1456 | |
---|
1457 | /** @name Protocol decodes |
---|
1458 | * These functions locate and return a pointer to various headers inside a |
---|
1459 | * packet |
---|
1460 | * |
---|
1461 | * A packet is divided up into several "layers.": |
---|
1462 | * |
---|
1463 | * @li Framing header -- This is the header provided by the capture format |
---|
1464 | * itself rather than anything that was sent over the network. This provides |
---|
1465 | * basic details about the packet record including capture lengths, wire |
---|
1466 | * lengths, timestamps, direction information and any other metadata that is |
---|
1467 | * part of the capture format. |
---|
1468 | * |
---|
1469 | * @li Metadata header (optional) -- A header containing metadata about a |
---|
1470 | * packet that was captured, but the metadata was not transmitted over the |
---|
1471 | * wire. Some examples include RadioTap and Linux_sll headers. This can be |
---|
1472 | * retrieved by trace_get_packet_meta(), or skipped using |
---|
1473 | * trace_get_payload_from_meta(). There may be multiple "metadata" headers on |
---|
1474 | * a packet. |
---|
1475 | * |
---|
1476 | * @li Layer 2/Link layer/Datalink header -- This can be retrieved by |
---|
1477 | * trace_get_layer2(), or skipped using trace_get_payload_from_layer2(). |
---|
1478 | * |
---|
1479 | * @li Layer 3/IP/IPv6 -- This can be retrieved by trace_get_layer3(). As a |
---|
1480 | * convenience trace_get_ip()/trace_get_ip6() can be used to find an IPv4/IPv6 |
---|
1481 | * header. |
---|
1482 | * |
---|
1483 | * @li Layer 5/transport -- These are protocols carried in IPv4/IPv6 frames. |
---|
1484 | * These can be retrieved using trace_get_transport(). |
---|
1485 | * |
---|
1486 | * @{ |
---|
1487 | */ |
---|
1488 | |
---|
1489 | |
---|
1490 | /** Gets a pointer to the first byte of the packet as it was captured and |
---|
1491 | * returns its corresponding linktype and capture length. |
---|
1492 | * |
---|
1493 | * Use this function instead of the deprecated trace_get_link(). |
---|
1494 | * |
---|
1495 | * @param packet The packet to get the buffer from |
---|
1496 | * @param[out] linktype The linktype of the returned pointer |
---|
1497 | * @param[out] remaining The capture length (the number of captured bytes from |
---|
1498 | * the returned pointer) |
---|
1499 | * @return A pointer to the first byte of the packet |
---|
1500 | */ |
---|
1501 | DLLEXPORT void *trace_get_packet_buffer(const libtrace_packet_t *packet, |
---|
1502 | libtrace_linktype_t *linktype, uint32_t *remaining); |
---|
1503 | |
---|
1504 | /** Get a pointer to the link layer for a given packet |
---|
1505 | * @param packet The packet to get the link layer for |
---|
1506 | * |
---|
1507 | * @return A pointer to the link layer, or NULL if there is no link layer |
---|
1508 | * |
---|
1509 | * @deprecated This function is deprecated: Use trace_get_packet_buffer() or |
---|
1510 | * one of the trace_get_layer*() functions instead. |
---|
1511 | * @note You should call trace_get_link_type to find out what type of link |
---|
1512 | * layer has been returned to you. |
---|
1513 | */ |
---|
1514 | DLLEXPORT SIMPLE_FUNCTION DEPRECATED |
---|
1515 | void *trace_get_link(const libtrace_packet_t *packet); |
---|
1516 | |
---|
1517 | /** Get a pointer to the IPv4 header (if any) for a given packet |
---|
1518 | * @param packet The packet to get the IPv4 header for |
---|
1519 | * |
---|
1520 | * @return A pointer to the IPv4 header, or NULL if there is no IPv4 header |
---|
1521 | * |
---|
1522 | * If a partial IP header is present, i.e. the packet has been truncated before |
---|
1523 | * the end of the IP header, this function will return NULL. |
---|
1524 | * |
---|
1525 | * You should consider using \ref trace_get_layer3 instead of this function. |
---|
1526 | */ |
---|
1527 | DLLEXPORT SIMPLE_FUNCTION |
---|
1528 | libtrace_ip_t *trace_get_ip(libtrace_packet_t *packet); |
---|
1529 | |
---|
1530 | /** get a pointer to the IPv6 header (if any) |
---|
1531 | * @param packet The packet to get the IPv6 header for |
---|
1532 | * |
---|
1533 | * @return A pointer to the IPv6 header, or NULL if there is no IPv6 header |
---|
1534 | * |
---|
1535 | * If a partial IPv6 header is present, i.e. the packet has been truncated |
---|
1536 | * before the end of the IP header, this function will return NULL. |
---|
1537 | * |
---|
1538 | * You should consider using \ref trace_get_layer3 instead of this function. |
---|
1539 | */ |
---|
1540 | DLLEXPORT SIMPLE_FUNCTION |
---|
1541 | libtrace_ip6_t *trace_get_ip6(libtrace_packet_t *packet); |
---|
1542 | |
---|
1543 | /** Return a pointer to the first metadata header in a packet, if present. |
---|
1544 | * |
---|
1545 | * This function takes a pointer to a libtrace packet and if any metadata |
---|
1546 | * headers exist, returns a pointer to the first one, along with its |
---|
1547 | * corresponding linktype. |
---|
1548 | * |
---|
1549 | * If no metadata headers exist in the packet, NULL is returned. |
---|
1550 | * |
---|
1551 | * A metadata header is a header that was prepended by the capturing device, |
---|
1552 | * such as a Linux SLL header, or a Radiotap wireless monitoring header. |
---|
1553 | * Subsequent metadata headers may be accessed with the |
---|
1554 | * trace_get_payload_from_meta(...) function. |
---|
1555 | * |
---|
1556 | * @param packet The libtrace packet |
---|
1557 | * @param[out] linktype The linktype of the returned metadata header |
---|
1558 | * @param[out] remaining The number of bytes captured after the returned |
---|
1559 | * pointer. |
---|
1560 | * @return A pointer to the first metadata header, or NULL if there are no |
---|
1561 | * metadata headers present. |
---|
1562 | * |
---|
1563 | * remaining may be NULL, however linktype must be provided. |
---|
1564 | */ |
---|
1565 | DLLEXPORT void *trace_get_packet_meta(const libtrace_packet_t *packet, |
---|
1566 | libtrace_linktype_t *linktype, |
---|
1567 | uint32_t *remaining); |
---|
1568 | |
---|
1569 | /** Returns the payload of a metadata header. |
---|
1570 | * |
---|
1571 | * This function takes a pointer to the start of a metadata header (either |
---|
1572 | * obtained via trace_get_packet_meta(...) or by a previous call to |
---|
1573 | * trace_get_payload_from_meta(...)) along with its corresponding linktype and |
---|
1574 | * returns the payload, i.e. the next header. It will also update the linktype |
---|
1575 | * parameter to indicate the type of payload. |
---|
1576 | * |
---|
1577 | * If the linktype indicates that the header passed in is not a metadata |
---|
1578 | * header, the function returns NULL to indicate this. The linktype remains |
---|
1579 | * unchanged in this case. |
---|
1580 | * |
---|
1581 | * This function allows the user to iterate through metadata headers which are |
---|
1582 | * sometimes present before the actual packet as it was received on the wire. |
---|
1583 | * Examples of metadata headers include the Linux SLL header and the Radiotap |
---|
1584 | * wireless monitoring header. |
---|
1585 | * |
---|
1586 | * If the metadata header passed into this function is truncated, this |
---|
1587 | * function will return NULL, and remaining will be set to 0. |
---|
1588 | * |
---|
1589 | * If there are 0 bytes of payload following the provided metadata header, the |
---|
1590 | * function will return a pointer to where the header would otherwise be and |
---|
1591 | * remaining will be 0. |
---|
1592 | * |
---|
1593 | * Therefore, be sure to check the value of remaining after calling this |
---|
1594 | * function! |
---|
1595 | * |
---|
1596 | * @param[in] meta A pointer to a metadata header |
---|
1597 | * @param[in,out] linktype The linktype of meta (updated to indicate the |
---|
1598 | * linktype of the returned header if applicable). |
---|
1599 | * @param[in,out] remaining The number of bytes after the meta pointer. |
---|
1600 | * @return A pointer to the payload of the metadata header. If meta is not a |
---|
1601 | * pointer to a metadata header, NULL is returned and linktype remains |
---|
1602 | * unchanged. |
---|
1603 | * |
---|
1604 | * All parameters are mandatory. |
---|
1605 | */ |
---|
1606 | DLLEXPORT void *trace_get_payload_from_meta(const void *meta, |
---|
1607 | libtrace_linktype_t *linktype, |
---|
1608 | uint32_t *remaining); |
---|
1609 | |
---|
1610 | |
---|
1611 | /** Get a pointer to the layer 2 header. Generally this is the first byte of the |
---|
1612 | * packet as it was seen on the wire. |
---|
1613 | * |
---|
1614 | * This function takes a libtrace packet and skips over any metadata headers if |
---|
1615 | * present (such as Linux SLL or Radiotap) and returns a pointer to the first |
---|
1616 | * byte of the packet that was actually received by the network interface. |
---|
1617 | * |
---|
1618 | * @param packet The libtrace packet to find the layer 2 header for |
---|
1619 | * @param[out] linktype The linktype of the returned layer 2 header |
---|
1620 | * @param[out] remaining The number of bytes left in the packet after the |
---|
1621 | * returned pointer. |
---|
1622 | * @return A pointer to the first byte of the packet as it was seen on the |
---|
1623 | * wire. If no layer 2 header is present, this function will return NULL. |
---|
1624 | * |
---|
1625 | * remaining may be NULL, otherwise it will be filled in by the function. |
---|
1626 | */ |
---|
1627 | DLLEXPORT void *trace_get_layer2(const libtrace_packet_t *packet, |
---|
1628 | libtrace_linktype_t *linktype, |
---|
1629 | uint32_t *remaining); |
---|
1630 | |
---|
1631 | /** Gets a pointer to the next header following a layer 2 header |
---|
1632 | * |
---|
1633 | * @param l2 The pointer to the current layer 2 header |
---|
1634 | * @param linktype The type of the layer 2 header |
---|
1635 | * @param[out] ethertype An optional output variable of the ethernet type of the new header |
---|
1636 | * @param[in,out] remaining Updated with the number of captured bytes |
---|
1637 | remaining |
---|
1638 | * |
---|
1639 | * @return A pointer to the header following the provided layer 2 header, or |
---|
1640 | * NULL if no subsequent header is present. |
---|
1641 | * |
---|
1642 | * Remaining must point to the number of bytes captured from the layer 2 header |
---|
1643 | * and beyond. It will be decremented by the number of bytes skipped to find |
---|
1644 | * the payload. |
---|
1645 | * |
---|
1646 | * If the layer 2 header is complete but there are zero bytes of payload after |
---|
1647 | * the end of the header, a pointer to where the payload would be is returned |
---|
1648 | * and remaining will be set to 0. If the layer 2 header is incomplete |
---|
1649 | * (truncated), then NULL is returned and remaining will be set to 0. |
---|
1650 | * Therefore, it is very important to check the value of remaining after |
---|
1651 | * calling this function. |
---|
1652 | * |
---|
1653 | */ |
---|
1654 | DLLEXPORT void *trace_get_payload_from_layer2(void *l2, |
---|
1655 | libtrace_linktype_t linktype, |
---|
1656 | uint16_t *ethertype, |
---|
1657 | uint32_t *remaining); |
---|
1658 | |
---|
1659 | |
---|
1660 | /** Get a pointer to the layer 3 (e.g. IP) header. |
---|
1661 | * @param packet The libtrace packet to find the layer 3 header for |
---|
1662 | * @param[out] ethertype The ethertype of the layer 3 header |
---|
1663 | * @param[out] remaining The amount of captured data remaining in the packet starting from the returned pointer, i.e. including the layer 3 header. |
---|
1664 | * |
---|
1665 | * @return A pointer to the layer 3 header. If no layer 3 header is present in |
---|
1666 | * the packet, NULL is returned. If the layer 3 header is truncated, a valid |
---|
1667 | * pointer will still be returned so be sure to check the value of remaining |
---|
1668 | * before attempting to process the returned header. |
---|
1669 | * |
---|
1670 | * remaining may be NULL, otherwise it will be set to the number of captured |
---|
1671 | * bytes after the pointer returned. |
---|
1672 | */ |
---|
1673 | DLLEXPORT |
---|
1674 | void *trace_get_layer3(const libtrace_packet_t *packet, |
---|
1675 | uint16_t *ethertype, uint32_t *remaining); |
---|
1676 | |
---|
1677 | /** Calculates the expected IP checksum for a packet. |
---|
1678 | * @param packet The libtrace packet to calculate the checksum for |
---|
1679 | * @param[out] csum The checksum that is calculated by this function. This |
---|
1680 | * may not be NULL. |
---|
1681 | * |
---|
1682 | * @return A pointer to the original checksum field within the IP |
---|
1683 | * header. If the checksum field is not present in the packet, NULL is returned. |
---|
1684 | * |
---|
1685 | * @note The return value points to the checksum that exists within the current |
---|
1686 | * packet. The value in csum is the value that the checksum should be, given |
---|
1687 | * the current packet contents. |
---|
1688 | * |
---|
1689 | * @note This function involves the use of a memcpy, so be careful about |
---|
1690 | * calling it excessively if performance is a concern for you. |
---|
1691 | * |
---|
1692 | * New in libtrace 3.0.17 |
---|
1693 | */ |
---|
1694 | DLLEXPORT uint16_t *trace_checksum_layer3(libtrace_packet_t *packet, |
---|
1695 | uint16_t *csum); |
---|
1696 | |
---|
1697 | /** Calculates the expected checksum for the transport header in a packet. |
---|
1698 | * @param packet The libtrace packet to calculate the checksum for |
---|
1699 | * @param[out] csum The checksum that is calculated by this function. This |
---|
1700 | * may not be NULL. |
---|
1701 | * |
---|
1702 | * @return A pointer to the original checksum field within the transport |
---|
1703 | * header. If the checksum field is not present in the packet, NULL is returned. |
---|
1704 | * |
---|
1705 | * @note The return value points to the checksum that exists within the current |
---|
1706 | * packet. The value in csum is the value that the checksum should be, given |
---|
1707 | * the current packet contents. |
---|
1708 | * |
---|
1709 | * @note This function involves the use of a memcpy, so be careful about |
---|
1710 | * calling it excessively if performance is a concern for you. |
---|
1711 | * |
---|
1712 | * @note Because transport checksums are calculated across the entire payload, |
---|
1713 | * truncated packets will result in NULL being returned. |
---|
1714 | * |
---|
1715 | * This function will determine the appropriate checksum for whatever transport |
---|
1716 | * layer header is present in the provided packet. At this stage, this only |
---|
1717 | * currently works for TCP, UDP and ICMP packets. |
---|
1718 | * |
---|
1719 | * Be wary of TCP checksum offloading if you are examining the checksum of |
---|
1720 | * packets captured on the same host that generated them! |
---|
1721 | * |
---|
1722 | * New in libtrace 3.0.17 |
---|
1723 | */ |
---|
1724 | DLLEXPORT uint16_t *trace_checksum_transport(libtrace_packet_t *packet, |
---|
1725 | uint16_t *csum); |
---|
1726 | |
---|
1727 | /** Gets a pointer to the transport layer header (if any) |
---|
1728 | * @param packet The libtrace packet to find the transport header for |
---|
1729 | * @param[out] proto The protocol present at the transport layer. |
---|
1730 | * @param[out] remaining The amount of captured data remaining in the packet |
---|
1731 | * starting from the returned pointer, i.e. including the transport header. |
---|
1732 | * |
---|
1733 | * @return A pointer to the transport layer header. If no transport header is |
---|
1734 | * present in the packet, NULL is returned. If the transport header is |
---|
1735 | * truncated, a valid pointer will still be returned so be sure to check the |
---|
1736 | * value of remaining before attempting to process the returned header. |
---|
1737 | * |
---|
1738 | * remaining may be NULL, otherwise it will be set to the number of captured |
---|
1739 | * bytes after the returned pointer. |
---|
1740 | * |
---|
1741 | * @note proto may be NULL if proto is unneeded. |
---|
1742 | */ |
---|
1743 | DLLEXPORT void *trace_get_transport(const libtrace_packet_t *packet, |
---|
1744 | uint8_t *proto, uint32_t *remaining); |
---|
1745 | |
---|
1746 | /** Gets a pointer to the payload following an IPv4 header |
---|
1747 | * @param ip The IPv4 Header |
---|
1748 | * @param[out] proto The protocol of the header following the IPv4 header |
---|
1749 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
1750 | * |
---|
1751 | * @return A pointer to the transport layer header, or NULL if no subsequent |
---|
1752 | * header is present. |
---|
1753 | * |
---|
1754 | * When calling this function, remaining must contain the number of captured |
---|
1755 | * bytes remaining in the packet starting from the IPv4 header (including the |
---|
1756 | * IPv4 header itself). |
---|
1757 | * |
---|
1758 | * remaining will be decremented by the size of the IPv4 header (including any |
---|
1759 | * options). If the IPv4 header is complete but there are zero bytes of payload |
---|
1760 | * after the IPv4 header, a pointer to where the payload would be is returned |
---|
1761 | * and remaining will be set to 0. If the IPv4 header is incomplete, NULL will |
---|
1762 | * be returned and remaining will be set to 0. Therefore, it is very important |
---|
1763 | * to check the value of remaining after calling this function. |
---|
1764 | * |
---|
1765 | * proto may be NULL, in which case it won't be updated. |
---|
1766 | * |
---|
1767 | * @note This is similar to trace_get_transport_from_ip in libtrace2 |
---|
1768 | */ |
---|
1769 | DLLEXPORT void *trace_get_payload_from_ip(libtrace_ip_t *ip, uint8_t *proto, |
---|
1770 | uint32_t *remaining); |
---|
1771 | |
---|
1772 | /** Gets a pointer to the payload following an IPv6 header |
---|
1773 | * @param ipptr The IPv6 Header |
---|
1774 | * @param[out] proto The protocol of the header following the IPv6 header |
---|
1775 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
1776 | * |
---|
1777 | * @return A pointer to the transport layer header, or NULL if no subsequent |
---|
1778 | * header is present. |
---|
1779 | * |
---|
1780 | * When calling this function, remaining must contain the number of captured |
---|
1781 | * bytes remaining in the packet starting from the IPv6 header (including the |
---|
1782 | * IPv6 header itself). |
---|
1783 | * |
---|
1784 | * remaining will be decremented by the size of the IPv6 header (including any |
---|
1785 | * options). If the IPv6 header is complete but there are zero bytes of payload |
---|
1786 | * after the IPv6 header, a pointer to where the payload would be is returned |
---|
1787 | * and remaining will be set to 0. If the IPv6 header is incomplete, NULL will |
---|
1788 | * be returned and remaining will be set to 0. Therefore, it is very important |
---|
1789 | * to check the value of remaining after calling this function. |
---|
1790 | * |
---|
1791 | * proto may be NULL, in which case it won't be updated. |
---|
1792 | * |
---|
1793 | */ |
---|
1794 | DLLEXPORT void *trace_get_payload_from_ip6(libtrace_ip6_t *ipptr, |
---|
1795 | uint8_t *proto, uint32_t *remaining); |
---|
1796 | |
---|
1797 | /** Gets a pointer to the payload following a link header |
---|
1798 | * @param linkptr A pointer to the link layer header |
---|
1799 | * @param linktype The linktype of the link header being examined |
---|
1800 | * @param[out] type An output variable for the ethernet type |
---|
1801 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
1802 | * |
---|
1803 | * @return A pointer to the header following the link header, or NULL if no |
---|
1804 | * subsequent header is present. |
---|
1805 | * |
---|
1806 | * When calling this function, remaining must contain the number of captured |
---|
1807 | * bytes remaining in the packet starting from the link header (including the |
---|
1808 | * link header itself). remaining will be updated to contain the number of |
---|
1809 | * bytes remaining after the link header has been skipped. |
---|
1810 | * |
---|
1811 | * @deprecated This function is deprecated: you should be using |
---|
1812 | * trace_get_payload_from_layer2() or trace_get_payload_from_meta() instead. |
---|
1813 | * |
---|
1814 | */ |
---|
1815 | DLLEXPORT void *trace_get_payload_from_link(void *linkptr, |
---|
1816 | libtrace_linktype_t linktype, |
---|
1817 | uint16_t *type, uint32_t *remaining); |
---|
1818 | |
---|
1819 | /** Gets a pointer to the payload following an 802.1q (VLAN) header. |
---|
1820 | * @param vlan A pointer to the VLAN header |
---|
1821 | * @param[out] type The ethernet type, replaced with the VLAN ether type |
---|
1822 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
1823 | * |
---|
1824 | * @return A pointer to the header beyond the VLAN header, if one is present. |
---|
1825 | * Otherwise, returns NULL. |
---|
1826 | * |
---|
1827 | * When calling this function, remaining must contain the number of captured |
---|
1828 | * bytes remaining in the packet starting from the VLAN header (including the |
---|
1829 | * VLAN header itself). remaining will be updated to contain the number of |
---|
1830 | * bytes remaining after the VLAN header has been skipped. |
---|
1831 | * |
---|
1832 | * If the VLAN header is complete but there are zero bytes of payload after |
---|
1833 | * the VLAN header, a pointer to where the payload would be is returned and |
---|
1834 | * remaining will be set to 0. If the VLAN header is incomplete, NULL will be |
---|
1835 | * returned and remaining will be set to 0. Therefore, it is important to check |
---|
1836 | * the value of remaining after calling this function. |
---|
1837 | * |
---|
1838 | * type will be set to the ethertype of the VLAN payload. This parameter is not |
---|
1839 | * mandatory, but is highly recommended. |
---|
1840 | * |
---|
1841 | */ |
---|
1842 | DLLEXPORT void *trace_get_payload_from_vlan( |
---|
1843 | void *vlan, uint16_t *type, uint32_t *remaining); |
---|
1844 | |
---|
1845 | /** Gets a pointer to the payload following an MPLS header. |
---|
1846 | * @param mpls A pointer to the MPLS header |
---|
1847 | * @param[out] type The ethernet type, replaced by the ether type of the |
---|
1848 | * returned header - 0x0000 if an Ethernet header is returned |
---|
1849 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
1850 | * |
---|
1851 | * @return A pointer to the header beyond the MPLS label, if one is present. |
---|
1852 | * Will return NULL if there is not enough bytes remaining to skip past the |
---|
1853 | * MPLS label. |
---|
1854 | * |
---|
1855 | * When calling this function, remaining must contain the number of captured |
---|
1856 | * bytes remaining in the packet starting from the MPLS header (including the |
---|
1857 | * MPLS header itself). remaining will be updated to contain the number of |
---|
1858 | * bytes remaining after the MPLS header has been skipped. |
---|
1859 | * |
---|
1860 | * If the MPLS header is complete but there are zero bytes of payload after |
---|
1861 | * the MPLS header, a pointer to where the payload would be is returned and |
---|
1862 | * remaining will be set to 0. If the MPLS header is incomplete, NULL will be |
---|
1863 | * returned and remaining will be set to 0. Therefore, it is important to check |
---|
1864 | * the value of remaining after calling this function. |
---|
1865 | * |
---|
1866 | * type will be set to the ethertype of the MPLS payload. This parameter is |
---|
1867 | * mandatory - it may not be NULL. |
---|
1868 | * |
---|
1869 | * @note This function will only remove one MPLS label at a time - the type |
---|
1870 | * will be set to 0x8847 if there is another MPLS label following the one |
---|
1871 | * skipped by this function. |
---|
1872 | * |
---|
1873 | */ |
---|
1874 | DLLEXPORT void *trace_get_payload_from_mpls( |
---|
1875 | void *mpls, uint16_t *type, uint32_t *remaining); |
---|
1876 | |
---|
1877 | /** Gets a pointer to the payload following a PPPoE header |
---|
1878 | * @param pppoe A pointer to the PPPoE header |
---|
1879 | * @param[out] type The ethernet type, replaced by the ether type of the |
---|
1880 | * returned header - 0x0000 if an Ethernet header is returned |
---|
1881 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
1882 | * |
---|
1883 | * @return A pointer to the header beyond the PPPoE header. NOTE that this |
---|
1884 | * function will also skip over the PPP header that will immediately follow |
---|
1885 | * the PPPoE header. This function will return NULL if there are not enough |
---|
1886 | * bytes remaining to skip past both the PPPoE and PPP headers. |
---|
1887 | * |
---|
1888 | * When calling this function, remaining must contain the number of captured |
---|
1889 | * bytes remaining in the packet starting from the PPPoE header (including the |
---|
1890 | * PPPoE header itself). remaining will be updated to contain the number of |
---|
1891 | * bytes remaining after the PPPoE and PPP headers have been removed. |
---|
1892 | * |
---|
1893 | * If the PPPoE and PPP headers are complete but there are zero bytes of |
---|
1894 | * payload after the PPP header, a pointer to where the payload would be is |
---|
1895 | * returned and remaining will be set to 0. If the PPPoE or PPP header is |
---|
1896 | * incomplete, NULL will be returned and remaining will be set to 0. Therefore, |
---|
1897 | * it is important to check the value of remaining after calling this function. |
---|
1898 | * |
---|
1899 | * type will be set to the ether type of the PPP payload. This parameter is |
---|
1900 | * mandatory - it may not be NULL. |
---|
1901 | * |
---|
1902 | */ |
---|
1903 | DLLEXPORT void *trace_get_payload_from_pppoe( |
---|
1904 | void *pppoe, uint16_t *type, uint32_t *remaining); |
---|
1905 | |
---|
1906 | /** Gets a pointer to the payload following a TCP header |
---|
1907 | * @param tcp A pointer to the TCP header |
---|
1908 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
1909 | * |
---|
1910 | * @return A pointer to the TCP payload, or NULL if the TCP header is truncated. |
---|
1911 | * |
---|
1912 | * When calling this function, remaining must contain the number of captured |
---|
1913 | * bytes remaining in the packet starting from the TCP header (including the |
---|
1914 | * TCP header itself). remaining will be updated to contain the number of |
---|
1915 | * bytes remaining after the TCP header has been skipped. |
---|
1916 | * |
---|
1917 | * If the TCP header is complete but there are zero bytes of payload after |
---|
1918 | * the TCP header, a pointer to where the payload would be is returned and |
---|
1919 | * remaining will be set to 0. If the TCP header is incomplete, NULL will be |
---|
1920 | * returned and remaining will be set to 0. Therefore, it is important to check |
---|
1921 | * the value of remaining after calling this function. |
---|
1922 | * |
---|
1923 | */ |
---|
1924 | DLLEXPORT void *trace_get_payload_from_tcp(libtrace_tcp_t *tcp, |
---|
1925 | uint32_t *remaining); |
---|
1926 | |
---|
1927 | /** Gets a pointer to the payload following a UDP header |
---|
1928 | * @param udp A pointer to the UDP header |
---|
1929 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
1930 | * |
---|
1931 | * @return A pointer to the UDP payload, or NULL if the UDP header is truncated. |
---|
1932 | * |
---|
1933 | * When calling this function, remaining must contain the number of captured |
---|
1934 | * bytes remaining in the packet starting from the UDP header (including the |
---|
1935 | * UDP header itself). remaining will be updated to contain the number of |
---|
1936 | * bytes remaining after the UDP header has been skipped. |
---|
1937 | * |
---|
1938 | * If the UDP header is complete but there are zero bytes of payload after |
---|
1939 | * the UDP header, a pointer to where the payload would be is returned and |
---|
1940 | * remaining will be set to 0. If the UDP header is incomplete, NULL will be |
---|
1941 | * returned and remaining will be set to 0. Therefore, it is important to check |
---|
1942 | * the value of remaining after calling this function. |
---|
1943 | * |
---|
1944 | */ |
---|
1945 | DLLEXPORT void *trace_get_payload_from_udp(libtrace_udp_t *udp, uint32_t *remaining); |
---|
1946 | |
---|
1947 | /** Gets a pointer to the payload following a ICMP header |
---|
1948 | * @param icmp A pointer to the ICMP header |
---|
1949 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
1950 | * |
---|
1951 | * @return A pointer to the ICMP payload, or NULL if the ICMP header is |
---|
1952 | * truncated. |
---|
1953 | * |
---|
1954 | * When calling this function, remaining must contain the number of captured |
---|
1955 | * bytes remaining in the packet starting from the ICMP header (including the |
---|
1956 | * ICMP header itself). remaining will be updated to contain the number of |
---|
1957 | * bytes remaining after the ICMP header has been skipped. |
---|
1958 | * |
---|
1959 | * If the ICMP header is complete but there are zero bytes of payload after |
---|
1960 | * the ICMP header, a pointer to where the payload would be is returned and |
---|
1961 | * remaining will be set to 0. If the ICMP header is incomplete, NULL will be |
---|
1962 | * returned and remaining will be set to 0. Therefore, it is important to check |
---|
1963 | * the value of remaining after calling this function. |
---|
1964 | * |
---|
1965 | * @note In the case of some ICMP messages, the payload may be the IP header |
---|
1966 | * from the packet that triggered the ICMP message. |
---|
1967 | * |
---|
1968 | */ |
---|
1969 | DLLEXPORT void *trace_get_payload_from_icmp(libtrace_icmp_t *icmp, |
---|
1970 | uint32_t *remaining); |
---|
1971 | |
---|
1972 | /** Gets a pointer to the payload following a ICMPv6 header |
---|
1973 | * @param icmp A pointer to the ICMPv6 header |
---|
1974 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
1975 | * |
---|
1976 | * @return A pointer to the ICMPv6 payload, or NULL if the ICMPv6 header is |
---|
1977 | * truncated. |
---|
1978 | * |
---|
1979 | * When calling this function, remaining must contain the number of captured |
---|
1980 | * bytes remaining in the packet starting from the ICMPv6 header (including the |
---|
1981 | * ICMP header itself). remaining will be updated to contain the number of |
---|
1982 | * bytes remaining after the ICMPv6 header has been skipped. |
---|
1983 | * |
---|
1984 | * If the ICMPv6 header is complete but there are zero bytes of payload after |
---|
1985 | * the header, a pointer to where the payload would be is returned and |
---|
1986 | * remaining will be set to 0. If the ICMPv6 header is incomplete, NULL will be |
---|
1987 | * returned and remaining will be set to 0. Therefore, it is important to check |
---|
1988 | * the value of remaining after calling this function. |
---|
1989 | * |
---|
1990 | * @note In the case of some ICMPv6 messages, the payload may be the IP header |
---|
1991 | * from the packet that triggered the ICMP message. |
---|
1992 | * |
---|
1993 | */ |
---|
1994 | DLLEXPORT void *trace_get_payload_from_icmp6(libtrace_icmp6_t *icmp, |
---|
1995 | uint32_t *remaining); |
---|
1996 | |
---|
1997 | /** Get a pointer to the TCP header (if present) |
---|
1998 | * @param packet The packet to get the TCP header from |
---|
1999 | * |
---|
2000 | * @return A pointer to the TCP header, or NULL if there is not a complete TCP |
---|
2001 | * header present in the packet. |
---|
2002 | * |
---|
2003 | * This is a short-cut function enabling quick and easy access to the TCP |
---|
2004 | * header if that is all you care about. However, we recommend the use of the |
---|
2005 | * more generic trace_get_transport() function instead. |
---|
2006 | * |
---|
2007 | * @note Unlike trace_get_transport(), this function will return NULL if the |
---|
2008 | * TCP header is incomplete or truncated. |
---|
2009 | */ |
---|
2010 | DLLEXPORT SIMPLE_FUNCTION |
---|
2011 | libtrace_tcp_t *trace_get_tcp(libtrace_packet_t *packet); |
---|
2012 | |
---|
2013 | /** Get a pointer to the TCP header following an IPv4 header (if present) |
---|
2014 | * @param ip The IP header to find the subsequent TCP header for |
---|
2015 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
2016 | * |
---|
2017 | * @return A pointer to the TCP header, or NULL if no TCP header is present in |
---|
2018 | * the packet. |
---|
2019 | * |
---|
2020 | * When calling this function, remaining must contain the number of captured |
---|
2021 | * bytes remaining in the packet starting from the IP header (including the |
---|
2022 | * IP header itself). remaining will be updated to contain the number of |
---|
2023 | * bytes remaining after the IP header has been skipped. |
---|
2024 | * |
---|
2025 | * If the IP header is complete but there are zero bytes of payload after |
---|
2026 | * the IP header, a pointer to where the payload would be is returned and |
---|
2027 | * remaining will be set to 0. If the IP header is incomplete, NULL will be |
---|
2028 | * returned and remaining will be set to 0. Therefore, it is important to check |
---|
2029 | * the value of remaining after calling this function. |
---|
2030 | * |
---|
2031 | * @note This function is rather redundant now that the layer 3 header is |
---|
2032 | * cached. There should be no performance advantage for the user to call this |
---|
2033 | * function over just calling trace_get_transport(). |
---|
2034 | * |
---|
2035 | * @note The last parameter has changed from libtrace2 |
---|
2036 | */ |
---|
2037 | DLLEXPORT SIMPLE_FUNCTION |
---|
2038 | libtrace_tcp_t *trace_get_tcp_from_ip(libtrace_ip_t *ip, uint32_t *remaining); |
---|
2039 | |
---|
2040 | /** Get a pointer to the UDP header (if present) |
---|
2041 | * @param packet The packet to get the UDP header from |
---|
2042 | * |
---|
2043 | * @return A pointer to the UDP header, or NULL if there is not a complete UDP |
---|
2044 | * header present in the packet. |
---|
2045 | * |
---|
2046 | * This is a short-cut function enabling quick and easy access to the UDP |
---|
2047 | * header if that is all you care about. However, we recommend the use of the |
---|
2048 | * more generic trace_get_transport() function instead. |
---|
2049 | * |
---|
2050 | * @note Unlike trace_get_transport(), this function will return NULL if the |
---|
2051 | * UDP header is incomplete or truncated. |
---|
2052 | */ |
---|
2053 | DLLEXPORT SIMPLE_FUNCTION |
---|
2054 | libtrace_udp_t *trace_get_udp(libtrace_packet_t *packet); |
---|
2055 | |
---|
2056 | /** Get a pointer to the UDP header following an IPv4 header (if present) |
---|
2057 | * @param ip The IP header to find the subsequent UDP header for |
---|
2058 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
2059 | * |
---|
2060 | * @return A pointer to the UDP header, or NULL if no UDP header is present in |
---|
2061 | * the packet. |
---|
2062 | * |
---|
2063 | * When calling this function, remaining must contain the number of captured |
---|
2064 | * bytes remaining in the packet starting from the IP header (including the |
---|
2065 | * IP header itself). remaining will be updated to contain the number of |
---|
2066 | * bytes remaining after the IP header has been skipped. |
---|
2067 | * |
---|
2068 | * If the IP header is complete but there are zero bytes of payload after |
---|
2069 | * the IP header, a pointer to where the payload would be is returned and |
---|
2070 | * remaining will be set to 0. If the IP header is incomplete, NULL will be |
---|
2071 | * returned and remaining will be set to 0. Therefore, it is important to check |
---|
2072 | * the value of remaining after calling this function. |
---|
2073 | * |
---|
2074 | * @note This function is rather redundant now that the layer 3 header is |
---|
2075 | * cached. There should be no performance advantage for the user to call this |
---|
2076 | * function over just calling trace_get_transport(). |
---|
2077 | * |
---|
2078 | * @note The last parameter has changed from libtrace2 |
---|
2079 | */ |
---|
2080 | DLLEXPORT SIMPLE_FUNCTION |
---|
2081 | libtrace_udp_t *trace_get_udp_from_ip(libtrace_ip_t *ip,uint32_t *remaining); |
---|
2082 | |
---|
2083 | /** Get a pointer to the ICMP header (if present) |
---|
2084 | * @param packet The packet to get the ICMP header from |
---|
2085 | * |
---|
2086 | * @return A pointer to the ICMP header, or NULL if there is not a complete |
---|
2087 | * ICMP header present in the packet. |
---|
2088 | * |
---|
2089 | * This is a short-cut function enabling quick and easy access to the ICMP |
---|
2090 | * header if that is all you care about. However, we recommend the use of the |
---|
2091 | * more generic trace_get_transport() function instead. |
---|
2092 | * |
---|
2093 | * @note Unlike trace_get_transport(), this function will return NULL if the |
---|
2094 | * ICMP header is incomplete or truncated. |
---|
2095 | */ |
---|
2096 | DLLEXPORT SIMPLE_FUNCTION |
---|
2097 | libtrace_icmp_t *trace_get_icmp(libtrace_packet_t *packet); |
---|
2098 | |
---|
2099 | /** Get a pointer to the ICMPv6 header (if present) |
---|
2100 | * @param packet The packet to get the ICMPv6 header from |
---|
2101 | * |
---|
2102 | * @return A pointer to the ICMPv6 header, or NULL if there is not a complete |
---|
2103 | * ICMP header present in the packet. |
---|
2104 | * |
---|
2105 | * This is a short-cut function enabling quick and easy access to the ICMPv6 |
---|
2106 | * header if that is all you care about. However, we recommend the use of the |
---|
2107 | * more generic trace_get_transport() function instead. |
---|
2108 | * |
---|
2109 | * @note Unlike trace_get_transport(), this function will return NULL if the |
---|
2110 | * ICMPv6 header is incomplete or truncated. |
---|
2111 | */ |
---|
2112 | DLLEXPORT SIMPLE_FUNCTION |
---|
2113 | libtrace_icmp6_t *trace_get_icmp6(libtrace_packet_t *packet); |
---|
2114 | |
---|
2115 | /** Get a pointer to the ICMP header following an IPv4 header (if present) |
---|
2116 | * @param ip The IP header to find the subsequent ICMP header for |
---|
2117 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
2118 | * |
---|
2119 | * @return A pointer to the ICMP header, or NULL if no UDP header is present in |
---|
2120 | * the packet. |
---|
2121 | * |
---|
2122 | * When calling this function, remaining must contain the number of captured |
---|
2123 | * bytes remaining in the packet starting from the IP header (including the |
---|
2124 | * IP header itself). remaining will be updated to contain the number of |
---|
2125 | * bytes remaining after the IP header has been skipped. |
---|
2126 | * |
---|
2127 | * If the IP header is complete but there are zero bytes of payload after |
---|
2128 | * the IP header, a pointer to where the payload would be is returned and |
---|
2129 | * remaining will be set to 0. If the IP header is incomplete, NULL will be |
---|
2130 | * returned and remaining will be set to 0. Therefore, it is important to check |
---|
2131 | * the value of remaining after calling this function. |
---|
2132 | * |
---|
2133 | * @note This function is rather redundant now that the layer 3 header is |
---|
2134 | * cached. There should be no performance advantage for the user to call this |
---|
2135 | * function over just calling trace_get_transport(). |
---|
2136 | * |
---|
2137 | * @note The last parameter has changed from libtrace2 |
---|
2138 | */ |
---|
2139 | DLLEXPORT SIMPLE_FUNCTION |
---|
2140 | libtrace_icmp_t *trace_get_icmp_from_ip(libtrace_ip_t *ip,uint32_t *remaining); |
---|
2141 | |
---|
2142 | /** Get a pointer to the OSPF header (if present) |
---|
2143 | * @param packet The packet to get the OSPF header from |
---|
2144 | * @param[out] version The OSPF version number |
---|
2145 | * @param[out] remaining Updated with the number of captured bytes remaining |
---|
2146 | * @return A pointer to the start of the OSPF header or NULL if there is no |
---|
2147 | * complete OSPF header present in the packet |
---|
2148 | * |
---|
2149 | * This is a short-cut function enabling quick and easy access to the OSPF |
---|
2150 | * header. If you only care about the OSPF header, this function may be useful |
---|
2151 | * but we otherwise recommend the use of the more generic trace_get_transport() |
---|
2152 | * function instead. |
---|
2153 | * |
---|
2154 | * Upon return, 'version' is updated to contain the OSPF version number for the |
---|
2155 | * packet so that the returned pointer may be cast to the correct type. |
---|
2156 | * The version parameter MUST contain a valid pointer; it MUST NOT be NULL. |
---|
2157 | * |
---|
2158 | * 'remaining' is also set to contain the number of captured bytes remaining |
---|
2159 | * starting from the pointer returned by this function. |
---|
2160 | * |
---|
2161 | * @note Unlike trace_get_transport(), this function will return NULL if the |
---|
2162 | * OSPF header is incomplete or truncated. |
---|
2163 | */ |
---|
2164 | DLLEXPORT SIMPLE_FUNCTION |
---|
2165 | void *trace_get_ospf_header(libtrace_packet_t *packet, uint8_t *version, |
---|
2166 | uint32_t *remaining); |
---|
2167 | |
---|
2168 | /** Get a pointer to the contents of the OSPF packet *after* the OSPF header |
---|
2169 | * @param header The OSPF header to get the OSPF contents from |
---|
2170 | * @param[out] ospf_type The OSPF packet type |
---|
2171 | * @param[in, out] remaining Updated with the number of captured bytes remaining |
---|
2172 | * @return A pointer to the first byte after the OSPF header. |
---|
2173 | * |
---|
2174 | * This function returns a void pointer that can be cast appropriately |
---|
2175 | * based on the ospf_type. For example, if the ospf_type is TRACE_OSPF_HELLO |
---|
2176 | * then the return pointer should be cast as a libtrace_ospf_hello_v2_t |
---|
2177 | * structure. |
---|
2178 | * |
---|
2179 | * If the OSPF header is truncated, then NULL will be returned. If the OSPF |
---|
2180 | * contents are missing or truncated, the pointer to the start of the content |
---|
2181 | * will still be returned so be careful to check the value of remaining. |
---|
2182 | * |
---|
2183 | * 'remaining' MUST be set to the amount of bytes remaining in the captured |
---|
2184 | * packet starting from the beginning of the OSPF header. It will be updated |
---|
2185 | * to contain the number of bytes remaining from the start of the OSPF contents. |
---|
2186 | * |
---|
2187 | * @note This function only works for OSPF version 2 packets. |
---|
2188 | * @note Use trace_get_first_ospf_lsa_v2_from_X() and trace_get_next_ospf_lsa_v2() to read the LSAs from Link State Update packets. |
---|
2189 | * @note Use trace_get_first_ospf_lsa_v2_from_X() and trace_get_next_ospf_lsa_header_v2() to read the LSA headers from Link State Ack packets. |
---|
2190 | * |
---|
2191 | */ |
---|
2192 | DLLEXPORT SIMPLE_FUNCTION |
---|
2193 | void *trace_get_ospf_contents_v2(libtrace_ospf_v2_t *header, |
---|
2194 | uint8_t *ospf_type, uint32_t *remaining); |
---|
2195 | |
---|
2196 | /** Get a pointer to the start of the first LSA contained within an LS Update packet |
---|
2197 | * @param ls_update Pointer to the LS Update header |
---|
2198 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
2199 | * @return A pointer to the first LSA in the packet. |
---|
2200 | * |
---|
2201 | * This function simply skips past the LS Update header to provide a suitable |
---|
2202 | * pointer to pass into trace_get_next_ospf_lsa_v2. |
---|
2203 | * |
---|
2204 | * If the OSPF packet is truncated, then NULL will be returned. |
---|
2205 | * |
---|
2206 | * 'remaining' MUST be set to the amount of bytes remaining in the captured |
---|
2207 | * packet starting from the beginning of the LS Update header. It will be |
---|
2208 | * updated to contain the number of bytes remaining from the start of the |
---|
2209 | * first LSA. |
---|
2210 | * |
---|
2211 | * @note This function only works for OSPF version 2 packets. |
---|
2212 | * @note trace_get_next_ospf_lsa_v2() should be subequently used to process the LSAs |
---|
2213 | */ |
---|
2214 | DLLEXPORT SIMPLE_FUNCTION |
---|
2215 | unsigned char *trace_get_first_ospf_lsa_from_update_v2( |
---|
2216 | libtrace_ospf_ls_update_t *ls_update, |
---|
2217 | uint32_t *remaining); |
---|
2218 | |
---|
2219 | /** Get a pointer to the start of the first LSA contained within an Database Description packet |
---|
2220 | * @param db_desc Pointer to the Database Description header |
---|
2221 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
2222 | * @return A pointer to the first LSA in the packet. |
---|
2223 | * |
---|
2224 | * This function simply skips past the Database Description header to provide a |
---|
2225 | * suitable pointer to pass into trace_get_next_ospf_lsa_header_v2. |
---|
2226 | * |
---|
2227 | * If the OSPF packet is truncated, then NULL will be returned. |
---|
2228 | * |
---|
2229 | * 'remaining' MUST be set to the amount of bytes remaining in the captured |
---|
2230 | * packet starting from the beginning of the Database Description header. It |
---|
2231 | * will be updated to contain the number of bytes remaining from the start of |
---|
2232 | * the first LSA. |
---|
2233 | * |
---|
2234 | * @note This function only works for OSPF version 2 packets. |
---|
2235 | * @note trace_get_next_ospf_lsa_header_v2() should be subequently used to process the LSA headers |
---|
2236 | */ |
---|
2237 | DLLEXPORT SIMPLE_FUNCTION |
---|
2238 | unsigned char *trace_get_first_ospf_lsa_from_db_desc_v2( |
---|
2239 | libtrace_ospf_db_desc_v2_t *db_desc, |
---|
2240 | uint32_t *remaining); |
---|
2241 | |
---|
2242 | /** Get a pointer to the start of the first link contained within a Router LSA |
---|
2243 | * @param lsa Pointer to the Router LSA |
---|
2244 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
2245 | * @return A pointer to the first link in the packet. |
---|
2246 | * |
---|
2247 | * This function simply skips past the Router LSA header to provide a |
---|
2248 | * suitable pointer to pass into trace_get_next_ospf_link_v2. |
---|
2249 | * |
---|
2250 | * If the OSPF packet is truncated, then NULL will be returned. |
---|
2251 | * |
---|
2252 | * 'remaining' MUST be set to the amount of bytes remaining in the captured |
---|
2253 | * packet starting from the beginning of the Router LSA (not including the LSA |
---|
2254 | * header) header. It will be updated to contain the number of bytes remaining |
---|
2255 | * from the start of the first Link. |
---|
2256 | * |
---|
2257 | * @note This function only works for OSPF version 2 packets. |
---|
2258 | * @note trace_get_next_ospf_link_v2() should be subequently used to process |
---|
2259 | * the links |
---|
2260 | */ |
---|
2261 | DLLEXPORT SIMPLE_FUNCTION |
---|
2262 | unsigned char *trace_get_first_ospf_link_from_router_lsa_v2( |
---|
2263 | libtrace_ospf_router_lsa_v2_t *lsa, |
---|
2264 | uint32_t *remaining); |
---|
2265 | |
---|
2266 | /** Parses an OSPF Router LSA Link and finds the next Link (if there is one) |
---|
2267 | * @param[in,out] current Pointer to the next Link (updated by this function) |
---|
2268 | * @param[out] link Set to point to the Link located at the original value of current |
---|
2269 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
2270 | * @param[out] link_len Set to the size of the Link pointed to by 'link' |
---|
2271 | * @return 0 if there are no more links after the current one, 1 otherwise. |
---|
2272 | * |
---|
2273 | * When called, 'current' MUST point to an OSPF Router LSA link. Ideally, this |
---|
2274 | * would come from either a call to |
---|
2275 | * trace_get_first_ospf_link_from_router_lsa_v2() or a previous call of this |
---|
2276 | * function. |
---|
2277 | * |
---|
2278 | * 'link' will be set to the value of 'current', so that the caller may then |
---|
2279 | * do any processing they wish on that particular link. 'current' is advanced |
---|
2280 | * to point to the next link and 'link_len' is updated to report the size of |
---|
2281 | * the original link. |
---|
2282 | * |
---|
2283 | * 'remaining' MUST be set to the amount of bytes remaining in the captured |
---|
2284 | * packet starting from the beginning of the Link pointed to by 'current'. |
---|
2285 | * It will be updated to contain the number of bytes remaining from the start |
---|
2286 | * of the next link. |
---|
2287 | * |
---|
2288 | * If this function returns 0 but 'link' is NOT NULL, that link is still valid |
---|
2289 | * but there are no more links after this one. |
---|
2290 | * If this function returns 0 AND link is NULL, the link is obviously not |
---|
2291 | * suitable for processing. |
---|
2292 | * |
---|
2293 | * @note This function only works for OSPF version 2 packets. |
---|
2294 | */ |
---|
2295 | DLLEXPORT SIMPLE_FUNCTION |
---|
2296 | int trace_get_next_ospf_link_v2(unsigned char **current, |
---|
2297 | libtrace_ospf_link_v2_t **link, |
---|
2298 | uint32_t *remaining, |
---|
2299 | uint32_t *link_len); |
---|
2300 | |
---|
2301 | /** Parses an OSPF LSA and finds the next LSA (if there is one) |
---|
2302 | * @param[in,out] current Pointer to the next LSA (updated by this function) |
---|
2303 | * @param[out] lsa_hdr Set to point to the header of the LSA located at the original value of current |
---|
2304 | * @param[out] lsa_body Set to point to the body of the LSA located at the original value of current |
---|
2305 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
2306 | * @param[out] lsa_type Set to the type of the LSA located at the original value of current |
---|
2307 | * @param[out] lsa_length Set to the size of the LSA located at the original value of current |
---|
2308 | * @return 1 if there are more LSAs after the current one, 0 if there are no more LSAs to come, and -1 if the current LSA is incomplete, truncated or invalid. |
---|
2309 | * |
---|
2310 | * When called, 'current' MUST point to an OSPF LSA. Ideally, this would come |
---|
2311 | * from either a call to trace_get_first_ospf_lsa_from_update_v2() or a |
---|
2312 | * previous call of this function. |
---|
2313 | * |
---|
2314 | * This function should only be used to access COMPLETE LSAs, i.e. LSAs that |
---|
2315 | * have both a header and a body. In OSPFv2, only the LSAs contained within |
---|
2316 | * LSA Update packets meet this requirement. trace_get_next_ospf_lsa_header_v2 |
---|
2317 | * should be used to read header-only LSAs, e.g. those present in LS Acks. |
---|
2318 | * |
---|
2319 | * 'lsa_hdr' will be set to the value of 'current', so that the caller may then |
---|
2320 | * do any processing they wish on that particular LSA. 'lsa_body' will be set |
---|
2321 | * to point to the first byte after the LSA header. 'current' is advanced |
---|
2322 | * to point to the next LSA. 'lsa_length' is updated to contain the size of |
---|
2323 | * the parsed LSA, while 'lsa_type' is set to indicate the LSA type. |
---|
2324 | * |
---|
2325 | * 'remaining' MUST be set to the amount of bytes remaining in the captured |
---|
2326 | * packet starting from the beginning of the LSA pointed to by 'current'. |
---|
2327 | * It will be updated to contain the number of bytes remaining from the start |
---|
2328 | * of the next LSA. |
---|
2329 | * |
---|
2330 | * If this function returns 0 but 'lsa_hdr' is NOT NULL, that LSA is still |
---|
2331 | * valid but there are no more LSAs after this one. |
---|
2332 | * If this function returns 0 AND 'lsa_hdr' is NULL, the LSA is obviously not |
---|
2333 | * suitable for processing. |
---|
2334 | * |
---|
2335 | * It is also recommended to check the value of 'lsa_body' before |
---|
2336 | * de-referencing it. 'lsa_body' will be set to NULL if there is only an LSA |
---|
2337 | * header present. |
---|
2338 | * |
---|
2339 | * @note This function only works for OSPF version 2 packets. |
---|
2340 | * |
---|
2341 | */ |
---|
2342 | DLLEXPORT SIMPLE_FUNCTION |
---|
2343 | int trace_get_next_ospf_lsa_v2(unsigned char **current, |
---|
2344 | libtrace_ospf_lsa_v2_t **lsa_hdr, |
---|
2345 | unsigned char **lsa_body, |
---|
2346 | uint32_t *remaining, |
---|
2347 | uint8_t *lsa_type, |
---|
2348 | uint16_t *lsa_length); |
---|
2349 | |
---|
2350 | /** Parses an OSPF LSA header and finds the next LSA (if there is one) |
---|
2351 | * @param[in,out] current Pointer to the next LSA (updated by this function) |
---|
2352 | * @param[out] lsa_hdr Set to point to the header of the LSA located at the original value of current |
---|
2353 | * @param[in,out] remaining Updated with the number of captured bytes remaining |
---|
2354 | * @param[out] lsa_length Set to the size of the LSA located at the original value of current |
---|
2355 | * @return 1 if there are more LSAs after the current one, 0 if there are no more LSAs to come, and -1 if the current LSA is incomplete, truncated or invalid. |
---|
2356 | * |
---|
2357 | * When called, 'current' MUST point to an OSPF LSA. Ideally, this would come |
---|
2358 | * from either a call to trace_get_first_ospf_lsa_from_db_desc_v2() or a |
---|
2359 | * previous call of this function. |
---|
2360 | * |
---|
2361 | * This function should only be used to access LSA headers, i.e. LSAs that |
---|
2362 | * have a header only. In OSPFv2, the LSAs contained within LSA Ack and |
---|
2363 | * Database Description packets meet this requirement. |
---|
2364 | * trace_get_next_ospf_lsa_v2 should be used to read full LSAs, e.g. those |
---|
2365 | * present in LS Updates. |
---|
2366 | * |
---|
2367 | * 'lsa_hdr' will be set to the value of 'current', so that the caller may then |
---|
2368 | * do any processing they wish on that particular LSA header. 'current' is |
---|
2369 | * advanced to point to the next LSA header. 'lsa_length' is updated to contain |
---|
2370 | * the size of the parsed LSA header. |
---|
2371 | * |
---|
2372 | * 'remaining' MUST be set to the amount of bytes remaining in the captured |
---|
2373 | * packet starting from the beginning of the LSA pointed to by 'current'. |
---|
2374 | * It will be updated to contain the number of bytes remaining from the start |
---|
2375 | * of the next LSA. |
---|
2376 | * |
---|
2377 | * If this function returns 0 but 'lsa_hdr' is NOT NULL, that LSA is still |
---|
2378 | * valid but there are no more LSAs after this one. |
---|
2379 | * If this function returns 0 AND 'lsa_hdr' is NULL, the LSA is obviously not |
---|
2380 | * suitable for processing. |
---|
2381 | * |
---|
2382 | * @note This function only works for OSPF version 2 packets. |
---|
2383 | * |
---|
2384 | */ |
---|
2385 | DLLEXPORT SIMPLE_FUNCTION |
---|
2386 | int trace_get_next_ospf_lsa_header_v2(unsigned char **current, |
---|
2387 | libtrace_ospf_lsa_v2_t **lsa_hdr, |
---|
2388 | uint32_t *remaining, |
---|
2389 | uint8_t *lsa_type, |
---|
2390 | uint16_t *lsa_length); |
---|
2391 | |
---|
2392 | /** Extracts the metric field from an AS External LSA packet |
---|
2393 | * |
---|
2394 | * @param as_lsa The AS External LSA |
---|
2395 | * @returns The value of the metric field |
---|
2396 | * |
---|
2397 | * The metric field in the AS External LSA packet is a 24-bit value, which |
---|
2398 | * is difficult to extract correctly. To avoid byte-ordering issues, use this |
---|
2399 | * function which will extract the correct value for you. |
---|
2400 | */ |
---|
2401 | DLLEXPORT SIMPLE_FUNCTION |
---|
2402 | uint32_t trace_get_ospf_metric_from_as_external_lsa_v2( |
---|
2403 | libtrace_ospf_as_external_lsa_v2_t *as_lsa); |
---|
2404 | |
---|
2405 | /** Extracts the metric field from a Summary LSA packet |
---|
2406 | * |
---|
2407 | * @param sum_lsa The Summary LSA |
---|
2408 | * @returns The value of the metric field |
---|
2409 | * |
---|
2410 | * The metric field in the Summary LSA packet is a 24-bit value, which |
---|
2411 | * is difficult to extract correctly. To avoid byte-ordering issues, use this |
---|
2412 | * function which will extract the correct value for you. |
---|
2413 | */ |
---|
2414 | DLLEXPORT SIMPLE_FUNCTION |
---|
2415 | uint32_t trace_get_ospf_metric_from_summary_lsa_v2( |
---|
2416 | libtrace_ospf_summary_lsa_v2_t *sum_lsa); |
---|
2417 | |
---|
2418 | |
---|
2419 | /** Gets the destination MAC address for a given packet |
---|
2420 | * @param packet The packet to extract the destination MAC address from |
---|
2421 | * |
---|
2422 | * @return A pointer to the destination MAC address field in the layer 2 |
---|
2423 | * header, (or NULL if there is no destination MAC address or layer 2 header |
---|
2424 | * available) |
---|
2425 | * |
---|
2426 | * @note This is a zero-copy function, so the memory that the returned pointer |
---|
2427 | * points to is part of the packet itself. |
---|
2428 | */ |
---|
2429 | DLLEXPORT SIMPLE_FUNCTION |
---|
2430 | uint8_t *trace_get_destination_mac(libtrace_packet_t *packet); |
---|
2431 | |
---|
2432 | /** Gets the source MAC address for a given packet |
---|
2433 | * @param packet The packet to extract the source MAC address from |
---|
2434 | * |
---|
2435 | * @return A pointer to the source MAC address field in the layer 2 |
---|
2436 | * header, (or NULL if there is no source MAC address or layer 2 header |
---|
2437 | * available) |
---|
2438 | * |
---|
2439 | * @note This is a zero-copy function, so the memory that the returned pointer |
---|
2440 | * points to is part of the packet itself. |
---|
2441 | */ |
---|
2442 | DLLEXPORT SIMPLE_FUNCTION |
---|
2443 | uint8_t *trace_get_source_mac(libtrace_packet_t *packet); |
---|
2444 | |
---|
2445 | /** Get the source IP address for a given packet |
---|
2446 | * @param packet The packet to extract the source IP address from |
---|
2447 | * @param addr A pointer to a sockaddr structure to store the address |
---|
2448 | * in. If NULL, static storage is used instead. |
---|
2449 | * @return A pointer to a sockaddr holding a v4 or v6 IP address or on some |
---|
2450 | * platforms a sockaddr holding a MAC address. Returns NULL if no source IP |
---|
2451 | * address was available. |
---|
2452 | * |
---|
2453 | * @note The best way to use this function is to pass in a pointer to the |
---|
2454 | * struct sockaddr_storage for the addr parameter. This will avoid problems |
---|
2455 | * with trying to shoe-horn an IPv6 address into a sockaddr that only supports |
---|
2456 | * IPv4. |
---|
2457 | */ |
---|
2458 | DLLEXPORT SIMPLE_FUNCTION |
---|
2459 | struct sockaddr *trace_get_source_address(const libtrace_packet_t *packet, |
---|
2460 | struct sockaddr *addr); |
---|
2461 | |
---|
2462 | /** Get the source IP address for a packet and convert it into a string |
---|
2463 | * @param packet The packet to extract the source IP address from |
---|
2464 | * @param space A pointer to a character buffer to store the address |
---|
2465 | * in. If NULL, static storage is used instead. |
---|
2466 | * @param spacelen The size of the buffer passed in via 'space'. Set this |
---|
2467 | * to zero if you are going to pass in a NULL buffer. |
---|
2468 | * @return A pointer to a character buffer containing the string representation |
---|
2469 | * of the source IP address. For packets where there is no suitable IP address, |
---|
2470 | * the source MAC will be returned instead. Returns NULL if no valid address |
---|
2471 | * is available. |
---|
2472 | * |
---|
2473 | * @note Be wary of the possibility of the address being an IPv6 address - make |
---|
2474 | * sure your buffer is large enough! |
---|
2475 | * |
---|
2476 | * New in libtrace 3.0.17. |
---|
2477 | */ |
---|
2478 | DLLEXPORT SIMPLE_FUNCTION |
---|
2479 | char *trace_get_source_address_string(const libtrace_packet_t *packet, |
---|
2480 | char *space, int spacelen); |
---|
2481 | |
---|
2482 | /** Get the destination IP address for a given packet |
---|
2483 | * @param packet The packet to extract the destination IP address from |
---|
2484 | * @param addr A pointer to a sockaddr structure to store the address |
---|
2485 | * in. If NULL, static storage is used instead. |
---|
2486 | * @return A pointer to a sockaddr holding a v4 or v6 IP address or on some |
---|
2487 | * platforms a sockaddr holding a MAC address. Returns NULL if no destination |
---|
2488 | * IP address was available. |
---|
2489 | * |
---|
2490 | * @note The best way to use this function is to pass in a pointer to the |
---|
2491 | * struct sockaddr_storage for the addr parameter. This will avoid problems |
---|
2492 | * with trying to shoe-horn an IPv6 address into a sockaddr that only supports |
---|
2493 | * IPv4. |
---|
2494 | */ |
---|
2495 | DLLEXPORT SIMPLE_FUNCTION |
---|
2496 | struct sockaddr *trace_get_destination_address(const libtrace_packet_t *packet, |
---|
2497 | struct sockaddr *addr); |
---|
2498 | |
---|
2499 | /** Get the destination IP address for a packet and convert it into a string |
---|
2500 | * @param packet The packet to extract the destination IP address from |
---|
2501 | * @param space A pointer to a character buffer to store the address |
---|
2502 | * in. If NULL, static storage is used instead. |
---|
2503 | * @param spacelen The size of the buffer passed in via 'space'. Set this |
---|
2504 | * to zero if you are going to pass in a NULL buffer. |
---|
2505 | * @return A pointer to a character buffer containing the string representation |
---|
2506 | * of the destination IP address. For packets where there is no suitable IP |
---|
2507 | * address, the destination MAC will be returned instead. Returns NULL if no |
---|
2508 | * valid address is available. |
---|
2509 | * |
---|
2510 | * @note Be wary of the possibility of the address being an IPv6 address - make |
---|
2511 | * sure your buffer is large enough! |
---|
2512 | * |
---|
2513 | * New in libtrace 3.0.17. |
---|
2514 | */ |
---|
2515 | DLLEXPORT SIMPLE_FUNCTION |
---|
2516 | char *trace_get_destination_address_string(const libtrace_packet_t *packet, |
---|
2517 | char *space, int spacelen); |
---|
2518 | |
---|
2519 | /** Parses an IP or TCP option |
---|
2520 | * @param[in,out] ptr The pointer to the current option |
---|
2521 | * @param[in,out] len The total length of all the remaining options |
---|
2522 | * @param[out] type The type of the option |
---|
2523 | * @param[out] optlen The length of the option |
---|
2524 | * @param[out] data The data of the option |
---|
2525 | * |
---|
2526 | * @return bool true if there is another option (and the fields are filled in) |
---|
2527 | * or false if this was the last option. |
---|
2528 | * |
---|
2529 | * This updates ptr to point to the next option after this one, and updates |
---|
2530 | * len to be the number of bytes remaining in the options area. Type is updated |
---|
2531 | * to be the code of this option, and data points to the data of this option, |
---|
2532 | * with optlen saying how many bytes there are. |
---|
2533 | * |
---|
2534 | * @note Beware of fragmented packets. |
---|
2535 | */ |
---|
2536 | DLLEXPORT int trace_get_next_option(unsigned char **ptr,int *len, |
---|
2537 | unsigned char *type, |
---|
2538 | unsigned char *optlen, |
---|
2539 | unsigned char **data); |
---|
2540 | |
---|
2541 | /*@}*/ |
---|
2542 | |
---|
2543 | /** @name Time |
---|
2544 | * These functions deal with the timestamp describing when a packet was |
---|
2545 | * captured and can convert it into various formats |
---|
2546 | * @{ |
---|
2547 | */ |
---|
2548 | |
---|
2549 | /** Get the packet timestamp in the DAG time format |
---|
2550 | * @param packet The packet to extract the timestamp from |
---|
2551 | * |
---|
2552 | * @return a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds |
---|
2553 | * past 1970-01-01, the lower 32bits are partial seconds) |
---|
2554 | */ |
---|
2555 | DLLEXPORT SIMPLE_FUNCTION |
---|
2556 | uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet); |
---|
2557 | |
---|
2558 | /** Get the packet timestamp as a struct timeval |
---|
2559 | * @param packet The packet to extract the timestamp from |
---|
2560 | * |
---|
2561 | * @return The time that this packet was captured in a struct timeval |
---|
2562 | */ |
---|
2563 | DLLEXPORT SIMPLE_FUNCTION |
---|
2564 | struct timeval trace_get_timeval(const libtrace_packet_t *packet); |
---|
2565 | |
---|
2566 | /** Get the packet timestamp as a struct timespec |
---|
2567 | * @param packet The packet to extract the timestamp from |
---|
2568 | * |
---|
2569 | * @return The time that this packet was captured in a struct timespec |
---|
2570 | */ |
---|
2571 | DLLEXPORT SIMPLE_FUNCTION |
---|
2572 | struct timespec trace_get_timespec(const libtrace_packet_t *packet); |
---|
2573 | |
---|
2574 | /** Get the packet timestamp in floating point seconds |
---|
2575 | * @param packet The packet to extract the timestamp from |
---|
2576 | * |
---|
2577 | * @return time that this packet was seen in 64-bit floating point seconds from |
---|
2578 | * the UNIX epoch (1970-01-01 00:00:00 UTC). |
---|
2579 | */ |
---|
2580 | DLLEXPORT SIMPLE_FUNCTION |
---|
2581 | double trace_get_seconds(const libtrace_packet_t *packet); |
---|
2582 | |
---|
2583 | /** Seek within an input trace to a time specified in floating point seconds |
---|
2584 | * @param trace The input trace to seek within |
---|
2585 | * @param seconds The time to seek to, in floating point seconds |
---|
2586 | * @return 0 on success, -1 if the seek fails. Use trace_perror() to determine |
---|
2587 | * the error that occurred. |
---|
2588 | * |
---|
2589 | * This will make the next packet read to be the first packet to occur at or |
---|
2590 | * after the specified time. This must be called in the configuration state |
---|
2591 | * (i.e. before trace_start() or after trace_pause()). |
---|
2592 | * |
---|
2593 | * The time format accepted by this function is 64-bit floating point seconds |
---|
2594 | * since the UNIX epoch (1970-01-01 00:00:00 UTC), i.e. the same format as |
---|
2595 | * trace_get_seconds(). |
---|
2596 | * |
---|
2597 | * @note This function may be extremely slow. |
---|
2598 | */ |
---|
2599 | DLLEXPORT int trace_seek_seconds(libtrace_t *trace, double seconds); |
---|
2600 | |
---|
2601 | /** Seek within an input trace to a time specified as a timeval |
---|
2602 | * @param trace The input trace to seek within |
---|
2603 | * @param tv The time to seek to, as a timeval |
---|
2604 | * |
---|
2605 | * @return 0 on success, -1 if the seek fails. Use trace_perror() to determine |
---|
2606 | * the error that occurred. |
---|
2607 | * |
---|
2608 | * This will make the next packet read to be the first packet to occur at or |
---|
2609 | * after the specified time. This must be called in the configuration state |
---|
2610 | * (i.e. before trace_start() or after trace_pause()). |
---|
2611 | * |
---|
2612 | * @note This function may be extremely slow. |
---|
2613 | */ |
---|
2614 | DLLEXPORT int trace_seek_timeval(libtrace_t *trace, struct timeval tv); |
---|
2615 | |
---|
2616 | /** Seek within an input trace to a time specified as an ERF timestamp |
---|
2617 | * @param trace The input trace to seek within |
---|
2618 | * @param ts The time to seek to, as an ERF timestamp |
---|
2619 | * |
---|
2620 | * @return 0 on success, -1 if the seek fails. Use trace_perror() to determine |
---|
2621 | * the error that occurred. |
---|
2622 | * |
---|
2623 | * This will make the next packet read to be the first packet to occur at or |
---|
2624 | * after the specified time. This must be called in the configuration state |
---|
2625 | * (i.e. before trace_start() or after trace_pause()). |
---|
2626 | * |
---|
2627 | * The time format accepted by this function is the ERF timestamp, which is a |
---|
2628 | * 64-bit value where the upper 32 bits are seconds since the UNIX epoch and |
---|
2629 | * the lower 32 bits are partial seconds. |
---|
2630 | * |
---|
2631 | * @note This function may be extremely slow. |
---|
2632 | */ |
---|
2633 | DLLEXPORT int trace_seek_erf_timestamp(libtrace_t *trace, uint64_t ts); |
---|
2634 | |
---|
2635 | /*@}*/ |
---|
2636 | |
---|
2637 | /** @name Sizes |
---|
2638 | * This section deals with finding or setting the various different lengths |
---|
2639 | * that a packet can have, e.g. capture lengths, wire lengths, etc. |
---|
2640 | * @{ |
---|
2641 | */ |
---|
2642 | /** Get the current size of the packet (in bytes), taking into account any |
---|
2643 | * truncation or snapping that may have previously been performed. |
---|
2644 | * |
---|
2645 | * @param packet The packet to determine the capture length for |
---|
2646 | * @return The size of the packet read from the input trace, i.e. what is |
---|
2647 | * actually available to libtrace at the moment. |
---|
2648 | * |
---|
2649 | * @note Most traces are header captures, so this value may not be the same |
---|
2650 | * as the size of the packet when it was captured. Use trace_get_wire_length() |
---|
2651 | * to get the original size of the packet. |
---|
2652 | |
---|
2653 | * @note This can (and often is) different for different packets in a trace! |
---|
2654 | |
---|
2655 | * @note This is sometimes called the "snaplen". |
---|
2656 | * |
---|
2657 | * @note The return size refers to the network-level payload of the packet and |
---|
2658 | * does not include any capture framing headers. For example, an Ethernet |
---|
2659 | * packet with an empty TCP packet will return sizeof(ethernet_header) + |
---|
2660 | * sizeof(ip_header) + sizeof(tcp_header), but not the capture format |
---|
2661 | * (pcap/erf/etc) header. |
---|
2662 | */ |
---|
2663 | DLLEXPORT SIMPLE_FUNCTION |
---|
2664 | size_t trace_get_capture_length(const libtrace_packet_t *packet); |
---|
2665 | |
---|
2666 | /** Get the size of the packet as it was originally seen on the wire (in bytes). |
---|
2667 | * @param packet The packet to determine the wire length for |
---|
2668 | * @return The size of the packet as it was on the wire. |
---|
2669 | * |
---|
2670 | * @note This value may not be the same as the capture length, due to |
---|
2671 | * truncation. |
---|
2672 | * |
---|
2673 | * @note trace_get_wire_length \em includes the Frame Check Sequence. This is |
---|
2674 | * different behaviour compared to most PCAP-based tools. |
---|
2675 | * |
---|
2676 | * @note The return size refers to the network-level payload of the packet and |
---|
2677 | * does not include any capture framing headers. For example, an Ethernet |
---|
2678 | * packet with an empty TCP packet will return sizeof(ethernet_header) + |
---|
2679 | * sizeof(ip_header) + sizeof(tcp_header), but not the capture format |
---|
2680 | * (pcap/erf/etc) header. |
---|
2681 | */ |
---|
2682 | DLLEXPORT SIMPLE_FUNCTION |
---|
2683 | size_t trace_get_wire_length(const libtrace_packet_t *packet); |
---|
2684 | |
---|
2685 | /** Get the length of the capture framing headers (in bytes). |
---|
2686 | * @param packet The packet to determine the framing length for |
---|
2687 | * @return The size of the capture format header encapsulating the packet. |
---|
2688 | * |
---|
2689 | * @note This length corresponds to the difference between the amount of |
---|
2690 | * memory required to store a captured packet and the capture length reported |
---|
2691 | * by trace_capture_length() |
---|
2692 | */ |
---|
2693 | DLLEXPORT SIMPLE_FUNCTION |
---|
2694 | size_t trace_get_framing_length(const libtrace_packet_t *packet); |
---|
2695 | |
---|
2696 | /** Get the length of the original payload content of the packet (in bytes). |
---|
2697 | * @param packet The packet to determine the payload length for |
---|
2698 | * @return The size of the packet payload (without headers). Returns 0 if |
---|
2699 | * unable to calculate payload length correctly. |
---|
2700 | * |
---|
2701 | * This function reports the amount of data that followed the transport header |
---|
2702 | * when the packet was originally captured, i.e. prior to any snapping. Best |
---|
2703 | * described as the wire length minus the packet headers. |
---|
2704 | * |
---|
2705 | * Currently only supports some protocols and will return 0 if an unsupported |
---|
2706 | * protocol header is encountered, or if one of the headers is truncated. |
---|
2707 | * |
---|
2708 | * @note Supports IPv4, IPv6, TCP, UDP and ICMP. |
---|
2709 | */ |
---|
2710 | DLLEXPORT SIMPLE_FUNCTION |
---|
2711 | size_t trace_get_payload_length(const libtrace_packet_t *packet); |
---|
2712 | |
---|
2713 | /** Truncate ("snap") the packet to the suggested length |
---|
2714 | * @param packet The packet to truncate |
---|
2715 | * @param size The new length of the packet (in bytes) |
---|
2716 | * |
---|
2717 | * @return The new capture length of the packet or the original capture |
---|
2718 | * length of the packet if unchanged. |
---|
2719 | * |
---|
2720 | * This function will modify the capture length of the given packet. The wire |
---|
2721 | * length will not be changed, so you can always determine what the original |
---|
2722 | * packet size was, prior to the truncation. |
---|
2723 | * |
---|
2724 | * @note You can only use this function to decrease the capture length. Any |
---|
2725 | * attempt to increase capture length will have no effect. |
---|
2726 | */ |
---|
2727 | DLLEXPORT size_t trace_set_capture_length(libtrace_packet_t *packet, size_t size); |
---|
2728 | |
---|
2729 | /*@}*/ |
---|
2730 | |
---|
2731 | |
---|
2732 | /** Gets the link layer type for a packet |
---|
2733 | * @param packet The packet to extract the link layer type for |
---|
2734 | * @return A libtrace_linktype_t describing the link layer protocol being used |
---|
2735 | * by this packet. |
---|
2736 | */ |
---|
2737 | DLLEXPORT SIMPLE_FUNCTION |
---|
2738 | libtrace_linktype_t trace_get_link_type(const libtrace_packet_t *packet); |
---|
2739 | |
---|
2740 | /** Set the direction flag for a packet, if the capture format supports |
---|
2741 | * direction tagging. |
---|
2742 | * |
---|
2743 | * @param packet The packet to set the direction for |
---|
2744 | * @param direction The new direction |
---|
2745 | * @returns -1 on error, or the direction that was set. |
---|
2746 | * |
---|
2747 | * @note Few capture formats actually support direction tagging. Most notably, |
---|
2748 | * we cannot set the direction on PCAP packets. |
---|
2749 | */ |
---|
2750 | DLLEXPORT libtrace_direction_t trace_set_direction(libtrace_packet_t *packet, libtrace_direction_t direction); |
---|
2751 | |
---|
2752 | /** Get the direction flag for a packet, if it has one. |
---|
2753 | * @param packet The packet to get the direction for |
---|
2754 | * |
---|
2755 | * @return A value representing the direction flag, or -1 if this is not |
---|
2756 | * supported by the capture format. |
---|
2757 | * |
---|
2758 | * The direction is defined as 0 for packets originating locally (ie, outbound) |
---|
2759 | * and 1 for packets originating remotely (ie, inbound). Other values are |
---|
2760 | * possible, which might be overloaded to mean special things for certain |
---|
2761 | * traces, e.g. in the Waikato traces, 2 is used to represent an "Unknown" |
---|
2762 | * direction. |
---|
2763 | * |
---|
2764 | * For DAG/ERF traces, the direction is extracted from the "Interface" bits in |
---|
2765 | * the ERF header, which can range from 0 - 3. |
---|
2766 | */ |
---|
2767 | DLLEXPORT SIMPLE_FUNCTION |
---|
2768 | libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet); |
---|
2769 | |
---|
2770 | /** @name BPF |
---|
2771 | * This section deals with using Berkley Packet Filters to filter input traces |
---|
2772 | * @{ |
---|
2773 | */ |
---|
2774 | /** Creates a BPF filter |
---|
2775 | * @param filterstring The filter string describing the BPF filter to create |
---|
2776 | * @return An opaque pointer to a libtrace_filter_t object |
---|
2777 | * |
---|
2778 | * @note The filter is not actually compiled at this point, so no correctness |
---|
2779 | * tests are performed here. trace_create_filter() will always return ok, but |
---|
2780 | * if the filter is poorly constructed an error will be generated when the |
---|
2781 | * filter is actually used. |
---|
2782 | */ |
---|
2783 | DLLEXPORT SIMPLE_FUNCTION |
---|
2784 | libtrace_filter_t *trace_create_filter(const char *filterstring); |
---|
2785 | |
---|
2786 | /** Create a BPF filter based on pre-compiled byte-code. |
---|
2787 | * @param bf_insns A pointer to the start of the byte-code |
---|
2788 | * @param bf_len The number of BPF instructions |
---|
2789 | * @return An opaque pointer to a libtrace_filter_t object |
---|
2790 | * @note The supplied byte-code is not checked for correctness. |
---|
2791 | * Instead, incorrect byte-code will generate an error |
---|
2792 | * once the filter is actually used. |
---|
2793 | * @author Scott Raynel |
---|
2794 | */ |
---|
2795 | DLLEXPORT libtrace_filter_t * |
---|
2796 | trace_create_filter_from_bytecode(void *bf_insns, unsigned int bf_len); |
---|
2797 | |
---|
2798 | /** Apply a BPF filter to a packet |
---|
2799 | * @param filter The filter to be applied |
---|
2800 | * @param packet The packet to be matched against the filter |
---|
2801 | * @return >0 if the filter matches, 0 if it doesn't, -1 on error. |
---|
2802 | * |
---|
2803 | * @note Due to the way BPF filters are built, the filter is not actually |
---|
2804 | * compiled until the first time trace_create_filter is called. If your filter |
---|
2805 | * is incorrect, it will generate an error message and assert, exiting the |
---|
2806 | * program. This behaviour may change to a more graceful handling of this error |
---|
2807 | * in the future. |
---|
2808 | */ |
---|
2809 | DLLEXPORT int trace_apply_filter(libtrace_filter_t *filter, |
---|
2810 | const libtrace_packet_t *packet); |
---|
2811 | |
---|
2812 | /** Destroy a BPF filter |
---|
2813 | * @param filter The filter to be destroyed |
---|
2814 | * |
---|
2815 | * Deallocates all the resources associated with a BPF filter. |
---|
2816 | */ |
---|
2817 | DLLEXPORT void trace_destroy_filter(libtrace_filter_t *filter); |
---|
2818 | /*@}*/ |
---|
2819 | |
---|
2820 | /** @name Portability |
---|
2821 | * This section contains functions that deal with portability issues, e.g. byte |
---|
2822 | * ordering. |
---|
2823 | * @{ |
---|
2824 | */ |
---|
2825 | |
---|
2826 | /** Converts an ethernet address to a printable string |
---|
2827 | * @param addr Ethernet address in network byte order |
---|
2828 | * @param buf Buffer to store the ascii representation, or NULL to indicate |
---|
2829 | * that static storage should be used. |
---|
2830 | * @return buf, or if buf is NULL then a statically allocated buffer. |
---|
2831 | * |
---|
2832 | * This function is similar to the GNU ether_ntoa_r function, with a few |
---|
2833 | * minor differences. If NULL is passed as buf, then the function will |
---|
2834 | * use an internal static buffer. If NULL isn't passed then the function |
---|
2835 | * will use that buffer instead. |
---|
2836 | * |
---|
2837 | * The address pointers returned by trace_get_source_mac() and |
---|
2838 | * trace_get_destination_mac() can be passed directly into this function. |
---|
2839 | * |
---|
2840 | * @note The type of addr isn't struct ether_addr as it is with ether_ntoa_r, |
---|
2841 | * however it is bit compatible so that a cast will work. |
---|
2842 | */ |
---|
2843 | DLLEXPORT char *trace_ether_ntoa(const uint8_t *addr, char *buf); |
---|
2844 | |
---|
2845 | /** Convert a string to an ethernet address |
---|
2846 | * @param buf A string containing an Ethernet address in hex format |
---|
2847 | * delimited with :'s. |
---|
2848 | * @param addr Buffer to store the binary representation, or NULL to indicate |
---|
2849 | * that static storage should be used. |
---|
2850 | * @return addr, or if addr is NULL then a statically allocated buffer. |
---|
2851 | * |
---|
2852 | * This function is similar to the GNU ether_aton_r function, with a few |
---|
2853 | * minor differences. If NULL is passed as addr, then the function will |
---|
2854 | * use an internal static buffer. If NULL isn't passed then the function will |
---|
2855 | * use that buffer instead. |
---|
2856 | * |
---|
2857 | * The address returned by this function will be in network byte order. |
---|
2858 | * |
---|
2859 | * @note the type of addr isn't struct ether_addr as it is with ether_aton_r, |
---|
2860 | * however it is bit compatible so that a cast will work. |
---|
2861 | */ |
---|
2862 | DLLEXPORT uint8_t *trace_ether_aton(const char *buf, uint8_t *addr); |
---|
2863 | |
---|
2864 | /*@}*/ |
---|
2865 | |
---|
2866 | /** @name Ports |
---|
2867 | * This section contains functions for dealing with port numbers at the |
---|
2868 | * transport layer. |
---|
2869 | * |
---|
2870 | * @{ |
---|
2871 | */ |
---|
2872 | |
---|
2873 | /** An indication of which port is the "server" port for a given port pair */ |
---|
2874 | typedef enum { |
---|
2875 | USE_DEST, /**< Destination port is the server port */ |
---|
2876 | USE_SOURCE /**< Source port is the server port */ |
---|
2877 | } serverport_t; |
---|
2878 | |
---|
2879 | /** Gets the source port for a given packet |
---|
2880 | * @param packet The packet to get the source port from |
---|
2881 | * @return The source port in HOST byte order or 0 if no suitable port number |
---|
2882 | * can be extracted from the packet. |
---|
2883 | * |
---|
2884 | * This function will return 0 if the transport protocol is known not to |
---|
2885 | * use port numbers, e.g. ICMP. 0 is also returned if no transport header is |
---|
2886 | * present in the packet or the transport header has been truncated such that |
---|
2887 | * the port fields are not readable. |
---|
2888 | * |
---|
2889 | * @note If the transport protocol is not known by libtrace, the first two |
---|
2890 | * bytes of the transport header will be treated as the source port field. |
---|
2891 | */ |
---|
2892 | DLLEXPORT SIMPLE_FUNCTION |
---|
2893 | uint16_t trace_get_source_port(const libtrace_packet_t *packet); |
---|
2894 | |
---|
2895 | /** Gets the destination port for a given packet |
---|
2896 | * @param packet The packet to get the destination port from |
---|
2897 | * @return The destination port in HOST byte order or 0 if no suitable port |
---|
2898 | * number can be extracted from the packet. |
---|
2899 | * |
---|
2900 | * This function will return 0 if the transport protocol is known not to |
---|
2901 | * use port numbers, e.g. ICMP. 0 is also returned if no transport header is |
---|
2902 | * present in the packet or the transport header has been truncated such that |
---|
2903 | * the port fields are not readable. |
---|
2904 | * |
---|
2905 | * @note If the transport protocol is not known by libtrace, the third and |
---|
2906 | * fourth bytes of the transport header will be treated as the destination |
---|
2907 | * port field. |
---|
2908 | * |
---|
2909 | */ |
---|
2910 | DLLEXPORT SIMPLE_FUNCTION |
---|
2911 | uint16_t trace_get_destination_port(const libtrace_packet_t *packet); |
---|
2912 | |
---|
2913 | /** Hint at which of the two provided ports is the server port. |
---|
2914 | * |
---|
2915 | * @param protocol The IP layer protocol, eg 6 (tcp), 17 (udp) |
---|
2916 | * @param source The source port from the packet |
---|
2917 | * @param dest The destination port from the packet |
---|
2918 | * |
---|
2919 | * @return one of USE_SOURCE or USE_DEST describing on which of the two ports |
---|
2920 | * is most likely to be the server port. |
---|
2921 | * |
---|
2922 | * @note Ports must be provided in HOST byte order! |
---|
2923 | * |
---|
2924 | * This function is based almost entirely on heuristics and should not be |
---|
2925 | * treated as a definitive means of identifying the server port. However, it |
---|
2926 | * is deterministic, so it is very handy for identifying both halves of the |
---|
2927 | * same flow. |
---|
2928 | */ |
---|
2929 | DLLEXPORT SIMPLE_FUNCTION |
---|
2930 | int8_t trace_get_server_port(uint8_t protocol, uint16_t source, uint16_t dest); |
---|
2931 | |
---|
2932 | /*@}*/ |
---|
2933 | |
---|
2934 | /** @name Wireless trace support |
---|
2935 | * Functions to access wireless information from packets that have wireless |
---|
2936 | * monitoring headers such as Radiotap or Prism. |
---|
2937 | * |
---|
2938 | * The trace_get_wireless_* functions provide an abstract interface for |
---|
2939 | * retrieving information from wireless traces. They take a pointer to the |
---|
2940 | * wireless monitoring header (usually found with trace_get_packet_meta()) and |
---|
2941 | * the linktype of the header passed in. |
---|
2942 | * |
---|
2943 | * All of the trace_get_wireless_* functions return false if the requested |
---|
2944 | * information was unavailable, or true if it was. The actual data is stored |
---|
2945 | * in an output variable supplied by the caller. Values returned into the |
---|
2946 | * output variable will always be returned in host byte order. |
---|
2947 | * @{ |
---|
2948 | */ |
---|
2949 | |
---|
2950 | |
---|
2951 | #ifndef ARPHRD_80211_RADIOTAP |
---|
2952 | /** libc doesn't define this yet, so we have to do so ourselves */ |
---|
2953 | #define ARPHRD_80211_RADIOTAP 803 |
---|
2954 | #endif |
---|
2955 | |
---|
2956 | /** Get the wireless Timer Synchronisation Function |
---|
2957 | * |
---|
2958 | * Gets the value of the timer synchronisation function for this frame, which |
---|
2959 | * is a value in microseconds indicating the time that the first bit of the |
---|
2960 | * MPDU was received by the MAC. |
---|
2961 | * |
---|
2962 | * @param linkptr The wireless meta header |
---|
2963 | * @param linktype The linktype of the wireless meta header passed in |
---|
2964 | * @param[out] tsft The value of the timer synchronisation function. |
---|
2965 | * @return true if the field was available, false if not. |
---|
2966 | */ |
---|
2967 | DLLEXPORT bool trace_get_wireless_tsft(void *linkptr, |
---|
2968 | libtrace_linktype_t linktype, uint64_t *tsft); |
---|
2969 | |
---|
2970 | /** Get the wireless data rate |
---|
2971 | * |
---|
2972 | * @param linkptr The wireless meta header |
---|
2973 | * @param linktype The linktype of the wireless meta header passed in |
---|
2974 | * @param[out] rate The data-rate of the frame in units of 500kbps |
---|
2975 | * @return true if the field was available, false if not. |
---|
2976 | */ |
---|
2977 | DLLEXPORT bool trace_get_wireless_rate(void *linkptr, |
---|
2978 | libtrace_linktype_t linktype, uint8_t *rate); |
---|
2979 | |
---|
2980 | /** Get the wireless channel frequency |
---|
2981 | * @param linkptr The wireless meta header |
---|
2982 | * @param linktype The linktype of the wireless meta header passed in |
---|
2983 | * @param[out] freq The frequency in MHz of the channel the frame was |
---|
2984 | * transmitted or received on. |
---|
2985 | * @return true if the field was available, false if not. |
---|
2986 | */ |
---|
2987 | DLLEXPORT bool trace_get_wireless_freq(void *linkptr, |
---|
2988 | libtrace_linktype_t linktype, uint16_t *freq); |
---|
2989 | |
---|
2990 | /** Get the wireless signal strength in dBm |
---|
2991 | * @param linkptr The wireless meta header |
---|
2992 | * @param linktype The linktype of the wireless meta header passed in |
---|
2993 | * @param[out] strength The RF signal power at the antenna, in dB difference |
---|
2994 | * from 1mW. |
---|
2995 | * @return true if the field was available, false if not. |
---|
2996 | */ |
---|
2997 | DLLEXPORT bool trace_get_wireless_signal_strength_dbm(void *linkptr, |
---|
2998 | libtrace_linktype_t linktype, int8_t *strength); |
---|
2999 | |
---|
3000 | /** Get the wireless noise strength in dBm |
---|
3001 | * @param linkptr The wireless meta header |
---|
3002 | * @param linktype The linktype of the wireless meta header passed in |
---|
3003 | * @param[out] strength The RF noise power at the antenna, in dB difference |
---|
3004 | * from 1mW. |
---|
3005 | * @return true if the field was available, false if not. |
---|
3006 | */ |
---|
3007 | DLLEXPORT bool trace_get_wireless_noise_strength_dbm(void *linkptr, |
---|
3008 | libtrace_linktype_t linktype, int8_t *strength); |
---|
3009 | |
---|
3010 | /** Get the wireless signal strength in dB |
---|
3011 | * @param linkptr The wireless meta header |
---|
3012 | * @param linktype The linktype of the wireless meta header passed in |
---|
3013 | * @param[out] strength The RF signal power at the antenna, in dB difference |
---|
3014 | * from a fixed reference. |
---|
3015 | * @return true if the field was available, false if not. |
---|
3016 | */ |
---|
3017 | DLLEXPORT bool trace_get_wireless_signal_strength_db(void *linkptr, |
---|
3018 | libtrace_linktype_t linktype, uint8_t *strength); |
---|
3019 | |
---|
3020 | /** Get the wireless noise strength in dB |
---|
3021 | * @param linkptr The wireless meta header |
---|
3022 | * @param linktype The linktype of the wireless meta header passed in |
---|
3023 | * @param[out] strength The RF noise power at the antenna, in dB difference |
---|
3024 | * from a fixed reference. |
---|
3025 | * @return true if the field was available, false if not. |
---|
3026 | */ |
---|
3027 | DLLEXPORT bool trace_get_wireless_noise_strength_db(void *linkptr, |
---|
3028 | libtrace_linktype_t linktype, uint8_t *strength); |
---|
3029 | |
---|
3030 | /** Get the wireless transmit attenuation |
---|
3031 | * @param linkptr The wireless meta header |
---|
3032 | * @param linktype The linktype of the wireless meta header passed in |
---|
3033 | * @param[out] attenuation The transmit power as a unitless distance from |
---|
3034 | * maximum power set at factory calibration. 0 indicates maximum transmission |
---|
3035 | * power. |
---|
3036 | * @return true if the field was available, false if not. |
---|
3037 | */ |
---|
3038 | DLLEXPORT bool trace_get_wireless_tx_attenuation(void *linkptr, |
---|
3039 | libtrace_linktype_t linktype, uint16_t *attenuation); |
---|
3040 | |
---|
3041 | /** Get the wireless transmit attenuation in dB |
---|
3042 | * @param linkptr The wireless meta header |
---|
3043 | * @param linktype The linktype of the wireless meta header passed in |
---|
3044 | * @param[out] attenuation The transmit power as dB difference from maximum |
---|
3045 | * power set at factory calibration. 0 indicates maximum power. |
---|
3046 | * @return true if the field was available, false if not. |
---|
3047 | */ |
---|
3048 | DLLEXPORT bool trace_get_wireless_tx_attenuation_db(void *linkptr, |
---|
3049 | libtrace_linktype_t linktype, uint16_t *attenuation); |
---|
3050 | |
---|
3051 | /** Get the wireless transmit power in dBm |
---|
3052 | * @param linkptr The wireless meta header |
---|
3053 | * @param linktype The linktype of the wireless meta header passed in |
---|
3054 | * @param[out] txpower The transmit power as dB from a 1mW reference. This is |
---|
3055 | * the absolute power level measured at the antenna port. |
---|
3056 | * @return true if the field was available, false if not. |
---|
3057 | */ |
---|
3058 | DLLEXPORT bool trace_get_wireless_tx_power_dbm(void *linkptr, |
---|
3059 | libtrace_linktype_t linktype, int8_t *txpower); |
---|
3060 | |
---|
3061 | /** Get the wireless antenna |
---|
3062 | * @param linkptr The wireless meta header |
---|
3063 | * @param linktype The linktype of the wireless meta header passed in |
---|
3064 | * @param[out] antenna The antenna that was used to transmit or receive the |
---|
3065 | * frame. |
---|
3066 | * @return true if the field was available, false if not. |
---|
3067 | */ |
---|
3068 | DLLEXPORT bool trace_get_wireless_antenna(void *linkptr, |
---|
3069 | libtrace_linktype_t linktype, uint8_t *antenna); |
---|
3070 | |
---|
3071 | /*@}*/ |
---|
3072 | |
---|
3073 | #ifdef __cplusplus |
---|
3074 | } /* extern "C" */ |
---|
3075 | #endif /* #ifdef __cplusplus */ |
---|
3076 | #endif /* LIBTRACE_H_ */ |
---|