Skip to content

Commit

Permalink
wiretap: clean up WTAP_BLOCK_ names.
Browse files Browse the repository at this point in the history
Remove NG from the names - it adds nothing.

Don't use the abbreviations for pcapng block names, spell out what the
block does (e.g. "WTAP_BLOCK_DECRYPTION_SECRETS" rather than
"WTAP_BLOCK_DSB"), to make it more obvious what the block does.

Spell out some other abbreviations.

Add WTAP_BLOCK_PACKET for future use for packet blocks; there's no need
to distinguish between the Enhanced Packet Block, the Simple Packet
Block, and the deprecated Packet Block here.
  • Loading branch information
guyharris committed Feb 9, 2021
1 parent d67b856 commit 0968464
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 43 deletions.
2 changes: 1 addition & 1 deletion editcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ main(int argc, char *argv[])
/* Warn for badly formatted files, but proceed anyway. */
validate_secrets_file(secrets_filename, secrets_type_id, data);

block = wtap_block_create(WTAP_BLOCK_DSB);
block = wtap_block_create(WTAP_BLOCK_DECRYPTION_SECRETS);
dsb = (wtapng_dsb_mandatory_t *)wtap_block_get_mandatory_data(block);
dsb->secrets_type = secrets_type_id;
dsb->secrets_len = (guint)data_len;
Expand Down
6 changes: 3 additions & 3 deletions extcap/etl.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ wtap_dumper* etw_dump_open(const char* pcapng_filename, int* err, gchar** err_in
wtap_dumper* pdh = NULL;

shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
shb_hdr = wtap_block_create(WTAP_BLOCK_NG_SECTION);
shb_hdr = wtap_block_create(WTAP_BLOCK_SECTION);
g_array_append_val(shb_hdrs, shb_hdr);

/* In the future, may create multiple WTAP_BLOCK_IF_DESCR separately for IP packet */
/* In the future, may create multiple WTAP_BLOCK_IF_DESCRIPTION separately for IP packet */
idb_info = g_new(wtapng_iface_descriptions_t, 1);
idb_datas = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
idb_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
idb_data = wtap_block_create(WTAP_BLOCK_IF_DESCRIPTION);
descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(idb_data);
descr_mand->tsprecision = WTAP_TSPREC_USEC;
descr_mand->wtap_encap = WTAP_ENCAP_ETW;
Expand Down
4 changes: 2 additions & 2 deletions ui/tap_export_pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, const char *comment, int *err,
os_info_str = g_string_new("");
get_os_version_info(os_info_str);

shb_hdr = wtap_block_create(WTAP_BLOCK_NG_SECTION);
shb_hdr = wtap_block_create(WTAP_BLOCK_SECTION);

/* options */
wtap_block_add_string_option(shb_hdr, OPT_COMMENT, comment, strlen(comment));
Expand All @@ -126,7 +126,7 @@ exp_pdu_open(exp_pdu_t *exp_pdu_tap_data, int fd, const char *comment, int *err,
exp_pdu_tap_data->idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));

/* create the fake interface data */
int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
int_data = wtap_block_create(WTAP_BLOCK_IF_DESCRIPTION);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);
int_data_mand->wtap_encap = WTAP_ENCAP_WIRESHARK_UPPER_PDU;
int_data_mand->time_units_per_second = 1000000000; /* default nanosecond resolution */
Expand Down
2 changes: 1 addition & 1 deletion wiretap/erf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,7 @@ static int erf_populate_interface(erf_t *erf_priv, wtap *wth, union wtap_pseudo_
return if_map->interfaces[if_num].if_index;
}

int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
int_data = wtap_block_create(WTAP_BLOCK_IF_DESCRIPTION);
int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data);

