Added support for compiling on win32 with Visual C and 'nmake'. It compiles,
[obnox/wireshark/wip.git] / wiretap / wtap.h
1 /* wtap.h
2  *
3  * $Id: wtap.h,v 1.20 1999/07/13 02:53:26 gram Exp $
4  *
5  * Wiretap Library
6  * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
7  * 
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  */
23
24 #ifndef __WTAP_H__
25 #define __WTAP_H__
26
27 /* Encapsulation types. Choose names that truly reflect
28  * what is contained in the packet trace file. */
29 #define WTAP_ENCAP_NONE                         0
30 #define WTAP_ENCAP_ETHERNET                     1
31 #define WTAP_ENCAP_TR                           2
32 #define WTAP_ENCAP_SLIP                         3
33 #define WTAP_ENCAP_PPP                          4
34 #define WTAP_ENCAP_FDDI                         5
35 #define WTAP_ENCAP_RAW_IP                       6
36 #define WTAP_ENCAP_ARCNET                       7
37 #define WTAP_ENCAP_ATM_RFC1483                  8
38
39 /* last WTAP_ENCAP_ value + 1 */
40 #define WTAP_NUM_ENCAP_TYPES                    9
41
42 /* File types that can be read by wiretap */
43 #define WTAP_FILE_UNKNOWN                       0
44 #define WTAP_FILE_WTAP                          1
45 #define WTAP_FILE_PCAP                          2
46 #define WTAP_FILE_LANALYZER                     3
47 #define WTAP_FILE_NGSNIFFER                     4
48 #define WTAP_FILE_SNOOP                         6
49 #define WTAP_FILE_IPTRACE                       7
50 #define WTAP_FILE_NETMON                        8
51 #define WTAP_FILE_NETXRAY                       9
52
53 /* Filter types that wiretap can create. An 'offline' filter is really
54  * a BPF filter, but it is treated specially because wiretap might not know
55  * in advance the datalink type(s) needed.
56  */
57 #define WTAP_FILTER_NONE                        0
58 #define WTAP_FILTER_OFFLINE                     1
59 #define WTAP_FILTER_BPF                         2
60
61 #include <sys/types.h>
62
63 #ifdef HAVE_SYS_TIME_H
64 #include <sys/time.h>
65 #endif
66
67 #ifdef HAVE_WINSOCK_H
68 #include <winsock.h>
69 #endif
70
71 #include <glib.h>
72 #include <stdio.h>
73
74 typedef struct {
75         double  timeunit;
76         time_t  start;
77         guint16 pkt_len;
78         guint16 size;
79         guint16 true_size;
80         double  t;
81         int     is_atm;
82 } ngsniffer_t;
83
84 typedef struct {
85         guint16 pkt_len;
86         guint32 totpktt;
87         time_t  start;
88 } lanalyzer_t;
89
90 typedef struct {
91         int     byte_swapped;
92         guint16 version_major;
93         guint16 version_minor;
94 } libpcap_t;
95
96 typedef struct {
97         time_t  start_secs;
98         guint32 start_usecs;
99         guint8  version_major;
100         int     end_offset;
101 } netmon_t;
102
103 typedef struct {
104         time_t  start_time;
105         double  timeunit;
106         double  start_timestamp;
107         int     wrapped;
108         int     end_offset;
109         int     version_major;
110 } netxray_t;
111
112 struct wtap_pkthdr {
113         struct timeval ts;
114         guint32 caplen;
115         guint32 len;
116         int pkt_encap;
117 };
118
119 typedef void (*wtap_handler)(u_char*, const struct wtap_pkthdr*,
120                 int, const u_char *);
121
122 struct wtap;
123 struct bpf_instruction;
124 struct Buffer;
125
126 typedef int (*subtype_func)(struct wtap*);
127 typedef struct wtap {
128         FILE*                   fh;
129         int                     file_type;
130         int                     snapshot_length;
131         struct Buffer           *frame_buffer;
132         struct wtap_pkthdr      phdr;
133
134         union {
135                 libpcap_t               *pcap;
136                 lanalyzer_t             *lanalyzer;
137                 ngsniffer_t             *ngsniffer;
138                 netmon_t                *netmon;
139                 netxray_t               *netxray;
140         } capture;
141
142         subtype_func            subtype_read;
143         int                     file_encap;     /* per-file, for those
144                                                    file formats that have
145                                                    per-file encapsulation
146                                                    types */
147 } wtap;
148
149
150 wtap* wtap_open_offline(char *filename);
151 void wtap_loop(wtap *wth, int, wtap_handler, u_char*);
152
153 FILE* wtap_file(wtap *wth);
154 int wtap_snapshot_length(wtap *wth); /* per file */
155 int wtap_file_type(wtap *wth);
156 void wtap_close(wtap *wth);
157
158
159 /* Pointer versions of ntohs and ntohl.  Given a pointer to a member of a
160  * byte array, returns the value of the two or four bytes at the pointer.
161  * The pletoh[sl] versions return the little-endian representation.
162  */
163
164 #ifndef pntohs
165 #define pntohs(p)  ((guint16)                       \
166                     ((guint16)*((guint8 *)p+0)<<8|  \
167                      (guint16)*((guint8 *)p+1)<<0))
168 #endif
169
170 #ifndef pntohl
171 #define pntohl(p)  ((guint32)*((guint8 *)p+0)<<24|  \
172                     (guint32)*((guint8 *)p+1)<<16|  \
173                     (guint32)*((guint8 *)p+2)<<8|   \
174                     (guint32)*((guint8 *)p+3)<<0)
175 #endif
176
177 #ifndef phtons
178 #define phtons(p)  ((guint16)                       \
179                     ((guint16)*((guint8 *)p+0)<<8|  \
180                      (guint16)*((guint8 *)p+1)<<0))
181 #endif
182
183 #ifndef phtonl
184 #define phtonl(p)  ((guint32)*((guint8 *)p+0)<<24|  \
185                     (guint32)*((guint8 *)p+1)<<16|  \
186                     (guint32)*((guint8 *)p+2)<<8|   \
187                     (guint32)*((guint8 *)p+3)<<0)
188 #endif
189
190 #ifndef pletohs
191 #define pletohs(p) ((guint16)                       \
192                     ((guint16)*((guint8 *)p+1)<<8|  \
193                      (guint16)*((guint8 *)p+0)<<0))
194 #endif
195
196 #ifndef plethol
197 #define pletohl(p) ((guint32)*((guint8 *)p+3)<<24|  \
198                     (guint32)*((guint8 *)p+2)<<16|  \
199                     (guint32)*((guint8 *)p+1)<<8|   \
200                     (guint32)*((guint8 *)p+0)<<0)
201 #endif
202
203 #endif /* __WTAP_H__ */