forked from osmocom/wireshark
wiretap: move the "fake an IDB for pcap files" code to libpcap.c.
That can just be done at the end of libpcap_open(), rather than in wtap_open_offline() immediately after the open routine - which, in this case, would be libpcap_open() - returns. That's cleaner, as it puts capture-file-type-dependent code in the capture-file-type-specific code. Note, though, that it's a bit weird for LINKTYPE_ERF files (and it was equally weird before this change), and that other capture file types should be doing this as well. Change-Id: Ida94779a2e1021c81314f82655ec1d0f2f14e960 Reviewed-on: https://code.wireshark.org/review/37022 Petri-Dish: Guy Harris <gharris@sonic.net> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <gharris@sonic.net>
This commit is contained in:
parent
7d95c27de2
commit
be63a17e54
|
@ -1139,29 +1139,6 @@ fail:
|
|||
return NULL;
|
||||
|
||||
success:
|
||||
if ((wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP) ||
|
||||
(wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC)) {
|
||||
|
||||
wtap_block_t descr = wtap_block_create(WTAP_BLOCK_IF_DESCR);
|
||||
wtapng_if_descr_mandatory_t* descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(descr);
|
||||
|
||||
descr_mand->wtap_encap = wth->file_encap;
|
||||
if (wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC) {
|
||||
descr_mand->time_units_per_second = 1000000000; /* nanosecond resolution */
|
||||
wtap_block_add_uint8_option(descr, OPT_IDB_TSRESOL, 9);
|
||||
descr_mand->tsprecision = WTAP_TSPREC_NSEC;
|
||||
} else {
|
||||
descr_mand->time_units_per_second = 1000000; /* default microsecond resolution */
|
||||
/* No need to add an option, this is the default */
|
||||
descr_mand->tsprecision = WTAP_TSPREC_USEC;
|
||||
}
|
||||
descr_mand->snap_len = wth->snapshot_length;
|
||||
|
||||
descr_mand->num_stat_entries = 0; /* Number of ISB:s */
|
||||
descr_mand->interface_statistics = NULL;
|
||||
wtap_add_idb(wth, descr);
|
||||
|
||||
}
|
||||
return wth;
|
||||
}
|
||||
|
||||
|
|
|
@ -521,6 +521,47 @@ done:
|
|||
/*Reset the ERF interface lookup table*/
|
||||
libpcap->encap_priv = erf_priv_create();
|
||||
}
|
||||
|
||||
/*
|
||||
* Add an IDB; we don't know how many interfaces were involved,
|
||||
* so we just say one interface, about which we only know
|
||||
* the link-layer type, snapshot length, and time stamp
|
||||
* resolution.
|
||||
*
|
||||
* This allows nanosecond pcap files to be correctly
|
||||
* converted to pcapng files.
|
||||
*
|
||||
* XXX - this will be a bit weird if you're trying to convert
|
||||
* a LINKTYPE_ERF pcap file to a pcapng file; it'll have a
|
||||
* placeholder interface added here, *plus* interfaces
|
||||
* added from the ERF records. Ideally, at some point in
|
||||
* the future, libpcap will have a more pcapng-friendly API
|
||||
* for capturing, and the DAG capture code will use it, so that
|
||||
* if you're capturing on more than one interface, they'll all
|
||||
* get regular IDBs, with no need for the placeholder.
|
||||
*
|
||||
* XXX - yes, adding at least one IDB should be done for *all*
|
||||
* file types.
|
||||
*/
|
||||
wtap_block_t descr = wtap_block_create(WTAP_BLOCK_IF_DESCR);
|
||||
wtapng_if_descr_mandatory_t* descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(descr);
|
||||
|
||||
descr_mand->wtap_encap = wth->file_encap;
|
||||
if (wth->file_type_subtype == WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC) {
|
||||
descr_mand->time_units_per_second = 1000000000; /* nanosecond resolution */
|
||||
wtap_block_add_uint8_option(descr, OPT_IDB_TSRESOL, 9);
|
||||
descr_mand->tsprecision = WTAP_TSPREC_NSEC;
|
||||
} else {
|
||||
descr_mand->time_units_per_second = 1000000; /* default microsecond resolution */
|
||||
/* No need to add an option, this is the default */
|
||||
descr_mand->tsprecision = WTAP_TSPREC_USEC;
|
||||
}
|
||||
descr_mand->snap_len = wth->snapshot_length;
|
||||
|
||||
descr_mand->num_stat_entries = 0; /* Number of ISB:s */
|
||||
descr_mand->interface_statistics = NULL;
|
||||
wtap_add_idb(wth, descr);
|
||||
|
||||
return WTAP_OPEN_MINE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue