source: lib/libtrace.h.in @ 254c926

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

Cleanup some duplicate code, Added datatype/option_name for libtrace_meta_t structure

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