diff options
author | Guy Harris <gharris@sonic.net> | 2021-07-14 22:16:30 -0700 |
---|---|---|
committer | Wireshark GitLab Utility <gerald+gitlab-utility@wireshark.org> | 2021-07-15 05:43:36 +0000 |
commit | 0a9ef601d201f87ff3effb8aca62c61184fd6146 (patch) | |
tree | ce64e2ddc50cdf76bbc4dc785e069a50a820c7b4 /writecap/pcapio.c | |
parent | 94ac641efabc9830bc91db1c793bf0ba42f1e46c (diff) |
Clean up handling of --capture-comment.
Don't store the comments in a capture_options structure, because that's
available only if we're being built with capture support, and
--capture-comment can be used in TShark when reading a capture file and
writing another capture file, with no live capture taking place.
This means we don't handle that option in capture_opts_add_opt(); handle
it in the programs that support it.
Support writing multiple comments in dumpcap when capturing.
These changes also fix builds without pcap, and makes --capture-comment
work in Wireshark when a capture is started from the command line with
-k.
Update the help messages to indicate that --capture-comment adds a
capture comment, it doesn't change any comment (much less "the" comment,
as there isn't necessarily a single comment).
Update the man pages:
- not to presume that only pcapng files support file comments (even if
that's true now, it might not be true in the future);
- to note that multiple instances of --capture-comment are supported,
and that multiple comments will be written, whether capturing or reading
one file and writing another;
- clarify that Wireshark doesn't *discard* SHB comments other than the
first one, even though it only displays the first one;
Diffstat (limited to 'writecap/pcapio.c')
-rw-r--r-- | writecap/pcapio.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/writecap/pcapio.c b/writecap/pcapio.c index 14e4d7f31b..124531de9c 100644 --- a/writecap/pcapio.c +++ b/writecap/pcapio.c @@ -307,7 +307,7 @@ pcapng_write_block(FILE* pfile, gboolean pcapng_write_section_header_block(FILE* pfile, - const char *comment, + GPtrArray *comments, const char *hw, const char *os, const char *appname, @@ -324,13 +324,17 @@ pcapng_write_section_header_block(FILE* pfile, block_total_length = sizeof(struct shb) + sizeof(guint32); options_length = 0; - options_length += pcapng_count_string_option(comment); + if (comments != NULL) { + for (guint i = 0; i < comments->len; i++) { + options_length += pcapng_count_string_option((char *)g_ptr_array_index(comments, i)); + } + } options_length += pcapng_count_string_option(hw); options_length += pcapng_count_string_option(os); options_length += pcapng_count_string_option(appname); /* If we have options add size of end-of-options */ if (options_length != 0) { - options_length += (guint32)sizeof(struct option); + options_length += (guint32)sizeof(struct option); } block_total_length += options_length; @@ -345,9 +349,14 @@ pcapng_write_section_header_block(FILE* pfile, if (!write_to_file(pfile, (const guint8*)&shb, sizeof(struct shb), bytes_written, err)) return FALSE; - if (!pcapng_write_string_option(pfile, OPT_COMMENT, comment, - bytes_written, err)) - return FALSE; + if (comments != NULL) { + for (guint i = 0; i < comments->len; i++) { + if (!pcapng_write_string_option(pfile, OPT_COMMENT, + (char *)g_ptr_array_index(comments, i), + bytes_written, err)) + return FALSE; + } + } if (!pcapng_write_string_option(pfile, SHB_HARDWARE, hw, bytes_written, err)) return FALSE; |