Replace the types from sys/types.h and netinet/in.h by their glib.h
[obnox/wireshark/wip.git] / file.h
1 /* file.h
2  * Definitions for file structures and routines
3  *
4  * $Id: file.h,v 1.96 2002/08/02 23:35:46 jmayer Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  * 
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  * 
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifndef __FILE_H__
26 #define __FILE_H__
27
28 #include "wiretap/wtap.h"
29 #include <epan/dfilter/dfilter.h>
30 #include "print.h"
31 #include <errno.h>
32 #include <epan/epan.h>
33
34 /* Current state of file. */
35 typedef enum {
36         FILE_CLOSED,            /* No file open */
37         FILE_READ_IN_PROGRESS,  /* Reading a file we've opened */
38         FILE_READ_ABORTED,      /* Read aborted by user */
39         FILE_READ_DONE          /* Read completed */
40 } file_state;
41
42 typedef struct _capture_file {
43   file_state   state;     /* Current state of capture file */
44   int          filed;     /* File descriptor of capture file */
45   gchar       *filename;  /* Name of capture file */
46   gboolean     is_tempfile; /* Is capture file a temporary file? */
47   gboolean     user_saved;/* If capture file is temporary, has it been saved by user yet? */
48   long         f_len;     /* Length of capture file */
49   guint16      cd_t;      /* File type of capture file */
50   int          lnk_t;     /* Link-layer type with which to save capture */
51   guint32      vers;      /* Version.  For tcpdump minor is appended to major */
52   int          count;     /* Total number of frames */
53   int          marked_count; /* Number of marked frames */
54   gboolean     drops_known; /* TRUE if we know how many packets were dropped */
55   guint32      drops;     /* Dropped packets */
56   guint32      esec;      /* Elapsed seconds */
57   guint32      eusec;     /* Elapsed microseconds */
58   gboolean     has_snap;  /* TRUE if maximum capture packet length is known */
59   int          snap;      /* Maximum captured packet length */
60   long         progbar_quantum; /* Number of bytes read per progress bar update */
61   long         progbar_nextstep; /* Next point at which to update progress bar */
62   gchar       *iface;     /* Interface */
63   gchar       *save_file; /* File that user saved capture to */
64   int          save_file_fd; /* File descriptor for saved file */
65   wtap        *wth;       /* Wiretap session */
66   dfilter_t   *rfcode;    /* Compiled read filter program */ 
67   gchar       *dfilter;   /* Display filter string */
68   dfilter_t   *dfcode;    /* Compiled display filter program */ 
69 #ifdef HAVE_LIBPCAP
70   gchar       *cfilter;   /* Capture filter string */
71 #endif
72   gchar       *sfilter;   /* Search filter string */
73   gboolean     sbackward;  /* TRUE if search is backward, FALSE if forward */
74   union wtap_pseudo_header pseudo_header;      /* Packet pseudo_header */
75   guint8       pd[WTAP_MAX_PACKET_SIZE];  /* Packet data */
76   GMemChunk   *plist_chunk; /* Memory chunk for frame_data structures */
77   frame_data  *plist;     /* Packet list */
78   frame_data  *plist_end; /* Last packet in list */
79   frame_data  *first_displayed; /* First frame displayed */
80   frame_data  *last_displayed;  /* Last frame displayed */
81   column_info  cinfo;    /* Column formatting information */
82   frame_data  *current_frame;  /* Frame data for current frame */
83   epan_dissect_t *edt; /* Protocol dissection fo rcurrently selected packet */
84   FILE        *print_fh;  /* File we're printing to */
85 } capture_file;
86
87 /* Return values from "read_cap_file()", "continue_tail_cap_file()",
88    and "finish_tail_cap_file()". */
89 typedef enum {
90         READ_SUCCESS,   /* read succeeded */
91         READ_ERROR,     /* read got an error */
92         READ_ABORTED    /* read aborted by user */
93 } read_status_t;
94
95 int  open_cap_file(char *, gboolean, capture_file *);
96 void close_cap_file(capture_file *);
97 read_status_t read_cap_file(capture_file *, int *);
98 int  start_tail_cap_file(char *, gboolean, capture_file *);
99 read_status_t continue_tail_cap_file(capture_file *, int, int *);
100 read_status_t finish_tail_cap_file(capture_file *, int *);
101 /* size_t read_frame_header(capture_file *); */
102 gboolean save_cap_file(char *, capture_file *, gboolean, gboolean, guint);
103
104 int filter_packets(capture_file *cf, gchar *dfilter);
105 void colorize_packets(capture_file *);
106 void redissect_packets(capture_file *cf);
107 int print_packets(capture_file *cf, print_args_t *print_args);
108 void change_time_formats(capture_file *);
109 gboolean find_packet(capture_file *cf, dfilter_t *sfcode);
110
111 typedef enum {
112   FOUND_FRAME,          /* found the frame */
113   NO_SUCH_FRAME,        /* no frame with that number */
114   FRAME_NOT_DISPLAYED   /* frame with that number isn't displayed */
115 } goto_result_t;
116 goto_result_t goto_frame(capture_file *cf, guint fnumber);
117
118 void select_packet(capture_file *, int);
119 void unselect_packet(capture_file *);
120
121 void unselect_field(void);
122
123 /*
124  * Mark a particular frame in a particular capture.
125  */
126 void mark_frame(capture_file *, frame_data *);
127
128 /*
129  * Unmark a particular frame in a particular capture.
130  */
131 void unmark_frame(capture_file *, frame_data *);
132
133 /* Moves or copies a file. Returns 0 on failure, 1 on success */
134 int file_mv(char *from, char *to);
135
136 /* Copies a file. Returns 0 on failure, 1 on success */
137 int file_cp(char *from, char *to);
138
139 char *file_open_error_message(int, gboolean, int);
140 char *file_read_error_message(int);
141 char *file_write_error_message(int);
142
143 #endif /* file.h */