source: lib/libtrace.h.in @ 95b1d6d

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 95b1d6d was 95b1d6d, checked in by Shane Alcock <salcock@…>, 14 years ago
  • Remember to clear the packet cache when trace_event is used to read packets
  • Packets that had a corrupt or incorrect rt_type will no longer be erroneously treated as pcap packets (unless the rt_type ends up being between 2000 and 2999!)
  • Property mode set to 100644
File size: 65.5 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2007 The University of Waikato, Hamilton, New Zealand.
5 * Authors: Daniel Lawson
6 *          Perry Lorier
7 *         
8 * All rights reserved.
9 *
10 * This code has been developed by the University of Waikato WAND
11 * research group. For further information please see http://www.wand.net.nz/
12 *
13 * libtrace is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * libtrace is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with libtrace; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 *
27 * $Id: libtrace.h 773 2006-05-01 12:58:09Z perry $
28 *
29 */
30
31#ifndef LIBTRACE_H
32#define LIBTRACE_H
33
34/** @file
35 *
36 * @brief Trace file processing library header
37 *
38 * @author Daniel Lawson
39 * @author Perry Lorier
40 *
41 * @version $Id: libtrace.h 773 2006-05-01 12:58:09Z perry $
42 *
43 * This library provides a per packet interface into a trace file, or a live
44 * captures.  It supports ERF, DAG cards, WAG cards, WAG's event format,
45 * pcap etc.
46 *
47 * @par Usage
48 * See the example/ directory in the source distribution for some simple examples
49 * @par Linking
50 * To use this library you need to link against libtrace by passing -ltrace
51 * to your linker. You may also need to link against a version of libpcap
52 * and of zlib which are compiled for largefile support (if you wish to access
53 * traces larger than 2 GB). This is left as an exercise for the reader. Debian
54 * Woody, at least, does not support large file offsets.
55 *
56 */
57
58#include <sys/types.h>
59#ifndef WIN32
60#include <sys/time.h>
61#endif
62
63#ifdef _MSC_VER
64    /* define the following from MSVC's internal types */
65    typedef             __int8  int8_t;
66    typedef             __int16 int16_t;
67    typedef             __int32 int32_t;
68    typedef             __int64 int64_t;
69    typedef unsigned    __int8  uint8_t;
70    typedef unsigned    __int16 uint16_t;
71    typedef unsigned    __int32 uint32_t;
72    typedef unsigned    __int64 uint64_t;
73    #ifdef BUILDING_DLL
74        #define DLLEXPORT __declspec(dllexport)
75    #else
76        #define DLLEXPORT __declspec(dllimport)
77    #endif
78    #define DLLLOCAL
79    /* Windows pads bitfields out to to the size of their parent type
80     * however gcc warns that this doesn't meet with the iso C specification
81     * so produces warnings for this behaviour.  sigh.
82     */
83    #define LT_BITFIELD8        uint8_t
84    #define LT_BITFIELD16       uint16_t
85    #define LT_BITFIELD32       uint32_t
86    #define LT_BITFIELD64       uint64_t
87#else
88#   include <stdint.h>
89    #ifdef HAVE_GCCVISIBILITYPATCH
90        #define DLLEXPORT __attribute__ (visibility("default"))
91        #define DLLLOCAL __attribute__ (visibility("hidden"))
92    #else
93        #define DLLEXPORT
94        #define DLLLOCAL
95    #endif
96    /* GCC warns if the bitfield type is not "unsigned int", however windows
97     * generates incorrect code for this (see above), so we define these
98     * macros.  How Hidious.  So much for C's portability.
99     */
100    #define LT_BITFIELD8        unsigned int
101    #define LT_BITFIELD16       unsigned int
102    #define LT_BITFIELD32       unsigned int
103    #define LT_BITFIELD64       unsigned int
104#endif
105
106#ifdef WIN32
107#   include <winsock2.h>
108#   include <ws2tcpip.h>
109    typedef short sa_family_t;
110    /* Make up for a lack of stdbool.h */
111#    define bool signed char
112#    define false 0
113#    define true 1
114#    if !defined(ssize_t)
115     /* XXX: Not 64-bit safe! */
116#    define ssize_t int
117#    endif   
118#else
119#    include <netinet/in.h>
120
121#ifndef __cplusplus
122#    include <stdbool.h>
123#endif
124
125#    include <sys/types.h>
126#    include <sys/socket.h>
127#endif
128
129/** API version as 2 byte hex digits, eg 0xXXYYZZ */
130#define LIBTRACE_API_VERSION \
131            ((@LIBTRACE_MAJOR@<<16)|(@LIBTRACE_MID@<<8)|(@LIBTRACE_MINOR@))
132
133#define LIBTRACE_SVN_REVISION 0
134#define DAG_DRIVER_V "@DAG_VERSION_NUM@"
135   
136#ifdef __cplusplus
137extern "C" {
138#endif
139
140/* Function does not depend on anything but its
141 * parameters, used to hint gcc's optimisations
142 */
143#if __GNUC__ >= 3
144#  define DEPRECATED __attribute__((deprecated))
145#  define SIMPLE_FUNCTION __attribute__((pure))
146#  define UNUSED __attribute__((unused))
147#  define PACKED __attribute__((packed))
148#  define PRINTF(formatpos,argpos) __attribute__((format(printf,formatpos,argpos)))
149#else
150#  define DEPRECATED
151#  define SIMPLE_FUNCTION
152#  define UNUSED
153#  define PACKED
154#  define PRINTF(formatpos,argpos)
155#endif
156       
157/** Opaque structure holding information about an output trace */
158typedef struct libtrace_out_t libtrace_out_t;
159       
160/** Opaque structure holding information about a trace */
161typedef struct libtrace_t libtrace_t;
162       
163/** Opaque structure holding information about a bpf filter */
164typedef struct libtrace_filter_t libtrace_filter_t;
165
166/** If a packet has memory allocated
167 * If the packet has allocated it's own memory it's buffer_control should
168 * be TRACE_CTRL_PACKET, when the packet is destroyed it's memory will be
169 * free()'d.  If it's doing zerocopy out of memory owned by something else
170 * it should be TRACE_CTRL_EXTERNAL.
171 * @note the letters p and e are magic numbers used to detect if the packet
172 * wasn't created properly
173 */
174typedef enum {
175        TRACE_CTRL_PACKET='p',
176        TRACE_CTRL_EXTERNAL='e'
177} buf_control_t;
178/** The size of a packet's buffer when managed by libtrace */
179#define LIBTRACE_PACKET_BUFSIZE 65536
180
181/** libtrace error information */
182typedef struct trace_err_t{
183        int err_num;            /**< error code */
184        char problem[255];      /**< the format, uri etc that caused the error for reporting purposes */
185} libtrace_err_t;
186
187/** Enumeration of error codes */
188enum {
189        /** No Error has occured.... yet. */
190        TRACE_ERR_NOERROR       = 0,
191        /** The URI passed to trace_create() is unsupported, or badly formed */
192        TRACE_ERR_BAD_FORMAT    = -1,
193        /** The trace failed to initialise */
194        TRACE_ERR_INIT_FAILED   = -2,
195        /** Unknown config option */
196        TRACE_ERR_UNKNOWN_OPTION= -3,
197        /** This output uri cannot write packets of this type */
198        TRACE_ERR_NO_CONVERSION = -4,
199        /** This packet is corrupt, or unusable for the action required */
200        TRACE_ERR_BAD_PACKET    = -5,
201        /** Option known, but unsupported by this format */
202        TRACE_ERR_OPTION_UNAVAIL= -6,
203        /** This feature is unsupported */
204        TRACE_ERR_UNSUPPORTED   = -7,
205        /** Illegal use of the API */
206        TRACE_ERR_BAD_STATE     = -8
207};
208
209/** Enumeration of DLT supported by libtrace
210 */
211typedef enum {
212        TRACE_DLT_NULL = 0,
213        TRACE_DLT_EN10MB = 1,
214        TRACE_DLT_PPP = 9,
215        TRACE_DLT_ATM_RFC1483 = 11,
216        /* Sigh. This is handled in files with LINKTYPE's */
217#ifdef __OpenBSD__
218        TRACE_DLT_RAW = 14,     
219#else
220        TRACE_DLT_RAW = 12,
221#endif
222        TRACE_DLT_LINKTYPE_RAW = 101,
223        TRACE_DLT_C_HDLC = 104,
224        TRACE_DLT_IEEE802_11 = 105,
225        TRACE_DLT_LINUX_SLL = 113,
226        TRACE_DLT_PFLOG = 117,
227        TRACE_DLT_IEEE802_11_RADIO = 127 /**< Radiotap */
228} libtrace_dlt_t ;
229
230/** Enumeration of link layer types supported by libtrace */
231typedef enum {
232    /* TRACE_TYPE_LEGACY = 0            Obsolete */
233       TRACE_TYPE_HDLC_POS = 1,
234       TRACE_TYPE_ETH = 2,              /**< 802.3 style Ethernet */
235       TRACE_TYPE_ATM = 3,              /**< ATM frame */
236       TRACE_TYPE_80211 = 4,            /**< 802.11 frames */
237       TRACE_TYPE_NONE = 5,             /**< Raw IP frames */
238       TRACE_TYPE_LINUX_SLL = 6,        /**< Linux "null" framing */
239       TRACE_TYPE_PFLOG = 7,            /**< FreeBSD's PFlug */
240    /* TRACE_TYPE_LEGACY_DEFAULT        Obsolete */
241       TRACE_TYPE_POS = 9,
242    /* TRACE_TYPE_LEGACY_ATM            Obsolete */
243    /* TRACE_TYPE_LEGACY_ETH            Obsolete */
244       TRACE_TYPE_80211_PRISM = 12,
245       TRACE_TYPE_AAL5 = 13,
246       TRACE_TYPE_DUCK = 14,         /**< Pseudo link layer for DUCK packets */
247       TRACE_TYPE_80211_RADIO = 15,  /**< Radiotap + 802.11 */
248       TRACE_TYPE_LLCSNAP = 16,      /**< Raw LLC/SNAP */
249       TRACE_TYPE_PPP = 17,          /**< PPP frames */
250       TRACE_TYPE_METADATA = 18         /**< WDCAP-style meta-data */
251       
252} libtrace_linktype_t;
253
254/** RT protocol base format identifiers
255 * This is used to say what kind of packet is being sent over the rt protocol
256 */
257enum base_format_t {
258        TRACE_FORMAT_ERF          =1,
259        TRACE_FORMAT_PCAP         =2,
260        TRACE_FORMAT_PCAPFILE     =3,
261        TRACE_FORMAT_WAG          =4,
262        TRACE_FORMAT_RT           =5,
263        TRACE_FORMAT_LEGACY_ATM   =6,
264        TRACE_FORMAT_LEGACY_POS   =7,
265        TRACE_FORMAT_LEGACY_ETH   =8,
266        TRACE_FORMAT_LINUX_NATIVE =9,
267        TRACE_FORMAT_DUCK         =10,
268        TRACE_FORMAT_BPF          =11,
269        TRACE_FORMAT_TSH          =12,
270        TRACE_FORMAT_ATMHDR       =13,
271        TRACE_FORMAT_LEGACY_NZIX  =14
272};
273
274/* RT protocol packet types */
275typedef enum {
276        TRACE_RT_HELLO          =1, /**< Connection accepted */
277        TRACE_RT_START          =2, /**< Request for data transmission to begin
278                                    */
279        TRACE_RT_ACK            =3, /**< Data acknowledgement */
280        TRACE_RT_STATUS         =4, /**< Fifo status packet */
281        TRACE_RT_DUCK           =5, /**< Dag duck info packet */
282        TRACE_RT_END_DATA       =6, /**< Server is exiting message */
283        TRACE_RT_CLOSE          =7, /**< Client is exiting message */
284        TRACE_RT_DENY_CONN      =8, /**< Connection has been denied */
285        TRACE_RT_PAUSE          =9, /**< Request server to suspend sending data
286                                     */
287        TRACE_RT_PAUSE_ACK      =10,/**< Server is paused message */
288        TRACE_RT_OPTION         =11,/**< Option request */
289        TRACE_RT_KEYCHANGE      =12,/**< Anonymisation key has changed */
290        TRACE_RT_DUCK_2_4       =13,/**< Dag 2.4 Duck */
291        TRACE_RT_DUCK_2_5       =14,/**< Dag 2.5 Duck */
292        TRACE_RT_LOSTCONN       =15,/**< Lost connection to server */
293        TRACE_RT_SERVERSTART    =16,/**< Reliable server has been restarted */
294        TRACE_RT_CLIENTDROP     =17,/**< Reliable client was lost */
295        TRACE_RT_METADATA       =18,/**< Packet contains server meta-data */
296
297        TRACE_RT_DATA_SIMPLE    = 1000, /**< Trace types that know their link
298                                          * type
299                                          */
300        TRACE_RT_DATA_ERF       =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_ERF,
301        TRACE_RT_DATA_WAG       =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_WAG,
302        TRACE_RT_DATA_LEGACY_ATM=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LEGACY_ATM,
303        TRACE_RT_DATA_LEGACY_POS=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LEGACY_POS,
304        TRACE_RT_DATA_LEGACY_ETH=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LEGACY_ETH,
305        TRACE_RT_DATA_LINUX_NATIVE=TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_LINUX_NATIVE,
306        TRACE_RT_DATA_TSH       =TRACE_RT_DATA_SIMPLE+TRACE_FORMAT_TSH,
307
308        TRACE_RT_DATA_ATMHDR = TRACE_RT_DATA_SIMPLE + TRACE_FORMAT_ATMHDR,
309        TRACE_RT_DATA_LEGACY_NZIX=TRACE_RT_DATA_SIMPLE + TRACE_FORMAT_LEGACY_NZIX,
310        TRACE_RT_DATA_DLT               = 2000, /**< Pcap doesn't store the
311                                                  * linktype per packet, and
312                                                  * thus we have to store it
313                                                  * in here.  sigh.
314                                                  */
315        TRACE_RT_DLT_NULL               =TRACE_RT_DATA_DLT+TRACE_DLT_NULL,
316        TRACE_RT_DLT_EN10MB             =TRACE_RT_DATA_DLT+TRACE_DLT_EN10MB,
317        TRACE_RT_DLT_IEEE802_11         =TRACE_RT_DATA_DLT+TRACE_DLT_IEEE802_11,
318        TRACE_RT_DLT_LINUX_SLL          =TRACE_RT_DATA_DLT+TRACE_DLT_LINUX_SLL,
319        TRACE_RT_DLT_PFLOG              =TRACE_RT_DATA_DLT+TRACE_DLT_PFLOG,
320        TRACE_RT_DLT_ATM_RFC1483        =TRACE_RT_DATA_DLT+TRACE_DLT_ATM_RFC1483,
321        TRACE_RT_DATA_DLT_END           = 2999,
322        TRACE_RT_LAST                   = (2<<31)
323} libtrace_rt_types_t;
324
325/** The libtrace packet structure, applications shouldn't be
326 * meddling around in here
327 */
328typedef struct libtrace_packet_t {
329        struct libtrace_t *trace;       /**< pointer to the trace */
330        void *header;                   /**< pointer to the framing header */
331        void *payload;                  /**< pointer to the link layer */
332        void *buffer;                   /**< allocated buffer */
333        libtrace_rt_types_t  type;      /**< rt protocol type for the packet */
334        buf_control_t buf_control;      /**< who owns the memory */
335        int capture_length;             /**< Cached capture length */
336        void *l3_header;                /**< Cached l3 header */
337        uint16_t l3_ethertype;          /**< Cached l3 ethertype */
338} libtrace_packet_t;
339
340
341/** Trace directions
342 * Note that these are the directions used by convention, more directions
343 * are possible, not just these 3, and that they may not conform to this
344 * convention.
345 */
346typedef enum {
347        TRACE_DIR_OUTGOING = 0,         /**< Packets originating "inside" */
348        TRACE_DIR_INCOMING = 1,         /**< Packets originating "outside" */
349        TRACE_DIR_OTHER    = 2          /**< Packets with an unknown direction, or one that's unknown */
350} libtrace_direction_t;
351
352/** Enumeration of Radiotap fields */
353typedef enum {
354    TRACE_RADIOTAP_TSFT = 0, /**< Timer synchronisation function, in microseconds (uint64) */
355    TRACE_RADIOTAP_FLAGS = 1, /**< Wireless flags (uint8) */
356    TRACE_RADIOTAP_RATE = 2, /**< Bitrate in units of 500kbps (uint8) */
357    TRACE_RADIOTAP_CHANNEL = 3, /**< Frequency in MHz (uint16) and channel flags (uint16) */
358    TRACE_RADIOTAP_FHSS = 4, /**< FHSS hop set (uint8) and hopping pattern (uint8) */
359    TRACE_RADIOTAP_DBM_ANTSIGNAL = 5, /**< Signal power in dBm (int8) */
360    TRACE_RADIOTAP_DBM_ANTNOISE = 6, /**< Noise power in dBm (int8) */
361    TRACE_RADIOTAP_LOCK_QUALITY = 7, /**< Barker Code lock quality (uint16) */
362    TRACE_RADIOTAP_TX_ATTENUATION = 8, /**< TX attenuation as unitless distance from max power (uint16) */
363    TRACE_RADIOTAP_DB_TX_ATTENUATION = 9, /**< TX attenutation as dB from max power (uint16) */
364    TRACE_RADIOTAP_DBM_TX_POWER = 10, /**< TX Power in dBm (int8) */
365    TRACE_RADIOTAP_ANTENNA = 11, /**< Antenna frame was rx'd or tx'd on (uint8) */
366    TRACE_RADIOTAP_DB_ANTSIGNAL = 12, /**< Signal power in dB from a fixed reference (uint8) */
367    TRACE_RADIOTAP_DB_ANTNOISE = 13, /**< Noise power in dB from a fixed reference (uint8) */
368    TRACE_RADIOTAP_RX_FLAGS = 14, /** Properties of received frame (uint16) */
369    TRACE_RADIOTAP_TX_FLAGS = 15, /** Properties of transmitted frame (uint16) */
370    TRACE_RADIOTAP_RTS_RETRIES = 16, /** Number of rts retries frame used (uint8) */
371    TRACE_RADIOTAP_DATA_RETRIES = 17, /** Number of unicast retries a transmitted frame used (uint8) */
372    TRACE_RADIOTAP_EXT = 31
373} libtrace_radiotap_field_t;
374
375
376/** @name Protocol structures
377 * These convenience structures are here as they are portable ways of dealing
378 * with various protocols.
379 * @{
380 */
381
382#ifdef WIN32
383#pragma pack(push)
384#pragma pack(1)
385#endif
386
387/** Generic IP header structure */
388typedef struct libtrace_ip
389{
390#if BYTE_ORDER == LITTLE_ENDIAN
391    LT_BITFIELD8 ip_hl:4;               /**< Header Length */
392    LT_BITFIELD8 ip_v:4;                /**< Version */
393#elif BYTE_ORDER == BIG_ENDIAN
394    LT_BITFIELD8 ip_v:4;                /**< Version */
395    LT_BITFIELD8 ip_hl:4;               /**< Header Length */
396#else
397#   error "Adjust your <bits/endian.h> defines"
398#endif
399    uint8_t  ip_tos;                    /**< Type of Service */
400    uint16_t ip_len;                    /**< Total Length */
401    int16_t  ip_id;                     /**< Identification */
402    uint16_t ip_off;                    /**< IP Fragment offset (and flags) */
403    uint8_t  ip_ttl;                    /**< Time to Live */
404    uint8_t  ip_p;                      /**< Protocol */
405    uint16_t ip_sum;                    /**< Checksum */
406    struct in_addr ip_src;              /**< Source Address */
407    struct in_addr ip_dst;              /**< Destination Address */
408} PACKED libtrace_ip_t;
409
410/** IPv6 header extension structure */
411typedef struct libtrace_ip6_ext
412{
413        uint8_t nxt;
414        uint8_t len;
415} PACKED libtrace_ip6_ext_t;
416
417/** Generic IPv6 header structure */
418typedef struct libtrace_ip6
419{
420    uint32_t flow;
421    uint16_t plen;                      /**< Payload length */
422    uint8_t nxt;                        /**< Next header */
423    uint8_t hlim;                       /**< Hop limit */
424    struct in6_addr ip_src;             /**< source address */
425    struct in6_addr ip_dst;             /**< dest address */
426} PACKED libtrace_ip6_t;
427
428/** Generic TCP header structure */
429typedef struct libtrace_tcp
430  {
431    uint16_t source;            /**< Source Port */
432    uint16_t dest;              /**< Destination port */
433    uint32_t seq;               /**< Sequence number */
434    uint32_t ack_seq;           /**< Acknowledgement Number */
435#  if BYTE_ORDER == LITTLE_ENDIAN
436    LT_BITFIELD8 res1:4;        /**< Reserved bits */
437    LT_BITFIELD8 doff:4;        /**< Data Offset */     
438    LT_BITFIELD8 fin:1;         /**< FIN */
439    LT_BITFIELD8 syn:1;         /**< SYN flag */
440    LT_BITFIELD8 rst:1;         /**< RST flag */
441    LT_BITFIELD8 psh:1;         /**< PuSH flag */
442    LT_BITFIELD8 ack:1;         /**< ACK flag */
443    LT_BITFIELD8 urg:1;         /**< URG flag */
444    LT_BITFIELD8 res2:2;        /**< Reserved */
445#  elif BYTE_ORDER == BIG_ENDIAN
446    LT_BITFIELD8 doff:4;        /**< Data offset */
447    LT_BITFIELD8 res1:4;        /**< Reserved bits */
448    LT_BITFIELD8 res2:2;        /**< Reserved */
449    LT_BITFIELD8 urg:1;         /**< URG flag */
450    LT_BITFIELD8 ack:1;         /**< ACK flag */
451    LT_BITFIELD8 psh:1;         /**< PuSH flag */
452    LT_BITFIELD8 rst:1;         /**< RST flag */
453    LT_BITFIELD8 syn:1;         /**< SYN flag */
454    LT_BITFIELD8 fin:1;         /**< FIN flag */
455#  else
456#   error "Adjust your <bits/endian.h> defines"
457#  endif
458    uint16_t window;            /**< Window Size */
459    uint16_t check;             /**< Checksum */
460    uint16_t urg_ptr;           /**< Urgent Pointer */
461} PACKED libtrace_tcp_t;
462
463/** Generic UDP header structure */
464typedef struct libtrace_udp {
465  uint16_t      source;         /**< Source port */
466  uint16_t      dest;           /**< Destination port */
467  uint16_t      len;            /**< Length */
468  uint16_t      check;          /**< Checksum */
469} PACKED libtrace_udp_t;
470
471/** Generic ICMP header structure */
472typedef struct libtrace_icmp
473{
474  uint8_t type;         /**< Message Type */
475  uint8_t code;         /**< Type Sub-code */
476  uint16_t checksum;            /**< Checksum */
477  union
478  {
479    struct
480    {
481      uint16_t  id;
482      uint16_t  sequence;
483    } echo;                     /**< Echo Datagram */
484    uint32_t    gateway;        /**< Gateway Address */
485    struct
486    {
487      uint16_t  unused;
488      uint16_t  mtu;
489    } frag;                     /**< Path MTU Discovery */
490  } un;                         /**< Union for Payloads of Various ICMP Codes */
491} PACKED libtrace_icmp_t;
492
493/** Generic LLC/SNAP header structure */
494typedef struct libtrace_llcsnap
495{
496/* LLC */
497  uint8_t dsap;                 /**< Destination Service Access Point */
498  uint8_t ssap;                 /**< Source Service Access Point */
499  uint8_t control;
500/* SNAP */
501  LT_BITFIELD32 oui:24;         /**< Organisationally Unique Identifier (scope)*/
502  uint16_t type;                /**< Protocol within OUI */
503} PACKED libtrace_llcsnap_t;
504
505/** 802.3 frame */
506typedef struct libtrace_ether
507{
508  uint8_t ether_dhost[6];       /**< Destination Ether Addr */
509  uint8_t ether_shost[6];       /**< Source Ether Addr */
510  uint16_t ether_type;          /**< Packet Type ID Field (next-header) */
511} PACKED libtrace_ether_t;
512
513/** 802.1Q frame */
514typedef struct libtrace_8021q
515{
516  LT_BITFIELD16 vlan_pri:3;      /**< VLAN User Priority */
517  LT_BITFIELD16 vlan_cfi:1;      /**< VLAN Format Indicator,
518                                   * 0 for ethernet, 1 for token ring */
519  LT_BITFIELD16 vlan_id:12;      /**< VLAN Id */
520  uint16_t vlan_ether_type;      /**< VLAN Sub-packet Type ID Field
521                                   * (next-header)*/
522} PACKED libtrace_8021q_t;
523
524/** ATM User Network Interface (UNI) Cell. */
525typedef struct libtrace_atm_cell
526{
527  LT_BITFIELD32 gfc:4;          /**< Generic Flow Control */
528  LT_BITFIELD32 vpi:8;          /**< Virtual Path Identifier */
529  LT_BITFIELD32 vci:16;         /**< Virtual Channel Identifier */
530  LT_BITFIELD32 pt:3;           /**< Payload Type */
531  LT_BITFIELD32 clp:1;          /**< Cell Loss Priority */
532  LT_BITFIELD32 hec:8;          /**< Header Error Control */
533} PACKED libtrace_atm_cell_t;
534
535/** ATM Network Node/Network Interface (NNI) Cell. */
536typedef struct libtrace_atm_nni_cell
537{
538  LT_BITFIELD32 vpi:12;         /**< Virtual Path Identifier */
539  LT_BITFIELD32 vci:16;         /**< Virtual Channel Identifier */
540  LT_BITFIELD32 pt:3;           /**< Payload Type */
541  LT_BITFIELD32 clp:1;          /**< Cell Loss Priority */
542  LT_BITFIELD32 hec:8;          /**< Header Error Control */
543} PACKED libtrace_atm_nni_cell_t;
544
545/** Captured UNI cell.
546 *
547 * Endance don't capture the HEC, presumably to keep alignment.  This
548 * version of the \ref libtrace_atm_cell  is used when dealing with dag
549 * captures of uni cells.
550 *
551 */
552typedef struct libtrace_atm_capture_cell
553{
554  LT_BITFIELD32 gfc:4;          /**< Generic Flow Control */
555  LT_BITFIELD32 vpi:8;          /**< Virtual Path Identifier */
556  LT_BITFIELD32 vci:16;         /**< Virtual Channel Identifier */
557  LT_BITFIELD32 pt:3;           /**< Payload Type */
558  LT_BITFIELD32 clp:1;          /**< Cell Loss Priority */
559} PACKED libtrace_atm_capture_cell_t;
560
561/** Captured NNI cell.
562 *
563 * Endance don't capture the HEC, presumably to keep alignment.  This
564 * version of the \ref libtrace_atm_nni_cell  is used when dealing with dag
565 * captures of nni cells.
566 *
567 */
568typedef struct libtrace_atm_nni_capture_cell
569{
570  LT_BITFIELD32 vpi:12;         /**< Virtual Path Identifier */
571  LT_BITFIELD32 vci:16;         /**< Virtual Channel Identifier */
572  LT_BITFIELD32 pt:3;           /**< Payload Type */
573  LT_BITFIELD32 clp:1;          /**< Cell Loss Priority */
574  LT_BITFIELD32 hec:8;          /**< Header Error Control */
575} PACKED libtrace_atm_nni_capture_cell_t;
576
577/** PPP header */
578typedef struct libtrace_pps
579{
580 uint8_t addres;                /**< PPP Address (0xFF - All stations) */
581 uint8_t header;                /**< PPP Control (0x03 - Unnumbered info) */
582 uint16_t protocol;             /**< PPP Protocol (htons(0x0021) - IPv4 */
583} PACKED libtrace_ppp_t;
584
585/** 802.11 header */
586typedef struct libtrace_80211_t {
587#if BYTE_ORDER == LITTLE_ENDIAN
588        LT_BITFIELD32      protocol:2;
589        LT_BITFIELD32      type:2;
590        LT_BITFIELD32      subtype:4;
591#else
592        LT_BITFIELD32      subtype:4;
593        LT_BITFIELD32      type:2;
594        LT_BITFIELD32      protocol:2;
595#endif
596
597#if BYTE_ORDER == LITTLE_ENDIAN
598        LT_BITFIELD32      to_ds:1;     /**< Packet to Distribution Service */
599        LT_BITFIELD32      from_ds:1;   /**< Packet from Distribution Service */
600        LT_BITFIELD32      more_frag:1; /**< Packet has more fragments */
601        LT_BITFIELD32      retry:1;     /**< Packet is a retry */
602        LT_BITFIELD32      power:1;
603        LT_BITFIELD32      more_data:1;
604        LT_BITFIELD32      wep:1;
605        LT_BITFIELD32      order:1;
606#else
607        LT_BITFIELD32      order:1;
608        LT_BITFIELD32      wep:1;
609        LT_BITFIELD32      more_data:1;
610        LT_BITFIELD32      power:1;
611        LT_BITFIELD32      retry:1;     /**< Packet is a retry */
612        LT_BITFIELD32      more_frag:1; /**< Packet has more fragments */
613        LT_BITFIELD32      from_ds:1;   /**< Packet from Distribution Service */
614        LT_BITFIELD32      to_ds:1;     /**< Packet to Distribution Service */
615#endif
616        uint16_t     duration;
617        uint8_t      mac1[6];
618        uint8_t      mac2[6];
619        uint8_t      mac3[6];
620        uint16_t     SeqCtl;
621        uint8_t      mac4[6];
622} PACKED libtrace_80211_t;
623
624/** The Radiotap header pre-amble
625 *
626 * All Radiotap headers start with this pre-amble, followed by the fields
627 * specified in the it_present bitmask. If bit 31 of it_present is set, then
628 * another bitmask follows.
629 * @note All of the radiotap data fields are in little-endian byte-order.
630 */
631typedef struct libtrace_radiotap_t {
632    uint8_t     it_version; /**< Radiotap version */
633    uint8_t     it_pad; /**< Padding for natural alignment */
634    uint16_t    it_len; /**< Length in bytes of the entire Radiotap header */
635    uint32_t    it_present; /**< Which Radiotap fields are present */
636} PACKED libtrace_radiotap_t;
637
638
639#ifdef WIN32
640#pragma pack(pop)
641#endif
642
643
644/*@}*/
645
646/** Prints help information for libtrace
647 *
648 * Function prints out some basic help information regarding libtrace,
649 * and then prints out the help() function registered with each input module
650 */
651DLLEXPORT void trace_help(void);
652
653/** @name Trace management
654 * These members deal with creating, configuring, starting, pausing and
655 * cleaning up a trace object
656 *@{
657 */
658
659/** Create a trace file from a URI
660 *
661 * @param uri containing a valid libtrace URI
662 * @return an opaque pointer to a libtrace_t
663 *
664 * Valid URI's are:
665 *  - erf:/path/to/erf/file
666 *  - erf:-  (stdin)
667 *  - dag:/dev/dagcard                 
668 *  - pcapint:pcapinterface                (eg: pcap:eth0)
669 *  - pcap:/path/to/pcap/file
670 *  - pcap:-
671 *  - rt:hostname
672 *  - rt:hostname:port
673 *  - rtclient:hostname (deprecated)
674 *  - rtclient:hostname:port (deprecated)
675 *
676 *  If an error occured when attempting to open the trace file, an error
677 *  trace is returned and trace_get_error should be called to find out
678 *  if an error occured, and what that error was.  The trace is created in the
679 *  configuration state, you must call trace_start to start the capture.
680 */
681DLLEXPORT libtrace_t *trace_create(const char *uri);
682
683/** Creates a "dummy" trace file that has only the format type set.
684 *
685 * @return an opaque pointer to a (sparsely initialised) libtrace_t
686 *
687 * IMPORTANT: Do not attempt to call trace_read_packet or other such functions
688 * with the dummy trace. Its intended purpose is to act as a packet->trace for
689 * libtrace_packet_t's that are not associated with a libtrace_t structure.
690 */
691DLLEXPORT libtrace_t *trace_create_dead(const char *uri);
692
693/** Creates a trace output file from a URI.
694 *
695 * @param uri   the uri string describing the output format and destination
696 * @return an opaque pointer to a libtrace_output_t
697 *
698 * Valid URI's are:
699 *  - erf:/path/to/erf/file
700 *  - pcap:/path/to/pcap/file
701 *  - wtf:/path/to/wtf/file
702 *
703 *  If an error occured when attempting to open the output trace, NULL is returned
704 *  and trace_errno is set. Use trace_perror_output() to get more information
705 */
706DLLEXPORT libtrace_out_t *trace_create_output(const char *uri);
707
708/** Start the capture
709 * @param libtrace      The trace to start
710 * @return 0 on success, -1 on failure
711 *
712 * This does the actual work with starting the trace capture, and applying
713 * all the config options.  This may fail.
714 */
715DLLEXPORT int trace_start(libtrace_t *libtrace);
716
717/** Pause the capture
718 * @param libtrace      The trace to pause
719 * @return 0 on success, -1 on failure
720 *
721 * This stops a capture in progress and returns you to the configuration
722 * state.  Any packets that arrive after trace_pause() has been called
723 * will be discarded.  To resume capture, call trace_start().
724 */
725DLLEXPORT int trace_pause(libtrace_t *libtrace);
726
727/** Start an output trace
728 * @param libtrace      The trace to start
729 * @return 0 on success, -1 on failure
730 *
731 * This does the actual work with starting a trace for write.  This generally
732 * creates the file.
733 */
734DLLEXPORT int trace_start_output(libtrace_out_t *libtrace);
735
736/** Valid trace capture options */
737typedef enum {
738        TRACE_OPTION_SNAPLEN,   /**< Number of bytes captured */
739        TRACE_OPTION_PROMISC,   /**< Capture packets to other hosts */
740        TRACE_OPTION_FILTER,    /**< Apply this filter to all packets */
741        TRACE_OPTION_META_FREQ, /**< Frequency of meta-data information, e.g. DUCK packets */
742        /** trace_event ignores gaps between packets when reading traces off disk */
743        TRACE_OPTION_EVENT_REALTIME
744} trace_option_t;
745
746/** Sets an input config option
747 * @param libtrace      the trace object to apply the option to
748 * @param option        the option to set
749 * @param value         the value to set the option to
750 * @return -1 if option configuration failed, 0 otherwise
751 * This should be called after trace_create, and before trace_start
752 */
753DLLEXPORT int trace_config(libtrace_t *libtrace,
754                trace_option_t option,
755                void *value);
756
757typedef enum {
758        TRACE_OPTION_OUTPUT_FILEFLAGS, /**< File flags to open the trace file
759                                        * with.  eg O_APPEND
760                                        */
761        TRACE_OPTION_OUTPUT_COMPRESS   /**< Compression level, eg 6. */
762} trace_option_output_t;
763
764/** Sets an output config option
765 *
766 * @param libtrace      the output trace object to apply the option to
767 * @param option        the option to set
768 * @param value         the value to set the option to
769 * @return -1 if option configuration failed, 0 otherwise
770 * This should be called after trace_create_output, and before
771 * trace_start_output
772 */
773DLLEXPORT int trace_config_output(libtrace_out_t *libtrace,
774                trace_option_output_t option,
775                void *value
776                );
777
778/** Close a trace file, freeing up any resources it may have been using
779 *
780 */
781DLLEXPORT void trace_destroy(libtrace_t *trace);
782
783/** Close a trace file, freeing up any resources it may have been using
784 * @param trace         trace file to be destroyed
785 */
786DLLEXPORT void trace_destroy_dead(libtrace_t *trace);
787
788/** Close a trace output file, freeing up any resources it may have been using
789 * @param trace         the output trace file to be destroyed
790 */
791DLLEXPORT void trace_destroy_output(libtrace_out_t *trace);
792
793/** Check (and clear) the current error state of an input trace
794 * @param trace         the trace file to check the error state on
795 * @return Error report
796 * This reads and returns the current error state and sets the current error
797 * to "no error".
798 */
799DLLEXPORT libtrace_err_t trace_get_err(libtrace_t *trace);
800
801/** Return if there is an error
802 * @param trace         the trace file to check the error state on
803 * This does not clear the error status, and only returns true or false.
804 */
805DLLEXPORT bool trace_is_err(libtrace_t *trace);
806
807/** Output an error message to stderr and clear the error status.
808 * @param trace         the trace with the error to output
809 * @param msg           the message to prefix to the error
810 * This function does clear the error status.
811 */
812DLLEXPORT void trace_perror(libtrace_t *trace, const char *msg,...) PRINTF(2,3);
813
814/** Check (and clear) the current error state of an output trace
815 * @param trace         the output trace file to check the error state on
816 * @return Error report
817 * This reads and returns the current error state and sets the current error
818 * to "no error".
819 */
820DLLEXPORT libtrace_err_t trace_get_err_output(libtrace_out_t *trace);
821
822/** Return if there is an error
823 * @param trace         the trace file to check the error state on
824 * This does not clear the error status, and only returns true or false.
825 */
826DLLEXPORT bool trace_is_err_output(libtrace_out_t *trace);
827
828/** Output an error message to stderr and clear the error status.
829 * @param trace         the trace with the error to output
830 * @param msg           the message to prefix to the error
831 * This function does clear the error status.
832 */
833DLLEXPORT void trace_perror_output(libtrace_out_t *trace, const char *msg,...)
834        PRINTF(2,3);
835
836
837/*@}*/
838
839/** @name Reading/Writing packets
840 * These members deal with creating, reading and writing packets
841 *
842 * @{
843 */
844
845/** Create a new packet object
846 *
847 * @return a pointer to an initialised libtrace_packet_t object
848 */
849DLLEXPORT libtrace_packet_t *trace_create_packet(void);
850
851/** Copy a packet
852 * @param packet        the source packet to copy
853 * @return a new packet which has the same content as the source packet
854 * @note This always involves a copy, which can be slow.  Use of this
855 * function should be avoided where possible.
856 * @par The reason you would want to use this function is that a zerocopied
857 * packet from a device is using the devices memory which may be a limited
858 * resource.  Copying the packet will cause it to be copied into the systems
859 * memory.
860 */
861DLLEXPORT libtrace_packet_t *trace_copy_packet(const libtrace_packet_t *packet);
862
863/** Destroy a packet object
864 *
865 * sideeffect: sets packet to NULL
866 */
867DLLEXPORT void trace_destroy_packet(libtrace_packet_t *packet);
868
869
870/** Read one packet from the trace
871 *
872 * @param trace         the libtrace opaque pointer
873 * @param packet        the packet opaque pointer
874 * @return 0 on EOF, negative value on error, number of bytes read when
875 * successful.
876 *
877 * @note the number of bytes read is usually (but not always) the same as
878 * trace_get_framing_length()+trace_get_capture_length() depending on the
879 * trace format.
880 * @note the trace must have been started with trace_start before calling
881 * this function
882 */
883DLLEXPORT int trace_read_packet(libtrace_t *trace, libtrace_packet_t *packet);
884
885/** Event types
886 * see \ref libtrace_eventobj_t and \ref trace_event
887 */
888typedef enum {
889        TRACE_EVENT_IOWAIT,     /**< Need to block on fd */
890        TRACE_EVENT_SLEEP,      /**< Sleep for some time */
891        TRACE_EVENT_PACKET,     /**< packet has arrived */
892        TRACE_EVENT_TERMINATE   /**< End of trace */
893} libtrace_event_t;
894
895/** Structure returned by libtrace_event explaining what the current event is */
896typedef struct libtrace_eventobj_t {
897        libtrace_event_t type; /**< event type (iowait,sleep,packet) */
898        int fd;                /**< if IOWAIT, the fd to sleep on */
899        double seconds;        /**< if SLEEP, the amount of time to sleep for
900                                */
901        int size;              /**< if PACKET, the value returned from
902                                *  trace_read_packet
903                                */
904} libtrace_eventobj_t;
905
906/** Processes the next libtrace event
907 * @param trace the libtrace opaque pointer
908 * @param packet the libtrace_packet opaque pointer
909 * @return libtrace_event struct containing the type, and potential
910 *      fd or seconds to sleep on
911 *
912 * Type can be:
913 *  TRACE_EVENT_IOWAIT  Waiting on I/O on fd
914 *  TRACE_EVENT_SLEEP   Next event in seconds
915 *  TRACE_EVENT_PACKET  Packet arrived in buffer with size size
916 *  TRACE_EVENT_TERMINATE Trace terminated (perhaps with an error condition)
917 */
918DLLEXPORT libtrace_eventobj_t trace_event(libtrace_t *trace,
919                libtrace_packet_t *packet);
920
921
922/** Write one packet out to the output trace
923 *
924 * @param trace         the libtrace_out opaque pointer
925 * @param packet        the packet opaque pointer
926 * @return the number of bytes written out, if zero or negative then an error has occured.
927 */
928DLLEXPORT int trace_write_packet(libtrace_out_t *trace, libtrace_packet_t *packet);
929/*@}*/
930
931/** @name Protocol decodes
932 * These functions locate and return a pointer to various headers inside a
933 * packet
934 * @{
935 */
936
937
938/** Gets a pointer to the first byte of the packet as it was captured and
939 * returns its corresponding linktype and capture length.
940 *
941 * Use this function instead of the deprecated trace_get_link().
942 *
943 * @param packet the packet pointer
944 * @param[out] linktype the linktype of the returned pointer
945 * @param[out] remaining the capture length (the number of captured bytes from
946 * the returned pointer)
947 * @return a pointer to the first byte of the packet
948 */
949DLLEXPORT void *trace_get_packet_buffer(const libtrace_packet_t *packet,
950                libtrace_linktype_t *linktype, uint32_t *remaining);
951
952/** get a pointer to the link layer
953 * @param packet        the packet opaque pointer
954 *
955 * @return a pointer to the link layer, or NULL if there is no link layer
956 *
957 * @deprecated This function is deprecated: Use trace_get_packet_buffer() or
958 * one of the trace_get_layer*() functions instead.
959 * @note you should call trace_get_link_type to find out what type of link
960 * layer this is
961 */
962DLLEXPORT SIMPLE_FUNCTION DEPRECATED
963void *trace_get_link(const libtrace_packet_t *packet);
964
965/** get a pointer to the IPv4 header (if any)
966 * @param packet        the packet opaque pointer
967 *
968 * @return a pointer to the IPv4 header, or NULL if there is no IPv4 header
969 *
970 * You should consider using \ref trace_get_layer3 instead of this function.
971 */
972DLLEXPORT SIMPLE_FUNCTION
973libtrace_ip_t *trace_get_ip(libtrace_packet_t *packet);
974
975/** get a pointer to the IPv6 header (if any)
976 * @param packet        the packet opaque pointer
977 *
978 * @return a pointer to the IPv6 header, or NULL if there is no IPv6 header
979 *
980 * You should consider using \ref trace_get_layer3 instead of this function.
981 */
982DLLEXPORT SIMPLE_FUNCTION
983libtrace_ip6_t *trace_get_ip6(libtrace_packet_t *packet);
984
985/** Return a pointer to the first metadata header in a packet, if present.
986 *
987 * This function takes a pointer to a libtrace packet and if any metadata
988 * headers exist, returns a pointer to the first one, along with its
989 * corresponding linktype.
990 *
991 * If no metadata headers exist in the packet, NULL is returned.
992 *
993 * A metadata header is a header that was prepended by the capturing device,
994 * such as a Linux SLL header, or a Radiotap wireless monitoring header.
995 * Subsequent metadata headers may be accessed with the
996 * trace_get_payload_from_meta(...) function.
997 *
998 * @param packet the libtrace packet
999 * @param[out] linktype the linktype of the returned metadata header
1000 * @param[out] remaining the number of bytes captured after the returned
1001 * pointer.
1002 * @return a pointer to the first metadata header, or NULL if there are no
1003 * metadata headers present.
1004 *
1005 * remaining may be NULL, however linktype must be provided.
1006 */
1007DLLEXPORT void *trace_get_packet_meta(const libtrace_packet_t *packet,
1008                libtrace_linktype_t *linktype,
1009                uint32_t *remaining);
1010
1011/** Returns the payload of a metadata header.
1012 *
1013 * This function takes a pointer to the start of a metadata header (either
1014 * obtained via trace_get_packet_meta(...) or by a previous call to
1015 * trace_get_payload_from_meta(...)) along with its corresponding linktype and
1016 * returns the payload, i.e. the next header. It will also update the linktype
1017 * parameter to indicate the type of payload.
1018 * 
1019 * If the linktype indicates that the header passed in is not a metadata
1020 * header, the function returns NULL to indicate this. The linktype remains
1021 * unchanged in this case.
1022 *
1023 * This function allows the user to iterate through metadata headers which are
1024 * sometimes present before the actual packet as it was received on the wire.
1025 * Examples of metadata headers include the Linux SLL header and the Radiotap
1026 * wireless monitoring header.
1027 *
1028 * @param[in] meta a pointer to a header
1029 * @param[in,out] linktype the linktype of meta (updated to indicate the
1030 * linktype of the returned header if applicable).
1031 * @param[in,out] remaining the number of bytes after the meta pointer.
1032 * @return a pointer to the payload of the metadata header. If meta is not a
1033 * pointer to a metadata header, NULL is returned and linktype remains
1034 * unchanged.
1035 *
1036 * All parameters are mandatory. NULL will be returned if any are NULL.
1037 */
1038DLLEXPORT void *trace_get_payload_from_meta(const void *meta,
1039                libtrace_linktype_t *linktype,
1040                uint32_t *remaining);
1041
1042
1043/** Get a pointer to the layer 2 header. Generally this is the first byte of the
1044 * packet as it was seen on the wire.
1045 *
1046 * This function takes a libtrace packet and skips over any metadata headers if
1047 * present (such as Linux SLL or Radiotap) and returns a pointer to the first
1048 * byte of the packet that was actually received by the network interface.
1049 *
1050 * @param packet the libtrace packet
1051 * @param[out] linktype the linktype of the returned layer 2 header
1052 * @param[out] remaining the number of bytes left in the packet after the
1053 * returned pointer.
1054 * @return a pointer to the first byte of the packet as it was seen on the
1055 * wire.
1056 *
1057 * remaining may be NULL, otherwise it will be filled in by the function.
1058 */
1059DLLEXPORT void *trace_get_layer2(const libtrace_packet_t *packet,
1060                libtrace_linktype_t *linktype,
1061                uint32_t *remaining);
1062
1063/** Gets a pointer to the next header given a pointer to a layer2 header
1064 *
1065 * @param l2                    The pointer to the current layer2 header
1066 * @param linktype              The type of the layer2 header
1067 * @param[out] ethertype        An optional output variable of the ethernet type
1068 * @param[in,out] remaining     Optionally updated with the length remaining
1069 *
1070 * @return a pointer to the transport layer header, or NULL if header isn't
1071 * present.
1072 *
1073 * type may be NULL if not needed.
1074 *
1075 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1076 * of bytes captured of the layer2 header and beyond.  It will be decremented
1077 * by the number of bytes skipped to find the payload.
1078 *
1079 */
1080DLLEXPORT void *trace_get_payload_from_layer2(void *l2,
1081                libtrace_linktype_t linktype,
1082                uint16_t *ethertype,
1083                uint32_t *remaining);
1084
1085
1086/** Get a pointer to the layer 3 header.
1087 * @param packet                The packet opaque pointer
1088 * @param[out] ethertype        The ethertype of the layer 3 header
1089 * @param[out] remaining        The amount of space available after this header
1090 *                              has been removed.
1091 *
1092 * @return a pointer to the layer 3 header.
1093 * remaining may be NULL, otherwise it will be set to the number of captured
1094 * bytes after the pointer returned.
1095 */
1096DLLEXPORT SIMPLE_FUNCTION
1097void *trace_get_layer3(const libtrace_packet_t *packet,
1098                uint16_t *ethertype, uint32_t *remaining);
1099
1100/** Gets a pointer to the transport layer header (if any)
1101 * @param packet        a pointer to a libtrace_packet structure
1102 * @param[out] proto    transport layer protocol
1103 *
1104 * @return a pointer to the transport layer header, or NULL if there is no
1105 * header
1106 *
1107 * @note proto may be NULL if proto is unneeded.
1108 */
1109DLLEXPORT void *trace_get_transport(const libtrace_packet_t *packet,
1110                uint8_t *proto, uint32_t *remaining);
1111
1112/** Gets a pointer to the payload given a pointer to the IP header
1113 * @param ip            The IP Header
1114 * @param[out] proto    An output variable of the IP protocol
1115 * @param[in,out] remaining Updated with the number of bytes remaining
1116 *
1117 * @return a pointer to the transport layer header, or NULL if header isn't
1118 * present.
1119 *
1120 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1121 * of bytes captured of the IP header and beyond.  It will be decremented by
1122 * the length of the IPv4 header (including any options).
1123 *
1124 * proto may be NULL if not needed.
1125 *
1126 * @note This is similar to trace_get_transport_from_ip in libtrace2
1127 */
1128DLLEXPORT void *trace_get_payload_from_ip(libtrace_ip_t *ip, uint8_t *proto,
1129                uint32_t *remaining);
1130
1131/** Gets a pointer to the payload given a pointer to the IPv6 header
1132 * @param ipptr         The IPv6 Header
1133 * @param[out] proto    An output variable of the protocol of the next header
1134 * @param[in,out] remaining Updated with the number of bytes remaining
1135 *
1136 * @return a pointer to the transport layer header, or NULL if the IPv6 header
1137 * isn't complete.
1138 *
1139 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1140 * of bytes captured of the IP header and beyond.  It will be decremented by
1141 * this function by the length of the IPV6 header.
1142 *
1143 * proto may be NULL if not needed.
1144 *
1145 */
1146DLLEXPORT void *trace_get_payload_from_ip6(libtrace_ip6_t *ipptr,
1147                uint8_t *prot, uint32_t *remaining);
1148
1149/** Gets a pointer to the payload given a pointer to the link header
1150 * @param ip            The link pointer
1151 * @param[out] type     An output variable of the ethernet type
1152 * @param[in,out] remaining Updated with the number of bytes remaining
1153 *
1154 * @return a pointer to the transport layer header, or NULL if header isn't
1155 * present.
1156 *
1157 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1158 * of bytes captured of the linklayer and beyond.  It will be updated after
1159 * this function to the number of bytes remaining after the IP header (and any
1160 * IP options) have been removed.
1161 *
1162 * type may be NULL if not needed.
1163 *
1164 */
1165DLLEXPORT void *trace_get_payload_from_link(void *linkptr,
1166                libtrace_linktype_t linktype,
1167                uint16_t *type, uint32_t *remaining);
1168
1169/** Skips over any 802.1q headers, if present.
1170 * @param ethernet      A pointer to the payload following an ethernet header
1171 * -usually the result of calling trace_get_payload_from_link
1172 * @param[in,out] type  The ethernet type, replaced with the vlan ether type
1173 * @param[in,out] remaining Updated with the number of bytes remaining
1174 *
1175 * @return a pointer to the header beyond the vlan header, if present.
1176 * Otherwise, returns the ethernet payload that was passed in
1177 *
1178 * Remaining may be NULL. If Remaining is not NULL it must point to the number
1179 * of bytes captured past (but not including) the link layer. This function
1180 * will decrement it by the length of the 802.1q headers if present.
1181 *
1182 * Type must point to the value of the ethernet type. Libtrace will assert
1183 * fail if type is NULL.
1184 *
1185 */
1186DLLEXPORT void *trace_get_vlan_payload_from_ethernet_payload(
1187                void *ethernet_payload, uint16_t *type, uint32_t *remaining);
1188
1189/** Gets a pointer to the payload given a pointer to a tcp header
1190 * @param tcp           The tcp Header
1191 * @param[in,out] remaining Updated with the number of bytes remaining
1192 *
1193 * @return a pointer to the tcp payload, or NULL if the payload isn't present.
1194 *
1195 * Remaining may be NULL.  If remaining is not NULL it must point to the number
1196 * of bytes captured of the TCP header and beyond.  It will be decremented by
1197 * this function by the length of the TCP header (including any options).
1198 *
1199 */
1200DLLEXPORT void *trace_get_payload_from_tcp(libtrace_tcp_t *tcp,
1201                uint32_t *remaining);
1202
1203/** Gets a pointer to the payload given a pointer to a udp header
1204 * @param udp           The udp Header
1205 * @param[in,out] remaining Updated with the number of bytes remaining
1206 *
1207 * @return a pointer to the udp payload, or NULL if the payload isn't present.
1208 *
1209 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1210 * of bytes captured of the UDP header and beyond.  It will be decremented by
1211 * this function to the number of bytes remaining after the UDP header.
1212 *
1213 */
1214DLLEXPORT void *trace_get_payload_from_udp(libtrace_udp_t *udp, uint32_t *remaining);
1215
1216/** Gets a pointer to the payload given a pointer to a icmp header
1217 * @param icmp          The icmp Header
1218 * @param[in,out] remaining Updated with the number of bytes remaining
1219 *
1220 * @return a pointer to the icmp payload, or NULL if the payload isn't present.
1221 *
1222 * Remaining may be NULL.  If remaining is not NULL it must point to the number
1223 * of bytes captured of the ICMP header and beyond.  It will be decremented
1224 * by the number of bytes in the ICMP header.
1225 *
1226 */
1227DLLEXPORT void *trace_get_payload_from_icmp(libtrace_icmp_t *icmp,
1228                uint32_t *remaining);
1229
1230/** get a pointer to the TCP header (if any)
1231 * @param packet        the packet opaque pointer
1232 *
1233 * @return a pointer to the TCP header, or NULL if there is not a TCP packet
1234 *
1235 * @note you should probably use trace_get_transport()
1236 */
1237DLLEXPORT SIMPLE_FUNCTION
1238libtrace_tcp_t *trace_get_tcp(libtrace_packet_t *packet);
1239
1240/** get a pointer to the TCP header (if any) given a pointer to the IP header
1241 * @param ip            The IP header
1242 * @param[in,out] remaining Updated with the number of bytes remaining
1243 *
1244 * @return a pointer to the TCP header, or NULL if this is not a TCP packet
1245 *
1246 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1247 * of bytes captured of the TCP header and beyond.  It will be decremented by
1248 * the number of bytes in the TCP header (including any TCP options).
1249 *
1250 * @note The last parameter has changed from libtrace2
1251 */
1252DLLEXPORT SIMPLE_FUNCTION
1253libtrace_tcp_t *trace_get_tcp_from_ip(libtrace_ip_t *ip, uint32_t *remaining);
1254
1255/** get a pointer to the UDP header (if any)
1256 * @param packet        the packet opaque pointer
1257 *
1258 * @return a pointer to the UDP header, or NULL if this is not a UDP packet
1259 */
1260DLLEXPORT SIMPLE_FUNCTION
1261libtrace_udp_t *trace_get_udp(libtrace_packet_t *packet);
1262
1263/** get a pointer to the UDP header (if any) given a pointer to the IP header
1264 * @param       ip      The IP header
1265 * @param[in,out] remaining Updated with the number of bytes remaining
1266 *
1267 * @return a pointer to the UDP header, or NULL if this is not an UDP packet
1268 *
1269 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1270 * of bytes captured of the UDP header and beyond.  This function will
1271 * decremented it by the length of the UDP header.
1272 *
1273 * @note Beware the change from libtrace2 from skipped to remaining
1274 */
1275DLLEXPORT SIMPLE_FUNCTION
1276libtrace_udp_t *trace_get_udp_from_ip(libtrace_ip_t *ip,uint32_t *remaining);
1277
1278/** get a pointer to the ICMP header (if any)
1279 * @param packet        the packet opaque pointer
1280 *
1281 * @return a pointer to the ICMP header, or NULL if this is not a ICMP packet
1282 */
1283DLLEXPORT SIMPLE_FUNCTION
1284libtrace_icmp_t *trace_get_icmp(libtrace_packet_t *packet);
1285
1286/** get a pointer to the ICMP header (if any) given a pointer to the IP header
1287 * @param ip            The IP header
1288 * @param[in,out] remaining Updated with the number of bytes remaining
1289 *
1290 * @return a pointer to the ICMP header, or NULL if this is not an ICMP packet
1291 *
1292 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1293 * of bytes captured of the ICMP header and beyond.  It will be decremented by
1294 * the length of the ICMP head in bytes.
1295 *
1296 * @note Beware the change from libtrace2 from skipped to remaining
1297 */
1298DLLEXPORT SIMPLE_FUNCTION
1299libtrace_icmp_t *trace_get_icmp_from_ip(libtrace_ip_t *ip,uint32_t *remaining);
1300
1301/** Get the destination MAC address
1302 * @param packet        the packet opaque pointer
1303 * @return a pointer to the destination mac, (or NULL if there is no
1304 * destination MAC)
1305 */
1306DLLEXPORT SIMPLE_FUNCTION
1307uint8_t *trace_get_destination_mac(libtrace_packet_t *packet);
1308
1309/** Get the source MAC address
1310 * @param packet        the packet opaque pointer
1311 * @return a pointer to the source mac, (or NULL if there is no source MAC)
1312 */
1313DLLEXPORT SIMPLE_FUNCTION
1314uint8_t *trace_get_source_mac(libtrace_packet_t *packet);
1315
1316/** Get the source IP address
1317 * @param packet        the packet opaque pointer
1318 * @param addr          a pointer to a sockaddr to store the address in, or NULL to use
1319 *                      static storage.
1320 * @return NULL if there is no source address, or a sockaddr holding a v4 or v6
1321 * address
1322 */
1323DLLEXPORT SIMPLE_FUNCTION
1324struct sockaddr *trace_get_source_address(const libtrace_packet_t *packet,
1325                struct sockaddr *addr);
1326
1327/** Get the destination IP address
1328 * @param packet        the packet opaque pointer
1329 * @param addr          a pointer to a sockaddr to store the address in, or NULL to use
1330 *                      static storage.
1331 * @return NULL if there is no destination address, or a sockaddr holding a v4
1332 * or v6 address
1333 */
1334DLLEXPORT SIMPLE_FUNCTION
1335struct sockaddr *trace_get_destination_address(const libtrace_packet_t *packet,
1336                struct sockaddr *addr);
1337
1338/*@}*/
1339
1340/** parse an ip or tcp option
1341 * @param[in,out] ptr   the pointer to the current option
1342 * @param[in,out] len   the length of the remaining buffer
1343 * @param[out] type     the type of the option
1344 * @param[out] optlen   the length of the option
1345 * @param[out] data     the data of the option
1346 *
1347 * @return bool true if there is another option (and the fields are filled in)
1348 *               or false if this was the last option.
1349 *
1350 * This updates ptr to point to the next option after this one, and updates
1351 * len to be the number of bytes remaining in the options area.  Type is updated
1352 * to be the code of this option, and data points to the data of this option,
1353 * with optlen saying how many bytes there are.
1354 *
1355 * @note Beware of fragmented packets.
1356 */
1357DLLEXPORT int trace_get_next_option(unsigned char **ptr,int *len,
1358                        unsigned char *type,
1359                        unsigned char *optlen,
1360                        unsigned char **data);
1361
1362
1363/** @name Time
1364 * These functions deal with time that a packet arrived and return it
1365 * in various formats
1366 * @{
1367 */
1368/** Get the current time in DAG time format
1369 * @param packet        the packet opaque pointer
1370 *
1371 * @return a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds
1372 * past 1970-01-01, the lower 32bits are partial seconds)
1373 */
1374DLLEXPORT SIMPLE_FUNCTION
1375uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet);
1376
1377/** Get the current time in struct timeval
1378 * @param packet        the packet opaque pointer
1379 *
1380 * @return time that this packet was seen in a struct timeval
1381 */
1382DLLEXPORT SIMPLE_FUNCTION
1383struct timeval trace_get_timeval(const libtrace_packet_t *packet);
1384
1385/** Get the current time in floating point seconds
1386 * @param packet        the packet opaque pointer
1387 *
1388 * @return time that this packet was seen in 64bit floating point seconds from
1389 * the unix epoch (1970-01-01 00:00:00 UTC).
1390 */
1391DLLEXPORT SIMPLE_FUNCTION
1392double trace_get_seconds(const libtrace_packet_t *packet);
1393
1394/** Seek within a trace
1395 * @param trace         trace to seek
1396 * @param seconds       time to seek to
1397 * @return 0 on success.
1398 * Make the next packet read to be the first packet to occur at or after the
1399 * time searched for.  This must be called in the configuration state (ie,
1400 * before trace_start() or after trace_pause().
1401 * @note This function may be extremely slow.
1402 */
1403DLLEXPORT int trace_seek_seconds(libtrace_t *trace, double seconds);
1404
1405/** Seek within a trace
1406 * @param trace         trace to seek
1407 * @param tv            time to seek to
1408 * @return 0 on success.
1409 * Make the next packet read to be the first packet to occur at or after the
1410 * time searched for.  This must be called in the configuration state (ie,
1411 * before trace_start() or after trace_pause().
1412 * @note This function may be extremely slow.
1413 */
1414DLLEXPORT int trace_seek_timeval(libtrace_t *trace, struct timeval tv);
1415
1416/** Seek within a trace
1417 * @param trace         trace to seek
1418 * @param ts            erf timestamp
1419 * @return 0 on success.
1420 * Make the next packet read to be the first packet to occur at or after the
1421 * time searched for.  This must be called in the configuration state (ie,
1422 * before trace_start() or after trace_pause().
1423 * @note This function may be extremely slow.
1424 */
1425DLLEXPORT int trace_seek_erf_timestamp(libtrace_t *trace, uint64_t ts);
1426
1427/*@}*/
1428
1429/** @name Sizes
1430 * This section deals with finding or setting the various different lengths
1431 * a packet can have
1432 * @{
1433 */
1434/** Get the size of the packet in the trace (in bytes)
1435 * @param packet        the packet opaque pointer
1436 * @return the size of the packet in the trace
1437 * @note Due to this being a header capture, or anonymisation, this may not
1438 * be the same size as the original packet.  See get_wire_length() for the
1439 * original size of the packet.
1440 * @note This can (and often is) different for different packets in a trace!
1441 * @note This is sometimes called the "snaplen".
1442 * @note The return size refers to the network-level payload of the packet and
1443 * does not include any capture framing headers. For example, an Ethernet
1444 * packet with an empty TCP packet will return sizeof(ethernet_header) +
1445 * sizeof(ip_header) + sizeof(tcp_header), but not the capture file
1446 * (pcap/erf/etc) header.
1447 */
1448DLLEXPORT SIMPLE_FUNCTION
1449size_t trace_get_capture_length(const libtrace_packet_t *packet);
1450
1451/** Get the size of the packet as it was seen on the wire (in bytes).
1452 * @param packet        the packet opaque pointer
1453 * @return the size of the packet as it was on the wire.
1454 * @note Due to the trace being a header capture, or anonymisation this may
1455 * not be the same as the Capture Len.
1456 * @note trace_getwire_length \em{includes} FCS.
1457 * @note The return size refers to the network-level payload of the packet and
1458 * does not include any capture framing headers. For example, an Ethernet
1459 * packet with an empty TCP packet will return sizeof(ethernet_header) +
1460 * sizeof(ip_header) + sizeof(tcp_header), but not the capture file
1461 * (pcap/erf/etc) header.
1462 */
1463DLLEXPORT SIMPLE_FUNCTION
1464size_t trace_get_wire_length(const libtrace_packet_t *packet);
1465
1466/** Get the length of the capture framing headers (in bytes).
1467 * @param packet        the packet opaque pointer
1468 * @return the size of the packet as it was on the wire.
1469 * @note this length corresponds to the difference between the size of a
1470 * captured packet in memory, and the captured length of the packet
1471 */
1472DLLEXPORT SIMPLE_FUNCTION
1473size_t trace_get_framing_length(const libtrace_packet_t *packet);
1474
1475/** Truncate ("snap") the packet at the suggested length
1476 * @param packet        the packet opaque pointer
1477 * @param size          the new length of the packet (in bytes)
1478 * @return the new capture length of the packet, or the original capture
1479 * length of the packet if unchanged
1480 */
1481DLLEXPORT size_t trace_set_capture_length(libtrace_packet_t *packet, size_t size);
1482
1483/*@}*/
1484
1485
1486/** Get the type of the link layer
1487 * @param packet        the packet opaque pointer
1488 * @return libtrace_linktype_t
1489 */
1490DLLEXPORT SIMPLE_FUNCTION
1491libtrace_linktype_t trace_get_link_type(const libtrace_packet_t *packet);
1492
1493/** Set the direction flag, if it has one
1494 * @param packet        the packet opaque pointer
1495 * @param direction     the new direction
1496 * @returns -1 on error, or the direction that was set.
1497 */
1498DLLEXPORT libtrace_direction_t trace_set_direction(libtrace_packet_t *packet, libtrace_direction_t direction);
1499
1500/** Get the direction flag, if it has one
1501 * @param packet        the packet opaque pointer
1502 * @return a value containing the direction flag, or -1 if this is not supported
1503 * The direction is defined as 0 for packets originating locally (ie, outbound)
1504 * and 1 for packets originating remotely (ie, inbound).
1505 * Other values are possible, which might be overloaded to mean special things
1506 * for a special trace.
1507 */
1508DLLEXPORT SIMPLE_FUNCTION
1509libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet);
1510
1511/** @name BPF
1512 * This section deals with using Berkley Packet Filters
1513 * @{
1514 */
1515/** setup a BPF filter
1516 * @param filterstring a char * containing the bpf filter string
1517 * @return opaque pointer pointer to a libtrace_filter_t object
1518 * @note The filter is not actually compiled at this point, so no correctness
1519 * tests are performed here. trace_create_filter will always return ok, but
1520 * if the filter is poorly constructed an error will be generated when the
1521 * filter is actually used
1522 */
1523DLLEXPORT SIMPLE_FUNCTION
1524libtrace_filter_t *trace_create_filter(const char *filterstring);
1525
1526/** Setup a BPF filter based on pre-compiled byte-code.
1527 * @param bf_insns      A pointer to the start of the byte-code
1528 * @param bf_len        The number of BPF instructions 
1529 * @returns             an opaque pointer to a libtrace_filter_t object
1530 * @note                The supplied byte-code is not checked for correctness.
1531 * @author              Scott Raynel
1532 */
1533DLLEXPORT libtrace_filter_t *
1534trace_create_filter_from_bytecode(void *bf_insns, unsigned int bf_len);
1535
1536/** Apply a BPF filter to a packet
1537 * @param filter        the filter opaque pointer
1538 * @param packet        the packet opaque pointer
1539 * @return >0 if the filter matches, 0 if it doesn't, -1 on error.
1540 * @note Due to the way BPF filters are built, the filter is not actually
1541 * compiled until the first time trace_create_filter is called. If your filter
1542 * is incorrect, it will generate an error message and assert, exiting the
1543 * program. This behaviour may change to more graceful handling of this error
1544 * in the future.
1545 */
1546DLLEXPORT int trace_apply_filter(libtrace_filter_t *filter,
1547                const libtrace_packet_t *packet);
1548
1549/** Destroy a BPF filter
1550 * @param filter        the filter opaque pointer
1551 * Deallocate all the resources associated with a BPF filter
1552 */
1553DLLEXPORT void trace_destroy_filter(libtrace_filter_t *filter);
1554/*@}*/
1555
1556/** @name Portability
1557 * This section has functions that causes annoyances to portability for one
1558 * reason or another.
1559 * @{
1560 */
1561
1562/** Convert an ethernet address to a string
1563 * @param addr  Ethernet address in network byte order
1564 * @param buf   Buffer to store the ascii representation, or NULL
1565 * @return buf, or if buf is NULL then a statically allocated buffer.
1566 *
1567 * This function is similar to the GNU ether_ntoa_r function, with a few
1568 * minor differences.  if NULL is passed as buf, then the function will
1569 * use an internal static buffer, if NULL isn't passed then the function
1570 * will use that buffer instead.
1571 *
1572 * @note the type of addr isn't struct ether_addr as it is with ether_ntoa_r,
1573 * however it is bit compatible so that a cast will work.
1574 */
1575DLLEXPORT char *trace_ether_ntoa(const uint8_t *addr, char *buf);
1576
1577/** Convert a string to an ethernet address
1578 * @param buf   Ethernet address in hex format delimited with :'s.
1579 * @param addr  buffer to store the binary representation, or NULL
1580 * @return addr, or if addr is NULL, then a statically allocated buffer.
1581 *
1582 * This function is similar to the GNU ether_aton_r function, with a few
1583 * minor differences.  if NULL is passed as addr, then the function will
1584 * use an internal static buffer, if NULL isn't passed then the function will
1585 * use that buffer instead.
1586 *
1587 * @note the type of addr isn't struct ether_addr as it is with ether_aton_r,
1588 * however it is bit compatible so that a cast will work.
1589 */
1590DLLEXPORT uint8_t *trace_ether_aton(const char *buf, uint8_t *addr);
1591
1592/*@}*/
1593
1594
1595/** Which port is the server port */
1596typedef enum {
1597        USE_DEST,       /**< Destination port is the server port */
1598        USE_SOURCE      /**< Source port is the server port */
1599} serverport_t;
1600
1601/** Get the source port
1602 * @param packet        the packet to read from
1603 * @return a port in \em HOST byte order, or equivalent to ports for this
1604 * protocol, or 0 if this protocol has no ports.
1605 */
1606DLLEXPORT SIMPLE_FUNCTION
1607uint16_t trace_get_source_port(const libtrace_packet_t *packet);
1608
1609/** Get the destination port
1610 * @param packet        the packet to read from
1611 * @return a port in \em HOST byte order, or equivilent to ports for this
1612 * protocol, or 0 if this protocol has no ports.
1613 */
1614DLLEXPORT SIMPLE_FUNCTION
1615uint16_t trace_get_destination_port(const libtrace_packet_t *packet);
1616
1617/** hint at the server port in specified protocol
1618 * @param protocol      the IP layer protocol, eg 6 (tcp), 17 (udp)
1619 * @param source        the source port from the packet
1620 * @param dest          the destination port from the packet
1621 * @return one of USE_SOURCE or USE_DEST depending on which one you should use
1622 * @note ports must be in \em HOST byte order!
1623 */
1624DLLEXPORT SIMPLE_FUNCTION
1625int8_t trace_get_server_port(uint8_t protocol, uint16_t source, uint16_t dest);
1626
1627/** Takes a uri and splits it into a format and uridata component.
1628 * @param uri           the uri to be parsed
1629 * @param format        destination location for the format component of the uri
1630 * @return 0 if an error occured, otherwise return the uridata component
1631 */
1632DLLEXPORT const char *trace_parse_uri(const char *uri, char **format);
1633
1634/** Gets the format type for a given packet.
1635 * @param packet        the packet opaque pointer
1636 * @return the format of the packet
1637 */
1638DLLEXPORT
1639enum base_format_t trace_get_format(struct libtrace_packet_t *packet);
1640
1641/** Construct a packet from a buffer.
1642 * @param packet[in,out]        Libtrace Packet object to update with the new
1643 *                              data.
1644 * @param linktype              The linktype of the packet.
1645 * @param[in] data              The packet data (including linklayer)
1646 * @param len                   Length of packet data
1647 */
1648DLLEXPORT
1649void trace_construct_packet(libtrace_packet_t *packet,
1650                libtrace_linktype_t linktype, const void *data, uint16_t len);
1651
1652/*@}*/
1653
1654/** @name Wireless trace support
1655 * Functions to access wireless information from packets that have wireless
1656 * monitoring headers such as Radiotap or Prism.
1657 *
1658 * The trace_get_wireless_* functions provide an abstract interface for
1659 * retrieving information from wireless traces. They take a pointer to the
1660 * wireless monitoring header (usually found with trace_get_link(packet)) and
1661 * the linktype of the header passed in.
1662 *
1663 * All of the trace_get_wireless_* functions return false if the requested
1664 * information was unavailable, or true if it was. The actual data is stored
1665 * in an output variable supplied by the caller. Values returned into the
1666 * output variable will always be returned in host byte order.
1667 * @{
1668 */
1669
1670
1671#ifndef ARPHRD_80211_RADIOTAP
1672/* libc doesn't define this yet, but it seems to be what everyone is using
1673 */
1674#define ARPHRD_80211_RADIOTAP 803
1675#endif
1676
1677/** Get the wireless Timer Syncronisation Function
1678 *
1679 * Gets the value of the timer syncronisation function for this frame, which
1680 * is a value in microseconds indicating the time that the first bit of the
1681 * MPDU was received by the MAC.
1682 *
1683 * @param link the wireless header
1684 * @param linktype the linktype of the wireless header passed in
1685 * @param[out] tsft the value of the timer syncronisation function.
1686 * @return true if the field was available, false if not.
1687 */
1688DLLEXPORT bool trace_get_wireless_tsft(void *linkptr,
1689        libtrace_linktype_t linktype, uint64_t *tsft);
1690
1691/** Get the wireless rate
1692 * @param link the wireless header
1693 * @param linktype the linktype of the wireless header passed in
1694 * @param[out] rate the data-rate of the frame in units of 500kbps
1695 * @return true if the field was available, false if not.
1696 */
1697DLLEXPORT bool trace_get_wireless_rate(void *linkptr,
1698        libtrace_linktype_t linktype, uint8_t *rate);
1699
1700/** Get the wireless channel frequency
1701 * @param link the wireless header
1702 * @param linktype the linktype of the wireless header passed in
1703 * @param[out] freq the frequency in MHz of the channel the frame was transmitted
1704 * or received on.
1705 * @return true if the field was available, false if not.
1706 */
1707DLLEXPORT bool trace_get_wireless_freq(void *linkptr,
1708        libtrace_linktype_t linktype, uint16_t *freq);
1709
1710/** Get the wireless signal strength in dBm
1711 * @param link the wireless header
1712 * @param linktype the linktype of the wireless header passed in
1713 * @param[out] strength the RF signal power at the antenna, in dB difference
1714 * from 1mW.
1715 * @return true if the field was available, false if not.
1716 */
1717DLLEXPORT bool trace_get_wireless_signal_strength_dbm(void *linkptr,
1718        libtrace_linktype_t linktype, int8_t *strength);
1719
1720/** Get the wireless noise strength in dBm
1721 * @param link the wireless header
1722 * @param linktype the linktype of the wireless header passed in
1723 * @param[out] strength the RF noise power at the antenna, in dB difference
1724 * from 1mW.
1725 * @return true if the field was available, false if not.
1726 */
1727DLLEXPORT bool trace_get_wireless_noise_strength_dbm(void *linkptr,
1728        libtrace_linktype_t linktype, int8_t *strength);
1729
1730/** Get the wireless signal strength in dB
1731 * @param link the wireless header
1732 * @param linktype the linktype of the wireless header passed in
1733 * @param[out] strength the RF signal power at the antenna,in dB difference
1734 * from a fixed reference.
1735 * @return true if the field was available, false if not.
1736 */
1737DLLEXPORT bool trace_get_wireless_signal_strength_db(void *linkptr,
1738        libtrace_linktype_t linktype, uint8_t *strength);
1739
1740/** Get the wireless noise strength in dB
1741 * @param link the wireless header
1742 * @param linktype the linktype of the wireless header passed in
1743 * @param[out] strength the RF noise power at the antenna, in dB difference
1744 * from a fixed reference.
1745 * @return true if the field was available, false if not.
1746 */
1747DLLEXPORT bool trace_get_wireless_noise_strength_db(void *linkptr,
1748        libtrace_linktype_t linktype, uint8_t *strength);
1749
1750/** Get the wireless transmit attenuation
1751 * @param link the wireless header
1752 * @param linktype the linktype of the wireless header passed in
1753 * @param[out] attenuation the transmit power as a unitless distance from maximum
1754 * power set at factory calibration. 0 indicates maximum transmission power.
1755 * @return true if the field was available, false if not.
1756 */
1757DLLEXPORT bool trace_get_wireless_tx_attenuation(void *linkptr,
1758        libtrace_linktype_t linktype, uint16_t *attenuation);
1759
1760/** Get the wireless transmit attenuation in dB
1761 * @param link the wireless header
1762 * @param linktype the linktype of the wireless header passed in
1763 * @param[out] attenuation the transmit power as dB difference from maximum power
1764 * set at factory calibration. 0 indicates maximum power.
1765 * @return true if the field was available, false if not.
1766 */
1767DLLEXPORT bool trace_get_wireless_tx_attenuation_db(void *linkptr,
1768        libtrace_linktype_t linktype, uint16_t *attenuation);
1769
1770/** Get the wireless transmit power in dBm @param link the wireless header
1771 * @param linktype the linktype of the wireless header passed in
1772 * @param[out] txpower the transmit power as dB from a 1mW reference. This is the absolute power level measured at the antenna port. 
1773 * @return true if the field was available, false if not.
1774 */
1775DLLEXPORT bool trace_get_wireless_tx_power_dbm(void *linkptr, libtrace_linktype_t
1776                linktype, int8_t *txpower);
1777
1778/** Get the wireless antenna
1779 * @param link the wireless header
1780 * @param linktype the linktype of the wireless header passed in
1781 * @param[out] antenna which antenna was used to transmit or receive the frame.
1782 * @return true if the field was available, false if not.
1783 */
1784DLLEXPORT bool trace_get_wireless_antenna(void *linkptr,
1785        libtrace_linktype_t linktype, uint8_t *antenna);
1786
1787/*@}*/
1788
1789#ifdef __cplusplus
1790} /* extern "C" */
1791#endif /* #ifdef __cplusplus */
1792#endif /* LIBTRACE_H_ */
Note: See TracBrowser for help on using the repository browser.