From 99a684a7c9a1405aa453fe495c38d179f0c0f2c9 Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Sat, 7 Aug 2010 22:30:52 +0200 Subject: [PATCH] Do more checking of command-line arguments --- src/main/radsniff.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/radsniff.c b/src/main/radsniff.c index c9a0cd8..b7bb8fa 100644 --- a/src/main/radsniff.c +++ b/src/main/radsniff.c @@ -161,7 +161,7 @@ static void sort(RADIUS_PACKET *packet) } #define USEC 1000000 -static void tv_sub(struct timeval *end, struct timeval *start, +static void tv_sub(const struct timeval *end, const struct timeval *start, struct timeval *elapsed) { elapsed->tv_sec = end->tv_sec - start->tv_sec; @@ -425,19 +425,23 @@ int main(int argc, char *argv[]) /* Open the device so we can spy */ if (filename) { descr = pcap_open_offline(filename, errbuf); + } else if (!dev) { + fprintf(stderr, "radsniff: No filename or device was specified.\n"); + exit(1); + } else { descr = pcap_open_live(dev, SNAPLEN, 1, 0, errbuf); } if (descr == NULL) { - printf("radsniff: pcap_open_live failed (%s)\n", errbuf); + fprintf(stderr, "radsniff: pcap_open_live failed (%s)\n", errbuf); exit(1); } /* Apply the rules */ if( pcap_compile(descr, &fp, pcap_filter, 0, netp) == -1) { - printf("radsniff: pcap_compile failed\n"); + fprintf(stderr, "radsniff: pcap_compile failed\n"); exit(1); } if (pcap_setfilter(descr, &fp) == -1) -- 2.1.4