diff options
author | Martin Kaiser <wireshark@kaiser.cx> | 2013-08-01 20:57:47 +0000 |
---|---|---|
committer | Martin Kaiser <wireshark@kaiser.cx> | 2013-08-01 20:57:47 +0000 |
commit | 6c5e16185dfd4c9e955618f56ac8827ad7eda9e7 (patch) | |
tree | 99c0af1fac940b388377f29e82490e6f3fc6e262 | |
parent | 91382394d674190aa83995dd16e194378795f080 (diff) | |
download | wireshark-6c5e16185dfd4c9e955618f56ac8827ad7eda9e7.tar.gz wireshark-6c5e16185dfd4c9e955618f56ac8827ad7eda9e7.tar.bz2 wireshark-6c5e16185dfd4c9e955618f56ac8827ad7eda9e7.zip |
add --capture-comment to tshark
make sure that getopt() does not permute tshark's argv[] array
svn path=/trunk/; revision=51089
-rw-r--r-- | capture_opts.h | 10 | ||||
-rw-r--r-- | tshark.c | 12 |
2 files changed, 19 insertions, 3 deletions
diff --git a/capture_opts.h b/capture_opts.h index a0fdbda5c7..cd98b56f7b 100644 --- a/capture_opts.h +++ b/capture_opts.h @@ -42,7 +42,15 @@ extern "C" { #endif /* __cplusplus */ -#define LONGOPT_NUM_CAP_COMMENT 0 +/* Attention: + for tshark, we're using a leading - in the optstring to prevent getopt() + from permuting the argv[] entries, in this case, unknown argv[] entries + will be returned as parameters to a dummy-option 1 + in short: we must not use 1 here */ + +/* this does not clash with tshark's -2 option which returns '2' */ +#define LONGOPT_NUM_CAP_COMMENT 2 + #ifdef HAVE_PCAP_REMOTE /* Type of capture source */ @@ -871,6 +871,10 @@ main(int argc, char *argv[]) GString *runtime_info_str; char *init_progfile_dir_error; int opt; + struct option long_options[] = { + {"capture-comment", required_argument, NULL, LONGOPT_NUM_CAP_COMMENT }, + {0, 0, 0, 0 } + }; gboolean arg_error = FALSE; #ifdef _WIN32 @@ -936,7 +940,10 @@ main(int argc, char *argv[]) #define OPTSTRING_I "" #endif -#define OPTSTRING "2a:" OPTSTRING_A "b:" OPTSTRING_B "c:C:d:De:E:f:F:gG:hH:i:" OPTSTRING_I "K:lLnN:o:O:pPqQr:R:s:S:t:T:u:vVw:W:xX:y:Y:z:" +/* the leading - ensures that getopt() does not permute the argv[] entries + we have to make sure that the first getopt() preserves the content of argv[] + for the subsequent getopt_long() call */ +#define OPTSTRING "-2a:" OPTSTRING_A "b:" OPTSTRING_B "c:C:d:De:E:f:F:gG:hH:i:" OPTSTRING_I "K:lLnN:o:O:pPqQr:R:s:S:t:T:u:vVw:W:xX:y:Y:z:" static const char optstring[] = OPTSTRING; @@ -1204,7 +1211,7 @@ main(int argc, char *argv[]) output_fields = output_fields_new(); /* Now get our args */ - while ((opt = getopt_long(argc, argv, optstring, NULL, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { switch (opt) { case '2': /* Perform two pass analysis */ perform_two_pass_analysis = TRUE; @@ -1225,6 +1232,7 @@ main(int argc, char *argv[]) case 's': /* Set the snapshot (capture) length */ case 'w': /* Write to capture file x */ case 'y': /* Set the pcap data link type */ + case LONGOPT_NUM_CAP_COMMENT: /* add a capture comment */ #if defined(_WIN32) || defined(HAVE_PCAP_CREATE) case 'B': /* Buffer size */ #endif /* _WIN32 or HAVE_PCAP_CREATE */ |