X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/ab3d424294b1daebe35c1b1b946da8f5dea1a916..e1e0824e40f4bfaaec7636f1e452911a6b8f7eca:/tcpdump.c diff --git a/tcpdump.c b/tcpdump.c index b08e00f1..2e9a5055 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -57,6 +57,10 @@ extern int SIZE_BUF; #include #endif +#ifdef HAVE_LIBCRYPTO +#include +#endif + #ifdef HAVE_GETOPT_LONG #include #else @@ -122,7 +126,8 @@ int32_t thiszone; /* seconds offset from gmt to local time */ /* Forwards */ static RETSIGTYPE cleanup(int); static RETSIGTYPE child_cleanup(int); -static void usage(void) __attribute__((noreturn)); +static void print_version(void); +static void print_usage(void); static void show_dlts_and_exit(const char *device, pcap_t *pd) __attribute__((noreturn)); static void print_packet(u_char *, const struct pcap_pkthdr *, const u_char *); @@ -638,12 +643,14 @@ show_devices_and_exit (void) * doesn't make sense; it should be --verbosity={N} or something such * as that. * - * We do not currently have long options with no corresponding short - * options; for those, we should define values outside the range of - * ASCII graphic characters, make that the last component of the - * entry for the long option, and have a case for that option in the - * switch statement. + * For long options with no corresponding short options, we define values + * outside the range of ASCII graphic characters, make that the last + * component of the entry for the long option, and have a case for that + * option in the switch statement. */ +#define OPTION_NUMBER 128 +#define OPTION_VERSION 129 + static struct option longopts[] = { #if defined(HAVE_PCAP_CREATE) || defined(WIN32) { "buffer-size", required_argument, NULL, 'B' }, @@ -675,7 +682,8 @@ static struct option longopts[] = { { "debug-filter-parser", no_argument, NULL, 'Y' }, #endif { "relinquish-privileges", required_argument, NULL, 'Z' }, - { "number", no_argument, NULL, 'z' + 1}, + { "number", no_argument, NULL, OPTION_NUMBER }, + { "version", no_argument, NULL, OPTION_VERSION }, { NULL, 0, NULL, 0 } }; @@ -979,7 +987,8 @@ main(int argc, char **argv) break; case 'h': - usage(); + print_usage(); + exit(0); break; case 'H': @@ -1257,12 +1266,18 @@ main(int argc, char **argv) username = strdup(optarg); break; - case 'z' + 1: + case OPTION_NUMBER: gndo->ndo_packet_number = 1; break; + case OPTION_VERSION: + print_version(); + exit(0); + break; + default: - usage(); + print_usage(); + exit(1); /* NOTREACHED */ } @@ -2243,7 +2258,7 @@ static void verbose_stats_dump(int sig _U_) #endif static void -usage(void) +print_version(void) { extern char version[]; #ifndef HAVE_PCAP_LIB_VERSION @@ -2270,6 +2285,20 @@ usage(void) (void)fprintf(stderr, "libpcap version %s\n", pcap_version); #endif /* WIN32 */ #endif /* HAVE_PCAP_LIB_VERSION */ + +#if defined(HAVE_LIBCRYPTO) && defined(SSLEAY_VERSION) + (void)fprintf (stderr, "%s\n", SSLeay_version(SSLEAY_VERSION)); +#endif + +#if defined(HAVE_SMI_H) + (void)fprintf (stderr, "SMI-library: %s\n", smi_version_string); +#endif +} + +static void +print_usage(void) +{ + print_version(); (void)fprintf(stderr, "Usage: %s [-aAbd" D_FLAG "efhH" I_FLAG J_FLAG "KlLnNOpqRStu" U_FLAG "vxX]" B_FLAG_USAGE " [ -c count ]\n", program_name); (void)fprintf(stderr, @@ -2281,12 +2310,11 @@ usage(void) "\t\t[ -Q in|out|inout ]\n"); #endif (void)fprintf(stderr, -"\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ -V file ] [ -w file ]\n"); +"\t\t[ -r file ] [ -s snaplen ] [ -T type ] [ --version ] [ -V file ]\n"); (void)fprintf(stderr, -"\t\t[ -W filecount ] [ -y datalinktype ] [ -z command ]\n"); +"\t\t[ -w file ] [ -W filecount ] [ -y datalinktype ] [ -z command ]\n"); (void)fprintf(stderr, "\t\t[ -Z user ] [ expression ]\n"); - exit(1); }