source: lib/libtrace.h.in @ 9bc4689

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

Move everything over to using the newer API's

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