wireshark/epan/dissectors/packet-pcapng_block.c
Guy Harris 166159f15d wiretap: eliminate the pcap/nspcap/pcapng WTAP_FILE_TYPE_SUBTYPE_ values.
Register the pcap and pcapng file types/subtypes rather than hardwiring
them into the table.

Call the registration routines for them directly, rather than through a
generated table; they're always supposed to be there, as some code in
Wireshark either writes only one of those formats or defaults to writing
one of those formats.  Don't run their source code through the
registration-routine-finder script.

Have the file type/subtype codes for them be directly exported to the
libwiretap core, and provide routines to return each of them, to be used
by the aforementioned code.

When reporting errors with cfile_write_failure_message(), use
wtap_dump_file_type_subtype() to get the file type/subtype value for the
wtap_dumper to which we're writing, rather than hardcoding it.

Have the "export PDU" code capable of supporting arbitrary file
types/subtypes, although we currently only use pcapng.

Get rid of declarations of now-static can_write_encap and
dump_open routines in various headers.
2021-02-23 21:56:20 +00:00

76 lines
2 KiB
C

/* packet-pcapng.c
* Dissector to handle pcapng file-type-specific blocks.
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "config.h"
#include <epan/packet.h>
#include <wiretap/wtap.h>
void proto_register_pcapng_block(void);
void proto_reg_handoff_pcapng_block(void);
static int proto_pcapng_block = -1;
static dissector_table_t pcapng_block_type_dissector_table;
static int
dissect_pcapng_block(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
/*
* Call the dissector for the block type of this block, if there
* is one.
*/
if (!dissector_try_uint(pcapng_block_type_dissector_table,
pinfo->rec->rec_header.ft_specific_header.record_type, tvb, pinfo, tree)) {
/*
* There isn't one; just do a minimal display.
*/
col_set_str(pinfo->cinfo, COL_PROTOCOL, "PCAPNG");
col_add_fstr(pinfo->cinfo, COL_INFO, "Pcapng block, type %u",
pinfo->rec->rec_header.ft_specific_header.record_type);
proto_tree_add_item(tree, proto_pcapng_block, tvb, 0, -1, ENC_NA);
}
return tvb_captured_length(tvb);
}
void proto_register_pcapng_block(void)
{
proto_pcapng_block = proto_register_protocol("Pcapng block",
"PCAPNG", "pcapng");
pcapng_block_type_dissector_table = register_dissector_table("pcapng.block_type",
"pcapng block type", proto_pcapng_block, FT_UINT32, BASE_DEC);
}
void
proto_reg_handoff_pcapng_block(void)
{
dissector_handle_t pcapng_block_handle;
pcapng_block_handle = create_dissector_handle(dissect_pcapng_block,
proto_pcapng_block);
dissector_add_uint("wtap_fts_rec", wtap_pcapng_file_type_subtype(),
pcapng_block_handle);
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: t
* End:
*
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
* :indentSize=8:tabSize=8:noTabs=false:
*/