source: lib/format.h @ 4dedc28

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 4dedc28 was 4dedc28, checked in by Daniel Lawson <dlawson@…>, 15 years ago

isplit input formats out

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * This file is part of libtrace
3 *
4 * Copyright (c) 2004 The University of Waikato, Hamilton, New Zealand.
5 * Authors: Daniel Lawson
6 *          Perry Lorier
7 *         
8 * All rights reserved.
9 *
10 * This code has been developed by the University of Waikato WAND
11 * research group. For further information please see http://www.wand.net.nz/
12 *
13 * libtrace is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * libtrace is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with libtrace; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 *
27 * $Id$
28 *
29 */
30
31#ifndef FORMAT_H
32#define FORMAT_H
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#include "common.h"
39#include "config.h"
40#include "libtrace.h"
41#include "fifo.h"
42
43#if HAVE_PCAP_BPF_H
44#  include <pcap-bpf.h>
45#else
46#  ifdef HAVE_NET_BPF_H
47#    include <net/bpf.h>
48#  endif
49#endif
50
51#if HAVE_PCAP_H
52#  include <pcap.h>
53#  ifdef HAVE_PCAP_INT_H
54#    include <pcap-int.h>
55#  endif
56#endif
57
58#ifdef HAVE_ZLIB_H
59#  include <zlib.h>
60#endif
61
62
63#include "wag.h"
64
65#ifdef HAVE_DAG_API
66#  include "dagnew.h"
67#  include "dagapi.h"
68#else
69#  include "dagformat.h"
70#endif
71
72typedef enum {SOCKET, TRACE, STDIN, DEVICE, INTERFACE, RT } source_t;
73
74#define RP_BUFSIZE 65536
75
76/** The information about traces that are open
77 * @internal
78 */
79struct libtrace_t {
80        struct format_t *format; /**< format driver pointer */
81        source_t sourcetype;    /**< The type (device,file, etc */
82
83        union {
84                /** Information about rtclients */
85                struct {
86                        char *hostname;
87                        short port;
88                } rt;
89                char *path;             /**< information for local sockets */
90                char *interface;        /**< intormation for reading of network
91                                             interfaces */
92        } conn_info;
93        /** Information about the current state of the input device */
94        union {
95                int fd;
96#if HAVE_ZLIB
97                gzFile *file;
98#else   
99                FILE *file;
100#endif
101#if HAVE_PCAP
102                pcap_t *pcap;
103#endif
104        } input;
105
106        struct fifo_t *fifo;   
107        struct {
108                void *buf; 
109                unsigned bottom;
110                unsigned top;
111                unsigned diff;
112                unsigned curr;
113                unsigned offset;
114        } dag;
115        struct {
116                void *buffer;
117                int size;
118        } packet;
119        double tdelta;
120        double trace_start_ts;
121        double real_start_ts;
122        double trace_last_ts;
123
124        double last_ts;
125        double start_ts;
126};
127
128struct trace_sll_header_t {
129        uint16_t pkttype;               /* packet type */
130        uint16_t hatype;                /* link-layer address type */
131        uint16_t halen;                 /* link-layer address length */
132        char addr[8];                   /* link-layer address */
133        uint16_t protocol;              /* protocol */
134};
135
136#ifndef PF_RULESET_NAME_SIZE
137#define PF_RULESET_NAME_SIZE 16
138#endif
139
140#ifndef IFNAMSIZ
141#define IFNAMSIZ 16
142#endif
143
144struct trace_pflog_header_t {
145        uint8_t    length;
146        sa_family_t   af;
147        uint8_t    action;
148        uint8_t    reason;
149        char       ifname[IFNAMSIZ];
150        char       ruleset[PF_RULESET_NAME_SIZE];
151        uint32_t   rulenr;
152        uint32_t   subrulenr;
153        uint8_t    dir;
154        uint8_t    pad[3];
155};
156
157struct format_t {
158        char *name;
159        char *version;
160        int (*init_input)(struct libtrace_t *libtrace);
161        int (*init_output)(struct libtrace_out_t *libtrace);
162        int (*fin_input)(struct libtrace_t *libtrace);
163        int (*read)(struct libtrace_t *libtrace, void *buffer, size_t len);
164        int (*read_packet)(struct libtrace_t *libtrace, struct libtrace_packet_t *packet);
165        int (*write_packet)(struct libtrace_out_t *libtrace, struct libtrace_packet_t *packet);
166        void* (*get_link)(const struct libtrace_packet_t *packet);
167        libtrace_linktype_t (*get_link_type)(const struct libtrace_packet_t *packet);
168        int8_t (*get_direction)(const struct libtrace_packet_t *packet);
169        int8_t (*set_direction)(const struct libtrace_packet_t *packet, int8_t direction);
170        uint64_t (*get_erf_timestamp)(const struct libtrace_packet_t *packet);
171        struct timeval (*get_timeval)(const struct libtrace_packet_t *packet);
172        double (*get_seconds)(const struct libtrace_packet_t *packet);
173        int (*get_capture_length)(const struct libtrace_packet_t *packet);
174        int (*get_wire_length)(const struct libtrace_packet_t *packet);
175        size_t (*truncate_packet)(const struct libtrace_packet_t *packet,size_t size);
176};
177
178extern struct format_t *form;
179
180void register_format(struct format_t *format);
181       
182#ifdef __cplusplus
183}
184#endif
185
186#endif // FORMAT_H
Note: See TracBrowser for help on using the repository browser.