* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
+/*
+ * This doesn't actually test libpcap itself; it tests whether
+ * valgrind properly handles the APIs libpcap uses. If it doesn't,
+ * we end up getting patches submitted to "fix" references that
+ * valgrind claims are being made to uninitialized data, when, in
+ * fact, the OS isn't making any such references - or we get
+ * valgrind *not* detecting *actual* incorrect references.
+ *
+ * Both BPF and Linux socket filters aren't handled correctly
+ * by some versions of valgrind. See valgrind bug 318203 for
+ * Linux:
+ *
+ * https://bugs.kde.org/show_bug.cgi?id=318203
+ *
+ * and valgrind bug 312989 for OS X:
+ *
+ * https://bugs.kde.org/show_bug.cgi?id=312989
+ *
+ * The fixes for both of those are checked into the official valgrind
+ * repository.
+ *
+ * The unofficial FreeBSD port has similar issues to the official OS X
+ * port, for similar reasons.
+ */
#ifndef lint
static const char copyright[] _U_ =
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000\n\
#endif
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include "pcap/funcattrs.h"
+
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
/* BSD-flavored OS - use BPF */
#define USE_BPF
#endif
#include <pcap.h>
-#ifndef HAVE___ATTRIBUTE__
-#define __attribute__(x)
-#endif
static char *program_name;
/* Forwards */
-static void usage(void) __attribute__((noreturn));
-static void error(const char *, ...)
- __attribute__((noreturn, format (printf, 1, 2)));
-static void warning(const char *, ...)
- __attribute__((format (printf, 1, 2)));
-
-extern int optind;
-extern int opterr;
-extern char *optarg;
+static void PCAP_NORETURN usage(void);
+static void PCAP_NORETURN error(const char *, ...) PCAP_PRINTFLIKE(1, 2);
+static void warning(const char *, ...) PCAP_PRINTFLIKE(1, 2);
/*
* On Windows, we need to open the file in binary mode, so that
char ebuf[PCAP_ERRBUF_SIZE];
char *infile;
char *cmdbuf;
+ pcap_if_t *devlist;
pcap_t *pd;
int status = 0;
int pcap_fd;
* No interface specified; get whatever pcap_lookupdev()
* finds.
*/
- device = pcap_lookupdev(ebuf);
- if (device == NULL) {
- error("couldn't find interface to use: %s",
- ebuf);
- }
+ if (pcap_findalldevs(&devlist, ebuf) == -1)
+ error("%s", ebuf);
+ if (devlist == NULL)
+ error("no interfaces available for capture");
+ device = strdup(devlist->name);
+ pcap_freealldevs(devlist);
}
if (infile != NULL) {