aboutsummaryrefslogtreecommitdiff
path: root/pcap-dbus.c
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2018-05-18 12:21:19 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2018-05-18 12:21:19 +0000
commitd109bf9e4b609b5a0626b433e56db4a47dc530bb (patch)
tree48bc2a4852c42b213448a7e9d93f2e5eb6348ea0 /pcap-dbus.c
parent2369c04eb959fda4140b71f1c78798251bf43b62 (diff)
downloadsrc-d109bf9e4b609b5a0626b433e56db4a47dc530bb.tar.gz
src-d109bf9e4b609b5a0626b433e56db4a47dc530bb.zip
Notes
Diffstat (limited to 'pcap-dbus.c')
-rw-r--r--pcap-dbus.c88
1 files changed, 80 insertions, 8 deletions
diff --git a/pcap-dbus.c b/pcap-dbus.c
index 8e92093da110..1252975e9ac7 100644
--- a/pcap-dbus.c
+++ b/pcap-dbus.c
@@ -29,7 +29,7 @@
*/
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
#include <string.h>
@@ -51,7 +51,7 @@ struct pcap_dbus {
};
static int
-dbus_read(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
+dbus_read(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_char *user)
{
struct pcap_dbus *handlep = handle->priv;
@@ -145,6 +145,28 @@ dbus_cleanup(pcap_t *handle)
pcap_cleanup_live_common(handle);
}
+/*
+ * We don't support non-blocking mode. I'm not sure what we'd
+ * do to support it and, given that we don't support select()/
+ * poll()/epoll_wait()/kevent() etc., it probably doesn't
+ * matter.
+ */
+static int
+dbus_getnonblock(pcap_t *p)
+{
+ pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "Non-blocking mode isn't supported for capturing on D-Bus");
+ return (-1);
+}
+
+static int
+dbus_setnonblock(pcap_t *p, int nonblock _U_)
+{
+ pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
+ "Non-blocking mode isn't supported for capturing on D-Bus");
+ return (-1);
+}
+
static int
dbus_activate(pcap_t *handle)
{
@@ -208,11 +230,36 @@ dbus_activate(pcap_t *handle)
handle->setfilter_op = install_bpf_program; /* XXX, later add support for dbus_bus_add_match() */
handle->setdirection_op = NULL;
handle->set_datalink_op = NULL; /* can't change data link type */
- handle->getnonblock_op = pcap_getnonblock_fd;
- handle->setnonblock_op = pcap_setnonblock_fd;
+ handle->getnonblock_op = dbus_getnonblock;
+ handle->setnonblock_op = dbus_setnonblock;
handle->stats_op = dbus_stats;
-
+ handle->cleanup_op = dbus_cleanup;
+
+#ifndef _WIN32
+ /*
+ * Unfortunately, trying to do a select()/poll()/epoll_wait()/
+ * kevent()/etc. on a D-Bus connection isn't a simple
+ * case of "give me an FD on which to wait".
+ *
+ * Apparently, you have to register "add watch", "remove watch",
+ * and "toggle watch" functions with
+ * dbus_connection_set_watch_functions(),
+ * keep a *set* of FDs, add to that set in the "add watch"
+ * function, subtract from it in the "remove watch" function,
+ * and either add to or subtract from that set in the "toggle
+ * watch" function, and do the wait on *all* of the FDs in the
+ * set. (Yes, you need the "toggle watch" function, so that
+ * the main loop doesn't itself need to check for whether
+ * a given watch is enabled or disabled - most libpcap programs
+ * know nothing about D-Bus and shouldn't *have* to know anything
+ * about D-Bus other than how to decode D-Bus messages.)
+ *
+ * Implementing that would require considerable changes in
+ * the way libpcap exports "selectable FDs" to its client.
+ * Until that's done, we just say "you can't do that".
+ */
handle->selectable_fd = handle->fd = -1;
+#endif
if (handle->opt.rfmon) {
/*
@@ -222,6 +269,14 @@ dbus_activate(pcap_t *handle)
return PCAP_ERROR_RFMON_NOTSUP;
}
+ /*
+ * Turn a negative snapshot value (invalid), a snapshot value of
+ * 0 (unspecified), or a value bigger than the normal maximum
+ * value, into the maximum message length for D-Bus (128MB).
+ */
+ if (handle->snapshot <= 0 || handle->snapshot > 134217728)
+ handle->snapshot = 134217728;
+
/* dbus_connection_set_max_message_size(handlep->conn, handle->snapshot); */
if (handle->opt.buffer_size != 0)
dbus_connection_set_max_received_size(handlep->conn, handle->opt.buffer_size);
@@ -264,15 +319,32 @@ dbus_create(const char *device, char *ebuf, int *is_ours)
return (NULL);
p->activate_op = dbus_activate;
+ /*
+ * Set these up front, so that, even if our client tries
+ * to set non-blocking mode before we're activated, or
+ * query the state of non-blocking mode, they get an error,
+ * rather than having the non-blocking mode option set
+ * for use later.
+ */
+ p->getnonblock_op = dbus_getnonblock;
+ p->setnonblock_op = dbus_setnonblock;
return (p);
}
int
-dbus_findalldevs(pcap_if_t **alldevsp, char *err_str)
+dbus_findalldevs(pcap_if_list_t *devlistp, char *err_str)
{
- if (pcap_add_if(alldevsp, "dbus-system", 0, "D-Bus system bus", err_str) < 0)
+ /*
+ * The notion of "connected" vs. "disconnected" doesn't apply.
+ * XXX - what about the notions of "up" and "running"?
+ */
+ if (add_dev(devlistp, "dbus-system",
+ PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE, "D-Bus system bus",
+ err_str) == NULL)
return -1;
- if (pcap_add_if(alldevsp, "dbus-session", 0, "D-Bus session bus", err_str) < 0)
+ if (add_dev(devlistp, "dbus-session",
+ PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE, "D-Bus session bus",
+ err_str) == NULL)
return -1;
return 0;
}