source: lib/libtrace.h.in @ d0f25d4

develop
Last change on this file since d0f25d4 was d0f25d4, checked in by Jacob Van Walraven <jcv9@…>, 21 months ago

Add ERF and PCAPNG decoders to libpacketdump

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