dumpcap: Handle multiple output files and swapped endian input pipe

When writing to a new output file and writing the saved SHB in
passthrough mode, check if the saved SHB (and thus the current
section of the single input) is byte swapped, and remember to
byte swap the number of bytes to write if so.

Fixup d4194c108693e5cd18fe97f24719fdeb577102ef

Ping #19965
This commit is contained in:
John Thacker 2025-04-30 12:59:00 -04:00 committed by AndersBroman
parent daea8c2fb6
commit d52ee96bec

View File

@ -3447,6 +3447,12 @@ capture_loop_init_pcapng_output(capture_options *capture_opts, loop_data *ld,
memcpy(&bh, ld->saved_shb, sizeof(pcapng_block_header_t));
ws_assert(global_ld.pcapng_passthrough);
capture_src *pcap_src = g_array_index(ld->pcaps, capture_src *, 0);
if (pcap_src->cap_pipe_info.pcapng.byte_swapped) {
bh.block_total_length = GUINT32_SWAP_LE_BE(bh.block_total_length);
}
successful = pcapng_write_block(ld->pdh, ld->saved_shb, bh.block_total_length, &ld->bytes_written, err);
ws_debug("%s: wrote saved passthrough SHB %d", G_STRFUNC, successful);