#include <smi.h>
#endif
+#ifdef HAVE_LIBCRYPTO
+#include <openssl/crypto.h>
+#endif
+
#ifdef HAVE_GETOPT_LONG
#include <getopt.h>
#else
#include <sys/resource.h>
#include <pwd.h>
#include <grp.h>
-#include <errno.h>
#endif /* WIN32 */
/* capabilities convinience library */
/* 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 *);
}
#endif /* HAVE_PCAP_FINDALLDEVS */
+/*
+ * Short options.
+ *
+ * Note that there we use all letters for short options except for g, k,
+ * o, and P, and those are used by other versions of tcpdump, and we should
+ * only use them for the same purposes that the other versions of tcpdump
+ * use them:
+ *
+ * OS X tcpdump uses -g to force non--v output for IP to be on one
+ * line, making it more "g"repable;
+ *
+ * OS X tcpdump uses -k tospecify that packet comments in pcap-ng files
+ * should be printed;
+ *
+ * OpenBSD tcpdump uses -o to indicate that OS fingerprinting should be done
+ * for hosts sending TCP SYN packets;
+ *
+ * OS X tcpdump uses -P to indicate that -w should write pcap-ng rather
+ * than pcap files.
+ */
+
/*
* Set up flags that might or might not be supported depending on the
* version of libpcap we're using.
#define Q_FLAG
#endif
+/*
+ * Long options.
+ *
+ * We do not currently have long options corresponding to all short
+ * options; we should probably pick appropriate option names for them.
+ *
+ * However, the short options where the number of times the option is
+ * specified matters, such as -v and -d and -t, should probably not
+ * just map to a long option, as saying
+ *
+ * tcpdump --verbose --verbose
+ *
+ * doesn't make sense; it should be --verbosity={N} or something such
+ * as that.
+ *
+ * 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[] = {
- { NULL, no_argument, NULL, 'a' },
- { NULL, no_argument, NULL, 'A' },
- { NULL, no_argument, NULL, 'b' },
#if defined(HAVE_PCAP_CREATE) || defined(WIN32)
- { NULL, required_argument, NULL, 'B' },
-#endif
- { NULL, required_argument, NULL, 'c' },
- { NULL, required_argument, NULL, 'C' },
- { NULL, no_argument, NULL, 'd' },
- { NULL, no_argument, NULL, 'D' },
- { NULL, no_argument, NULL, 'e' },
- { NULL, required_argument, NULL, 'E' },
- { NULL, no_argument, NULL, 'f' },
- { NULL, required_argument, NULL, 'F' },
- /*
- * NOTE: OS X tcpdump uses -g; we shouldn't use it except for
- * the same purpose (forcing non--v output for IP to be on one
- * line, making it more "g"repable).
- */
- { NULL, required_argument, NULL, 'G' },
- { NULL, no_argument, NULL, 'h' },
- { NULL, no_argument, NULL, 'H' },
- { NULL, required_argument, NULL, 'i' },
+ { "buffer-size", required_argument, NULL, 'B' },
+#endif
+ { "list-interfaces", no_argument, NULL, 'D' },
+ { "help", no_argument, NULL, 'h' },
+ { "interface", required_argument, NULL, 'i' },
#ifdef HAVE_PCAP_CREATE
- { NULL, no_argument, NULL, 'I' },
+ { "monitor-mode", no_argument, NULL, 'I' },
#endif
#ifdef HAVE_PCAP_SET_TSTAMP_TYPE
- { NULL, required_argument, NULL, 'j' },
- { NULL, no_argument, NULL, 'J' },
+ { "time-stamp-type", required_argument, NULL, 'j' },
+ { "list-time-stamp-types", no_argument, NULL, 'J' },
#endif
- /*
- * NOTE: OS X tcpdump uses -k; we shouldn't use it except for
- * the same purpose (printing packet comments in pcap-ng files).
- */
- { NULL, no_argument, NULL, 'K' },
- { NULL, no_argument, NULL, 'l' },
- { NULL, no_argument, NULL, 'L' },
- { NULL, required_argument, NULL, 'm' },
- { NULL, required_argument, NULL, 'M' },
- { NULL, no_argument, NULL, 'n' },
- { NULL, no_argument, NULL, 'N' },
- /*
- * NOTE: OpenBSD tcpdump uses -o; we shouldn't use it except for
- * the same purpose (trying to do OS fingerprinting for
- * hosts sending TCP SYN packets).
- */
- { NULL, no_argument, NULL, 'O' },
- { NULL, no_argument, NULL, 'p' },
- /*
- * NOTE: OS X tcpdump uses -P; we shouldn't use it except for
- * the same purpose (writing pcap-ng rather than pcap files).
- */
- { NULL, no_argument, NULL, 'q' },
+ { "dont-verify-checksums", no_argument, NULL, 'K' },
+ { "list-data-link-types", no_argument, NULL, 'L' },
+ { "no-optimize", no_argument, NULL, 'O' },
+ { "no-promiscuous-mode", no_argument, NULL, 'p' },
#ifdef HAVE_PCAP_SETDIRECTION
- { NULL, required_argument, NULL, 'Q' },
-#endif
- { NULL, required_argument, NULL, 'r' },
- { NULL, no_argument, NULL, 'R' },
- { NULL, required_argument, NULL, 's' },
- { NULL, no_argument, NULL, 'S' },
- { NULL, no_argument, NULL, 't' },
- { NULL, required_argument, NULL, 'T' },
- { NULL, no_argument, NULL, 'u' },
+ { "direction", required_argument, NULL, 'Q' },
+#endif
+ { "snapshot-length", required_argument, NULL, 's' },
+ { "absolute-tcp-sequence-numbers", no_argument, NULL, 'S' },
#ifdef HAVE_PCAP_DUMP_FLUSH
- { NULL, no_argument, NULL, 'U' },
-#endif
- { NULL, no_argument, NULL, 'v' },
- { NULL, required_argument, NULL, 'V' },
- { NULL, required_argument, NULL, 'w' },
- { NULL, required_argument, NULL, 'W' },
- { NULL, no_argument, NULL, 'x' },
- { NULL, no_argument, NULL, 'X' },
- { NULL, required_argument, NULL, 'y' },
+ { "packet-buffered", no_argument, NULL, 'U' },
+#endif
+ { "linktype", required_argument, NULL, 'y' },
#if defined(HAVE_PCAP_DEBUG) || defined(HAVE_YYDEBUG)
- { NULL, no_argument, NULL, 'Y' },
+ { "debug-filter-parser", no_argument, NULL, 'Y' },
#endif
- { NULL, required_argument, NULL, 'z' },
- { NULL, required_argument, NULL, 'Z' },
+ { "relinquish-privileges", required_argument, NULL, 'Z' },
+ { "number", no_argument, NULL, OPTION_NUMBER },
+ { "version", no_argument, NULL, OPTION_VERSION },
{ NULL, 0, NULL, 0 }
};
break;
case 'h':
- usage();
+ print_usage();
+ exit(0);
break;
case 'H':
username = strdup(optarg);
break;
+ case OPTION_NUMBER:
+ gndo->ndo_packet_number = 1;
+ break;
+
+ case OPTION_VERSION:
+ print_version();
+ exit(0);
+ break;
+
default:
- usage();
+ print_usage();
+ exit(1);
/* NOTREACHED */
}
print_info = (struct print_info *)user;
ndo = print_info->ndo;
+
+ if(ndo->ndo_packet_number)
+ ND_PRINT((ndo, "%5u ", packets_captured));
+
ts_print(ndo, &h->ts);
/*
#endif
static void
-usage(void)
+print_version(void)
{
extern char version[];
#ifndef HAVE_PCAP_LIB_VERSION
(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,
"\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
(void)fprintf(stderr,
-"\t\t[ -i interface ]" j_FLAG_USAGE " [ -M secret ]\n");
+"\t\t[ -i interface ]" j_FLAG_USAGE " [ -M secret ] [ --number ]\n");
#ifdef HAVE_PCAP_SETDIRECTION
(void)fprintf(stderr,
"\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);
}