4 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
6 * SPDX-License-Identifier: GPL-2.0-or-later
13 #define WS_LOG_DOMAIN LOG_DOMAIN_WIRETAP
17 #include <sys/types.h>
19 #include "wtap_opttypes.h"
21 #include "file_wrappers.h"
22 #include <wsutil/file_util.h>
23 #include <wsutil/buffer.h>
24 #include <wsutil/ws_assert.h>
25 #include <wsutil/exported_pdu_tlvs.h>
27 #include <wsutil/plugins.h>
31 static plugins_t
*libwiretap_plugins
;
34 #define PADDING4(x) ((((x + 3) >> 2) << 2) - x)
36 static GSList
*wtap_plugins
;
40 wtap_register_plugin(const wtap_plugin
*plug
)
42 wtap_plugins
= g_slist_prepend(wtap_plugins
, (wtap_plugin
*)plug
);
44 #else /* HAVE_PLUGINS */
46 wtap_register_plugin(const wtap_plugin
*plug _U_
)
48 ws_warning("wtap_register_plugin: built without support for binary plugins");
50 #endif /* HAVE_PLUGINS */
53 wtap_plugins_supported(void)
56 return plugins_supported() ? 0 : 1;
63 call_plugin_register_wtap_module(void *data
, void *user_data _U_
)
65 wtap_plugin
*plug
= (wtap_plugin
*)data
;
67 if (plug
->register_wtap_module
) {
68 plug
->register_wtap_module();
73 * Return the size of the file, as reported by the OS.
74 * (int64_t, in case that's 64 bits.)
77 wtap_file_size(wtap
*wth
, int *err
)
81 if (file_fstat((wth
->fh
== NULL
) ? wth
->random_fh
: wth
->fh
,
88 * Do an fstat on the file.
91 wtap_fstat(wtap
*wth
, ws_statb64
*statb
, int *err
)
93 if (file_fstat((wth
->fh
== NULL
) ? wth
->random_fh
: wth
->fh
,
100 wtap_file_type_subtype(wtap
*wth
)
102 return wth
->file_type_subtype
;
106 wtap_snapshot_length(wtap
*wth
)
108 return wth
->snapshot_length
;
112 wtap_file_encap(wtap
*wth
)
114 return wth
->file_encap
;
118 wtap_file_tsprec(wtap
*wth
)
120 return wth
->file_tsprec
;
124 wtap_file_get_num_shbs(wtap
*wth
)
126 return wth
->shb_hdrs
->len
;
130 wtap_file_get_shb(wtap
*wth
, unsigned shb_num
)
132 if ((wth
== NULL
) || (wth
->shb_hdrs
== NULL
) || (shb_num
>= wth
->shb_hdrs
->len
))
135 return g_array_index(wth
->shb_hdrs
, wtap_block_t
, shb_num
);
139 wtap_file_get_shb_global_interface_id(wtap
*wth
, unsigned shb_num
, uint32_t interface_id
)
141 if ((wth
== NULL
) || (wth
->shb_hdrs
== NULL
) || (shb_num
>= wth
->shb_hdrs
->len
)) {
142 ws_warning("unexpected SHB %u and interface id %u", shb_num
, interface_id
);
146 return interface_id
+ g_array_index(wth
->shb_iface_to_global
, unsigned, shb_num
);
150 wtap_file_get_shb_for_new_file(wtap
*wth
)
153 wtap_block_t shb_hdr_src
, shb_hdr_dest
;
156 if ((wth
== NULL
) || (wth
->shb_hdrs
== NULL
) || (wth
->shb_hdrs
->len
== 0))
159 shb_hdrs
= g_array_new(false, false, sizeof(wtap_block_t
));
161 for (shb_count
= 0; shb_count
< wth
->shb_hdrs
->len
; shb_count
++) {
162 shb_hdr_src
= g_array_index(wth
->shb_hdrs
, wtap_block_t
, shb_count
);
163 shb_hdr_dest
= wtap_block_make_copy(shb_hdr_src
);
164 g_array_append_val(shb_hdrs
, shb_hdr_dest
);
171 * XXX - replace with APIs that let us handle multiple comments.
174 wtap_write_shb_comment(wtap
*wth
, char *comment
)
176 if ((wth
!= NULL
) && (wth
->shb_hdrs
!= NULL
) && (wth
->shb_hdrs
->len
> 0)) {
177 wtap_block_set_nth_string_option_value(g_array_index(wth
->shb_hdrs
, wtap_block_t
, 0), OPT_COMMENT
, 0, comment
, (size_t)(comment
? strlen(comment
) : 0));
181 wtapng_iface_descriptions_t
*
182 wtap_file_get_idb_info(wtap
*wth
)
184 wtapng_iface_descriptions_t
*idb_info
;
186 idb_info
= g_new(wtapng_iface_descriptions_t
,1);
188 idb_info
->interface_data
= wth
->interface_data
;
194 wtap_get_next_interface_description(wtap
*wth
)
196 if (wth
->next_interface_data
< wth
->interface_data
->len
) {
198 * We have an IDB to return. Advance to the next
199 * IDB, and return this one.
203 idb
= g_array_index(wth
->interface_data
, wtap_block_t
,
204 wth
->next_interface_data
);
205 wth
->next_interface_data
++;
210 * We've returned all the interface descriptions we currently
211 * have. (There may be more in the future, if we read more.)
217 wtap_file_get_num_dsbs(wtap
*wth
)
222 return wth
->dsbs
->len
;
226 wtap_file_get_dsb(wtap
*wth
, unsigned dsb_num
)
228 if ((wth
== NULL
) || (wth
->dsbs
== NULL
) || (dsb_num
>= wth
->dsbs
->len
))
231 return g_array_index(wth
->dsbs
, wtap_block_t
, dsb_num
);
235 wtap_file_add_decryption_secrets(wtap
*wth
, const wtap_block_t dsb
)
238 wth
->dsbs
= g_array_new(false, false, sizeof(wtap_block_t
));
240 g_array_append_val(wth
->dsbs
, dsb
);
244 wtap_file_discard_decryption_secrets(wtap
*wth
)
246 if (!wth
->dsbs
|| wth
->dsbs
->len
== 0)
249 wtap_block_array_free(wth
->dsbs
);
255 wtap_file_add_meta_event(wtap
*wth
, const wtap_block_t mev
)
257 if (!wth
->meta_events
) {
258 wth
->meta_events
= g_array_new(false, false, sizeof(wtap_block_t
));
260 g_array_append_val(wth
->meta_events
, mev
);
264 wtap_file_discard_meta_events(wtap
*wth
)
266 if (!wth
->meta_events
|| wth
->meta_events
->len
== 0)
269 wtap_block_array_free(wth
->meta_events
);
270 wth
->meta_events
= NULL
;
275 wtap_add_idb(wtap
*wth
, wtap_block_t idb
)
277 g_array_append_val(wth
->interface_data
, idb
);
281 wtap_generate_idb(int encap
, int tsprec
, int snaplen
)
284 wtapng_if_descr_mandatory_t
*if_descr_mand
;
286 ws_assert(encap
!= WTAP_ENCAP_UNKNOWN
&&
287 encap
!= WTAP_ENCAP_PER_PACKET
&&
288 encap
!= WTAP_ENCAP_NONE
);
290 idb
= wtap_block_create(WTAP_BLOCK_IF_ID_AND_INFO
);
292 if_descr_mand
= (wtapng_if_descr_mandatory_t
*)wtap_block_get_mandatory_data(idb
);
293 if_descr_mand
->wtap_encap
= encap
;
294 if_descr_mand
->tsprecision
= tsprec
;
295 if (tsprec
< 0 || tsprec
> WS_TSPREC_MAX
) {
297 * Either WTAP_TSPREC_PER_PACKET, WTAP_TSPREC_UNKNOWN,
298 * or not a valid WTAP_TSPREC_ value.
300 * Unknown timestamp precision; use the default of
301 * microsecond resolution.
303 tsprec
= 6; /* microsecond resolution */
307 * Compute 10^{params->tsprec}.
309 if_descr_mand
->time_units_per_second
= 1;
310 for (int i
= 0; i
< tsprec
; i
++)
311 if_descr_mand
->time_units_per_second
*= 10;
313 if (tsprec
!= WTAP_TSPREC_USEC
) {
315 * Microsecond precision is the default, so we only
316 * add an option if the precision isn't microsecond
319 wtap_block_add_uint8_option(idb
, OPT_IDB_TSRESOL
, tsprec
);
323 * No snapshot length was specified. Pick an
324 * appropriate snapshot length for this
327 * We use WTAP_MAX_PACKET_SIZE_STANDARD for everything except
328 * D-Bus, which has a maximum packet size of 128MB,
329 * and EBHSCR, which has a maximum packet size of 8MB,
330 * which is more than we want to put into files
331 * with other link-layer header types, as that
332 * might cause some software reading those files
333 * to allocate an unnecessarily huge chunk of
334 * memory for a packet buffer.
336 if (encap
== WTAP_ENCAP_DBUS
)
337 snaplen
= 128*1024*1024;
338 else if (encap
== WTAP_ENCAP_EBHSCR
)
339 snaplen
= 8*1024*1024;
341 snaplen
= WTAP_MAX_PACKET_SIZE_STANDARD
;
343 if_descr_mand
->snap_len
= snaplen
;
344 if_descr_mand
->num_stat_entries
= 0; /* Number of ISBs */
345 if_descr_mand
->interface_statistics
= NULL
;
351 wtap_add_generated_idb(wtap
*wth
)
355 idb
= wtap_generate_idb(wth
->file_encap
, wth
->file_tsprec
, wth
->snapshot_length
);
359 wtap_add_idb(wth
, idb
);
363 wtap_free_idb_info(wtapng_iface_descriptions_t
*idb_info
)
365 if (idb_info
== NULL
)
368 wtap_block_array_free(idb_info
->interface_data
);
373 wtap_get_debug_if_descr(const wtap_block_t if_descr
,
375 const char* line_end
)
378 wtapng_if_descr_mandatory_t
* if_descr_mand
;
379 GString
*info
= g_string_new("");
383 if_filter_opt_t if_filter
;
387 if_descr_mand
= (wtapng_if_descr_mandatory_t
*)wtap_block_get_mandatory_data(if_descr
);
388 if (wtap_block_get_string_option_value(if_descr
, OPT_IDB_NAME
, &tmp_content
) == WTAP_OPTTYPE_SUCCESS
) {
389 g_string_printf(info
,
390 "%*cName = %s%s", indent
, ' ',
391 tmp_content
? tmp_content
: "UNKNOWN",
395 if (wtap_block_get_string_option_value(if_descr
, OPT_IDB_DESCRIPTION
, &tmp_content
) == WTAP_OPTTYPE_SUCCESS
) {
396 g_string_append_printf(info
,
397 "%*cDescription = %s%s", indent
, ' ',
398 tmp_content
? tmp_content
: "NONE",
402 g_string_append_printf(info
,
403 "%*cEncapsulation = %s (%d - %s)%s", indent
, ' ',
404 wtap_encap_description(if_descr_mand
->wtap_encap
),
405 if_descr_mand
->wtap_encap
,
406 wtap_encap_name(if_descr_mand
->wtap_encap
),
409 if (wtap_block_get_string_option_value(if_descr
, OPT_IDB_HARDWARE
, &tmp_content
) == WTAP_OPTTYPE_SUCCESS
) {
410 g_string_append_printf(info
,
411 "%*cHardware = %s%s", indent
, ' ',
412 tmp_content
? tmp_content
: "NONE",
416 if (wtap_block_get_uint64_option_value(if_descr
, OPT_IDB_SPEED
, &tmp64
) == WTAP_OPTTYPE_SUCCESS
) {
417 g_string_append_printf(info
,
418 "%*cSpeed = %" PRIu64
"%s", indent
, ' ',
423 g_string_append_printf(info
,
424 "%*cCapture length = %u%s", indent
, ' ',
425 if_descr_mand
->snap_len
,
428 if (wtap_block_get_uint8_option_value(if_descr
, OPT_IDB_FCSLEN
, &tmp8
) == WTAP_OPTTYPE_SUCCESS
) {
429 g_string_append_printf(info
,
430 "%*cFCS length = %u%s", indent
, ' ',
435 g_string_append_printf(info
,
436 "%*cTime precision = %s (%d)%s", indent
, ' ',
437 wtap_tsprec_string(if_descr_mand
->tsprecision
),
438 if_descr_mand
->tsprecision
,
441 g_string_append_printf(info
,
442 "%*cTime ticks per second = %" PRIu64
"%s", indent
, ' ',
443 if_descr_mand
->time_units_per_second
,
446 if (wtap_block_get_uint8_option_value(if_descr
, OPT_IDB_TSRESOL
, &tmp8
) == WTAP_OPTTYPE_SUCCESS
) {
447 g_string_append_printf(info
,
448 "%*cTime resolution = 0x%.2x%s", indent
, ' ',
453 if (wtap_block_get_int64_option_value(if_descr
, OPT_IDB_TSOFFSET
, &itmp64
) == WTAP_OPTTYPE_SUCCESS
) {
454 g_string_append_printf(info
,
455 "%*cTimestamp offset = %" PRId64
"%s", indent
, ' ',
460 if (wtap_block_get_if_filter_option_value(if_descr
, OPT_IDB_FILTER
, &if_filter
) == WTAP_OPTTYPE_SUCCESS
) {
461 switch (if_filter
.type
) {
464 g_string_append_printf(info
,
465 "%*cFilter string = %s%s", indent
, ' ',
466 if_filter
.data
.filter_str
,
471 g_string_append_printf(info
,
472 "%*cBPF filter length = %u%s", indent
, ' ',
473 if_filter
.data
.bpf_prog
.bpf_prog_len
,
478 g_string_append_printf(info
,
479 "%*cUnknown filter type %u%s", indent
, ' ',
486 if (wtap_block_get_string_option_value(if_descr
, OPT_IDB_OS
, &tmp_content
) == WTAP_OPTTYPE_SUCCESS
) {
487 g_string_append_printf(info
,
488 "%*cOperating system = %s%s", indent
, ' ',
489 tmp_content
? tmp_content
: "UNKNOWN",
494 * XXX - support multiple comments.
496 if (wtap_block_get_nth_string_option_value(if_descr
, OPT_COMMENT
, 0, &tmp_content
) == WTAP_OPTTYPE_SUCCESS
) {
497 g_string_append_printf(info
,
498 "%*cComment = %s%s", indent
, ' ',
499 tmp_content
? tmp_content
: "NONE",
503 g_string_append_printf(info
,
504 "%*cNumber of stat entries = %u%s", indent
, ' ',
505 if_descr_mand
->num_stat_entries
,
508 return g_string_free(info
, FALSE
);
512 wtap_file_get_nrb(wtap
*wth
)
514 if ((wth
== NULL
) || (wth
->nrbs
== NULL
) || (wth
->nrbs
->len
== 0))
517 return g_array_index(wth
->nrbs
, wtap_block_t
, 0);
521 wtap_file_get_nrb_for_new_file(wtap
*wth
)
524 wtap_block_t nrb_src
, nrb_dest
;
527 if ((wth
== NULL
|| wth
->nrbs
== NULL
) || (wth
->nrbs
->len
== 0))
530 nrbs
= g_array_new(false, false, sizeof(wtap_block_t
));
532 for (nrb_count
= 0; nrb_count
< wth
->nrbs
->len
; nrb_count
++) {
533 nrb_src
= g_array_index(wth
->nrbs
, wtap_block_t
, nrb_count
);
534 nrb_dest
= wtap_block_make_copy(nrb_src
);
535 g_array_append_val(nrbs
, nrb_dest
);
542 wtap_dump_params_init(wtap_dump_params
*params
, wtap
*wth
)
544 memset(params
, 0, sizeof(*params
));
548 params
->encap
= wtap_file_encap(wth
);
549 params
->snaplen
= wtap_snapshot_length(wth
);
550 params
->tsprec
= wtap_file_tsprec(wth
);
551 params
->shb_hdrs
= wtap_file_get_shb_for_new_file(wth
);
552 params
->idb_inf
= wtap_file_get_idb_info(wth
);
553 /* Assume that the input handle remains open until the dumper is closed.
554 * Refer to the DSBs from the input file, wtap_dump will then copy DSBs
555 * as they become available. */
556 params
->shb_iface_to_global
= wth
->shb_iface_to_global
;
557 params
->nrbs_growing
= wth
->nrbs
;
558 params
->dsbs_growing
= wth
->dsbs
;
559 params
->mevs_growing
= wth
->meta_events
;
560 params
->dont_copy_idbs
= false;
564 * XXX - eventually, we should make this wtap_dump_params_init(),
565 * and have everything copy IDBs as they're read.
568 wtap_dump_params_init_no_idbs(wtap_dump_params
*params
, wtap
*wth
)
570 memset(params
, 0, sizeof(*params
));
574 params
->encap
= wtap_file_encap(wth
);
575 params
->snaplen
= wtap_snapshot_length(wth
);
576 params
->tsprec
= wtap_file_tsprec(wth
);
577 params
->shb_hdrs
= wtap_file_get_shb_for_new_file(wth
);
578 params
->idb_inf
= wtap_file_get_idb_info(wth
);
579 /* Assume that the input handle remains open until the dumper is closed.
580 * Refer to the DSBs from the input file, wtap_dump will then copy DSBs
581 * as they become available. */
582 params
->shb_iface_to_global
= wth
->shb_iface_to_global
;
583 params
->nrbs_growing
= wth
->nrbs
;
584 params
->dsbs_growing
= wth
->dsbs
;
585 params
->dont_copy_idbs
= true;
589 wtap_dump_params_discard_name_resolution(wtap_dump_params
*params
)
591 params
->nrbs_growing
= NULL
;
595 wtap_dump_params_discard_decryption_secrets(wtap_dump_params
*params
)
597 params
->dsbs_initial
= NULL
;
598 params
->dsbs_growing
= NULL
;
602 wtap_dump_params_discard_meta_events(wtap_dump_params
*params
)
604 params
->mevs_growing
= NULL
;
608 wtap_dump_params_cleanup(wtap_dump_params
*params
)
610 wtap_block_array_free(params
->shb_hdrs
);
611 /* params->idb_inf is currently expected to be freed by the caller. */
613 memset(params
, 0, sizeof(*params
));
617 wtap_dump_params_generate_idb(const wtap_dump_params
*params
)
619 return wtap_generate_idb(params
->encap
, params
->tsprec
, params
->snaplen
);
622 /* Table of the encapsulation types we know about. */
623 struct encap_type_info
{
625 const char *description
;
628 static struct encap_type_info encap_table_base
[] = {
629 /* WTAP_ENCAP_UNKNOWN */
630 { "unknown", "Unknown" },
632 /* WTAP_ENCAP_ETHERNET */
633 { "ether", "Ethernet" },
635 /* WTAP_ENCAP_TOKEN_RING */
636 { "tr", "Token Ring" },
638 /* WTAP_ENCAP_SLIP */
644 /* WTAP_ENCAP_FDDI */
647 /* WTAP_ENCAP_FDDI_BITSWAPPED */
648 { "fddi-swapped", "FDDI with bit-swapped MAC addresses" },
650 /* WTAP_ENCAP_RAW_IP */
651 { "rawip", "Raw IP" },
653 /* WTAP_ENCAP_ARCNET */
654 { "arcnet", "ARCNET" },
656 /* WTAP_ENCAP_ARCNET_LINUX */
657 { "arcnet_linux", "Linux ARCNET" },
659 /* WTAP_ENCAP_ATM_RFC1483 */
660 { "atm-rfc1483", "RFC 1483 ATM" },
662 /* WTAP_ENCAP_LINUX_ATM_CLIP */
663 { "linux-atm-clip", "Linux ATM CLIP" },
665 /* WTAP_ENCAP_LAPB */
668 /* WTAP_ENCAP_ATM_PDUS */
669 { "atm-pdus", "ATM PDUs" },
671 /* WTAP_ENCAP_ATM_PDUS_UNTRUNCATED */
672 { "atm-pdus-untruncated", "ATM PDUs - untruncated" },
674 /* WTAP_ENCAP_NULL */
675 { "null", "NULL/Loopback" },
677 /* WTAP_ENCAP_ASCEND */
678 { "ascend", "Lucent/Ascend access equipment" },
680 /* WTAP_ENCAP_ISDN */
683 /* WTAP_ENCAP_IP_OVER_FC */
684 { "ip-over-fc", "RFC 2625 IP-over-Fibre Channel" },
686 /* WTAP_ENCAP_PPP_WITH_PHDR */
687 { "ppp-with-direction", "PPP with Directional Info" },
689 /* WTAP_ENCAP_IEEE_802_11 */
690 { "ieee-802-11", "IEEE 802.11 Wireless LAN" },
692 /* WTAP_ENCAP_IEEE_802_11_PRISM */
693 { "ieee-802-11-prism", "IEEE 802.11 plus Prism II monitor mode radio header" },
695 /* WTAP_ENCAP_IEEE_802_11_WITH_RADIO */
696 { "ieee-802-11-radio", "IEEE 802.11 Wireless LAN with radio information" },
698 /* WTAP_ENCAP_IEEE_802_11_RADIOTAP */
699 { "ieee-802-11-radiotap", "IEEE 802.11 plus radiotap radio header" },
701 /* WTAP_ENCAP_IEEE_802_11_AVS */
702 { "ieee-802-11-avs", "IEEE 802.11 plus AVS radio header" },
705 { "linux-sll", "Linux cooked-mode capture v1" },
707 /* WTAP_ENCAP_FRELAY */
708 { "frelay", "Frame Relay" },
710 /* WTAP_ENCAP_FRELAY_WITH_PHDR */
711 { "frelay-with-direction", "Frame Relay with Directional Info" },
713 /* WTAP_ENCAP_CHDLC */
714 { "chdlc", "Cisco HDLC" },
716 /* WTAP_ENCAP_CISCO_IOS */
717 { "ios", "Cisco IOS internal" },
719 /* WTAP_ENCAP_LOCALTALK */
720 { "ltalk", "Localtalk" },
722 /* WTAP_ENCAP_OLD_PFLOG */
723 { "pflog-old", "OpenBSD PF Firewall logs, pre-3.4" },
725 /* WTAP_ENCAP_HHDLC */
726 { "hhdlc", "HiPath HDLC" },
728 /* WTAP_ENCAP_DOCSIS */
729 { "docsis", "Data Over Cable Service Interface Specification" },
731 /* WTAP_ENCAP_COSINE */
732 { "cosine", "CoSine L2 debug log" },
734 /* WTAP_ENCAP_WFLEET_HDLC */
735 { "whdlc", "Wellfleet HDLC" },
737 /* WTAP_ENCAP_SDLC */
740 /* WTAP_ENCAP_TZSP */
741 { "tzsp", "Tazmen sniffer protocol" },
744 { "enc", "OpenBSD enc(4) encapsulating interface" },
746 /* WTAP_ENCAP_PFLOG */
747 { "pflog", "OpenBSD PF Firewall logs" },
749 /* WTAP_ENCAP_CHDLC_WITH_PHDR */
750 { "chdlc-with-direction", "Cisco HDLC with Directional Info" },
752 /* WTAP_ENCAP_BLUETOOTH_H4 */
753 { "bluetooth-h4", "Bluetooth H4" },
755 /* WTAP_ENCAP_MTP2 */
756 { "mtp2", "SS7 MTP2" },
758 /* WTAP_ENCAP_MTP3 */
759 { "mtp3", "SS7 MTP3" },
761 /* WTAP_ENCAP_IRDA */
764 /* WTAP_ENCAP_USER0 */
765 { "user0", "USER 0" },
767 /* WTAP_ENCAP_USER1 */
768 { "user1", "USER 1" },
770 /* WTAP_ENCAP_USER2 */
771 { "user2", "USER 2" },
773 /* WTAP_ENCAP_USER3 */
774 { "user3", "USER 3" },
776 /* WTAP_ENCAP_USER4 */
777 { "user4", "USER 4" },
779 /* WTAP_ENCAP_USER5 */
780 { "user5", "USER 5" },
782 /* WTAP_ENCAP_USER6 */
783 { "user6", "USER 6" },
785 /* WTAP_ENCAP_USER7 */
786 { "user7", "USER 7" },
788 /* WTAP_ENCAP_USER8 */
789 { "user8", "USER 8" },
791 /* WTAP_ENCAP_USER9 */
792 { "user9", "USER 9" },
794 /* WTAP_ENCAP_USER10 */
795 { "user10", "USER 10" },
797 /* WTAP_ENCAP_USER11 */
798 { "user11", "USER 11" },
800 /* WTAP_ENCAP_USER12 */
801 { "user12", "USER 12" },
803 /* WTAP_ENCAP_USER13 */
804 { "user13", "USER 13" },
806 /* WTAP_ENCAP_USER14 */
807 { "user14", "USER 14" },
809 /* WTAP_ENCAP_USER15 */
810 { "user15", "USER 15" },
812 /* WTAP_ENCAP_SYMANTEC */
813 { "symantec", "Symantec Enterprise Firewall" },
815 /* WTAP_ENCAP_APPLE_IP_OVER_IEEE1394 */
816 { "ap1394", "Apple IP-over-IEEE 1394" },
818 /* WTAP_ENCAP_BACNET_MS_TP */
819 { "bacnet-ms-tp", "BACnet MS/TP" },
821 /* WTAP_ENCAP_NETTL_RAW_ICMP */
822 { "raw-icmp-nettl", "Raw ICMP with nettl headers" },
824 /* WTAP_ENCAP_NETTL_RAW_ICMPV6 */
825 { "raw-icmpv6-nettl", "Raw ICMPv6 with nettl headers" },
827 /* WTAP_ENCAP_GPRS_LLC */
828 { "gprs-llc", "GPRS LLC" },
830 /* WTAP_ENCAP_JUNIPER_ATM1 */
831 { "juniper-atm1", "Juniper ATM1" },
833 /* WTAP_ENCAP_JUNIPER_ATM2 */
834 { "juniper-atm2", "Juniper ATM2" },
836 /* WTAP_ENCAP_REDBACK */
837 { "redback", "Redback SmartEdge" },
839 /* WTAP_ENCAP_NETTL_RAW_IP */
840 { "rawip-nettl", "Raw IP with nettl headers" },
842 /* WTAP_ENCAP_NETTL_ETHERNET */
843 { "ether-nettl", "Ethernet with nettl headers" },
845 /* WTAP_ENCAP_NETTL_TOKEN_RING */
846 { "tr-nettl", "Token Ring with nettl headers" },
848 /* WTAP_ENCAP_NETTL_FDDI */
849 { "fddi-nettl", "FDDI with nettl headers" },
851 /* WTAP_ENCAP_NETTL_UNKNOWN */
852 { "unknown-nettl", "Unknown link-layer type with nettl headers" },
854 /* WTAP_ENCAP_MTP2_WITH_PHDR */
855 { "mtp2-with-phdr", "MTP2 with pseudoheader" },
857 /* WTAP_ENCAP_JUNIPER_PPPOE */
858 { "juniper-pppoe", "Juniper PPPoE" },
860 /* WTAP_ENCAP_GCOM_TIE1 */
861 { "gcom-tie1", "GCOM TIE1" },
863 /* WTAP_ENCAP_GCOM_SERIAL */
864 { "gcom-serial", "GCOM Serial" },
866 /* WTAP_ENCAP_NETTL_X25 */
867 { "x25-nettl", "X.25 with nettl headers" },
870 { "k12", "K12 protocol analyzer" },
872 /* WTAP_ENCAP_JUNIPER_MLPPP */
873 { "juniper-mlppp", "Juniper MLPPP" },
875 /* WTAP_ENCAP_JUNIPER_MLFR */
876 { "juniper-mlfr", "Juniper MLFR" },
878 /* WTAP_ENCAP_JUNIPER_ETHER */
879 { "juniper-ether", "Juniper Ethernet" },
881 /* WTAP_ENCAP_JUNIPER_PPP */
882 { "juniper-ppp", "Juniper PPP" },
884 /* WTAP_ENCAP_JUNIPER_FRELAY */
885 { "juniper-frelay", "Juniper Frame-Relay" },
887 /* WTAP_ENCAP_JUNIPER_CHDLC */
888 { "juniper-chdlc", "Juniper C-HDLC" },
890 /* WTAP_ENCAP_JUNIPER_GGSN */
891 { "juniper-ggsn", "Juniper GGSN" },
893 /* WTAP_ENCAP_LINUX_LAPD */
894 { "linux-lapd", "LAPD with Linux pseudo-header" },
896 /* WTAP_ENCAP_CATAPULT_DCT2000 */
897 { "dct2000", "Catapult DCT2000" },
900 { "ber", "ASN.1 Basic Encoding Rules" },
902 /* WTAP_ENCAP_JUNIPER_VP */
903 { "juniper-vp", "Juniper Voice PIC" },
905 /* WTAP_ENCAP_USB_FREEBSD */
906 { "usb-freebsd", "USB packets with FreeBSD header" },
908 /* WTAP_ENCAP_IEEE802_16_MAC_CPS */
909 { "ieee-802-16-mac-cps", "IEEE 802.16 MAC Common Part Sublayer" },
911 /* WTAP_ENCAP_NETTL_RAW_TELNET */
912 { "raw-telnet-nettl", "Raw telnet with nettl headers" },
914 /* WTAP_ENCAP_USB_LINUX */
915 { "usb-linux", "USB packets with Linux header" },
917 /* WTAP_ENCAP_MPEG */
921 { "ppi", "Per-Packet Information header" },
924 { "erf", "Extensible Record Format" },
926 /* WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR */
927 { "bluetooth-h4-linux", "Bluetooth H4 with linux header" },
929 /* WTAP_ENCAP_SITA */
930 { "sita-wan", "SITA WAN packets" },
932 /* WTAP_ENCAP_SCCP */
933 { "sccp", "SS7 SCCP" },
935 /* WTAP_ENCAP_BLUETOOTH_HCI */
936 { "bluetooth-hci", "Bluetooth without transport layer" },
938 /* WTAP_ENCAP_IPMB_KONTRON */
939 { "ipmb-kontron", "Intelligent Platform Management Bus with Kontron pseudo-header" },
941 /* WTAP_ENCAP_IEEE802_15_4 */
942 { "wpan", "IEEE 802.15.4 Wireless PAN" },
944 /* WTAP_ENCAP_X2E_XORAYA */
945 { "x2e-xoraya", "X2E Xoraya" },
947 /* WTAP_ENCAP_FLEXRAY */
948 { "flexray", "FlexRay" },
951 { "lin", "Local Interconnect Network" },
953 /* WTAP_ENCAP_MOST */
954 { "most", "Media Oriented Systems Transport" },
956 /* WTAP_ENCAP_CAN20B */
957 { "can20b", "Controller Area Network 2.0B" },
959 /* WTAP_ENCAP_LAYER1_EVENT */
960 { "layer1-event", "EyeSDN Layer 1 event" },
962 /* WTAP_ENCAP_X2E_SERIAL */
963 { "x2e-serial", "X2E serial line capture" },
965 /* WTAP_ENCAP_I2C_LINUX */
966 { "i2c-linux", "I2C with Linux-specific pseudo-header" },
968 /* WTAP_ENCAP_IEEE802_15_4_NONASK_PHY */
969 { "wpan-nonask-phy", "IEEE 802.15.4 Wireless PAN non-ASK PHY" },
971 /* WTAP_ENCAP_TNEF */
972 { "tnef", "Transport-Neutral Encapsulation Format" },
974 /* WTAP_ENCAP_USB_LINUX_MMAPPED */
975 { "usb-linux-mmap", "USB packets with Linux header and padding" },
977 /* WTAP_ENCAP_GSM_UM */
978 { "gsm_um", "GSM Um Interface" },
980 /* WTAP_ENCAP_DPNSS */
981 { "dpnss_link", "Digital Private Signalling System No 1 Link Layer" },
983 /* WTAP_ENCAP_PACKETLOGGER */
984 { "packetlogger", "Apple Bluetooth PacketLogger" },
986 /* WTAP_ENCAP_NSTRACE_1_0 */
987 { "nstrace10", "NetScaler Encapsulation 1.0 of Ethernet" },
989 /* WTAP_ENCAP_NSTRACE_2_0 */
990 { "nstrace20", "NetScaler Encapsulation 2.0 of Ethernet" },
992 /* WTAP_ENCAP_FIBRE_CHANNEL_FC2 */
993 { "fc2", "Fibre Channel FC-2" },
995 /* WTAP_ENCAP_FIBRE_CHANNEL_FC2_WITH_FRAME_DELIMS */
996 { "fc2sof", "Fibre Channel FC-2 With Frame Delimiter" },
998 /* WTAP_ENCAP_JPEG_JFIF */
999 { "jfif", "JPEG/JFIF" },
1001 /* WTAP_ENCAP_IPNET */
1002 { "ipnet", "Solaris IPNET" },
1004 /* WTAP_ENCAP_SOCKETCAN */
1005 { "socketcan", "SocketCAN" },
1007 /* WTAP_ENCAP_IEEE_802_11_NETMON */
1008 { "ieee-802-11-netmon", "IEEE 802.11 plus Network Monitor radio header" },
1010 /* WTAP_ENCAP_IEEE802_15_4_NOFCS */
1011 { "wpan-nofcs", "IEEE 802.15.4 Wireless PAN with FCS not present" },
1013 /* WTAP_ENCAP_RAW_IPFIX */
1014 { "ipfix", "RFC 5655/RFC 5101 IPFIX" },
1016 /* WTAP_ENCAP_RAW_IP4 */
1017 { "rawip4", "Raw IPv4" },
1019 /* WTAP_ENCAP_RAW_IP6 */
1020 { "rawip6", "Raw IPv6" },
1022 /* WTAP_ENCAP_LAPD */
1025 /* WTAP_ENCAP_DVBCI */
1026 { "dvbci", "DVB-CI (Common Interface)" },
1028 /* WTAP_ENCAP_MUX27010 */
1029 { "mux27010", "MUX27010" },
1031 /* WTAP_ENCAP_MIME */
1034 /* WTAP_ENCAP_NETANALYZER */
1035 { "netanalyzer", "Hilscher netANALYZER" },
1037 /* WTAP_ENCAP_NETANALYZER_TRANSPARENT */
1038 { "netanalyzer-transparent", "Hilscher netANALYZER-Transparent" },
1040 /* WTAP_ENCAP_IP_OVER_IB */
1041 { "ip-over-ib", "IP over InfiniBand" },
1043 /* WTAP_ENCAP_MPEG_2_TS */
1044 { "mp2ts", "ISO/IEC 13818-1 MPEG2-TS" },
1046 /* WTAP_ENCAP_PPP_ETHER */
1047 { "pppoes", "PPP-over-Ethernet session" },
1049 /* WTAP_ENCAP_NFC_LLCP */
1050 { "nfc-llcp", "NFC LLCP" },
1052 /* WTAP_ENCAP_NFLOG */
1053 { "nflog", "NFLOG" },
1055 /* WTAP_ENCAP_V5_EF */
1056 { "v5-ef", "V5 Envelope Function" },
1058 /* WTAP_ENCAP_BACNET_MS_TP_WITH_PHDR */
1059 { "bacnet-ms-tp-with-direction", "BACnet MS/TP with Directional Info" },
1061 /* WTAP_ENCAP_IXVERIWAVE */
1062 { "ixveriwave", "IxVeriWave header and stats block" },
1064 /* WTAP_ENCAP_SDH */
1067 /* WTAP_ENCAP_DBUS */
1068 { "dbus", "D-Bus" },
1070 /* WTAP_ENCAP_AX25_KISS */
1071 { "ax25-kiss", "AX.25 with KISS header" },
1073 /* WTAP_ENCAP_AX25 */
1074 { "ax25", "Amateur Radio AX.25" },
1076 /* WTAP_ENCAP_SCTP */
1079 /* WTAP_ENCAP_INFINIBAND */
1080 { "infiniband", "InfiniBand" },
1082 /* WTAP_ENCAP_JUNIPER_SVCS */
1083 { "juniper-svcs", "Juniper Services" },
1085 /* WTAP_ENCAP_USBPCAP */
1086 { "usb-usbpcap", "USB packets with USBPcap header" },
1088 /* WTAP_ENCAP_RTAC_SERIAL */
1089 { "rtac-serial", "RTAC serial-line" },
1091 /* WTAP_ENCAP_BLUETOOTH_LE_LL */
1092 { "bluetooth-le-ll", "Bluetooth Low Energy Link Layer" },
1094 /* WTAP_ENCAP_WIRESHARK_UPPER_PDU */
1095 { "wireshark-upper-pdu", "Wireshark Upper PDU export" },
1097 /* WTAP_ENCAP_STANAG_4607 */
1098 { "s4607", "STANAG 4607" },
1100 /* WTAP_ENCAP_STANAG_5066_D_PDU */
1101 { "s5066-dpdu", "STANAG 5066 Data Transfer Sublayer PDUs(D_PDU)" },
1103 /* WTAP_ENCAP_NETLINK */
1104 { "netlink", "Linux Netlink" },
1106 /* WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR */
1107 { "bluetooth-linux-monitor", "Bluetooth Linux Monitor" },
1109 /* WTAP_ENCAP_BLUETOOTH_BREDR_BB */
1110 { "bluetooth-bredr-bb-rf", "Bluetooth BR/EDR Baseband RF" },
1112 /* WTAP_ENCAP_BLUETOOTH_LE_LL_WITH_PHDR */
1113 { "bluetooth-le-ll-rf", "Bluetooth Low Energy Link Layer RF" },
1115 /* WTAP_ENCAP_NSTRACE_3_0 */
1116 { "nstrace30", "NetScaler Encapsulation 3.0 of Ethernet" },
1118 /* WTAP_ENCAP_LOGCAT */
1119 { "logcat", "Android Logcat Binary format" },
1121 /* WTAP_ENCAP_LOGCAT_BRIEF */
1122 { "logcat_brief", "Android Logcat Brief text format" },
1124 /* WTAP_ENCAP_LOGCAT_PROCESS */
1125 { "logcat_process", "Android Logcat Process text format" },
1127 /* WTAP_ENCAP_LOGCAT_TAG */
1128 { "logcat_tag", "Android Logcat Tag text format" },
1130 /* WTAP_ENCAP_LOGCAT_THREAD */
1131 { "logcat_thread", "Android Logcat Thread text format" },
1133 /* WTAP_ENCAP_LOGCAT_TIME */
1134 { "logcat_time", "Android Logcat Time text format" },
1136 /* WTAP_ENCAP_LOGCAT_THREADTIME */
1137 { "logcat_threadtime", "Android Logcat Threadtime text format" },
1139 /* WTAP_ENCAP_LOGCAT_LONG */
1140 { "logcat_long", "Android Logcat Long text format" },
1142 /* WTAP_ENCAP_PKTAP */
1143 { "pktap", "Apple PKTAP" },
1145 /* WTAP_ENCAP_EPON */
1146 { "epon", "Ethernet Passive Optical Network" },
1148 /* WTAP_ENCAP_IPMI_TRACE */
1149 { "ipmi-trace", "IPMI Trace Data Collection" },
1151 /* WTAP_ENCAP_LOOP */
1152 { "loop", "OpenBSD loopback" },
1154 /* WTAP_ENCAP_JSON */
1155 { "json", "JavaScript Object Notation" },
1157 /* WTAP_ENCAP_NSTRACE_3_5 */
1158 { "nstrace35", "NetScaler Encapsulation 3.5 of Ethernet" },
1160 /* WTAP_ENCAP_ISO14443 */
1161 { "iso14443", "ISO 14443 contactless smartcard standards" },
1163 /* WTAP_ENCAP_GFP_T */
1164 { "gfp-t", "ITU-T G.7041/Y.1303 Generic Framing Procedure Transparent mode" },
1166 /* WTAP_ENCAP_GFP_F */
1167 { "gfp-f", "ITU-T G.7041/Y.1303 Generic Framing Procedure Frame-mapped mode" },
1169 /* WTAP_ENCAP_IP_OVER_IB_PCAP */
1170 { "ip-ib", "IP over IB" },
1172 /* WTAP_ENCAP_JUNIPER_VN */
1173 { "juniper-vn", "Juniper VN" },
1175 /* WTAP_ENCAP_USB_DARWIN */
1176 { "usb-darwin", "USB packets with Darwin (macOS, etc.) headers" },
1178 /* WTAP_ENCAP_LORATAP */
1179 { "loratap", "LoRaTap" },
1181 /* WTAP_ENCAP_3MB_ETHERNET */
1182 { "xeth", "Xerox 3MB Ethernet" },
1184 /* WTAP_ENCAP_VSOCK */
1185 { "vsock", "Linux vsock" },
1187 /* WTAP_ENCAP_NORDIC_BLE */
1188 { "nordic_ble", "nRF Sniffer for Bluetooth LE" },
1190 /* WTAP_ENCAP_NETMON_NET_NETEVENT */
1191 { "netmon_event", "Network Monitor Network Event" },
1193 /* WTAP_ENCAP_NETMON_HEADER */
1194 { "netmon_header", "Network Monitor Header" },
1196 /* WTAP_ENCAP_NETMON_NET_FILTER */
1197 { "netmon_filter", "Network Monitor Filter" },
1199 /* WTAP_ENCAP_NETMON_NETWORK_INFO_EX */
1200 { "netmon_network_info", "Network Monitor Network Info" },
1202 /* WTAP_ENCAP_MA_WFP_CAPTURE_V4 */
1203 { "message_analyzer_wfp_capture_v4", "Message Analyzer WFP Capture v4" },
1205 /* WTAP_ENCAP_MA_WFP_CAPTURE_V6 */
1206 { "message_analyzer_wfp_capture_v6", "Message Analyzer WFP Capture v6" },
1208 /* WTAP_ENCAP_MA_WFP_CAPTURE_2V4 */
1209 { "message_analyzer_wfp_capture2_v4", "Message Analyzer WFP Capture2 v4" },
1211 /* WTAP_ENCAP_MA_WFP_CAPTURE_2V6 */
1212 { "message_analyzer_wfp_capture2_v6", "Message Analyzer WFP Capture2 v6" },
1214 /* WTAP_ENCAP_MA_WFP_CAPTURE_AUTH_V4 */
1215 { "message_analyzer_wfp_capture_auth_v4", "Message Analyzer WFP Capture Auth v4" },
1217 /* WTAP_ENCAP_MA_WFP_CAPTURE_AUTH_V6 */
1218 { "message_analyzer_wfp_capture_auth_v6", "Message Analyzer WFP Capture Auth v6" },
1220 /* WTAP_ENCAP_JUNIPER_ST */
1221 { "juniper-st", "Juniper Secure Tunnel Information" },
1223 /* WTAP_ENCAP_ETHERNET_MPACKET */
1224 { "ether-mpacket", "IEEE 802.3br mPackets" },
1226 /* WTAP_ENCAP_DOCSIS31_XRA31 */
1227 { "docsis31_xra31", "DOCSIS with Excentis XRA pseudo-header" },
1229 /* WTAP_ENCAP_DPAUXMON */
1230 { "dpauxmon", "DisplayPort AUX channel with Unigraf pseudo-header" },
1232 /* WTAP_ENCAP_RUBY_MARSHAL */
1233 { "ruby_marshal", "Ruby marshal object" },
1235 /* WTAP_ENCAP_RFC7468 */
1236 { "rfc7468", "RFC 7468 file" },
1238 /* WTAP_ENCAP_SYSTEMD_JOURNAL */
1239 { "sdjournal", "systemd journal" },
1241 /* WTAP_ENCAP_EBHSCR */
1242 { "ebhscr", "Elektrobit High Speed Capture and Replay" },
1244 /* WTAP_ENCAP_VPP */
1245 { "vpp", "Vector Packet Processing graph dispatch trace" },
1247 /* WTAP_ENCAP_IEEE802_15_4_TAP */
1248 { "wpan-tap", "IEEE 802.15.4 Wireless with TAP pseudo-header" },
1250 /* WTAP_ENCAP_LOG_3GPP */
1251 { "log_3GPP", "3GPP Phone Log" },
1253 /* WTAP_ENCAP_USB_2_0 */
1254 { "usb-20", "USB 2.0/1.1/1.0 packets" },
1256 /* WTAP_ENCAP_MP4 */
1257 { "mp4", "MP4 files" },
1259 /* WTAP_ENCAP_SLL2 */
1260 { "linux-sll2", "Linux cooked-mode capture v2" },
1262 /* WTAP_ENCAP_ZWAVE_SERIAL */
1263 { "zwave-serial", "Z-Wave Serial API packets" },
1265 /* WTAP_ENCAP_ETW */
1266 { "etw", "Event Tracing for Windows messages" },
1268 /* WTAP_ENCAP_ERI_ENB_LOG */
1269 { "eri_enb_log", "Ericsson eNode-B raw log" },
1271 /* WTAP_ENCAP_ZBNCP */
1272 { "zbncp", "ZBOSS NCP" },
1274 /* WTAP_ENCAP_USB_2_0_LOW_SPEED */
1275 { "usb-20-low", "Low-Speed USB 2.0/1.1/1.0 packets" },
1277 /* WTAP_ENCAP_USB_2_0_FULL_SPEED */
1278 { "usb-20-full", "Full-Speed USB 2.0/1.1/1.0 packets" },
1280 /* WTAP_ENCAP_USB_2_0_HIGH_SPEED */
1281 { "usb-20-high", "High-Speed USB 2.0 packets" },
1283 /* WTAP_ENCAP_AUTOSAR_DLT */
1284 { "autosardlt", "AUTOSAR DLT" },
1286 /* WTAP_ENCAP_AUERSWALD_LOG */
1287 { "auerlog", "Auerswald Log" },
1289 /* WTAP_ENCAP_ATSC_ALP */
1290 { "alp", "ATSC Link-Layer Protocol (A/330) packets" },
1292 /* WTAP_ENCAP_FIRA_UCI */
1293 { "fira-uci", "FiRa UWB Controller Interface (UCI) protocol." },
1295 /* WTAP_ENCAP_SILABS_DEBUG_CHANNEL */
1296 { "silabs-dch", "Silabs Debug Channel"},
1298 /* WTAP_ENCAP_MDB */
1299 { "mdb", "MDB (Multi-Drop Bus)"},
1301 /* WTAP_ENCAP_EMS */
1302 { "ems", "EMS (EGNOS Message Server) file"},
1304 /* WTAP_ENCAP_DECT_NR */
1305 { "dect_nr", "DECT-2020 New Radio (NR) MAC layer" },
1309 int wtap_num_encap_types
= array_length(encap_table_base
);
1310 static GArray
* encap_table_arr
;
1312 #define encap_table_entry(encap) \
1313 g_array_index(encap_table_arr, struct encap_type_info, encap)
1315 static void wtap_init_encap_types(void) {
1317 if (encap_table_arr
) return;
1319 encap_table_arr
= g_array_new(false,true,sizeof(struct encap_type_info
));
1321 g_array_append_vals(encap_table_arr
,encap_table_base
,wtap_num_encap_types
);
1324 static void wtap_cleanup_encap_types(void) {
1325 if (encap_table_arr
) {
1326 g_array_free(encap_table_arr
, true);
1327 encap_table_arr
= NULL
;
1331 int wtap_get_num_encap_types(void) {
1332 return wtap_num_encap_types
;
1337 wtap_register_encap_type(const char *description
, const char *name
)
1339 struct encap_type_info e
;
1341 e
.name
= g_strdup(name
);
1342 e
.description
= g_strdup(description
);
1344 g_array_append_val(encap_table_arr
,e
);
1346 return wtap_num_encap_types
++;
1349 /* Name to use in, say, a command-line flag specifying the type. */
1351 wtap_encap_name(int encap
)
1353 if (encap
< WTAP_ENCAP_NONE
|| encap
>= WTAP_NUM_ENCAP_TYPES
)
1355 else if (encap
== WTAP_ENCAP_NONE
)
1357 else if (encap
== WTAP_ENCAP_PER_PACKET
)
1358 return "per-packet";
1360 return encap_table_entry(encap
).name
;
1363 /* Description to show to users. */
1365 wtap_encap_description(int encap
)
1367 if (encap
< WTAP_ENCAP_NONE
|| encap
>= WTAP_NUM_ENCAP_TYPES
)
1369 else if (encap
== WTAP_ENCAP_NONE
)
1371 else if (encap
== WTAP_ENCAP_PER_PACKET
)
1372 return "Per packet";
1374 return encap_table_entry(encap
).description
;
1377 /* Translate a name to a capture file type. */
1379 wtap_name_to_encap(const char *name
)
1383 for (encap
= 0; encap
< WTAP_NUM_ENCAP_TYPES
; encap
++) {
1384 if (encap_table_entry(encap
).name
!= NULL
&&
1385 strcmp(name
, encap_table_entry(encap
).name
) == 0)
1388 return -1; /* no such encapsulation type */
1392 * For precision values that correspond to a specific precision.
1394 static const char *precnames
[NUM_WS_TSPREC_VALS
] = {
1396 "100 milliseconds (deciseconds)",
1397 "10 milliseconds (centiseconds)",
1408 wtap_tsprec_string(int tsprec
)
1411 if (tsprec
== WTAP_TSPREC_PER_PACKET
)
1413 else if (tsprec
>= 0 && tsprec
< NUM_WS_TSPREC_VALS
)
1414 s
= precnames
[tsprec
];
1415 else if (tsprec
== WTAP_TSPREC_UNKNOWN
)
1422 static const char *wtap_errlist
[] = {
1423 /* WTAP_ERR_NOT_REGULAR_FILE */
1424 "The file isn't a plain file or pipe",
1426 /* WTAP_ERR_RANDOM_OPEN_PIPE */
1427 "The file is being opened for random access but is a pipe",
1429 /* WTAP_ERR_FILE_UNKNOWN_FORMAT */
1430 "The file isn't a capture file in a known format",
1432 /* WTAP_ERR_UNSUPPORTED */
1433 "File contains record data we don't support",
1435 /* WTAP_ERR_CANT_WRITE_TO_PIPE */
1436 "That file format cannot be written to a pipe",
1438 /* WTAP_ERR_CANT_OPEN */
1441 /* WTAP_ERR_UNWRITABLE_FILE_TYPE */
1442 "Files can't be saved in that format",
1444 /* WTAP_ERR_UNWRITABLE_ENCAP */
1445 "Packets with that network type can't be saved in that format",
1447 /* WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED */
1448 "That file format doesn't support per-packet encapsulations",
1450 /* WTAP_ERR_CANT_WRITE */
1451 "A write failed for some unknown reason",
1453 /* WTAP_ERR_CANT_CLOSE */
1456 /* WTAP_ERR_SHORT_READ */
1457 "Less data was read than was expected",
1459 /* WTAP_ERR_BAD_FILE */
1460 "The file appears to be damaged or corrupt",
1462 /* WTAP_ERR_SHORT_WRITE */
1463 "Less data was written than was requested",
1465 /* WTAP_ERR_UNC_OVERFLOW */
1466 "Uncompression error: data would overflow buffer",
1468 /* WTAP_ERR_RANDOM_OPEN_STDIN */
1469 "The standard input cannot be opened for random access",
1471 /* WTAP_ERR_COMPRESSION_NOT_SUPPORTED */
1472 "That file format doesn't support compression",
1474 /* WTAP_ERR_CANT_SEEK */
1477 /* WTAP_ERR_CANT_SEEK_COMPRESSED */
1480 /* WTAP_ERR_DECOMPRESS */
1481 "Uncompression error",
1483 /* WTAP_ERR_INTERNAL */
1486 /* WTAP_ERR_PACKET_TOO_LARGE */
1487 "The packet being written is too large for that format",
1489 /* WTAP_ERR_CHECK_WSLUA */
1492 /* WTAP_ERR_UNWRITABLE_REC_TYPE */
1493 "That record type cannot be written in that format",
1495 /* WTAP_ERR_UNWRITABLE_REC_DATA */
1496 "That record can't be written in that format",
1498 /* WTAP_ERR_DECOMPRESSION_NOT_SUPPORTED */
1499 "We don't support decompressing that type of compressed file",
1501 /* WTAP_ERR_TIME_STAMP_NOT_SUPPORTED */
1502 "We don't support writing that record's time stamp to that file type",
1504 #define WTAP_ERRLIST_SIZE array_length(wtap_errlist)
1507 wtap_strerror(int err
)
1509 static char errbuf
[128];
1510 unsigned int wtap_errlist_index
;
1513 wtap_errlist_index
= -1 - err
;
1514 if (wtap_errlist_index
>= WTAP_ERRLIST_SIZE
) {
1515 snprintf(errbuf
, 128, "Error %d", err
);
1518 if (wtap_errlist
[wtap_errlist_index
] == NULL
)
1519 return "Unknown reason";
1520 return wtap_errlist
[wtap_errlist_index
];
1522 return g_strerror(err
);
1525 /* Close only the sequential side, freeing up memory it uses.
1527 Note that we do *not* want to call the subtype's close function,
1528 as it would free any per-subtype data, and that data may be
1529 needed by the random-access side.
1531 Instead, if the subtype has a "sequential close" function, we call it,
1532 to free up stuff used only by the sequential side. */
1534 wtap_sequential_close(wtap
*wth
)
1536 if (wth
->subtype_sequential_close
!= NULL
)
1537 (*wth
->subtype_sequential_close
)(wth
);
1539 if (wth
->fh
!= NULL
) {
1540 file_close(wth
->fh
);
1546 g_fast_seek_item_free(void *data
, void *user_data _U_
)
1552 * Close the file descriptors for the sequential and random streams, but
1553 * don't discard any information about those streams. Used on Windows if
1554 * we need to rename a file that we have open or if we need to rename on
1555 * top of a file we have open.
1558 wtap_fdclose(wtap
*wth
)
1560 if (wth
->fh
!= NULL
)
1561 file_fdclose(wth
->fh
);
1562 if (wth
->random_fh
!= NULL
)
1563 file_fdclose(wth
->random_fh
);
1567 wtap_close(wtap
*wth
)
1569 wtap_sequential_close(wth
);
1571 if (wth
->subtype_close
!= NULL
)
1572 (*wth
->subtype_close
)(wth
);
1574 if (wth
->random_fh
!= NULL
)
1575 file_close(wth
->random_fh
);
1579 g_free(wth
->pathname
);
1581 if (wth
->fast_seek
!= NULL
) {
1582 g_ptr_array_foreach(wth
->fast_seek
, g_fast_seek_item_free
, NULL
);
1583 g_ptr_array_free(wth
->fast_seek
, true);
1586 wtap_block_array_free(wth
->shb_hdrs
);
1587 wtap_block_array_free(wth
->nrbs
);
1588 g_array_free(wth
->shb_iface_to_global
, true);
1589 wtap_block_array_free(wth
->interface_data
);
1590 wtap_block_array_free(wth
->dsbs
);
1591 wtap_block_array_free(wth
->meta_events
);
1597 wtap_cleareof(wtap
*wth
) {
1599 file_clearerr(wth
->fh
);
1603 wtapng_process_nrb_ipv4(wtap
*wth
, wtap_block_t nrb
)
1605 const wtapng_nrb_mandatory_t
*nrb_mand
= (wtapng_nrb_mandatory_t
*)wtap_block_get_mandatory_data(nrb
);
1607 if (wth
->add_new_ipv4
) {
1608 for (GList
*elem
= nrb_mand
->ipv4_addr_list
; elem
!= NULL
; elem
= elem
->next
) {
1609 hashipv4_t
*tp
= elem
->data
;
1610 wth
->add_new_ipv4(tp
->addr
, tp
->name
, false);
1616 wtapng_process_nrb_ipv6(wtap
*wth
, wtap_block_t nrb
)
1618 const wtapng_nrb_mandatory_t
*nrb_mand
= (wtapng_nrb_mandatory_t
*)wtap_block_get_mandatory_data(nrb
);
1620 if (wth
->add_new_ipv6
) {
1621 for (GList
*elem
= nrb_mand
->ipv6_addr_list
; elem
!= NULL
; elem
= elem
->next
) {
1622 hashipv6_t
*tp
= elem
->data
;
1623 wth
->add_new_ipv6(tp
->addr
, tp
->name
, false);
1628 void wtap_set_cb_new_ipv4(wtap
*wth
, wtap_new_ipv4_callback_t add_new_ipv4
) {
1632 wth
->add_new_ipv4
= add_new_ipv4
;
1634 /* Are there any existing NRBs? */
1638 * Send all NRBs that were read so far to the new callback. file.c
1639 * relies on this to support redissection (during redissection, the
1640 * previous name resolutions are lost and has to be resupplied).
1642 for (unsigned i
= 0; i
< wth
->nrbs
->len
; i
++) {
1643 wtap_block_t nrb
= g_array_index(wth
->nrbs
, wtap_block_t
, i
);
1644 wtapng_process_nrb_ipv4(wth
, nrb
);
1648 void wtap_set_cb_new_ipv6(wtap
*wth
, wtap_new_ipv6_callback_t add_new_ipv6
) {
1652 wth
->add_new_ipv6
= add_new_ipv6
;
1654 /* Are there any existing NRBs? */
1658 * Send all NRBs that were read so far to the new callback. file.c
1659 * relies on this to support redissection (during redissection, the
1660 * previous name resolutions are lost and has to be resupplied).
1662 for (unsigned i
= 0; i
< wth
->nrbs
->len
; i
++) {
1663 wtap_block_t nrb
= g_array_index(wth
->nrbs
, wtap_block_t
, i
);
1664 wtapng_process_nrb_ipv6(wth
, nrb
);
1669 wtapng_process_nrb(wtap
*wth
, wtap_block_t nrb
)
1671 wtapng_process_nrb_ipv4(wth
, nrb
);
1672 wtapng_process_nrb_ipv6(wth
, nrb
);
1675 void wtap_set_cb_new_secrets(wtap
*wth
, wtap_new_secrets_callback_t add_new_secrets
) {
1676 /* Is a valid wth given that supports DSBs? */
1677 if (!wth
|| !wth
->dsbs
)
1680 wth
->add_new_secrets
= add_new_secrets
;
1682 * Send all DSBs that were read so far to the new callback. file.c
1683 * relies on this to support redissection (during redissection, the
1684 * previous secrets are lost and has to be resupplied).
1686 for (unsigned i
= 0; i
< wth
->dsbs
->len
; i
++) {
1687 wtap_block_t dsb
= g_array_index(wth
->dsbs
, wtap_block_t
, i
);
1688 wtapng_process_dsb(wth
, dsb
);
1693 wtapng_process_dsb(wtap
*wth
, wtap_block_t dsb
)
1695 const wtapng_dsb_mandatory_t
*dsb_mand
= (wtapng_dsb_mandatory_t
*)wtap_block_get_mandatory_data(dsb
);
1697 if (wth
->add_new_secrets
)
1698 wth
->add_new_secrets(dsb_mand
->secrets_type
, dsb_mand
->secrets_data
, dsb_mand
->secrets_len
);
1701 /* Perform per-packet initialization */
1703 wtap_init_rec(wtap
*wth
, wtap_rec
*rec
)
1706 * Set the packet encapsulation to the file's encapsulation
1707 * value; if that's not WTAP_ENCAP_PER_PACKET, it's the
1708 * right answer (and means that the read routine for this
1709 * capture file type doesn't have to set it), and if it
1710 * *is* WTAP_ENCAP_PER_PACKET, the caller needs to set it
1713 * Do the same for the packet time stamp resolution.
1715 rec
->rec_header
.packet_header
.pkt_encap
= wth
->file_encap
;
1716 rec
->tsprec
= wth
->file_tsprec
;
1718 rec
->block_was_modified
= false;
1721 * Assume the file has only one section; the module for the
1722 * file type needs to indicate the section number if there's
1723 * more than one section.
1725 rec
->section_number
= 0;
1729 wtap_read(wtap
*wth
, wtap_rec
*rec
, Buffer
*buf
, int *err
,
1730 char **err_info
, int64_t *offset
)
1733 * Initialize the record to default values.
1735 wtap_init_rec(wth
, rec
);
1736 ws_buffer_clean(buf
);
1740 if (!wth
->subtype_read(wth
, rec
, buf
, err
, err_info
, offset
)) {
1742 * If we didn't get an error indication, we read
1743 * the last packet. See if there's any deferred
1744 * error, as might, for example, occur if we're
1745 * reading a compressed file, and we got an error
1746 * reading compressed data from the file, but
1747 * got enough compressed data to decompress the
1748 * last packet of the file.
1751 *err
= file_error(wth
->fh
, err_info
);
1752 if (rec
->block
!= NULL
) {
1754 * Unreference any block created for this record.
1756 wtap_block_unref(rec
->block
);
1759 return false; /* failure */
1763 * Is this a packet record?
1765 if (rec
->rec_type
== REC_TYPE_PACKET
) {
1767 * Make sure that it's not WTAP_ENCAP_PER_PACKET, as that
1768 * probably means the file has that encapsulation type
1769 * but the read routine didn't set this packet's
1770 * encapsulation type.
1772 ws_assert(rec
->rec_header
.packet_header
.pkt_encap
!= WTAP_ENCAP_PER_PACKET
);
1773 ws_assert(rec
->rec_header
.packet_header
.pkt_encap
!= WTAP_ENCAP_NONE
);
1776 return true; /* success */
1780 * Read a given number of bytes from a file into a buffer or, if
1781 * buf is NULL, just discard them.
1783 * If we succeed, return true.
1785 * If we get an EOF, return false with *err set to 0, reporting this
1788 * If we get fewer bytes than the specified number, return false with
1789 * *err set to WTAP_ERR_SHORT_READ, reporting this as a short read
1792 * If we get a read error, return false with *err and *err_info set
1796 wtap_read_bytes_or_eof(FILE_T fh
, void *buf
, unsigned int count
, int *err
,
1801 bytes_read
= file_read(buf
, count
, fh
);
1802 if (bytes_read
< 0 || (unsigned)bytes_read
!= count
) {
1803 *err
= file_error(fh
, err_info
);
1804 if (*err
== 0 && bytes_read
> 0)
1805 *err
= WTAP_ERR_SHORT_READ
;
1812 * Read a given number of bytes from a file into a buffer or, if
1813 * buf is NULL, just discard them.
1815 * If we succeed, return true.
1817 * If we get fewer bytes than the specified number, including getting
1818 * an EOF, return false with *err set to WTAP_ERR_SHORT_READ, reporting
1819 * this as a short read error.
1821 * If we get a read error, return false with *err and *err_info set
1825 wtap_read_bytes(FILE_T fh
, void *buf
, unsigned int count
, int *err
,
1830 bytes_read
= file_read(buf
, count
, fh
);
1831 if (bytes_read
< 0 || (unsigned)bytes_read
!= count
) {
1832 *err
= file_error(fh
, err_info
);
1834 *err
= WTAP_ERR_SHORT_READ
;
1841 * Read packet data into a Buffer, growing the buffer as necessary.
1843 * This returns an error on a short read, even if the short read hit
1844 * the EOF immediately. (The assumption is that each packet has a
1845 * header followed by raw packet data, and that we've already read the
1846 * header, so if we get an EOF trying to read the packet data, the file
1847 * has been cut short, even if the read didn't read any data at all.)
1850 wtap_read_packet_bytes(FILE_T fh
, Buffer
*buf
, unsigned length
, int *err
,
1854 ws_buffer_assure_space(buf
, length
);
1855 rv
= wtap_read_bytes(fh
, ws_buffer_end_ptr(buf
), length
, err
,
1858 ws_buffer_increase_length(buf
, length
);
1864 * Return an approximation of the amount of data we've read sequentially
1865 * from the file so far. (int64_t, in case that's 64 bits.)
1868 wtap_read_so_far(wtap
*wth
)
1870 return file_tell_raw(wth
->fh
);
1873 /* Perform global/initial initialization */
1875 wtap_rec_init(wtap_rec
*rec
)
1877 memset(rec
, 0, sizeof *rec
);
1878 ws_buffer_init(&rec
->options_buf
, 0);
1879 /* In the future, see if we can create rec->block here once
1880 * and have it be reused like the rest of rec.
1881 * Currently it's recreated for each packet.
1885 /* re-initialize record */
1887 wtap_rec_reset(wtap_rec
*rec
)
1889 wtap_block_unref(rec
->block
);
1891 rec
->block_was_modified
= false;
1894 /* clean up record metadata */
1896 wtap_rec_cleanup(wtap_rec
*rec
)
1898 wtap_rec_reset(rec
);
1899 ws_buffer_free(&rec
->options_buf
);
1903 wtap_rec_generate_idb(const wtap_rec
*rec
)
1906 ws_assert(rec
->rec_type
== REC_TYPE_PACKET
);
1907 if (rec
->presence_flags
& WTAP_HAS_TS
) {
1908 tsprec
= rec
->tsprec
;
1910 tsprec
= WTAP_TSPREC_USEC
;
1913 return wtap_generate_idb(rec
->rec_header
.packet_header
.pkt_encap
, tsprec
, 0);
1917 wtap_seek_read(wtap
*wth
, int64_t seek_off
, wtap_rec
*rec
, Buffer
*buf
,
1918 int *err
, char **err_info
)
1921 * Initialize the record to default values.
1923 wtap_init_rec(wth
, rec
);
1924 ws_buffer_clean(buf
);
1928 if (!wth
->subtype_seek_read(wth
, seek_off
, rec
, buf
, err
, err_info
)) {
1929 if (rec
->block
!= NULL
) {
1931 * Unreference any block created for this record.
1933 wtap_block_unref(rec
->block
);
1940 * Is this a packet record?
1942 if (rec
->rec_type
== REC_TYPE_PACKET
) {
1944 * Make sure that it's not WTAP_ENCAP_PER_PACKET, as that
1945 * probably means the file has that encapsulation type
1946 * but the read routine didn't set this packet's
1947 * encapsulation type.
1949 ws_assert(rec
->rec_header
.packet_header
.pkt_encap
!= WTAP_ENCAP_PER_PACKET
);
1950 ws_assert(rec
->rec_header
.packet_header
.pkt_encap
!= WTAP_ENCAP_NONE
);
1957 wtap_full_file_read_file(wtap
*wth
, FILE_T fh
, wtap_rec
*rec
, Buffer
*buf
, int *err
, char **err_info
)
1960 int packet_size
= 0;
1961 const int block_size
= 1024 * 1024;
1963 if ((file_size
= wtap_file_size(wth
, err
)) == -1)
1966 if (file_size
> INT_MAX
) {
1968 * Avoid allocating space for an immensely-large file.
1970 *err
= WTAP_ERR_BAD_FILE
;
1971 *err_info
= ws_strdup_printf("%s: File has %" PRId64
"-byte packet, bigger than maximum of %u",
1972 wtap_encap_name(wth
->file_encap
), file_size
, INT_MAX
);
1977 * Compressed files might expand to a larger size than the actual file
1978 * size. Try to read the full size and then read in smaller increments
1979 * to avoid frequent memory reallocations.
1981 int buffer_size
= block_size
* (1 + (int)file_size
/ block_size
);
1983 if (buffer_size
<= 0) {
1984 *err
= WTAP_ERR_BAD_FILE
;
1985 *err_info
= ws_strdup_printf("%s: Uncompressed file is bigger than maximum of %u",
1986 wtap_encap_name(wth
->file_encap
), INT_MAX
);
1989 ws_buffer_assure_space(buf
, buffer_size
);
1990 int nread
= file_read(ws_buffer_start_ptr(buf
) + packet_size
, buffer_size
- packet_size
, fh
);
1992 *err
= file_error(fh
, err_info
);
1994 *err
= WTAP_ERR_BAD_FILE
;
1997 packet_size
+= nread
;
1998 if (packet_size
!= buffer_size
) {
2002 buffer_size
+= block_size
;
2005 rec
->rec_type
= REC_TYPE_PACKET
;
2006 rec
->presence_flags
= 0; /* yes, we have no bananas^Wtime stamp */
2009 rec
->rec_header
.packet_header
.caplen
= packet_size
;
2010 rec
->rec_header
.packet_header
.len
= packet_size
;
2016 wtap_full_file_read(wtap
*wth
, wtap_rec
*rec
, Buffer
*buf
,
2017 int *err
, char **err_info
, int64_t *data_offset
)
2019 int64_t offset
= file_tell(wth
->fh
);
2021 /* There is only one packet with the full file contents. */
2027 *data_offset
= offset
;
2028 return wtap_full_file_read_file(wth
, wth
->fh
, rec
, buf
, err
, err_info
);
2032 wtap_full_file_seek_read(wtap
*wth
, int64_t seek_off
, wtap_rec
*rec
, Buffer
*buf
, int *err
, char **err_info
)
2034 /* There is only one packet with the full file contents. */
2040 if (file_seek(wth
->random_fh
, seek_off
, SEEK_SET
, err
) == -1)
2043 return wtap_full_file_read_file(wth
, wth
->random_fh
, rec
, buf
, err
, err_info
);
2047 wtap_buffer_append_epdu_tag(Buffer
*buf
, uint16_t epdu_tag
, const uint8_t *data
, uint16_t data_len
)
2049 uint8_t pad_len
= 0;
2050 unsigned space_needed
= 4; /* 2 for tag field, 2 for length field */
2053 if (epdu_tag
!= 0 && data
!= NULL
&& data_len
!= 0) {
2054 pad_len
+= PADDING4(data_len
);
2055 space_needed
+= data_len
+ pad_len
;
2061 ws_buffer_assure_space(buf
, space_needed
);
2062 buf_data
= ws_buffer_end_ptr(buf
);
2063 memset(buf_data
, 0, space_needed
);
2064 phton16(buf_data
+ 0, epdu_tag
);
2065 /* It seems as though the convention for exported_pdu is to specify
2066 * the fully-padded length of the tag value, not just its useful length.
2067 * e.g. the string value 'a' would be given a length of 4.
2069 phton16(buf_data
+ 2, data_len
+ pad_len
);
2071 /* Still only copy as many bytes as we actually have */
2072 memcpy(buf_data
+ 4, data
, data_len
);
2074 ws_buffer_increase_length(buf
, space_needed
);
2078 wtap_buffer_append_epdu_uint(Buffer
*buf
, uint16_t epdu_tag
, uint32_t val
)
2080 const unsigned space_needed
= 8; /* 2 for tag field, 2 for length field, 4 for value */
2083 ws_assert(epdu_tag
!= 0);
2084 ws_buffer_assure_space(buf
, space_needed
);
2085 buf_data
= ws_buffer_end_ptr(buf
);
2086 memset(buf_data
, 0, space_needed
);
2087 phton16(buf_data
+ 0, epdu_tag
);
2088 phton16(buf_data
+ 2, 4);
2089 phton32(buf_data
+ 4, val
);
2090 ws_buffer_increase_length(buf
, space_needed
);
2094 wtap_buffer_append_epdu_string(Buffer
*buf
, uint16_t epdu_tag
, const char *val
)
2098 string_len
= strlen(val
);
2100 * Cut off string length at UINT16_MAX.
2102 * XXX - make sure we don't leave an incomplete UTF-8
2103 * sequence at the end.
2105 if (string_len
> UINT16_MAX
)
2106 string_len
= UINT16_MAX
;
2107 wtap_buffer_append_epdu_tag(buf
, epdu_tag
, val
, (uint16_t) string_len
);
2111 wtap_buffer_append_epdu_end(Buffer
*buf
)
2113 const unsigned space_needed
= 4; /* 2 for tag (=0000), 2 for length field (=0) */
2116 ws_buffer_assure_space(buf
, space_needed
);
2117 buf_data
= ws_buffer_end_ptr(buf
);
2118 memset(buf_data
, 0, space_needed
);
2119 ws_buffer_increase_length(buf
, space_needed
);
2121 return (int)ws_buffer_length(buf
);
2125 * Initialize the library.
2128 wtap_init(bool load_wiretap_plugins
)
2130 init_open_routines();
2131 wtap_opttypes_initialize();
2132 wtap_init_encap_types();
2133 wtap_init_file_type_subtypes();
2134 if (load_wiretap_plugins
) {
2136 libwiretap_plugins
= plugins_init(WS_PLUGIN_WIRETAP
);
2138 g_slist_foreach(wtap_plugins
, call_plugin_register_wtap_module
, NULL
);
2143 * Cleanup the library
2148 wtap_cleanup_encap_types();
2149 wtap_opttypes_cleanup();
2150 ws_buffer_cleanup();
2151 cleanup_open_routines();
2152 g_slist_free(wtap_plugins
);
2153 wtap_plugins
= NULL
;
2155 plugins_cleanup(libwiretap_plugins
);
2156 libwiretap_plugins
= NULL
;
2161 * Editor modelines - https://www.wireshark.org/tools/modelines.html
2166 * indent-tabs-mode: t
2169 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
2170 * :indentSize=8:tabSize=8:noTabs=false: