6 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
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.
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.
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.
30 #ifdef HAVE_SYS_TYPES_H
31 #include <sys/types.h>
44 #include "file_wrappers.h"
45 #include <wsutil/file_util.h>
49 * Return the size of the file, as reported by the OS.
50 * (gint64, in case that's 64 bits.)
53 wtap_file_size(wtap *wth, int *err)
57 if (file_fstat((wth->fh == NULL) ? wth->random_fh : wth->fh,
64 * Do an fstat on the file.
67 wtap_fstat(wtap *wth, ws_statb64 *statb, int *err)
69 if (file_fstat((wth->fh == NULL) ? wth->random_fh : wth->fh,
76 wtap_file_type(wtap *wth)
78 return wth->file_type;
82 wtap_iscompressed(wtap *wth)
84 return file_iscompressed((wth->fh == NULL) ? wth->random_fh : wth->fh);
88 wtap_snapshot_length(wtap *wth)
90 return wth->snapshot_length;
94 wtap_file_encap(wtap *wth)
96 return wth->file_encap;
100 wtap_file_tsprecision(wtap *wth)
102 return wth->tsprecision;
106 wtap_file_get_shb_info(wtap *wth)
108 wtapng_section_t *shb_hdr;
112 shb_hdr = g_new(wtapng_section_t,1);
113 shb_hdr->section_length = wth->shb_hdr.section_length;
115 shb_hdr->opt_comment = wth->shb_hdr.opt_comment; /* NULL if not available */
116 shb_hdr->shb_hardware = wth->shb_hdr.shb_hardware; /* NULL if not available, UTF-8 string containing the description of the hardware used to create this section. */
117 shb_hdr->shb_os = wth->shb_hdr.shb_os; /* NULL if not available, UTF-8 string containing the name of the operating system used to create this section. */
118 shb_hdr->shb_user_appl = wth->shb_hdr.shb_user_appl; /* NULL if not available, UTF-8 string containing the name of the application used to create this section. */
125 wtap_write_shb_comment(wtap *wth, gchar *comment)
127 g_free(wth->shb_hdr.opt_comment);
128 wth->shb_hdr.opt_comment = comment;
132 wtapng_iface_descriptions_t *
133 wtap_file_get_idb_info(wtap *wth)
135 wtapng_iface_descriptions_t *idb_info;
137 idb_info = g_new(wtapng_iface_descriptions_t,1);
139 idb_info->number_of_interfaces = wth->number_of_interfaces;
140 idb_info->interface_data = wth->interface_data;
145 /* Table of the encapsulation types we know about. */
146 struct encap_type_info {
148 const char *short_name;
151 static struct encap_type_info encap_table_base[] = {
152 /* WTAP_ENCAP_UNKNOWN */
153 { "Unknown", "unknown" },
155 /* WTAP_ENCAP_ETHERNET */
156 { "Ethernet", "ether" },
158 /* WTAP_ENCAP_TOKEN_RING */
159 { "Token Ring", "tr" },
161 /* WTAP_ENCAP_SLIP */
167 /* WTAP_ENCAP_FDDI */
170 /* WTAP_ENCAP_FDDI_BITSWAPPED */
171 { "FDDI with bit-swapped MAC addresses", "fddi-swapped" },
173 /* WTAP_ENCAP_RAW_IP */
174 { "Raw IP", "rawip" },
176 /* WTAP_ENCAP_ARCNET */
177 { "ARCNET", "arcnet" },
179 /* WTAP_ENCAP_ARCNET_LINUX */
180 { "Linux ARCNET", "arcnet_linux" },
182 /* WTAP_ENCAP_ATM_RFC1483 */
183 { "RFC 1483 ATM", "atm-rfc1483" },
185 /* WTAP_ENCAP_LINUX_ATM_CLIP */
186 { "Linux ATM CLIP", "linux-atm-clip" },
188 /* WTAP_ENCAP_LAPB */
191 /* WTAP_ENCAP_ATM_PDUS */
192 { "ATM PDUs", "atm-pdus" },
194 /* WTAP_ENCAP_ATM_PDUS_UNTRUNCATED */
195 { "ATM PDUs - untruncated", "atm-pdus-untruncated" },
197 /* WTAP_ENCAP_NULL */
200 /* WTAP_ENCAP_ASCEND */
201 { "Lucent/Ascend access equipment", "ascend" },
203 /* WTAP_ENCAP_ISDN */
206 /* WTAP_ENCAP_IP_OVER_FC */
207 { "RFC 2625 IP-over-Fibre Channel", "ip-over-fc" },
209 /* WTAP_ENCAP_PPP_WITH_PHDR */
210 { "PPP with Directional Info", "ppp-with-direction" },
212 /* WTAP_ENCAP_IEEE_802_11 */
213 { "IEEE 802.11 Wireless LAN", "ieee-802-11" },
215 /* WTAP_ENCAP_IEEE_802_11_PRISM */
216 { "IEEE 802.11 plus Prism II monitor mode radio header", "ieee-802-11-prism" },
218 /* WTAP_ENCAP_IEEE_802_11_WITH_RADIO */
219 { "IEEE 802.11 Wireless LAN with radio information", "ieee-802-11-radio" },
221 /* WTAP_ENCAP_IEEE_802_11_RADIOTAP */
222 { "IEEE 802.11 plus radiotap radio header", "ieee-802-11-radiotap" },
224 /* WTAP_ENCAP_IEEE_802_11_AVS */
225 { "IEEE 802.11 plus AVS radio header", "ieee-802-11-avs" },
228 { "Linux cooked-mode capture", "linux-sll" },
230 /* WTAP_ENCAP_FRELAY */
231 { "Frame Relay", "frelay" },
233 /* WTAP_ENCAP_FRELAY_WITH_PHDR */
234 { "Frame Relay with Directional Info", "frelay-with-direction" },
236 /* WTAP_ENCAP_CHDLC */
237 { "Cisco HDLC", "chdlc" },
239 /* WTAP_ENCAP_CISCO_IOS */
240 { "Cisco IOS internal", "ios" },
242 /* WTAP_ENCAP_LOCALTALK */
243 { "Localtalk", "ltalk" },
245 /* WTAP_ENCAP_OLD_PFLOG */
246 { "OpenBSD PF Firewall logs, pre-3.4", "pflog-old" },
248 /* WTAP_ENCAP_HHDLC */
249 { "HiPath HDLC", "hhdlc" },
251 /* WTAP_ENCAP_DOCSIS */
252 { "Data Over Cable Service Interface Specification", "docsis" },
254 /* WTAP_ENCAP_COSINE */
255 { "CoSine L2 debug log", "cosine" },
257 /* WTAP_ENCAP_WFLEET_HDLC */
258 { "Wellfleet HDLC", "whdlc" },
260 /* WTAP_ENCAP_SDLC */
263 /* WTAP_ENCAP_TZSP */
264 { "Tazmen sniffer protocol", "tzsp" },
267 { "OpenBSD enc(4) encapsulating interface", "enc" },
269 /* WTAP_ENCAP_PFLOG */
270 { "OpenBSD PF Firewall logs", "pflog" },
272 /* WTAP_ENCAP_CHDLC_WITH_PHDR */
273 { "Cisco HDLC with Directional Info", "chdlc-with-direction" },
275 /* WTAP_ENCAP_BLUETOOTH_H4 */
276 { "Bluetooth H4", "bluetooth-h4" },
278 /* WTAP_ENCAP_MTP2 */
279 { "SS7 MTP2", "mtp2" },
281 /* WTAP_ENCAP_MTP3 */
282 { "SS7 MTP3", "mtp3" },
284 /* WTAP_ENCAP_IRDA */
287 /* WTAP_ENCAP_USER0 */
288 { "USER 0", "user0" },
290 /* WTAP_ENCAP_USER1 */
291 { "USER 1", "user1" },
293 /* WTAP_ENCAP_USER2 */
294 { "USER 2", "user2" },
296 /* WTAP_ENCAP_USER3 */
297 { "USER 3", "user3" },
299 /* WTAP_ENCAP_USER4 */
300 { "USER 4", "user4" },
302 /* WTAP_ENCAP_USER5 */
303 { "USER 5", "user5" },
305 /* WTAP_ENCAP_USER6 */
306 { "USER 6", "user6" },
308 /* WTAP_ENCAP_USER7 */
309 { "USER 7", "user7" },
311 /* WTAP_ENCAP_USER8 */
312 { "USER 8", "user8" },
314 /* WTAP_ENCAP_USER9 */
315 { "USER 9", "user9" },
317 /* WTAP_ENCAP_USER10 */
318 { "USER 10", "user10" },
320 /* WTAP_ENCAP_USER11 */
321 { "USER 11", "user11" },
323 /* WTAP_ENCAP_USER12 */
324 { "USER 12", "user12" },
326 /* WTAP_ENCAP_USER13 */
327 { "USER 13", "user13" },
329 /* WTAP_ENCAP_USER14 */
330 { "USER 14", "user14" },
332 /* WTAP_ENCAP_USER15 */
333 { "USER 15", "user15" },
335 /* WTAP_ENCAP_SYMANTEC */
336 { "Symantec Enterprise Firewall", "symantec" },
338 /* WTAP_ENCAP_APPLE_IP_OVER_IEEE1394 */
339 { "Apple IP-over-IEEE 1394", "ap1394" },
341 /* WTAP_ENCAP_BACNET_MS_TP */
342 { "BACnet MS/TP", "bacnet-ms-tp" },
344 /* WTAP_ENCAP_NETTL_RAW_ICMP */
345 { "Raw ICMP with nettl headers", "raw-icmp-nettl" },
347 /* WTAP_ENCAP_NETTL_RAW_ICMPV6 */
348 { "Raw ICMPv6 with nettl headers", "raw-icmpv6-nettl" },
350 /* WTAP_ENCAP_GPRS_LLC */
351 { "GPRS LLC", "gprs-llc" },
353 /* WTAP_ENCAP_JUNIPER_ATM1 */
354 { "Juniper ATM1", "juniper-atm1" },
356 /* WTAP_ENCAP_JUNIPER_ATM2 */
357 { "Juniper ATM2", "juniper-atm2" },
359 /* WTAP_ENCAP_REDBACK */
360 { "Redback SmartEdge", "redback" },
362 /* WTAP_ENCAP_NETTL_RAW_IP */
363 { "Raw IP with nettl headers", "rawip-nettl" },
365 /* WTAP_ENCAP_NETTL_ETHERNET */
366 { "Ethernet with nettl headers", "ether-nettl" },
368 /* WTAP_ENCAP_NETTL_TOKEN_RING */
369 { "Token Ring with nettl headers", "tr-nettl" },
371 /* WTAP_ENCAP_NETTL_FDDI */
372 { "FDDI with nettl headers", "fddi-nettl" },
374 /* WTAP_ENCAP_NETTL_UNKNOWN */
375 { "Unknown link-layer type with nettl headers", "unknown-nettl" },
377 /* WTAP_ENCAP_MTP2_WITH_PHDR */
378 { "MTP2 with pseudoheader", "mtp2-with-phdr" },
380 /* WTAP_ENCAP_JUNIPER_PPPOE */
381 { "Juniper PPPoE", "juniper-pppoe" },
383 /* WTAP_ENCAP_GCOM_TIE1 */
384 { "GCOM TIE1", "gcom-tie1" },
386 /* WTAP_ENCAP_GCOM_SERIAL */
387 { "GCOM Serial", "gcom-serial" },
389 /* WTAP_ENCAP_NETTL_X25 */
390 { "X.25 with nettl headers", "x25-nettl" },
393 { "K12 protocol analyzer", "k12" },
395 /* WTAP_ENCAP_JUNIPER_MLPPP */
396 { "Juniper MLPPP", "juniper-mlppp" },
398 /* WTAP_ENCAP_JUNIPER_MLFR */
399 { "Juniper MLFR", "juniper-mlfr" },
401 /* WTAP_ENCAP_JUNIPER_ETHER */
402 { "Juniper Ethernet", "juniper-ether" },
404 /* WTAP_ENCAP_JUNIPER_PPP */
405 { "Juniper PPP", "juniper-ppp" },
407 /* WTAP_ENCAP_JUNIPER_FRELAY */
408 { "Juniper Frame-Relay", "juniper-frelay" },
410 /* WTAP_ENCAP_JUNIPER_CHDLC */
411 { "Juniper C-HDLC", "juniper-chdlc" },
413 /* WTAP_ENCAP_JUNIPER_GGSN */
414 { "Juniper GGSN", "juniper-ggsn" },
416 /* WTAP_ENCAP_LINUX_LAPD */
417 { "LAPD with Linux pseudo-header", "linux-lapd" },
419 /* WTAP_ENCAP_CATAPULT_DCT2000 */
420 { "Catapult DCT2000", "dct2000" },
423 { "ASN.1 Basic Encoding Rules", "ber" },
425 /* WTAP_ENCAP_JUNIPER_VP */
426 { "Juniper Voice PIC", "juniper-vp" },
429 { "Raw USB packets", "usb" },
431 /* WTAP_ENCAP_IEEE802_16_MAC_CPS */
432 { "IEEE 802.16 MAC Common Part Sublayer", "ieee-802-16-mac-cps" },
434 /* WTAP_ENCAP_NETTL_RAW_TELNET */
435 { "Raw telnet with nettl headers", "raw-telnet-nettl" },
437 /* WTAP_ENCAP_USB_LINUX */
438 { "USB packets with Linux header", "usb-linux" },
440 /* WTAP_ENCAP_MPEG */
444 { "Per-Packet Information header", "ppi" },
447 { "Endace Record File", "erf" },
449 /* WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR */
450 { "Bluetooth H4 with linux header", "bluetooth-h4-linux" },
452 /* WTAP_ENCAP_SITA */
453 { "SITA WAN packets", "sita-wan" },
455 /* WTAP_ENCAP_SCCP */
456 { "SS7 SCCP", "sccp" },
458 /* WTAP_ENCAP_BLUETOOTH_HCI */
459 { "Bluetooth without transport layer", "bluetooth-hci" },
461 /* WTAP_ENCAP_IPMB */
462 { "Intelligent Platform Management Bus", "ipmb" },
464 /* WTAP_ENCAP_IEEE802_15_4 */
465 { "IEEE 802.15.4 Wireless PAN", "wpan" },
467 /* WTAP_ENCAP_X2E_XORAYA */
468 { "X2E Xoraya", "x2e-xoraya" },
470 /* WTAP_ENCAP_FLEXRAY */
471 { "FlexRay", "flexray" },
474 { "Local Interconnect Network", "lin" },
476 /* WTAP_ENCAP_MOST */
477 { "Media Oriented Systems Transport", "most" },
479 /* WTAP_ENCAP_CAN20B */
480 { "Controller Area Network 2.0B", "can20b" },
482 /* WTAP_ENCAP_LAYER1_EVENT */
483 { "EyeSDN Layer 1 event", "layer1-event" },
485 /* WTAP_ENCAP_X2E_SERIAL */
486 { "X2E serial line capture", "x2e-serial" },
491 /* WTAP_ENCAP_IEEE802_15_4_NONASK_PHY */
492 { "IEEE 802.15.4 Wireless PAN non-ASK PHY", "wpan-nonask-phy" },
494 /* WTAP_ENCAP_TNEF */
495 { "Transport-Neutral Encapsulation Format", "tnef" },
497 /* WTAP_ENCAP_USB_LINUX_MMAPPED */
498 { "USB packets with Linux header and padding", "usb-linux-mmap" },
500 /* WTAP_ENCAP_GSM_UM */
501 { "GSM Um Interface", "gsm_um" },
503 /* WTAP_ENCAP_DPNSS */
504 { "Digital Private Signalling System No 1 Link Layer", "dpnss_link" },
506 /* WTAP_ENCAP_PACKETLOGGER */
507 { "PacketLogger", "packetlogger" },
509 /* WTAP_ENCAP_NSTRACE_1_0 */
510 { "NetScaler Encapsulation 1.0 of Ethernet", "nstrace10" },
512 /* WTAP_ENCAP_NSTRACE_2_0 */
513 { "NetScaler Encapsulation 2.0 of Ethernet", "nstrace20" },
515 /* WTAP_ENCAP_FIBRE_CHANNEL_FC2 */
516 { "Fibre Channel FC-2", "fc2" },
518 /* WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS */
519 { "Fibre Channel FC-2 With Frame Delimiter", "fc2sof"},
521 /* WTAP_ENCAP_JPEG_JFIF */
522 { "JPEG/JFIF", "jfif" },
524 /* WTAP_ENCAP_IPNET */
525 { "Solaris IPNET", "ipnet" },
527 /* WTAP_ENCAP_SOCKETCAN */
528 { "SocketCAN", "socketcan" },
530 /* WTAP_ENCAP_IEEE_802_11_NETMON */
531 { "IEEE 802.11 plus Network Monitor radio header", "ieee-802-11-netmon" },
533 /* WTAP_ENCAP_IEEE802_15_4_NOFCS */
534 { "IEEE 802.15.4 Wireless PAN with FCS not present", "wpan-nofcs" },
536 /* WTAP_ENCAP_RAW_IPFIX */
537 { "IPFIX", "ipfix" },
539 /* WTAP_ENCAP_RAW_IP4 */
540 { "Raw IPv4", "rawip4" },
542 /* WTAP_ENCAP_RAW_IP6 */
543 { "Raw IPv6", "rawip6" },
545 /* WTAP_ENCAP_LAPD */
548 /* WTAP_ENCAP_DVBCI */
549 { "DVB-CI (Common Interface)", "dvbci"},
551 /* WTAP_ENCAP_MUX27010 */
552 { "MUX27010", "mux27010"},
554 /* WTAP_ENCAP_MIME */
557 /* WTAP_ENCAP_NETANALYZER */
558 { "netANALYZER", "netanalyzer" },
560 /* WTAP_ENCAP_NETANALYZER_TRANSPARENT */
561 { "netANALYZER-Transparent", "netanalyzer-transparent" },
563 /* WTAP_ENCAP_IP_OVER_IB */
564 { "IP over Infiniband", "ip-over-ib" },
566 /* WTAP_ENCAP_MPEG_2_TS */
567 { "ISO/IEC 13818-1 MPEG2-TS", "mp2ts" },
569 /* WTAP_ENCAP_PPP_ETHER */
570 { "PPP-over-Ethernet session", "pppoes" },
572 /* WTAP_ENCAP_NFC_LLCP */
573 { "NFC LLCP", "nfc-llcp" },
575 /* WTAP_ENCAP_NFLOG */
576 { "NFLOG", "nflog" },
578 /* WTAP_ENCAP_V5_EF */
579 { "V5 Envelope Function", "v5-ef" },
581 /* WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR */
582 { "BACnet MS/TP with Directional Info", "bacnet-ms-tp-with-direction" },
584 /* WTAP_ENCAP_IXVERIWAVE */
585 { "IxVeriWave header and stats block", "ixveriwave" },
587 /* WTAP_ENCAP_IEEE_802_11_AIROPEEK */
588 { "IEEE 802.11 plus AiroPeek radio header", "ieee-802-11-airopeek" },
591 gint wtap_num_encap_types = sizeof(encap_table_base) / sizeof(struct encap_type_info);
592 static GArray* encap_table_arr = NULL;
593 static const struct encap_type_info* encap_table = NULL;
595 static void wtap_init_encap_types(void) {
597 if (encap_table_arr) return;
599 encap_table_arr = g_array_new(FALSE,TRUE,sizeof(struct encap_type_info));
601 g_array_append_vals(encap_table_arr,encap_table_base,wtap_num_encap_types);
603 encap_table = (void*)encap_table_arr->data;
606 int wtap_get_num_encap_types(void) {
607 wtap_init_encap_types();
608 return wtap_num_encap_types;
612 int wtap_register_encap_type(char* name, char* short_name) {
613 struct encap_type_info e;
614 wtap_init_encap_types();
616 e.name = g_strdup(name);
617 e.short_name = g_strdup(short_name);
619 g_array_append_val(encap_table_arr,e);
621 encap_table = (void*)encap_table_arr->data;
623 return wtap_num_encap_types++;
627 /* Name that should be somewhat descriptive. */
629 wtap_encap_string(int encap)
631 if (encap < WTAP_ENCAP_PER_PACKET || encap >= WTAP_NUM_ENCAP_TYPES)
633 else if (encap == WTAP_ENCAP_PER_PACKET)
636 return encap_table[encap].name;
639 /* Name to use in, say, a command-line flag specifying the type. */
641 wtap_encap_short_string(int encap)
643 if (encap < WTAP_ENCAP_PER_PACKET || encap >= WTAP_NUM_ENCAP_TYPES)
645 else if (encap == WTAP_ENCAP_PER_PACKET)
648 return encap_table[encap].short_name;
651 /* Translate a short name to a capture file type. */
653 wtap_short_string_to_encap(const char *short_name)
657 for (encap = 0; encap < WTAP_NUM_ENCAP_TYPES; encap++) {
658 if (encap_table[encap].short_name != NULL &&
659 strcmp(short_name, encap_table[encap].short_name) == 0)
662 return -1; /* no such encapsulation type */
665 static const char *wtap_errlist[] = {
666 "The file isn't a plain file or pipe",
667 "The file is being opened for random access but is a pipe",
668 "The file isn't a capture file in a known format",
669 "File contains record data we don't support",
670 "That file format cannot be written to a pipe",
672 "Files can't be saved in that format",
673 "Files from that network type can't be saved in that format",
674 "That file format doesn't support per-packet encapsulations",
677 "Less data was read than was expected",
678 "The file appears to be damaged or corrupt.",
679 "Less data was written than was requested",
680 "Uncompression error: data oddly truncated",
681 "Uncompression error: data would overflow buffer",
682 "Uncompression error: bad LZ77 offset",
683 "The standard input cannot be opened for random access",
684 "That file format doesn't support compression",
686 "Uncompression error",
689 #define WTAP_ERRLIST_SIZE (sizeof wtap_errlist / sizeof wtap_errlist[0])
692 wtap_strerror(int err)
694 static char errbuf[128];
695 unsigned int wtap_errlist_index;
698 wtap_errlist_index = -1 - err;
699 if (wtap_errlist_index >= WTAP_ERRLIST_SIZE) {
700 g_snprintf(errbuf, 128, "Error %d", err);
703 if (wtap_errlist[wtap_errlist_index] == NULL)
704 return "Unknown reason";
705 return wtap_errlist[wtap_errlist_index];
707 return g_strerror(err);
710 /* Close only the sequential side, freeing up memory it uses.
712 Note that we do *not* want to call the subtype's close function,
713 as it would free any per-subtype data, and that data may be
714 needed by the random-access side.
716 Instead, if the subtype has a "sequential close" function, we call it,
717 to free up stuff used only by the sequential side. */
719 wtap_sequential_close(wtap *wth)
721 if (wth->subtype_sequential_close != NULL)
722 (*wth->subtype_sequential_close)(wth);
724 if (wth->fh != NULL) {
729 if (wth->frame_buffer) {
730 buffer_free(wth->frame_buffer);
731 g_free(wth->frame_buffer);
732 wth->frame_buffer = NULL;
737 g_fast_seek_item_free(gpointer data, gpointer user_data _U_)
743 * Close the file descriptors for the sequential and random streams, but
744 * don't discard any information about those streams. Used on Windows if
745 * we need to rename a file that we have open or if we need to rename on
746 * top of a file we have open.
749 wtap_fdclose(wtap *wth)
752 file_fdclose(wth->fh);
753 if (wth->random_fh != NULL)
754 file_fdclose(wth->random_fh);
758 wtap_close(wtap *wth)
761 wtapng_if_descr_t *wtapng_if_descr;
762 wtapng_if_stats_t *if_stats;
764 wtap_sequential_close(wth);
766 if (wth->subtype_close != NULL)
767 (*wth->subtype_close)(wth);
769 if (wth->random_fh != NULL)
770 file_close(wth->random_fh);
772 if (wth->priv != NULL)
775 if (wth->fast_seek != NULL) {
776 g_ptr_array_foreach(wth->fast_seek, g_fast_seek_item_free, NULL);
777 g_ptr_array_free(wth->fast_seek, TRUE);
779 for(i = 0; i < (gint)wth->number_of_interfaces; i++) {
780 wtapng_if_descr = &g_array_index(wth->interface_data, wtapng_if_descr_t, i);
781 if(wtapng_if_descr->opt_comment != NULL){
782 g_free(wtapng_if_descr->opt_comment);
784 if(wtapng_if_descr->if_name != NULL){
785 g_free(wtapng_if_descr->if_name);
787 if(wtapng_if_descr->if_description != NULL){
788 g_free(wtapng_if_descr->if_description);
790 if(wtapng_if_descr->if_filter_str != NULL){
791 g_free(wtapng_if_descr->if_filter_str);
793 if(wtapng_if_descr->if_filter_bpf_bytes != NULL){
794 g_free(wtapng_if_descr->if_filter_bpf_bytes);
796 if(wtapng_if_descr->if_os != NULL){
797 g_free(wtapng_if_descr->if_os);
799 for(j = 0; j < (gint)wtapng_if_descr->num_stat_entries; j++) {
800 if_stats = &g_array_index(wtapng_if_descr->interface_statistics, wtapng_if_stats_t, j);
801 if(if_stats->opt_comment != NULL){
802 g_free(if_stats->opt_comment);
805 if(wtapng_if_descr->num_stat_entries != 0){
806 g_array_free(wtapng_if_descr->interface_statistics, TRUE);
809 if(wth->number_of_interfaces != 0){
810 g_array_free(wth->interface_data, TRUE);
816 wtap_cleareof(wtap *wth) {
818 file_clearerr(wth->fh);
821 void wtap_set_cb_new_ipv4(wtap *wth, wtap_new_ipv4_callback_t add_new_ipv4) {
823 wth->add_new_ipv4 = add_new_ipv4;
826 void wtap_set_cb_new_ipv6(wtap *wth, wtap_new_ipv6_callback_t add_new_ipv6) {
828 wth->add_new_ipv6 = add_new_ipv6;
832 wtap_read(wtap *wth, int *err, gchar **err_info, gint64 *data_offset)
835 * Set the packet encapsulation to the file's encapsulation
836 * value; if that's not WTAP_ENCAP_PER_PACKET, it's the
837 * right answer (and means that the read routine for this
838 * capture file type doesn't have to set it), and if it
839 * *is* WTAP_ENCAP_PER_PACKET, the caller needs to set it
842 wth->phdr.pkt_encap = wth->file_encap;
844 if (!wth->subtype_read(wth, err, err_info, data_offset)) {
846 * If we didn't get an error indication, we read
847 * the last packet. See if there's any deferred
848 * error, as might, for example, occur if we're
849 * reading a compressed file, and we got an error
850 * reading compressed data from the file, but
851 * got enough compressed data to decompress the
852 * last packet of the file.
855 *err = file_error(wth->fh, err_info);
856 return FALSE; /* failure */
860 * It makes no sense for the captured data length to be bigger
861 * than the actual data length.
863 if (wth->phdr.caplen > wth->phdr.len)
864 wth->phdr.caplen = wth->phdr.len;
867 * Make sure that it's not WTAP_ENCAP_PER_PACKET, as that
868 * probably means the file has that encapsulation type
869 * but the read routine didn't set this packet's
870 * encapsulation type.
872 g_assert(wth->phdr.pkt_encap != WTAP_ENCAP_PER_PACKET);
874 return TRUE; /* success */
878 * Return an approximation of the amount of data we've read sequentially
879 * from the file so far. (gint64, in case that's 64 bits.)
882 wtap_read_so_far(wtap *wth)
884 return file_tell_raw(wth->fh);
893 union wtap_pseudo_header *
894 wtap_pseudoheader(wtap *wth)
896 return &wth->pseudo_header;
900 wtap_buf_ptr(wtap *wth)
902 return buffer_start_ptr(wth->frame_buffer);
906 wtap_seek_read(wtap *wth, gint64 seek_off,
907 union wtap_pseudo_header *pseudo_header, guint8 *pd, int len,
908 int *err, gchar **err_info)
910 return wth->subtype_seek_read(wth, seek_off, pseudo_header, pd, len,