wiretap: have dummy IDBs set OPT_IDB_TSRESOL if needed

In wtap_dump_init_dumper(), when constructing a dummy IDB for files
that don't have one, if the tsprecision value is anything other than
the default, then the OPT_IDB_TSRESOL option also needs to be set.
Without it, for a pcapng the timestamps will be written according to the
tsprecision and time_units_per_second values, but when it is read,
the values will be interpreted incorrectly.

It would probably be better if the consistency of these values were enforced.
This commit is contained in:
John Thacker 2021-12-15 01:22:34 -05:00 committed by Wireshark GitLab Utility
parent bf15343241
commit 67a4e70382
1 changed files with 6 additions and 0 deletions

View File

@ -2289,26 +2289,32 @@ wtap_dump_init_dumper(int file_type_subtype, wtap_compression_type compression_t
case WTAP_TSPREC_SEC:
descr_mand->time_units_per_second = 1;
wtap_block_add_uint8_option(descr, OPT_IDB_TSRESOL, 0);
break;
case WTAP_TSPREC_DSEC:
descr_mand->time_units_per_second = 10;
wtap_block_add_uint8_option(descr, OPT_IDB_TSRESOL, 1);
break;
case WTAP_TSPREC_CSEC:
descr_mand->time_units_per_second = 100;
wtap_block_add_uint8_option(descr, OPT_IDB_TSRESOL, 2);
break;
case WTAP_TSPREC_MSEC:
descr_mand->time_units_per_second = 1000;
wtap_block_add_uint8_option(descr, OPT_IDB_TSRESOL, 3);
break;
case WTAP_TSPREC_USEC:
descr_mand->time_units_per_second = 1000000;
/* This is the default, so we save a few bytes by not adding the option. */
break;
case WTAP_TSPREC_NSEC:
descr_mand->time_units_per_second = 1000000000;
wtap_block_add_uint8_option(descr, OPT_IDB_TSRESOL, 9);
break;
default: