Put back a define to make the Lua build happy.
[metze/wireshark/wip.git] / wiretap / wtap.h
1 /* wtap.h
2  *
3  * Wiretap Library
4  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20
21 #ifndef __WTAP_H__
22 #define __WTAP_H__
23
24 #include <glib.h>
25 #include <time.h>
26 #include <wsutil/buffer.h>
27 #include <wsutil/nstime.h>
28 #include "ws_symbol_export.h"
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 /* Encapsulation types. Choose names that truly reflect
35  * what is contained in the packet trace file.
36  *
37  * WTAP_ENCAP_PER_PACKET is a value passed to "wtap_dump_open()" or
38  * "wtap_dump_fd_open()" to indicate that there is no single encapsulation
39  * type for all packets in the file; this may cause those routines to
40  * fail if the capture file format being written can't support that.
41  * It's also returned by "wtap_file_encap()" for capture files that
42  * don't have a single encapsulation type for all packets in the file.
43  *
44  * WTAP_ENCAP_UNKNOWN is returned by "wtap_pcap_encap_to_wtap_encap()"
45  * if it's handed an unknown encapsulation.
46  *
47  * WTAP_ENCAP_FDDI_BITSWAPPED is for FDDI captures on systems where the
48  * MAC addresses you get from the hardware are bit-swapped.  Ideally,
49  * the driver would tell us that, but I know of none that do, so, for
50  * now, we base it on the machine on which we're *reading* the
51  * capture, rather than on the machine on which the capture was taken
52  * (they're probably likely to be the same).  We assume that they're
53  * bit-swapped on everything except for systems running Ultrix, Alpha
54  * systems, and BSD/OS systems (that's what "tcpdump" does; I guess
55  * Digital decided to bit-swap addresses in the hardware or in the
56  * driver, and I guess BSDI bit-swapped them in the driver, given that
57  * BSD/OS generally runs on Boring Old PC's).  If we create a wiretap
58  * save file format, we'd use the WTAP_ENCAP values to flag the
59  * encapsulation of a packet, so there we'd at least be able to base
60  * it on the machine on which the capture was taken.
61  *
62  * WTAP_ENCAP_LINUX_ATM_CLIP is the encapsulation you get with the
63  * ATM on Linux code from <http://linux-atm.sourceforge.net/>;
64  * that code adds a DLT_ATM_CLIP DLT_ code of 19, and that
65  * encapsulation isn't the same as the DLT_ATM_RFC1483 encapsulation
66  * presumably used on some BSD systems, which we turn into
67  * WTAP_ENCAP_ATM_RFC1483.
68  *
69  * WTAP_ENCAP_NULL corresponds to DLT_NULL from "libpcap".  This
70  * corresponds to
71  *
72  *  1) PPP-over-HDLC encapsulation, at least with some versions
73  *     of ISDN4BSD (but not the current ones, it appears, unless
74  *     I've missed something);
75  *
76  *  2) a 4-byte header containing the AF_ address family, in
77  *     the byte order of the machine that saved the capture,
78  *     for the packet, as used on many BSD systems for the
79  *     loopback device and some other devices, or a 4-byte header
80  *     containing the AF_ address family in network byte order,
81  *     as used on recent OpenBSD systems for the loopback device;
82  *
83  *  3) a 4-byte header containing 2 octets of 0 and an Ethernet
84  *     type in the byte order from an Ethernet header, that being
85  *     what older versions of "libpcap" on Linux turn the Ethernet
86  *     header for loopback interfaces into (0.6.0 and later versions
87  *     leave the Ethernet header alone and make it DLT_EN10MB). */
88 #define WTAP_ENCAP_PER_PACKET                   -1
89 #define WTAP_ENCAP_UNKNOWN                        0
90 #define WTAP_ENCAP_ETHERNET                       1
91 #define WTAP_ENCAP_TOKEN_RING                     2
92 #define WTAP_ENCAP_SLIP                           3
93 #define WTAP_ENCAP_PPP                            4
94 #define WTAP_ENCAP_FDDI                           5
95 #define WTAP_ENCAP_FDDI_BITSWAPPED                6
96 #define WTAP_ENCAP_RAW_IP                         7
97 #define WTAP_ENCAP_ARCNET                         8
98 #define WTAP_ENCAP_ARCNET_LINUX                   9
99 #define WTAP_ENCAP_ATM_RFC1483                   10
100 #define WTAP_ENCAP_LINUX_ATM_CLIP                11
101 #define WTAP_ENCAP_LAPB                          12
102 #define WTAP_ENCAP_ATM_PDUS                      13
103 #define WTAP_ENCAP_ATM_PDUS_UNTRUNCATED          14
104 #define WTAP_ENCAP_NULL                          15
105 #define WTAP_ENCAP_ASCEND                        16
106 #define WTAP_ENCAP_ISDN                          17
107 #define WTAP_ENCAP_IP_OVER_FC                    18
108 #define WTAP_ENCAP_PPP_WITH_PHDR                 19
109 #define WTAP_ENCAP_IEEE_802_11                   20
110 #define WTAP_ENCAP_IEEE_802_11_PRISM             21
111 #define WTAP_ENCAP_IEEE_802_11_WITH_RADIO        22
112 #define WTAP_ENCAP_IEEE_802_11_RADIOTAP          23
113 #define WTAP_ENCAP_IEEE_802_11_AVS               24
114 #define WTAP_ENCAP_SLL                           25
115 #define WTAP_ENCAP_FRELAY                        26
116 #define WTAP_ENCAP_FRELAY_WITH_PHDR              27
117 #define WTAP_ENCAP_CHDLC                         28
118 #define WTAP_ENCAP_CISCO_IOS                     29
119 #define WTAP_ENCAP_LOCALTALK                     30
120 #define WTAP_ENCAP_OLD_PFLOG                     31
121 #define WTAP_ENCAP_HHDLC                         32
122 #define WTAP_ENCAP_DOCSIS                        33
123 #define WTAP_ENCAP_COSINE                        34
124 #define WTAP_ENCAP_WFLEET_HDLC                   35
125 #define WTAP_ENCAP_SDLC                          36
126 #define WTAP_ENCAP_TZSP                          37
127 #define WTAP_ENCAP_ENC                           38
128 #define WTAP_ENCAP_PFLOG                         39
129 #define WTAP_ENCAP_CHDLC_WITH_PHDR               40
130 #define WTAP_ENCAP_BLUETOOTH_H4                  41
131 #define WTAP_ENCAP_MTP2                          42
132 #define WTAP_ENCAP_MTP3                          43
133 #define WTAP_ENCAP_IRDA                          44
134 #define WTAP_ENCAP_USER0                         45
135 #define WTAP_ENCAP_USER1                         46
136 #define WTAP_ENCAP_USER2                         47
137 #define WTAP_ENCAP_USER3                         48
138 #define WTAP_ENCAP_USER4                         49
139 #define WTAP_ENCAP_USER5                         50
140 #define WTAP_ENCAP_USER6                         51
141 #define WTAP_ENCAP_USER7                         52
142 #define WTAP_ENCAP_USER8                         53
143 #define WTAP_ENCAP_USER9                         54
144 #define WTAP_ENCAP_USER10                        55
145 #define WTAP_ENCAP_USER11                        56
146 #define WTAP_ENCAP_USER12                        57
147 #define WTAP_ENCAP_USER13                        58
148 #define WTAP_ENCAP_USER14                        59
149 #define WTAP_ENCAP_USER15                        60
150 #define WTAP_ENCAP_SYMANTEC                      61
151 #define WTAP_ENCAP_APPLE_IP_OVER_IEEE1394        62
152 #define WTAP_ENCAP_BACNET_MS_TP                  63
153 #define WTAP_ENCAP_NETTL_RAW_ICMP                64
154 #define WTAP_ENCAP_NETTL_RAW_ICMPV6              65
155 #define WTAP_ENCAP_GPRS_LLC                      66
156 #define WTAP_ENCAP_JUNIPER_ATM1                  67
157 #define WTAP_ENCAP_JUNIPER_ATM2                  68
158 #define WTAP_ENCAP_REDBACK                       69
159 #define WTAP_ENCAP_NETTL_RAW_IP                  70
160 #define WTAP_ENCAP_NETTL_ETHERNET                71
161 #define WTAP_ENCAP_NETTL_TOKEN_RING              72
162 #define WTAP_ENCAP_NETTL_FDDI                    73
163 #define WTAP_ENCAP_NETTL_UNKNOWN                 74
164 #define WTAP_ENCAP_MTP2_WITH_PHDR                75
165 #define WTAP_ENCAP_JUNIPER_PPPOE                 76
166 #define WTAP_ENCAP_GCOM_TIE1                     77
167 #define WTAP_ENCAP_GCOM_SERIAL                   78
168 #define WTAP_ENCAP_NETTL_X25                     79
169 #define WTAP_ENCAP_K12                           80
170 #define WTAP_ENCAP_JUNIPER_MLPPP                 81
171 #define WTAP_ENCAP_JUNIPER_MLFR                  82
172 #define WTAP_ENCAP_JUNIPER_ETHER                 83
173 #define WTAP_ENCAP_JUNIPER_PPP                   84
174 #define WTAP_ENCAP_JUNIPER_FRELAY                85
175 #define WTAP_ENCAP_JUNIPER_CHDLC                 86
176 #define WTAP_ENCAP_JUNIPER_GGSN                  87
177 #define WTAP_ENCAP_LINUX_LAPD                    88
178 #define WTAP_ENCAP_CATAPULT_DCT2000              89
179 #define WTAP_ENCAP_BER                           90
180 #define WTAP_ENCAP_JUNIPER_VP                    91
181 /*
182  * RESERVED FOR FUTURE USE WITH USB
183  * NOT GUARANTEED TO CORRESPOND TO THE OLD DEPRECATED LINUX USB
184  * PSEUDO-HEADER
185  * DEFINED FOR NOW SOLELY TO MAKE LUA HAPPY
186  */
187 #define WTAP_ENCAP_USB                           92
188 #define WTAP_ENCAP_IEEE802_16_MAC_CPS            93
189 #define WTAP_ENCAP_NETTL_RAW_TELNET              94
190 #define WTAP_ENCAP_USB_LINUX                     95
191 #define WTAP_ENCAP_MPEG                          96
192 #define WTAP_ENCAP_PPI                           97
193 #define WTAP_ENCAP_ERF                           98
194 #define WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR        99
195 #define WTAP_ENCAP_SITA                         100
196 #define WTAP_ENCAP_SCCP                         101
197 #define WTAP_ENCAP_BLUETOOTH_HCI                102 /*raw packets without a transport layer header e.g. H4*/
198 #define WTAP_ENCAP_IPMB                         103
199 #define WTAP_ENCAP_IEEE802_15_4                 104
200 #define WTAP_ENCAP_X2E_XORAYA                   105
201 #define WTAP_ENCAP_FLEXRAY                      106
202 #define WTAP_ENCAP_LIN                          107
203 #define WTAP_ENCAP_MOST                         108
204 #define WTAP_ENCAP_CAN20B                       109
205 #define WTAP_ENCAP_LAYER1_EVENT                 110
206 #define WTAP_ENCAP_X2E_SERIAL                   111
207 #define WTAP_ENCAP_I2C                          112
208 #define WTAP_ENCAP_IEEE802_15_4_NONASK_PHY      113
209 #define WTAP_ENCAP_TNEF                         114
210 #define WTAP_ENCAP_USB_LINUX_MMAPPED            115
211 #define WTAP_ENCAP_GSM_UM                       116
212 #define WTAP_ENCAP_DPNSS                        117
213 #define WTAP_ENCAP_PACKETLOGGER                 118
214 #define WTAP_ENCAP_NSTRACE_1_0                  119
215 #define WTAP_ENCAP_NSTRACE_2_0                  120
216 #define WTAP_ENCAP_FIBRE_CHANNEL_FC2            121
217 #define WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS 122
218 #define WTAP_ENCAP_JPEG_JFIF                    123 /* obsoleted by WTAP_ENCAP_MIME*/
219 #define WTAP_ENCAP_IPNET                        124
220 #define WTAP_ENCAP_SOCKETCAN                    125
221 #define WTAP_ENCAP_IEEE_802_11_NETMON           126
222 #define WTAP_ENCAP_IEEE802_15_4_NOFCS           127
223 #define WTAP_ENCAP_RAW_IPFIX                    128
224 #define WTAP_ENCAP_RAW_IP4                      129
225 #define WTAP_ENCAP_RAW_IP6                      130
226 #define WTAP_ENCAP_LAPD                         131
227 #define WTAP_ENCAP_DVBCI                        132
228 #define WTAP_ENCAP_MUX27010                     133
229 #define WTAP_ENCAP_MIME                         134
230 #define WTAP_ENCAP_NETANALYZER                  135
231 #define WTAP_ENCAP_NETANALYZER_TRANSPARENT      136
232 #define WTAP_ENCAP_IP_OVER_IB                   137
233 #define WTAP_ENCAP_MPEG_2_TS                    138
234 #define WTAP_ENCAP_PPP_ETHER                    139
235 #define WTAP_ENCAP_NFC_LLCP                     140
236 #define WTAP_ENCAP_NFLOG                        141
237 #define WTAP_ENCAP_V5_EF                        142
238 #define WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR       143
239 #define WTAP_ENCAP_IXVERIWAVE                   144
240 #define WTAP_ENCAP_SDH                          145
241 #define WTAP_ENCAP_DBUS                         146
242 #define WTAP_ENCAP_AX25_KISS                    147
243 #define WTAP_ENCAP_AX25                         148
244 #define WTAP_ENCAP_SCTP                         149
245 #define WTAP_ENCAP_INFINIBAND                   150
246 #define WTAP_ENCAP_JUNIPER_SVCS                 151
247 #define WTAP_ENCAP_USBPCAP                      152
248 #define WTAP_ENCAP_RTAC_SERIAL                  153
249 #define WTAP_ENCAP_BLUETOOTH_LE_LL              154
250 #define WTAP_ENCAP_WIRESHARK_UPPER_PDU          155
251 #define WTAP_ENCAP_STANAG_4607                  156
252 #define WTAP_ENCAP_STANAG_5066_D_PDU            157
253 #define WTAP_ENCAP_NETLINK                      158
254 #define WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR      159
255 #define WTAP_ENCAP_BLUETOOTH_BREDR_BB           160
256 #define WTAP_ENCAP_BLUETOOTH_LE_LL_WITH_PHDR    161
257 #define WTAP_ENCAP_NSTRACE_3_0                  162
258 #define WTAP_ENCAP_LOGCAT                       163
259 #define WTAP_ENCAP_LOGCAT_BRIEF                 164
260 #define WTAP_ENCAP_LOGCAT_PROCESS               165
261 #define WTAP_ENCAP_LOGCAT_TAG                   166
262 #define WTAP_ENCAP_LOGCAT_THREAD                167
263 #define WTAP_ENCAP_LOGCAT_TIME                  168
264 #define WTAP_ENCAP_LOGCAT_THREADTIME            169
265 #define WTAP_ENCAP_LOGCAT_LONG                  170
266 #define WTAP_ENCAP_PKTAP                        171
267 #define WTAP_ENCAP_EPON                         172
268 #define WTAP_ENCAP_IPMI_TRACE                   173
269 #define WTAP_ENCAP_LOOP                         174
270 #define WTAP_ENCAP_JSON                         175
271 #define WTAP_ENCAP_NSTRACE_3_5                  176
272 #define WTAP_ENCAP_ISO14443                     177
273 #define WTAP_ENCAP_GFP_T                        178
274 #define WTAP_ENCAP_GFP_F                        179
275 /* After adding new item here, please also add new item to encap_table_base array */
276
277 #define WTAP_NUM_ENCAP_TYPES                    wtap_get_num_encap_types()
278
279 /* File types/subtypes that can be read by wiretap.
280    We support writing many of these file types, too, so we
281    distinguish between different subtypes of them, as
282    different subtypes need to be written in a different
283    fashion. */
284 #define WTAP_FILE_TYPE_SUBTYPE_UNKNOWN                        0
285 #define WTAP_FILE_TYPE_SUBTYPE_PCAP                           1
286 #define WTAP_FILE_TYPE_SUBTYPE_PCAPNG                         2
287 #define WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC                      3
288 #define WTAP_FILE_TYPE_SUBTYPE_PCAP_AIX                       4
289 #define WTAP_FILE_TYPE_SUBTYPE_PCAP_SS991029                  5
290 #define WTAP_FILE_TYPE_SUBTYPE_PCAP_NOKIA                     6
291 #define WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990417                  7
292 #define WTAP_FILE_TYPE_SUBTYPE_PCAP_SS990915                  8
293 #define WTAP_FILE_TYPE_SUBTYPE_5VIEWS                         9
294 #define WTAP_FILE_TYPE_SUBTYPE_IPTRACE_1_0                   10
295 #define WTAP_FILE_TYPE_SUBTYPE_IPTRACE_2_0                   11
296 #define WTAP_FILE_TYPE_SUBTYPE_BER                           12
297 #define WTAP_FILE_TYPE_SUBTYPE_HCIDUMP                       13
298 #define WTAP_FILE_TYPE_SUBTYPE_CATAPULT_DCT2000              14
299 #define WTAP_FILE_TYPE_SUBTYPE_NETXRAY_OLD                   15
300 #define WTAP_FILE_TYPE_SUBTYPE_NETXRAY_1_0                   16
301 #define WTAP_FILE_TYPE_SUBTYPE_COSINE                        17
302 #define WTAP_FILE_TYPE_SUBTYPE_CSIDS                         18
303 #define WTAP_FILE_TYPE_SUBTYPE_DBS_ETHERWATCH                19
304 #define WTAP_FILE_TYPE_SUBTYPE_ERF                           20
305 #define WTAP_FILE_TYPE_SUBTYPE_EYESDN                        21
306 #define WTAP_FILE_TYPE_SUBTYPE_NETTL                         22
307 #define WTAP_FILE_TYPE_SUBTYPE_ISERIES                       23
308 #define WTAP_FILE_TYPE_SUBTYPE_ISERIES_UNICODE               24
309 #define WTAP_FILE_TYPE_SUBTYPE_I4BTRACE                      25
310 #define WTAP_FILE_TYPE_SUBTYPE_ASCEND                        26
311 #define WTAP_FILE_TYPE_SUBTYPE_NETMON_1_x                    27
312 #define WTAP_FILE_TYPE_SUBTYPE_NETMON_2_x                    28
313 #define WTAP_FILE_TYPE_SUBTYPE_NGSNIFFER_UNCOMPRESSED        29
314 #define WTAP_FILE_TYPE_SUBTYPE_NGSNIFFER_COMPRESSED          30
315 #define WTAP_FILE_TYPE_SUBTYPE_NETXRAY_1_1                   31
316 #define WTAP_FILE_TYPE_SUBTYPE_NETXRAY_2_00x                 32
317 #define WTAP_FILE_TYPE_SUBTYPE_NETWORK_INSTRUMENTS           33
318 #define WTAP_FILE_TYPE_SUBTYPE_LANALYZER                     34
319 #define WTAP_FILE_TYPE_SUBTYPE_PPPDUMP                       35
320 #define WTAP_FILE_TYPE_SUBTYPE_RADCOM                        36
321 #define WTAP_FILE_TYPE_SUBTYPE_SNOOP                         37
322 #define WTAP_FILE_TYPE_SUBTYPE_SHOMITI                       38
323 #define WTAP_FILE_TYPE_SUBTYPE_VMS                           39
324 #define WTAP_FILE_TYPE_SUBTYPE_K12                           40
325 #define WTAP_FILE_TYPE_SUBTYPE_TOSHIBA                       41
326 #define WTAP_FILE_TYPE_SUBTYPE_VISUAL_NETWORKS               42
327 #define WTAP_FILE_TYPE_SUBTYPE_PEEKCLASSIC_V56               43
328 #define WTAP_FILE_TYPE_SUBTYPE_PEEKCLASSIC_V7                44
329 #define WTAP_FILE_TYPE_SUBTYPE_PEEKTAGGED                    45
330 #define WTAP_FILE_TYPE_SUBTYPE_MPEG                          46
331 #define WTAP_FILE_TYPE_SUBTYPE_K12TEXT                       47
332 #define WTAP_FILE_TYPE_SUBTYPE_NETSCREEN                     48
333 #define WTAP_FILE_TYPE_SUBTYPE_COMMVIEW                      49
334 #define WTAP_FILE_TYPE_SUBTYPE_BTSNOOP                       50
335 #define WTAP_FILE_TYPE_SUBTYPE_TNEF                          51
336 #define WTAP_FILE_TYPE_SUBTYPE_DCT3TRACE                     52
337 #define WTAP_FILE_TYPE_SUBTYPE_PACKETLOGGER                  53
338 #define WTAP_FILE_TYPE_SUBTYPE_DAINTREE_SNA                  54
339 #define WTAP_FILE_TYPE_SUBTYPE_NETSCALER_1_0                 55
340 #define WTAP_FILE_TYPE_SUBTYPE_NETSCALER_2_0                 56
341 #define WTAP_FILE_TYPE_SUBTYPE_JPEG_JFIF                     57 /* obsoleted by WTAP_FILE_TYPE_SUBTYPE_MIME */
342 #define WTAP_FILE_TYPE_SUBTYPE_IPFIX                         58
343 #define WTAP_FILE_TYPE_SUBTYPE_MIME                          59
344 #define WTAP_FILE_TYPE_SUBTYPE_AETHRA                        60
345 #define WTAP_FILE_TYPE_SUBTYPE_MPEG_2_TS                     61
346 #define WTAP_FILE_TYPE_SUBTYPE_VWR_80211                     62
347 #define WTAP_FILE_TYPE_SUBTYPE_VWR_ETH                       63
348 #define WTAP_FILE_TYPE_SUBTYPE_CAMINS                        64
349 #define WTAP_FILE_TYPE_SUBTYPE_STANAG_4607                   65
350 #define WTAP_FILE_TYPE_SUBTYPE_NETSCALER_3_0                 66
351 #define WTAP_FILE_TYPE_SUBTYPE_LOGCAT                        67
352 #define WTAP_FILE_TYPE_SUBTYPE_LOGCAT_BRIEF                  68
353 #define WTAP_FILE_TYPE_SUBTYPE_LOGCAT_PROCESS                69
354 #define WTAP_FILE_TYPE_SUBTYPE_LOGCAT_TAG                    70
355 #define WTAP_FILE_TYPE_SUBTYPE_LOGCAT_THREAD                 71
356 #define WTAP_FILE_TYPE_SUBTYPE_LOGCAT_TIME                   72
357 #define WTAP_FILE_TYPE_SUBTYPE_LOGCAT_THREADTIME             73
358 #define WTAP_FILE_TYPE_SUBTYPE_LOGCAT_LONG                   74
359 #define WTAP_FILE_TYPE_SUBTYPE_COLASOFT_CAPSA                75
360 #define WTAP_FILE_TYPE_SUBTYPE_COLASOFT_PACKET_BUILDER       76
361 #define WTAP_FILE_TYPE_SUBTYPE_JSON                          77
362 #define WTAP_FILE_TYPE_SUBTYPE_NETSCALER_3_5                 78
363 #define WTAP_FILE_TYPE_SUBTYPE_NETTRACE_3GPP_32_423          79
364
365 #define WTAP_NUM_FILE_TYPES_SUBTYPES  wtap_get_num_file_types_subtypes()
366
367 /* timestamp precision (currently only these values are supported) */
368 #define WTAP_TSPREC_UNKNOWN    -2
369 #define WTAP_TSPREC_PER_PACKET -1  /* as a per-file value, means per-packet */
370 #define WTAP_TSPREC_SEC         0
371 #define WTAP_TSPREC_DSEC        1
372 #define WTAP_TSPREC_CSEC        2
373 #define WTAP_TSPREC_MSEC        3
374 #define WTAP_TSPREC_USEC        6
375 #define WTAP_TSPREC_NSEC        9
376 /* if you add to the above, update wtap_tsprec_string() */
377
378 /*
379  * Maximum packet size we'll support.
380  * 262144 is the largest snapshot length that libpcap supports, so we
381  * use that.
382  */
383 #define WTAP_MAX_PACKET_SIZE    262144
384
385 /*
386  * "Pseudo-headers" are used to supply to the clients of wiretap
387  * per-packet information that's not part of the packet payload
388  * proper.
389  *
390  * NOTE: do not use pseudo-header structures to hold information
391  * used by the code to read a particular capture file type; to
392  * keep that sort of state information, add a new structure for
393  * that private information to "wtap-int.h", add a pointer to that
394  * type of structure to the "capture" member of the "struct wtap"
395  * structure, and allocate one of those structures and set that member
396  * in the "open" routine for that capture file type if the open
397  * succeeds.  See various other capture file type handlers for examples
398  * of that.
399  */
400
401
402 /* Packet "pseudo-header" information for Ethernet capture files. */
403 struct eth_phdr {
404     gint   fcs_len;  /* Number of bytes of FCS - -1 means "unknown" */
405 };
406
407 /* Packet "pseudo-header" information for X.25 capture files. */
408 #define FROM_DCE 0x80
409 struct x25_phdr {
410     guint8  flags;   /* ENCAP_LAPB, ENCAP_V120 : 1st bit means From DCE */
411 };
412
413 /* Packet "pseudo-header" information for ISDN capture files. */
414
415 /* Direction */
416 struct isdn_phdr {
417     gboolean uton;
418     guint8   channel;   /* 0 = D-channel; n = B-channel n */
419 };
420
421 /* Packet "pseudo-header" for ATM capture files.
422    Not all of this information is supplied by all capture types.
423    These originally came from the Network General (DOS-based)
424    ATM Sniffer file format, but we've added some additional
425    items. */
426
427 /*
428  * Status bits.
429  */
430 #define ATM_RAW_CELL         0x01 /* TRUE if the packet is a single cell */
431 #define ATM_NO_HEC           0x02 /* TRUE if the cell has HEC stripped out */
432 #define ATM_AAL2_NOPHDR      0x04 /* TRUE if the AAL2 PDU has no pseudo-header */
433 #define ATM_REASSEMBLY_ERROR 0x08 /* TRUE if this is an incompletely-reassembled PDU */
434
435 /*
436  * AAL types.
437  */
438 #define AAL_UNKNOWN     0  /* AAL unknown */
439 #define AAL_1           1  /* AAL1 */
440 #define AAL_2           2  /* AAL2 */
441 #define AAL_3_4         3  /* AAL3/4 */
442 #define AAL_5           4  /* AAL5 */
443 #define AAL_USER        5  /* User AAL */
444 #define AAL_SIGNALLING  6  /* Signaling AAL */
445 #define AAL_OAMCELL     7  /* OAM cell */
446
447 /*
448  * Traffic types.
449  */
450 #define TRAF_UNKNOWN    0  /* Unknown */
451 #define TRAF_LLCMX      1  /* LLC multiplexed (RFC 1483) */
452 #define TRAF_VCMX       2  /* VC multiplexed (RFC 1483) */
453 #define TRAF_LANE       3  /* LAN Emulation */
454 #define TRAF_ILMI       4  /* ILMI */
455 #define TRAF_FR         5  /* Frame Relay */
456 #define TRAF_SPANS      6  /* FORE SPANS */
457 #define TRAF_IPSILON    7  /* Ipsilon */
458 #define TRAF_UMTS_FP    8  /* UMTS Frame Protocol */
459 #define TRAF_GPRS_NS    9  /* GPRS Network Services */
460 #define TRAF_SSCOP     10  /* SSCOP */
461
462 /*
463  * Traffic subtypes.
464  */
465 #define TRAF_ST_UNKNOWN     0   /* Unknown */
466
467 /*
468  * For TRAF_VCMX:
469  */
470 #define TRAF_ST_VCMX_802_3_FCS   1  /* 802.3 with an FCS */
471 #define TRAF_ST_VCMX_802_4_FCS   2  /* 802.4 with an FCS */
472 #define TRAF_ST_VCMX_802_5_FCS   3  /* 802.5 with an FCS */
473 #define TRAF_ST_VCMX_FDDI_FCS    4  /* FDDI with an FCS */
474 #define TRAF_ST_VCMX_802_6_FCS   5  /* 802.6 with an FCS */
475 #define TRAF_ST_VCMX_802_3       7  /* 802.3 without an FCS */
476 #define TRAF_ST_VCMX_802_4       8  /* 802.4 without an FCS */
477 #define TRAF_ST_VCMX_802_5       9  /* 802.5 without an FCS */
478 #define TRAF_ST_VCMX_FDDI       10  /* FDDI without an FCS */
479 #define TRAF_ST_VCMX_802_6      11  /* 802.6 without an FCS */
480 #define TRAF_ST_VCMX_FRAGMENTS  12  /* Fragments */
481 #define TRAF_ST_VCMX_BPDU       13  /* BPDU */
482
483 /*
484  * For TRAF_LANE:
485  */
486 #define TRAF_ST_LANE_LE_CTRL     1  /* LANE: LE Ctrl */
487 #define TRAF_ST_LANE_802_3       2  /* LANE: 802.3 */
488 #define TRAF_ST_LANE_802_5       3  /* LANE: 802.5 */
489 #define TRAF_ST_LANE_802_3_MC    4  /* LANE: 802.3 multicast */
490 #define TRAF_ST_LANE_802_5_MC    5  /* LANE: 802.5 multicast */
491
492 /*
493  * For TRAF_IPSILON:
494  */
495 #define TRAF_ST_IPSILON_FT0      1  /* Ipsilon: Flow Type 0 */
496 #define TRAF_ST_IPSILON_FT1      2  /* Ipsilon: Flow Type 1 */
497 #define TRAF_ST_IPSILON_FT2      3  /* Ipsilon: Flow Type 2 */
498
499 struct atm_phdr {
500     guint32 flags;      /* status flags */
501     guint8  aal;        /* AAL of the traffic */
502     guint8  type;       /* traffic type */
503     guint8  subtype;    /* traffic subtype */
504     guint16 vpi;        /* virtual path identifier */
505     guint16 vci;        /* virtual circuit identifier */
506     guint8  aal2_cid;   /* channel id */
507     guint16 channel;    /* link: 0 for DTE->DCE, 1 for DCE->DTE */
508     guint16 cells;      /* number of cells */
509     guint16 aal5t_u2u;  /* user-to-user indicator */
510     guint16 aal5t_len;  /* length of the packet */
511     guint32 aal5t_chksum;   /* checksum for AAL5 packet */
512 };
513
514 /* Packet "pseudo-header" for the output from "wandsession", "wannext",
515    "wandisplay", and similar commands on Lucent/Ascend access equipment. */
516
517 #define ASCEND_MAX_STR_LEN 64
518
519 #define ASCEND_PFX_WDS_X    1
520 #define ASCEND_PFX_WDS_R    2
521 #define ASCEND_PFX_WDD      3
522 #define ASCEND_PFX_ISDN_X   4
523 #define ASCEND_PFX_ISDN_R   5
524 #define ASCEND_PFX_ETHER    6
525
526 struct ascend_phdr {
527     guint16 type;                         /* ASCEND_PFX_*, as defined above */
528     char    user[ASCEND_MAX_STR_LEN];     /* Username, from wandsession header */
529     guint32 sess;                         /* Session number, from wandsession header */
530     char    call_num[ASCEND_MAX_STR_LEN]; /* Called number, from WDD header */
531     guint32 chunk;                        /* Chunk number, from WDD header */
532     guint32 task;                         /* Task number */
533 };
534
535 /* Also defined in epan/packet_info.h */
536 #define P2P_DIR_UNKNOWN -1
537 #define P2P_DIR_SENT     0
538 #define P2P_DIR_RECV     1
539
540 /* Packet "pseudo-header" for point-to-point links with direction flags. */
541 struct p2p_phdr {
542     int sent; /* TRUE=sent, FALSE=received, -1=unknown*/
543 };
544
545 /*
546  * Packet "pseudo-header" information for 802.11.
547  * Radio information is only present in this form for
548  * WTAP_ENCAP_IEEE_802_11_WITH_RADIO.  This is used for file formats in
549  * which the radio information isn't provided as a pseudo-header in the
550  * packet data.  It is also used by the dissectors for the pseudo-headers
551  * in the packet data to supply radio information, in a form independent
552  * of the file format and pseudo-header format, to the "802.11 radio"
553  * dissector.
554  *
555  * Signal strength, etc. information:
556  *
557  * Raw signal strength can be measured in milliwatts.
558  * It can also be represented as dBm, which is 10 times the log base 10
559  * of the signal strength in mW.
560  *
561  * The Receive Signal Strength Indicator is an integer in the range 0 to 255.
562  * The actual RSSI value for a given signal strength is dependent on the
563  * vendor (and perhaps on the adapter).  The maximum possible RSSI value
564  * is also dependent on the vendor and perhaps the adapter.
565  *
566  * The signal strength can be represented as a percentage, which is 100
567  * times the ratio of the RSSI and the maximum RSSI.
568  */
569
570 /*
571  * PHY types.
572  */
573 #define PHDR_802_11_PHY_UNKNOWN        0 /* PHY not known */
574 #define PHDR_802_11_PHY_11_FHSS        1 /* 802.11 FHSS */
575 #define PHDR_802_11_PHY_11_IR          2 /* 802.11 IR */
576 #define PHDR_802_11_PHY_11_DSSS        3 /* 802.11 DSSS */
577 #define PHDR_802_11_PHY_11B            4 /* 802.11b */
578 #define PHDR_802_11_PHY_11A            5 /* 802.11a */
579 #define PHDR_802_11_PHY_11G            6 /* 802.11g */
580 #define PHDR_802_11_PHY_11N            7 /* 802.11n */
581 #define PHDR_802_11_PHY_11AC           8 /* 802.11ac */
582 #define PHDR_802_11_PHY_11AD           9 /* 802.11ad */
583
584 /*
585  * PHY-specific information.
586  */
587
588 /*
589  * 802.11 legacy FHSS.
590  */
591 struct ieee_802_11_fhss {
592     guint    has_hop_set:1;
593     guint    has_hop_pattern:1;
594     guint    has_hop_index:1;
595
596     guint8   hop_set;        /* Hop set */
597     guint8   hop_pattern;    /* Hop pattern */
598     guint8   hop_index;      /* Hop index */
599 };
600
601 /*
602  * 802.11b.
603  */
604 struct ieee_802_11b {
605     /* Which of this information is present? */
606     guint    has_short_preamble:1;
607
608     gboolean short_preamble; /* Short preamble */
609 };
610
611 /*
612  * 802.11a.
613  */
614 struct ieee_802_11a {
615     /* Which of this information is present? */
616     guint    has_channel_type:1;
617     guint    has_turbo_type:1;
618
619     guint    channel_type:2;
620     guint    turbo_type:2;
621 };
622
623 /*
624  * Channel type values.
625  */
626 #define PHDR_802_11A_CHANNEL_TYPE_NORMAL           0
627 #define PHDR_802_11A_CHANNEL_TYPE_HALF_CLOCKED     1
628 #define PHDR_802_11A_CHANNEL_TYPE_QUARTER_CLOCKED  2
629
630 /*
631  * "Turbo" is an Atheros proprietary extension with 40 MHz-wide channels.
632  * It can be dynamic or static.
633  *
634  * See
635  *
636  *    http://wifi-insider.com/atheros/turbo.htm
637  */
638 #define PHDR_802_11A_TURBO_TYPE_NORMAL           0
639 #define PHDR_802_11A_TURBO_TYPE_TURBO            1  /* If we don't know wehther it's static or dynamic */
640 #define PHDR_802_11A_TURBO_TYPE_DYNAMIC_TURBO    2
641 #define PHDR_802_11A_TURBO_TYPE_STATIC_TURBO     3
642
643 /*
644  * 802.11g.
645  */
646 struct ieee_802_11g {
647     /* Which of this information is present? */
648     guint    has_short_preamble:1;
649     guint    has_mode:1;
650
651     gboolean short_preamble; /* Short preamble */
652     guint32  mode;           /* Various proprietary extensions */
653 };
654
655 /*
656  * Mode values.
657  */
658 #define PHDR_802_11G_MODE_NORMAL    0
659 #define PHDR_802_11G_MODE_SUPER_G   1  /* Atheros Super G */
660
661 /*
662  * 802.11n.
663  */
664 struct ieee_802_11n {
665     /* Which of this information is present? */
666     guint    has_mcs_index:1;
667     guint    has_bandwidth:1;
668     guint    has_short_gi:1;
669     guint    has_greenfield:1;
670     guint    has_fec:1;
671     guint    has_stbc_streams:1;
672     guint    has_ness:1;
673
674     guint16  mcs_index;      /* MCS index */
675     guint    bandwidth;      /* Bandwidth = 20 MHz, 40 MHz, etc. */
676     guint    short_gi:1;     /* True for short guard interval */
677     guint    greenfield:1;   /* True for greenfield, short for mixed */
678     guint    fec:1;          /* FEC: 0 = BCC, 1 = LDPC */
679     guint    stbc_streams:2; /* Number of STBC streams */
680     guint    ness;           /* Number of extension spatial streams */
681 };
682
683 /*
684  * Bandwidth values; used for both 11n and 11ac.
685  */
686 #define PHDR_802_11_BANDWIDTH_20_MHZ   0  /* 20 MHz */
687 #define PHDR_802_11_BANDWIDTH_40_MHZ   1  /* 40 MHz */
688 #define PHDR_802_11_BANDWIDTH_20_20L   2  /* 20 + 20L, 40 MHz */
689 #define PHDR_802_11_BANDWIDTH_20_20U   3  /* 20 + 20U, 40 MHz */
690 #define PHDR_802_11_BANDWIDTH_80_MHZ   4  /* 80 MHz */
691 #define PHDR_802_11_BANDWIDTH_40_40L   5  /* 40 + 40L MHz, 80 MHz */
692 #define PHDR_802_11_BANDWIDTH_40_40U   6  /* 40 + 40U MHz, 80 MHz */
693 #define PHDR_802_11_BANDWIDTH_20LL     7  /* ???, 80 MHz */
694 #define PHDR_802_11_BANDWIDTH_20LU     8  /* ???, 80 MHz */
695 #define PHDR_802_11_BANDWIDTH_20UL     9  /* ???, 80 MHz */
696 #define PHDR_802_11_BANDWIDTH_20UU     10 /* ???, 80 MHz */
697 #define PHDR_802_11_BANDWIDTH_160_MHZ  11 /* 160 MHz */
698 #define PHDR_802_11_BANDWIDTH_80_80L   12 /* 80 + 80L, 160 MHz */
699 #define PHDR_802_11_BANDWIDTH_80_80U   13 /* 80 + 80U, 160 MHz */
700 #define PHDR_802_11_BANDWIDTH_40LL     14 /* ???, 160 MHz */
701 #define PHDR_802_11_BANDWIDTH_40LU     15 /* ???, 160 MHz */
702 #define PHDR_802_11_BANDWIDTH_40UL     16 /* ???, 160 MHz */
703 #define PHDR_802_11_BANDWIDTH_40UU     17 /* ???, 160 MHz */
704 #define PHDR_802_11_BANDWIDTH_20LLL    18 /* ???, 160 MHz */
705 #define PHDR_802_11_BANDWIDTH_20LLU    19 /* ???, 160 MHz */
706 #define PHDR_802_11_BANDWIDTH_20LUL    20 /* ???, 160 MHz */
707 #define PHDR_802_11_BANDWIDTH_20LUU    21 /* ???, 160 MHz */
708 #define PHDR_802_11_BANDWIDTH_20ULL    22 /* ???, 160 MHz */
709 #define PHDR_802_11_BANDWIDTH_20ULU    23 /* ???, 160 MHz */
710 #define PHDR_802_11_BANDWIDTH_20UUL    24 /* ???, 160 MHz */
711 #define PHDR_802_11_BANDWIDTH_20UUU    25 /* ???, 160 MHz */
712
713 /*
714  * 802.11ac.
715  */
716 struct ieee_802_11ac {
717     /* Which of this information is present? */
718     guint    has_stbc:1;
719     guint    has_txop_ps_not_allowed:1;
720     guint    has_short_gi:1;
721     guint    has_short_gi_nsym_disambig:1;
722     guint    has_ldpc_extra_ofdm_symbol:1;
723     guint    has_beamformed:1;
724     guint    has_bandwidth:1;
725     guint    has_fec:1;
726     guint    has_group_id:1;
727     guint    has_partial_aid:1;
728
729     guint    stbc:1;         /* 1 if all spatial streams have STBC */
730     guint    txop_ps_not_allowed:1;
731     guint    short_gi:1;     /* True for short guard interval */
732     guint    short_gi_nsym_disambig:1;
733     guint    ldpc_extra_ofdm_symbol:1;
734     guint    beamformed:1;
735     guint8   bandwidth;      /* Bandwidth = 20 MHz, 40 MHz, etc. */
736     guint8   mcs[4];         /* MCS index per user */
737     guint8   nss[4];         /* NSS per user */
738     guint8   fec;            /* Bit array of FEC per user: 0 = BCC, 1 = LDPC */
739     guint8   group_id;
740     guint16  partial_aid;
741 };
742
743 /*
744  * 802.11ad.
745  */
746
747 /*
748  * Min and Max frequencies for 802.11ad and a macro for checking for 802.11ad.
749  */
750
751 #define PHDR_802_11AD_MIN_FREQUENCY    57000
752 #define PHDR_802_11AD_MAX_FREQUENCY    66000
753
754 #define IS_80211AD(frequency) (((frequency) >= PHDR_802_11AD_MIN_FREQUENCY) &&\
755                                ((frequency) <= PHDR_802_11AD_MAX_FREQUENCY))
756
757 struct ieee_802_11ad {
758     /* Which of this information is present? */
759     guint    has_mcs_index:1;
760
761     guint8   mcs;            /* MCS index */
762 };
763
764 struct ieee_802_11_phdr {
765     gint     fcs_len;        /* Number of bytes of FCS - -1 means "unknown" */
766     gboolean decrypted;      /* TRUE if frame is decrypted even if "protected" bit is set */
767     gboolean datapad;        /* TRUE if frame has padding between 802.11 header and payload */
768     guint    phy;            /* PHY type */
769     union {
770         struct ieee_802_11_fhss info_11_fhss;
771         struct ieee_802_11b info_11b;
772         struct ieee_802_11a info_11a;
773         struct ieee_802_11g info_11g;
774         struct ieee_802_11n info_11n;
775         struct ieee_802_11ac info_11ac;
776         struct ieee_802_11ad info_11ad;
777     } phy_info;
778
779     /* Which of this information is present? */
780     guint    has_channel:1;
781     guint    has_frequency:1;
782     guint    has_data_rate:1;
783     guint    has_signal_percent:1;
784     guint    has_noise_percent:1;
785     guint    has_signal_dbm:1;
786     guint    has_noise_dbm:1;
787     guint    has_tsf_timestamp:1;
788     guint    has_aggregate_info:1;    /* aggregate flags and ID */
789
790     guint16  channel;        /* Channel number */
791     guint32  frequency;      /* Channel center frequency */
792     guint16  data_rate;      /* Data rate, in .5 Mb/s units */
793     guint8   signal_percent; /* Signal level, as a percentage */
794     guint8   noise_percent;  /* Noise level, as a percentage */
795     gint8    signal_dbm;     /* Signal level, in dBm */
796     gint8    noise_dbm;      /* Noise level, in dBm */
797     guint64  tsf_timestamp;
798     guint32  aggregate_flags; /* A-MPDU flags */
799     guint32  aggregate_id;    /* ID for A-MPDU reassembly */
800 };
801
802 /*
803  * A-MPDU flags.
804  */
805 #define PHDR_802_11_LAST_PART_OF_A_MPDU    0x00000001 /* this is the last part of an A-MPDU */
806 #define PHDR_802_11_A_MPDU_DELIM_CRC_ERROR 0x00000002 /* delimiter CRC error after this part */
807
808 /* Packet "pseudo-header" for the output from CoSine L2 debug output. */
809
810 #define COSINE_MAX_IF_NAME_LEN  128
811
812 #define COSINE_ENCAP_TEST      1
813 #define COSINE_ENCAP_PPoATM    2
814 #define COSINE_ENCAP_PPoFR     3
815 #define COSINE_ENCAP_ATM       4
816 #define COSINE_ENCAP_FR        5
817 #define COSINE_ENCAP_HDLC      6
818 #define COSINE_ENCAP_PPP       7
819 #define COSINE_ENCAP_ETH       8
820 #define COSINE_ENCAP_UNKNOWN  99
821
822 #define COSINE_DIR_TX 1
823 #define COSINE_DIR_RX 2
824
825 struct cosine_phdr {
826     guint8  encap;      /* COSINE_ENCAP_* as defined above */
827     guint8  direction;  /* COSINE_DIR_*, as defined above */
828     char    if_name[COSINE_MAX_IF_NAME_LEN];  /* Encap & Logical I/F name */
829     guint16 pro;        /* Protocol */
830     guint16 off;        /* Offset */
831     guint16 pri;        /* Priority */
832     guint16 rm;         /* Rate Marking */
833     guint16 err;        /* Error Code */
834 };
835
836 /* Packet "pseudo-header" for IrDA capture files. */
837
838 /*
839  * Direction of the packet
840  */
841 #define IRDA_INCOMING       0x0000
842 #define IRDA_OUTGOING       0x0004
843
844 /*
845  * "Inline" log messages produced by IrCOMM2k on Windows
846  */
847 #define IRDA_LOG_MESSAGE    0x0100  /* log message */
848 #define IRDA_MISSED_MSG     0x0101  /* missed log entry or frame */
849
850 /*
851  * Differentiate between frames and log messages
852  */
853 #define IRDA_CLASS_FRAME    0x0000
854 #define IRDA_CLASS_LOG      0x0100
855 #define IRDA_CLASS_MASK     0xFF00
856
857 struct irda_phdr {
858     guint16 pkttype;    /* packet type */
859 };
860
861 /* Packet "pseudo-header" for nettl (HP-UX) capture files. */
862
863 struct nettl_phdr {
864     guint16 subsys;
865     guint32 devid;
866     guint32 kind;
867     gint32  pid;
868     guint16 uid;
869 };
870
871 /* Packet "pseudo-header" for MTP2 files. */
872
873 #define MTP2_ANNEX_A_NOT_USED      0
874 #define MTP2_ANNEX_A_USED          1
875 #define MTP2_ANNEX_A_USED_UNKNOWN  2
876
877 struct mtp2_phdr {
878     guint8  sent;
879     guint8  annex_a_used;
880     guint16 link_number;
881 };
882
883 /* Packet "pseudo-header" for K12 files. */
884
885 typedef union {
886     struct {
887         guint16 vp;
888         guint16 vc;
889         guint16 cid;
890     } atm;
891
892     guint32 ds0mask;
893 } k12_input_info_t;
894
895 struct k12_phdr {
896     guint32           input;
897     const gchar      *input_name;
898     const gchar      *stack_file;
899     guint32           input_type;
900     k12_input_info_t  input_info;
901     guint8           *extra_info;
902     guint32           extra_length;
903     void*             stuff;
904 };
905
906 #define K12_PORT_DS0S      0x00010008
907 #define K12_PORT_DS1       0x00100008
908 #define K12_PORT_ATMPVC    0x01020000
909
910 struct lapd_phdr {
911     guint16 pkttype;    /* packet type */
912     guint8 we_network;
913 };
914
915 struct wtap;
916 struct catapult_dct2000_phdr
917 {
918     union
919     {
920         struct isdn_phdr isdn;
921         struct atm_phdr  atm;
922         struct p2p_phdr  p2p;
923     } inner_pseudo_header;
924     gint64       seek_off;
925     struct wtap *wth;
926 };
927
928 /*
929  * Endace Record Format pseudo header
930  */
931 struct erf_phdr {
932     guint64 ts;     /* Time stamp */
933     guint8  type;
934     guint8  flags;
935     guint16 rlen;
936     guint16 lctr;
937     guint16 wlen;
938 };
939
940 struct erf_ehdr {
941   guint64 ehdr;
942 };
943
944 /*
945  * ERF pseudo header with optional subheader
946  * (Multichannel or Ethernet)
947  */
948
949 #define MAX_ERF_EHDR 8
950
951 struct wtap_erf_eth_hdr {
952     guint8 offset;
953     guint8 pad;
954 };
955
956 struct erf_mc_phdr {
957     struct erf_phdr phdr;
958     struct erf_ehdr ehdr_list[MAX_ERF_EHDR];
959     union
960     {
961         struct wtap_erf_eth_hdr eth_hdr;
962         guint32 mc_hdr;
963         guint32 aal2_hdr;
964     } subhdr;
965 };
966
967 #define SITA_FRAME_DIR_TXED            (0x00)  /* values of sita_phdr.flags */
968 #define SITA_FRAME_DIR_RXED            (0x01)
969 #define SITA_FRAME_DIR                 (0x01)  /* mask */
970 #define SITA_ERROR_NO_BUFFER           (0x80)
971
972 #define SITA_SIG_DSR                   (0x01)  /* values of sita_phdr.signals */
973 #define SITA_SIG_DTR                   (0x02)
974 #define SITA_SIG_CTS                   (0x04)
975 #define SITA_SIG_RTS                   (0x08)
976 #define SITA_SIG_DCD                   (0x10)
977 #define SITA_SIG_UNDEF1                (0x20)
978 #define SITA_SIG_UNDEF2                (0x40)
979 #define SITA_SIG_UNDEF3                (0x80)
980
981 #define SITA_ERROR_TX_UNDERRUN         (0x01)  /* values of sita_phdr.errors2 (if SITA_FRAME_DIR_TXED) */
982 #define SITA_ERROR_TX_CTS_LOST         (0x02)
983 #define SITA_ERROR_TX_UART_ERROR       (0x04)
984 #define SITA_ERROR_TX_RETX_LIMIT       (0x08)
985 #define SITA_ERROR_TX_UNDEF1           (0x10)
986 #define SITA_ERROR_TX_UNDEF2           (0x20)
987 #define SITA_ERROR_TX_UNDEF3           (0x40)
988 #define SITA_ERROR_TX_UNDEF4           (0x80)
989
990 #define SITA_ERROR_RX_FRAMING          (0x01)  /* values of sita_phdr.errors1 (if SITA_FRAME_DIR_RXED) */
991 #define SITA_ERROR_RX_PARITY           (0x02)
992 #define SITA_ERROR_RX_COLLISION        (0x04)
993 #define SITA_ERROR_RX_FRAME_LONG       (0x08)
994 #define SITA_ERROR_RX_FRAME_SHORT      (0x10)
995 #define SITA_ERROR_RX_UNDEF1           (0x20)
996 #define SITA_ERROR_RX_UNDEF2           (0x40)
997 #define SITA_ERROR_RX_UNDEF3           (0x80)
998
999 #define SITA_ERROR_RX_NONOCTET_ALIGNED (0x01)  /* values of sita_phdr.errors2 (if SITA_FRAME_DIR_RXED) */
1000 #define SITA_ERROR_RX_ABORT            (0x02)
1001 #define SITA_ERROR_RX_CD_LOST          (0x04)
1002 #define SITA_ERROR_RX_DPLL             (0x08)
1003 #define SITA_ERROR_RX_OVERRUN          (0x10)
1004 #define SITA_ERROR_RX_FRAME_LEN_VIOL   (0x20)
1005 #define SITA_ERROR_RX_CRC              (0x40)
1006 #define SITA_ERROR_RX_BREAK            (0x80)
1007
1008 #define SITA_PROTO_UNUSED              (0x00)  /* values of sita_phdr.proto */
1009 #define SITA_PROTO_BOP_LAPB            (0x01)
1010 #define SITA_PROTO_ETHERNET            (0x02)
1011 #define SITA_PROTO_ASYNC_INTIO         (0x03)
1012 #define SITA_PROTO_ASYNC_BLKIO         (0x04)
1013 #define SITA_PROTO_ALC                 (0x05)
1014 #define SITA_PROTO_UTS                 (0x06)
1015 #define SITA_PROTO_PPP_HDLC            (0x07)
1016 #define SITA_PROTO_SDLC                (0x08)
1017 #define SITA_PROTO_TOKENRING           (0x09)
1018 #define SITA_PROTO_I2C                 (0x10)
1019 #define SITA_PROTO_DPM_LINK            (0x11)
1020 #define SITA_PROTO_BOP_FRL             (0x12)
1021
1022 struct sita_phdr {
1023     guint8  sita_flags;
1024     guint8  sita_signals;
1025     guint8  sita_errors1;
1026     guint8  sita_errors2;
1027     guint8  sita_proto;
1028 };
1029
1030 /*pseudo header for Bluetooth HCI*/
1031 struct bthci_phdr {
1032     gboolean  sent;
1033     guint32   channel;
1034 };
1035
1036 #define BTHCI_CHANNEL_COMMAND  1
1037 #define BTHCI_CHANNEL_ACL      2
1038 #define BTHCI_CHANNEL_SCO      3
1039 #define BTHCI_CHANNEL_EVENT    4
1040
1041 /* pseudo header for WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR */
1042 struct btmon_phdr {
1043     guint16   adapter_id;
1044     guint16   opcode;
1045 };
1046
1047 /* pseudo header for WTAP_ENCAP_LAYER1_EVENT */
1048 struct l1event_phdr {
1049     gboolean uton;
1050 };
1051
1052 /* * I2C pseudo header */
1053 struct i2c_phdr {
1054     guint8  is_event;
1055     guint8  bus;
1056     guint32 flags;
1057 };
1058
1059 /* pseudo header for WTAP_ENCAP_GSM_UM */
1060 struct gsm_um_phdr {
1061     gboolean uplink;
1062     guint8   channel;
1063     /* The following are only populated for downlink */
1064     guint8   bsic;
1065     guint16  arfcn;
1066     guint32  tdma_frame;
1067     guint8   error;
1068     guint16  timeshift;
1069 };
1070
1071 #define GSM_UM_CHANNEL_UNKNOWN  0
1072 #define GSM_UM_CHANNEL_BCCH     1
1073 #define GSM_UM_CHANNEL_SDCCH    2
1074 #define GSM_UM_CHANNEL_SACCH    3
1075 #define GSM_UM_CHANNEL_FACCH    4
1076 #define GSM_UM_CHANNEL_CCCH     5
1077 #define GSM_UM_CHANNEL_RACH     6
1078 #define GSM_UM_CHANNEL_AGCH     7
1079 #define GSM_UM_CHANNEL_PCH      8
1080
1081 /* Pseudo-header for nstrace packets */
1082 struct nstr_phdr {
1083     gint64 rec_offset;
1084     gint32 rec_len;
1085     guint8 nicno_offset;
1086     guint8 nicno_len;
1087     guint8 dir_offset;
1088     guint8 dir_len;
1089     guint8 eth_offset;
1090     guint8 pcb_offset;
1091     guint8 l_pcb_offset;
1092     guint8 rec_type;
1093     guint8 vlantag_offset;
1094     guint8 coreid_offset;
1095     guint8 srcnodeid_offset;
1096     guint8 destnodeid_offset;
1097     guint8 clflags_offset;
1098     guint8 src_vmname_len_offset;
1099     guint8 dst_vmname_len_offset;
1100     guint8 ns_activity_offset;
1101     guint8 data_offset;
1102 };
1103
1104 /* Packet "pseudo-header" for Nokia output */
1105 struct nokia_phdr {
1106     struct eth_phdr eth;
1107     guint8 stuff[4];    /* mysterious stuff */
1108 };
1109
1110 #define LLCP_PHDR_FLAG_SENT 0
1111 struct llcp_phdr {
1112     guint8 adapter;
1113     guint8 flags;
1114 };
1115
1116 /* pseudo header for WTAP_ENCAP_LOGCAT */
1117 struct logcat_phdr {
1118     gint version;
1119 };
1120
1121 /* Packet "pseudo-header" information for Sysdig events. */
1122
1123 struct sysdig_event_phdr {
1124     guint record_type;    /* XXX match ft_specific_record_phdr so that we chain off of packet-pcapng_block for now. */
1125     int byte_order;
1126     guint16 cpu_id;
1127     /* guint32 sentinel; */
1128     guint64 timestamp; /* ns since epoch */
1129     guint64 thread_id;
1130     guint32 event_len; /* XXX dup of wtap_pkthdr.len */
1131     guint16 event_type;
1132     /* ... Event ... */
1133 };
1134
1135 /* Pseudo-header for file-type-specific records */
1136 struct ft_specific_record_phdr {
1137     guint record_type;    /* the type of record this is */
1138 };
1139
1140 union wtap_pseudo_header {
1141     struct eth_phdr     eth;
1142     struct x25_phdr     x25;
1143     struct isdn_phdr    isdn;
1144     struct atm_phdr     atm;
1145     struct ascend_phdr  ascend;
1146     struct p2p_phdr     p2p;
1147     struct ieee_802_11_phdr ieee_802_11;
1148     struct cosine_phdr  cosine;
1149     struct irda_phdr    irda;
1150     struct nettl_phdr   nettl;
1151     struct mtp2_phdr    mtp2;
1152     struct k12_phdr     k12;
1153     struct lapd_phdr    lapd;
1154     struct catapult_dct2000_phdr dct2000;
1155     struct erf_mc_phdr  erf;
1156     struct sita_phdr    sita;
1157     struct bthci_phdr   bthci;
1158     struct btmon_phdr   btmon;
1159     struct l1event_phdr l1event;
1160     struct i2c_phdr     i2c;
1161     struct gsm_um_phdr  gsm_um;
1162     struct nstr_phdr    nstr;
1163     struct nokia_phdr   nokia;
1164     struct llcp_phdr    llcp;
1165     struct logcat_phdr  logcat;
1166     struct sysdig_event_phdr sysdig_event;
1167     struct ft_specific_record_phdr ftsrec;
1168 };
1169
1170 /*
1171  * Record type values.
1172  *
1173  * This list will expand over time, so don't assume everything will
1174  * forever be one of the types listed below.
1175  *
1176  * For file-type-specific records, the "ftsrec" field of the pseudo-header
1177  * contains a file-type-specific subtype value, such as a block type for
1178  * a pcap-ng file.
1179  *
1180  * An "event" is an indication that something happened during the capture
1181  * process, such as a status transition of some sort on the network.
1182  * These should, ideally, have a time stamp and, if they're relevant to
1183  * a particular interface on a multi-interface capture, should also have
1184  * an interface ID.  The data for the event is file-type-specific and
1185  * subtype-specific.  These should be dissected and displayed just as
1186  * packets are.
1187  *
1188  * A "report" supplies information not corresponding to an event;
1189  * for example, a pcap-ng Interface Statistics Block would be a report,
1190  * as it doesn't correspond to something happening on the network.
1191  * They may have a time stamp, and should be dissected and displayed
1192  * just as packets are.
1193  *
1194  * We distingiush between "events" and "reports" so that, for example,
1195  * the packet display can show the delta between a packet and an event
1196  * but not show the delta between a packet and a report, as the time
1197  * stamp of a report may not correspond to anything interesting on
1198  * the network but the time stamp of an event would.
1199  *
1200  * XXX - are there any file-type-specific records that *shouldn't* be
1201  * dissected and displayed?  If so, they should be parsed and the
1202  * information in them stored somewhere, and used somewhere, whether
1203  * it's just used when saving the file in its native format or also
1204  * used to parse *other* file-type-specific records.
1205  */
1206 #define REC_TYPE_PACKET               0    /**< packet */
1207 #define REC_TYPE_FT_SPECIFIC_EVENT    1    /**< file-type-specific event */
1208 #define REC_TYPE_FT_SPECIFIC_REPORT   2    /**< file-type-specific report */
1209
1210 struct wtap_pkthdr {
1211     guint     rec_type;         /* what type of record is this? */
1212     guint32   presence_flags;   /* what stuff do we have? */
1213     nstime_t  ts;               /* time stamp */
1214     guint32   caplen;           /* data length in the file */
1215     guint32   len;              /* data length on the wire */
1216     int       pkt_encap;        /* WTAP_ENCAP_ value for this packet */
1217     int       pkt_tsprec;       /* WTAP_TSPREC_ value for this packet */
1218                                 /* pcapng variables */
1219     guint32   interface_id;     /* identifier of the interface. */
1220                                 /* options */
1221     gchar     *opt_comment;     /* NULL if not available */
1222     guint64   drop_count;       /* number of packets lost (by the interface and the
1223                                    operating system) between this packet and the preceding one. */
1224     guint32   pack_flags;       /* XXX - 0 for now (any value for "we don't have it"?) */
1225     Buffer    ft_specific_data; /* file-type specific data */
1226
1227     union wtap_pseudo_header  pseudo_header;
1228 };
1229
1230 /*
1231  * Bits in presence_flags, indicating which of the fields we have.
1232  *
1233  * For the time stamp, we may need some more flags to indicate
1234  * whether the time stamp is an absolute date-and-time stamp, an
1235  * absolute time-only stamp (which can make relative time
1236  * calculations tricky, as you could in theory have two time
1237  * stamps separated by an unknown number of days), or a time stamp
1238  * relative to some unspecified time in the past (see mpeg.c).
1239  *
1240  * There is no presence flag for len - there has to be *some* length
1241  * value for the packet.  (The "captured length" can be missing if
1242  * the file format doesn't report a captured length distinct from
1243  * the on-the-network length because the application(s) producing those
1244  * files don't support slicing packets.)
1245  *
1246  * There could be a presence flag for the packet encapsulation - if it's
1247  * absent, use the file encapsulation - but it's not clear that's useful;
1248  * we currently do that in the module for the file format.
1249  */
1250 #define WTAP_HAS_TS            0x00000001  /**< time stamp */
1251 #define WTAP_HAS_CAP_LEN       0x00000002  /**< captured length separate from on-the-network length */
1252 #define WTAP_HAS_INTERFACE_ID  0x00000004  /**< interface ID */
1253 #define WTAP_HAS_COMMENTS      0x00000008  /**< comments */
1254 #define WTAP_HAS_DROP_COUNT    0x00000010  /**< drop count */
1255 #define WTAP_HAS_PACK_FLAGS    0x00000020  /**< packet flags */
1256
1257 /**
1258  * Holds the option strings from pcapng:s Section Header block(SHB).
1259  */
1260 typedef struct wtapng_section_s {
1261     /* mandatory */
1262     guint64             section_length; /**< 64-bit value specifying the length in bytes of the
1263                                          *     following section.
1264                                          *     Section Length equal -1 (0xFFFFFFFFFFFFFFFF) means
1265                                          *     that the size of the section is not specified
1266                                          *   Note: if writing to a new file, this length will
1267                                          *     be invalid if anything changes, such as the other
1268                                          *     members of this struct, or the packets written.
1269                                          */
1270     /* options */
1271     gchar               *opt_comment;   /**< NULL if not available */
1272     gchar               *shb_hardware;  /**< NULL if not available
1273                                          *     UTF-8 string containing the description of the
1274                                          *     hardware used to create this section.
1275                                          */
1276     gchar               *shb_os;        /**< NULL if not available, UTF-8 string containing the
1277                                          *     name of the operating system used to create this section.
1278                                          */
1279     gchar               *shb_user_appl; /**< NULL if not available, UTF-8 string containing the
1280                                          *     name of the application used to create this section.
1281                                          */
1282 } wtapng_section_t;
1283
1284
1285 /** struct holding the information to build IDB:s
1286  *  the interface_data array holds an array of wtapng_if_descr_t
1287  *  one per interface.
1288  */
1289 typedef struct wtapng_iface_descriptions_s {
1290     GArray *interface_data;
1291 } wtapng_iface_descriptions_t;
1292
1293 /* Interface Description
1294  *
1295  * Options:
1296  *
1297  * if_name        2  A UTF-8 string containing the name of the device used to capture data.
1298  *                     "eth0" / "\Device\NPF_{AD1CE675-96D0-47C5-ADD0-2504B9126B68}" / ...
1299  *
1300  * if_description 3  A UTF-8 string containing the description of the device used
1301  *                     to capture data. "Broadcom NetXtreme" / "First Ethernet Interface" / ...
1302  *
1303  * if_IPv4addr    4  Interface network address and netmask. This option can be
1304  *                     repeated multiple times within the same Interface Description Block
1305  *                     when multiple IPv4 addresses are assigned to the interface. 192 168 1 1 255 255 255 0
1306  *
1307  * if_IPv6addr    5  Interface network address and prefix length (stored in the last byte).
1308  *                     This option can be repeated multiple times within the same Interface
1309  *                     Description Block when multiple IPv6 addresses are assigned to the interface.
1310  *                     2001:0db8:85a3:08d3:1319:8a2e:0370:7344/64 is written (in hex) as
1311  *                     "20 01 0d b8 85 a3 08 d3 13 19 8a 2e 03 70 73 44 40"
1312  *
1313  * if_MACaddr     6  Interface Hardware MAC address (48 bits). 00 01 02 03 04 05
1314  *
1315  * if_EUIaddr     7  Interface Hardware EUI address (64 bits), if available. TODO: give a good example
1316  *
1317  * if_speed       8  Interface speed (in bps). 100000000 for 100Mbps
1318  *
1319  * if_tsresol     9  Resolution of timestamps. If the Most Significant Bit is equal to zero,
1320  *                     the remaining bits indicates the resolution of the timestamp as as a
1321  *                     negative power of 10 (e.g. 6 means microsecond resolution, timestamps
1322  *                     are the number of microseconds since 1/1/1970). If the Most Significant Bit
1323  *                     is equal to one, the remaining bits indicates the resolution has a
1324  *                     negative power of 2 (e.g. 10 means 1/1024 of second).
1325  *                     If this option is not present, a resolution of 10^-6 is assumed
1326  *                     (i.e. timestamps have the same resolution of the standard 'libpcap' timestamps). 6
1327  *
1328  * if_tzone      10  Time zone for GMT support (TODO: specify better). TODO: give a good example
1329  *
1330  * if_filter     11  The filter (e.g. "capture only TCP traffic") used to capture traffic.
1331  *                     The first byte of the Option Data keeps a code of the filter used
1332  *                     (e.g. if this is a libpcap string, or BPF bytecode, and more).
1333  *                     More details about this format will be presented in Appendix XXX (TODO).
1334  *                     (TODO: better use different options for different fields?
1335  *                     e.g. if_filter_pcap, if_filter_bpf, ...) 00 "tcp port 23 and host 10.0.0.5"
1336  *
1337  * if_os         12  A UTF-8 string containing the name of the operating system of the
1338  *                     machine in which this interface is installed.
1339  *                     This can be different from the same information that can be
1340  *                     contained by the Section Header Block
1341  *                     (Section 3.1 (Section Header Block (mandatory))) because
1342  *                     the capture can have been done on a remote machine.
1343  *                     "Windows XP SP2" / "openSUSE 10.2" / ...
1344  *
1345  * if_fcslen     13  An integer value that specified the length of the
1346  *                     Frame Check Sequence (in bits) for this interface.
1347  *                     For link layers whose FCS length can change during time,
1348  *                     the Packet Block Flags Word can be used (see Appendix A (Packet Block Flags Word)). 4
1349  *
1350  * if_tsoffset   14  A 64 bits integer value that specifies an offset (in seconds)
1351  *                     that must be added to the timestamp of each packet to obtain
1352  *                     the absolute timestamp of a packet. If the option is missing,
1353  *                     the timestamps stored in the packet must be considered absolute
1354  *                     timestamps. The time zone of the offset can be specified with the
1355  *                     option if_tzone. TODO: won't a if_tsoffset_low for fractional
1356  *                     second offsets be useful for highly syncronized capture systems? 1234
1357  */
1358 /**
1359  * Interface description data
1360  */
1361 typedef struct wtapng_if_descr_s {
1362     int                    wtap_encap;            /**< link_type translated to wtap_encap */
1363     guint64                time_units_per_second;
1364     int                    tsprecision;           /**< WTAP_TSPREC_ value for this interface */
1365
1366     /* mandatory */
1367     guint16                link_type;
1368     guint32                snap_len;
1369
1370     /* options */
1371     gchar                 *opt_comment;           /**< NULL if not available */
1372     gchar                 *if_name;               /**< NULL if not available
1373                                                    *  opt 2
1374                                                    *     A UTF-8 string containing the name of the
1375                                                    *     device used to capture data.
1376                                                    */
1377     gchar                 *if_description;        /**< NULL if not available
1378                                                    *  opt 3
1379                                                    *     A UTF-8 string containing the description
1380                                                    *     of the device used to capture data.
1381                                                    */
1382
1383     /* XXX: if_IPv4addr opt 4  Interface network address and netmask.                                */
1384     /* XXX: if_IPv6addr opt 5  Interface network address and prefix length (stored in the last byte).*/
1385     /* XXX: if_MACaddr  opt 6  Interface Hardware MAC address (48 bits).                             */
1386     /* XXX: if_EUIaddr  opt 7  Interface Hardware EUI address (64 bits)                              */
1387
1388     guint64                if_speed;              /**< 0xFFFFFFFF if unknown
1389                                                    *  opt 8
1390                                                    *     Interface speed (in bps). 100000000 for 100Mbps
1391                                                    */
1392     guint8                 if_tsresol;            /**< default is 6 for microsecond resolution
1393                                                    *  opt 9
1394                                                    *     Resolution of timestamps.
1395                                                    *     If the Most Significant Bit is equal to zero,
1396                                                    *     the remaining bits indicates the resolution of the
1397                                                    *     timestamp as as a negative power of 10
1398                                                    */
1399
1400     /* XXX: if_tzone      10  Time zone for GMT support (TODO: specify better). */
1401
1402     gchar                 *if_filter_str;         /**< NULL if not available
1403                                                    *  opt 11  libpcap string.
1404                                                    */
1405     guint16                bpf_filter_len;        /** Opt 11 variant II BPF filter len 0 if not used*/
1406     gchar                 *if_filter_bpf_bytes;   /** Opt 11 BPF filter or NULL */
1407     gchar                 *if_os;                 /**< NULL if not available
1408                                                    *     12  A UTF-8 string containing the name of the
1409                                                    *     operating system of the machine in which this
1410                                                    *     interface is installed.
1411                                                    */
1412     gint8                  if_fcslen;             /**< -1 if unknown or changes between packets,
1413                                                    *  opt 13
1414                                                    *     An integer value that specified the length of
1415                                                    *     the Frame Check Sequence (in bits) for this interface. */
1416     /* XXX: guint64    if_tsoffset; opt 14  A 64 bits integer value that specifies an offset (in seconds)...*/
1417     guint8                 num_stat_entries;
1418     GArray                *interface_statistics;  /**< An array holding the interface statistics from
1419                                                    *     pcapng ISB:s or equivalent(?)*/
1420 } wtapng_if_descr_t;
1421
1422
1423 /**
1424  * Interface Statistics. pcap-ng Interface Statistics Block (ISB).
1425  */
1426 typedef struct wtapng_if_stats_s {
1427     /* mandatory */
1428     guint32  interface_id;
1429     guint32  ts_high;
1430     guint32  ts_low;
1431     /* options */
1432     gchar   *opt_comment;       /**< NULL if not available */
1433     guint64  isb_starttime;
1434     guint64  isb_endtime;
1435     guint64  isb_ifrecv;
1436     guint64  isb_ifdrop;
1437     guint64  isb_filteraccept;
1438     guint64  isb_osdrop;
1439     guint64  isb_usrdeliv;
1440 } wtapng_if_stats_t;
1441
1442
1443 /* Name Resolution, pcap-ng Name Resolution Block (NRB). */
1444 typedef struct wtapng_name_res_s {
1445     /* options */
1446     gchar  *opt_comment;    /**< NULL if not available */
1447     /* XXX */
1448 } wtapng_name_res_t;
1449
1450 #ifndef MAXNAMELEN
1451 #define MAXNAMELEN      64      /* max name length (hostname and port name) */
1452 #endif
1453
1454 typedef struct hashipv4 {
1455     guint             addr;
1456     guint8            flags;          /* B0 dummy_entry, B1 resolve, B2 If the address is used in the trace */
1457     gchar             ip[16];
1458     gchar             name[MAXNAMELEN];
1459 } hashipv4_t;
1460
1461 typedef struct hashipv6 {
1462     guint8            addr[16];
1463     guint8            flags;          /* B0 dummy_entry, B1 resolve, B2 If the address is used in the trace */
1464     gchar             ip6[40];
1465     gchar             name[MAXNAMELEN];
1466 } hashipv6_t;
1467
1468 /** A struct with lists of resolved addresses.
1469  *  Used when writing name resoultion blocks (NRB)
1470  */
1471 typedef struct addrinfo_lists {
1472     GList      *ipv4_addr_list; /**< A list of resolved hashipv4_t*/
1473     GList      *ipv6_addr_list; /**< A list of resolved hashipv6_t*/
1474 } addrinfo_lists_t;
1475
1476 struct wtap_dumper;
1477
1478 typedef struct wtap wtap;
1479 typedef struct wtap_dumper wtap_dumper;
1480
1481 typedef struct wtap_reader *FILE_T;
1482
1483 /* Similar to the wtap_open_routine_info for open routines, the following
1484  * wtap_wslua_file_info struct is used by wslua code for Lua-based file writers.
1485  *
1486  * This concept is necessary because when wslua goes to invoke the
1487  * registered dump/write_open routine callback in Lua, it needs the ref number representing
1488  * the hooked function inside Lua.  This will be stored in the thing pointed to
1489  * by the void* data here.  This 'data' pointer will be copied into the
1490  * wtap_dumper struct's 'void* data' member when calling the dump_open function,
1491  * which is how wslua finally retrieves it.  Unlike wtap_dumper's 'priv' member, its
1492  * 'data' member is not free'd in wtap_dump_close().
1493  */
1494 typedef struct wtap_wslua_file_info {
1495     int (*wslua_can_write_encap)(int, void*);   /* a can_write_encap func for wslua uses */
1496     void* wslua_data;                           /* holds the wslua data */
1497 } wtap_wslua_file_info_t;
1498
1499 /*
1500  * For registering extensions used for capture file formats.
1501  *
1502  * These items are used in dialogs for opening files, so that
1503  * the user can ask to see all capture files (as identified
1504  * by file extension) or particular types of capture files.
1505  *
1506  * Each file type has a description and a list of extensions the file
1507  * might have.  Some file types aren't real file types, they're
1508  * just generic types, such as "text file" or "XML file", that can
1509  * be used for, among other things, captures we can read, or for
1510  * extensions such as ".cap" that were unimaginatively chosen by
1511  * several different sniffers for their file formats.
1512  */
1513 struct file_extension_info {
1514     /* the file type name */
1515     const char *name;
1516
1517     /* a semicolon-separated list of file extensions used for this type */
1518     const char *extensions;
1519 };
1520
1521 /*
1522  * For registering file types that we can open.
1523  *
1524  * Each file type has an open routine and an optional list of extensions
1525  * the file might have.
1526  *
1527  * The open routine should return:
1528  *
1529  *      WTAP_OPEN_ERROR on an I/O error;
1530  *
1531  *      WTAP_OPEN_MINE if the file it's reading is one of the types
1532  *      it handles;
1533  *
1534  *      WTAP_OPEN_NOT_MINE if the file it's reading isn't one of the
1535  *      types it handles.
1536  *
1537  * If the routine handles this type of file, it should set the "file_type"
1538  * field in the "struct wtap" to the type of the file.
1539  *
1540  * Note that the routine does not have to free the private data pointer on
1541  * error. The caller takes care of that by calling wtap_close on error.
1542  * (See https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8518)
1543  *
1544  * However, the caller does have to free the private data pointer when
1545  * returning WTAP_OPEN_NOT_MINE, since the next file type will be called
1546  * and will likely just overwrite the pointer.
1547  */
1548 typedef enum {
1549     WTAP_OPEN_NOT_MINE = 0,
1550     WTAP_OPEN_MINE = 1,
1551     WTAP_OPEN_ERROR = -1
1552 } wtap_open_return_val;
1553
1554 typedef wtap_open_return_val (*wtap_open_routine_t)(struct wtap*, int *,
1555     char **);
1556
1557 /*
1558  * Some file formats have defined magic numbers at fixed offsets from
1559  * the beginning of the file; those routines should return 1 if and
1560  * only if the file has the magic number at that offset.  (pcap-ng
1561  * is a bit of a special case, as it has both the Section Header Block
1562  * type field and its byte-order magic field; it checks for both.)
1563  * Those file formats do not require a file name extension in order
1564  * to recognize them or to avoid recognizing other file types as that
1565  * type, and have no extensions specified for them.
1566  *
1567  * Other file formats don't have defined magic numbers at fixed offsets,
1568  * so a heuristic is required.  If that file format has any file name
1569  * extensions used for it, a list of those extensions should be
1570  * specified, so that, if the name of the file being opened has an
1571  * extension, the file formats that use that extension are tried before
1572  * the ones that don't, to handle the case where a file of one type
1573  * might be recognized by the heuristics for a different file type.
1574  */
1575
1576 typedef enum {
1577     OPEN_INFO_MAGIC = 0,
1578     OPEN_INFO_HEURISTIC = 1
1579 } wtap_open_type;
1580
1581 WS_DLL_PUBLIC void init_open_routines(void);
1582
1583 struct open_info {
1584     const char *name;
1585     wtap_open_type type;
1586     wtap_open_routine_t open_routine;
1587     const char *extensions;
1588     gchar **extensions_set; /* populated using extensions member during initialization */
1589     void* wslua_data; /* should be NULL for C-code file readers */
1590 };
1591 WS_DLL_PUBLIC struct open_info *open_routines;
1592
1593 /*
1594  * Types of comments.
1595  */
1596 #define WTAP_COMMENT_PER_SECTION        0x00000001      /* per-file/per-file-section */
1597 #define WTAP_COMMENT_PER_INTERFACE      0x00000002      /* per-interface */
1598 #define WTAP_COMMENT_PER_PACKET         0x00000004      /* per-packet */
1599
1600 struct file_type_subtype_info {
1601     /* the file type name */
1602     /* should be NULL for all "pseudo" types that are only internally used and not read/writeable */
1603     const char *name;
1604
1605     /* the file type short name, used as a shortcut for the command line tools */
1606     /* should be NULL for all "pseudo" types that are only internally used and not read/writeable */
1607     const char *short_name;
1608
1609     /* the default file extension, used to save this type */
1610     /* should be NULL if no default extension is known */
1611     const char *default_file_extension;
1612
1613     /* a semicolon-separated list of additional file extensions */
1614     /* used for this type */
1615     /* should be NULL if no extensions, or no extensions other */
1616     /* than the default extension, are known */
1617     const char *additional_file_extensions;
1618
1619     /* when writing this file format, is seeking required? */
1620     gboolean writing_must_seek;
1621
1622     /* does this type support name resolution records? */
1623     /* should be FALSE is this file type doesn't support name resolution records */
1624     gboolean has_name_resolution;
1625
1626     /* what types of comment does this file support? */
1627     guint32 supported_comment_types;
1628
1629     /* can this type write this encapsulation format? */
1630     /* should be NULL is this file type doesn't have write support */
1631     int (*can_write_encap)(int);
1632
1633     /* the function to open the capture file for writing */
1634     /* should be NULL is this file type don't have write support */
1635     int (*dump_open)(wtap_dumper *, int *);
1636
1637     /* if can_write_encap returned WTAP_ERR_CHECK_WSLUA, then this is used instead */
1638     /* this should be NULL for everyone except Lua-based file writers */
1639     wtap_wslua_file_info_t *wslua_info;
1640 };
1641
1642 #define WTAP_TYPE_AUTO 0
1643
1644 /** On failure, "wtap_open_offline()" returns NULL, and puts into the
1645  * "int" pointed to by its second argument:
1646  *
1647  * @param filename Name of the file to open
1648  * @param type WTAP_TYPE_AUTO for automatic recognize file format or explicit choose format type
1649  * @param err a positive "errno" value if the capture file can't be opened;
1650  * a negative number, indicating the type of error, on other failures.
1651  * @param err_info for some errors, a string giving more details of
1652  * the error
1653  * @param do_random TRUE if random access to the file will be done,
1654  * FALSE if not
1655  */
1656 WS_DLL_PUBLIC
1657 struct wtap* wtap_open_offline(const char *filename, unsigned int type, int *err,
1658     gchar **err_info, gboolean do_random);
1659
1660 /**
1661  * If we were compiled with zlib and we're at EOF, unset EOF so that
1662  * wtap_read/gzread has a chance to succeed. This is necessary if
1663  * we're tailing a file.
1664  */
1665 WS_DLL_PUBLIC
1666 void wtap_cleareof(wtap *wth);
1667
1668 /**
1669  * Set callback functions to add new hostnames. Currently pcapng-only.
1670  * MUST match add_ipv4_name and add_ipv6_name in addr_resolv.c.
1671  */
1672 typedef void (*wtap_new_ipv4_callback_t) (const guint addr, const gchar *name);
1673 WS_DLL_PUBLIC
1674 void wtap_set_cb_new_ipv4(wtap *wth, wtap_new_ipv4_callback_t add_new_ipv4);
1675
1676 typedef void (*wtap_new_ipv6_callback_t) (const void *addrp, const gchar *name);
1677 WS_DLL_PUBLIC
1678 void wtap_set_cb_new_ipv6(wtap *wth, wtap_new_ipv6_callback_t add_new_ipv6);
1679
1680 /** Returns TRUE if read was successful. FALSE if failure. data_offset is
1681  * set to the offset in the file where the data for the read packet is
1682  * located. */
1683 WS_DLL_PUBLIC
1684 gboolean wtap_read(wtap *wth, int *err, gchar **err_info,
1685     gint64 *data_offset);
1686
1687 WS_DLL_PUBLIC
1688 gboolean wtap_seek_read (wtap *wth, gint64 seek_off,
1689         struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
1690
1691 /*** get various information snippets about the current packet ***/
1692 WS_DLL_PUBLIC
1693 struct wtap_pkthdr *wtap_phdr(wtap *wth);
1694 WS_DLL_PUBLIC
1695 guint8 *wtap_buf_ptr(wtap *wth);
1696
1697 /*** initialize a wtap_pkthdr structure ***/
1698 WS_DLL_PUBLIC
1699 void wtap_phdr_init(struct wtap_pkthdr *phdr);
1700
1701 /*** clean up a wtap_pkthdr structure, freeing what wtap_phdr_init() allocated */
1702 WS_DLL_PUBLIC
1703 void wtap_phdr_cleanup(struct wtap_pkthdr *phdr);
1704
1705 /*** get various information snippets about the current file ***/
1706
1707 /** Return an approximation of the amount of data we've read sequentially
1708  * from the file so far. */
1709 WS_DLL_PUBLIC
1710 gint64 wtap_read_so_far(wtap *wth);
1711 WS_DLL_PUBLIC
1712 gint64 wtap_file_size(wtap *wth, int *err);
1713 WS_DLL_PUBLIC
1714 gboolean wtap_iscompressed(wtap *wth);
1715 WS_DLL_PUBLIC
1716 guint wtap_snapshot_length(wtap *wth); /* per file */
1717 WS_DLL_PUBLIC
1718 int wtap_file_type_subtype(wtap *wth);
1719 WS_DLL_PUBLIC
1720 int wtap_file_encap(wtap *wth);
1721 WS_DLL_PUBLIC
1722 int wtap_file_tsprec(wtap *wth);
1723
1724 /**
1725  * @brief Gets existing section header block, not for new file.
1726  * @details Returns the pointer to the existing SHB, without creating a
1727  *          new one. This should only be used for accessing info, not
1728  *          for creating a new file based on existing SHB info. Use
1729  *          wtap_file_get_shb_for_new_file() for that.
1730  *
1731  * @param wth The wiretap session.
1732  * @return The existing section header, which must NOT be g_free'd.
1733  */
1734 WS_DLL_PUBLIC
1735 const wtapng_section_t* wtap_file_get_shb(wtap *wth);
1736
1737 /**
1738  * @brief Gets new section header block for new file, based on existing info.
1739  * @details Creates a new wtapng_section_t section header block and only
1740  *          copies appropriate members of the SHB for a new file. In
1741  *          particular, the comment string is copied, and any custom options
1742  *          which should be copied are copied. The os, hardware, and
1743  *          application strings are *not* copied.
1744  *
1745  * @note Use wtap_free_shb() to free the returned section header.
1746  *
1747  * @param wth The wiretap session.
1748  * @return The new section header, which must be wtap_free_shb'd.
1749  */
1750 WS_DLL_PUBLIC
1751 wtapng_section_t* wtap_file_get_shb_for_new_file(wtap *wth);
1752
1753 /**
1754  * Free's a section header block and all of its members.
1755  */
1756 WS_DLL_PUBLIC
1757 void wtap_free_shb(wtapng_section_t *shb_hdr);
1758
1759 /**
1760  * @brief Gets the section header comment string.
1761  * @details This gets the pointer, without duplicating the string.
1762  *
1763  * @param wth The wtap session.
1764  * @return The comment string.
1765  */
1766 WS_DLL_PUBLIC
1767 const gchar* wtap_file_get_shb_comment(wtap *wth);
1768
1769 /**
1770  * @brief Sets or replaces the section header comment.
1771  * @details The passed-in comment string is set to be the comment
1772  *          for the section header block. The passed-in string's
1773  *          ownership will be owned by the block, so it should be
1774  *          duplicated before passing into this function.
1775  *
1776  * @param wth The wiretap session.
1777  * @param comment The comment string.
1778  */
1779 WS_DLL_PUBLIC
1780 void wtap_write_shb_comment(wtap *wth, gchar *comment);
1781
1782 /**
1783  * @brief Gets existing interface descriptions.
1784  * @details Returns a new struct containing a pointer to the existing
1785  *          description, without creating new descriptions internally.
1786  * @note The returned pointer must be g_free'd, but its internal
1787  *       interface_data must not.
1788  *
1789  * @param wth The wiretap session.
1790  * @return A new struct of the existing section descriptions, which must be g_free'd.
1791  */
1792 WS_DLL_PUBLIC
1793 wtapng_iface_descriptions_t *wtap_file_get_idb_info(wtap *wth);
1794
1795 /**
1796  * @brief Free's a interface description block and all of its members.
1797  *
1798  * @details This free's all of the interface descriptions inside the passed-in
1799  *     struct, including their members (e.g., comments); and then free's the
1800  *     passed-in struct as well.
1801  *
1802  * @warning Do not use this for the struct returned by
1803  *     wtap_file_get_idb_info(), as that one did not create the internal
1804  *     interface descriptions; for that case you can simply g_free() the new
1805  *     struct.
1806  */
1807 WS_DLL_PUBLIC
1808 void wtap_free_idb_info(wtapng_iface_descriptions_t *idb_info);
1809
1810 /**
1811  * @brief Gets a debug string of an interface description.
1812  * @details Returns a newly allocated string of debug information about
1813  *          the given interface descrption, useful for debugging.
1814  * @note The returned pointer must be g_free'd.
1815  *
1816  * @param if_descr The interface description.
1817  * @param indent Number of spaces to indent each line by.
1818  * @param line_end A string to append to each line (e.g., "\n" or ", ").
1819  * @return A newly allocated gcahr array string, which must be g_free'd.
1820  */
1821 WS_DLL_PUBLIC
1822 gchar *wtap_get_debug_if_descr(const wtapng_if_descr_t *if_descr,
1823                                const int indent,
1824                                const char* line_end);
1825
1826 /**
1827  * @brief Gets new name resolution info for new file, based on existing info.
1828  * @details Creates a new wtapng_name_res_t name resolution info and only
1829  *          copies appropriate members for a new file.
1830  *
1831  * @note Use wtap_free_nrb() to free the returned pointer.
1832  *
1833  * @param wth The wiretap session.
1834  * @return The new name resolution info, which must be wtap_free_nrb'd.
1835  */
1836 WS_DLL_PUBLIC
1837 wtapng_name_res_t* wtap_file_get_nrb_for_new_file(wtap *wth);
1838
1839 /**
1840  * Free's the name resolution info and all of its members.
1841  */
1842 WS_DLL_PUBLIC
1843 void wtap_free_nrb(wtapng_name_res_t *nrb_hdr);
1844
1845 /**
1846  * @brief Gets the name resolution comment, if any.
1847  * @details This retrieves the name resolution comment string pointer,
1848  *          possibly NULL.
1849  *
1850  * @param wth The wiretap session.
1851  * @return The comment string.
1852  */
1853 WS_DLL_PUBLIC
1854 const gchar* wtap_get_nrb_comment(wtap *wth);
1855
1856 /**
1857  * @brief Sets or replaces the name resolution comment.
1858  * @details The passed-in comment string is set to be the comment
1859  *          for the name resolution block. The passed-in string's
1860  *          ownership will be owned by the block, so it should be
1861  *          duplicated before passing into this function.
1862  *
1863  * @param wth The wiretap session.
1864  * @param comment The comment string.
1865  */
1866 WS_DLL_PUBLIC
1867 void wtap_write_nrb_comment(wtap *wth, gchar *comment);
1868
1869 /*** close the file descriptors for the current file ***/
1870 WS_DLL_PUBLIC
1871 void wtap_fdclose(wtap *wth);
1872
1873 /*** reopen the random file descriptor for the current file ***/
1874 WS_DLL_PUBLIC
1875 gboolean wtap_fdreopen(wtap *wth, const char *filename, int *err);
1876
1877 /*** close the current file ***/
1878 WS_DLL_PUBLIC
1879 void wtap_sequential_close(wtap *wth);
1880 WS_DLL_PUBLIC
1881 void wtap_close(wtap *wth);
1882
1883 /*** dump packets into a capture file ***/
1884 WS_DLL_PUBLIC
1885 gboolean wtap_dump_can_open(int filetype);
1886
1887 /**
1888  * Given a GArray of WTAP_ENCAP_ types, return the per-file encapsulation
1889  * type that would be needed to write out a file with those types.
1890  */
1891 WS_DLL_PUBLIC
1892 int wtap_dump_file_encap_type(const GArray *file_encaps);
1893
1894 /**
1895  * Return TRUE if we can write this capture file format out in
1896  * compressed form, FALSE if not.
1897  */
1898 WS_DLL_PUBLIC
1899 gboolean wtap_dump_can_compress(int filetype);
1900
1901 /**
1902  * Return TRUE if this capture file format supports storing name
1903  * resolution information in it, FALSE if not.
1904  */
1905 WS_DLL_PUBLIC
1906 gboolean wtap_dump_has_name_resolution(int filetype);
1907
1908 /**
1909  * Return TRUE if this capture file format supports all the comment
1910  * types specified, FALSE if not.
1911  */
1912 WS_DLL_PUBLIC
1913 gboolean wtap_dump_supports_comment_types(int filetype, guint32 comment_types);
1914
1915 WS_DLL_PUBLIC
1916 wtap_dumper* wtap_dump_open(const char *filename, int file_type_subtype, int encap,
1917     int snaplen, gboolean compressed, int *err);
1918
1919 /**
1920  * @brief Opens a new capture file for writing.
1921  *
1922  * @note The shb_hdr, idb_inf, and nrb_hdr arguments will be used until
1923  *     wtap_dump_close() is called, but will not be free'd by the dumper. If
1924  *     you created them, you must free them yourself after wtap_dump_close().
1925  *
1926  * @param filename The new file's name.
1927  * @param file_type_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type.
1928  * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi)
1929  * @param snaplen The maximum packet capture length.
1930  * @param compressed True if file should be compressed.
1931  * @param shb_hdr The section header block information, or NULL.
1932  * @param idb_inf The interface description information, or NULL.
1933  * @param nrb_hdr The name resolution comment/custom_opts information, or NULL.
1934  * @param[out] err Will be set to an error code on failure.
1935  * @return The newly created dumper object, or NULL on failure.
1936  */
1937 WS_DLL_PUBLIC
1938 wtap_dumper* wtap_dump_open_ng(const char *filename, int file_type_subtype, int encap,
1939     int snaplen, gboolean compressed, wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf,
1940     wtapng_name_res_t *nrb_hdr, int *err);
1941
1942 WS_DLL_PUBLIC
1943 wtap_dumper* wtap_dump_open_tempfile(char **filenamep, const char *pfx,
1944     int file_type_subtype, int encap, int snaplen, gboolean compressed,
1945     int *err);
1946
1947 /**
1948  * @brief Creates a dumper for a temporary file.
1949  *
1950  * @note The shb_hdr, idb_inf, and nrb_hdr arguments will be used until
1951  *     wtap_dump_close() is called, but will not be free'd by the dumper. If
1952  *     you created them, you must free them yourself after wtap_dump_close().
1953  *
1954  * @param filenamep Points to a pointer that's set to point to the
1955  *        pathname of the temporary file; it's allocated with g_malloc()
1956  * @param pfx A string to be used as the prefix for the temporary file name
1957  * @param file_type_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type.
1958  * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi)
1959  * @param snaplen The maximum packet capture length.
1960  * @param compressed True if file should be compressed.
1961  * @param shb_hdr The section header block information, or NULL.
1962  * @param idb_inf The interface description information, or NULL.
1963  * @param nrb_hdr The name resolution comment/custom_opts information, or NULL.
1964  * @param[out] err Will be set to an error code on failure.
1965  * @return The newly created dumper object, or NULL on failure.
1966  */
1967 WS_DLL_PUBLIC
1968 wtap_dumper* wtap_dump_open_tempfile_ng(char **filenamep, const char *pfx,
1969     int file_type_subtype, int encap, int snaplen, gboolean compressed,
1970     wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf,
1971     wtapng_name_res_t *nrb_hdr, int *err);
1972
1973 WS_DLL_PUBLIC
1974 wtap_dumper* wtap_dump_fdopen(int fd, int file_type_subtype, int encap, int snaplen,
1975     gboolean compressed, int *err);
1976
1977 /**
1978  * @brief Creates a dumper for an existing file descriptor.
1979  *
1980  * @note The shb_hdr, idb_inf, and nrb_hdr arguments will be used until
1981  *     wtap_dump_close() is called, but will not be free'd by the dumper. If
1982  *     you created them, you must free them yourself after wtap_dump_close().
1983  *
1984  * @param fd The file descriptor for which the dumper should be created.
1985  * @param file_type_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type.
1986  * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi)
1987  * @param snaplen The maximum packet capture length.
1988  * @param compressed True if file should be compressed.
1989  * @param shb_hdr The section header block information, or NULL.
1990  * @param idb_inf The interface description information, or NULL.
1991  * @param nrb_hdr The name resolution comment/custom_opts information, or NULL.
1992  * @param[out] err Will be set to an error code on failure.
1993  * @return The newly created dumper object, or NULL on failure.
1994  */
1995 WS_DLL_PUBLIC
1996 wtap_dumper* wtap_dump_fdopen_ng(int fd, int file_type_subtype, int encap, int snaplen,
1997                 gboolean compressed, wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf,
1998                 wtapng_name_res_t *nrb_hdr, int *err);
1999
2000 WS_DLL_PUBLIC
2001 wtap_dumper* wtap_dump_open_stdout(int file_type_subtype, int encap, int snaplen,
2002     gboolean compressed, int *err);
2003
2004 /**
2005  * @brief Creates a dumper for the standard output.
2006  *
2007  * @note The shb_hdr, idb_inf, and nrb_hdr arguments will be used until
2008  *     wtap_dump_close() is called, but will not be free'd by the dumper. If
2009  *     you created them, you must free them yourself after wtap_dump_close().
2010  *
2011  * @param file_type_subtype The WTAP_FILE_TYPE_SUBTYPE_XXX file type.
2012  * @param encap The WTAP_ENCAP_XXX encapsulation type (WTAP_ENCAP_PER_PACKET for multi)
2013  * @param snaplen The maximum packet capture length.
2014  * @param compressed True if file should be compressed.
2015  * @param shb_hdr The section header block information, or NULL.
2016  * @param idb_inf The interface description information, or NULL.
2017  * @param nrb_hdr The name resolution comment/custom_opts information, or NULL.
2018  * @param[out] err Will be set to an error code on failure.
2019  * @return The newly created dumper object, or NULL on failure.
2020  */
2021 WS_DLL_PUBLIC
2022 wtap_dumper* wtap_dump_open_stdout_ng(int file_type_subtype, int encap, int snaplen,
2023                 gboolean compressed, wtapng_section_t *shb_hdr, wtapng_iface_descriptions_t *idb_inf,
2024                 wtapng_name_res_t *nrb_hdr, int *err);
2025
2026 WS_DLL_PUBLIC
2027 gboolean wtap_dump(wtap_dumper *, const struct wtap_pkthdr *, const guint8 *,
2028      int *err, gchar **err_info);
2029 WS_DLL_PUBLIC
2030 void wtap_dump_flush(wtap_dumper *);
2031 WS_DLL_PUBLIC
2032 gint64 wtap_get_bytes_dumped(wtap_dumper *);
2033 WS_DLL_PUBLIC
2034 void wtap_set_bytes_dumped(wtap_dumper *wdh, gint64 bytes_dumped);
2035 struct addrinfo;
2036 WS_DLL_PUBLIC
2037 gboolean wtap_dump_set_addrinfo_list(wtap_dumper *wdh, addrinfo_lists_t *addrinfo_lists);
2038 WS_DLL_PUBLIC
2039 gboolean wtap_dump_close(wtap_dumper *, int *);
2040
2041 /**
2042  * Return TRUE if we can write a file out with the given GArray of file
2043  * encapsulations and the given bitmask of comment types.
2044  */
2045 WS_DLL_PUBLIC
2046 gboolean wtap_dump_can_write(const GArray *file_encaps, guint32 required_comment_types);
2047
2048 /**
2049  * Get a GArray of WTAP_FILE_TYPE_SUBTYPE_ values for file types/subtypes
2050  * that can be used to save a file of a given type with a given GArray of
2051  * WTAP_ENCAP_ types and the given bitmask of comment types.
2052  */
2053 WS_DLL_PUBLIC
2054 GArray *wtap_get_savable_file_types_subtypes(int file_type,
2055     const GArray *file_encaps, guint32 required_comment_types);
2056
2057 /*** various string converter functions ***/
2058 WS_DLL_PUBLIC
2059 const char *wtap_file_type_subtype_string(int file_type_subtype);
2060 WS_DLL_PUBLIC
2061 const char *wtap_file_type_subtype_short_string(int file_type_subtype);
2062 WS_DLL_PUBLIC
2063 int wtap_short_string_to_file_type_subtype(const char *short_name);
2064
2065 /*** various file extension functions ***/
2066 WS_DLL_PUBLIC
2067 GSList *wtap_get_all_file_extensions_list(void);
2068 WS_DLL_PUBLIC
2069 const char *wtap_default_file_extension(int filetype);
2070 WS_DLL_PUBLIC
2071 GSList *wtap_get_file_extensions_list(int filetype, gboolean include_compressed);
2072 WS_DLL_PUBLIC
2073 void wtap_free_extensions_list(GSList *extensions);
2074
2075 WS_DLL_PUBLIC
2076 const char *wtap_encap_string(int encap);
2077 WS_DLL_PUBLIC
2078 const char *wtap_encap_short_string(int encap);
2079 WS_DLL_PUBLIC
2080 int wtap_short_string_to_encap(const char *short_name);
2081
2082 WS_DLL_PUBLIC
2083 const char* wtap_tsprec_string(int tsprec);
2084
2085 WS_DLL_PUBLIC
2086 const char *wtap_strerror(int err);
2087
2088 /*** get available number of file types and encapsulations ***/
2089 WS_DLL_PUBLIC
2090 int wtap_get_num_file_type_extensions(void);
2091 WS_DLL_PUBLIC
2092 int wtap_get_num_encap_types(void);
2093 WS_DLL_PUBLIC
2094 int wtap_get_num_file_types_subtypes(void);
2095
2096 /*** get information for file type extension ***/
2097 WS_DLL_PUBLIC
2098 const char *wtap_get_file_extension_type_name(int extension_type);
2099 WS_DLL_PUBLIC
2100 GSList *wtap_get_file_extension_type_extensions(guint extension_type);
2101
2102 /*** dynamically register new file types and encapsulations ***/
2103 WS_DLL_PUBLIC
2104 void wtap_register_plugin_types(void);
2105 WS_DLL_PUBLIC
2106 void register_all_wiretap_modules(void);
2107 WS_DLL_PUBLIC
2108 void wtap_register_file_type_extension(const struct file_extension_info *ei);
2109
2110 WS_DLL_PUBLIC
2111 void wtap_register_open_info(struct open_info *oi, const gboolean first_routine);
2112 WS_DLL_PUBLIC
2113 gboolean wtap_has_open_info(const gchar *name);
2114 WS_DLL_PUBLIC
2115 void wtap_deregister_open_info(const gchar *name);
2116
2117 WS_DLL_PUBLIC
2118 unsigned int open_info_name_to_type(const char *name);
2119 WS_DLL_PUBLIC
2120 int wtap_register_file_type_subtypes(const struct file_type_subtype_info* fi, const int subtype);
2121 WS_DLL_PUBLIC
2122 void wtap_deregister_file_type_subtype(const int file_type_subtype);
2123
2124 WS_DLL_PUBLIC
2125 int wtap_register_encap_type(const char* name, const char* short_name);
2126
2127
2128 /**
2129  * Wiretap error codes.
2130  */
2131 #define WTAP_ERR_NOT_REGULAR_FILE              -1
2132     /** The file being opened for reading isn't a plain file (or pipe) */
2133
2134 #define WTAP_ERR_RANDOM_OPEN_PIPE              -2
2135     /** The file is being opened for random access and it's a pipe */
2136
2137 #define WTAP_ERR_FILE_UNKNOWN_FORMAT           -3
2138     /** The file being opened is not a capture file in a known format */
2139
2140 #define WTAP_ERR_UNSUPPORTED                   -4
2141     /** Supported file type, but there's something in the file we
2142        can't support */
2143
2144 #define WTAP_ERR_CANT_WRITE_TO_PIPE            -5
2145     /** Wiretap can't save to a pipe in the specified format */
2146
2147 #define WTAP_ERR_CANT_OPEN                     -6
2148     /** The file couldn't be opened, reason unknown */
2149
2150 #define WTAP_ERR_UNWRITABLE_FILE_TYPE          -7
2151     /** Wiretap can't save files in the specified format */
2152
2153 #define WTAP_ERR_UNWRITABLE_ENCAP              -8
2154     /** Wiretap can't read or save files in the specified format with the
2155        specified encapsulation */
2156
2157 #define WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED  -9
2158     /** The specified format doesn't support per-packet encapsulations */
2159
2160 #define WTAP_ERR_CANT_WRITE                   -10
2161     /** An attempt to read failed, reason unknown */
2162
2163 #define WTAP_ERR_CANT_CLOSE                   -11
2164     /** The file couldn't be closed, reason unknown */
2165
2166 #define WTAP_ERR_SHORT_READ                   -12
2167     /** An attempt to read read less data than it should have */
2168
2169 #define WTAP_ERR_BAD_FILE                     -13
2170     /** The file appears to be damaged or corrupted or otherwise bogus */
2171
2172 #define WTAP_ERR_SHORT_WRITE                  -14
2173     /** An attempt to write wrote less data than it should have */
2174
2175 #define WTAP_ERR_UNC_OVERFLOW                 -15
2176     /** Uncompressing Sniffer data would overflow buffer */
2177
2178 #define WTAP_ERR_RANDOM_OPEN_STDIN            -16
2179     /** We're trying to open the standard input for random access */
2180
2181 #define WTAP_ERR_COMPRESSION_NOT_SUPPORTED    -17
2182     /* The filetype doesn't support output compression */
2183
2184 #define WTAP_ERR_CANT_SEEK                    -18
2185     /** An attempt to seek failed, reason unknown */
2186
2187 #define WTAP_ERR_CANT_SEEK_COMPRESSED         -19
2188     /** An attempt to seek on a compressed stream */
2189
2190 #define WTAP_ERR_DECOMPRESS                   -20
2191     /** Error decompressing */
2192
2193 #define WTAP_ERR_INTERNAL                     -21
2194     /** "Shouldn't happen" internal errors */
2195
2196 #define WTAP_ERR_PACKET_TOO_LARGE             -22
2197     /** Packet being written is larger than we support; do not use when
2198         reading, use WTAP_ERR_BAD_FILE instead */
2199
2200 #define WTAP_ERR_CHECK_WSLUA                  -23
2201     /** Not really an error: the file type being checked is from a Lua
2202         plugin, so that the code will call wslua_can_write_encap() instead if it gets this */
2203
2204 #define WTAP_ERR_UNWRITABLE_REC_TYPE          -24
2205     /** Specified record type can't be written to that file type */
2206
2207 #define WTAP_ERR_UNWRITABLE_REC_DATA          -25
2208     /** Something in the record data can't be written to that file type */
2209
2210 #ifdef __cplusplus
2211 }
2212 #endif /* __cplusplus */
2213
2214 #endif /* __WTAP_H__ */
2215
2216 /*
2217  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
2218  *
2219  * Local variables:
2220  * c-basic-offset: 4
2221  * tab-width: 8
2222  * indent-tabs-mode: nil
2223  * End:
2224  *
2225  * vi: set shiftwidth=4 tabstop=8 expandtab:
2226  * :indentSize=4:tabSize=8:noTabs=true:
2227  */