source: lib/libtrace.h.in @ 7b4f5e2

develop
Last change on this file since 7b4f5e2 was 7b4f5e2, checked in by Jacob Van Walraven <jcv9@…>, 2 years ago

cleanup trace_get_interface ipv4 and ipv6 functions

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