source: lib/libtrace.h.in @ 977e0db

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

Add meta api for erf and pcapng meta packets

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