source: lib/libtrace.h.in @ a2ce0a6

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

Fix broken LIBTRACE_SVN_REVISION macro

The macro is now a duplicate of the LIBTRACE_API_VERSION macro, so anything
that is using it (e.g. wdcap) will get a valid value even if it no
longer refers to an SVN revision number.

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