source: lib/libtrace_int.h @ 39e141f

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

Merge windows portability fixes

  • Property mode set to 100644
File size: 12.1 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$
28 *
29 */
30/** @file */
31
32#ifndef LIBTRACE_INT_H
33#define LIBTRACE_INT_H
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39#include "common.h"
40#include "config.h"
41#include "libtrace.h"
42
43#ifdef _MSC_VER
44#pragma warning(disable:4996)
45#endif
46
47#ifdef HAVE_INTTYPES_H
48# include <inttypes.h>
49#else
50# include "lt_inttypes.h"
51#endif
52
53#ifdef HAVE_STDDEF_H
54# include <stddef.h>
55#else
56#ifndef WIN32
57# error "Can't find stddev.h -- do you define ptrdiff_t elsewhere?"
58#endif
59#endif
60
61
62#include "fifo.h"
63#include "rt_protocol.h"
64       
65#if HAVE_PCAP_BPF_H
66#  include <pcap-bpf.h>
67#else
68#  ifdef HAVE_NET_BPF_H
69#    include <net/bpf.h>
70#  endif
71#endif
72
73#if HAVE_PCAP_H
74#  include <pcap.h>
75#  ifdef HAVE_PCAP_INT_H
76#    include <pcap-int.h>
77#  endif
78#endif
79
80#ifdef HAVE_ZLIB_H
81#  include <zlib.h>
82#endif
83
84#ifndef HAVE_STRNCASECMP
85# ifndef HAVE__STRNICMP
86int strncasecmp(const char *str1, const char *str2, size_t n);
87# else
88# define strncasecmp _strnicmp
89# endif
90#endif
91
92#ifndef HAVE_SNPRINTF
93# ifndef HAVE_SPRINTF_S
94int snprintf(char *str, size_t size, const char *format, ...);
95# else
96# define snprintf sprintf_s
97# endif
98#endif
99
100#include "wag.h"
101#include "daglegacy.h"
102       
103#ifdef HAVE_DAG_API
104#  include "dagnew.h"
105#  include "dagapi.h"
106#else
107#  include "dagformat.h"
108#endif
109
110#define RP_BUFSIZE 65536
111
112struct libtrace_event_status_t {
113        libtrace_packet_t *packet;
114        int psize;
115        double tdelta;
116        double trace_last_ts;
117};
118
119/** The information about traces that are open
120 * @internal
121 */
122struct libtrace_t {
123        struct libtrace_format_t *format; /**< format driver pointer */
124        void *format_data; /**<format data pointer */
125        bool started;                   /**< if this trace has started */
126        libtrace_err_t err;             /**< error information */
127        struct libtrace_event_status_t event;   /**< the next event */
128        char *uridata;                  /**< the uri of this trace */
129        struct tracefifo_t *fifo;       /**< fifo used in this trace */
130        struct libtrace_filter_t *filter; /**< used by libtrace if the module
131                                            * doesn't support filters natively
132                                            */
133        int snaplen;                    /**< used by libtrace if the module
134                                          * doesn't support snapping natively
135                                          */
136};
137
138/** Information about output traces
139 * @internal
140 */
141struct libtrace_out_t {
142        struct libtrace_format_t *format;       /**< format driver */
143        void *format_data;              /**< format data */
144        bool started;                   /**< trace started */
145        libtrace_err_t err;             /**< Associated error */
146        char *uridata;                  /**< URI associated with this trace */
147};
148
149void trace_set_err(libtrace_t *trace, int errcode,const char *msg,...);
150void trace_set_err_out(libtrace_out_t *trace, int errcode, const char *msg,...);
151
152typedef struct libtrace_sll_header_t {
153        uint16_t pkttype;               /* packet type */
154        uint16_t hatype;                /* link-layer address type */
155        uint16_t halen;                 /* link-layer address length */
156        char addr[8];                   /* link-layer address */
157        uint16_t protocol;              /* protocol */
158} libtrace_sll_header_t;
159
160#ifndef PF_RULESET_NAME_SIZE
161#define PF_RULESET_NAME_SIZE 16
162#endif
163
164#ifndef IFNAMSIZ
165#define IFNAMSIZ 16
166#endif
167
168typedef struct libtrace_pflog_header_t {
169        uint8_t    length;
170        sa_family_t   af;
171        uint8_t    action;
172        uint8_t    reason;
173        char       ifname[IFNAMSIZ];
174        char       ruleset[PF_RULESET_NAME_SIZE];
175        uint32_t   rulenr;
176        uint32_t   subrulenr;
177        uint8_t    dir;
178        uint8_t    pad[3];
179} libtrace_pflog_header_t;
180
181
182
183/** Module definition structure */
184/* all of these should return -1, or NULL on failure */
185struct libtrace_format_t {
186        /** the uri name of this module */
187        char *name;
188        /** the version of this module */
189        char *version;
190        /** the RT protocol type of this module */
191        enum base_format_t type;
192        /** stuff that deals with input @{ */
193        /** initialise an trace (or NULL if input is not supported) */
194        int (*init_input)(libtrace_t *libtrace);
195        /** configure an trace (or NULL if input is not supported) */
196        int (*config_input)(libtrace_t *libtrace,trace_option_t option,void *value);
197        /** start/unpause an trace (or NULL if input not supported) */
198        int (*start_input)(libtrace_t *libtrace);
199        /** pause an trace (or NULL if input not supported) */
200        int (*pause_input)(libtrace_t *libtrace);
201        /** @} */
202        /** stuff that deals with output @{ */
203        /** initialise output traces (or NULL if output not supported) */
204        int (*init_output)(libtrace_out_t *libtrace);
205        /** configure output traces (or NULL if output not supported) */
206        int (*config_output)(libtrace_out_t *libtrace, trace_option_output_t option, void *);
207        /** start output traces (or NULL if output not supported)
208         * There is no pause for output traces, as packets are not arriving
209         * asyncronously
210         */
211        int (*start_output)(libtrace_out_t *libtrace);
212        /** @} */
213        /** finish an input trace, cleanup (or NULL if input not supported)
214         * if the trace is not paused, libtrace will pause the trace before
215         * calling this function.
216         */
217        int (*fin_input)(libtrace_t *libtrace);
218        /** finish an output trace, cleanup (or NULL if output not supported) */
219        int (*fin_output)(libtrace_out_t *libtrace);
220        /** read a packet from a trace into the provided packet structure
221         * @returns -1 on error, or get_framing_length()+get_capture_length() \
222         * on success.
223         * if this function is not supported, this field may be NULL.
224         */
225        int (*read_packet)(libtrace_t *libtrace, libtrace_packet_t *packet);
226        /** finalise a packet
227         * cleanup any resources used by a packet that can't be reused for
228         * the next packet.
229         */
230        void (*fin_packet)(libtrace_packet_t *packet);
231        /** write a packet to a trace from the provided packet
232         * (or NULL if output not supported)
233         */
234        int (*write_packet)(libtrace_out_t *libtrace, const libtrace_packet_t *packet);
235        /** return the libtrace link type for this packet
236         * @return the libtrace link type, or -1 if this link type is unknown
237         */ 
238        libtrace_linktype_t (*get_link_type)(const libtrace_packet_t *packet);
239        /** return the direction of this packet
240         * @note This callback may be NULL if not supported.
241         */ 
242        int8_t (*get_direction)(const libtrace_packet_t *packet);
243        /** set the direction of this packet
244         * @note This callback may be NULL if not supported.
245         */ 
246        int8_t (*set_direction)(const libtrace_packet_t *packet, int8_t direction);
247        /** return the erf timestamp of the packet.
248         * @return the 64bit erf timestamp
249         * This field may be NULL in the structure, and libtrace will
250         * synthesise the result from get_timeval or get_seconds if they
251         * exist.  AT least one of get_erf_timestamp, get_timeval or
252         * get_seconds must be implemented.
253         */
254        uint64_t (*get_erf_timestamp)(const libtrace_packet_t *packet);
255        /** return the timeval of this packet.
256         * @return the timeval
257         * This field may be NULL in the structure, and libtrace will
258         * synthesise the result from get_erf_timestamp or get_seconds if they
259         * exist.  AT least one of get_erf_timestamp, get_timeval or
260         * get_seconds must be implemented.
261         */
262        struct timeval (*get_timeval)(const libtrace_packet_t *packet);
263        /** return the timestamp of this packet.
264         * @return the floating point seconds since 1970-01-01 00:00:00
265         * This field may be NULL in the structure, and libtrace will
266         * synthesise the result from get_timeval or get_erf_timestamp if they
267         * exist.  AT least one of get_erf_timestamp, get_timeval or
268         * get_seconds must be implemented.
269         */
270        double (*get_seconds)(const libtrace_packet_t *packet);
271        /** move the pointer within the trace.
272         * @return 0 on success, -1 on failure.
273         * The next packet returned by read_packet be the first
274         * packet in the trace to have a timestamp equal or greater than
275         * timestamp.
276         * @note this function may be NULL if the format does not support
277         * this feature.  If the format implements seek_timeval and/or
278         * seek_seconds then libtrace will call those functions instead.
279         */
280        int (*seek_erf)(libtrace_t *trace, uint64_t timestamp);
281        /** move the pointer within the trace.
282         * @return 0 on success, -1 on failure.
283         * The next packet returned by read_packet be the first
284         * packet in the trace to have a timestamp equal or greater than
285         * timestamp.
286         * @note this function may be NULL if the format does not support
287         * this feature.  If the format implements seek_erf and/or
288         * seek_seconds then libtrace will call those functions instead.
289         */
290        int (*seek_timeval)(libtrace_t *trace, struct timeval tv);
291        /** move the pointer within the trace.
292         * @return 0 on success, -1 on failure.
293         * The next packet returned by read_packet be the first
294         * packet in the trace to have a timestamp equal or greater than
295         * tv.
296         * @note this function may be NULL if the format does not support
297         * this feature.  If the format implements seek_erf and/or
298         * seek_timeval then libtrace will call those functions instead.
299         */
300        int (*seek_seconds)(libtrace_t *trace, double seconds);
301        /** return the captured payload length
302         * @return the amount of data captured in a trace.
303         * This is the number of bytes actually in the trace.  This does not
304         * include the trace framing length.  This is usually shorter or
305         * equal to the wire length.
306         */
307        int (*get_capture_length)(const libtrace_packet_t *packet);
308        /** return the original length of the packet on the wire.
309         * @return the length of the packet on the wire before truncation.
310         * This is the number of bytes actually in the trace.  This does not
311         * include the trace framing length.  This is usually shorter or
312         * equal to the wire length.
313         */
314        int (*get_wire_length)(const libtrace_packet_t *packet);
315        /** return the length of the trace framing header
316         * @return the length of the framing header
317         * The framing header is the extra metadata a trace stores about
318         * a packet.  This does not include the wire or capture length
319         * of the packet.  Usually get_framing_length()+get_capture_length()
320         * is the size returned by read_packet
321         */
322        int (*get_framing_length)(const libtrace_packet_t *packet);
323        /** truncate (snap) the packet
324         * @returns the new size
325         * @note This callback may be NULL if not supported.
326         */
327        size_t (*set_capture_length)(struct libtrace_packet_t *packet,size_t size);
328        /** return the filedescriptor associated with this interface.
329         * @note This callback may be NULL if not supported.
330         * This function is only needed if you use trace_event_interface
331         * as the pointer for trace_event
332         */
333        int (*get_fd)(const libtrace_t *trace);
334        /** return the next event from this source
335         * @note may be NULL if not supported.
336         */
337        struct libtrace_eventobj_t (*trace_event)(libtrace_t *trace, libtrace_packet_t *packet);       
338        /** return information about this trace format to standard out */
339        void (*help)();
340        /** next pointer, should be NULL */
341        struct libtrace_format_t *next;
342};
343
344extern struct libtrace_format_t *form;
345
346void register_format(struct libtrace_format_t *format);
347
348libtrace_linktype_t pcap_dlt_to_libtrace(int dlt);
349char libtrace_to_pcap_dlt(libtrace_linktype_t type);
350enum rt_field_t pcap_dlt_to_rt(int dlt);
351int rt_to_pcap_dlt(enum rt_field_t rt_type);
352libtrace_linktype_t erf_type_to_libtrace(char erf);
353char libtrace_to_erf_type(libtrace_linktype_t linktype);
354
355#if HAVE_BPF
356/* A type encapsulating a bpf filter
357 * This type covers the compiled bpf filter, as well as the original filter
358 * string
359 *
360 */
361struct libtrace_filter_t {
362        struct bpf_program filter;
363        int flag;
364        char * filterstring;
365};
366#endif
367       
368#ifdef __cplusplus
369}
370#endif
371
372#endif /* LIBTRACE_INT_H */
Note: See TracBrowser for help on using the repository browser.