source: lib/libtrace.h.in @ e7132d6

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

improvements to meta-api

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