source: lib/libtrace.h.in @ 8f18776

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 8f18776 was 8f18776, checked in by Perry Lorier <perry@…>, 14 years ago

Avoid using assert() to report errors

  • 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_LAST                   = (2<<31)
322} libtrace_rt_types_t;
323
324/** The libtrace packet structure, applications shouldn't be
325 * meddling around in here
326 */
327typedef struct libtrace_packet_t {
328        struct libtrace_t *trace;       /**< pointer to the trace */
329        void *header;                   /**< pointer to the framing header */
330        void *payload;                  /**< pointer to the link layer */
331        void *buffer;                   /**< allocated buffer */
332        libtrace_rt_types_t  type;      /**< rt protocol type for the packet */
333        buf_control_t buf_control;      /**< who owns the memory */
334        int capture_length;             /**< Cached capture length */
335        void *l3_header;                /**< Cached l3 header */
336        uint16_t l3_ethertype;          /**< Cached l3 ethertype */
337} libtrace_packet_t;
338
339
340/** Trace directions
341 * Note that these are the directions used by convention, more directions
342 * are possible, not just these 3, and that they may not conform to this
343 * convention.
344 */
345typedef enum {
346        TRACE_DIR_OUTGOING = 0,         /**< Packets originating "inside" */
347        TRACE_DIR_INCOMING = 1,         /**< Packets originating "outside" */
348        TRACE_DIR_OTHER    = 2          /**< Packets with an unknown direction, or one that's unknown */
349} libtrace_direction_t;
350
351/** Enumeration of Radiotap fields */
352typedef enum {
353    TRACE_RADIOTAP_TSFT = 0, /**< Timer synchronisation function, in microseconds (uint64) */
354    TRACE_RADIOTAP_FLAGS = 1, /**< Wireless flags (uint8) */
355    TRACE_RADIOTAP_RATE = 2, /**< Bitrate in units of 500kbps (uint8) */
356    TRACE_RADIOTAP_CHANNEL = 3, /**< Frequency in MHz (uint16) and channel flags (uint16) */
357    TRACE_RADIOTAP_FHSS = 4, /**< FHSS hop set (uint8) and hopping pattern (uint8) */
358    TRACE_RADIOTAP_DBM_ANTSIGNAL = 5, /**< Signal power in dBm (int8) */
359    TRACE_RADIOTAP_DBM_ANTNOISE = 6, /**< Noise power in dBm (int8) */
360    TRACE_RADIOTAP_LOCK_QUALITY = 7, /**< Barker Code lock quality (uint16) */
361    TRACE_RADIOTAP_TX_ATTENUATION = 8, /**< TX attenuation as unitless distance from max power (uint16) */
362    TRACE_RADIOTAP_DB_TX_ATTENUATION = 9, /**< TX attenutation as dB from max power (uint16) */
363    TRACE_RADIOTAP_DBM_TX_POWER = 10, /**< TX Power in dBm (int8) */
364    TRACE_RADIOTAP_ANTENNA = 11, /**< Antenna frame was rx'd or tx'd on (uint8) */
365    TRACE_RADIOTAP_DB_ANTSIGNAL = 12, /**< Signal power in dB from a fixed reference (uint8) */
366    TRACE_RADIOTAP_DB_ANTNOISE = 13, /**< Noise power in dB from a fixed reference (uint8) */
367    TRACE_RADIOTAP_RX_FLAGS = 14, /** Properties of received frame (uint16) */
368    TRACE_RADIOTAP_TX_FLAGS = 15, /** Properties of transmitted frame (uint16) */
369    TRACE_RADIOTAP_RTS_RETRIES = 16, /** Number of rts retries frame used (uint8) */
370    TRACE_RADIOTAP_DATA_RETRIES = 17, /** Number of unicast retries a transmitted frame used (uint8) */
371    TRACE_RADIOTAP_EXT = 31
372} libtrace_radiotap_field_t;
373
374
375/** @name Protocol structures
376 * These convenience structures are here as they are portable ways of dealing
377 * with various protocols.
378 * @{
379 */
380
381#ifdef WIN32
382#pragma pack(push)
383#pragma pack(1)
384#endif
385
386/** Generic IP header structure */
387typedef struct libtrace_ip
388{
389#if BYTE_ORDER == LITTLE_ENDIAN
390    LT_BITFIELD8 ip_hl:4;               /**< Header Length */
391    LT_BITFIELD8 ip_v:4;                /**< Version */
392#elif BYTE_ORDER == BIG_ENDIAN
393    LT_BITFIELD8 ip_v:4;                /**< Version */
394    LT_BITFIELD8 ip_hl:4;               /**< Header Length */
395#else
396#   error "Adjust your <bits/endian.h> defines"
397#endif
398    uint8_t  ip_tos;                    /**< Type of Service */
399    uint16_t ip_len;                    /**< Total Length */
400    int16_t  ip_id;                     /**< Identification */
401    uint16_t ip_off;                    /**< IP Fragment offset (and flags) */
402    uint8_t  ip_ttl;                    /**< Time to Live */
403    uint8_t  ip_p;                      /**< Protocol */
404    uint16_t ip_sum;                    /**< Checksum */
405    struct in_addr ip_src;              /**< Source Address */
406    struct in_addr ip_dst;              /**< Destination Address */
407} PACKED libtrace_ip_t;
408
409/** IPv6 header extension structure */
410typedef struct libtrace_ip6_ext
411{
412        uint8_t nxt;
413        uint8_t len;
414} PACKED libtrace_ip6_ext_t;
415
416/** Generic IPv6 header structure */
417typedef struct libtrace_ip6
418{
419    uint32_t flow;
420    uint16_t plen;                      /**< Payload length */
421    uint8_t nxt;                        /**< Next header */
422    uint8_t hlim;                       /**< Hop limit */
423    struct in6_addr ip_src;             /**< source address */
424    struct in6_addr ip_dst;             /**< dest address */
425} PACKED libtrace_ip6_t;
426
427/** Generic TCP header structure */
428typedef struct libtrace_tcp
429  {
430    uint16_t source;            /**< Source Port */
431    uint16_t dest;              /**< Destination port */
432    uint32_t seq;               /**< Sequence number */
433    uint32_t ack_seq;           /**< Acknowledgement Number */
434#  if BYTE_ORDER == LITTLE_ENDIAN
435    LT_BITFIELD8 res1:4;        /**< Reserved bits */
436    LT_BITFIELD8 doff:4;        /**< Data Offset */     
437    LT_BITFIELD8 fin:1;         /**< FIN */
438    LT_BITFIELD8 syn:1;         /**< SYN flag */
439    LT_BITFIELD8 rst:1;         /**< RST flag */
440    LT_BITFIELD8 psh:1;         /**< PuSH flag */
441    LT_BITFIELD8 ack:1;         /**< ACK flag */
442    LT_BITFIELD8 urg:1;         /**< URG flag */
443    LT_BITFIELD8 res2:2;        /**< Reserved */
444#  elif BYTE_ORDER == BIG_ENDIAN
445    LT_BITFIELD8 doff:4;        /**< Data offset */
446    LT_BITFIELD8 res1:4;        /**< Reserved bits */
447    LT_BITFIELD8 res2:2;        /**< Reserved */
448    LT_BITFIELD8 urg:1;         /**< URG flag */
449    LT_BITFIELD8 ack:1;         /**< ACK flag */
450    LT_BITFIELD8 psh:1;         /**< PuSH flag */
451    LT_BITFIELD8 rst:1;         /**< RST flag */
452    LT_BITFIELD8 syn:1;         /**< SYN flag */
453    LT_BITFIELD8 fin:1;         /**< FIN flag */
454#  else
455#   error "Adjust your <bits/endian.h> defines"
456#  endif
457    uint16_t window;            /**< Window Size */
458    uint16_t check;             /**< Checksum */
459    uint16_t urg_ptr;           /**< Urgent Pointer */
460} PACKED libtrace_tcp_t;
461
462/** Generic UDP header structure */
463typedef struct libtrace_udp {
464  uint16_t      source;         /**< Source port */
465  uint16_t      dest;           /**< Destination port */
466  uint16_t      len;            /**< Length */
467  uint16_t      check;          /**< Checksum */
468} PACKED libtrace_udp_t;
469
470/** Generic ICMP header structure */
471typedef struct libtrace_icmp
472{
473  uint8_t type;         /**< Message Type */
474  uint8_t code;         /**< Type Sub-code */
475  uint16_t checksum;            /**< Checksum */
476  union
477  {
478    struct
479    {
480      uint16_t  id;
481      uint16_t  sequence;
482    } echo;                     /**< Echo Datagram */
483    uint32_t    gateway;        /**< Gateway Address */
484    struct
485    {
486      uint16_t  unused;
487      uint16_t  mtu;
488    } frag;                     /**< Path MTU Discovery */
489  } un;                         /**< Union for Payloads of Various ICMP Codes */
490} PACKED libtrace_icmp_t;
491
492/** Generic LLC/SNAP header structure */
493typedef struct libtrace_llcsnap
494{
495/* LLC */
496  uint8_t dsap;                 /**< Destination Service Access Point */
497  uint8_t ssap;                 /**< Source Service Access Point */
498  uint8_t control;
499/* SNAP */
500  LT_BITFIELD32 oui:24;         /**< Organisationally Unique Identifier (scope)*/
501  uint16_t type;                /**< Protocol within OUI */
502} PACKED libtrace_llcsnap_t;
503
504/** 802.3 frame */
505typedef struct libtrace_ether
506{
507  uint8_t ether_dhost[6];       /**< Destination Ether Addr */
508  uint8_t ether_shost[6];       /**< Source Ether Addr */
509  uint16_t ether_type;          /**< Packet Type ID Field (next-header) */
510} PACKED libtrace_ether_t;
511
512/** 802.1Q frame */
513typedef struct libtrace_8021q
514{
515  LT_BITFIELD16 vlan_pri:3;      /**< VLAN User Priority */
516  LT_BITFIELD16 vlan_cfi:1;      /**< VLAN Format Indicator,
517                                   * 0 for ethernet, 1 for token ring */
518  LT_BITFIELD16 vlan_id:12;      /**< VLAN Id */
519  uint16_t vlan_ether_type;      /**< VLAN Sub-packet Type ID Field
520                                   * (next-header)*/
521} PACKED libtrace_8021q_t;
522
523/** ATM User Network Interface (UNI) Cell. */
524typedef struct libtrace_atm_cell
525{
526  LT_BITFIELD32 gfc:4;          /**< Generic Flow Control */
527  LT_BITFIELD32 vpi:8;          /**< Virtual Path Identifier */
528  LT_BITFIELD32 vci:16;         /**< Virtual Channel Identifier */
529  LT_BITFIELD32 pt:3;           /**< Payload Type */
530  LT_BITFIELD32 clp:1;          /**< Cell Loss Priority */
531  LT_BITFIELD32 hec:8;          /**< Header Error Control */
532} PACKED libtrace_atm_cell_t;
533
534/** ATM Network Node/Network Interface (NNI) Cell. */
535typedef struct libtrace_atm_nni_cell
536{
537  LT_BITFIELD32 vpi:12;         /**< Virtual Path Identifier */
538  LT_BITFIELD32 vci:16;         /**< Virtual Channel Identifier */
539  LT_BITFIELD32 pt:3;           /**< Payload Type */
540  LT_BITFIELD32 clp:1;          /**< Cell Loss Priority */
541  LT_BITFIELD32 hec:8;          /**< Header Error Control */
542} PACKED libtrace_atm_nni_cell_t;
543
544/** Captured UNI cell.
545 *
546 * Endance don't capture the HEC, presumably to keep alignment.  This
547 * version of the \ref libtrace_atm_cell  is used when dealing with dag
548 * captures of uni cells.
549 *
550 */
551typedef struct libtrace_atm_capture_cell
552{
553  LT_BITFIELD32 gfc:4;          /**< Generic Flow Control */
554  LT_BITFIELD32 vpi:8;          /**< Virtual Path Identifier */
555  LT_BITFIELD32 vci:16;         /**< Virtual Channel Identifier */
556  LT_BITFIELD32 pt:3;           /**< Payload Type */
557  LT_BITFIELD32 clp:1;          /**< Cell Loss Priority */
558} PACKED libtrace_atm_capture_cell_t;
559
560/** Captured NNI cell.
561 *
562 * Endance don't capture the HEC, presumably to keep alignment.  This
563 * version of the \ref libtrace_atm_nni_cell  is used when dealing with dag
564 * captures of nni cells.
565 *
566 */
567typedef struct libtrace_atm_nni_capture_cell
568{
569  LT_BITFIELD32 vpi:12;         /**< Virtual Path Identifier */
570  LT_BITFIELD32 vci:16;         /**< Virtual Channel Identifier */
571  LT_BITFIELD32 pt:3;           /**< Payload Type */
572  LT_BITFIELD32 clp:1;          /**< Cell Loss Priority */
573  LT_BITFIELD32 hec:8;          /**< Header Error Control */
574} PACKED libtrace_atm_nni_capture_cell_t;
575
576/** PPP header */
577typedef struct libtrace_pps
578{
579 uint8_t addres;                /**< PPP Address (0xFF - All stations) */
580 uint8_t header;                /**< PPP Control (0x03 - Unnumbered info) */
581 uint16_t protocol;             /**< PPP Protocol (htons(0x0021) - IPv4 */
582} PACKED libtrace_ppp_t;
583
584/** 802.11 header */
585typedef struct libtrace_80211_t {
586#if BYTE_ORDER == LITTLE_ENDIAN
587        LT_BITFIELD32      protocol:2;
588        LT_BITFIELD32      type:2;
589        LT_BITFIELD32      subtype:4;
590#else
591        LT_BITFIELD32      subtype:4;
592        LT_BITFIELD32      type:2;
593        LT_BITFIELD32      protocol:2;
594#endif
595
596#if BYTE_ORDER == LITTLE_ENDIAN
597        LT_BITFIELD32      to_ds:1;     /**< Packet to Distribution Service */
598        LT_BITFIELD32      from_ds:1;   /**< Packet from Distribution Service */
599        LT_BITFIELD32      more_frag:1; /**< Packet has more fragments */
600        LT_BITFIELD32      retry:1;     /**< Packet is a retry */
601        LT_BITFIELD32      power:1;
602        LT_BITFIELD32      more_data:1;
603        LT_BITFIELD32      wep:1;
604        LT_BITFIELD32      order:1;
605#else
606        LT_BITFIELD32      order:1;
607        LT_BITFIELD32      wep:1;
608        LT_BITFIELD32      more_data:1;
609        LT_BITFIELD32      power:1;
610        LT_BITFIELD32      retry:1;     /**< Packet is a retry */
611        LT_BITFIELD32      more_frag:1; /**< Packet has more fragments */
612        LT_BITFIELD32      from_ds:1;   /**< Packet from Distribution Service */
613        LT_BITFIELD32      to_ds:1;     /**< Packet to Distribution Service */
614#endif
615        uint16_t     duration;
616        uint8_t      mac1[6];
617        uint8_t      mac2[6];
618        uint8_t      mac3[6];
619        uint16_t     SeqCtl;
620        uint8_t      mac4[6];
621} PACKED libtrace_80211_t;
622
623/** The Radiotap header pre-amble
624 *
625 * All Radiotap headers start with this pre-amble, followed by the fields
626 * specified in the it_present bitmask. If bit 31 of it_present is set, then
627 * another bitmask follows.
628 * @note All of the radiotap data fields are in little-endian byte-order.
629 */
630typedef struct libtrace_radiotap_t {
631    uint8_t     it_version; /**< Radiotap version */
632    uint8_t     it_pad; /**< Padding for natural alignment */
633    uint16_t    it_len; /**< Length in bytes of the entire Radiotap header */
634    uint32_t    it_present; /**< Which Radiotap fields are present */
635} PACKED libtrace_radiotap_t;
636
637
638#ifdef WIN32
639#pragma pack(pop)
640#endif
641
642
643/*@}*/
644
645/** Prints help information for libtrace
646 *
647 * Function prints out some basic help information regarding libtrace,
648 * and then prints out the help() function registered with each input module
649 */
650DLLEXPORT void trace_help(void);
651
652/** @name Trace management
653 * These members deal with creating, configuring, starting, pausing and
654 * cleaning up a trace object
655 *@{
656 */
657
658/** Create a trace file from a URI
659 *
660 * @param uri containing a valid libtrace URI
661 * @return an opaque pointer to a libtrace_t
662 *
663 * Valid URI's are:
664 *  - erf:/path/to/erf/file
665 *  - erf:-  (stdin)
666 *  - dag:/dev/dagcard                 
667 *  - pcapint:pcapinterface                (eg: pcap:eth0)
668 *  - pcap:/path/to/pcap/file
669 *  - pcap:-
670 *  - rt:hostname
671 *  - rt:hostname:port
672 *  - rtclient:hostname (deprecated)
673 *  - rtclient:hostname:port (deprecated)
674 *
675 *  If an error occured when attempting to open the trace file, an error
676 *  trace is returned and trace_get_error should be called to find out
677 *  if an error occured, and what that error was.  The trace is created in the
678 *  configuration state, you must call trace_start to start the capture.
679 */
680DLLEXPORT libtrace_t *trace_create(const char *uri);
681
682/** Creates a "dummy" trace file that has only the format type set.
683 *
684 * @return an opaque pointer to a (sparsely initialised) libtrace_t
685 *
686 * IMPORTANT: Do not attempt to call trace_read_packet or other such functions
687 * with the dummy trace. Its intended purpose is to act as a packet->trace for
688 * libtrace_packet_t's that are not associated with a libtrace_t structure.
689 */
690DLLEXPORT libtrace_t *trace_create_dead(const char *uri);
691
692/** Creates a trace output file from a URI.
693 *
694 * @param uri   the uri string describing the output format and destination
695 * @return an opaque pointer to a libtrace_output_t
696 *
697 * Valid URI's are:
698 *  - erf:/path/to/erf/file
699 *  - pcap:/path/to/pcap/file
700 *  - wtf:/path/to/wtf/file
701 *
702 *  If an error occured when attempting to open the output trace, NULL is returned
703 *  and trace_errno is set. Use trace_perror_output() to get more information
704 */
705DLLEXPORT libtrace_out_t *trace_create_output(const char *uri);
706
707/** Start the capture
708 * @param libtrace      The trace to start
709 * @return 0 on success, -1 on failure
710 *
711 * This does the actual work with starting the trace capture, and applying
712 * all the config options.  This may fail.
713 */
714DLLEXPORT int trace_start(libtrace_t *libtrace);
715
716/** Pause the capture
717 * @param libtrace      The trace to pause
718 * @return 0 on success, -1 on failure
719 *
720 * This stops a capture in progress and returns you to the configuration
721 * state.  Any packets that arrive after trace_pause() has been called
722 * will be discarded.  To resume capture, call trace_start().
723 */
724DLLEXPORT int trace_pause(libtrace_t *libtrace);
725
726/** Start an output trace
727 * @param libtrace      The trace to start
728 * @return 0 on success, -1 on failure
729 *
730 * This does the actual work with starting a trace for write.  This generally
731 * creates the file.
732 */
733DLLEXPORT int trace_start_output(libtrace_out_t *libtrace);
734
735/** Valid trace capture options */
736typedef enum {
737        TRACE_OPTION_SNAPLEN,   /**< Number of bytes captured */
738        TRACE_OPTION_PROMISC,   /**< Capture packets to other hosts */
739        TRACE_OPTION_FILTER,    /**< Apply this filter to all packets */
740        TRACE_OPTION_META_FREQ, /**< Frequency of meta-data information, e.g. DUCK packets */
741        /** trace_event ignores gaps between packets when reading traces off disk */
742        TRACE_OPTION_EVENT_REALTIME
743} trace_option_t;
744
745/** Sets an input config option
746 * @param libtrace      the trace object to apply the option to
747 * @param option        the option to set
748 * @param value         the value to set the option to
749 * @return -1 if option configuration failed, 0 otherwise
750 * This should be called after trace_create, and before trace_start
751 */
752DLLEXPORT int trace_config(libtrace_t *libtrace,
753                trace_option_t option,
754                void *value);
755
756typedef enum {
757        TRACE_OPTION_OUTPUT_FILEFLAGS, /**< File flags to open the trace file
758                                        * with.  eg O_APPEND
759                                        */
760        TRACE_OPTION_OUTPUT_COMPRESS   /**< Compression level, eg 6. */
761} trace_option_output_t;
762
763/** Sets an output config option
764 *
765 * @param libtrace      the output trace object to apply the option to
766 * @param option        the option to set
767 * @param value         the value to set the option to
768 * @return -1 if option configuration failed, 0 otherwise
769 * This should be called after trace_create_output, and before
770 * trace_start_output
771 */
772DLLEXPORT int trace_config_output(libtrace_out_t *libtrace,
773                trace_option_output_t option,
774                void *value
775                );
776
777/** Close a trace file, freeing up any resources it may have been using
778 *
779 */
780DLLEXPORT void trace_destroy(libtrace_t *trace);
781
782/** Close a trace file, freeing up any resources it may have been using
783 * @param trace         trace file to be destroyed
784 */
785DLLEXPORT void trace_destroy_dead(libtrace_t *trace);
786
787/** Close a trace output file, freeing up any resources it may have been using
788 * @param trace         the output trace file to be destroyed
789 */
790DLLEXPORT void trace_destroy_output(libtrace_out_t *trace);
791
792/** Check (and clear) the current error state of an input trace
793 * @param trace         the trace file to check the error state on
794 * @return Error report
795 * This reads and returns the current error state and sets the current error
796 * to "no error".
797 */
798DLLEXPORT libtrace_err_t trace_get_err(libtrace_t *trace);
799
800/** Return if there is an error
801 * @param trace         the trace file to check the error state on
802 * This does not clear the error status, and only returns true or false.
803 */
804DLLEXPORT bool trace_is_err(libtrace_t *trace);
805
806/** Output an error message to stderr and clear the error status.
807 * @param trace         the trace with the error to output
808 * @param msg           the message to prefix to the error
809 * This function does clear the error status.
810 */
811DLLEXPORT void trace_perror(libtrace_t *trace, const char *msg,...) PRINTF(2,3);
812
813/** Check (and clear) the current error state of an output trace
814 * @param trace         the output trace file to check the error state on
815 * @return Error report
816 * This reads and returns the current error state and sets the current error
817 * to "no error".
818 */
819DLLEXPORT libtrace_err_t trace_get_err_output(libtrace_out_t *trace);
820
821/** Return if there is an error
822 * @param trace         the trace file to check the error state on
823 * This does not clear the error status, and only returns true or false.
824 */
825DLLEXPORT bool trace_is_err_output(libtrace_out_t *trace);
826
827/** Output an error message to stderr and clear the error status.
828 * @param trace         the trace with the error to output
829 * @param msg           the message to prefix to the error
830 * This function does clear the error status.
831 */
832DLLEXPORT void trace_perror_output(libtrace_out_t *trace, const char *msg,...)
833        PRINTF(2,3);
834
835
836/*@}*/
837
838/** @name Reading/Writing packets
839 * These members deal with creating, reading and writing packets
840 *
841 * @{
842 */
843
844/** Create a new packet object
845 *
846 * @return a pointer to an initialised libtrace_packet_t object
847 */
848DLLEXPORT libtrace_packet_t *trace_create_packet(void);
849
850/** Copy a packet
851 * @param packet        the source packet to copy
852 * @return a new packet which has the same content as the source packet
853 * @note This always involves a copy, which can be slow.  Use of this
854 * function should be avoided where possible.
855 * @par The reason you would want to use this function is that a zerocopied
856 * packet from a device is using the devices memory which may be a limited
857 * resource.  Copying the packet will cause it to be copied into the systems
858 * memory.
859 */
860DLLEXPORT libtrace_packet_t *trace_copy_packet(const libtrace_packet_t *packet);
861
862/** Destroy a packet object
863 *
864 * sideeffect: sets packet to NULL
865 */
866DLLEXPORT void trace_destroy_packet(libtrace_packet_t *packet);
867
868
869/** Read one packet from the trace
870 *
871 * @param trace         the libtrace opaque pointer
872 * @param packet        the packet opaque pointer
873 * @return 0 on EOF, negative value on error, number of bytes read when
874 * successful.
875 *
876 * @note the number of bytes read is usually (but not always) the same as
877 * trace_get_framing_length()+trace_get_capture_length() depending on the
878 * trace format.
879 * @note the trace must have been started with trace_start before calling
880 * this function
881 */
882DLLEXPORT int trace_read_packet(libtrace_t *trace, libtrace_packet_t *packet);
883
884/** Event types
885 * see \ref libtrace_eventobj_t and \ref trace_event
886 */
887typedef enum {
888        TRACE_EVENT_IOWAIT,     /**< Need to block on fd */
889        TRACE_EVENT_SLEEP,      /**< Sleep for some time */
890        TRACE_EVENT_PACKET,     /**< packet has arrived */
891        TRACE_EVENT_TERMINATE   /**< End of trace */
892} libtrace_event_t;
893
894/** Structure returned by libtrace_event explaining what the current event is */
895typedef struct libtrace_eventobj_t {
896        libtrace_event_t type; /**< event type (iowait,sleep,packet) */
897        int fd;                /**< if IOWAIT, the fd to sleep on */
898        double seconds;        /**< if SLEEP, the amount of time to sleep for
899                                */
900        int size;              /**< if PACKET, the value returned from
901                                *  trace_read_packet
902                                */
903} libtrace_eventobj_t;
904
905/** Processes the next libtrace event
906 * @param trace the libtrace opaque pointer
907 * @param packet the libtrace_packet opaque pointer
908 * @return libtrace_event struct containing the type, and potential
909 *      fd or seconds to sleep on
910 *
911 * Type can be:
912 *  TRACE_EVENT_IOWAIT  Waiting on I/O on fd
913 *  TRACE_EVENT_SLEEP   Next event in seconds
914 *  TRACE_EVENT_PACKET  Packet arrived in buffer with size size
915 *  TRACE_EVENT_TERMINATE Trace terminated (perhaps with an error condition)
916 */
917DLLEXPORT libtrace_eventobj_t trace_event(libtrace_t *trace,
918                libtrace_packet_t *packet);
919
920
921/** Write one packet out to the output trace
922 *
923 * @param trace         the libtrace_out opaque pointer
924 * @param packet        the packet opaque pointer
925 * @return the number of bytes written out, if zero or negative then an error has occured.
926 */
927DLLEXPORT int trace_write_packet(libtrace_out_t *trace, libtrace_packet_t *packet);
928/*@}*/
929
930/** @name Protocol decodes
931 * These functions locate and return a pointer to various headers inside a
932 * packet
933 * @{
934 */
935
936
937/** Gets a pointer to the first byte of the packet as it was captured and
938 * returns its corresponding linktype and capture length.
939 *
940 * Use this function instead of the deprecated trace_get_link().
941 *
942 * @param packet the packet pointer
943 * @param[out] linktype the linktype of the returned pointer
944 * @param[out] remaining the capture length (the number of captured bytes from
945 * the returned pointer)
946 * @return a pointer to the first byte of the packet
947 */
948DLLEXPORT void *trace_get_packet_buffer(const libtrace_packet_t *packet,
949                libtrace_linktype_t *linktype, uint32_t *remaining);
950
951/** get a pointer to the link layer
952 * @param packet        the packet opaque pointer
953 *
954 * @return a pointer to the link layer, or NULL if there is no link layer
955 *
956 * @deprecated This function is deprecated: Use trace_get_packet_buffer() or
957 * one of the trace_get_layer*() functions instead.
958 * @note you should call trace_get_link_type to find out what type of link
959 * layer this is
960 */
961DLLEXPORT SIMPLE_FUNCTION DEPRECATED
962void *trace_get_link(const libtrace_packet_t *packet);
963
964/** get a pointer to the IPv4 header (if any)
965 * @param packet        the packet opaque pointer
966 *
967 * @return a pointer to the IPv4 header, or NULL if there is no IPv4 header
968 *
969 * You should consider using \ref trace_get_layer3 instead of this function.
970 */
971DLLEXPORT SIMPLE_FUNCTION
972libtrace_ip_t *trace_get_ip(libtrace_packet_t *packet);
973
974/** get a pointer to the IPv6 header (if any)
975 * @param packet        the packet opaque pointer
976 *
977 * @return a pointer to the IPv6 header, or NULL if there is no IPv6 header
978 *
979 * You should consider using \ref trace_get_layer3 instead of this function.
980 */
981DLLEXPORT SIMPLE_FUNCTION
982libtrace_ip6_t *trace_get_ip6(libtrace_packet_t *packet);
983
984/** Return a pointer to the first metadata header in a packet, if present.
985 *
986 * This function takes a pointer to a libtrace packet and if any metadata
987 * headers exist, returns a pointer to the first one, along with its
988 * corresponding linktype.
989 *
990 * If no metadata headers exist in the packet, NULL is returned.
991 *
992 * A metadata header is a header that was prepended by the capturing device,
993 * such as a Linux SLL header, or a Radiotap wireless monitoring header.
994 * Subsequent metadata headers may be accessed with the
995 * trace_get_payload_from_meta(...) function.
996 *
997 * @param packet the libtrace packet
998 * @param[out] linktype the linktype of the returned metadata header
999 * @param[out] remaining the number of bytes captured after the returned
1000 * pointer.
1001 * @return a pointer to the first metadata header, or NULL if there are no
1002 * metadata headers present.
1003 *
1004 * remaining may be NULL, however linktype must be provided.
1005 */
1006DLLEXPORT void *trace_get_packet_meta(const libtrace_packet_t *packet,
1007                libtrace_linktype_t *linktype,
1008                uint32_t *remaining);
1009
1010/** Returns the payload of a metadata header.
1011 *
1012 * This function takes a pointer to the start of a metadata header (either
1013 * obtained via trace_get_packet_meta(...) or by a previous call to
1014 * trace_get_payload_from_meta(...)) along with its corresponding linktype and
1015 * returns the payload, i.e. the next header. It will also update the linktype
1016 * parameter to indicate the type of payload.
1017 * 
1018 * If the linktype indicates that the header passed in is not a metadata
1019 * header, the function returns NULL to indicate this. The linktype remains
1020 * unchanged in this case.
1021 *
1022 * This function allows the user to iterate through metadata headers which are
1023 * sometimes present before the actual packet as it was received on the wire.
1024 * Examples of metadata headers include the Linux SLL header and the Radiotap
1025 * wireless monitoring header.
1026 *
1027 * @param[in] meta a pointer to a header
1028 * @param[in,out] linktype the linktype of meta (updated to indicate the
1029 * linktype of the returned header if applicable).
1030 * @param[in,out] remaining the number of bytes after the meta pointer.
1031 * @return a pointer to the payload of the metadata header. If meta is not a
1032 * pointer to a metadata header, NULL is returned and linktype remains
1033 * unchanged.
1034 *
1035 * All parameters are mandatory. NULL will be returned if any are NULL.
1036 */
1037DLLEXPORT void *trace_get_payload_from_meta(const void *meta,
1038                libtrace_linktype_t *linktype,
1039                uint32_t *remaining);
1040
1041
1042/** Get a pointer to the layer 2 header. Generally this is the first byte of the
1043 * packet as it was seen on the wire.
1044 *
1045 * This function takes a libtrace packet and skips over any metadata headers if
1046 * present (such as Linux SLL or Radiotap) and returns a pointer to the first
1047 * byte of the packet that was actually received by the network interface.
1048 *
1049 * @param packet the libtrace packet
1050 * @param[out] linktype the linktype of the returned layer 2 header
1051 * @param[out] remaining the number of bytes left in the packet after the
1052 * returned pointer.
1053 * @return a pointer to the first byte of the packet as it was seen on the
1054 * wire.
1055 *
1056 * remaining may be NULL, otherwise it will be filled in by the function.
1057 */
1058DLLEXPORT void *trace_get_layer2(const libtrace_packet_t *packet,
1059                libtrace_linktype_t *linktype,
1060                uint32_t *remaining);
1061
1062/** Gets a pointer to the next header given a pointer to a layer2 header
1063 *
1064 * @param l2                    The pointer to the current layer2 header
1065 * @param linktype              The type of the layer2 header
1066 * @param[out] ethertype        An optional output variable of the ethernet type
1067 * @param[in,out] remaining     Optionally updated with the length remaining
1068 *
1069 * @return a pointer to the transport layer header, or NULL if header isn't
1070 * present.
1071 *
1072 * type may be NULL if not needed.
1073 *
1074 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1075 * of bytes captured of the layer2 header and beyond.  It will be decremented
1076 * by the number of bytes skipped to find the payload.
1077 *
1078 */
1079DLLEXPORT void *trace_get_payload_from_layer2(void *l2,
1080                libtrace_linktype_t linktype,
1081                uint16_t *ethertype,
1082                uint32_t *remaining);
1083
1084
1085/** Get a pointer to the layer 3 header.
1086 * @param packet                The packet opaque pointer
1087 * @param[out] ethertype        The ethertype of the layer 3 header
1088 * @param[out] remaining        The amount of space available after this header
1089 *                              has been removed.
1090 *
1091 * @return a pointer to the layer 3 header.
1092 * remaining may be NULL, otherwise it will be set to the number of captured
1093 * bytes after the pointer returned.
1094 */
1095DLLEXPORT SIMPLE_FUNCTION
1096void *trace_get_layer3(const libtrace_packet_t *packet,
1097                uint16_t *ethertype, uint32_t *remaining);
1098
1099/** Gets a pointer to the transport layer header (if any)
1100 * @param packet        a pointer to a libtrace_packet structure
1101 * @param[out] proto    transport layer protocol
1102 *
1103 * @return a pointer to the transport layer header, or NULL if there is no
1104 * header
1105 *
1106 * @note proto may be NULL if proto is unneeded.
1107 */
1108DLLEXPORT void *trace_get_transport(const libtrace_packet_t *packet,
1109                uint8_t *proto, uint32_t *remaining);
1110
1111/** Gets a pointer to the payload given a pointer to the IP header
1112 * @param ip            The IP Header
1113 * @param[out] proto    An output variable of the IP protocol
1114 * @param[in,out] remaining Updated with the number of bytes remaining
1115 *
1116 * @return a pointer to the transport layer header, or NULL if header isn't
1117 * present.
1118 *
1119 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1120 * of bytes captured of the IP header and beyond.  It will be decremented by
1121 * the length of the IPv4 header (including any options).
1122 *
1123 * proto may be NULL if not needed.
1124 *
1125 * @note This is similar to trace_get_transport_from_ip in libtrace2
1126 */
1127DLLEXPORT void *trace_get_payload_from_ip(libtrace_ip_t *ip, uint8_t *proto,
1128                uint32_t *remaining);
1129
1130/** Gets a pointer to the payload given a pointer to the IPv6 header
1131 * @param ipptr         The IPv6 Header
1132 * @param[out] proto    An output variable of the protocol of the next header
1133 * @param[in,out] remaining Updated with the number of bytes remaining
1134 *
1135 * @return a pointer to the transport layer header, or NULL if the IPv6 header
1136 * isn't complete.
1137 *
1138 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1139 * of bytes captured of the IP header and beyond.  It will be decremented by
1140 * this function by the length of the IPV6 header.
1141 *
1142 * proto may be NULL if not needed.
1143 *
1144 */
1145DLLEXPORT void *trace_get_payload_from_ip6(libtrace_ip6_t *ipptr,
1146                uint8_t *prot, uint32_t *remaining);
1147
1148/** Gets a pointer to the payload given a pointer to the link header
1149 * @param ip            The link pointer
1150 * @param[out] type     An output variable of the ethernet type
1151 * @param[in,out] remaining Updated with the number of bytes remaining
1152 *
1153 * @return a pointer to the transport layer header, or NULL if header isn't
1154 * present.
1155 *
1156 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1157 * of bytes captured of the linklayer and beyond.  It will be updated after
1158 * this function to the number of bytes remaining after the IP header (and any
1159 * IP options) have been removed.
1160 *
1161 * type may be NULL if not needed.
1162 *
1163 */
1164DLLEXPORT void *trace_get_payload_from_link(void *linkptr,
1165                libtrace_linktype_t linktype,
1166                uint16_t *type, uint32_t *remaining);
1167
1168/** Skips over any 802.1q headers, if present.
1169 * @param ethernet      A pointer to the payload following an ethernet header
1170 * -usually the result of calling trace_get_payload_from_link
1171 * @param[in,out] type  The ethernet type, replaced with the vlan ether type
1172 * @param[in,out] remaining Updated with the number of bytes remaining
1173 *
1174 * @return a pointer to the header beyond the vlan header, if present.
1175 * Otherwise, returns the ethernet payload that was passed in
1176 *
1177 * Remaining may be NULL. If Remaining is not NULL it must point to the number
1178 * of bytes captured past (but not including) the link layer. This function
1179 * will decrement it by the length of the 802.1q headers if present.
1180 *
1181 * Type must point to the value of the ethernet type. Libtrace will assert
1182 * fail if type is NULL.
1183 *
1184 */
1185DLLEXPORT void *trace_get_vlan_payload_from_ethernet_payload(
1186                void *ethernet_payload, uint16_t *type, uint32_t *remaining);
1187
1188/** Gets a pointer to the payload given a pointer to a tcp header
1189 * @param tcp           The tcp Header
1190 * @param[in,out] remaining Updated with the number of bytes remaining
1191 *
1192 * @return a pointer to the tcp payload, or NULL if the payload isn't present.
1193 *
1194 * Remaining may be NULL.  If remaining is not NULL it must point to the number
1195 * of bytes captured of the TCP header and beyond.  It will be decremented by
1196 * this function by the length of the TCP header (including any options).
1197 *
1198 */
1199DLLEXPORT void *trace_get_payload_from_tcp(libtrace_tcp_t *tcp,
1200                uint32_t *remaining);
1201
1202/** Gets a pointer to the payload given a pointer to a udp header
1203 * @param udp           The udp Header
1204 * @param[in,out] remaining Updated with the number of bytes remaining
1205 *
1206 * @return a pointer to the udp payload, or NULL if the payload isn't present.
1207 *
1208 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1209 * of bytes captured of the UDP header and beyond.  It will be decremented by
1210 * this function to the number of bytes remaining after the UDP header.
1211 *
1212 */
1213DLLEXPORT void *trace_get_payload_from_udp(libtrace_udp_t *udp, uint32_t *remaining);
1214
1215/** Gets a pointer to the payload given a pointer to a icmp header
1216 * @param icmp          The icmp Header
1217 * @param[in,out] remaining Updated with the number of bytes remaining
1218 *
1219 * @return a pointer to the icmp payload, or NULL if the payload isn't present.
1220 *
1221 * Remaining may be NULL.  If remaining is not NULL it must point to the number
1222 * of bytes captured of the ICMP header and beyond.  It will be decremented
1223 * by the number of bytes in the ICMP header.
1224 *
1225 */
1226DLLEXPORT void *trace_get_payload_from_icmp(libtrace_icmp_t *icmp,
1227                uint32_t *remaining);
1228
1229/** get a pointer to the TCP header (if any)
1230 * @param packet        the packet opaque pointer
1231 *
1232 * @return a pointer to the TCP header, or NULL if there is not a TCP packet
1233 *
1234 * @note you should probably use trace_get_transport()
1235 */
1236DLLEXPORT SIMPLE_FUNCTION
1237libtrace_tcp_t *trace_get_tcp(libtrace_packet_t *packet);
1238
1239/** get a pointer to the TCP header (if any) given a pointer to the IP header
1240 * @param ip            The IP header
1241 * @param[in,out] remaining Updated with the number of bytes remaining
1242 *
1243 * @return a pointer to the TCP header, or NULL if this is not a TCP packet
1244 *
1245 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1246 * of bytes captured of the TCP header and beyond.  It will be decremented by
1247 * the number of bytes in the TCP header (including any TCP options).
1248 *
1249 * @note The last parameter has changed from libtrace2
1250 */
1251DLLEXPORT SIMPLE_FUNCTION
1252libtrace_tcp_t *trace_get_tcp_from_ip(libtrace_ip_t *ip, uint32_t *remaining);
1253
1254/** get a pointer to the UDP header (if any)
1255 * @param packet        the packet opaque pointer
1256 *
1257 * @return a pointer to the UDP header, or NULL if this is not a UDP packet
1258 */
1259DLLEXPORT SIMPLE_FUNCTION
1260libtrace_udp_t *trace_get_udp(libtrace_packet_t *packet);
1261
1262/** get a pointer to the UDP header (if any) given a pointer to the IP header
1263 * @param       ip      The IP header
1264 * @param[in,out] remaining Updated with the number of bytes remaining
1265 *
1266 * @return a pointer to the UDP header, or NULL if this is not an UDP packet
1267 *
1268 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1269 * of bytes captured of the UDP header and beyond.  This function will
1270 * decremented it by the length of the UDP header.
1271 *
1272 * @note Beware the change from libtrace2 from skipped to remaining
1273 */
1274DLLEXPORT SIMPLE_FUNCTION
1275libtrace_udp_t *trace_get_udp_from_ip(libtrace_ip_t *ip,uint32_t *remaining);
1276
1277/** get a pointer to the ICMP header (if any)
1278 * @param packet        the packet opaque pointer
1279 *
1280 * @return a pointer to the ICMP header, or NULL if this is not a ICMP packet
1281 */
1282DLLEXPORT SIMPLE_FUNCTION
1283libtrace_icmp_t *trace_get_icmp(libtrace_packet_t *packet);
1284
1285/** get a pointer to the ICMP header (if any) given a pointer to the IP header
1286 * @param ip            The IP header
1287 * @param[in,out] remaining Updated with the number of bytes remaining
1288 *
1289 * @return a pointer to the ICMP header, or NULL if this is not an ICMP packet
1290 *
1291 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1292 * of bytes captured of the ICMP header and beyond.  It will be decremented by
1293 * the length of the ICMP head in bytes.
1294 *
1295 * @note Beware the change from libtrace2 from skipped to remaining
1296 */
1297DLLEXPORT SIMPLE_FUNCTION
1298libtrace_icmp_t *trace_get_icmp_from_ip(libtrace_ip_t *ip,uint32_t *remaining);
1299
1300/** Get the destination MAC address
1301 * @param packet        the packet opaque pointer
1302 * @return a pointer to the destination mac, (or NULL if there is no
1303 * destination MAC)
1304 */
1305DLLEXPORT SIMPLE_FUNCTION
1306uint8_t *trace_get_destination_mac(libtrace_packet_t *packet);
1307
1308/** Get the source MAC address
1309 * @param packet        the packet opaque pointer
1310 * @return a pointer to the source mac, (or NULL if there is no source MAC)
1311 */
1312DLLEXPORT SIMPLE_FUNCTION
1313uint8_t *trace_get_source_mac(libtrace_packet_t *packet);
1314
1315/** Get the source IP address
1316 * @param packet        the packet opaque pointer
1317 * @param addr          a pointer to a sockaddr to store the address in, or NULL to use
1318 *                      static storage.
1319 * @return NULL if there is no source address, or a sockaddr holding a v4 or v6
1320 * address
1321 */
1322DLLEXPORT SIMPLE_FUNCTION
1323struct sockaddr *trace_get_source_address(const libtrace_packet_t *packet,
1324                struct sockaddr *addr);
1325
1326/** Get the destination IP address
1327 * @param packet        the packet opaque pointer
1328 * @param addr          a pointer to a sockaddr to store the address in, or NULL to use
1329 *                      static storage.
1330 * @return NULL if there is no destination address, or a sockaddr holding a v4
1331 * or v6 address
1332 */
1333DLLEXPORT SIMPLE_FUNCTION
1334struct sockaddr *trace_get_destination_address(const libtrace_packet_t *packet,
1335                struct sockaddr *addr);
1336
1337/*@}*/
1338
1339/** parse an ip or tcp option
1340 * @param[in,out] ptr   the pointer to the current option
1341 * @param[in,out] len   the length of the remaining buffer
1342 * @param[out] type     the type of the option
1343 * @param[out] optlen   the length of the option
1344 * @param[out] data     the data of the option
1345 *
1346 * @return bool true if there is another option (and the fields are filled in)
1347 *               or false if this was the last option.
1348 *
1349 * This updates ptr to point to the next option after this one, and updates
1350 * len to be the number of bytes remaining in the options area.  Type is updated
1351 * to be the code of this option, and data points to the data of this option,
1352 * with optlen saying how many bytes there are.
1353 *
1354 * @note Beware of fragmented packets.
1355 */
1356DLLEXPORT int trace_get_next_option(unsigned char **ptr,int *len,
1357                        unsigned char *type,
1358                        unsigned char *optlen,
1359                        unsigned char **data);
1360
1361
1362/** @name Time
1363 * These functions deal with time that a packet arrived and return it
1364 * in various formats
1365 * @{
1366 */
1367/** Get the current time in DAG time format
1368 * @param packet        the packet opaque pointer
1369 *
1370 * @return a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds
1371 * past 1970-01-01, the lower 32bits are partial seconds)
1372 */
1373DLLEXPORT SIMPLE_FUNCTION
1374uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet);
1375
1376/** Get the current time in struct timeval
1377 * @param packet        the packet opaque pointer
1378 *
1379 * @return time that this packet was seen in a struct timeval
1380 */
1381DLLEXPORT SIMPLE_FUNCTION
1382struct timeval trace_get_timeval(const libtrace_packet_t *packet);
1383
1384/** Get the current time in floating point seconds
1385 * @param packet        the packet opaque pointer
1386 *
1387 * @return time that this packet was seen in 64bit floating point seconds from
1388 * the unix epoch (1970-01-01 00:00:00 UTC).
1389 */
1390DLLEXPORT SIMPLE_FUNCTION
1391double trace_get_seconds(const libtrace_packet_t *packet);
1392
1393/** Seek within a trace
1394 * @param trace         trace to seek
1395 * @param seconds       time to seek to
1396 * @return 0 on success.
1397 * Make the next packet read to be the first packet to occur at or after the
1398 * time searched for.  This must be called in the configuration state (ie,
1399 * before trace_start() or after trace_pause().
1400 * @note This function may be extremely slow.
1401 */
1402DLLEXPORT int trace_seek_seconds(libtrace_t *trace, double seconds);
1403
1404/** Seek within a trace
1405 * @param trace         trace to seek
1406 * @param tv            time to seek to
1407 * @return 0 on success.
1408 * Make the next packet read to be the first packet to occur at or after the
1409 * time searched for.  This must be called in the configuration state (ie,
1410 * before trace_start() or after trace_pause().
1411 * @note This function may be extremely slow.
1412 */
1413DLLEXPORT int trace_seek_timeval(libtrace_t *trace, struct timeval tv);
1414
1415/** Seek within a trace
1416 * @param trace         trace to seek
1417 * @param ts            erf timestamp
1418 * @return 0 on success.
1419 * Make the next packet read to be the first packet to occur at or after the
1420 * time searched for.  This must be called in the configuration state (ie,
1421 * before trace_start() or after trace_pause().
1422 * @note This function may be extremely slow.
1423 */
1424DLLEXPORT int trace_seek_erf_timestamp(libtrace_t *trace, uint64_t ts);
1425
1426/*@}*/
1427
1428/** @name Sizes
1429 * This section deals with finding or setting the various different lengths
1430 * a packet can have
1431 * @{
1432 */
1433/** Get the size of the packet in the trace (in bytes)
1434 * @param packet        the packet opaque pointer
1435 * @return the size of the packet in the trace
1436 * @note Due to this being a header capture, or anonymisation, this may not
1437 * be the same size as the original packet.  See get_wire_length() for the
1438 * original size of the packet.
1439 * @note This can (and often is) different for different packets in a trace!
1440 * @note This is sometimes called the "snaplen".
1441 * @note The return size refers to the network-level payload of the packet and
1442 * does not include any capture framing headers. For example, an Ethernet
1443 * packet with an empty TCP packet will return sizeof(ethernet_header) +
1444 * sizeof(ip_header) + sizeof(tcp_header), but not the capture file
1445 * (pcap/erf/etc) header.
1446 */
1447DLLEXPORT SIMPLE_FUNCTION
1448size_t trace_get_capture_length(const libtrace_packet_t *packet);
1449
1450/** Get the size of the packet as it was seen on the wire (in bytes).
1451 * @param packet        the packet opaque pointer
1452 * @return the size of the packet as it was on the wire.
1453 * @note Due to the trace being a header capture, or anonymisation this may
1454 * not be the same as the Capture Len.
1455 * @note trace_getwire_length \em{includes} FCS.
1456 * @note The return size refers to the network-level payload of the packet and
1457 * does not include any capture framing headers. For example, an Ethernet
1458 * packet with an empty TCP packet will return sizeof(ethernet_header) +
1459 * sizeof(ip_header) + sizeof(tcp_header), but not the capture file
1460 * (pcap/erf/etc) header.
1461 */
1462DLLEXPORT SIMPLE_FUNCTION
1463size_t trace_get_wire_length(const libtrace_packet_t *packet);
1464
1465/** Get the length of the capture framing headers (in bytes).
1466 * @param packet        the packet opaque pointer
1467 * @return the size of the packet as it was on the wire.
1468 * @note this length corresponds to the difference between the size of a
1469 * captured packet in memory, and the captured length of the packet
1470 */
1471DLLEXPORT SIMPLE_FUNCTION
1472size_t trace_get_framing_length(const libtrace_packet_t *packet);
1473
1474/** Truncate ("snap") the packet at the suggested length
1475 * @param packet        the packet opaque pointer
1476 * @param size          the new length of the packet (in bytes)
1477 * @return the new capture length of the packet, or the original capture
1478 * length of the packet if unchanged
1479 */
1480DLLEXPORT size_t trace_set_capture_length(libtrace_packet_t *packet, size_t size);
1481
1482/*@}*/
1483
1484
1485/** Get the type of the link layer
1486 * @param packet        the packet opaque pointer
1487 * @return libtrace_linktype_t
1488 */
1489DLLEXPORT SIMPLE_FUNCTION
1490libtrace_linktype_t trace_get_link_type(const libtrace_packet_t *packet);
1491
1492/** Set the direction flag, if it has one
1493 * @param packet        the packet opaque pointer
1494 * @param direction     the new direction
1495 * @returns -1 on error, or the direction that was set.
1496 */
1497DLLEXPORT libtrace_direction_t trace_set_direction(libtrace_packet_t *packet, libtrace_direction_t direction);
1498
1499/** Get the direction flag, if it has one
1500 * @param packet        the packet opaque pointer
1501 * @return a value containing the direction flag, or -1 if this is not supported
1502 * The direction is defined as 0 for packets originating locally (ie, outbound)
1503 * and 1 for packets originating remotely (ie, inbound).
1504 * Other values are possible, which might be overloaded to mean special things
1505 * for a special trace.
1506 */
1507DLLEXPORT SIMPLE_FUNCTION
1508libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet);
1509
1510/** @name BPF
1511 * This section deals with using Berkley Packet Filters
1512 * @{
1513 */
1514/** setup a BPF filter
1515 * @param filterstring a char * containing the bpf filter string
1516 * @return opaque pointer pointer to a libtrace_filter_t object
1517 * @note The filter is not actually compiled at this point, so no correctness
1518 * tests are performed here. trace_create_filter will always return ok, but
1519 * if the filter is poorly constructed an error will be generated when the
1520 * filter is actually used
1521 */
1522DLLEXPORT SIMPLE_FUNCTION
1523libtrace_filter_t *trace_create_filter(const char *filterstring);
1524
1525/** Setup a BPF filter based on pre-compiled byte-code.
1526 * @param bf_insns      A pointer to the start of the byte-code
1527 * @param bf_len        The number of BPF instructions 
1528 * @returns             an opaque pointer to a libtrace_filter_t object
1529 * @note                The supplied byte-code is not checked for correctness.
1530 * @author              Scott Raynel
1531 */
1532DLLEXPORT libtrace_filter_t *
1533trace_create_filter_from_bytecode(void *bf_insns, unsigned int bf_len);
1534
1535/** Apply a BPF filter to a packet
1536 * @param filter        the filter opaque pointer
1537 * @param packet        the packet opaque pointer
1538 * @return >0 if the filter matches, 0 if it doesn't, -1 on error.
1539 * @note Due to the way BPF filters are built, the filter is not actually
1540 * compiled until the first time trace_create_filter is called. If your filter
1541 * is incorrect, it will generate an error message and assert, exiting the
1542 * program. This behaviour may change to more graceful handling of this error
1543 * in the future.
1544 */
1545DLLEXPORT int trace_apply_filter(libtrace_filter_t *filter,
1546                const libtrace_packet_t *packet);
1547
1548/** Destroy a BPF filter
1549 * @param filter        the filter opaque pointer
1550 * Deallocate all the resources associated with a BPF filter
1551 */
1552DLLEXPORT void trace_destroy_filter(libtrace_filter_t *filter);
1553/*@}*/
1554
1555/** @name Portability
1556 * This section has functions that causes annoyances to portability for one
1557 * reason or another.
1558 * @{
1559 */
1560
1561/** Convert an ethernet address to a string
1562 * @param addr  Ethernet address in network byte order
1563 * @param buf   Buffer to store the ascii representation, or NULL
1564 * @return buf, or if buf is NULL then a statically allocated buffer.
1565 *
1566 * This function is similar to the GNU ether_ntoa_r function, with a few
1567 * minor differences.  if NULL is passed as buf, then the function will
1568 * use an internal static buffer, if NULL isn't passed then the function
1569 * will use that buffer instead.
1570 *
1571 * @note the type of addr isn't struct ether_addr as it is with ether_ntoa_r,
1572 * however it is bit compatible so that a cast will work.
1573 */
1574DLLEXPORT char *trace_ether_ntoa(const uint8_t *addr, char *buf);
1575
1576/** Convert a string to an ethernet address
1577 * @param buf   Ethernet address in hex format delimited with :'s.
1578 * @param addr  buffer to store the binary representation, or NULL
1579 * @return addr, or if addr is NULL, then a statically allocated buffer.
1580 *
1581 * This function is similar to the GNU ether_aton_r function, with a few
1582 * minor differences.  if NULL is passed as addr, then the function will
1583 * use an internal static buffer, if NULL isn't passed then the function will
1584 * use that buffer instead.
1585 *
1586 * @note the type of addr isn't struct ether_addr as it is with ether_aton_r,
1587 * however it is bit compatible so that a cast will work.
1588 */
1589DLLEXPORT uint8_t *trace_ether_aton(const char *buf, uint8_t *addr);
1590
1591/*@}*/
1592
1593
1594/** Which port is the server port */
1595typedef enum {
1596        USE_DEST,       /**< Destination port is the server port */
1597        USE_SOURCE      /**< Source port is the server port */
1598} serverport_t;
1599
1600/** Get the source port
1601 * @param packet        the packet to read from
1602 * @return a port in \em HOST byte order, or equivalent to ports for this
1603 * protocol, or 0 if this protocol has no ports.
1604 */
1605DLLEXPORT SIMPLE_FUNCTION
1606uint16_t trace_get_source_port(const libtrace_packet_t *packet);
1607
1608/** Get the destination port
1609 * @param packet        the packet to read from
1610 * @return a port in \em HOST byte order, or equivilent to ports for this
1611 * protocol, or 0 if this protocol has no ports.
1612 */
1613DLLEXPORT SIMPLE_FUNCTION
1614uint16_t trace_get_destination_port(const libtrace_packet_t *packet);
1615
1616/** hint at the server port in specified protocol
1617 * @param protocol      the IP layer protocol, eg 6 (tcp), 17 (udp)
1618 * @param source        the source port from the packet
1619 * @param dest          the destination port from the packet
1620 * @return one of USE_SOURCE or USE_DEST depending on which one you should use
1621 * @note ports must be in \em HOST byte order!
1622 */
1623DLLEXPORT SIMPLE_FUNCTION
1624int8_t trace_get_server_port(uint8_t protocol, uint16_t source, uint16_t dest);
1625
1626/** Takes a uri and splits it into a format and uridata component.
1627 * @param uri           the uri to be parsed
1628 * @param format        destination location for the format component of the uri
1629 * @return 0 if an error occured, otherwise return the uridata component
1630 */
1631DLLEXPORT const char *trace_parse_uri(const char *uri, char **format);
1632
1633/** Gets the format type for a given packet.
1634 * @param packet        the packet opaque pointer
1635 * @return the format of the packet
1636 */
1637DLLEXPORT
1638enum base_format_t trace_get_format(struct libtrace_packet_t *packet);
1639
1640/** Construct a packet from a buffer.
1641 * @param packet[in,out]        Libtrace Packet object to update with the new
1642 *                              data.
1643 * @param linktype              The linktype of the packet.
1644 * @param[in] data              The packet data (including linklayer)
1645 * @param len                   Length of packet data
1646 */
1647DLLEXPORT
1648void trace_construct_packet(libtrace_packet_t *packet,
1649                libtrace_linktype_t linktype, const void *data, uint16_t len);
1650
1651/*@}*/
1652
1653/** @name Wireless trace support
1654 * Functions to access wireless information from packets that have wireless
1655 * monitoring headers such as Radiotap or Prism.
1656 *
1657 * The trace_get_wireless_* functions provide an abstract interface for
1658 * retrieving information from wireless traces. They take a pointer to the
1659 * wireless monitoring header (usually found with trace_get_link(packet)) and
1660 * the linktype of the header passed in.
1661 *
1662 * All of the trace_get_wireless_* functions return false if the requested
1663 * information was unavailable, or true if it was. The actual data is stored
1664 * in an output variable supplied by the caller. Values returned into the
1665 * output variable will always be returned in host byte order.
1666 * @{
1667 */
1668
1669
1670#ifndef ARPHRD_80211_RADIOTAP
1671/* libc doesn't define this yet, but it seems to be what everyone is using
1672 */
1673#define ARPHRD_80211_RADIOTAP 803
1674#endif
1675
1676/** Get the wireless Timer Syncronisation Function
1677 *
1678 * Gets the value of the timer syncronisation function for this frame, which
1679 * is a value in microseconds indicating the time that the first bit of the
1680 * MPDU was received by the MAC.
1681 *
1682 * @param link the wireless header
1683 * @param linktype the linktype of the wireless header passed in
1684 * @param[out] tsft the value of the timer syncronisation function.
1685 * @return true if the field was available, false if not.
1686 */
1687DLLEXPORT bool trace_get_wireless_tsft(void *linkptr,
1688        libtrace_linktype_t linktype, uint64_t *tsft);
1689
1690/** Get the wireless rate
1691 * @param link the wireless header
1692 * @param linktype the linktype of the wireless header passed in
1693 * @param[out] rate the data-rate of the frame in units of 500kbps
1694 * @return true if the field was available, false if not.
1695 */
1696DLLEXPORT bool trace_get_wireless_rate(void *linkptr,
1697        libtrace_linktype_t linktype, uint8_t *rate);
1698
1699/** Get the wireless channel frequency
1700 * @param link the wireless header
1701 * @param linktype the linktype of the wireless header passed in
1702 * @param[out] freq the frequency in MHz of the channel the frame was transmitted
1703 * or received on.
1704 * @return true if the field was available, false if not.
1705 */
1706DLLEXPORT bool trace_get_wireless_freq(void *linkptr,
1707        libtrace_linktype_t linktype, uint16_t *freq);
1708
1709/** Get the wireless signal strength in dBm
1710 * @param link the wireless header
1711 * @param linktype the linktype of the wireless header passed in
1712 * @param[out] strength the RF signal power at the antenna, in dB difference
1713 * from 1mW.
1714 * @return true if the field was available, false if not.
1715 */
1716DLLEXPORT bool trace_get_wireless_signal_strength_dbm(void *linkptr,
1717        libtrace_linktype_t linktype, int8_t *strength);
1718
1719/** Get the wireless noise strength in dBm
1720 * @param link the wireless header
1721 * @param linktype the linktype of the wireless header passed in
1722 * @param[out] strength the RF noise power at the antenna, in dB difference
1723 * from 1mW.
1724 * @return true if the field was available, false if not.
1725 */
1726DLLEXPORT bool trace_get_wireless_noise_strength_dbm(void *linkptr,
1727        libtrace_linktype_t linktype, int8_t *strength);
1728
1729/** Get the wireless signal strength in dB
1730 * @param link the wireless header
1731 * @param linktype the linktype of the wireless header passed in
1732 * @param[out] strength the RF signal power at the antenna,in dB difference
1733 * from a fixed reference.
1734 * @return true if the field was available, false if not.
1735 */
1736DLLEXPORT bool trace_get_wireless_signal_strength_db(void *linkptr,
1737        libtrace_linktype_t linktype, uint8_t *strength);
1738
1739/** Get the wireless noise strength in dB
1740 * @param link the wireless header
1741 * @param linktype the linktype of the wireless header passed in
1742 * @param[out] strength the RF noise power at the antenna, in dB difference
1743 * from a fixed reference.
1744 * @return true if the field was available, false if not.
1745 */
1746DLLEXPORT bool trace_get_wireless_noise_strength_db(void *linkptr,
1747        libtrace_linktype_t linktype, uint8_t *strength);
1748
1749/** Get the wireless transmit attenuation
1750 * @param link the wireless header
1751 * @param linktype the linktype of the wireless header passed in
1752 * @param[out] attenuation the transmit power as a unitless distance from maximum
1753 * power set at factory calibration. 0 indicates maximum transmission power.
1754 * @return true if the field was available, false if not.
1755 */
1756DLLEXPORT bool trace_get_wireless_tx_attenuation(void *linkptr,
1757        libtrace_linktype_t linktype, uint16_t *attenuation);
1758
1759/** Get the wireless transmit attenuation in dB
1760 * @param link the wireless header
1761 * @param linktype the linktype of the wireless header passed in
1762 * @param[out] attenuation the transmit power as dB difference from maximum power
1763 * set at factory calibration. 0 indicates maximum power.
1764 * @return true if the field was available, false if not.
1765 */
1766DLLEXPORT bool trace_get_wireless_tx_attenuation_db(void *linkptr,
1767        libtrace_linktype_t linktype, uint16_t *attenuation);
1768
1769/** Get the wireless transmit power in dBm @param link the wireless header
1770 * @param linktype the linktype of the wireless header passed in
1771 * @param[out] txpower the transmit power as dB from a 1mW reference. This is the absolute power level measured at the antenna port. 
1772 * @return true if the field was available, false if not.
1773 */
1774DLLEXPORT bool trace_get_wireless_tx_power_dbm(void *linkptr, libtrace_linktype_t
1775                linktype, int8_t *txpower);
1776
1777/** Get the wireless antenna
1778 * @param link the wireless header
1779 * @param linktype the linktype of the wireless header passed in
1780 * @param[out] antenna which antenna was used to transmit or receive the frame.
1781 * @return true if the field was available, false if not.
1782 */
1783DLLEXPORT bool trace_get_wireless_antenna(void *linkptr,
1784        libtrace_linktype_t linktype, uint8_t *antenna);
1785
1786/*@}*/
1787
1788#ifdef __cplusplus
1789} /* extern "C" */
1790#endif /* #ifdef __cplusplus */
1791#endif /* LIBTRACE_H_ */
Note: See TracBrowser for help on using the repository browser.