source: lib/libtrace.h.in @ fd4482d

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since fd4482d was fd4482d, checked in by Shane Alcock <salcock@…>, 5 years ago

Make sure trace_create_packet() doesn't segfault

If allocating memory for the new packet fails, we now return NULL
instead of carrying on and trying to initialise the packet fields.

This has always been the intended behaviour (see some of the examples
for cases where we check if packet is NULL after calling trace_create_packet())
but I guess nobody actually implemented it...

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