Fix non-libz build.
[metze/wireshark/wip.git] / wiretap / wtap.c
1 /* wtap.c
2  *
3  * $Id$
4  *
5  * Wiretap Library
6  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <string.h>
28 #include <errno.h>
29
30 #ifdef HAVE_SYS_TYPES_H
31 #include <sys/types.h>
32 #endif
33
34 #ifdef HAVE_UNISTD_H
35 #include <unistd.h>
36 #endif
37
38 #ifdef HAVE_LIBZ
39 #include <zlib.h>
40 #endif
41
42 #include "wtap-int.h"
43 #include "wtap.h"
44
45 #include "file_wrappers.h"
46 #include <wsutil/file_util.h>
47 #include "buffer.h"
48
49 /*
50  * Return the size of the file, as reported by the OS.
51  * (gint64, in case that's 64 bits.)
52  */
53 gint64
54 wtap_file_size(wtap *wth, int *err)
55 {
56         struct stat statb;
57
58         if (fstat(wth->fd, &statb) == -1) {
59                 if (err != NULL)
60                         *err = errno;
61                 return -1;
62         }
63         return statb.st_size;
64 }
65
66 int
67 wtap_file_type(wtap *wth)
68 {
69         return wth->file_type;
70 }
71
72 int
73 wtap_snapshot_length(wtap *wth)
74 {
75         return wth->snapshot_length;
76 }
77
78 int
79 wtap_file_encap(wtap *wth)
80 {
81         return wth->file_encap;
82 }
83
84 int
85 wtap_file_tsprecision(wtap *wth)
86 {
87         return wth->tsprecision;
88 }
89
90 /* Table of the encapsulation types we know about. */
91 struct encap_type_info {
92         const char *name;
93         const char *short_name;
94 };
95
96 static struct encap_type_info encap_table_base[] = {
97         /* WTAP_ENCAP_UNKNOWN */
98         { "Unknown", "unknown" },
99
100         /* WTAP_ENCAP_ETHERNET */
101         { "Ethernet", "ether" },
102
103         /* WTAP_ENCAP_TOKEN_RING */
104         { "Token Ring", "tr" },
105
106         /* WTAP_ENCAP_SLIP */
107         { "SLIP", "slip" },
108
109         /* WTAP_ENCAP_PPP */
110         { "PPP", "ppp" },
111
112         /* WTAP_ENCAP_FDDI */
113         { "FDDI", "fddi" },
114
115         /* WTAP_ENCAP_FDDI_BITSWAPPED */
116         { "FDDI with bit-swapped MAC addresses", "fddi-swapped" },
117
118         /* WTAP_ENCAP_RAW_IP */
119         { "Raw IP", "rawip" },
120
121         /* WTAP_ENCAP_ARCNET */
122         { "ARCNET", "arcnet" },
123
124         /* WTAP_ENCAP_ARCNET_LINUX */
125         { "Linux ARCNET", "arcnet_linux" },
126
127         /* WTAP_ENCAP_ATM_RFC1483 */
128         { "RFC 1483 ATM", "atm-rfc1483" },
129
130         /* WTAP_ENCAP_LINUX_ATM_CLIP */
131         { "Linux ATM CLIP", "linux-atm-clip" },
132
133         /* WTAP_ENCAP_LAPB */
134         { "LAPB", "lapb" },
135
136         /* WTAP_ENCAP_ATM_PDUS */
137         { "ATM PDUs", "atm-pdus" },
138
139         /* WTAP_ENCAP_ATM_PDUS_UNTRUNCATED */
140         { "ATM PDUs - untruncated", "atm-pdus-untruncated" },
141
142         /* WTAP_ENCAP_NULL */
143         { "NULL", "null" },
144
145         /* WTAP_ENCAP_ASCEND */
146         { "Lucent/Ascend access equipment", "ascend" },
147
148         /* WTAP_ENCAP_ISDN */
149         { "ISDN", "isdn" },
150
151         /* WTAP_ENCAP_IP_OVER_FC */
152         { "RFC 2625 IP-over-Fibre Channel", "ip-over-fc" },
153
154         /* WTAP_ENCAP_PPP_WITH_PHDR */
155         { "PPP with Directional Info", "ppp-with-direction" },
156
157         /* WTAP_ENCAP_IEEE_802_11 */
158         { "IEEE 802.11 Wireless LAN", "ieee-802-11" },
159
160         /* WTAP_ENCAP_PRISM_HEADER */
161         { "IEEE 802.11 plus Prism II monitor mode header", "prism" },
162
163         /* WTAP_ENCAP_IEEE_802_11_WITH_RADIO */
164         { "IEEE 802.11 Wireless LAN with radio information", "ieee-802-11-radio" },
165
166         /* WTAP_ENCAP_IEEE_802_11_WLAN_RADIOTAP */
167         { "IEEE 802.11 plus radiotap WLAN header", "ieee-802-11-radiotap" },
168
169         /* WTAP_ENCAP_IEEE_802_11_WLAN_AVS */
170         { "IEEE 802.11 plus AVS WLAN header", "ieee-802-11-avs" },
171
172         /* WTAP_ENCAP_SLL */
173         { "Linux cooked-mode capture", "linux-sll" },
174
175         /* WTAP_ENCAP_FRELAY */
176         { "Frame Relay", "frelay" },
177
178         /* WTAP_ENCAP_FRELAY_WITH_PHDR */
179         { "Frame Relay with Directional Info", "frelay-with-direction" },
180
181         /* WTAP_ENCAP_CHDLC */
182         { "Cisco HDLC", "chdlc" },
183
184         /* WTAP_ENCAP_CISCO_IOS */
185         { "Cisco IOS internal", "ios" },
186
187         /* WTAP_ENCAP_LOCALTALK */
188         { "Localtalk", "ltalk" },
189
190         /* WTAP_ENCAP_OLD_PFLOG  */
191         { "OpenBSD PF Firewall logs, pre-3.4", "pflog-old" },
192
193         /* WTAP_ENCAP_HHDLC */
194         { "HiPath HDLC", "hhdlc" },
195
196         /* WTAP_ENCAP_DOCSIS */
197         { "Data Over Cable Service Interface Specification", "docsis" },
198
199         /* WTAP_ENCAP_COSINE */
200         { "CoSine L2 debug log", "cosine" },
201
202         /* WTAP_ENCAP_WFLEET_HDLC */
203         { "Wellfleet HDLC", "whdlc" },
204
205         /* WTAP_ENCAP_SDLC */
206         { "SDLC", "sdlc" },
207
208         /* WTAP_ENCAP_TZSP */
209         { "Tazmen sniffer protocol", "tzsp" },
210
211         /* WTAP_ENCAP_ENC */
212         { "OpenBSD enc(4) encapsulating interface", "enc" },
213
214         /* WTAP_ENCAP_PFLOG  */
215         { "OpenBSD PF Firewall logs", "pflog" },
216
217         /* WTAP_ENCAP_CHDLC_WITH_PHDR */
218         { "Cisco HDLC with Directional Info", "chdlc-with-direction" },
219
220         /* WTAP_ENCAP_BLUETOOTH_H4 */
221         { "Bluetooth H4", "bluetooth-h4" },
222
223         /* WTAP_ENCAP_MTP2 */
224         { "SS7 MTP2", "mtp2" },
225
226         /* WTAP_ENCAP_MTP3 */
227         { "SS7 MTP3", "mtp3" },
228
229         /* WTAP_ENCAP_IRDA */
230         { "IrDA", "irda" },
231
232         /* WTAP_ENCAP_USER0 */
233         { "USER 0", "user0" },
234
235         /* WTAP_ENCAP_USER1 */
236         { "USER 1", "user1" },
237
238         /* WTAP_ENCAP_USER2 */
239         { "USER 2", "user2" },
240
241         /* WTAP_ENCAP_USER3 */
242         { "USER 3", "user3" },
243
244         /* WTAP_ENCAP_USER4 */
245         { "USER 4", "user4" },
246
247         /* WTAP_ENCAP_USER5 */
248         { "USER 5", "user5" },
249
250         /* WTAP_ENCAP_USER6 */
251         { "USER 6", "user6" },
252
253         /* WTAP_ENCAP_USER7 */
254         { "USER 7", "user7" },
255
256         /* WTAP_ENCAP_USER8 */
257         { "USER 8", "user8" },
258
259         /* WTAP_ENCAP_USER9 */
260         { "USER 9", "user9" },
261
262         /* WTAP_ENCAP_USER10 */
263         { "USER 10", "user10" },
264
265         /* WTAP_ENCAP_USER11 */
266         { "USER 11", "user11" },
267
268         /* WTAP_ENCAP_USER12 */
269         { "USER 12", "user12" },
270
271         /* WTAP_ENCAP_USER13 */
272         { "USER 13", "user13" },
273
274         /* WTAP_ENCAP_USER14 */
275         { "USER 14", "user14" },
276
277         /* WTAP_ENCAP_USER15 */
278         { "USER 15", "user15" },
279
280         /* WTAP_ENCAP_SYMANTEC */
281         { "Symantec Enterprise Firewall", "symantec" },
282
283         /* WTAP_ENCAP_APPLE_IP_OVER_IEEE1394 */
284         { "Apple IP-over-IEEE 1394", "ap1394" },
285
286         /* WTAP_ENCAP_BACNET_MS_TP */
287         { "BACnet MS/TP", "bacnet-ms-tp" },
288
289         /* WTAP_ENCAP_NETTL_RAW_ICMP */
290         { "Raw ICMP with nettl headers", "raw-icmp-nettl" },
291
292         /* WTAP_ENCAP_NETTL_RAW_ICMPV6 */
293         { "Raw ICMPv6 with nettl headers", "raw-icmpv6-nettl" },
294
295         /* WTAP_ENCAP_GPRS_LLC */
296         { "GPRS LLC", "gprs-llc" },
297
298         /* WTAP_ENCAP_JUNIPER_ATM1 */
299         { "Juniper ATM1", "juniper-atm1" },
300
301         /* WTAP_ENCAP_JUNIPER_ATM2 */
302         { "Juniper ATM2", "juniper-atm2" },
303
304         /* WTAP_ENCAP_REDBACK */
305         { "Redback SmartEdge", "redback" },
306
307         /* WTAP_ENCAP_NETTL_RAW_IP */
308         { "Raw IP with nettl headers", "rawip-nettl" },
309
310         /* WTAP_ENCAP_NETTL_ETHERNET */
311         { "Ethernet with nettl headers", "ether-nettl" },
312
313         /* WTAP_ENCAP_NETTL_TOKEN_RING */
314         { "Token Ring with nettl headers", "tr-nettl" },
315
316         /* WTAP_ENCAP_NETTL_FDDI */
317         { "FDDI with nettl headers", "fddi-nettl" },
318
319         /* WTAP_ENCAP_NETTL_UNKNOWN */
320         { "Unknown link-layer type with nettl headers", "unknown-nettl" },
321
322         /* WTAP_ENCAP_MTP2_WITH_PHDR */
323         { "MTP2 with pseudoheader", "mtp2-with-phdr" },
324
325         /* WTAP_ENCAP_JUNIPER_PPPOE */
326         { "Juniper PPPoE", "juniper-pppoe" },
327
328         /* WTAP_ENCAP_GCOM_TIE1 */
329         { "GCOM TIE1", "gcom-tie1" },
330
331         /* WTAP_ENCAP_GCOM_SERIAL */
332         { "GCOM Serial", "gcom-serial" },
333
334         /* WTAP_ENCAP_NETTL_X25 */
335         { "X25 with nettl headers", "x25-nettl" },
336
337         /* WTAP_ENCAP_K12 */
338         { "K12 protocol analyzer", "k12" },
339
340         /* WTAP_ENCAP_JUNIPER_MLPPP */
341         { "Juniper MLPPP", "juniper-mlppp" },
342
343         /* WTAP_ENCAP_JUNIPER_MLFR */
344         { "Juniper MLFR", "juniper-mlfr" },
345
346         /* WTAP_ENCAP_JUNIPER_ETHER */
347         { "Juniper Ethernet", "juniper-ether" },
348
349         /* WTAP_ENCAP_JUNIPER_PPP */
350         { "Juniper PPP", "juniper-ppp" },
351
352         /* WTAP_ENCAP_JUNIPER_FRELAY */
353         { "Juniper Frame-Relay", "juniper-frelay" },
354
355         /* WTAP_ENCAP_JUNIPER_CHDLC */
356         { "Juniper C-HDLC", "juniper-chdlc" },
357
358         /* WTAP_ENCAP_JUNIPER_GGSN */
359         { "Juniper GGSN", "juniper-ggsn" },
360
361         /* WTAP_ENCAP_LINUX_LAPD */
362         { "LAPD", "lapd" },
363
364         /* WTAP_ENCAP_CATAPULT_DCT2000 */
365         { "Catapult DCT2000", "dct2000" },
366
367         /* WTAP_ENCAP_BER */
368         { "ASN.1 Basic Encoding Rules", "ber" },
369
370         /* WTAP_ENCAP_JUNIPER_VP */
371         { "Juniper Voice PIC", "juniper-vp" },
372
373         /* WTAP_ENCAP_USB */
374         { "Raw USB packets", "usb" },
375
376         /* WTAP_ENCAP_IEEE802_16_MAC_CPS */
377         { "IEEE 802.16 MAC Common Part Sublayer", "ieee-802-16-mac-cps" },
378
379         /* WTAP_ENCAP_NETTL_RAW_TELNET */
380         { "Raw telnet with nettl headers", "raw-telnet-nettl" },
381
382         /* WTAP_ENCAP_USB_LINUX */
383         { "USB packets with Linux header", "usb-linux" },
384
385         /* WTAP_ENCAP_MPEG */
386         { "MPEG", "mpeg" },
387
388         /* WTAP_ENCAP_PPI */
389         { "Per-Packet Information header", "ppi" },
390
391         /* WTAP_ENCAP_ERF */
392         { "Endace Record File", "erf" },
393
394         /* WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR */
395         { "Bluetooth H4 with linux header", "bluetooth-h4-linux" },
396
397         /* WTAP_ENCAP_SITA */
398         { "SITA WAN packets", "sita-wan" },
399
400         /* WTAP_ENCAP_SCCP */
401         { "SS7 SCCP", "sccp" },
402
403         /* WTAP_ENCAP_BLUETOOTH_HCI */
404         { "Bluetooth without transport layer", "bluetooth-hci" },
405
406         /* WTAP_ENCAP_IPMB */
407         { "Intelligent Platform Management Bus", "ipmb" },
408
409         /* WTAP_ENCAP_IEEE802_15_4 */
410         { "IEEE 802.15.4 Wireless PAN", "wpan" },
411
412         /* WTAP_ENCAP_X2E_XORAYA */
413         { "X2E Xoraya", "x2e-xoraya" },
414
415         /* WTAP_ENCAP_FLEXRAY */
416         { "FlexRay", "flexray" },
417
418         /* WTAP_ENCAP_LIN */
419         { "Local Interconnect Network", "lin" },
420
421         /* WTAP_ENCAP_MOST */
422         { "Media Oriented Systems Transport", "most" },
423
424         /* WTAP_ENCAP_CAN20B */
425         { "Controller Area Network 2.0B", "can20b" },
426
427         /* WTAP_ENCAP_LAYER1_EVENT */
428         { "EyeSDN Layer 1 event", "layer1-event" },
429
430         /* WTAP_ENCAP_X2E_SERIAL */
431         { "X2E serial line capture", "x2e-serial" },
432
433         /* WTAP_ENCAP_I2C */
434         { "I2C", "i2c" },
435
436         /* WTAP_ENCAP_IEEE802_15_4_NONASK_PHY */
437         { "IEEE 802.15.4 Wireless PAN non-ASK PHY", "wpan-nonask-phy" },
438
439         /* WTAP_ENCAP_TNEF */
440         { "Transport-Neutral Encapsulation Format", "tnef" },
441
442         /* WTAP_ENCAP_USB_LINUX_MMAPPED */
443         { "USB packets with Linux header and padding", "usb-linux-mmap" },
444
445         /* WTAP_ENCAP_GSM_UM */
446         { "GSM Um Interface", "gsm_um" },
447
448         /* WTAP_ENCAP_DPNSS */
449         { "Digital Private Signalling System No 1 Link Layer", "dpnss_link" },
450
451         /* WTAP_ENCAP_PACKETLOGGER */
452         { "PacketLogger", "packetlogger" },
453
454         /* WTAP_ENCAP_NSTRACE_1_0 */
455         { "NetScaler Encapsulation 1.0 of Ethernet", "nstrace10" },
456
457         /* WTAP_ENCAP_NSTRACE_2_0 */
458         { "NetScaler Encapsulation 2.0 of Ethernet", "nstrace20" },
459
460         /* WTAP_ENCAP_FIBRE_CHANNEL_FC2 */
461         { "Fibre Channel FC-2", "fc2" },
462
463         /* WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS */
464         { "Fibre Channel FC-2 With Frame Delimiter", "fc2sof"},
465
466         /* WTAP_ENCAP_JPEG_JFIF */
467         { "JPEG/JFIF", "jfif" },
468
469         /* WTAP_ENCAP_IPNET */
470         { "Solaris IPNET", "ipnet" }
471
472 };
473
474 gint wtap_num_encap_types = sizeof(encap_table_base) / sizeof(struct encap_type_info);
475 static GArray* encap_table_arr = NULL;
476 static const struct encap_type_info* encap_table = NULL;
477
478 static void wtap_init_encap_types(void) {
479
480         if (encap_table_arr) return;
481
482         encap_table_arr = g_array_new(FALSE,TRUE,sizeof(struct encap_type_info));
483
484         g_array_append_vals(encap_table_arr,encap_table_base,wtap_num_encap_types);
485
486         encap_table = (void*)encap_table_arr->data;
487 }
488
489 int wtap_get_num_encap_types(void) {
490         wtap_init_encap_types();
491         return wtap_num_encap_types;
492 }
493
494
495 int wtap_register_encap_type(char* name, char* short_name) {
496         struct encap_type_info e;
497         wtap_init_encap_types();
498
499         e.name = g_strdup(name);
500         e.short_name = g_strdup(short_name);
501
502         g_array_append_val(encap_table_arr,e);
503
504         encap_table = (void*)encap_table_arr->data;
505
506         return wtap_num_encap_types++;
507 }
508
509
510 /* Name that should be somewhat descriptive. */
511 const char
512 *wtap_encap_string(int encap)
513 {
514         if (encap < WTAP_ENCAP_PER_PACKET || encap >= WTAP_NUM_ENCAP_TYPES)
515                 return "Illegal";
516         else if (encap == WTAP_ENCAP_PER_PACKET)
517                 return "Per packet";
518         else
519                 return encap_table[encap].name;
520 }
521
522 /* Name to use in, say, a command-line flag specifying the type. */
523 const char
524 *wtap_encap_short_string(int encap)
525 {
526         if (encap < WTAP_ENCAP_PER_PACKET || encap >= WTAP_NUM_ENCAP_TYPES)
527                 return "illegal";
528         else if (encap == WTAP_ENCAP_PER_PACKET)
529                 return "per-packet";
530         else
531                 return encap_table[encap].short_name;
532 }
533
534 /* Translate a short name to a capture file type. */
535 int
536 wtap_short_string_to_encap(const char *short_name)
537 {
538         int encap;
539
540         for (encap = 0; encap < WTAP_NUM_ENCAP_TYPES; encap++) {
541                 if (encap_table[encap].short_name != NULL &&
542                     strcmp(short_name, encap_table[encap].short_name) == 0)
543                         return encap;
544         }
545         return -1;      /* no such encapsulation type */
546 }
547
548 static const char *wtap_errlist[] = {
549         "The file isn't a plain file or pipe",
550         "The file is being opened for random access but is a pipe",
551         "The file isn't a capture file in a known format",
552         "File contains record data we don't support",
553         "That file format cannot be written to a pipe",
554         NULL,
555         "Files can't be saved in that format",
556         "Files from that network type can't be saved in that format",
557         "That file format doesn't support per-packet encapsulations",
558         NULL,
559         NULL,
560         "Less data was read than was expected",
561         "File contains a record that's not valid",
562         "Less data was written than was requested",
563         "Uncompression error: data oddly truncated",
564         "Uncompression error: data would overflow buffer",
565         "Uncompression error: bad LZ77 offset",
566         "The standard input cannot be opened for random access"
567 };
568 #define WTAP_ERRLIST_SIZE       (sizeof wtap_errlist / sizeof wtap_errlist[0])
569
570 const char
571 *wtap_strerror(int err)
572 {
573         static char errbuf[128];
574         unsigned int wtap_errlist_index;
575
576         if (err < 0) {
577 #ifdef HAVE_LIBZ
578                 if (err >= WTAP_ERR_ZLIB_MIN && err <= WTAP_ERR_ZLIB_MAX) {
579                         /* Assume it's a zlib error. */
580                         g_snprintf(errbuf, 128, "Uncompression error: %s",
581                             zError(err - WTAP_ERR_ZLIB));
582                         return errbuf;
583                 }
584 #endif
585                 wtap_errlist_index = -1 - err;
586                 if (wtap_errlist_index >= WTAP_ERRLIST_SIZE) {
587                         g_snprintf(errbuf, 128, "Error %d", err);
588                         return errbuf;
589                 }
590                 if (wtap_errlist[wtap_errlist_index] == NULL)
591                         return "Unknown reason";
592                 return wtap_errlist[wtap_errlist_index];
593         } else
594                 return strerror(err);
595 }
596
597 /* Close only the sequential side, freeing up memory it uses.
598
599    Note that we do *not* want to call the subtype's close function,
600    as it would free any per-subtype data, and that data may be
601    needed by the random-access side.
602
603    Instead, if the subtype has a "sequential close" function, we call it,
604    to free up stuff used only by the sequential side. */
605 void
606 wtap_sequential_close(wtap *wth)
607 {
608         if (wth->subtype_sequential_close != NULL)
609                 (*wth->subtype_sequential_close)(wth);
610
611         if (wth->fh != NULL) {
612                 file_close(wth->fh);
613                 wth->fh = NULL;
614         }
615
616         if (wth->frame_buffer) {
617                 buffer_free(wth->frame_buffer);
618                 g_free(wth->frame_buffer);
619                 wth->frame_buffer = NULL;
620         }
621 }
622
623 void
624 wtap_close(wtap *wth)
625 {
626         wtap_sequential_close(wth);
627
628         if (wth->subtype_close != NULL)
629                 (*wth->subtype_close)(wth);
630
631         if (wth->random_fh != NULL)
632                 file_close(wth->random_fh);
633
634         if (wth->priv != NULL)
635                 g_free(wth->priv);
636
637         g_free(wth);
638 }
639
640 void
641 wtap_cleareof(wtap *wth _U_) {
642 #ifdef HAVE_LIBZ
643         /* Reset EOF */
644         if (gzeof(wth->fh))
645                 gzclearerr(wth->fh);
646 #endif
647 }
648
649 gboolean
650 wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
651 {
652         /*
653          * Set the packet encapsulation to the file's encapsulation
654          * value; if that's not WTAP_ENCAP_PER_PACKET, it's the
655          * right answer (and means that the read routine for this
656          * capture file type doesn't have to set it), and if it
657          * *is* WTAP_ENCAP_PER_PACKET, the caller needs to set it
658          * anyway.
659          */
660         wth->phdr.pkt_encap = wth->file_encap;
661
662         if (!wth->subtype_read(wth, err, err_info, data_offset))
663                 return FALSE;   /* failure */
664
665         /*
666          * It makes no sense for the captured data length to be bigger
667          * than the actual data length.
668          */
669         if (wth->phdr.caplen > wth->phdr.len)
670                 wth->phdr.caplen = wth->phdr.len;
671
672         /*
673          * Make sure that it's not WTAP_ENCAP_PER_PACKET, as that
674          * probably means the file has that encapsulation type
675          * but the read routine didn't set this packet's
676          * encapsulation type.
677          */
678         g_assert(wth->phdr.pkt_encap != WTAP_ENCAP_PER_PACKET);
679
680         return TRUE;    /* success */
681 }
682
683 /*
684  * Return an approximation of the amount of data we've read sequentially
685  * from the file so far.  (gint64, in case that's 64 bits.)
686  */
687 gint64
688 wtap_read_so_far(wtap *wth, int *err)
689 {
690         off_t file_pos;
691
692         file_pos = ws_lseek(wth->fd, 0, SEEK_CUR);
693         if (file_pos == -1) {
694                 if (err != NULL)
695                         *err = errno;
696                 return -1;
697         }
698         return file_pos;
699 }
700
701 struct wtap_pkthdr*
702 wtap_phdr(wtap *wth)
703 {
704         return &wth->phdr;
705 }
706
707 union wtap_pseudo_header*
708 wtap_pseudoheader(wtap *wth)
709 {
710         return &wth->pseudo_header;
711 }
712
713 guint8*
714 wtap_buf_ptr(wtap *wth)
715 {
716         return buffer_start_ptr(wth->frame_buffer);
717 }
718
719 gboolean
720 wtap_seek_read(wtap *wth, gint64 seek_off,
721         union wtap_pseudo_header *pseudo_header, guint8 *pd, int len,
722         int *err, gchar **err_info)
723 {
724         return wth->subtype_seek_read(wth, seek_off, pseudo_header, pd, len,
725                 err, err_info);
726 }