Add a new "prefs_register_protocol()" routine, which is like
[obnox/wireshark/wip.git] / file.h
1 /* file.h
2  * Definitions for file structures and routines
3  *
4  * $Id: file.h,v 1.78 2000/10/20 04:26:38 gram Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@zing.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * 
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.
15  * 
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.
20  * 
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.
24  */
25
26 #ifndef __FILE_H__
27 #define __FILE_H__
28
29 #ifdef HAVE_SYS_TYPES_H
30 #include <sys/types.h>
31 #endif
32
33 #include "wiretap/wtap.h"
34
35 #ifdef HAVE_LIBPCAP
36 #include <pcap.h>
37 #endif
38
39 #include "dfilter.h"
40 #include "print.h"
41
42 #include <errno.h>
43
44 #include <epan.h>
45
46 #ifdef HAVE_LIBZ
47 #include "zlib.h"
48 #define FILE_T gzFile
49 #define file_open gzopen
50 #define filed_open gzdopen
51 #define file_close gzclose
52 #else /* No zLib */
53 #define FILE_T FILE *
54 #define file_open fopen
55 #define filed_open fdopen
56 #define file_close fclose
57 #endif /* HAVE_LIBZ */
58
59 typedef struct bpf_program bpf_prog;
60
61 /* Current state of file. */
62 typedef enum {
63         FILE_CLOSED,            /* No file open */
64         FILE_READ_IN_PROGRESS,  /* Reading a file we've opened */
65         FILE_READ_ABORTED,      /* Read aborted by user */
66         FILE_READ_DONE          /* Read completed */
67 } file_state;
68
69 typedef struct _capture_file {
70   file_state   state;     /* Current state of capture file */
71   int          filed;     /* File descriptor of capture file */
72   gchar       *filename;  /* Name of capture file */
73   gboolean     is_tempfile; /* Is capture file a temporary file? */
74   gboolean     user_saved;/* If capture file is temporary, has it been saved by user yet? */
75   long         f_len;     /* Length of capture file */
76   guint16      cd_t;      /* File type of capture file */
77   int          lnk_t;     /* Link-layer type with which to save capture */
78   guint32      vers;      /* Version.  For tcpdump minor is appended to major */
79   guint32      count;     /* Packet count */
80   guint32      drops;     /* Dropped packets */
81   guint32      esec;      /* Elapsed seconds */
82   guint32      eusec;     /* Elapsed microseconds */
83   guint32      snap;      /* Captured packet length */
84   long         progbar_quantum; /* Number of bytes read per progress bar update */
85   long         progbar_nextstep; /* Next point at which to update progress bar */
86   gchar       *iface;     /* Interface */
87   gchar       *save_file; /* File that user saved capture to */
88   int          save_file_fd; /* File descriptor for saved file */
89   wtap        *wth;       /* Wiretap session */
90   dfilter     *rfcode;    /* Compiled read filter program */ 
91   gchar       *dfilter;   /* Display filter string */
92   struct _colfilter   *colors;    /* Colors for colorizing packet window */
93   dfilter     *dfcode;    /* Compiled display filter program */ 
94 #ifdef HAVE_LIBPCAP
95   gchar       *cfilter;   /* Capture filter string */
96   bpf_prog     fcode;     /* Compiled capture filter program */
97 #endif
98   gchar       *sfilter;   /* Search filter string */
99   gboolean     sbackward;  /* TRUE if search is backward, FALSE if forward */
100   union wtap_pseudo_header pseudo_header;      /* Packet pseudo_header */
101   guint8       pd[WTAP_MAX_PACKET_SIZE];  /* Packet data */
102   GMemChunk   *plist_chunk; /* Memory chunk for frame_data structures */
103   frame_data  *plist;     /* Packet list */
104   frame_data  *plist_end; /* Last packet in list */
105   frame_data  *first_displayed; /* First frame displayed */
106   frame_data  *last_displayed;  /* Last frame displayed */
107   column_info  cinfo;    /* Column formatting information */
108   frame_data  *current_frame;  /* Frame data for current frame */
109   proto_tree  *protocol_tree; /* Protocol tree for currently selected packet */
110   epan_dissect_t *edt; /* Protocol dissection fo rcurrently selected packet */
111   FILE        *print_fh;  /* File we're printing to */
112 } capture_file;
113
114 /* Return values from "read_cap_file()", "continue_tail_cap_file()",
115    and "finish_tail_cap_file()". */
116 typedef enum {
117         READ_SUCCESS,   /* read succeeded */
118         READ_ERROR,     /* read got an error */
119         READ_ABORTED    /* read aborted by user */
120 } read_status_t;
121
122 int  open_cap_file(char *, gboolean, capture_file *);
123 void close_cap_file(capture_file *, void *);
124 read_status_t read_cap_file(capture_file *, int *);
125 int  start_tail_cap_file(char *, gboolean, capture_file *);
126 read_status_t continue_tail_cap_file(capture_file *, int, int *);
127 read_status_t finish_tail_cap_file(capture_file *, int *);
128 /* size_t read_frame_header(capture_file *); */
129 int  save_cap_file(char *, capture_file *, gboolean, gboolean, guint);
130
131 int filter_packets(capture_file *cf, gchar *dfilter);
132 void colorize_packets(capture_file *);
133 void redissect_packets(capture_file *cf);
134 int print_packets(capture_file *cf, print_args_t *print_args);
135 void change_time_formats(capture_file *);
136 gboolean find_packet(capture_file *cf, dfilter *sfcode);
137
138 typedef enum {
139   FOUND_FRAME,          /* found the frame */
140   NO_SUCH_FRAME,        /* no frame with that number */
141   FRAME_NOT_DISPLAYED   /* frame with that number isn't displayed */
142 } goto_result_t;
143 goto_result_t goto_frame(capture_file *cf, guint fnumber);
144
145 void select_packet(capture_file *, int);
146 void unselect_packet(capture_file *);
147
148 /* Moves or copies a file. Returns 0 on failure, 1 on success */
149 int file_mv(char *from, char *to);
150
151 /* Copies a file. Returns 0 on failure, 1 on success */
152 int file_cp(char *from, char *to);
153
154 char *file_open_error_message(int, gboolean);
155 char *file_read_error_message(int);
156 char *file_write_error_message(int);
157
158 #endif /* file.h */