aboutsummaryrefslogtreecommitdiffstats
path: root/editcap.c
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2006-01-10 21:37:36 +0000
committerUlf Lamping <ulf.lamping@web.de>2006-01-10 21:37:36 +0000
commit4d9839c0d65153939b668f5acde364649d5145da (patch)
treeafe253cb28ab1bf7af717c3a13bd1e593fe85f22 /editcap.c
parent0c66b4dff92fcf076e455a0bf1e9368ffdd497f0 (diff)
redesign of the usage output (displayed with -h or an unknown option):
option explanation is more detailed now, I've added the option parameters to the description added version information to the usage output instead of using the usage page to display the available file and encapsulation types (which makes the usage page almost unreadable), use empty options -F or -T to print the available types. I've used optopt for this, it seems to be portable that way ... svn path=/trunk/; revision=16991
Diffstat (limited to 'editcap.c')
-rw-r--r--editcap.c102
1 files changed, 66 insertions, 36 deletions
diff --git a/editcap.c b/editcap.c
index f7fd60c87b..d459853484 100644
--- a/editcap.c
+++ b/editcap.c
@@ -36,6 +36,8 @@
#include <process.h> /* getpid */
#endif
+#include "svnversion.h"
+
/*
* Some globals so we can pass things to various routines
*/
@@ -207,45 +209,69 @@ set_time_adjustment(char *optarg)
static void usage(void)
{
+ fprintf(stderr, "Editcap %s"
+#ifdef SVNVERSION
+ " (" SVNVERSION ")"
+#endif
+ "\n", VERSION);
+ fprintf(stderr, "Edit and/or translate the format of capture files.\n");
+ fprintf(stderr, "See http://www.ethereal.com for more information.\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Usage: editcap [options] ... <infile> <outfile> [ <packet#>[-<packet#>] ... ]\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "A single packet or a range of packets can be selected.\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Packets:\n");
+ fprintf(stderr, " -C <choplen> chop each packet at the end by <choplen> bytes\n");
+ fprintf(stderr, " -E <error probability> set the probability (between 0.0 and 1.0 incl.)\n");
+ fprintf(stderr, " that a particular packet byte will be randomly changed\n");
+ fprintf(stderr, " -r keep the selected packets, default is to delete them\n");
+ fprintf(stderr, " -s <snaplen> truncate packets to max. <snaplen> bytes of data\n");
+ fprintf(stderr, " -t <time adjustment> adjust the timestamp of selected packets,\n");
+ fprintf(stderr, " <time adjustment> is in relative seconds (e.g. -0.5)\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Output File(s):\n");
+ fprintf(stderr, " -c <packets per file> split the packet output to different files,\n");
+ fprintf(stderr, " with a maximum of <packets per file> each\n");
+ fprintf(stderr, " -F <capture type> set the output file type, default is libpcap\n");
+ fprintf(stderr, " an empty \"-F\" option will list the file types\n");
+ fprintf(stderr, " -T <encap type> set the output file encapsulation type,\n");
+ fprintf(stderr, " default is the same as the input file\n");
+ fprintf(stderr, " an empty \"-T\" option will list the encapsulation types\n");
+ fprintf(stderr, "\n");
+ fprintf(stderr, "Miscellaneous:\n");
+ fprintf(stderr, " -h display this help and exit\n");
+ fprintf(stderr, " -v verbose output\n");
+ fprintf(stderr, "\n");
+}
+
+
+static void bad_option_help(int bad_opt) {
int i;
const char *string;
- fprintf(stderr, "Usage: editcap [-c <packets per file>] [-C <choplen>] [-E <probability>]\n");
- fprintf(stderr, " [-F <capture type>] [-h] [-r] [-s <snaplen>]\n");
- fprintf(stderr, " [-t <time adjustment>] [-T <encap type>] [-v]\n");
- fprintf(stderr, " <infile> <outfile> [ <packet#>[-<packet#>] ... ]\n");
- fprintf(stderr, " where\n");
- fprintf(stderr, " \t-c <packets per file> split the output to different files\n");
- fprintf(stderr, " \t-C <choplen> specifies that each packet should be chopped by\n");
- fprintf(stderr, " \t <choplen> bytes of data at the packet end\n");
- fprintf(stderr, " \t-E <probability> specifies the probability (between 0.0 and 1.0 incl.)\n");
- fprintf(stderr, " \t that a particular byte will have an error\n");
- fprintf(stderr, " \t-F <capture type> specifies the capture file type to write:\n");
- for (i = 0; i < WTAP_NUM_FILE_TYPES; i++) {
- if (wtap_dump_can_open(i))
- fprintf(stderr, " \t %s - %s\n",
- wtap_file_type_short_string(i), wtap_file_type_string(i));
- }
- fprintf(stderr, " \t default is libpcap\n");
- fprintf(stderr, " \t-h produces this help\n");
- fprintf(stderr, " \t-r specifies that the packets specified should be kept,\n");
- fprintf(stderr, " the default is to delete them\n");
- fprintf(stderr, " \t-s <snaplen> specifies that packets should be truncated to\n");
- fprintf(stderr, " \t <snaplen> bytes of data\n");
- fprintf(stderr, " \t-t <time adjustment> specifies the time adjustment in seconds\n");
- fprintf(stderr, " \t to be applied to selected packets (e.g. -0.5)\n");
- fprintf(stderr, " \t-T <encap type> specifies the encapsulation type to use:\n");
- for (i = 0; i < WTAP_NUM_ENCAP_TYPES; i++) {
- string = wtap_encap_short_string(i);
- if (string != NULL)
- fprintf(stderr, " \t %s - %s\n",
- string, wtap_encap_string(i));
+
+ switch(bad_opt) {
+ case'F':
+ fprintf(stderr, "The available capture file types for \"F\":\n");
+ for (i = 0; i < WTAP_NUM_FILE_TYPES; i++) {
+ if (wtap_dump_can_open(i))
+ fprintf(stderr, " %s - %s\n",
+ wtap_file_type_short_string(i), wtap_file_type_string(i));
+ }
+ break;
+ case'T':
+ fprintf(stderr, "The available encapsulation types for \"T\":\n");
+ for (i = 0; i < WTAP_NUM_ENCAP_TYPES; i++) {
+ string = wtap_encap_short_string(i);
+ if (string != NULL)
+ fprintf(stderr, " %s - %s\n",
+ string, wtap_encap_string(i));
+ }
+ break;
+ default:
+ usage();
}
- fprintf(stderr, " \t default is the same as the input file\n");
- fprintf(stderr, " \t-v specifies verbose operation (slows down output),\n");
- fprintf(stderr, " \t default is silent\n");
- fprintf(stderr, "\n");
- fprintf(stderr, " A single packet or a range of packets can be specified\n");
}
int main(int argc, char *argv[])
@@ -319,8 +345,12 @@ int main(int argc, char *argv[])
}
break;
- case 'h':
case '?': /* Bad options if GNU getopt */
+ bad_option_help(optopt);
+ exit(1);
+ break;
+
+ case 'h':
usage();
exit(1);
break;