int_data_mand->wtap_encap = WTAP_ENCAP_ERF;
Expand Down
4 changes: 2 additions & 2 deletions wiretap/file_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ wtap_open_offline(const char *filename, unsigned int type, int *err, char **err_
wth->priv = NULL;
wth->wslua_data = NULL;
wth->shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
shb = wtap_block_create(WTAP_BLOCK_NG_SECTION);
shb = wtap_block_create(WTAP_BLOCK_SECTION);
if (shb)
g_array_append_val(wth->shb_hdrs, shb);

Expand Down Expand Up @@ -2349,7 +2349,7 @@ wtap_dump_init_dumper(int file_type_subtype, wtap_compression_type compression_t
int snaplen;

// XXX IDBs should be optional.
descr = wtap_block_create(WTAP_BLOCK_IF_DESCR);
descr = wtap_block_create(WTAP_BLOCK_IF_DESCRIPTION);
descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(descr);
descr_mand->wtap_encap = params->encap;
descr_mand->tsprecision = params->tsprec;
Expand Down
4 changes: 2 additions & 2 deletions wiretap/iptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ iptrace_read_rec_1_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf,
/*
* Now make a new IDB and add it.
*/
int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
int_data = wtap_block_create(WTAP_BLOCK_IF_DESCRIPTION);
int_data_mand = (wtapng_if_descr_mandatory_t *)wtap_block_get_mandatory_data(int_data);

int_data_mand->wtap_encap = rec->rec_header.packet_header.pkt_encap;
Expand Down Expand Up @@ -600,7 +600,7 @@ iptrace_read_rec_2_0(wtap *wth, FILE_T fh, wtap_rec *rec, Buffer *buf,
/*
* Now make a new IDB and add it.
*/
int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
int_data = wtap_block_create(WTAP_BLOCK_IF_DESCRIPTION);
int_data_mand = (wtapng_if_descr_mandatory_t *)wtap_block_get_mandatory_data(int_data);

int_data_mand->wtap_encap = rec->rec_header.packet_header.pkt_encap;
Expand Down
2 changes: 1 addition & 1 deletion wiretap/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ static guint
add_idb_to_merged_file(wtapng_iface_descriptions_t *merged_idb_list,
const wtap_block_t input_file_idb)
{
wtap_block_t idb = wtap_block_create(WTAP_BLOCK_IF_DESCR);
wtap_block_t idb = wtap_block_create(WTAP_BLOCK_IF_DESCRIPTION);
wtapng_if_descr_mandatory_t* idb_mand;

g_assert(merged_idb_list != NULL);
Expand Down
16 changes: 8 additions & 8 deletions wiretap/pcapng.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ pcapng_read_section_header_block(FILE_T fh, pcapng_block_header_t *bh,
section_info->version_major = version_major;
section_info->version_minor = version_minor;

wblock->block = wtap_block_create(WTAP_BLOCK_NG_SECTION);
wblock->block = wtap_block_create(WTAP_BLOCK_SECTION);
section_data = (wtapng_mandatory_section_t*)wtap_block_get_mandatory_data(wblock->block);
/* 64bit section_length (currently unused) */
if (section_info->byte_swapped) {
Expand Down Expand Up @@ -891,7 +891,7 @@ pcapng_read_if_descr_block(wtap *wth, FILE_T fh, pcapng_block_header_t *bh,
}

/* mandatory values */
wblock->block = wtap_block_create(WTAP_BLOCK_IF_DESCR);
wblock->block = wtap_block_create(WTAP_BLOCK_IF_DESCRIPTION);
if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(wblock->block);
if (section_info->byte_swapped) {
link_type = GUINT16_SWAP_LE_BE(idb.linktype);
Expand Down Expand Up @@ -1195,7 +1195,7 @@ pcapng_read_decryption_secrets_block(FILE_T fh, pcapng_block_header_t *bh,
}

/* mandatory values */
wblock->block = wtap_block_create(WTAP_BLOCK_DSB);
wblock->block = wtap_block_create(WTAP_BLOCK_DECRYPTION_SECRETS);
dsb_mand = (wtapng_dsb_mandatory_t *)wtap_block_get_mandatory_data(wblock->block);
if (section_info->byte_swapped) {
dsb_mand->secrets_type = GUINT32_SWAP_LE_BE(dsb.secrets_type);
Expand Down Expand Up @@ -1905,7 +1905,7 @@ pcapng_read_name_resolution_block(FILE_T fh, pcapng_block_header_t *bh,

/* Ensure we have a name resolution block */
if (wblock->block == NULL) {
wblock->block = wtap_block_create(WTAP_BLOCK_NG_NRB);
wblock->block = wtap_block_create(WTAP_BLOCK_NAME_RESOLUTION);
}

/*
Expand Down Expand Up @@ -2181,7 +2181,7 @@ pcapng_read_interface_statistics_block(FILE_T fh, pcapng_block_header_t *bh,
return FALSE;
}

wblock->block = wtap_block_create(WTAP_BLOCK_IF_STATS);
wblock->block = wtap_block_create(WTAP_BLOCK_IF_STATISTICS);
if_stats_mand = (wtapng_if_stats_mandatory_t*)wtap_block_get_mandatory_data(wblock->block);
if (section_info->byte_swapped) {
if_stats_mand->interface_id = GUINT32_SWAP_LE_BE(isb.interface_id);
Expand Down Expand Up @@ -2712,7 +2712,7 @@ static void
pcapng_process_idb(wtap *wth, section_info_t *section_info,
wtapng_block_t *wblock)
{
wtap_block_t int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR);
wtap_block_t int_data = wtap_block_create(WTAP_BLOCK_IF_DESCRIPTION);
interface_info_t iface_info;
wtapng_if_descr_mandatory_t *if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data),
*wblock_if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(wblock->block);
Expand Down Expand Up @@ -3037,7 +3037,7 @@ pcapng_read(wtap *wth, wtap_rec *rec, Buffer *buf, int *err,
wtapng_if_descr_mand->interface_statistics = g_array_new(FALSE, FALSE, sizeof(wtap_block_t));
}

if_stats = wtap_block_create(WTAP_BLOCK_IF_STATS);
if_stats = wtap_block_create(WTAP_BLOCK_IF_STATISTICS);
if_stats_mand = (wtapng_if_stats_mandatory_t*)wtap_block_get_mandatory_data(if_stats);
if_stats_mand->interface_id = if_stats_mand_block->interface_id;
if_stats_mand->ts_high = if_stats_mand_block->ts_high;
Expand Down Expand Up @@ -4768,7 +4768,7 @@ static gboolean pcapng_add_idb(wtap_dumper *wdh, wtap_block_t idb,
/*
* Add a copy of this IDB to our array of IDBs.
*/
idb_copy = wtap_block_create(WTAP_BLOCK_IF_DESCR);
idb_copy = wtap_block_create(WTAP_BLOCK_IF_DESCRIPTION);
wtap_block_copy(idb_copy, idb);
g_array_append_val(wdh->interface_data, idb_copy);

Expand Down
2 changes: 1 addition & 1 deletion wiretap/wtap.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ wtap_add_generated_idb(wtap *wth)
g_assert(wth->file_tsprec != WTAP_TSPREC_UNKNOWN &&
wth->file_tsprec != WTAP_TSPREC_PER_PACKET);

idb = wtap_block_create(WTAP_BLOCK_IF_DESCR);
idb = wtap_block_create(WTAP_BLOCK_IF_DESCRIPTION);

if_descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(idb);
if_descr_mand->wtap_encap = wth->file_encap;
Expand Down
32 changes: 16 additions & 16 deletions wiretap/wtap_opttypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ static void dsb_copy_mand(wtap_block_t dest_block, wtap_block_t src_block)
void wtap_opttypes_initialize(void)
{
static wtap_blocktype_t shb_block = {
WTAP_BLOCK_NG_SECTION, /* block_type */
WTAP_BLOCK_SECTION, /* block_type */
"SHB", /* name */
"Section Header Block", /* description */
shb_create, /* create */
Expand Down Expand Up @@ -1075,7 +1075,7 @@ void wtap_opttypes_initialize(void)
};

static wtap_blocktype_t idb_block = {
WTAP_BLOCK_IF_DESCR, /* block_type */
WTAP_BLOCK_IF_DESCRIPTION, /* block_type */
"IDB", /* name */
"Interface Description Block", /* description */
idb_create, /* create */
Expand Down Expand Up @@ -1133,7 +1133,7 @@ void wtap_opttypes_initialize(void)
};

static wtap_blocktype_t dsb_block = {
WTAP_BLOCK_DSB,
WTAP_BLOCK_DECRYPTION_SECRETS,
"DSB",
"Decryption Secrets Block",
dsb_create,
Expand All @@ -1143,13 +1143,13 @@ void wtap_opttypes_initialize(void)
};

static wtap_blocktype_t nrb_block = {
WTAP_BLOCK_NG_NRB, /* block_type */
"NRB", /* name */
"Name Resolution Block", /* description */
nrb_create, /* create */
NULL, /* free_mand */
NULL, /* copy_mand */
NULL /* options */
WTAP_BLOCK_NAME_RESOLUTION, /* block_type */
"NRB", /* name */
"Name Resolution Block", /* description */
nrb_create, /* create */
NULL, /* free_mand */
NULL, /* copy_mand */
NULL /* options */
};
static const wtap_opttype_t ns_dnsname = {
"dnsname",
Expand All @@ -1171,7 +1171,7 @@ void wtap_opttypes_initialize(void)
};

static wtap_blocktype_t isb_block = {
WTAP_BLOCK_IF_STATS, /* block_type */
WTAP_BLOCK_IF_STATISTICS, /* block_type */
"ISB", /* name */
"Interface Statistics Block", /* description */
isb_create, /* create */
Expand Down Expand Up @@ -1230,15 +1230,15 @@ void wtap_opttypes_initialize(void)
/*
* Register the SHB and the options that can appear in it.
*/
wtap_opttype_block_register(WTAP_BLOCK_NG_SECTION, &shb_block);
wtap_opttype_block_register(WTAP_BLOCK_SECTION, &shb_block);
wtap_opttype_option_register(&shb_block, OPT_SHB_HARDWARE, &shb_hardware);
wtap_opttype_option_register(&shb_block, OPT_SHB_OS, &shb_os);
wtap_opttype_option_register(&shb_block, OPT_SHB_USERAPPL, &shb_userappl);

/*
* Register the IDB and the options that can appear in it.
*/
wtap_opttype_block_register(WTAP_BLOCK_IF_DESCR, &idb_block);
wtap_opttype_block_register(WTAP_BLOCK_IF_DESCRIPTION, &idb_block);
wtap_opttype_option_register(&idb_block, OPT_IDB_NAME, &if_name);
wtap_opttype_option_register(&idb_block, OPT_IDB_DESCR, &if_description);
wtap_opttype_option_register(&idb_block, OPT_IDB_SPEED, &if_speed);
Expand All @@ -1251,15 +1251,15 @@ void wtap_opttypes_initialize(void)
/*
* Register the NRB and the options that can appear in it.
*/
wtap_opttype_block_register(WTAP_BLOCK_NG_NRB, &nrb_block);
wtap_opttype_block_register(WTAP_BLOCK_NAME_RESOLUTION, &nrb_block);
wtap_opttype_option_register(&nrb_block, OPT_NS_DNSNAME, &ns_dnsname);
wtap_opttype_option_register(&nrb_block, OPT_NS_DNSIP4ADDR, &ns_dnsIP4addr);
wtap_opttype_option_register(&nrb_block, OPT_NS_DNSIP6ADDR, &ns_dnsIP6addr);

/*
* Register the ISB and the options that can appear in it.
*/
wtap_opttype_block_register(WTAP_BLOCK_IF_STATS, &isb_block);
wtap_opttype_block_register(WTAP_BLOCK_IF_STATISTICS, &isb_block);
wtap_opttype_option_register(&isb_block, OPT_ISB_STARTTIME, &isb_starttime);
wtap_opttype_option_register(&isb_block, OPT_ISB_ENDTIME, &isb_endtime);
wtap_opttype_option_register(&isb_block, OPT_ISB_IFRECV, &isb_ifrecv);
Expand All @@ -1271,7 +1271,7 @@ void wtap_opttypes_initialize(void)
/*
* Register the DSB, currently no options are defined.
*/
wtap_opttype_block_register(WTAP_BLOCK_DSB, &dsb_block);
wtap_opttype_block_register(WTAP_BLOCK_DECRYPTION_SECRETS, &dsb_block);
}

void wtap_opttypes_cleanup(void)
Expand Down
18 changes: 12 additions & 6 deletions wiretap/wtap_opttypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,20 @@ typedef struct wtap_block *wtap_block_t;

/*
* Currently supported blocks; these are not the pcapng block type values
* for them, they're identifiers used internally.
* for them, they're identifiers used internally, and more than one
* pcapng block type may use a given block type.
*
* WTAP_BLOCK_PACKET (which corresponds to the Enhanced Packet Block,
* the Simple Packet Block, and the deprecated Packet Block) is not
* currently used; it's reserved for future use.
*/
typedef enum {
WTAP_BLOCK_NG_SECTION = 0,
WTAP_BLOCK_IF_DESCR,
WTAP_BLOCK_NG_NRB,
WTAP_BLOCK_IF_STATS,
WTAP_BLOCK_DSB,
WTAP_BLOCK_SECTION = 0,
WTAP_BLOCK_IF_DESCRIPTION,
WTAP_BLOCK_NAME_RESOLUTION,
WTAP_BLOCK_IF_STATISTICS,
WTAP_BLOCK_DECRYPTION_SECRETS,
WTAP_BLOCK_PACKET,
WTAP_BLOCK_END_OF_LIST
} wtap_block_type_t;

Expand Down

0 comments on commit 0968464

Please sign in to comment.