source: lib/libtrace.h.in @ 37592ce

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

Try and clarify the documentation about the *remaining parameter in the
trace_get_payload_from_* functions

  • Property mode set to 100644
File size: 65.4 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 (the number of captured bytes from
943 * the returned 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 *
967 * You should consider using \ref trace_get_layer3 instead of this function.
968 */
969DLLEXPORT SIMPLE_FUNCTION
970libtrace_ip_t *trace_get_ip(libtrace_packet_t *packet);
971
972/** get a pointer to the IPv6 header (if any)
973 * @param packet        the packet opaque pointer
974 *
975 * @return a pointer to the IPv6 header, or NULL if there is no IPv6 header
976 *
977 * You should consider using \ref trace_get_layer3 instead of this function.
978 */
979DLLEXPORT SIMPLE_FUNCTION
980libtrace_ip6_t *trace_get_ip6(libtrace_packet_t *packet);
981
982/** Return a pointer to the first metadata header in a packet, if present.
983 *
984 * This function takes a pointer to a libtrace packet and if any metadata
985 * headers exist, returns a pointer to the first one, along with its
986 * corresponding linktype.
987 *
988 * If no metadata headers exist in the packet, NULL is returned.
989 *
990 * A metadata header is a header that was prepended by the capturing device,
991 * such as a Linux SLL header, or a Radiotap wireless monitoring header.
992 * Subsequent metadata headers may be accessed with the
993 * trace_get_payload_from_meta(...) function.
994 *
995 * @param packet the libtrace packet
996 * @param[out] linktype the linktype of the returned metadata header
997 * @param[out] remaining the number of bytes captured after the returned
998 * pointer.
999 * @return a pointer to the first metadata header, or NULL if there are no
1000 * metadata headers present.
1001 *
1002 * remaining may be NULL, however linktype must be provided.
1003 */
1004DLLEXPORT void *trace_get_packet_meta(const libtrace_packet_t *packet,
1005                libtrace_linktype_t *linktype,
1006                uint32_t *remaining);
1007
1008/** Returns the payload of a metadata header.
1009 *
1010 * This function takes a pointer to the start of a metadata header (either
1011 * obtained via trace_get_packet_meta(...) or by a previous call to
1012 * trace_get_payload_from_meta(...)) along with its corresponding linktype and
1013 * returns the payload, i.e. the next header. It will also update the linktype
1014 * parameter to indicate the type of payload.
1015 * 
1016 * If the linktype indicates that the header passed in is not a metadata
1017 * header, the function returns NULL to indicate this. The linktype remains
1018 * unchanged in this case.
1019 *
1020 * This function allows the user to iterate through metadata headers which are
1021 * sometimes present before the actual packet as it was received on the wire.
1022 * Examples of metadata headers include the Linux SLL header and the Radiotap
1023 * wireless monitoring header.
1024 *
1025 * @param[in] meta a pointer to a header
1026 * @param[in,out] linktype the linktype of meta (updated to indicate the
1027 * linktype of the returned header if applicable).
1028 * @param[in,out] remaining the number of bytes after the meta pointer.
1029 * @return a pointer to the payload of the metadata header. If meta is not a
1030 * pointer to a metadata header, NULL is returned and linktype remains
1031 * unchanged.
1032 *
1033 * All parameters are mandatory. NULL will be returned if any are NULL.
1034 */
1035DLLEXPORT void *trace_get_payload_from_meta(const void *meta,
1036                libtrace_linktype_t *linktype,
1037                uint32_t *remaining);
1038
1039
1040/** Get a pointer to the layer 2 header. Generally this is the first byte of the
1041 * packet as it was seen on the wire.
1042 *
1043 * This function takes a libtrace packet and skips over any metadata headers if
1044 * present (such as Linux SLL or Radiotap) and returns a pointer to the first
1045 * byte of the packet that was actually received by the network interface.
1046 *
1047 * @param packet the libtrace packet
1048 * @param[out] linktype the linktype of the returned layer 2 header
1049 * @param[out] remaining the number of bytes left in the packet after the
1050 * returned pointer.
1051 * @return a pointer to the first byte of the packet as it was seen on the
1052 * wire.
1053 *
1054 * remaining may be NULL, otherwise it will be filled in by the function.
1055 */
1056DLLEXPORT void *trace_get_layer2(const libtrace_packet_t *packet,
1057                libtrace_linktype_t *linktype,
1058                uint32_t *remaining);
1059
1060/** Gets a pointer to the next header given a pointer to a layer2 header
1061 *
1062 * @param l2                    The pointer to the current layer2 header
1063 * @param linktype              The type of the layer2 header
1064 * @param[out] ethertype        An optional output variable of the ethernet type
1065 * @param[in,out] remaining     Optionally updated with the length remaining
1066 *
1067 * @return a pointer to the transport layer header, or NULL if header isn't
1068 * present.
1069 *
1070 * type may be NULL if not needed.
1071 *
1072 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1073 * of bytes captured of the layer2 header and beyond.  It will be decremented
1074 * by the number of bytes skipped to find the payload.
1075 *
1076 */
1077DLLEXPORT void *trace_get_payload_from_layer2(void *l2,
1078                libtrace_linktype_t linktype,
1079                uint16_t *ethertype,
1080                uint32_t *remaining);
1081
1082
1083/** Get a pointer to the layer 3 header.
1084 * @param packet                The packet opaque pointer
1085 * @param[out] ethertype        The ethertype of the layer 3 header
1086 * @param[out] remaining        The amount of space available after this header
1087 *                              has been removed.
1088 *
1089 * @return a pointer to the layer 3 header.
1090 * remaining may be NULL, otherwise it will be set to the number of captured
1091 * bytes after the pointer returned.
1092 */
1093DLLEXPORT SIMPLE_FUNCTION
1094void *trace_get_layer3(const libtrace_packet_t *packet,
1095                uint16_t *ethertype, uint32_t *remaining);
1096
1097/** Gets a pointer to the transport layer header (if any)
1098 * @param packet        a pointer to a libtrace_packet structure
1099 * @param[out] proto    transport layer protocol
1100 *
1101 * @return a pointer to the transport layer header, or NULL if there is no
1102 * header
1103 *
1104 * @note proto may be NULL if proto is unneeded.
1105 */
1106DLLEXPORT void *trace_get_transport(const libtrace_packet_t *packet,
1107                uint8_t *proto, uint32_t *remaining);
1108
1109/** Gets a pointer to the payload given a pointer to the IP header
1110 * @param ip            The IP Header
1111 * @param[out] proto    An output variable of the IP protocol
1112 * @param[in,out] remaining Updated with the number of bytes remaining
1113 *
1114 * @return a pointer to the transport layer header, or NULL if header isn't
1115 * present.
1116 *
1117 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1118 * of bytes captured of the IP header and beyond.  It will be decremented by
1119 * the length of the IPv4 header (including any options).
1120 *
1121 * proto may be NULL if not needed.
1122 *
1123 * @note This is similar to trace_get_transport_from_ip in libtrace2
1124 */
1125DLLEXPORT void *trace_get_payload_from_ip(libtrace_ip_t *ip, uint8_t *proto,
1126                uint32_t *remaining);
1127
1128/** Gets a pointer to the payload given a pointer to the IPv6 header
1129 * @param ipptr         The IPv6 Header
1130 * @param[out] proto    An output variable of the protocol of the next header
1131 * @param[in,out] remaining Updated with the number of bytes remaining
1132 *
1133 * @return a pointer to the transport layer header, or NULL if the IPv6 header
1134 * isn't complete.
1135 *
1136 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1137 * of bytes captured of the IP header and beyond.  It will be decremented by
1138 * this function by the length of the IPV6 header.
1139 *
1140 * proto may be NULL if not needed.
1141 *
1142 */
1143DLLEXPORT void *trace_get_payload_from_ip6(libtrace_ip6_t *ipptr,
1144                uint8_t *prot, uint32_t *remaining);
1145
1146/** Gets a pointer to the payload given a pointer to the link header
1147 * @param ip            The link pointer
1148 * @param[out] type     An output variable of the ethernet type
1149 * @param[in,out] remaining Updated with the number of bytes remaining
1150 *
1151 * @return a pointer to the transport layer header, or NULL if header isn't
1152 * present.
1153 *
1154 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1155 * of bytes captured of the linklayer and beyond.  It will be updated after
1156 * this function to the number of bytes remaining after the IP header (and any
1157 * IP options) have been removed.
1158 *
1159 * type may be NULL if not needed.
1160 *
1161 */
1162DLLEXPORT void *trace_get_payload_from_link(void *linkptr,
1163                libtrace_linktype_t linktype,
1164                uint16_t *type, uint32_t *remaining);
1165
1166/** Skips over any 802.1q headers, if present.
1167 * @param ethernet      A pointer to the payload following an ethernet header
1168 * -usually the result of calling trace_get_payload_from_link
1169 * @param[in,out] type  The ethernet type, replaced with the vlan ether type
1170 * @param[in,out] remaining Updated with the number of bytes remaining
1171 *
1172 * @return a pointer to the header beyond the vlan header, if present.
1173 * Otherwise, returns the ethernet payload that was passed in
1174 *
1175 * Remaining may be NULL. If Remaining is not NULL it must point to the number
1176 * of bytes captured past (but not including) the link layer. This function
1177 * will decrement it by the length of the 802.1q headers if present.
1178 *
1179 * Type must point to the value of the ethernet type. Libtrace will assert
1180 * fail if type is NULL.
1181 *
1182 */
1183DLLEXPORT void *trace_get_vlan_payload_from_ethernet_payload(
1184                void *ethernet_payload, uint16_t *type, uint32_t *remaining);
1185
1186/** Gets a pointer to the payload given a pointer to a tcp header
1187 * @param tcp           The tcp Header
1188 * @param[in,out] remaining Updated with the number of bytes remaining
1189 *
1190 * @return a pointer to the tcp payload, or NULL if the payload isn't present.
1191 *
1192 * Remaining may be NULL.  If remaining is not NULL it must point to the number
1193 * of bytes captured of the TCP header and beyond.  It will be decremented by
1194 * this function by the length of the TCP header (including any options).
1195 *
1196 */
1197DLLEXPORT void *trace_get_payload_from_tcp(libtrace_tcp_t *tcp,
1198                uint32_t *remaining);
1199
1200/** Gets a pointer to the payload given a pointer to a udp header
1201 * @param udp           The udp Header
1202 * @param[in,out] remaining Updated with the number of bytes remaining
1203 *
1204 * @return a pointer to the udp payload, or NULL if the payload isn't present.
1205 *
1206 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1207 * of bytes captured of the UDP header and beyond.  It will be decremented by
1208 * this function to the number of bytes remaining after the UDP header.
1209 *
1210 */
1211DLLEXPORT void *trace_get_payload_from_udp(libtrace_udp_t *udp, uint32_t *remaining);
1212
1213/** Gets a pointer to the payload given a pointer to a icmp header
1214 * @param icmp          The icmp Header
1215 * @param[in,out] remaining Updated with the number of bytes remaining
1216 *
1217 * @return a pointer to the icmp payload, or NULL if the payload isn't present.
1218 *
1219 * Remaining may be NULL.  If remaining is not NULL it must point to the number
1220 * of bytes captured of the ICMP header and beyond.  It will be decremented
1221 * by the number of bytes in the ICMP header.
1222 *
1223 */
1224DLLEXPORT void *trace_get_payload_from_icmp(libtrace_icmp_t *icmp,
1225                uint32_t *remaining);
1226
1227/** get a pointer to the TCP header (if any)
1228 * @param packet        the packet opaque pointer
1229 *
1230 * @return a pointer to the TCP header, or NULL if there is not a TCP packet
1231 *
1232 * @note you should probably use trace_get_transport()
1233 */
1234DLLEXPORT SIMPLE_FUNCTION
1235libtrace_tcp_t *trace_get_tcp(libtrace_packet_t *packet);
1236
1237/** get a pointer to the TCP header (if any) given a pointer to the IP header
1238 * @param ip            The IP header
1239 * @param[in,out] remaining Updated with the number of bytes remaining
1240 *
1241 * @return a pointer to the TCP header, or NULL if this is not a TCP packet
1242 *
1243 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1244 * of bytes captured of the TCP header and beyond.  It will be decremented by
1245 * the number of bytes in the TCP header (including any TCP options).
1246 *
1247 * @note The last parameter has changed from libtrace2
1248 */
1249DLLEXPORT SIMPLE_FUNCTION
1250libtrace_tcp_t *trace_get_tcp_from_ip(libtrace_ip_t *ip, uint32_t *remaining);
1251
1252/** get a pointer to the UDP header (if any)
1253 * @param packet        the packet opaque pointer
1254 *
1255 * @return a pointer to the UDP header, or NULL if this is not a UDP packet
1256 */
1257DLLEXPORT SIMPLE_FUNCTION
1258libtrace_udp_t *trace_get_udp(libtrace_packet_t *packet);
1259
1260/** get a pointer to the UDP header (if any) given a pointer to the IP header
1261 * @param       ip      The IP header
1262 * @param[in,out] remaining Updated with the number of bytes remaining
1263 *
1264 * @return a pointer to the UDP header, or NULL if this is not an UDP packet
1265 *
1266 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1267 * of bytes captured of the UDP header and beyond.  This function will
1268 * decremented it by the length of the UDP header.
1269 *
1270 * @note Beware the change from libtrace2 from skipped to remaining
1271 */
1272DLLEXPORT SIMPLE_FUNCTION
1273libtrace_udp_t *trace_get_udp_from_ip(libtrace_ip_t *ip,uint32_t *remaining);
1274
1275/** get a pointer to the ICMP header (if any)
1276 * @param packet        the packet opaque pointer
1277 *
1278 * @return a pointer to the ICMP header, or NULL if this is not a ICMP packet
1279 */
1280DLLEXPORT SIMPLE_FUNCTION
1281libtrace_icmp_t *trace_get_icmp(libtrace_packet_t *packet);
1282
1283/** get a pointer to the ICMP header (if any) given a pointer to the IP header
1284 * @param ip            The IP header
1285 * @param[in,out] remaining Updated with the number of bytes remaining
1286 *
1287 * @return a pointer to the ICMP header, or NULL if this is not an ICMP packet
1288 *
1289 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
1290 * of bytes captured of the ICMP header and beyond.  It will be decremented by
1291 * the length of the ICMP head in bytes.
1292 *
1293 * @note Beware the change from libtrace2 from skipped to remaining
1294 */
1295DLLEXPORT SIMPLE_FUNCTION
1296libtrace_icmp_t *trace_get_icmp_from_ip(libtrace_ip_t *ip,uint32_t *remaining);
1297
1298/** Get the destination MAC address
1299 * @param packet        the packet opaque pointer
1300 * @return a pointer to the destination mac, (or NULL if there is no
1301 * destination MAC)
1302 */
1303DLLEXPORT SIMPLE_FUNCTION
1304uint8_t *trace_get_destination_mac(libtrace_packet_t *packet);
1305
1306/** Get the source MAC address
1307 * @param packet        the packet opaque pointer
1308 * @return a pointer to the source mac, (or NULL if there is no source MAC)
1309 */
1310DLLEXPORT SIMPLE_FUNCTION
1311uint8_t *trace_get_source_mac(libtrace_packet_t *packet);
1312
1313/** Get the source IP address
1314 * @param packet        the packet opaque pointer
1315 * @param addr          a pointer to a sockaddr to store the address in, or NULL to use
1316 *                      static storage.
1317 * @return NULL if there is no source address, or a sockaddr holding a v4 or v6
1318 * address
1319 */
1320DLLEXPORT SIMPLE_FUNCTION
1321struct sockaddr *trace_get_source_address(const libtrace_packet_t *packet,
1322                struct sockaddr *addr);
1323
1324/** Get the destination IP address
1325 * @param packet        the packet opaque pointer
1326 * @param addr          a pointer to a sockaddr to store the address in, or NULL to use
1327 *                      static storage.
1328 * @return NULL if there is no destination address, or a sockaddr holding a v4
1329 * or v6 address
1330 */
1331DLLEXPORT SIMPLE_FUNCTION
1332struct sockaddr *trace_get_destination_address(const libtrace_packet_t *packet,
1333                struct sockaddr *addr);
1334
1335/*@}*/
1336
1337/** parse an ip or tcp option
1338 * @param[in,out] ptr   the pointer to the current option
1339 * @param[in,out] len   the length of the remaining buffer
1340 * @param[out] type     the type of the option
1341 * @param[out] optlen   the length of the option
1342 * @param[out] data     the data of the option
1343 *
1344 * @return bool true if there is another option (and the fields are filled in)
1345 *               or false if this was the last option.
1346 *
1347 * This updates ptr to point to the next option after this one, and updates
1348 * len to be the number of bytes remaining in the options area.  Type is updated
1349 * to be the code of this option, and data points to the data of this option,
1350 * with optlen saying how many bytes there are.
1351 *
1352 * @note Beware of fragmented packets.
1353 */
1354DLLEXPORT int trace_get_next_option(unsigned char **ptr,int *len,
1355                        unsigned char *type,
1356                        unsigned char *optlen,
1357                        unsigned char **data);
1358
1359
1360/** @name Time
1361 * These functions deal with time that a packet arrived and return it
1362 * in various formats
1363 * @{
1364 */
1365/** Get the current time in DAG time format
1366 * @param packet        the packet opaque pointer
1367 *
1368 * @return a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds
1369 * past 1970-01-01, the lower 32bits are partial seconds)
1370 */
1371DLLEXPORT SIMPLE_FUNCTION
1372uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet);
1373
1374/** Get the current time in struct timeval
1375 * @param packet        the packet opaque pointer
1376 *
1377 * @return time that this packet was seen in a struct timeval
1378 */
1379DLLEXPORT SIMPLE_FUNCTION
1380struct timeval trace_get_timeval(const libtrace_packet_t *packet);
1381
1382/** Get the current time in floating point seconds
1383 * @param packet        the packet opaque pointer
1384 *
1385 * @return time that this packet was seen in 64bit floating point seconds from
1386 * the unix epoch (1970-01-01 00:00:00 UTC).
1387 */
1388DLLEXPORT SIMPLE_FUNCTION
1389double trace_get_seconds(const libtrace_packet_t *packet);
1390
1391/** Seek within a trace
1392 * @param trace         trace to seek
1393 * @param seconds       time to seek to
1394 * @return 0 on success.
1395 * Make the next packet read to be the first packet to occur at or after the
1396 * time searched for.  This must be called in the configuration state (ie,
1397 * before trace_start() or after trace_pause().
1398 * @note This function may be extremely slow.
1399 */
1400DLLEXPORT int trace_seek_seconds(libtrace_t *trace, double seconds);
1401
1402/** Seek within a trace
1403 * @param trace         trace to seek
1404 * @param tv            time to seek to
1405 * @return 0 on success.
1406 * Make the next packet read to be the first packet to occur at or after the
1407 * time searched for.  This must be called in the configuration state (ie,
1408 * before trace_start() or after trace_pause().
1409 * @note This function may be extremely slow.
1410 */
1411DLLEXPORT int trace_seek_timeval(libtrace_t *trace, struct timeval tv);
1412
1413/** Seek within a trace
1414 * @param trace         trace to seek
1415 * @param ts            erf timestamp
1416 * @return 0 on success.
1417 * Make the next packet read to be the first packet to occur at or after the
1418 * time searched for.  This must be called in the configuration state (ie,
1419 * before trace_start() or after trace_pause().
1420 * @note This function may be extremely slow.
1421 */
1422DLLEXPORT int trace_seek_erf_timestamp(libtrace_t *trace, uint64_t ts);
1423
1424/*@}*/
1425
1426/** @name Sizes
1427 * This section deals with finding or setting the various different lengths
1428 * a packet can have
1429 * @{
1430 */
1431/** Get the size of the packet in the trace (in bytes)
1432 * @param packet        the packet opaque pointer
1433 * @return the size of the packet in the trace
1434 * @note Due to this being a header capture, or anonymisation, this may not
1435 * be the same size as the original packet.  See get_wire_length() for the
1436 * original size of the packet.
1437 * @note This can (and often is) different for different packets in a trace!
1438 * @note This is sometimes called the "snaplen".
1439 * @note The return size refers to the network-level payload of the packet and
1440 * does not include any capture framing headers. For example, an Ethernet
1441 * packet with an empty TCP packet will return sizeof(ethernet_header) +
1442 * sizeof(ip_header) + sizeof(tcp_header), but not the capture file
1443 * (pcap/erf/etc) header.
1444 */
1445DLLEXPORT SIMPLE_FUNCTION
1446size_t trace_get_capture_length(const libtrace_packet_t *packet);
1447
1448/** Get the size of the packet as it was seen on the wire (in bytes).
1449 * @param packet        the packet opaque pointer
1450 * @return the size of the packet as it was on the wire.
1451 * @note Due to the trace being a header capture, or anonymisation this may
1452 * not be the same as the Capture Len.
1453 * @note trace_getwire_length \em{includes} FCS.
1454 * @note The return size refers to the network-level payload of the packet and
1455 * does not include any capture framing headers. For example, an Ethernet
1456 * packet with an empty TCP packet will return sizeof(ethernet_header) +
1457 * sizeof(ip_header) + sizeof(tcp_header), but not the capture file
1458 * (pcap/erf/etc) header.
1459 */
1460DLLEXPORT SIMPLE_FUNCTION
1461size_t trace_get_wire_length(const libtrace_packet_t *packet);
1462
1463/** Get the length of the capture framing headers (in bytes).
1464 * @param packet        the packet opaque pointer
1465 * @return the size of the packet as it was on the wire.
1466 * @note this length corresponds to the difference between the size of a
1467 * captured packet in memory, and the captured length of the packet
1468 */
1469DLLEXPORT SIMPLE_FUNCTION
1470size_t trace_get_framing_length(const libtrace_packet_t *packet);
1471
1472/** Truncate ("snap") the packet at the suggested length
1473 * @param packet        the packet opaque pointer
1474 * @param size          the new length of the packet (in bytes)
1475 * @return the new capture length of the packet, or the original capture
1476 * length of the packet if unchanged
1477 */
1478DLLEXPORT size_t trace_set_capture_length(libtrace_packet_t *packet, size_t size);
1479
1480/*@}*/
1481
1482
1483/** Get the type of the link layer
1484 * @param packet        the packet opaque pointer
1485 * @return libtrace_linktype_t
1486 */
1487DLLEXPORT SIMPLE_FUNCTION
1488libtrace_linktype_t trace_get_link_type(const libtrace_packet_t *packet);
1489
1490/** Set the direction flag, if it has one
1491 * @param packet        the packet opaque pointer
1492 * @param direction     the new direction
1493 * @returns -1 on error, or the direction that was set.
1494 */
1495DLLEXPORT libtrace_direction_t trace_set_direction(libtrace_packet_t *packet, libtrace_direction_t direction);
1496
1497/** Get the direction flag, if it has one
1498 * @param packet        the packet opaque pointer
1499 * @return a value containing the direction flag, or -1 if this is not supported
1500 * The direction is defined as 0 for packets originating locally (ie, outbound)
1501 * and 1 for packets originating remotely (ie, inbound).
1502 * Other values are possible, which might be overloaded to mean special things
1503 * for a special trace.
1504 */
1505DLLEXPORT SIMPLE_FUNCTION
1506libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet);
1507
1508/** @name BPF
1509 * This section deals with using Berkley Packet Filters
1510 * @{
1511 */
1512/** setup a BPF filter
1513 * @param filterstring a char * containing the bpf filter string
1514 * @return opaque pointer pointer to a libtrace_filter_t object
1515 * @note The filter is not actually compiled at this point, so no correctness
1516 * tests are performed here. trace_create_filter will always return ok, but
1517 * if the filter is poorly constructed an error will be generated when the
1518 * filter is actually used
1519 */
1520DLLEXPORT SIMPLE_FUNCTION
1521libtrace_filter_t *trace_create_filter(const char *filterstring);
1522
1523/** Setup a BPF filter based on pre-compiled byte-code.
1524 * @param bf_insns      A pointer to the start of the byte-code
1525 * @param bf_len        The number of BPF instructions 
1526 * @returns             an opaque pointer to a libtrace_filter_t object
1527 * @note                The supplied byte-code is not checked for correctness.
1528 * @author              Scott Raynel
1529 */
1530DLLEXPORT libtrace_filter_t *
1531trace_create_filter_from_bytecode(void *bf_insns, unsigned int bf_len);
1532
1533/** Apply a BPF filter to a packet
1534 * @param filter        the filter opaque pointer
1535 * @param packet        the packet opaque pointer
1536 * @return >0 if the filter matches, 0 if it doesn't, -1 on error.
1537 * @note Due to the way BPF filters are built, the filter is not actually
1538 * compiled until the first time trace_create_filter is called. If your filter
1539 * is incorrect, it will generate an error message and assert, exiting the
1540 * program. This behaviour may change to more graceful handling of this error
1541 * in the future.
1542 */
1543DLLEXPORT int trace_apply_filter(libtrace_filter_t *filter,
1544                const libtrace_packet_t *packet);
1545
1546/** Destroy a BPF filter
1547 * @param filter        the filter opaque pointer
1548 * Deallocate all the resources associated with a BPF filter
1549 */
1550DLLEXPORT void trace_destroy_filter(libtrace_filter_t *filter);
1551/*@}*/
1552
1553/** @name Portability
1554 * This section has functions that causes annoyances to portability for one
1555 * reason or another.
1556 * @{
1557 */
1558
1559/** Convert an ethernet address to a string
1560 * @param addr  Ethernet address in network byte order
1561 * @param buf   Buffer to store the ascii representation, or NULL
1562 * @return buf, or if buf is NULL then a statically allocated buffer.
1563 *
1564 * This function is similar to the GNU ether_ntoa_r function, with a few
1565 * minor differences.  if NULL is passed as buf, then the function will
1566 * use an internal static buffer, if NULL isn't passed then the function
1567 * will use that buffer instead.
1568 *
1569 * @note the type of addr isn't struct ether_addr as it is with ether_ntoa_r,
1570 * however it is bit compatible so that a cast will work.
1571 */
1572DLLEXPORT char *trace_ether_ntoa(const uint8_t *addr, char *buf);
1573
1574/** Convert a string to an ethernet address
1575 * @param buf   Ethernet address in hex format delimited with :'s.
1576 * @param addr  buffer to store the binary representation, or NULL
1577 * @return addr, or if addr is NULL, then a statically allocated buffer.
1578 *
1579 * This function is similar to the GNU ether_aton_r function, with a few
1580 * minor differences.  if NULL is passed as addr, then the function will
1581 * use an internal static buffer, if NULL isn't passed then the function will
1582 * use that buffer instead.
1583 *
1584 * @note the type of addr isn't struct ether_addr as it is with ether_aton_r,
1585 * however it is bit compatible so that a cast will work.
1586 */
1587DLLEXPORT uint8_t *trace_ether_aton(const char *buf, uint8_t *addr);
1588
1589/*@}*/
1590
1591
1592/** Which port is the server port */
1593typedef enum {
1594        USE_DEST,       /**< Destination port is the server port */
1595        USE_SOURCE      /**< Source port is the server port */
1596} serverport_t;
1597
1598/** Get the source port
1599 * @param packet        the packet to read from
1600 * @return a port in \em HOST byte order, or equivalent to ports for this
1601 * protocol, or 0 if this protocol has no ports.
1602 */
1603DLLEXPORT SIMPLE_FUNCTION
1604uint16_t trace_get_source_port(const libtrace_packet_t *packet);
1605
1606/** Get the destination port
1607 * @param packet        the packet to read from
1608 * @return a port in \em HOST byte order, or equivilent to ports for this
1609 * protocol, or 0 if this protocol has no ports.
1610 */
1611DLLEXPORT SIMPLE_FUNCTION
1612uint16_t trace_get_destination_port(const libtrace_packet_t *packet);
1613
1614/** hint at the server port in specified protocol
1615 * @param protocol      the IP layer protocol, eg 6 (tcp), 17 (udp)
1616 * @param source        the source port from the packet
1617 * @param dest          the destination port from the packet
1618 * @return one of USE_SOURCE or USE_DEST depending on which one you should use
1619 * @note ports must be in \em HOST byte order!
1620 */
1621DLLEXPORT SIMPLE_FUNCTION
1622int8_t trace_get_server_port(uint8_t protocol, uint16_t source, uint16_t dest);
1623
1624/** Takes a uri and splits it into a format and uridata component.
1625 * @param uri           the uri to be parsed
1626 * @param format        destination location for the format component of the uri
1627 * @return 0 if an error occured, otherwise return the uridata component
1628 */
1629DLLEXPORT const char *trace_parse_uri(const char *uri, char **format);
1630
1631/** Gets the format type for a given packet.
1632 * @param packet        the packet opaque pointer
1633 * @return the format of the packet
1634 */
1635DLLEXPORT
1636enum base_format_t trace_get_format(struct libtrace_packet_t *packet);
1637
1638/** Construct a packet from a buffer.
1639 * @param packet[in,out]        Libtrace Packet object to update with the new
1640 *                              data.
1641 * @param linktype              The linktype of the packet.
1642 * @param[in] data              The packet data (including linklayer)
1643 * @param len                   Length of packet data
1644 */
1645DLLEXPORT
1646void trace_construct_packet(libtrace_packet_t *packet,
1647                libtrace_linktype_t linktype, const void *data, uint16_t len);
1648
1649/*@}*/
1650
1651/** @name Wireless trace support
1652 * Functions to access wireless information from packets that have wireless
1653 * monitoring headers such as Radiotap or Prism.
1654 *
1655 * The trace_get_wireless_* functions provide an abstract interface for
1656 * retrieving information from wireless traces. They take a pointer to the
1657 * wireless monitoring header (usually found with trace_get_link(packet)) and
1658 * the linktype of the header passed in.
1659 *
1660 * All of the trace_get_wireless_* functions return false if the requested
1661 * information was unavailable, or true if it was. The actual data is stored
1662 * in an output variable supplied by the caller. Values returned into the
1663 * output variable will always be returned in host byte order.
1664 * @{
1665 */
1666
1667
1668#ifndef ARPHRD_80211_RADIOTAP
1669/* libc doesn't define this yet, but it seems to be what everyone is using
1670 */
1671#define ARPHRD_80211_RADIOTAP 803
1672#endif
1673
1674/** Get the wireless Timer Syncronisation Function
1675 *
1676 * Gets the value of the timer syncronisation function for this frame, which
1677 * is a value in microseconds indicating the time that the first bit of the
1678 * MPDU was received by the MAC.
1679 *
1680 * @param link the wireless header
1681 * @param linktype the linktype of the wireless header passed in
1682 * @param[out] tsft the value of the timer syncronisation function.
1683 * @return true if the field was available, false if not.
1684 */
1685DLLEXPORT bool trace_get_wireless_tsft(void *linkptr,
1686        libtrace_linktype_t linktype, uint64_t *tsft);
1687
1688/** Get the wireless rate
1689 * @param link the wireless header
1690 * @param linktype the linktype of the wireless header passed in
1691 * @param[out] rate the data-rate of the frame in units of 500kbps
1692 * @return true if the field was available, false if not.
1693 */
1694DLLEXPORT bool trace_get_wireless_rate(void *linkptr,
1695        libtrace_linktype_t linktype, uint8_t *rate);
1696
1697/** Get the wireless channel frequency
1698 * @param link the wireless header
1699 * @param linktype the linktype of the wireless header passed in
1700 * @param[out] freq the frequency in MHz of the channel the frame was transmitted
1701 * or received on.
1702 * @return true if the field was available, false if not.
1703 */
1704DLLEXPORT bool trace_get_wireless_freq(void *linkptr,
1705        libtrace_linktype_t linktype, uint16_t *freq);
1706
1707/** Get the wireless signal strength in dBm
1708 * @param link the wireless header
1709 * @param linktype the linktype of the wireless header passed in
1710 * @param[out] strength the RF signal power at the antenna, in dB difference
1711 * from 1mW.
1712 * @return true if the field was available, false if not.
1713 */
1714DLLEXPORT bool trace_get_wireless_signal_strength_dbm(void *linkptr,
1715        libtrace_linktype_t linktype, int8_t *strength);
1716
1717/** Get the wireless noise strength in dBm
1718 * @param link the wireless header
1719 * @param linktype the linktype of the wireless header passed in
1720 * @param[out] strength the RF noise power at the antenna, in dB difference
1721 * from 1mW.
1722 * @return true if the field was available, false if not.
1723 */
1724DLLEXPORT bool trace_get_wireless_noise_strength_dbm(void *linkptr,
1725        libtrace_linktype_t linktype, int8_t *strength);
1726
1727/** Get the wireless signal strength in dB
1728 * @param link the wireless header
1729 * @param linktype the linktype of the wireless header passed in
1730 * @param[out] strength the RF signal power at the antenna,in dB difference
1731 * from a fixed reference.
1732 * @return true if the field was available, false if not.
1733 */
1734DLLEXPORT bool trace_get_wireless_signal_strength_db(void *linkptr,
1735        libtrace_linktype_t linktype, uint8_t *strength);
1736
1737/** Get the wireless noise strength in dB
1738 * @param link the wireless header
1739 * @param linktype the linktype of the wireless header passed in
1740 * @param[out] strength the RF noise power at the antenna, in dB difference
1741 * from a fixed reference.
1742 * @return true if the field was available, false if not.
1743 */
1744DLLEXPORT bool trace_get_wireless_noise_strength_db(void *linkptr,
1745        libtrace_linktype_t linktype, uint8_t *strength);
1746
1747/** Get the wireless transmit attenuation
1748 * @param link the wireless header
1749 * @param linktype the linktype of the wireless header passed in
1750 * @param[out] attenuation the transmit power as a unitless distance from maximum
1751 * power set at factory calibration. 0 indicates maximum transmission power.
1752 * @return true if the field was available, false if not.
1753 */
1754DLLEXPORT bool trace_get_wireless_tx_attenuation(void *linkptr,
1755        libtrace_linktype_t linktype, uint16_t *attenuation);
1756
1757/** Get the wireless transmit attenuation in dB
1758 * @param link the wireless header
1759 * @param linktype the linktype of the wireless header passed in
1760 * @param[out] attenuation the transmit power as dB difference from maximum power
1761 * set at factory calibration. 0 indicates maximum power.
1762 * @return true if the field was available, false if not.
1763 */
1764DLLEXPORT bool trace_get_wireless_tx_attenuation_db(void *linkptr,
1765        libtrace_linktype_t linktype, uint16_t *attenuation);
1766
1767/** Get the wireless transmit power in dBm @param link the wireless header
1768 * @param linktype the linktype of the wireless header passed in
1769 * @param[out] txpower the transmit power as dB from a 1mW reference. This is the absolute power level measured at the antenna port. 
1770 * @return true if the field was available, false if not.
1771 */
1772DLLEXPORT bool trace_get_wireless_tx_power_dbm(void *linkptr, libtrace_linktype_t
1773                linktype, int8_t *txpower);
1774
1775/** Get the wireless antenna
1776 * @param link the wireless header
1777 * @param linktype the linktype of the wireless header passed in
1778 * @param[out] antenna which antenna was used to transmit or receive the frame.
1779 * @return true if the field was available, false if not.
1780 */
1781DLLEXPORT bool trace_get_wireless_antenna(void *linkptr,
1782        libtrace_linktype_t linktype, uint8_t *antenna);
1783
1784/*@}*/
1785
1786#ifdef __cplusplus
1787} /* extern "C" */
1788#endif /* #ifdef __cplusplus */
1789#endif /* LIBTRACE_H_ */
Note: See TracBrowser for help on using the repository browser.