# include "config.h"
#endif
+#include <stdio.h>
+#include <glib.h>
+#include <gmodule.h>
+
#ifdef HAVE_LIBPCAP
#include <pcap.h>
#endif
-#include <glib.h>
-#include <gmodule.h>
-
#include "capture-pcap-util.h"
#include "capture-pcap-util-int.h"
/* XXX - yes, I know, I should move cppmagic.h to a generic location. */
#include "tools/lemon/cppmagic.h"
-
#define MAX_WIN_IF_NAME_LEN 511
static const char *(*p_pcap_lib_version) (void);
static int (*p_pcap_setbuff) (pcap_t *, int dim);
static int (*p_pcap_next_ex) (pcap_t *, struct pcap_pkthdr **pkt_header, const u_char **pkt_data);
+#ifdef HAVE_PCAP_REMOTE
+static pcap_t* (*p_pcap_open) (const char *, int, int, int,
+ struct pcap_rmtauth *, char *);
+static int (*p_pcap_findalldevs_ex) (char *, struct pcap_rmtauth *,
+ pcap_if_t **, char *);
+static int (*p_pcap_createsrcstr) (char *, int, const char *, const char *,
+ const char *, char *);
+#endif
+#ifdef HAVE_PCAP_SETSAMPLING
+static struct pcap_samp* (*p_pcap_setsampling)(pcap_t *);
+#endif
typedef struct {
const char *name;
SYM(pcap_geterr, FALSE),
SYM(pcap_compile, FALSE),
SYM(pcap_lookupnet, FALSE),
+#ifdef HAVE_PCAP_REMOTE
+ SYM(pcap_open, FALSE),
+ SYM(pcap_findalldevs_ex, FALSE),
+ SYM(pcap_createsrcstr, FALSE),
+#else
SYM(pcap_open_live, FALSE),
+#endif
+#ifdef HAVE_PCAP_SETSAMPLING
+ SYM(pcap_setsampling, TRUE),
+#endif
SYM(pcap_loop, FALSE),
SYM(pcap_freecode, TRUE),
#ifdef HAVE_PCAP_FINDALLDEVS
return p_pcap_open_live(a, b, c, d, e);
}
+#ifdef HAVE_PCAP_REMOTE
+pcap_t*
+pcap_open(const char *a, int b, int c, int d, struct pcap_rmtauth *e, char *f)
+{
+ g_assert(has_wpcap);
+ return p_pcap_open(a, b, c, d, e, f);
+}
+
+int
+pcap_findalldevs_ex(char *a, struct pcap_rmtauth *b, pcap_if_t **c, char *d)
+{
+ g_assert(has_wpcap);
+ return p_pcap_findalldevs_ex(a, b, c, d);
+}
+
+int
+pcap_createsrcstr(char *a, int b, const char *c, const char *d, const char *e,
+ char *f)
+{
+ g_assert(has_wpcap);
+ return p_pcap_createsrcstr(a, b, c, d, e, f);
+}
+#endif
+
+#ifdef HAVE_PCAP_SETSAMPLING
+struct pcap_samp *
+pcap_setsampling(pcap_t *a)
+{
+ g_assert(has_wpcap);
+ if (p_pcap_setsampling != NULL) {
+ return p_pcap_setsampling(a);
+ }
+ return NULL;
+}
+#endif
+
int
pcap_loop(pcap_t *a, int b, pcap_handler c, guchar *d)
{
* We don't have it in WinPcap; do it ourselves.
*/
for (i = 0; dlt_choices[i].name != NULL; i++) {
- if (strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1,
+ if (g_ascii_strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1,
name) == 0)
return dlt_choices[i].dlt;
}
return p_pcap_next_ex(a, b, c);
}
+#ifdef HAVE_PCAP_REMOTE
+GList *
+get_remote_interface_list(const char *hostname, const char *port,
+ int auth_type, const char *username,
+ const char *passwd, int *err, char **err_str)
+{
+ struct pcap_rmtauth auth;
+ char source[PCAP_BUF_SIZE];
+ char errbuf[PCAP_ERRBUF_SIZE];
+ GList *result;
+
+ if (pcap_createsrcstr(source, PCAP_SRC_IFREMOTE, hostname, port,
+ NULL, errbuf) == -1) {
+ *err = CANT_GET_INTERFACE_LIST;
+ if (err_str != NULL)
+ *err_str = cant_get_if_list_error_message(errbuf);
+ return NULL;
+ }
+
+ auth.type = auth_type;
+ auth.username = g_strdup(username);
+ auth.password = g_strdup(passwd);
+
+ result = get_interface_list_findalldevs_ex(source, &auth, err, err_str);
+ g_free(auth.username);
+ g_free(auth.password);
+
+ return result;
+}
+#endif
+
/*
* This will use "pcap_findalldevs()" if we have it, otherwise it'll
* fall back on "pcap_lookupdev()".
*/
GList *
-get_interface_list(int *err, char *err_str)
+get_interface_list(int *err, char **err_str)
{
+#ifdef HAVE_PCAP_REMOTE
+ char source[PCAP_BUF_SIZE];
+#else
GList *il = NULL;
wchar_t *names;
char *win95names;
char ascii_name[MAX_WIN_IF_NAME_LEN + 1];
char ascii_desc[MAX_WIN_IF_NAME_LEN + 1];
int i, j;
+#endif
+ char errbuf[PCAP_ERRBUF_SIZE];
+
+#ifdef HAVE_PCAP_REMOTE
+ if (p_pcap_createsrcstr(source, PCAP_SRC_IFLOCAL, NULL, NULL,
+ NULL, errbuf) == -1) {
+ *err = CANT_GET_INTERFACE_LIST;
+ if (err_str != NULL)
+ *err_str = cant_get_if_list_error_message(errbuf);
+ return NULL;
+ }
+ return get_interface_list_findalldevs_ex(source, NULL, err, err_str);
+#else
#ifdef HAVE_PCAP_FINDALLDEVS
if (p_pcap_findalldevs != NULL)
* description of the Nth adapter.
*/
- names = (wchar_t *)pcap_lookupdev(err_str);
+ names = (wchar_t *)pcap_lookupdev(errbuf);
i = 0;
if (names) {
* No interfaces found.
*/
*err = NO_INTERFACES_FOUND;
+ if (err_str != NULL)
+ *err_str = NULL;
}
return il;
+#endif /* HAVE_PCAP_REMOTE */
}
/*
gchar *blankp;
if (has_wpcap) {
- g_string_sprintfa(str, "with ");
+ g_string_append_printf(str, "with ");
if (p_pcap_lib_version != NULL)
- g_string_sprintfa(str, p_pcap_lib_version());
+ g_string_append_printf(str, p_pcap_lib_version());
else {
/*
* An alternative method of obtaining the version
g_module_close(handle);
}
}
- g_string_sprintfa(str, "WinPcap (%s)", packetVer);
+ g_string_append_printf(str, "WinPcap (%s)", packetVer);
}
} else
g_string_append(str, "without WinPcap");