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

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

Added trace_get_fragment_offset to API

New function performs all the bit-shifting, masking,
multiplying and (in the case of IPv6) header skipping necessary to
work out the fragment offset for a packet, in bytes.

Fixed trace_get_source_port and trace_get_destination_port so
that they do not try to lookup port numbers if the packet is
not the first fragment.

IPv6 fragment offsets probably need more testing.

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