-/* pcap-util.c
- * Utility routines for packet capture
- *
- * $Id: pcap-util.c,v 1.24 2004/02/24 01:11:27 guy Exp $
- *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
- * Copyright 1998 Gerald Combs
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * 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.
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#ifdef HAVE_LIBPCAP
-
-#include <pcap.h>
-
-#include <glib.h>
-
-#include <stdlib.h>
-#include <limits.h>
-#include <string.h>
-
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#include <wtap.h>
-#include <wtap-capture.h>
-
-#include "pcap-util.h"
-#include "pcap-util-int.h"
-
-/*
- * Get the data-link type for a libpcap device.
- * This works around AIX 5.x's non-standard and incompatible-with-the-
- * rest-of-the-universe libpcap.
- */
-int
-get_pcap_linktype(pcap_t *pch, char *devname
-#ifndef _AIX
- _U_
-#endif
-)
-{
- int linktype;
-#ifdef _AIX
- char *ifacename;
-#endif
-
- linktype = pcap_datalink(pch);
-#ifdef _AIX
-
- /*
- * The libpcap that comes with AIX 5.x uses RFC 1573 ifType values
- * rather than DLT_ values for link-layer types; the ifType values
- * for LAN devices are:
- *
- * Ethernet 6
- * 802.3 7
- * Token Ring 9
- * FDDI 15
- *
- * and the ifType value for a loopback device is 24.
- *
- * The AIX names for LAN devices begin with:
- *
- * Ethernet en
- * 802.3 et
- * Token Ring tr
- * FDDI fi
- *
- * and the AIX names for loopback devices begin with "lo".
- *
- * (The difference between "Ethernet" and "802.3" is presumably
- * whether packets have an Ethernet header, with a packet type,
- * or an 802.3 header, with a packet length, followed by an 802.2
- * header and possibly a SNAP header.)
- *
- * If the device name matches "linktype" interpreted as an ifType
- * value, rather than as a DLT_ value, we will assume this is AIX's
- * non-standard, incompatible libpcap, rather than a standard libpcap,
- * and will map the link-layer type to the standard DLT_ value for
- * that link-layer type, as that's what the rest of Ethereal expects.
- *
- * (This means the capture files won't be readable by a tcpdump
- * linked with AIX's non-standard libpcap, but so it goes. They
- * *will* be readable by standard versions of tcpdump, Ethereal,
- * and so on.)
- *
- * XXX - if we conclude we're using AIX libpcap, should we also
- * set a flag to cause us to assume the time stamps are in
- * seconds-and-nanoseconds form, and to convert them to
- * seconds-and-microseconds form before processing them and
- * writing them out?
- */
-
- /*
- * Find the last component of the device name, which is the
- * interface name.
- */
- ifacename = strchr(devname, '/');
- if (ifacename == NULL)
- ifacename = devname;
-
- /* See if it matches any of the LAN device names. */
- if (strncmp(ifacename, "en", 2) == 0) {
- if (linktype == 6) {
- /*
- * That's the RFC 1573 value for Ethernet; map it
- * to DLT_EN10MB.
- */
- linktype = 1;
- }
- } else if (strncmp(ifacename, "et", 2) == 0) {
- if (linktype == 7) {
- /*
- * That's the RFC 1573 value for 802.3; map it to
- * DLT_EN10MB.
- * (libpcap, tcpdump, Ethereal, etc. don't care if
- * it's Ethernet or 802.3.)
- */
- linktype = 1;
- }
- } else if (strncmp(ifacename, "tr", 2) == 0) {
- if (linktype == 9) {
- /*
- * That's the RFC 1573 value for 802.5 (Token Ring);
- * map it to DLT_IEEE802, which is what's used for
- * Token Ring.
- */
- linktype = 6;
- }
- } else if (strncmp(ifacename, "fi", 2) == 0) {
- if (linktype == 15) {
- /*
- * That's the RFC 1573 value for FDDI; map it to
- * DLT_FDDI.
- */
- linktype = 10;
- }
- } else if (strncmp(ifacename, "lo", 2) == 0) {
- if (linktype == 24) {
- /*
- * That's the RFC 1573 value for "software loopback"
- * devices; map it to DLT_NULL, which is what's used
- * for loopback devices on BSD.
- */
- linktype = 0;
- }
- }
-#endif
-
- return linktype;
-}
-
-if_info_t *
-if_info_new(char *name, char *description)
-{
- if_info_t *if_info;
-
- if_info = g_malloc(sizeof (if_info_t));
- if_info->name = g_strdup(name);
- if (description == NULL)
- if_info->description = NULL;
- else
- if_info->description = g_strdup(description);
- return if_info;
-}
-
-#ifdef HAVE_PCAP_FINDALLDEVS
-GList *
-get_interface_list_findalldevs(int *err, char *err_str)
-{
- GList *il = NULL;
- pcap_if_t *alldevs, *dev;
- if_info_t *if_info;
-
- if (pcap_findalldevs(&alldevs, err_str) == -1) {
- *err = CANT_GET_INTERFACE_LIST;
- return NULL;
- }
-
- if (alldevs == NULL) {
- /*
- * No interfaces found.
- */
- *err = NO_INTERFACES_FOUND;
- return NULL;
- }
-
- for (dev = alldevs; dev != NULL; dev = dev->next) {
- if_info = if_info_new(dev->name, dev->description);
- il = g_list_append(il, if_info);
- }
- pcap_freealldevs(alldevs);
-
- return il;
-}
-#endif /* HAVE_PCAP_FINDALLDEVS */
-
-static void
-free_if_cb(gpointer data, gpointer user_data _U_)
-{
- if_info_t *if_info = data;
-
- g_free(if_info->name);
- if (if_info->description != NULL)
- g_free(if_info->description);
-}
-
-void
-free_interface_list(GList *if_list)
-{
- g_list_foreach(if_list, free_if_cb, NULL);
- g_list_free(if_list);
-}
-
-/*
- * Get the data-link types available for a libpcap device.
- */
-static data_link_info_t *
-create_data_link_info(int dlt)
-{
- data_link_info_t *data_link_info;
-#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
- const char *typename;
-#endif
- int wtap_encap;
-
- data_link_info = g_malloc(sizeof (data_link_info_t));
- data_link_info->dlt = dlt;
-#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
- typename = pcap_datalink_val_to_name(dlt);
- if (typename != NULL)
- data_link_info->name = g_strdup(typename);
- else
-#endif
- data_link_info->name = g_strdup_printf("DLT %d", dlt);
- wtap_encap = wtap_pcap_encap_to_wtap_encap(dlt);
- if (wtap_encap == WTAP_ENCAP_UNKNOWN) {
- /*
- * We don't support this in Wiretap.
- * However, we should, so you can capture on it.
- * Put in an entry for it, with no description.
- */
- data_link_info->description = NULL;
- } else {
- /*
- * If this is null, that's a bug in
- * "wtap_pcap_encap_to_wtap_encap()" - it should always
- * return a valid encapsulation type - so we assume it's
- * not null.
- */
- data_link_info->description =
- g_strdup(wtap_encap_string(wtap_encap));
- }
- return data_link_info;
-}
-
-GList *
-get_pcap_linktype_list(char *devname, char *err_buf)
-{
- GList *linktype_list = NULL;
- pcap_t *pch;
- int deflt;
-#ifdef HAVE_PCAP_SET_DATALINK
- int *linktypes;
- int i, nlt;
-#endif
- data_link_info_t *data_link_info;
-
- pch = pcap_open_live(devname, MIN_PACKET_SIZE, 0, 0, err_buf);
- if (pch == NULL)
- return NULL;
- err_buf[0] = '\0'; /* an empty list doesn't mean an error */
- deflt = get_pcap_linktype(pch, devname);
-#ifdef HAVE_PCAP_LIST_DATALINKS
- nlt = pcap_list_datalinks(pch, &linktypes);
- if (nlt == 0 || linktypes == NULL)
- return NULL;
- for (i = 0; i < nlt; i++) {
- data_link_info = create_data_link_info(linktypes[i]);
-
- /*
- * XXX - for 802.11, make the most detailed 802.11
- * version the default, rather than the one the
- * device has as the default?
- */
- if (linktypes[i] == deflt)
- linktype_list = g_list_prepend(linktype_list,
- data_link_info);
- else
- linktype_list = g_list_append(linktype_list,
- data_link_info);
- }
- free(linktypes);
-#else
- data_link_info = create_data_link_info(deflt);
- linktype_list = g_list_append(linktype_list, data_link_info);
-#endif
-
- pcap_close(pch);
- return linktype_list;
-}
-
-static void
-free_linktype_cb(gpointer data, gpointer user_data _U_)
-{
- data_link_info_t *linktype_info = data;
-
- g_free(linktype_info->name);
- if (linktype_info->description != NULL)
- g_free(linktype_info->description);
-}
-
-void
-free_pcap_linktype_list(GList *linktype_list)
-{
- g_list_foreach(linktype_list, free_linktype_cb, NULL);
- g_list_free(linktype_list);
-}
-
-/* Set the data link type on a pcap. */
-const char *
-set_pcap_linktype(pcap_t *pch, char *devname
-#ifdef HAVE_PCAP_SET_DATALINK
- _U_
-#endif
- , int dlt)
-{
-#ifdef HAVE_PCAP_SET_DATALINK
- if (pcap_set_datalink(pch, dlt) == 0)
- return NULL; /* no error */
- return pcap_geterr(pch);
-#else
- /* Let them set it to the type it is; reject any other request. */
- if (get_pcap_linktype(pch, devname) == dlt)
- return NULL; /* no error */
- return "That DLT is not one of the DLTs supported by this device";
-#endif
-}
-
-#endif /* HAVE_LIBPCAP */
+/* pcap-util.c\r
+ * Utility routines for packet capture\r
+ *\r
+ * $Id: pcap-util.c,v 1.24 2004/02/24 01:11:27 guy Exp $\r
+ *\r
+ * Ethereal - Network traffic analyzer\r
+ * By Gerald Combs <gerald@ethereal.com>\r
+ * Copyright 1998 Gerald Combs\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+ */\r
+\r
+#ifdef HAVE_CONFIG_H\r
+# include "config.h"\r
+#endif\r
+\r
+#ifdef HAVE_LIBPCAP\r
+\r
+#include <pcap.h>\r
+\r
+#include <glib.h>\r
+\r
+#include <stdlib.h>\r
+#include <limits.h>\r
+#include <string.h>\r
+\r
+#ifdef HAVE_SYS_TYPES_H\r
+# include <sys/types.h>\r
+#endif\r
+\r
+#ifdef HAVE_SYS_SOCKET_H\r
+#include <sys/socket.h>\r
+#endif\r
+\r
+#include <wtap.h>\r
+#include <wtap-capture.h>\r
+\r
+#include "pcap-util.h"\r
+#include "pcap-util-int.h"\r
+\r
+#ifndef WIN32\r
+#include <netinet/in.h>\r
+#endif\r
+\r
+\r
+/*\r
+ * Get the data-link type for a libpcap device.\r
+ * This works around AIX 5.x's non-standard and incompatible-with-the-\r
+ * rest-of-the-universe libpcap.\r
+ */\r
+int\r
+get_pcap_linktype(pcap_t *pch, char *devname\r
+#ifndef _AIX\r
+ _U_\r
+#endif\r
+)\r
+{\r
+ int linktype;\r
+#ifdef _AIX\r
+ char *ifacename;\r
+#endif\r
+\r
+ linktype = pcap_datalink(pch);\r
+#ifdef _AIX\r
+\r
+ /*\r
+ * The libpcap that comes with AIX 5.x uses RFC 1573 ifType values\r
+ * rather than DLT_ values for link-layer types; the ifType values\r
+ * for LAN devices are:\r
+ *\r
+ * Ethernet 6\r
+ * 802.3 7\r
+ * Token Ring 9\r
+ * FDDI 15\r
+ *\r
+ * and the ifType value for a loopback device is 24.\r
+ *\r
+ * The AIX names for LAN devices begin with:\r
+ *\r
+ * Ethernet en\r
+ * 802.3 et\r
+ * Token Ring tr\r
+ * FDDI fi\r
+ *\r
+ * and the AIX names for loopback devices begin with "lo".\r
+ *\r
+ * (The difference between "Ethernet" and "802.3" is presumably\r
+ * whether packets have an Ethernet header, with a packet type,\r
+ * or an 802.3 header, with a packet length, followed by an 802.2\r
+ * header and possibly a SNAP header.)\r
+ *\r
+ * If the device name matches "linktype" interpreted as an ifType\r
+ * value, rather than as a DLT_ value, we will assume this is AIX's\r
+ * non-standard, incompatible libpcap, rather than a standard libpcap,\r
+ * and will map the link-layer type to the standard DLT_ value for\r
+ * that link-layer type, as that's what the rest of Ethereal expects.\r
+ *\r
+ * (This means the capture files won't be readable by a tcpdump\r
+ * linked with AIX's non-standard libpcap, but so it goes. They\r
+ * *will* be readable by standard versions of tcpdump, Ethereal,\r
+ * and so on.)\r
+ *\r
+ * XXX - if we conclude we're using AIX libpcap, should we also\r
+ * set a flag to cause us to assume the time stamps are in\r
+ * seconds-and-nanoseconds form, and to convert them to\r
+ * seconds-and-microseconds form before processing them and\r
+ * writing them out?\r
+ */\r
+\r
+ /*\r
+ * Find the last component of the device name, which is the\r
+ * interface name.\r
+ */\r
+ ifacename = strchr(devname, '/');\r
+ if (ifacename == NULL)\r
+ ifacename = devname;\r
+\r
+ /* See if it matches any of the LAN device names. */\r
+ if (strncmp(ifacename, "en", 2) == 0) {\r
+ if (linktype == 6) {\r
+ /*\r
+ * That's the RFC 1573 value for Ethernet; map it\r
+ * to DLT_EN10MB.\r
+ */\r
+ linktype = 1;\r
+ }\r
+ } else if (strncmp(ifacename, "et", 2) == 0) {\r
+ if (linktype == 7) {\r
+ /*\r
+ * That's the RFC 1573 value for 802.3; map it to\r
+ * DLT_EN10MB.\r
+ * (libpcap, tcpdump, Ethereal, etc. don't care if\r
+ * it's Ethernet or 802.3.)\r
+ */\r
+ linktype = 1;\r
+ }\r
+ } else if (strncmp(ifacename, "tr", 2) == 0) {\r
+ if (linktype == 9) {\r
+ /*\r
+ * That's the RFC 1573 value for 802.5 (Token Ring);\r
+ * map it to DLT_IEEE802, which is what's used for\r
+ * Token Ring.\r
+ */\r
+ linktype = 6;\r
+ }\r
+ } else if (strncmp(ifacename, "fi", 2) == 0) {\r
+ if (linktype == 15) {\r
+ /*\r
+ * That's the RFC 1573 value for FDDI; map it to\r
+ * DLT_FDDI.\r
+ */\r
+ linktype = 10;\r
+ }\r
+ } else if (strncmp(ifacename, "lo", 2) == 0) {\r
+ if (linktype == 24) {\r
+ /*\r
+ * That's the RFC 1573 value for "software loopback"\r
+ * devices; map it to DLT_NULL, which is what's used\r
+ * for loopback devices on BSD.\r
+ */\r
+ linktype = 0;\r
+ }\r
+ }\r
+#endif\r
+\r
+ return linktype;\r
+}\r
+\r
+if_info_t *\r
+if_info_new(char *name, char *description)\r
+{\r
+ if_info_t *if_info;\r
+\r
+ if_info = g_malloc(sizeof (if_info_t));\r
+ if_info->name = g_strdup(name);\r
+ if (description == NULL)\r
+ if_info->description = NULL;\r
+ else\r
+ if_info->description = g_strdup(description);\r
+ if_info->ip_addr = NULL;\r
+ if_info->loopback = FALSE;\r
+ return if_info;\r
+}\r
+\r
+\r
+/* get all ip address information from the given interface */\r
+static void if_info_ip(if_info_t *if_info, pcap_if_t *d)\r
+{\r
+ pcap_addr_t *a;\r
+ guint32 *ip_addr;\r
+\r
+ /* Loopback interface */\r
+ if_info->loopback = (d->flags & PCAP_IF_LOOPBACK) ? TRUE : FALSE;\r
+\r
+ /* All addresses */\r
+ for(a=d->addresses;a;a=a->next) {\r
+ switch(a->addr->sa_family)\r
+ {\r
+ /* IPv4 address */\r
+ case AF_INET:\r
+ if (a->addr) {\r
+ struct sockaddr_in *ai = ((struct sockaddr_in *)(a->addr));\r
+ ip_addr = g_malloc(sizeof(*ip_addr));\r
+ *ip_addr = *((guint32 *)&(ai->sin_addr.s_addr));\r
+ if_info->ip_addr = g_slist_append(if_info->ip_addr, ip_addr);\r
+ }\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
+\r
+#ifdef HAVE_PCAP_FINDALLDEVS\r
+GList *\r
+get_interface_list_findalldevs(int *err, char *err_str)\r
+{\r
+ GList *il = NULL;\r
+ pcap_if_t *alldevs, *dev;\r
+ if_info_t *if_info;\r
+\r
+ if (pcap_findalldevs(&alldevs, err_str) == -1) {\r
+ *err = CANT_GET_INTERFACE_LIST;\r
+ return NULL;\r
+ }\r
+\r
+ if (alldevs == NULL) {\r
+ /*\r
+ * No interfaces found.\r
+ */\r
+ *err = NO_INTERFACES_FOUND;\r
+ return NULL;\r
+ }\r
+\r
+ for (dev = alldevs; dev != NULL; dev = dev->next) {\r
+ if_info = if_info_new(dev->name, dev->description);\r
+ il = g_list_append(il, if_info);\r
+ if_info_ip(if_info, dev);\r
+ }\r
+ pcap_freealldevs(alldevs);\r
+\r
+ return il;\r
+}\r
+#endif /* HAVE_PCAP_FINDALLDEVS */\r
+\r
+static void\r
+free_if_info_addr_cb(gpointer addr, gpointer user_data _U_)\r
+{\r
+ g_free(addr);\r
+}\r
+\r
+static void\r
+free_if_cb(gpointer data, gpointer user_data _U_)\r
+{\r
+ if_info_t *if_info = data;\r
+\r
+ g_free(if_info->name);\r
+ if (if_info->description != NULL)\r
+ g_free(if_info->description);\r
+\r
+ g_slist_foreach(if_info->ip_addr, free_if_info_addr_cb, NULL);\r
+ g_slist_free(if_info->ip_addr);\r
+}\r
+\r
+void\r
+free_interface_list(GList *if_list)\r
+{\r
+ g_list_foreach(if_list, free_if_cb, NULL);\r
+ g_list_free(if_list);\r
+}\r
+\r
+/*\r
+ * Get the data-link types available for a libpcap device.\r
+ */\r
+static data_link_info_t *\r
+create_data_link_info(int dlt)\r
+{\r
+ data_link_info_t *data_link_info;\r
+#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME\r
+ const char *typename;\r
+#endif\r
+ int wtap_encap;\r
+\r
+ data_link_info = g_malloc(sizeof (data_link_info_t));\r
+ data_link_info->dlt = dlt;\r
+#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME\r
+ typename = pcap_datalink_val_to_name(dlt);\r
+ if (typename != NULL)\r
+ data_link_info->name = g_strdup(typename);\r
+ else\r
+#endif\r
+ data_link_info->name = g_strdup_printf("DLT %d", dlt);\r
+ wtap_encap = wtap_pcap_encap_to_wtap_encap(dlt);\r
+ if (wtap_encap == WTAP_ENCAP_UNKNOWN) {\r
+ /*\r
+ * We don't support this in Wiretap.\r
+ * However, we should, so you can capture on it.\r
+ * Put in an entry for it, with no description.\r
+ */\r
+ data_link_info->description = NULL;\r
+ } else {\r
+ /*\r
+ * If this is null, that's a bug in\r
+ * "wtap_pcap_encap_to_wtap_encap()" - it should always\r
+ * return a valid encapsulation type - so we assume it's\r
+ * not null.\r
+ */\r
+ data_link_info->description =\r
+ g_strdup(wtap_encap_string(wtap_encap));\r
+ }\r
+ return data_link_info;\r
+}\r
+\r
+GList *\r
+get_pcap_linktype_list(char *devname, char *err_buf)\r
+{\r
+ GList *linktype_list = NULL;\r
+ pcap_t *pch;\r
+ int deflt;\r
+#ifdef HAVE_PCAP_SET_DATALINK\r
+ int *linktypes;\r
+ int i, nlt;\r
+#endif\r
+ data_link_info_t *data_link_info;\r
+\r
+ pch = pcap_open_live(devname, MIN_PACKET_SIZE, 0, 0, err_buf);\r
+ if (pch == NULL)\r
+ return NULL;\r
+ err_buf[0] = '\0'; /* an empty list doesn't mean an error */\r
+ deflt = get_pcap_linktype(pch, devname);\r
+#ifdef HAVE_PCAP_LIST_DATALINKS\r
+ nlt = pcap_list_datalinks(pch, &linktypes);\r
+ if (nlt == 0 || linktypes == NULL)\r
+ return NULL;\r
+ for (i = 0; i < nlt; i++) {\r
+ data_link_info = create_data_link_info(linktypes[i]);\r
+\r
+ /*\r
+ * XXX - for 802.11, make the most detailed 802.11\r
+ * version the default, rather than the one the\r
+ * device has as the default?\r
+ */\r
+ if (linktypes[i] == deflt)\r
+ linktype_list = g_list_prepend(linktype_list,\r
+ data_link_info);\r
+ else\r
+ linktype_list = g_list_append(linktype_list,\r
+ data_link_info);\r
+ }\r
+ free(linktypes);\r
+#else\r
+ data_link_info = create_data_link_info(deflt);\r
+ linktype_list = g_list_append(linktype_list, data_link_info);\r
+#endif\r
+\r
+ pcap_close(pch);\r
+ return linktype_list;\r
+}\r
+\r
+static void\r
+free_linktype_cb(gpointer data, gpointer user_data _U_)\r
+{\r
+ data_link_info_t *linktype_info = data;\r
+\r
+ g_free(linktype_info->name);\r
+ if (linktype_info->description != NULL)\r
+ g_free(linktype_info->description);\r
+}\r
+\r
+void\r
+free_pcap_linktype_list(GList *linktype_list)\r
+{\r
+ g_list_foreach(linktype_list, free_linktype_cb, NULL);\r
+ g_list_free(linktype_list);\r
+}\r
+\r
+/* Set the data link type on a pcap. */\r
+const char *\r
+set_pcap_linktype(pcap_t *pch, char *devname\r
+#ifdef HAVE_PCAP_SET_DATALINK\r
+ _U_\r
+#endif\r
+ , int dlt)\r
+{\r
+#ifdef HAVE_PCAP_SET_DATALINK\r
+ if (pcap_set_datalink(pch, dlt) == 0)\r
+ return NULL; /* no error */\r
+ return pcap_geterr(pch);\r
+#else\r
+ /* Let them set it to the type it is; reject any other request. */\r
+ if (get_pcap_linktype(pch, devname) == dlt)\r
+ return NULL; /* no error */\r
+ return "That DLT is not one of the DLTs supported by this device";\r
+#endif\r
+}\r
+\r
+#endif /* HAVE_LIBPCAP */\r
-/* pcap-util.h
- * Utility definitions for packet capture
- *
- * $Id: pcap-util.h,v 1.7 2004/06/12 07:47:13 guy Exp $
- *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
- * Copyright 1998 Gerald Combs
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * 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.
- */
-
-#ifndef __PCAP_UTIL_H__
-#define __PCAP_UTIL_H__
-
-#ifdef HAVE_LIBPCAP
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-/*
- * XXX - this is also the traditional default snapshot size in
- * tcpdump - but, if IPv6 is enabled, it defaults to 96, to get an
- * IPv6 header + TCP + 22 extra bytes.
- *
- * Some libpcap versions for particular capture devices might happen
- * to impose a minimum, but it's not always 68.
- */
-#define MIN_PACKET_SIZE 68 /* minimum amount of packet data we can read */
-
-#define MAX_WIN_IF_NAME_LEN 511
-
-/*
- * The list of interfaces returned by "get_interface_list()" is
- * a list of these structures.
- */
-typedef struct {
- char *name;
- char *description;
-} if_info_t;
-
-GList *get_interface_list(int *err, char *err_str);
-
-/* Error values from "get_interface_list()". */
-#define CANT_GET_INTERFACE_LIST 0 /* error getting list */
-#define NO_INTERFACES_FOUND 1 /* list is empty */
-
-void free_interface_list(GList *if_list);
-
-/*
- * Get an error message string for a CANT_GET_INTERFACE_LIST error from
- * "get_interface_list()".
- */
-gchar *cant_get_if_list_error_message(const char *err_str);
-
-/*
- * The list of data link types returned by "get_pcap_linktype_list()" is
- * a list of these structures.
- */
-typedef struct {
- int dlt;
- char *name;
- char *description;
-} data_link_info_t;
-
-int get_pcap_linktype(pcap_t *pch, char *devname);
-GList *get_pcap_linktype_list(char *devname, char *err_buf);
-void free_pcap_linktype_list(GList *linktype_list);
-const char *set_pcap_linktype(pcap_t *pch, char *devname, int dlt);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* HAVE_LIBPCAP */
-
-/*
- * Append to a GString an indication of the version of libpcap/WinPcap
- * with which we were compiled, if we were, or an indication that we
- * weren't compiled with libpcap/WinPcap, if we weren't.
- */
-extern void get_compiled_pcap_version(GString *str);
-
-/*
- * Append to a GString an indication of the version of libpcap/WinPcap
- * with which we're running, or an indication that we're not running
- * with libpcap/WinPcap, if we were compiled with libpcap/WinPcap,
- * or nothing, if we weren't compiled with libpcap/WinPcap.
- */
-extern void get_runtime_pcap_version(GString *str);
-
-#endif /* __PCAP_UTIL_H__ */
+/* pcap-util.h\r
+ * Utility definitions for packet capture\r
+ *\r
+ * $Id: pcap-util.h,v 1.7 2004/06/12 07:47:13 guy Exp $\r
+ *\r
+ * Ethereal - Network traffic analyzer\r
+ * By Gerald Combs <gerald@ethereal.com>\r
+ * Copyright 1998 Gerald Combs\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+ */\r
+\r
+#ifndef __PCAP_UTIL_H__\r
+#define __PCAP_UTIL_H__\r
+\r
+#ifdef HAVE_LIBPCAP\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif /* __cplusplus */\r
+\r
+/*\r
+ * XXX - this is also the traditional default snapshot size in\r
+ * tcpdump - but, if IPv6 is enabled, it defaults to 96, to get an\r
+ * IPv6 header + TCP + 22 extra bytes.\r
+ *\r
+ * Some libpcap versions for particular capture devices might happen\r
+ * to impose a minimum, but it's not always 68.\r
+ */\r
+#define MIN_PACKET_SIZE 68 /* minimum amount of packet data we can read */\r
+\r
+#define MAX_WIN_IF_NAME_LEN 511\r
+\r
+/*\r
+ * The list of interfaces returned by "get_interface_list()" is\r
+ * a list of these structures.\r
+ */\r
+typedef struct {\r
+ char *name;\r
+ char *description;\r
+ GSList *ip_addr; /* containing guint32 values */\r
+ gboolean loopback;\r
+} if_info_t;\r
+\r
+GList *get_interface_list(int *err, char *err_str);\r
+\r
+/* Error values from "get_interface_list()". */\r
+#define CANT_GET_INTERFACE_LIST 0 /* error getting list */\r
+#define NO_INTERFACES_FOUND 1 /* list is empty */\r
+\r
+void free_interface_list(GList *if_list);\r
+\r
+/*\r
+ * Get an error message string for a CANT_GET_INTERFACE_LIST error from\r
+ * "get_interface_list()".\r
+ */\r
+gchar *cant_get_if_list_error_message(const char *err_str);\r
+\r
+/*\r
+ * The list of data link types returned by "get_pcap_linktype_list()" is\r
+ * a list of these structures.\r
+ */\r
+typedef struct {\r
+ int dlt;\r
+ char *name;\r
+ char *description;\r
+} data_link_info_t;\r
+\r
+int get_pcap_linktype(pcap_t *pch, char *devname);\r
+GList *get_pcap_linktype_list(char *devname, char *err_buf);\r
+void free_pcap_linktype_list(GList *linktype_list);\r
+const char *set_pcap_linktype(pcap_t *pch, char *devname, int dlt);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif /* __cplusplus */\r
+\r
+#endif /* HAVE_LIBPCAP */\r
+\r
+/*\r
+ * Append to a GString an indication of the version of libpcap/WinPcap\r
+ * with which we were compiled, if we were, or an indication that we\r
+ * weren't compiled with libpcap/WinPcap, if we weren't.\r
+ */\r
+extern void get_compiled_pcap_version(GString *str);\r
+\r
+/*\r
+ * Append to a GString an indication of the version of libpcap/WinPcap\r
+ * with which we're running, or an indication that we're not running\r
+ * with libpcap/WinPcap, if we were compiled with libpcap/WinPcap,\r
+ * or nothing, if we weren't compiled with libpcap/WinPcap.\r
+ */\r
+extern void get_runtime_pcap_version(GString *str);\r
+\r
+#endif /* __PCAP_UTIL_H__ */\r