source: lib/libtrace.h.in @ a81d2fc

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since a81d2fc was 3a14f3b, checked in by Scott Raynel <smr26@…>, 14 years ago

Allow libtrace applications to create filters based on pre-compiled BPF
bytecode as well as filterstrings. See trace_create_filter_from_bytecode()

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