source: lib/libtrace.h.in @ 3fcb8b4

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 3fcb8b4 was 3fcb8b4, checked in by Shane Alcock <salcock@…>, 15 years ago

Added a couple of necessary fixes for FreeBSD compilation - defining PATH_MAX and including unistd.h for ssize_t and off_t
stdbool.h is no longer included if you're compiling as C++ as this causes conflicts under OpenBSD

  • Property mode set to 100644
File size: 42.7 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2004 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#include <sys/time.h>
60
61#ifdef _MSC_VER
62    /* define the following from MSVC's internal types */
63    typedef             __int8  int8_t;
64    typedef             __int16 int16_t;
65    typedef             __int32 int32_t;
66    typedef             __int64 int64_t;
67    typedef unsigned    __int8  uint8_t;
68    typedef unsigned    __int16 uint16_t;
69    typedef unsigned    __int32 uint32_t;
70    typedef unsigned    __int64 uint64_t;
71        #ifdef BUILDING_DLL
72                #define DLLEXPORT __declspec(dllexport)
73        #else
74                #define DLLEXPORT __declspec(dllimport)
75        #endif
76        #define DLLLOCAL
77#else
78        #ifdef HAVE_GCCVISIBILITYPATCH
79                #define DLLEXPORT __attribute__ (visibility("default"))
80                #define DLLLOCAL __attribute__ (visibility("hidden"))
81        #else
82                #define DLLEXPORT
83                #define DLLLOCAL
84        #endif
85#endif
86
87#ifdef WIN32
88#   include <winsock2.h>
89#   include <ws2tcpip.h>
90    typedef short sa_family_t;
91    /* Make up for a lack of stdbool.h */
92#    define bool signed char
93#    define false 0
94#    define true 1
95#    if !defined(ssize_t)
96     /* XXX: Not 64-bit safe! */
97#    define ssize_t int
98#    endif   
99#else
100#    include <netinet/in.h>
101
102#ifndef __cplusplus
103#    include <stdbool.h>
104#endif
105
106#    include <sys/types.h>
107#    include <sys/socket.h>
108#endif
109
110/** API version as 2 byte hex digits, eg 0xXXYYZZ */
111#define LIBTRACE_API_VERSION \
112            ((@LIBTRACE_MAJOR@<<16)|(@LIBTRACE_MID@<<8)|(@LIBTRACE_MINOR@))
113
114#ifdef __cplusplus
115extern "C" {
116#endif
117
118/* Function does not depend on anything but its
119 * parameters, used to hint gcc's optimisations
120 */
121#if __GNUC__ >= 3
122#  define SIMPLE_FUNCTION __attribute__((pure))
123#  define UNUSED __attribute__((unused))
124#  define PACKED __attribute__((packed))
125#  define CONSTRUCTOR __attribute__((constructor))
126#else
127#  define SIMPLE_FUNCTION
128#  define UNUSED
129#  define PACKED
130#  define CONSTRUCTOR
131#endif
132       
133/** Opaque structure holding information about an output trace */
134typedef struct libtrace_out_t libtrace_out_t;
135       
136/** Opaque structure holding information about a trace */
137typedef struct libtrace_t libtrace_t;
138       
139/** Opaque structure holding information about a bpf filter */
140typedef struct libtrace_filter_t libtrace_filter_t;
141
142/** if a packet has memory allocated
143 * If the packet has allocated it's own memory it's buffer_control should
144 * be TRACE_CTRL_PACKET, when the packet is destroyed it's memory will be
145 * free()'d.  If it's doing zerocopy out of memory owned by something else
146 * it should be TRACE_CTRL_EXTERNAL.
147 * @note the letters p and e are magic numbers used to detect if the packet
148 * wasn't created properly
149 */
150typedef enum {
151        TRACE_CTRL_PACKET='p',
152        TRACE_CTRL_EXTERNAL='e'
153} buf_control_t;
154/** Structure holding information about a packet */
155#define LIBTRACE_PACKET_BUFSIZE 65536
156
157/** The libtrace structure, applications shouldn't be meddling around in here
158 */
159typedef struct libtrace_packet_t {
160        struct libtrace_t *trace; /**< pointer to the trace */
161        void *header;           /**< pointer to the framing header */
162        void *payload;          /**< pointer to the link layer */
163        buf_control_t buf_control; /**< who owns the memory */
164        void *buffer;           /**< allocated buffer */
165        size_t size;            /**< trace_get_framing_length()
166                                 * +trace_get_capture_length() */
167        uint32_t type;          /**< rt protocol type for the packet */
168} libtrace_packet_t;
169
170/** libtrace error information */
171typedef struct trace_err_t{
172        int err_num;            /**< error code */
173        char problem[255];      /**< the format, uri etc that caused the error for reporting purposes */
174} libtrace_err_t;
175
176/** Enumeration of error codes */
177enum {
178        /** No Error has occured.... yet. */
179        TRACE_ERR_NOERROR       = 0,
180        /** The URI passed to trace_create() is unsupported, or badly formed */
181        TRACE_ERR_BAD_FORMAT    = -1,
182        /** The trace failed to initialise */
183        TRACE_ERR_INIT_FAILED   = -2,
184        /** Unknown config option */
185        TRACE_ERR_UNKNOWN_OPTION= -3,
186        /** Option known, but unsupported by this format */
187        TRACE_ERR_OPTION_UNAVAIL= -6,
188        /** This output uri cannot write packets of this type */
189        TRACE_ERR_NO_CONVERSION = -4,
190        /** This packet is corrupt, or unusable for the action required */
191        TRACE_ERR_BAD_PACKET    = -5,
192        /** This feature is unsupported */
193        TRACE_ERR_UNSUPPORTED   = -7
194};
195
196typedef enum {
197        TRACE_DLT_NULL = 0,
198        TRACE_DLT_EN10MB = 1,
199        TRACE_DLT_ATM_RFC1483 = 11,
200        TRACE_DLT_IEEE802_11 = 105,
201        TRACE_DLT_LINUX_SLL = 113,
202        TRACE_DLT_PFLOG = 117
203} libtrace_dlt_t ;
204
205/** Link layer types
206 * This enumates the various different link types that libtrace understands
207 */
208typedef enum {
209       TRACE_TYPE_HDLC_POS = 1,
210       TRACE_TYPE_ETH,                  /**< 802.3 style Ethernet */
211       TRACE_TYPE_ATM,
212       TRACE_TYPE_AAL5,
213       TRACE_TYPE_80211,                /**< 802.11 frames */
214       TRACE_TYPE_NONE,                 /**< Raw IP frames */
215       TRACE_TYPE_LINUX_SLL,            /**< Linux "null" framing */
216       TRACE_TYPE_PFLOG,                /**< FreeBSD's PFlug */
217       TRACE_TYPE_POS,
218       TRACE_TYPE_80211_PRISM = 12
219     } libtrace_linktype_t;
220
221/** Trace directions
222 * Note that these are the directions used by convention, more directions
223 * are possible, not just these 3, and that they may not conform to this
224 * convention.
225 */
226typedef enum {
227        TRACE_DIR_OUTGOING = 0,         /**< Packets originating "outside" */
228        TRACE_DIR_INCOMING = 1,         /**< Packets originating "inside" */
229        TRACE_DIR_OTHER    = 2          /**< Packets with an unknown direction, or one that's unknown */
230} libtrace_direction_t;
231
232/** @name Protocol structures
233 * These convenience structures are here as they are portable ways of dealing
234 * with various protocols.
235 * @{
236 */
237
238#ifdef WIN32
239#pragma pack(push)
240#pragma pack(1)
241#endif
242
243/** Structure for dealing with IP packets */
244typedef struct libtrace_ip
245{
246#if BYTE_ORDER == LITTLE_ENDIAN
247    uint8_t ip_hl:4;            /**< header length */
248    uint8_t ip_v:4;             /**< version */
249#elif BYTE_ORDER == BIG_ENDIAN
250    uint8_t ip_v:4;             /**< version */
251    uint8_t ip_hl:4;            /**< header length */
252#else
253#   error "Adjust your <bits/endian.h> defines"
254#endif
255    uint8_t  ip_tos;                    /**< type of service */
256    uint16_t ip_len;                    /**< total length */
257    int16_t  ip_id;                     /**< identification */
258#if BYTE_ORDER == LITTLE_ENDIAN
259    uint16_t ip_off:12;         /**< fragment offset */
260    uint16_t ip_mf:1;           /**< more fragments flag */
261    uint16_t ip_df:1;           /**< dont fragment flag */
262    uint16_t ip_rf:1;           /**< reserved fragment flag */
263#elif BYTE_ORDER == BIG_ENDIAN
264    uint16_t ip_rf:1;
265    uint16_t ip_df:1;
266    uint16_t ip_mf:1;
267    uint16_t ip_off:12;
268#else
269#   error "Adjust your <bits/endian.h> defines"
270#endif
271    uint8_t  ip_ttl;                    /**< time to live */
272    uint8_t  ip_p;                      /**< protocol */
273    uint16_t ip_sum;                    /**< checksum */
274    struct in_addr ip_src;              /**< source address */
275    struct in_addr ip_dst;              /**< dest address */
276} PACKED libtrace_ip_t;
277
278typedef struct libtrace_ip6_ext
279{
280        uint8_t nxt;
281        uint8_t len;
282} PACKED libtrace_ip6_ext_t;
283
284/** IPv6 header structure */
285typedef struct libtrace_ip6
286{
287    uint32_t flow;
288    uint16_t plen;                      /**< Payload length */
289    uint8_t nxt;                        /**< Next header */
290    uint8_t hlim;                       /**< Hop limit */
291    struct in6_addr ip_src;             /**< source address */
292    struct in6_addr ip_dst;             /**< dest address */
293} PACKED libtrace_ip6_t;
294
295/** Structure for dealing with TCP packets */
296typedef struct libtrace_tcp
297  {
298    uint16_t source;            /**< Source Port */
299    uint16_t dest;              /**< Destination port */
300    uint32_t seq;               /**< Sequence number */
301    uint32_t ack_seq;           /**< Acknowledgement Number */
302#  if BYTE_ORDER == LITTLE_ENDIAN
303    uint8_t res1:4;     /**< Reserved bits */
304    uint8_t doff:4;     /**< data offset */     
305    uint8_t fin:1;              /**< FIN */
306    uint8_t syn:1;              /**< SYN flag */
307    uint8_t rst:1;              /**< RST flag */
308    uint8_t psh:1;              /**< PuSH flag */
309    uint8_t ack:1;              /**< ACK flag */
310    uint8_t urg:1;              /**< URG flag */
311    uint8_t res2:2;     /**< Reserved */
312#  elif BYTE_ORDER == BIG_ENDIAN
313    uint8_t doff:4;     /**< Data offset */
314    uint8_t res1:4;     /**< Reserved bits */
315    uint8_t res2:2;     /**< Reserved */
316    uint8_t urg:1;              /**< URG flag */
317    uint8_t ack:1;              /**< ACK flag */
318    uint8_t psh:1;              /**< PuSH flag */
319    uint8_t rst:1;              /**< RST flag */
320    uint8_t syn:1;              /**< SYN flag */
321    uint8_t fin:1;              /**< FIN flag */
322#  else
323#   error "Adjust your <bits/endian.h> defines"
324#  endif
325    uint16_t window;            /**< Window Size */
326    uint16_t check;             /**< Checksum */
327    uint16_t urg_ptr;           /**< Urgent Pointer */
328} PACKED libtrace_tcp_t;
329
330/** UDP Header for dealing with UDP packets */
331typedef struct libtrace_udp {
332  uint16_t      source;         /**< Source port */
333  uint16_t      dest;           /**< Destination port */
334  uint16_t      len;            /**< Length */
335  uint16_t      check;          /**< Checksum */
336} PACKED libtrace_udp_t;
337
338/** ICMP Header for dealing with icmp packets */
339typedef struct libtrace_icmp
340{
341  uint8_t type;         /**< message type */
342  uint8_t code;         /**< type sub-code */
343  uint16_t checksum;            /**< checksum */
344  union
345  {
346    struct
347    {
348      uint16_t  id;
349      uint16_t  sequence;
350    } echo;                     /**< echo datagram */
351    uint32_t    gateway;        /**< gateway address */
352    struct
353    {
354      uint16_t  unused;
355      uint16_t  mtu;
356    } frag;                     /**< path mtu discovery */
357  } un;                         /**< Union for payloads of various icmp codes */
358} PACKED libtrace_icmp_t;
359
360/** LLC/SNAP header */
361typedef struct libtrace_llcsnap
362{
363/* LLC */
364  uint8_t dsap;                 /**< Destination Service Access Point */
365  uint8_t ssap;                 /**< Source Service Access Point */
366  uint8_t control;
367/* SNAP */
368  uint32_t oui:24;              /**< Organisationally Unique Identifier (scope)*/
369  uint16_t type;                /**< Protocol within OUI */
370} PACKED libtrace_llcsnap_t;
371
372/** 802.3 frame */
373typedef struct libtrace_ether
374{
375  uint8_t ether_dhost[6];       /**< destination ether addr */
376  uint8_t ether_shost[6];       /**< source ether addr */
377  uint16_t ether_type;          /**< packet type ID field (next-header) */
378} PACKED libtrace_ether_t;
379
380/** 802.1Q frame */
381typedef struct libtrace_8021q
382{
383  uint16_t vlan_pri:3;   /**< vlan user priority */
384  uint16_t vlan_cfi:1;   /**< vlan format indicator,
385                                   * 0 for ethernet, 1 for token ring */
386  uint16_t vlan_id:12;   /**< vlan id */
387  uint16_t vlan_ether_type;      /**< vlan sub-packet type ID field
388                                   * (next-header)*/
389} PACKED libtrace_8021q_t;
390
391/** ATM cell */
392typedef struct libtrace_atm_cell
393{
394  uint32_t gfc:4;               /**< Generic Flow Control */
395  uint32_t vpi:8;               /**< Virtual Path Identifier */
396  uint32_t vci:8;               /**< Virtual Channel Identifier */
397  uint32_t pt:3;                /**< Payload Type */
398  uint32_t clp:1;               /**< Cell Loss Priority */
399  uint32_t hec:8;               /**< Header Error Control */
400} PACKED libtrace_atm_cell_t;
401
402/** POS header */
403typedef struct libtrace_pos
404{
405 uint16_t header;
406 uint16_t ether_type;           /**< ether type */
407} PACKED libtrace_pos_t;
408
409/** 802.11 header */
410typedef struct libtrace_80211_t {
411        uint16_t      protocol:2;
412        uint16_t      type:2;
413        uint16_t      subtype:4;
414        uint16_t      to_ds:1;          /**< Packet to Distribution Service */
415        uint16_t      from_ds:1;        /**< Packet from Distribution Service */
416        uint16_t      more_frag:1;      /**< Packet has more fragments */
417        uint16_t      retry:1;          /**< Packet is a retry */
418        uint16_t      power:1;
419        uint16_t      more_data:1;
420        uint16_t      wep:1;
421        uint16_t      order:1;
422        uint16_t     duration;
423        uint8_t      mac1[6];
424        uint8_t      mac2[6];
425        uint8_t      mac3[6];
426        uint16_t     SeqCtl;
427        uint8_t      mac4[6];
428} PACKED libtrace_80211_t;
429
430#ifdef WIN32
431#pragma pack(pop)
432#endif
433
434
435/*@}*/
436
437/** Prints help information for libtrace
438 *
439 * Function prints out some basic help information regarding libtrace,
440 * and then prints out the help() function registered with each input module
441 */
442DLLEXPORT void trace_help();
443
444/** Gets the output format for a given output trace
445 *
446 * @param libtrace      the output trace to get the name of the format fo
447 * @return callee-owned null-terminated char* containing the output format
448 *
449 */
450DLLEXPORT SIMPLE_FUNCTION
451char *trace_get_output_format(const libtrace_out_t *libtrace);
452
453/** @name Trace management
454 * These members deal with creating, configuring, starting, pausing and
455 * cleaning up a trace object
456 *@{
457 */
458
459/** Create a trace file from a URI
460 *
461 * @param uri containing a valid libtrace URI
462 * @return opaque pointer to a libtrace_t
463 *
464 * Valid URI's are:
465 *  - erf:/path/to/erf/file
466 *  - erf:/path/to/erf/file.gz
467 *  - erf:/path/to/rtclient/socket
468 *  - erf:-  (stdin)
469 *  - dag:/dev/dagcard                 
470 *  - pcapint:pcapinterface                (eg: pcap:eth0)
471 *  - pcap:/path/to/pcap/file
472 *  - pcap:-
473 *  - rtclient:hostname
474 *  - rtclient:hostname:port
475 *  - wag:-
476 *  - wag:/path/to/wag/file
477 *  - wag:/path/to/wag/file.gz
478 *  - wag:/path/to/wag/socket
479 *
480 *  If an error occured when attempting to open the trace file, an error
481 *  trace is returned and trace_get_error should be called to find out
482 *  if an error occured, and what that error was.  The trace is created in the
483 *  configuration state, you must call trace_start to start the capture.
484 */
485DLLEXPORT libtrace_t *trace_create(const char *uri);
486
487/** Creates a "dummy" trace file that has only the format type set.
488 *
489 * @return opaque pointer to a (sparsely initialised) libtrace_t
490 *
491 * IMPORTANT: Do not attempt to call trace_read_packet or other such functions
492 * with the dummy trace. Its intended purpose is to act as a packet->trace for
493 * libtrace_packet_t's that are not associated with a libtrace_t structure.
494 */
495DLLEXPORT libtrace_t *trace_create_dead(const char *uri);
496
497/** Creates a trace output file from a URI.
498 *
499 * @param uri   the uri string describing the output format and destination
500 * @return opaque pointer to a libtrace_output_t
501 * @author Shane Alcock
502 *
503 * Valid URI's are:
504 *  - gzerf:/path/to/erf/file.gz
505 *  - gzerf:/path/to/erf/file
506 *  - rtserver:hostname
507 *  - rtserver:hostname:port
508 *
509 *  If an error occured when attempting to open the output trace, NULL is returned
510 *  and trace_errno is set. Use trace_perror() to get more information
511 */
512DLLEXPORT libtrace_out_t *trace_create_output(const char *uri);
513
514/** Start the capture
515 * @param libtrace      The trace to start
516 * @return 0 on success
517 *
518 * This does the actual work with starting the trace capture, and applying
519 * all the config options.  This may fail.
520 */
521DLLEXPORT int trace_start(libtrace_t *libtrace);
522
523/** Pause the capture
524 * @param libtrace      The trace to pause
525 * @return 0 on success
526 *
527 * This stops a capture in progress and returns you to the configuration
528 * state.  Any packets that arrive after trace_pause() has been called
529 * will be discarded.  To resume capture, call trace_start().
530 */
531DLLEXPORT int trace_pause(libtrace_t *libtrace);
532
533/** Start an output trace
534 * @param libtrace      The trace to start
535 * @return 0 on success
536 *
537 * This does the actual work with starting a trace for write.  This generally
538 * creates the file.
539 */
540DLLEXPORT int trace_start_output(libtrace_out_t *libtrace);
541
542/** Valid trace capture options */
543typedef enum {
544        TRACE_OPTION_SNAPLEN, /**< Number of bytes captured */
545        TRACE_OPTION_PROMISC, /**< Capture packets to other hosts */
546        TRACE_OPTION_FILTER   /**< Apply this filter to all packets recieved */
547} trace_option_t;
548
549/** Sets an input config option
550 * @param libtrace      the trace object to apply the option to
551 * @param option        the option to set
552 * @param value         the value to set the option to
553 * @return -1 if option configuration failed, 0 otherwise
554 * This should be called after trace_create, and before trace_start
555 */
556DLLEXPORT int trace_config(libtrace_t *libtrace,
557                trace_option_t option,
558                void *value);
559
560typedef enum {
561        TRACE_OPTION_OUTPUT_FILEFLAGS, /**< File flags to open the trace file
562                                        * with.  eg O_APPEND
563                                        */
564        TRACE_OPTION_OUTPUT_COMPRESS   /**< Compression level, eg 6. */
565} trace_option_output_t;
566
567/** Sets an output config option
568 *
569 * @param libtrace      the output trace object to apply the option to
570 * @param option        the option to set
571 * @param value         the value to set the option to
572 * @return -1 if option configuration failed, 0 otherwise
573 * This should be called after trace_create_output, and before
574 * trace_start_output
575 */
576DLLEXPORT int trace_config_output(libtrace_out_t *libtrace,
577                trace_option_output_t option,
578                void *value
579                );
580
581/** Close a trace file, freeing up any resources it may have been using
582 *
583 */
584DLLEXPORT void trace_destroy(libtrace_t *trace);
585
586/** Close a trace file, freeing up any resources it may have been using
587 * @param trace         trace file to be destroyed
588 */
589DLLEXPORT void trace_destroy_dead(libtrace_t *trace);
590
591/** Close a trace output file, freeing up any resources it may have been using
592 * @param trace         the output trace file to be destroyed
593 *
594 * @author Shane Alcock
595 */
596DLLEXPORT void trace_destroy_output(libtrace_out_t *trace);
597
598/** Check (and clear) the current error state of an input trace
599 * @param trace         the trace file to check the error state on
600 * @return Error report
601 * This reads and returns the current error state and sets the current error
602 * to "no error".
603 */
604DLLEXPORT libtrace_err_t trace_get_err(libtrace_t *trace);
605
606/** Return if there is an error
607 * @param trace         the trace file to check the error state on
608 * This does not clear the error status, and only returns true or false.
609 */
610DLLEXPORT bool trace_is_err(libtrace_t *trace);
611
612/** Output an error message to stderr and clear the error status.
613 * @param trace         the trace with the error to output
614 * @param msg           the message to prefix to the error
615 * This function does clear the error status.
616 */
617DLLEXPORT void trace_perror(libtrace_t *trace, const char *msg,...);
618
619/** Check (and clear) the current error state of an output trace
620 * @param trace         the output trace file to check the error state on
621 * @return Error report
622 * This reads and returns the current error state and sets the current error
623 * to "no error".
624 */
625DLLEXPORT libtrace_err_t trace_get_err_output(libtrace_out_t *trace);
626
627/** Return if there is an error
628 * @param trace         the trace file to check the error state on
629 * This does not clear the error status, and only returns true or false.
630 */
631DLLEXPORT bool trace_is_err_output(libtrace_out_t *trace);
632
633/** Output an error message to stderr and clear the error status.
634 * @param trace         the trace with the error to output
635 * @param msg           the message to prefix to the error
636 * This function does clear the error status.
637 */
638DLLEXPORT void trace_perror_output(libtrace_out_t *trace, const char *msg,...);
639
640
641/*@}*/
642
643/** @name Reading/Writing packets
644 * These members deal with creating, reading and writing packets
645 *
646 * @{
647 */
648
649/** Create a new packet object
650 *
651 * @return a pointer to an initialised libtrace_packet_t object
652 */
653DLLEXPORT libtrace_packet_t *trace_create_packet();
654
655/** Copy a packet
656 * @param packet        the source packet to copy
657 * @return a new packet which has the same content as the source packet
658 * @note This always involves a copy, which can be slow.  Use of this
659 * function should be avoided where possible.
660 * @par The reason you would want to use this function is that a zerocopied
661 * packet from a device is using the devices memory which may be a limited
662 * resource.  Copying the packet will cause it to be copied into the systems
663 * memory.
664 */
665DLLEXPORT libtrace_packet_t *trace_copy_packet(const libtrace_packet_t *packet);
666
667/** Destroy a packet object
668 *
669 * sideeffect: sets packet to NULL
670 */
671DLLEXPORT void trace_destroy_packet(libtrace_packet_t **packet);
672
673
674/** Read one packet from the trace into buffer
675 *
676 * @param trace         the libtrace opaque pointer
677 * @param packet        the packet opaque pointer
678 * @return 0 on EOF, negative value on error, number of bytes read when
679 * successful.
680 *
681 * @note the number of bytes read is usually (but not always) the same as
682 * trace_get_framing_length()+trace_get_capture_length() depending on the
683 * trace format.
684 * @note the trace must have been started with trace_start before calling
685 * this function
686 */
687DLLEXPORT int trace_read_packet(libtrace_t *trace, libtrace_packet_t *packet);
688
689/** Event types
690 * see \ref libtrace_eventobj_t and \ref trace_event
691 */
692typedef enum {
693        TRACE_EVENT_IOWAIT,     /**< Need to block on fd */
694        TRACE_EVENT_SLEEP,      /**< Sleep for some time */
695        TRACE_EVENT_PACKET,     /**< packet has arrived */
696        TRACE_EVENT_TERMINATE   /**< End of trace */
697} libtrace_event_t;
698
699/** structure returned by libtrace_event explaining what the current event is */
700typedef struct libtrace_eventobj_t {
701        libtrace_event_t type; /**< event type (iowait,sleep,packet) */
702        int fd;                /**< if IOWAIT, the fd to sleep on */
703        double seconds;        /**< if SLEEP, the amount of time to sleep for
704                                */
705        int size;              /**< if PACKET, the value returned from
706                                *  trace_read_packet
707                                */
708} libtrace_eventobj_t;
709
710/** process a libtrace event
711 * @param trace the libtrace opaque pointer
712 * @param packet the libtrace_packet opaque pointer
713 * @return libtrace_event struct containing the type, and potential
714 *      fd or seconds to sleep on
715 *
716 * Type can be:
717 *  TRACE_EVENT_IOWAIT  Waiting on I/O on fd
718 *  TRACE_EVENT_SLEEP   Next event in seconds
719 *  TRACE_EVENT_PACKET  Packet arrived in buffer with size size
720 *  TRACE_EVENT_TERMINATE Trace terminated (perhaps with an error condition)
721 */
722DLLEXPORT libtrace_eventobj_t trace_event(libtrace_t *trace,
723                libtrace_packet_t *packet);
724
725
726/** Write one packet out to the output trace
727 *
728 * @param trace         the libtrace_out opaque pointer
729 * @param packet        the packet opaque pointer
730 * @return the number of bytes written out, if zero or negative then an error has occured.
731 */
732DLLEXPORT int trace_write_packet(libtrace_out_t *trace, const libtrace_packet_t *packet);
733/*@}*/
734
735/** @name Protocol decodes
736 * These functions locate and return a pointer to various headers inside a
737 * packet
738 * @{
739 */
740
741/** get a pointer to the link layer
742 * @param packet        the packet opaque pointer
743 *
744 * @return a pointer to the link layer, or NULL if there is no link layer
745 *
746 * @note you should call getLinkType() to find out what type of link layer
747 * this is
748 */
749DLLEXPORT SIMPLE_FUNCTION
750void *trace_get_link(const libtrace_packet_t *packet);
751
752/** get a pointer to the IP header (if any)
753 * @param packet        the packet opaque pointer
754 *
755 * @return a pointer to the IP header, or NULL if there is not an IP packet
756 */
757DLLEXPORT SIMPLE_FUNCTION
758libtrace_ip_t *trace_get_ip(libtrace_packet_t *packet);
759
760/** Gets a pointer to the transport layer header (if any)
761 * @param packet        a pointer to a libtrace_packet structure
762 * @param[out] proto    transport layer protocol
763 *
764 * @return a pointer to the transport layer header, or NULL if there is no header
765 *
766 * @note proto may be NULL if proto is unneeded.
767 */
768DLLEXPORT void *trace_get_transport(libtrace_packet_t *packet, uint8_t *proto,
769                uint32_t *remaining);
770
771/** Gets a pointer to the payload given a pointer to the IP header
772 * @param ip            The IP Header
773 * @param[out] proto    An output variable of the IP protocol
774 * @param[in,out] remaining Updated with the number of bytes remaining
775 *
776 * @return a pointer to the transport layer header, or NULL if header isn't present.
777 *
778 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
779 * of bytes captured of the IP header and beyond.  It will be updated after this
780 * function to the number of bytes remaining after the IP header (and any IP options)
781 * have been removed.
782 *
783 * proto may be NULL if not needed.
784 *
785 * @note This is similar to trace_get_transport_from_ip in libtrace2
786 */
787DLLEXPORT void *trace_get_payload_from_ip(libtrace_ip_t *ip, uint8_t *proto,
788                uint32_t *remaining);
789
790/** Gets a pointer to the payload given a pointer to a tcp header
791 * @param tcp           The tcp Header
792 * @param[in,out] remaining Updated with the number of bytes remaining
793 *
794 * @return a pointer to the tcp payload, or NULL if the payload isn't present.
795 *
796 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
797 * of bytes captured of the TCP header and beyond.  It will be updated after this
798 * function to the number of bytes remaining after the TCP header (and any TCP options)
799 * have been removed.
800 *
801 * @note This is similar to trace_get_transport_from_ip in libtrace2
802 */
803DLLEXPORT void *trace_get_payload_from_tcp(libtrace_tcp_t *tcp, uint32_t *remaining);
804
805/** Gets a pointer to the payload given a pointer to a udp header
806 * @param udp           The udp Header
807 * @param[in,out] remaining Updated with the number of bytes remaining
808 *
809 * @return a pointer to the udp payload, or NULL if the payload isn't present.
810 *
811 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
812 * of bytes captured of the TCP header and beyond.  It will be updated after this
813 * function to the number of bytes remaining after the TCP header (and any TCP options)
814 * have been removed.
815 *
816 * @note This is similar trace_get_transport_from_ip in libtrace2
817 */
818DLLEXPORT void *trace_get_payload_from_udp(libtrace_udp_t *udp, uint32_t *remaining);
819
820/** Gets a pointer to the payload given a pointer to a icmp header
821 * @param icmp          The icmp Header
822 * @param[in,out] remaining Updated with the number of bytes remaining
823 *
824 * @return a pointer to the icmp payload, or NULL if the payload isn't present.
825 *
826 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
827 * of bytes captured of the TCP header and beyond.  It will be updated after this
828 * function to the number of bytes remaining after the TCP header (and any TCP options)
829 * have been removed.
830 *
831 * @note This is similar to trace_get_payload_from_icmp in libtrace2
832 */
833DLLEXPORT void *trace_get_payload_from_icmp(libtrace_icmp_t *icmp, uint32_t *skipped);
834
835/** get a pointer to the TCP header (if any)
836 * @param packet        the packet opaque pointer
837 *
838 * @return a pointer to the TCP header, or NULL if there is not a TCP packet
839 */
840DLLEXPORT SIMPLE_FUNCTION
841libtrace_tcp_t *trace_get_tcp(libtrace_packet_t *packet);
842
843/** get a pointer to the TCP header (if any) given a pointer to the IP header
844 * @param ip            The IP header
845 * @param[in,out] remaining Updated with the number of bytes remaining
846 *
847 * @return a pointer to the TCP header, or NULL if this is not a TCP packet
848 *
849 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
850 * of bytes captured of the TCP header and beyond.  It will be updated after this
851 * function to the number of bytes remaining after the TCP header (and any TCP options)
852 * have been removed.
853 *
854 * @note The last parameter has changed from libtrace2
855 */
856DLLEXPORT SIMPLE_FUNCTION
857libtrace_tcp_t *trace_get_tcp_from_ip(libtrace_ip_t *ip, uint32_t *remaining);
858
859/** get a pointer to the UDP header (if any)
860 * @param packet        the packet opaque pointer
861 *
862 * @return a pointer to the UDP header, or NULL if this is not a UDP packet
863 */
864DLLEXPORT SIMPLE_FUNCTION
865libtrace_udp_t *trace_get_udp(libtrace_packet_t *packet);
866
867/** get a pointer to the UDP header (if any) given a pointer to the IP header
868 * @param       ip      The IP header
869 * @param[in,out] remaining Updated with the number of bytes remaining
870 *
871 * @return a pointer to the UDP header, or NULL if this is not an UDP packet
872 *
873 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
874 * of bytes captured of the TCP header and beyond.  It will be updated after this
875 * function to the number of bytes remaining after the TCP header (and any TCP options)
876 * have been removed.
877 *
878 * @note Beware the change from libtrace2 from skipped to remaining
879 */
880DLLEXPORT SIMPLE_FUNCTION
881libtrace_udp_t *trace_get_udp_from_ip(libtrace_ip_t *ip,uint32_t *remaining);
882
883/** get a pointer to the ICMP header (if any)
884 * @param packet        the packet opaque pointer
885 *
886 * @return a pointer to the ICMP header, or NULL if this is not a ICMP packet
887 */
888DLLEXPORT SIMPLE_FUNCTION
889libtrace_icmp_t *trace_get_icmp(libtrace_packet_t *packet);
890
891/** get a pointer to the ICMP header (if any) given a pointer to the IP header
892 * @param ip            The IP header
893 * @param[in,out] remaining Updated with the number of bytes remaining
894 *
895 * @return a pointer to the ICMP header, or NULL if this is not an ICMP packet
896 *
897 * Remaining may be NULL.  If Remaining is not NULL it must point to the number
898 * of bytes captured of the TCP header and beyond.  It will be updated after this
899 * function to the number of bytes remaining after the TCP header (and any TCP options)
900 * have been removed.
901 *
902 * @note Beware the change from libtrace2 from skipped to remaining
903 */
904DLLEXPORT SIMPLE_FUNCTION
905libtrace_icmp_t *trace_get_icmp_from_ip(libtrace_ip_t *ip,uint32_t *remaining);
906
907/** Get the destination MAC addres
908 * @param packet        the packet opaque pointer
909 * @return a pointer to the destination mac, (or NULL if there is no
910 * destination MAC)
911 */
912DLLEXPORT SIMPLE_FUNCTION
913uint8_t *trace_get_destination_mac(libtrace_packet_t *packet);
914
915/** Get the source MAC addres
916 * @param packet        the packet opaque pointer
917 * @return a pointer to the source mac, (or NULL if there is no source MAC)
918 */
919DLLEXPORT SIMPLE_FUNCTION
920uint8_t *trace_get_source_mac(libtrace_packet_t *packet);
921
922/** Get the source addres
923 * @param packet        the packet opaque pointer
924 * @param addr          a pointer to a sockaddr to store the address in, or NULL to use
925 *                      static storage.
926 * @return NULL if there is no source address, or a sockaddr holding a v4 or v6 address
927 */
928DLLEXPORT SIMPLE_FUNCTION
929struct sockaddr *trace_get_source_address(const libtrace_packet_t *packet,
930                struct sockaddr *addr);
931
932/** Get the source addres
933 * @param packet        the packet opaque pointer
934 * @param addr          a pointer to a sockaddr to store the address in, or NULL to use
935 *                      static storage.
936 * @return NULL if there is no source address, or a sockaddr holding a v4 or v6 address
937 */
938DLLEXPORT SIMPLE_FUNCTION
939struct sockaddr *trace_get_destination_address(const libtrace_packet_t *packet,
940                struct sockaddr *addr);
941
942/*@}*/
943
944/** parse an ip or tcp option
945 * @param[in,out] ptr   the pointer to the current option
946 * @param[in,out] len   the length of the remaining buffer
947 * @param[out] type     the type of the option
948 * @param[out] optlen   the length of the option
949 * @param[out] data     the data of the option
950 *
951 * @return bool true if there is another option (and the fields are filled in)
952 *               or false if this was the last option.
953 *
954 * This updates ptr to point to the next option after this one, and updates
955 * len to be the number of bytes remaining in the options area.  Type is updated
956 * to be the code of this option, and data points to the data of this option,
957 * with optlen saying how many bytes there are.
958 *
959 * @note Beware of fragmented packets.
960 */
961DLLEXPORT int trace_get_next_option(unsigned char **ptr,int *len,
962                        unsigned char *type,
963                        unsigned char *optlen,
964                        unsigned char **data);
965
966
967/** @name Time
968 * These functions deal with time that a packet arrived and return it
969 * in various formats
970 * @{
971 */
972/** Get the current time in DAG time format
973 * @param packet        the packet opaque pointer
974 *
975 * @return a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds
976 * past 1970-01-01, the lower 32bits are partial seconds)
977 * @author Daniel Lawson
978 */
979DLLEXPORT SIMPLE_FUNCTION
980uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet);
981
982/** Get the current time in struct timeval
983 * @param packet        the packet opaque pointer
984 *
985 * @return time that this packet was seen in a struct timeval
986 * @author Daniel Lawson
987 * @author Perry Lorier
988 */
989DLLEXPORT SIMPLE_FUNCTION
990struct timeval trace_get_timeval(const libtrace_packet_t *packet);
991
992/** Get the current time in floating point seconds
993 * @param packet        the packet opaque pointer
994 *
995 * @return time that this packet was seen in 64bit floating point seconds
996 * @author Daniel Lawson
997 * @author Perry Lorier
998 */
999DLLEXPORT SIMPLE_FUNCTION
1000double trace_get_seconds(const libtrace_packet_t *packet);
1001
1002/** Seek within a trace
1003 * @param trace         trace to seek
1004 * @param seconds       time to seek to
1005 * @return 0 on success.
1006 * Make the next packet read to be the first packet to occur at or after the
1007 * time searched for.  This must be called in the configuration state (ie,
1008 * before trace_start() or after trace_pause().
1009 * @note This function may be extremely slow.
1010 */
1011DLLEXPORT int trace_seek_seconds(libtrace_t *trace, double seconds);
1012
1013/** Seek within a trace
1014 * @param trace         trace to seek
1015 * @param tv            time to seek to
1016 * @return 0 on success.
1017 * Make the next packet read to be the first packet to occur at or after the
1018 * time searched for.  This must be called in the configuration state (ie,
1019 * before trace_start() or after trace_pause().
1020 * @note This function may be extremely slow.
1021 */
1022DLLEXPORT int trace_seek_timeval(libtrace_t *trace, struct timeval tv);
1023
1024/** Seek within a trace
1025 * @param trace         trace to seek
1026 * @param ts            erf timestamp
1027 * @return 0 on success.
1028 * Make the next packet read to be the first packet to occur at or after the
1029 * time searched for.  This must be called in the configuration state (ie,
1030 * before trace_start() or after trace_pause().
1031 * @note This function may be extremely slow.
1032 */
1033DLLEXPORT int trace_seek_erf_timestamp(libtrace_t *trace, uint64_t ts);
1034
1035/*@}*/
1036
1037/** @name Sizes
1038 * This section deals with finding or setting the various different lengths
1039 * a packet can have
1040 * @{
1041 */
1042/** Get the size of the packet in the trace
1043 * @param packet        the packet opaque pointer
1044 * @return the size of the packet in the trace
1045 * @author Perry Lorier
1046 * @note Due to this being a header capture, or anonymisation, this may not
1047 * be the same size as the original packet.  See get_wire_length() for the
1048 * original size of the packet.
1049 * @note This can (and often is) different for different packets in a trace!
1050 * @note This is sometimes called the "snaplen".
1051 * @note The return size refers to the network-level payload of the packet and
1052 * does not include any capture headers. For example, an Ethernet packet with
1053 * an empty TCP packet will return sizeof(ethernet_header) + sizeof(ip_header)
1054 * + sizeof(tcp_header).
1055 */
1056DLLEXPORT SIMPLE_FUNCTION
1057size_t trace_get_capture_length(const libtrace_packet_t *packet);
1058
1059/** Get the size of the packet as it was seen on the wire.
1060 * @param packet        the packet opaque pointer
1061 * @return the size of the packet as it was on the wire.
1062 * @note Due to the trace being a header capture, or anonymisation this may
1063 * not be the same as the Capture Len.
1064 * @note trace_getwire_length \em{includes} FCS.
1065 */
1066DLLEXPORT SIMPLE_FUNCTION
1067size_t trace_get_wire_length(const libtrace_packet_t *packet);
1068
1069/** Get the length of the capture framing headers.
1070 * @param packet        the packet opaque pointer
1071 * @return the size of the packet as it was on the wire.
1072 * @author Perry Lorier
1073 * @author Daniel Lawson
1074 * @note this length corresponds to the difference between the size of a
1075 * captured packet in memory, and the captured length of the packet
1076 */
1077DLLEXPORT SIMPLE_FUNCTION
1078size_t trace_get_framing_length(const libtrace_packet_t *packet);
1079
1080/** Truncate ("snap") the packet at the suggested length
1081 * @param packet        the packet opaque pointer
1082 * @param size          the new length of the packet
1083 * @return the new capture length of the packet, or the original capture
1084 * length of the packet if unchanged
1085 */
1086DLLEXPORT size_t trace_set_capture_length(libtrace_packet_t *packet, size_t size);
1087
1088/*@}*/
1089
1090
1091/** Get the type of the link layer
1092 * @param packet        the packet opaque pointer
1093 * @return libtrace_linktype_t
1094 * @author Perry Lorier
1095 * @author Daniel Lawson
1096 */
1097DLLEXPORT SIMPLE_FUNCTION
1098libtrace_linktype_t trace_get_link_type(const libtrace_packet_t *packet);
1099
1100/** Set the direction flag, if it has one
1101 * @param packet        the packet opaque pointer
1102 * @param direction     the new direction
1103 * @returns -1 on error, or the direction that was set.
1104 */
1105DLLEXPORT libtrace_direction_t trace_set_direction(libtrace_packet_t *packet, libtrace_direction_t direction);
1106
1107/** Get the direction flag, if it has one
1108 * @param packet        the packet opaque pointer
1109 * @return a value containing the direction flag, or -1 if this is not supported
1110 * The direction is defined as 0 for packets originating locally (ie, outbound)
1111 * and 1 for packets originating remotely (ie, inbound).
1112 * Other values are possible, which might be overloaded to mean special things
1113 * for a special trace.
1114 * @author Daniel Lawson
1115 */
1116DLLEXPORT SIMPLE_FUNCTION
1117libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet);
1118
1119/** @name BPF
1120 * This section deals with using Berkley Packet Filters
1121 * @{
1122 */
1123/** setup a BPF filter
1124 * @param filterstring a char * containing the bpf filter string
1125 * @return opaque pointer pointer to a libtrace_filter_t object
1126 * @author Daniel Lawson
1127 * @note The filter is not actually compiled at this point, so no correctness
1128 * tests are performed here. trace_bpf_setfilter will always return ok, but
1129 * if the filter is poorly constructed an error will be generated when the
1130 * filter is actually used
1131 */
1132DLLEXPORT SIMPLE_FUNCTION
1133libtrace_filter_t *trace_bpf_setfilter(const char *filterstring);
1134
1135/** apply a BPF filter
1136 * @param filter        the filter opaque pointer
1137 * @param packet        the packet opaque pointer
1138 * @return 1 if the filter matches, 0 if it doesn't.
1139 * @note Due to the way BPF filters are built, the filter is not actually
1140 * compiled until the first time trace_bpf_filter is called. If your filter is
1141 * incorrect, it will generate an error message and assert, exiting the
1142 * program. This behaviour may change to more graceful handling of this error
1143 * in the future.
1144 */
1145DLLEXPORT int trace_bpf_filter(libtrace_filter_t *filter,
1146                const libtrace_packet_t *packet);
1147
1148/** destory of BPF filter
1149 * @param filter        the filter opaque pointer
1150 * Deallocate all the resources associated with a BPF filter
1151 */
1152DLLEXPORT void trace_destroy_bpf(libtrace_filter_t *filter);
1153/*@}*/
1154
1155/** @name Portability
1156 * This section has functions that causes annoyances to portability for one
1157 * reason or another.
1158 * @{
1159 */
1160
1161/** Convert an ethernet address to a string
1162 * @param addr  Ethernet address in network byte order
1163 * @param buf   Buffer to store the ascii representation, or NULL
1164 * @return buf, or if buf is NULL then a statically allocated buffer.
1165 *
1166 * This function is similar to the GNU ether_ntoa_r function, with a few
1167 * minor differences.  if NULL is passed as buf, then the function will
1168 * use an internal static buffer, if NULL isn't passed then the function
1169 * will use that buffer instead.
1170 *
1171 * @note the type of addr isn't struct ether_addr as it is with ether_ntoa_r,
1172 * however it is bit compatible so that a cast will work.
1173 */
1174DLLEXPORT char *trace_ether_ntoa(const uint8_t *addr, char *buf);
1175
1176/** Convert a string to an ethernet address
1177 * @param buf   Ethernet address in hex format delimited with :'s.
1178 * @param addr  buffer to store the binary representation, or NULL
1179 * @return addr, or if addr is NULL, then a statically allocated buffer.
1180 *
1181 * This function is similar to the GNU ether_aton_r function, with a few
1182 * minor differences.  if NULL is passed as addr, then the function will
1183 * use an internal static buffer, if NULL isn't passed then the function will
1184 * use that buffer instead.
1185 *
1186 * @note the type of addr isn't struct ether_addr as it is with ether_aton_r,
1187 * however it is bit compatible so that a cast will work.
1188 */
1189DLLEXPORT uint8_t *trace_ether_aton(const char *buf, uint8_t *addr);
1190
1191/*@}*/
1192
1193
1194/** Which port is the server port */
1195typedef enum {
1196        USE_DEST,       /**< Destination port is the server port */
1197        USE_SOURCE      /**< Source port is the server port */
1198} serverport_t;
1199
1200/** Get the source port
1201 * @param packet        the packet to read from
1202 * @return a port in \em HOST byte order, or equivilent to ports for this
1203 * protocol, or 0 if this protocol has no ports.
1204 * @author Perry Lorier
1205 */
1206DLLEXPORT SIMPLE_FUNCTION
1207uint16_t trace_get_source_port(const libtrace_packet_t *packet);
1208
1209/** Get the destination port
1210 * @param packet        the packet to read from
1211 * @return a port in \em HOST byte order, or equivilent to ports for this
1212 * protocol, or 0 if this protocol has no ports.
1213 * @author Perry Lorier
1214 */
1215DLLEXPORT SIMPLE_FUNCTION
1216uint16_t trace_get_destination_port(const libtrace_packet_t *packet);
1217
1218/** hint at the server port in specified protocol
1219 * @param protocol      the IP layer protocol, eg 6 (tcp), 17 (udp)
1220 * @param source        the source port from the packet
1221 * @param dest          the destination port from the packet
1222 * @return one of USE_SOURCE or USE_DEST depending on which one you should use
1223 * @note ports must be in \em HOST byte order!
1224 * @author Daniel Lawson
1225 */
1226DLLEXPORT SIMPLE_FUNCTION
1227int8_t trace_get_server_port(uint8_t protocol, uint16_t source, uint16_t dest);
1228
1229/** Takes a uri and splits it into a format and uridata component.
1230 * Primarily for internal use but made available for external use.
1231 * @param uri           the uri to be parsed
1232 * @param format        destination location for the format component of the uri
1233 * @return 0 if an error occured, otherwise return the uridata component
1234 * @author Shane Alcock
1235 */
1236DLLEXPORT const char *trace_parse_uri(const char *uri, char **format);
1237
1238/** RT protocol base format identifiers
1239 * This is used to say what kind of packet is being sent over the rt protocol
1240 */
1241enum base_format_t {
1242        TRACE_FORMAT_ERF          =1,
1243        TRACE_FORMAT_PCAP         =2,
1244        TRACE_FORMAT_PCAPFILE     =3,
1245        TRACE_FORMAT_WAG          =4,
1246        TRACE_FORMAT_RT           =5,
1247        TRACE_FORMAT_LEGACY_ATM   =6,
1248        TRACE_FORMAT_LEGACY_POS   =7,
1249        TRACE_FORMAT_LEGACY_ETH   =8,
1250        TRACE_FORMAT_LINUX_NATIVE =9
1251};
1252
1253/** Gets the framing header type for a given packet.
1254 * @param packet        the packet opaque pointer
1255 * @return the format of the packet
1256 */
1257DLLEXPORT
1258enum base_format_t trace_get_format(struct libtrace_packet_t *packet);
1259
1260#ifdef __cplusplus
1261} /* extern "C" */
1262#endif /* #ifdef __cplusplus */
1263#endif /* LIBTRACE_H_ */
Note: See TracBrowser for help on using the repository browser.