source: lib/libtrace.h.in @ 77285d9

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

OpenBSD compatibility fixes - adding in various #defines and #includes that are needed to compile under OpenBSD
Added a replacement pcap_next_ex function for systems that aren't running pcap-0.8 or better

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