*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include "config.h"
#include <stdio.h>
#include <glib.h>
#include <gmodule.h>
+#include <epan/strutil.h>
+
#include "capture_ifinfo.h"
#include "capture-pcap-util.h"
#include "capture-pcap-util-int.h"
+#include "capture-wpcap.h"
#include <wsutil/file_util.h>
char *);
static pcap_t* (*p_pcap_open_live) (const char *, int, int, int, char *);
static int (*p_pcap_loop) (pcap_t *, int, pcap_handler, guchar *);
+#ifdef HAVE_PCAP_OPEN_DEAD
+static pcap_t* (*p_pcap_open_dead) (int, int);
+#endif
static void (*p_pcap_freecode) (struct bpf_program *);
#ifdef HAVE_PCAP_FINDALLDEVS
static int (*p_pcap_findalldevs) (pcap_if_t **, char *);
static int (*p_pcap_free_datalinks)(int *);
#endif
+#ifdef HAVE_BPF_IMAGE
+static char *(*p_bpf_image) (const struct bpf_insn *, int);
+#endif
+
typedef struct {
const char *name;
gpointer *ptr;
gboolean optional;
} symbol_table_t;
-#define SYM(x, y) { STRINGIFY(x) , (gpointer) &CONCAT(p_,x), y }
+#define SYM(x, y) { G_STRINGIFY(x) , (gpointer) &CONCAT(p_,x), y }
void
load_wpcap(void)
SYM(pcap_createsrcstr, FALSE),
#endif
SYM(pcap_open_live, FALSE),
+#ifdef HAVE_PCAP_OPEN_DEAD
+ SYM(pcap_open_dead, FALSE),
+#endif
#ifdef HAVE_PCAP_SETSAMPLING
SYM(pcap_setsampling, TRUE),
#endif
#endif
#ifdef HAVE_PCAP_FREE_DATALINKS
SYM(pcap_free_datalinks, TRUE),
+#endif
+#ifdef HAVE_BPF_IMAGE
+ SYM(bpf_image, FALSE),
#endif
{ NULL, NULL, FALSE }
};
has_wpcap = TRUE;
}
+/*
+ * The official list of WinPcap mirrors is at
+ * http://www.winpcap.org/misc/mirrors.htm
+ */
+char *
+cant_load_winpcap_err(const char *app_name)
+{
+ return g_strdup_printf(
+"Unable to load WinPcap (wpcap.dll); %s will not be able to capture\n"
+"packets.\n"
+"\n"
+"In order to capture packets, WinPcap must be installed; see\n"
+"\n"
+" http://www.winpcap.org/\n"
+"\n"
+"or the mirror at\n"
+"\n"
+" http://www.mirrors.wiretapped.net/security/packet-capture/winpcap/\n"
+"\n"
+"or the mirror at\n"
+"\n"
+" http://winpcap.cs.pu.edu.tw/\n"
+"\n"
+"for a downloadable version of WinPcap and for instructions on how to install\n"
+"WinPcap.",
+ app_name);
+}
+
char*
pcap_lookupdev (char *a)
{
pcap_open_live(const char *a, int b, int c, int d, char *e)
{
if (!has_wpcap) {
+ g_snprintf(e, PCAP_ERRBUF_SIZE,
+ "unable to load WinPcap (wpcap.dll); can't open %s to capture",
+ a);
return NULL;
}
return p_pcap_open_live(a, b, c, d, e);
}
+#ifdef HAVE_PCAP_OPEN_DEAD
+pcap_t*
+pcap_open_dead(int a, int b)
+{
+ if (!has_wpcap) {
+ return NULL;
+ }
+ return p_pcap_open_dead(a, b);
+}
+#endif
+
+#ifdef HAVE_BPF_IMAGE
+char *
+bpf_image(const struct bpf_insn *a, int b)
+{
+ if (!has_wpcap) {
+ return NULL;
+ }
+ return p_bpf_image(a, b);
+}
+#endif
+
#ifdef HAVE_PCAP_REMOTE
pcap_t*
pcap_open(const char *a, int b, int c, int d, struct pcap_rmtauth *e, char *f)
{
if (!has_wpcap) {
+ g_snprintf(f, PCAP_ERRBUF_SIZE,
+ "unable to load WinPcap (wpcap.dll); can't open %s to capture",
+ a);
return NULL;
}
return p_pcap_open(a, b, c, d, e, f);
int i, j;
char errbuf[PCAP_ERRBUF_SIZE];
+ if (!has_wpcap) {
+ /*
+ * We don't have WinPcap, so we can't get a list of
+ * interfaces.
+ */
+ *err = DONT_HAVE_PCAP;
+ *err_str = cant_load_winpcap_err("you");
+ return NULL;
+ }
+
#ifdef HAVE_PCAP_FINDALLDEVS
if (p_pcap_findalldevs != NULL)
return get_interface_list_findalldevs(err, err_str);
j = 0;
while (names[i] != 0) {
if (j < MAX_WIN_IF_NAME_LEN)
- ascii_name[j++] = (char) names[i++];
+ ascii_name[j++] = (char) names[i++];
}
ascii_name[j] = '\0';
i++;
il = g_list_append(il,
- if_info_new(ascii_name, ascii_desc));
+ if_info_new(ascii_name, ascii_desc, FALSE));
}
} else {
/*
* that interface's description.
*/
il = g_list_append(il,
- if_info_new(&win95names[i], desc));
+ if_info_new(&win95names[i], desc, FALSE));
/*
* Skip to the next description.
void
get_compiled_pcap_version(GString *str)
{
- g_string_append(str, "with WinPcap (version unknown)");
+ g_string_append(str, "with WinPcap (" G_STRINGIFY(PCAP_VERSION) ")");
}
/*
* not and, if we have it and we have "pcap_lib_version()",
* what version we have.
*/
- GModule *handle; /* handle returned by dlopen */
+ GModule *handle; /* handle returned by ws_module_open */
static gchar *packetVer;
gchar *blankp;