source: lib/libtrace.h.in @ e696e87

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

Fix byteorder issues with ip struct

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