*
* 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"
#ifdef HAVE_LIBPCAP
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef NEED_INET_V6DEFS_H
-# include "inet_v6defs.h"
+# include "wsutil/inet_v6defs.h"
#endif
#include <glib.h>
#include "capture_opts.h"
+#include "capture_session.h"
#include "capture_sync.h"
#include "log.h"
#include "capture_ifinfo.h"
+#ifdef HAVE_PCAP_REMOTE
+static GList *remote_interface_list = NULL;
+
+static void append_remote_list(GList *iflist)
+{
+ GSList *list;
+ GList *rlist;
+ if_addr_t *if_addr, *temp_addr;
+ if_info_t *if_info, *temp;
+
+ for (rlist = g_list_nth(remote_interface_list, 0); rlist != NULL; rlist = g_list_next(rlist)) {
+ if_info = (if_info_t *)rlist->data;
+ temp = g_malloc0(sizeof(if_info_t));
+ temp->name = g_strdup(if_info->name);
+ temp->friendly_name = g_strdup(if_info->friendly_name);
+ temp->vendor_description = g_strdup(if_info->vendor_description);
+ for (list = g_slist_nth(if_info->addrs, 0); list != NULL; list = g_slist_next(list)) {
+ temp_addr = g_malloc0(sizeof(if_addr_t));
+ if_addr = (if_addr_t *)list->data;
+ if (if_addr) {
+ temp_addr->ifat_type = if_addr->ifat_type;
+ if (temp_addr->ifat_type == IF_AT_IPv4) {
+ temp_addr->addr.ip4_addr = if_addr->addr.ip4_addr;
+ } else {
+ memcpy(temp_addr->addr.ip6_addr, if_addr->addr.ip6_addr, sizeof(if_addr->addr));
+ }
+ } else {
+ g_free(temp_addr);
+ temp_addr = NULL;
+ }
+ if (temp_addr) {
+ temp->addrs = g_slist_append(temp->addrs, temp_addr);
+ }
+ }
+ temp->loopback = if_info->loopback;
+ iflist = g_list_append(iflist, temp);
+ }
+}
+#endif
+
/**
* Fetch the interface list from a child process (dumpcap).
*
/* XXX - We parse simple text output to get our interface list. Should
* we use "real" data serialization instead, e.g. via XML? */
GList *
-capture_interface_list(int *err, char **err_str)
+capture_interface_list(int *err, char **err_str, void (*update_cb)(void))
{
int ret;
GList *if_list = NULL;
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface List ...");
/* Try to get our interface list */
- ret = sync_interface_list_open(&data, &primary_msg, &secondary_msg);
+ ret = sync_interface_list_open(&data, &primary_msg, &secondary_msg, update_cb);
if (ret != 0) {
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface List failed!");
if (err_str) {
g_free(data);
for (i = 0; raw_list[i] != NULL; i++) {
- if_parts = g_strsplit(raw_list[i], "\t", 4);
+ if_parts = g_strsplit(raw_list[i], "\t", 6);
if (if_parts[0] == NULL || if_parts[1] == NULL || if_parts[2] == NULL ||
- if_parts[3] == NULL) {
+ if_parts[3] == NULL || if_parts[4] == NULL || if_parts[5] == NULL) {
g_strfreev(if_parts);
continue;
}
continue;
}
- if_info = g_malloc0(sizeof(if_info_t));
+ if_info = g_new0(if_info_t,1);
if_info->name = g_strdup(name);
if (strlen(if_parts[1]) > 0)
- if_info->description = g_strdup(if_parts[1]);
- addr_parts = g_strsplit(if_parts[2], ",", 0);
+ if_info->vendor_description = g_strdup(if_parts[1]);
+ if (strlen(if_parts[2]) > 0)
+ if_info->friendly_name = g_strdup(if_parts[2]);
+ if_info->type = (interface_type)(int)strtol(if_parts[3], NULL, 10);
+ addr_parts = g_strsplit(if_parts[4], ",", 0);
for (j = 0; addr_parts[j] != NULL; j++) {
- if_addr = g_malloc0(sizeof(if_addr_t));
- if (inet_pton(AF_INET, addr_parts[j], &if_addr->addr.ip4_addr)) {
+ if_addr = g_new0(if_addr_t,1);
+ if (inet_pton(AF_INET, addr_parts[j], &if_addr->addr.ip4_addr) > 0) {
if_addr->ifat_type = IF_AT_IPv4;
} else if (inet_pton(AF_INET6, addr_parts[j],
- &if_addr->addr.ip6_addr)) {
+ &if_addr->addr.ip6_addr) > 0) {
if_addr->ifat_type = IF_AT_IPv6;
} else {
g_free(if_addr);
if_info->addrs = g_slist_append(if_info->addrs, if_addr);
}
}
- if (strcmp(if_parts[3], "loopback") == 0)
+ if (strcmp(if_parts[5], "loopback") == 0)
if_info->loopback = TRUE;
g_strfreev(if_parts);
g_strfreev(addr_parts);
if (err_str)
*err_str = g_strdup("No interfaces found");
}
+#ifdef HAVE_PCAP_REMOTE
+ if (remote_interface_list && g_list_length(remote_interface_list) > 0) {
+ append_remote_list(if_list);
+ }
+#endif
return if_list;
}
* we use "real" data serialization instead, e.g. via XML? */
if_capabilities_t *
capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
- char **err_str)
+ char **err_str, void (*update_cb)(void))
{
if_capabilities_t *caps;
GList *linktype_list = NULL;
/* Try to get our interface list */
err = sync_if_capabilities_open(ifname, monitor_mode, &data,
- &primary_msg, &secondary_msg);
+ &primary_msg, &secondary_msg, update_cb);
if (err != 0) {
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities failed!");
if (err_str) {
/*
* Allocate the interface capabilities structure.
*/
- caps = g_malloc(sizeof *caps);
+ caps = (if_capabilities_t *)g_malloc(sizeof *caps);
switch (*raw_list[0]) {
case '0':
continue;
}
- data_link_info = g_malloc(sizeof (data_link_info_t));
+ data_link_info = g_new(data_link_info_t,1);
data_link_info->dlt = (int) strtol(lt_parts[0], NULL, 10);
data_link_info->name = g_strdup(lt_parts[1]);
if (strcmp(lt_parts[2], "(not supported)") != 0)
return caps;
}
+#ifdef HAVE_PCAP_REMOTE
+void add_interface_to_remote_list(if_info_t *if_info)
+{
+ GSList *list;
+ if_addr_t *if_addr, *temp_addr;
+
+ if_info_t *temp = g_malloc0(sizeof(if_info_t));
+ temp->name = g_strdup(if_info->name);
+ temp->friendly_name = g_strdup(if_info->friendly_name);
+ temp->vendor_description = g_strdup(if_info->vendor_description);
+ for (list = g_slist_nth(if_info->addrs, 0); list != NULL; list = g_slist_next(list)) {
+ temp_addr = g_malloc0(sizeof(if_addr_t));
+ if_addr = (if_addr_t *)list->data;
+ if (if_addr) {
+ temp_addr->ifat_type = if_addr->ifat_type;
+ if (temp_addr->ifat_type == IF_AT_IPv4) {
+ temp_addr->addr.ip4_addr = if_addr->addr.ip4_addr;
+ } else {
+ memcpy(temp_addr->addr.ip6_addr, if_addr->addr.ip6_addr, sizeof(if_addr->addr));
+ }
+ } else {
+ g_free(temp_addr);
+ temp_addr = NULL;
+ }
+ if (temp_addr) {
+ temp->addrs = g_slist_append(temp->addrs, temp_addr);
+ }
+ }
+ temp->loopback = if_info->loopback;
+ remote_interface_list = g_list_append(remote_interface_list, temp);
+}
+#endif
#endif /* HAVE_LIBPCAP */