2 * Definitions for file structures and routines
4 * $Id: file.h,v 1.49 1999/10/11 06:39:03 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
34 #include "wiretap/wtap.h"
57 #define file_open gzopen
58 #define filed_open gzdopen
59 #define file_seek gzseek
60 #define file_read(buf, bsize, count, file) gzread((file),(buf),((count)*(bsize)))
61 #define file_write(buf, bsize, count, file) gzwrite((file),(buf),((count)*(bsize)))
62 #define file_close gzclose
63 static inline int file_error(void *fh) {
66 if (errnum<0) return errnum;
72 #define file_open fopen
73 #define filed_open fdopen
74 #define file_seek fseek
75 #define file_read fread
76 #define file_write fwrite
77 #define file_close fclose
78 #define file_error ferror
79 #endif /* HAVE_LIBZ */
81 typedef struct bpf_program bpf_prog;
83 typedef struct _capture_file {
84 FILE_T fh; /* Capture file */
85 int filed; /* Filedes of capture file */
86 gchar *filename; /* filename */
87 long f_len; /* File length */
88 guint16 cd_t; /* Capture data type */
89 const gchar *cd_t_desc; /* Description of that data type */
90 guint32 vers; /* Version. For tcpdump minor is appended to major */
91 guint32 count; /* Packet count */
92 gfloat unfiltered_count; /* used for dfilter progress bar */
93 guint32 drops; /* Dropped packets */
94 guint32 esec; /* Elapsed seconds */
95 guint32 eusec; /* Elapsed microseconds */
96 guint32 snap; /* Captured packet length */
97 gboolean update_progbar; /* TRUE if we should update the progress bar */
98 long progbar_quantum; /* Number of bytes read per progress bar update */
99 long progbar_nextstep; /* Next point at which to update progress bar */
100 gchar *iface; /* Interface */
101 gchar *save_file; /* File that user saved capture to */
102 int save_file_fd; /* File descriptor for saved file */
103 gint user_saved;/* Was capture file saved by user yet? */
104 wtap *wth; /* Wiretap session */
105 dfilter *rfcode; /* Compiled read filter program */
106 gchar *dfilter; /* Display filter string */
107 colfilter *colors; /* Colors for colorizing packet window */
108 dfilter *dfcode; /* Compiled display filter program */
110 gchar *cfilter; /* Capture filter string */
111 bpf_prog fcode; /* Compiled capture filter program */
113 guint8 pd[WTAP_MAX_PACKET_SIZE]; /* Packet data */
114 frame_data *plist; /* Packet list */
115 frame_data *plist_end; /* Last packet in list */
116 column_info cinfo; /* Column formatting information */
117 int selected_packet; /* Index in packet list of currently selected packet, if any */
118 int selected_row; /* Row in packet display of currently selected packet, if any */
119 frame_data *fd; /* Frame data for currently selected packet */
120 proto_tree *protocol_tree; /* Protocol tree for currently selected packet */
121 FILE *print_fh; /* File we're printing to */
124 int open_cap_file(char *, capture_file *);
125 void close_cap_file(capture_file *, void *, guint);
126 int read_cap_file(capture_file *);
127 int tail_cap_file(char *, capture_file *);
128 /* size_t read_frame_header(capture_file *); */
130 void filter_packets(capture_file *cf, gchar *dfilter);
131 void colorize_packets(capture_file *);
132 int print_packets(capture_file *cf, print_args_t *print_args);
133 void change_time_formats(capture_file *);
134 void select_packet(capture_file *, int);
135 void unselect_packet(capture_file *);
137 /* Moves or copies a file. Returns 0 on failure, 1 on success */
138 int file_mv(char *from, char *to);
140 /* Copies a file. Returns 0 on failure, 1 on success */
141 int file_cp(char *from, char *to);
143 char *file_open_error_message(int, int);
144 char *file_read_error_message(int);
145 char *file_write_error_message(int);