Add support to wiretap for reading Sun "snoop" capture files.
[obnox/wireshark/wip.git] / file.h
1 /* file.h
2  * Definitions for file structures and routines
3  *
4  * $Id: file.h,v 1.6 1998/11/15 05:29:01 guy 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 #include <sys/types.h>
30 #include <sys/time.h>
31
32 #ifdef WITH_WIRETAP
33  #include <wtap.h>
34  #include <pcap.h>
35 #else
36  #include <pcap.h>
37
38   /* Data file formats */
39   #define CD_UNKNOWN    0
40   #define CD_WIRE       1
41   #define CD_SNOOP      2
42   #define CD_PCAP_BE    3
43   #define CD_PCAP_LE    4
44   #define CD_NA_UNCOMPR 5
45
46   /* Data file magic info */
47   #define SNOOP_MAGIC_1 0x736e6f6f /* 'snoop' in ASCII */
48   #define SNOOP_MAGIC_2 0x70000000
49   #define PCAP_MAGIC    0xa1b2c3d4
50
51   /* Data file format versions we can handle */
52   #define SNOOP_MIN_VERSION 2
53   #define SNOOP_MAX_VERSION 2
54
55   /* Link types (removed in favor of the DLT_* defines from bpf.h */
56 #endif
57
58 typedef struct bpf_program bpf_prog;
59
60 typedef struct _capture_file {
61   FILE       *fh;        /* Capture file */
62   gchar      *filename;  /* filename */
63   long        f_len;     /* File length */
64   int         swap;      /* Swap data bytes? */
65   guint16     cd_t;      /* Capture data type */
66   guint32     vers;      /* Version.  For tcpdump minor is appended to major */
67   guint32     lnk_t;     /* Network link type */
68   guint32     count;     /* Packet count */
69   guint32     drops;     /* Dropped packets */
70   guint32     esec;      /* Elapsed seconds */
71   guint32     eusec;     /* Elapsed microseconds */
72   guint32     snap;      /* Captured packet length */
73   gchar      *iface;     /* Interface */
74   gchar      *save_file; /* File to write capture data */
75 #ifdef WITH_WIRETAP
76   wtap     *wth;       /* Wiretap session */
77 #else
78   pcap_t     *pfh;       /* Pcap session */
79 #endif
80   gchar      *dfilter;   /* Display filter string */
81   gchar      *cfilter;   /* Capture filter string */
82   bpf_prog    fcode;     /* Compiled filter program */
83   guint8      pd[4096];  /* Packet data */
84   GList      *plist;     /* Packet list */
85   frame_data *cur;       /* Current list item */
86 } capture_file;
87
88 /* Taken from RFC 1761 */
89
90 typedef struct _snoop_file_hdr {
91   guint32 magic1;
92   guint32 magic2;
93   guint32 vers;
94   guint32 s_lnk_t;
95 } snoop_file_hdr;
96
97 typedef struct _snoop_frame_hdr {
98   guint32 orig_len;
99   guint32 inc_len;
100   guint32 pr_len;
101   guint32 drops;
102   guint32 secs;
103   guint32 usecs;
104 } snoop_frame_hdr;
105
106 int  open_cap_file(char *, capture_file *);
107 void close_cap_file(capture_file *, GtkWidget *, guint);
108 int  load_cap_file(char *, capture_file *);
109 /* size_t read_frame_header(capture_file *); */
110
111 #endif /* file.h */