source: lib/libtrace.h.in @ c0cd256

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

Remove old CONSTRUCTOR initialisation code, and only rely on the newer
trace_init() function.

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