source: lib/libtrace.h.in @ 6d082e6

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 6d082e6 was 6d082e6, checked in by Perry Lorier <git@…>, 7 years ago

Add support for VXLAN and GRE.

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