source: lib/libtrace.h.in @ c2cb712

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

Fix missing ;

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