4 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
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.
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.
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.
26 #ifdef HAVE_SYS_TYPES_H
27 #include <sys/types.h>
38 #include "wftap-int.h"
41 #include "file_wrappers.h"
42 #include <wsutil/file_util.h>
47 #include <wsutil/plugins.h>
50 * List of wiretap plugins.
53 void (*register_wtap_module)(void); /* routine to call to register a wiretap module */
56 static GSList *wtap_plugins = NULL;
59 * Callback for each plugin found.
62 check_for_wtap_plugin(GModule *handle)
65 void (*register_wtap_module)(void);
69 * Do we have a register_wtap_module routine?
71 if (!g_module_symbol(handle, "register_wtap_module", &gp)) {
72 /* No, so this isn't a wiretap module plugin. */
77 * Yes - this plugin includes one or more wiretap modules.
79 register_wtap_module = (void (*)(void))gp;
82 * Add this one to the list of wiretap module plugins.
84 plugin = (wtap_plugin *)g_malloc(sizeof (wtap_plugin));
85 plugin->register_wtap_module = register_wtap_module;
86 wtap_plugins = g_slist_append(wtap_plugins, plugin);
91 wtap_register_plugin_types(void)
93 add_plugin_type("file format", check_for_wtap_plugin);
97 register_wtap_module_plugin(gpointer data, gpointer user_data _U_)
99 wtap_plugin *plugin = (wtap_plugin *)data;
101 (plugin->register_wtap_module)();
105 * For all wiretap module plugins, call their register routines.
108 register_all_wiretap_modules(void)
110 g_slist_foreach(wtap_plugins, register_wtap_module_plugin, NULL);
112 #endif /* HAVE_PLUGINS */
115 * Return the size of the file, as reported by the OS.
116 * (gint64, in case that's 64 bits.)
119 wftap_file_size(wftap *wfth, int *err)
123 if (file_fstat((wfth->fh == NULL) ? wfth->random_fh : wfth->fh,
126 return statb.st_size;
130 * Do an fstat on the file.
133 wftap_fstat(wftap *wfth, ws_statb64 *statb, int *err)
135 if (file_fstat((wfth->fh == NULL) ? wfth->random_fh : wfth->fh,
142 wftap_file_type_subtype(wftap *wfth)
144 return wfth->file_type_subtype;
148 wftap_iscompressed(wftap *wfth)
150 return file_iscompressed((wfth->fh == NULL) ? wfth->random_fh : wfth->fh);
154 wftap_snapshot_length(wftap *wfth)
156 return wfth->snapshot_length;
160 wftap_file_encap(wftap *wfth)
162 return wfth->file_encap;
166 wftap_file_tsprecision(wftap *wfth)
168 return wfth->tsprecision;
172 wtap_file_get_shb_info(wftap *wfth)
174 wtapng_section_t *shb_hdr;
180 wth = (wtap*)wfth->tap_specific_data;
183 shb_hdr = g_new(wtapng_section_t,1);
184 shb_hdr->section_length = wth->shb_hdr.section_length;
186 shb_hdr->opt_comment = wth->shb_hdr.opt_comment; /* NULL if not available */
187 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. */
188 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. */
189 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. */
196 wtap_write_shb_comment(wftap *wfth, gchar *comment)
198 wtap* wth = (wtap*)wfth->tap_specific_data;
200 g_free(wth->shb_hdr.opt_comment);
201 wth->shb_hdr.opt_comment = comment;
205 wtapng_iface_descriptions_t *
206 wtap_file_get_idb_info(wftap *wfth)
208 wtapng_iface_descriptions_t *idb_info;
209 wtap *wth = (wtap*)wfth->tap_specific_data;
211 idb_info = g_new(wtapng_iface_descriptions_t,1);
213 idb_info->number_of_interfaces = wth->number_of_interfaces;
214 idb_info->interface_data = wth->interface_data;
219 /* Table of the encapsulation types we know about. */
220 struct encap_type_info {
222 const char *short_name;
225 static struct encap_type_info encap_table_base[] = {
226 /* WTAP_ENCAP_UNKNOWN */
227 { "Unknown", "unknown" },
229 /* WTAP_ENCAP_ETHERNET */
230 { "Ethernet", "ether" },
232 /* WTAP_ENCAP_TOKEN_RING */
233 { "Token Ring", "tr" },
235 /* WTAP_ENCAP_SLIP */
241 /* WTAP_ENCAP_FDDI */
244 /* WTAP_ENCAP_FDDI_BITSWAPPED */
245 { "FDDI with bit-swapped MAC addresses", "fddi-swapped" },
247 /* WTAP_ENCAP_RAW_IP */
248 { "Raw IP", "rawip" },
250 /* WTAP_ENCAP_ARCNET */
251 { "ARCNET", "arcnet" },
253 /* WTAP_ENCAP_ARCNET_LINUX */
254 { "Linux ARCNET", "arcnet_linux" },
256 /* WTAP_ENCAP_ATM_RFC1483 */
257 { "RFC 1483 ATM", "atm-rfc1483" },
259 /* WTAP_ENCAP_LINUX_ATM_CLIP */
260 { "Linux ATM CLIP", "linux-atm-clip" },
262 /* WTAP_ENCAP_LAPB */
265 /* WTAP_ENCAP_ATM_PDUS */
266 { "ATM PDUs", "atm-pdus" },
268 /* WTAP_ENCAP_ATM_PDUS_UNTRUNCATED */
269 { "ATM PDUs - untruncated", "atm-pdus-untruncated" },
271 /* WTAP_ENCAP_NULL */
274 /* WTAP_ENCAP_ASCEND */
275 { "Lucent/Ascend access equipment", "ascend" },
277 /* WTAP_ENCAP_ISDN */
280 /* WTAP_ENCAP_IP_OVER_FC */
281 { "RFC 2625 IP-over-Fibre Channel", "ip-over-fc" },
283 /* WTAP_ENCAP_PPP_WITH_PHDR */
284 { "PPP with Directional Info", "ppp-with-direction" },
286 /* WTAP_ENCAP_IEEE_802_11 */
287 { "IEEE 802.11 Wireless LAN", "ieee-802-11" },
289 /* WTAP_ENCAP_IEEE_802_11_PRISM */
290 { "IEEE 802.11 plus Prism II monitor mode radio header", "ieee-802-11-prism" },
292 /* WTAP_ENCAP_IEEE_802_11_WITH_RADIO */
293 { "IEEE 802.11 Wireless LAN with radio information", "ieee-802-11-radio" },
295 /* WTAP_ENCAP_IEEE_802_11_RADIOTAP */
296 { "IEEE 802.11 plus radiotap radio header", "ieee-802-11-radiotap" },
298 /* WTAP_ENCAP_IEEE_802_11_AVS */
299 { "IEEE 802.11 plus AVS radio header", "ieee-802-11-avs" },
302 { "Linux cooked-mode capture", "linux-sll" },
304 /* WTAP_ENCAP_FRELAY */
305 { "Frame Relay", "frelay" },
307 /* WTAP_ENCAP_FRELAY_WITH_PHDR */
308 { "Frame Relay with Directional Info", "frelay-with-direction" },
310 /* WTAP_ENCAP_CHDLC */
311 { "Cisco HDLC", "chdlc" },
313 /* WTAP_ENCAP_CISCO_IOS */
314 { "Cisco IOS internal", "ios" },
316 /* WTAP_ENCAP_LOCALTALK */
317 { "Localtalk", "ltalk" },
319 /* WTAP_ENCAP_OLD_PFLOG */
320 { "OpenBSD PF Firewall logs, pre-3.4", "pflog-old" },
322 /* WTAP_ENCAP_HHDLC */
323 { "HiPath HDLC", "hhdlc" },
325 /* WTAP_ENCAP_DOCSIS */
326 { "Data Over Cable Service Interface Specification", "docsis" },
328 /* WTAP_ENCAP_COSINE */
329 { "CoSine L2 debug log", "cosine" },
331 /* WTAP_ENCAP_WFLEET_HDLC */
332 { "Wellfleet HDLC", "whdlc" },
334 /* WTAP_ENCAP_SDLC */
337 /* WTAP_ENCAP_TZSP */
338 { "Tazmen sniffer protocol", "tzsp" },
341 { "OpenBSD enc(4) encapsulating interface", "enc" },
343 /* WTAP_ENCAP_PFLOG */
344 { "OpenBSD PF Firewall logs", "pflog" },
346 /* WTAP_ENCAP_CHDLC_WITH_PHDR */
347 { "Cisco HDLC with Directional Info", "chdlc-with-direction" },
349 /* WTAP_ENCAP_BLUETOOTH_H4 */
350 { "Bluetooth H4", "bluetooth-h4" },
352 /* WTAP_ENCAP_MTP2 */
353 { "SS7 MTP2", "mtp2" },
355 /* WTAP_ENCAP_MTP3 */
356 { "SS7 MTP3", "mtp3" },
358 /* WTAP_ENCAP_IRDA */
361 /* WTAP_ENCAP_USER0 */
362 { "USER 0", "user0" },
364 /* WTAP_ENCAP_USER1 */
365 { "USER 1", "user1" },
367 /* WTAP_ENCAP_USER2 */
368 { "USER 2", "user2" },
370 /* WTAP_ENCAP_USER3 */
371 { "USER 3", "user3" },
373 /* WTAP_ENCAP_USER4 */
374 { "USER 4", "user4" },
376 /* WTAP_ENCAP_USER5 */
377 { "USER 5", "user5" },
379 /* WTAP_ENCAP_USER6 */
380 { "USER 6", "user6" },
382 /* WTAP_ENCAP_USER7 */
383 { "USER 7", "user7" },
385 /* WTAP_ENCAP_USER8 */
386 { "USER 8", "user8" },
388 /* WTAP_ENCAP_USER9 */
389 { "USER 9", "user9" },
391 /* WTAP_ENCAP_USER10 */
392 { "USER 10", "user10" },
394 /* WTAP_ENCAP_USER11 */
395 { "USER 11", "user11" },
397 /* WTAP_ENCAP_USER12 */
398 { "USER 12", "user12" },
400 /* WTAP_ENCAP_USER13 */
401 { "USER 13", "user13" },
403 /* WTAP_ENCAP_USER14 */
404 { "USER 14", "user14" },
406 /* WTAP_ENCAP_USER15 */
407 { "USER 15", "user15" },
409 /* WTAP_ENCAP_SYMANTEC */
410 { "Symantec Enterprise Firewall", "symantec" },
412 /* WTAP_ENCAP_APPLE_IP_OVER_IEEE1394 */
413 { "Apple IP-over-IEEE 1394", "ap1394" },
415 /* WTAP_ENCAP_BACNET_MS_TP */
416 { "BACnet MS/TP", "bacnet-ms-tp" },
418 /* WTAP_ENCAP_NETTL_RAW_ICMP */
419 { "Raw ICMP with nettl headers", "raw-icmp-nettl" },
421 /* WTAP_ENCAP_NETTL_RAW_ICMPV6 */
422 { "Raw ICMPv6 with nettl headers", "raw-icmpv6-nettl" },
424 /* WTAP_ENCAP_GPRS_LLC */
425 { "GPRS LLC", "gprs-llc" },
427 /* WTAP_ENCAP_JUNIPER_ATM1 */
428 { "Juniper ATM1", "juniper-atm1" },
430 /* WTAP_ENCAP_JUNIPER_ATM2 */
431 { "Juniper ATM2", "juniper-atm2" },
433 /* WTAP_ENCAP_REDBACK */
434 { "Redback SmartEdge", "redback" },
436 /* WTAP_ENCAP_NETTL_RAW_IP */
437 { "Raw IP with nettl headers", "rawip-nettl" },
439 /* WTAP_ENCAP_NETTL_ETHERNET */
440 { "Ethernet with nettl headers", "ether-nettl" },
442 /* WTAP_ENCAP_NETTL_TOKEN_RING */
443 { "Token Ring with nettl headers", "tr-nettl" },
445 /* WTAP_ENCAP_NETTL_FDDI */
446 { "FDDI with nettl headers", "fddi-nettl" },
448 /* WTAP_ENCAP_NETTL_UNKNOWN */
449 { "Unknown link-layer type with nettl headers", "unknown-nettl" },
451 /* WTAP_ENCAP_MTP2_WITH_PHDR */
452 { "MTP2 with pseudoheader", "mtp2-with-phdr" },
454 /* WTAP_ENCAP_JUNIPER_PPPOE */
455 { "Juniper PPPoE", "juniper-pppoe" },
457 /* WTAP_ENCAP_GCOM_TIE1 */
458 { "GCOM TIE1", "gcom-tie1" },
460 /* WTAP_ENCAP_GCOM_SERIAL */
461 { "GCOM Serial", "gcom-serial" },
463 /* WTAP_ENCAP_NETTL_X25 */
464 { "X.25 with nettl headers", "x25-nettl" },
467 { "K12 protocol analyzer", "k12" },
469 /* WTAP_ENCAP_JUNIPER_MLPPP */
470 { "Juniper MLPPP", "juniper-mlppp" },
472 /* WTAP_ENCAP_JUNIPER_MLFR */
473 { "Juniper MLFR", "juniper-mlfr" },
475 /* WTAP_ENCAP_JUNIPER_ETHER */
476 { "Juniper Ethernet", "juniper-ether" },
478 /* WTAP_ENCAP_JUNIPER_PPP */
479 { "Juniper PPP", "juniper-ppp" },
481 /* WTAP_ENCAP_JUNIPER_FRELAY */
482 { "Juniper Frame-Relay", "juniper-frelay" },
484 /* WTAP_ENCAP_JUNIPER_CHDLC */
485 { "Juniper C-HDLC", "juniper-chdlc" },
487 /* WTAP_ENCAP_JUNIPER_GGSN */
488 { "Juniper GGSN", "juniper-ggsn" },
490 /* WTAP_ENCAP_LINUX_LAPD */
491 { "LAPD with Linux pseudo-header", "linux-lapd" },
493 /* WTAP_ENCAP_CATAPULT_DCT2000 */
494 { "Catapult DCT2000", "dct2000" },
497 { "ASN.1 Basic Encoding Rules", "ber" },
499 /* WTAP_ENCAP_JUNIPER_VP */
500 { "Juniper Voice PIC", "juniper-vp" },
503 { "Raw USB packets", "usb" },
505 /* WTAP_ENCAP_IEEE802_16_MAC_CPS */
506 { "IEEE 802.16 MAC Common Part Sublayer", "ieee-802-16-mac-cps" },
508 /* WTAP_ENCAP_NETTL_RAW_TELNET */
509 { "Raw telnet with nettl headers", "raw-telnet-nettl" },
511 /* WTAP_ENCAP_USB_LINUX */
512 { "USB packets with Linux header", "usb-linux" },
514 /* WTAP_ENCAP_MPEG */
518 { "Per-Packet Information header", "ppi" },
521 { "Extensible Record Format", "erf" },
523 /* WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR */
524 { "Bluetooth H4 with linux header", "bluetooth-h4-linux" },
526 /* WTAP_ENCAP_SITA */
527 { "SITA WAN packets", "sita-wan" },
529 /* WTAP_ENCAP_SCCP */
530 { "SS7 SCCP", "sccp" },
532 /* WTAP_ENCAP_BLUETOOTH_HCI */
533 { "Bluetooth without transport layer", "bluetooth-hci" },
535 /* WTAP_ENCAP_IPMB */
536 { "Intelligent Platform Management Bus", "ipmb" },
538 /* WTAP_ENCAP_IEEE802_15_4 */
539 { "IEEE 802.15.4 Wireless PAN", "wpan" },
541 /* WTAP_ENCAP_X2E_XORAYA */
542 { "X2E Xoraya", "x2e-xoraya" },
544 /* WTAP_ENCAP_FLEXRAY */
545 { "FlexRay", "flexray" },
548 { "Local Interconnect Network", "lin" },
550 /* WTAP_ENCAP_MOST */
551 { "Media Oriented Systems Transport", "most" },
553 /* WTAP_ENCAP_CAN20B */
554 { "Controller Area Network 2.0B", "can20b" },
556 /* WTAP_ENCAP_LAYER1_EVENT */
557 { "EyeSDN Layer 1 event", "layer1-event" },
559 /* WTAP_ENCAP_X2E_SERIAL */
560 { "X2E serial line capture", "x2e-serial" },
565 /* WTAP_ENCAP_IEEE802_15_4_NONASK_PHY */
566 { "IEEE 802.15.4 Wireless PAN non-ASK PHY", "wpan-nonask-phy" },
568 /* WTAP_ENCAP_TNEF */
569 { "Transport-Neutral Encapsulation Format", "tnef" },
571 /* WTAP_ENCAP_USB_LINUX_MMAPPED */
572 { "USB packets with Linux header and padding", "usb-linux-mmap" },
574 /* WTAP_ENCAP_GSM_UM */
575 { "GSM Um Interface", "gsm_um" },
577 /* WTAP_ENCAP_DPNSS */
578 { "Digital Private Signalling System No 1 Link Layer", "dpnss_link" },
580 /* WTAP_ENCAP_PACKETLOGGER */
581 { "PacketLogger", "packetlogger" },
583 /* WTAP_ENCAP_NSTRACE_1_0 */
584 { "NetScaler Encapsulation 1.0 of Ethernet", "nstrace10" },
586 /* WTAP_ENCAP_NSTRACE_2_0 */
587 { "NetScaler Encapsulation 2.0 of Ethernet", "nstrace20" },
589 /* WTAP_ENCAP_FIBRE_CHANNEL_FC2 */
590 { "Fibre Channel FC-2", "fc2" },
592 /* WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS */
593 { "Fibre Channel FC-2 With Frame Delimiter", "fc2sof"},
595 /* WTAP_ENCAP_JPEG_JFIF */
596 { "JPEG/JFIF", "jfif" },
598 /* WTAP_ENCAP_IPNET */
599 { "Solaris IPNET", "ipnet" },
601 /* WTAP_ENCAP_SOCKETCAN */
602 { "SocketCAN", "socketcan" },
604 /* WTAP_ENCAP_IEEE_802_11_NETMON */
605 { "IEEE 802.11 plus Network Monitor radio header", "ieee-802-11-netmon" },
607 /* WTAP_ENCAP_IEEE802_15_4_NOFCS */
608 { "IEEE 802.15.4 Wireless PAN with FCS not present", "wpan-nofcs" },
610 /* WTAP_ENCAP_RAW_IPFIX */
611 { "IPFIX", "ipfix" },
613 /* WTAP_ENCAP_RAW_IP4 */
614 { "Raw IPv4", "rawip4" },
616 /* WTAP_ENCAP_RAW_IP6 */
617 { "Raw IPv6", "rawip6" },
619 /* WTAP_ENCAP_LAPD */
622 /* WTAP_ENCAP_DVBCI */
623 { "DVB-CI (Common Interface)", "dvbci"},
625 /* WTAP_ENCAP_MUX27010 */
626 { "MUX27010", "mux27010"},
628 /* WTAP_ENCAP_MIME */
631 /* WTAP_ENCAP_NETANALYZER */
632 { "netANALYZER", "netanalyzer" },
634 /* WTAP_ENCAP_NETANALYZER_TRANSPARENT */
635 { "netANALYZER-Transparent", "netanalyzer-transparent" },
637 /* WTAP_ENCAP_IP_OVER_IB */
638 { "IP over Infiniband", "ip-over-ib" },
640 /* WTAP_ENCAP_MPEG_2_TS */
641 { "ISO/IEC 13818-1 MPEG2-TS", "mp2ts" },
643 /* WTAP_ENCAP_PPP_ETHER */
644 { "PPP-over-Ethernet session", "pppoes" },
646 /* WTAP_ENCAP_NFC_LLCP */
647 { "NFC LLCP", "nfc-llcp" },
649 /* WTAP_ENCAP_NFLOG */
650 { "NFLOG", "nflog" },
652 /* WTAP_ENCAP_V5_EF */
653 { "V5 Envelope Function", "v5-ef" },
655 /* WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR */
656 { "BACnet MS/TP with Directional Info", "bacnet-ms-tp-with-direction" },
658 /* WTAP_ENCAP_IXVERIWAVE */
659 { "IxVeriWave header and stats block", "ixveriwave" },
661 /* WTAP_ENCAP_IEEE_802_11_AIROPEEK */
662 { "IEEE 802.11 plus AiroPeek radio header", "ieee-802-11-airopeek" },
667 /* WTAP_ENCAP_DBUS */
670 /* WTAP_ENCAP_AX25_KISS */
671 { "AX.25 with KISS header", "ax25-kiss" },
673 /* WTAP_ENCAP_AX25 */
674 { "Amateur Radio AX.25", "ax25" },
676 /* WTAP_ENCAP_SCTP */
679 /* WTAP_ENCAP_INFINIBAND */
680 { "InfiniBand", "infiniband" },
682 /* WTAP_ENCAP_JUNIPER_SVCS */
683 { "Juniper Services", "juniper-svcs" },
685 /* WTAP_ENCAP_USBPCAP */
686 { "USB packets with USBPcap header", "usb-usbpcap" },
688 /* WTAP_ENCAP_RTAC_SERIAL */
689 { "RTAC serial-line", "rtac-serial" },
691 /* WTAP_ENCAP_BLUETOOTH_LE_LL */
692 { "Bluetooth Low Energy Link Layer", "bluetooth-le-ll" },
694 /* WTAP_ENCAP_WIRESHARK_UPPER_PDU */
695 { "Wireshark Upper PDU export", "wireshark-upper-pdu" },
697 /* WTAP_ENCAP_STANAG_4607 */
698 { "STANAG 4607", "s4607" },
700 /* WTAP_ENCAP_STANAG_5066_D_PDU */
701 { "STANAG 5066 Data Transfer Sublayer PDUs(D_PDU)", "s5066-dpdu"},
703 /* WTAP_ENCAP_NETLINK */
704 { "Netlink", "Linux netlink" },
706 /* WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR */
707 { "Bluetooth Linux Monitor", "bluetooth-linux-monitor" },
709 /* WTAP_ENCAP_BLUETOOTH_BREDR_BB */
710 { "Bluetooth BR/EDR Baseband RF", "bluetooth-bredr-bb-rf" },
712 /* WTAP_ENCAP_BLUETOOTH_LE_LL_WITH_PHDR */
713 { "Bluetooth Low Energy Link Layer RF", "bluetooth-le-ll-rf" },
715 /* WTAP_ENCAP_NSTRACE_3_0 */
716 { "NetScaler Encapsulation 3.0 of Ethernet", "nstrace30" },
718 /* WTAP_ENCAP_LOGCAT */
719 { "Android Logcat Binary format", "logcat" },
721 /* WTAP_ENCAP_LOGCAT_BRIEF */
722 { "Android Logcat Brief text format", "logcat_brief" },
724 /* WTAP_ENCAP_LOGCAT_PROCESS */
725 { "Android Logcat Process text format", "logcat_process" },
727 /* WTAP_ENCAP_LOGCAT_TAG */
728 { "Android Logcat Tag text format", "logcat_tag" },
730 /* WTAP_ENCAP_LOGCAT_THREAD */
731 { "Android Logcat Thread text format", "logcat_thread" },
733 /* WTAP_ENCAP_LOGCAT_TIME */
734 { "Android Logcat Time text format", "logcat_time" },
736 /* WTAP_ENCAP_LOGCAT_THREADTIME */
737 { "Android Logcat Threadtime text format", "logcat_threadtime" },
739 /* WTAP_ENCAP_LOGCAT_LONG */
740 { "Android Logcat Long text format", "logcat_long" },
742 /* WTAP_ENCAP_PKTAP */
743 { "Apple PKTAP", "pktap" },
745 /* WTAP_ENCAP_EPON */
746 { "Ethernet Passive Optical Network", "epon" },
750 gint wtap_num_encap_types = sizeof(encap_table_base) / sizeof(struct encap_type_info);
751 static GArray* encap_table_arr = NULL;
753 #define encap_table_entry(encap) \
754 g_array_index(encap_table_arr, struct encap_type_info, encap)
756 static void wtap_init_encap_types(void) {
758 if (encap_table_arr) return;
760 encap_table_arr = g_array_new(FALSE,TRUE,sizeof(struct encap_type_info));
762 g_array_append_vals(encap_table_arr,encap_table_base,wtap_num_encap_types);
765 int wtap_get_num_encap_types(void) {
766 wtap_init_encap_types();
767 return wtap_num_encap_types;
771 int wtap_register_encap_type(const char* name, const char* short_name) {
772 struct encap_type_info e;
773 wtap_init_encap_types();
775 e.name = g_strdup(name);
776 e.short_name = g_strdup(short_name);
778 g_array_append_val(encap_table_arr,e);
780 return wtap_num_encap_types++;
784 /* Name that should be somewhat descriptive. */
786 wtap_encap_string(int encap)
788 if (encap < WTAP_ENCAP_PER_PACKET || encap >= WTAP_NUM_ENCAP_TYPES)
790 else if (encap == WTAP_ENCAP_PER_PACKET)
793 return encap_table_entry(encap).name;
796 /* Name to use in, say, a command-line flag specifying the type. */
798 wtap_encap_short_string(int encap)
800 if (encap < WTAP_ENCAP_PER_PACKET || encap >= WTAP_NUM_ENCAP_TYPES)
802 else if (encap == WTAP_ENCAP_PER_PACKET)
805 return encap_table_entry(encap).short_name;
808 /* Translate a short name to a capture file type. */
810 wtap_short_string_to_encap(const char *short_name)
814 for (encap = 0; encap < WTAP_NUM_ENCAP_TYPES; encap++) {
815 if (encap_table_entry(encap).short_name != NULL &&
816 strcmp(short_name, encap_table_entry(encap).short_name) == 0)
819 return -1; /* no such encapsulation type */
822 static const char *wtap_errlist[] = {
823 "The file isn't a plain file or pipe",
824 "The file is being opened for random access but is a pipe",
825 "The file isn't a capture file in a known format",
826 "File contains record data we don't support",
827 "That file format cannot be written to a pipe",
829 "Files can't be saved in that format",
830 "Files from that network type can't be saved in that format",
831 "That file format doesn't support per-packet encapsulations",
834 "Less data was read than was expected",
835 "The file appears to be damaged or corrupt",
836 "Less data was written than was requested",
837 "Uncompression error: data oddly truncated",
838 "Uncompression error: data would overflow buffer",
839 "Uncompression error: bad LZ77 offset",
840 "The standard input cannot be opened for random access",
841 "That file format doesn't support compression",
844 "Uncompression error",
846 "The packet being written is too large for that format"
848 #define WTAP_ERRLIST_SIZE (sizeof wtap_errlist / sizeof wtap_errlist[0])
851 wtap_strerror(int err)
853 static char errbuf[128];
854 unsigned int wtap_errlist_index;
857 wtap_errlist_index = -1 - err;
858 if (wtap_errlist_index >= WTAP_ERRLIST_SIZE) {
859 g_snprintf(errbuf, 128, "Error %d", err);
862 if (wtap_errlist[wtap_errlist_index] == NULL)
863 return "Unknown reason";
864 return wtap_errlist[wtap_errlist_index];
866 return g_strerror(err);
869 /* Close only the sequential side, freeing up memory it uses.
871 Note that we do *not* want to call the subtype's close function,
872 as it would free any per-subtype data, and that data may be
873 needed by the random-access side.
875 Instead, if the subtype has a "sequential close" function, we call it,
876 to free up stuff used only by the sequential side. */
878 wftap_sequential_close(wftap *wfth)
880 if (wfth->subtype_sequential_close != NULL)
881 (*wfth->subtype_sequential_close)(wfth);
883 if (wfth->fh != NULL) {
884 file_close(wfth->fh);
888 if (wfth->frame_buffer) {
889 buffer_free(wfth->frame_buffer);
890 g_free(wfth->frame_buffer);
891 wfth->frame_buffer = NULL;
896 g_fast_seek_item_free(gpointer data, gpointer user_data _U_)
902 * Close the file descriptors for the sequential and random streams, but
903 * don't discard any information about those streams. Used on Windows if
904 * we need to rename a file that we have open or if we need to rename on
905 * top of a file we have open.
908 wftap_fdclose(wftap *wfth)
910 if (wfth->fh != NULL)
911 file_fdclose(wfth->fh);
912 if (wfth->random_fh != NULL)
913 file_fdclose(wfth->random_fh);
917 wftap_close(wftap *wfth)
919 wftap_sequential_close(wfth);
921 if (wfth->subtype_close != NULL)
922 (*wfth->subtype_close)(wfth);
924 if (wfth->random_fh != NULL)
925 file_close(wfth->random_fh);
927 if (wfth->priv != NULL)
930 if (wfth->fast_seek != NULL) {
931 g_ptr_array_foreach(wfth->fast_seek, g_fast_seek_item_free, NULL);
932 g_ptr_array_free(wfth->fast_seek, TRUE);
935 if (wfth->tap_specific_data != NULL)
936 g_free(wfth->tap_specific_data);
942 wtap_close(wftap *wfth)
945 wtapng_if_descr_t *wtapng_if_descr;
946 wtapng_if_stats_t *if_stats;
947 wtap* wth = (wtap*)wfth->tap_specific_data;
949 for(i = 0; i < (gint)wth->number_of_interfaces; i++) {
950 wtapng_if_descr = &g_array_index(wth->interface_data, wtapng_if_descr_t, i);
951 if(wtapng_if_descr->opt_comment != NULL){
952 g_free(wtapng_if_descr->opt_comment);
954 if(wtapng_if_descr->if_name != NULL){
955 g_free(wtapng_if_descr->if_name);
957 if(wtapng_if_descr->if_description != NULL){
958 g_free(wtapng_if_descr->if_description);
960 if(wtapng_if_descr->if_filter_str != NULL){
961 g_free(wtapng_if_descr->if_filter_str);
963 if(wtapng_if_descr->if_filter_bpf_bytes != NULL){
964 g_free(wtapng_if_descr->if_filter_bpf_bytes);
966 if(wtapng_if_descr->if_os != NULL){
967 g_free(wtapng_if_descr->if_os);
969 for(j = 0; j < (gint)wtapng_if_descr->num_stat_entries; j++) {
970 if_stats = &g_array_index(wtapng_if_descr->interface_statistics, wtapng_if_stats_t, j);
971 if(if_stats->opt_comment != NULL){
972 g_free(if_stats->opt_comment);
975 if(wtapng_if_descr->num_stat_entries != 0){
976 g_array_free(wtapng_if_descr->interface_statistics, TRUE);
979 if(wth->number_of_interfaces != 0){
980 g_array_free(wth->interface_data, TRUE);
987 wftap_cleareof(wftap *wfth) {
989 file_clearerr(wfth->fh);
992 void wtap_set_cb_new_ipv4(wftap *wfth, wtap_new_ipv4_callback_t add_new_ipv4) {
995 wtap* wth = (wtap*)wfth->tap_specific_data;
997 wth->add_new_ipv4 = add_new_ipv4;
1001 void wtap_set_cb_new_ipv6(wftap *wfth, wtap_new_ipv6_callback_t add_new_ipv6) {
1004 wtap* wth = (wtap*)wfth->tap_specific_data;
1006 wth->add_new_ipv6 = add_new_ipv6;
1011 wtap_read(wftap *wfth, int *err, gchar **err_info, gint64 *data_offset)
1013 wtap* wth = (wtap*)wfth->tap_specific_data;
1016 * Set the packet encapsulation to the file's encapsulation
1017 * value; if that's not WTAP_ENCAP_PER_PACKET, it's the
1018 * right answer (and means that the read routine for this
1019 * capture file type doesn't have to set it), and if it
1020 * *is* WTAP_ENCAP_PER_PACKET, the caller needs to set it
1023 wth->phdr.pkt_encap = wfth->file_encap;
1025 if (!wfth->subtype_read(wfth, err, err_info, data_offset)) {
1027 * If we didn't get an error indication, we read
1028 * the last packet. See if there's any deferred
1029 * error, as might, for example, occur if we're
1030 * reading a compressed file, and we got an error
1031 * reading compressed data from the file, but
1032 * got enough compressed data to decompress the
1033 * last packet of the file.
1036 *err = file_error(wfth->fh, err_info);
1037 return FALSE; /* failure */
1041 * It makes no sense for the captured data length to be bigger
1042 * than the actual data length.
1044 if (wth->phdr.caplen > wth->phdr.len)
1045 wth->phdr.caplen = wth->phdr.len;
1048 * Make sure that it's not WTAP_ENCAP_PER_PACKET, as that
1049 * probably means the file has that encapsulation type
1050 * but the read routine didn't set this packet's
1051 * encapsulation type.
1053 g_assert(wth->phdr.pkt_encap != WTAP_ENCAP_PER_PACKET);
1055 return TRUE; /* success */
1059 * Read packet data into a Buffer, growing the buffer as necessary.
1061 * This returns an error on a short read, even if the short read hit
1062 * the EOF immediately. (The assumption is that each packet has a
1063 * header followed by raw packet data, and that we've already read the
1064 * header, so if we get an EOF trying to read the packet data, the file
1065 * has been cut short, even if the read didn't read any data at all.)
1068 wtap_read_packet_bytes(FILE_T fh, Buffer *buf, guint length, int *err,
1073 buffer_assure_space(buf, length);
1074 errno = WTAP_ERR_CANT_READ;
1075 bytes_read = file_read(buffer_start_ptr(buf), length, fh);
1077 if (bytes_read < 0 || (guint)bytes_read != length) {
1078 *err = file_error(fh, err_info);
1080 *err = WTAP_ERR_SHORT_READ;
1087 * Return an approximation of the amount of data we've read sequentially
1088 * from the file so far. (gint64, in case that's 64 bits.)
1091 wftap_read_so_far(wftap *wfth)
1093 return file_tell_raw(wfth->fh);
1096 struct wtap_pkthdr *
1097 wtap_phdr(wftap *wfth)
1099 wtap* wth = (wtap*)wfth->tap_specific_data;
1104 wftap_buf_ptr(wftap *wfth)
1106 return buffer_start_ptr(wfth->frame_buffer);
1110 wftap_seek_read(wftap *wfth, gint64 seek_off,
1111 void* tap_pkthdr, Buffer *buf, int *err, gchar **err_info)
1113 wtap* wth = (wtap*)wfth->tap_specific_data;
1115 if (!wfth->subtype_seek_read(wfth, seek_off, tap_pkthdr, buf, err, err_info))
1119 * It makes no sense for the captured data length to be bigger
1120 * than the actual data length.
1122 if (wth->phdr.caplen > wth->phdr.len)
1123 wth->phdr.caplen = wth->phdr.len;
1126 * Make sure that it's not WTAP_ENCAP_PER_PACKET, as that
1127 * probably means the file has that encapsulation type
1128 * but the read routine didn't set this packet's
1129 * encapsulation type.
1131 g_assert(wth->phdr.pkt_encap != WTAP_ENCAP_PER_PACKET);