diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 5a49a38fd2..3875ffbd2b 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -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; } diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c index 5e3dbf07cc..ac4c2f4dd6 100644 --- a/wiretap/libpcap.c +++ b/wiretap/libpcap.c @@ -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; }