2005-12-06 00:07:13 +00:00
|
|
|
/* capture-pcap-util.c
|
2004-07-18 00:24:25 +00:00
|
|
|
* Utility routines for packet capture
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2004-07-18 00:24:25 +00:00
|
|
|
* 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
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-07-18 00:24:25 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 01:29:52 +00:00
|
|
|
#include "config.h"
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2007-11-30 22:01:05 +00:00
|
|
|
#include <stdio.h>
|
2004-07-18 00:24:25 +00:00
|
|
|
#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>
|
2007-08-23 17:49:47 +00:00
|
|
|
#include <libpcap.h>
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2010-03-04 01:12:04 +00:00
|
|
|
#include "capture_ifinfo.h"
|
2005-12-06 00:07:13 +00:00
|
|
|
#include "capture-pcap-util.h"
|
|
|
|
#include "capture-pcap-util-int.h"
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifndef _WIN32
|
2004-07-18 00:24:25 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
From Mike Garratt:
Friendly Names for interfaces on Windows
Notes on the changes the patch covers:
* if_info_t struct: addition of friendly_name
* Dumpcap Interface list format changes:
+ Win32: "dumpcap -D" shows friendly_name in place of descript if known
+ All: machine interface "dumpcap -D -Z none" includes friendly_name in the
list in addition to the existing parameters
* interface_options struct: addition of console_display_name
+ When an interface name is displayed in a console, it will typically be the
console_display_name (instead of name).
+ console_display_name is used as the basis of the autogenerated temp
filenames
+ console_display_name is typically set to the friendly_name if known,
otherwise it is set to the interface name
* Enhancements to capture_opts_add_iface_opt() (the function which process -i
options).
+ Can now specify the interface using its name and friendly_name
+ Interface name matching is case insenstive
+ Name matching first attempts exact matching, then falls back to prefix
matching
(e.g. dumpcap -i local)
+ Validates interface names, instead of blindly sending them off to
winpcap/libpcap
+ Interface specification by number is still supported.
* capture_opts_trim_iface() has been refactored:
+ Instead of repeating a decent chunk of the cost in
capture_opts_add_iface_opt(), it calls capture_opts_trim_iface() to specify the
interface.
* introduction of capture_win_ifnames.[ch] (windows only code)
+ Implements static function GetInterfaceFriendlyNameFromDeviceGuid() - a
windows version independant function to convert an interface guid into its
friendly name. Uses published api functions on windows vista and higher, but
falls back to unpublished API functions on older windows releases.
+ void get_windows_interface_friendlyname(/* IN */ char
*interface_devicename, /* OUT */char **interface_friendlyname); - extracts the
GUID from the interface_devicename, then uses
GetInterfaceFriendlyNameFromDeviceGuid() to do the resolution
* Auto temp filename generation:
+ Now uses wireshark_pcapng_* or wireshark_pcap_* depending on file format
+ Basis temp filename format on console_display_name
+ Win32: if console_display_name is a windows interface guid, extracts
numbers from GUID here (instead of in interface option processing)
GUI CHANGES:
* Dialog that displays when you click the "Manage Interfaces" button (within
Capture Options dialog) has been renamed from "Add new interfaces" to
"Interface Management"
* ui/gtk/capture_dlg.c: new_interfaces_w variable renamed to
interface_management_w
* Win32: Local Interfaces tab on Interface Management dialog, shows includes
friendly name as far left column
* Interface Management dialog defaults to larger size on win32 - so it fits
without resizing local interfaces tab
* Interface Management dialog now saves preferences when you click the apply
button (local hidden interfaces was not persisting across restarts)
* Tweaks: "Interface Details" dialog (Interface list->Capture Interfaces ->
Details):
+ "Friendly Name" renamed to "NDIS Friendly Name"
+ Added "OS Friendly Name" to the top of the list
* Win32: The "Capture Interfaces" dialog now shows the friendly name instead of
device guid
* Welcome screen:
+ The height of the interface list scrollbox dynamically adjusts & updates to
the number visible interfaces.
Up to 10 interfaces can be listed without a scroll bar, the minimum height
is for 2 interfaces.
+ Win32: now shows just the Friendly Name if known - in place of
"Interfacename_Guid:(Description)"
svn path=/trunk/; revision=46083
2012-11-19 20:07:27 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "capture_win_ifnames.h" /* windows friendly interface names */
|
2012-11-22 06:02:49 +00:00
|
|
|
#else
|
|
|
|
#include "capture_unix_ifnames.h"
|
From Mike Garratt:
Friendly Names for interfaces on Windows
Notes on the changes the patch covers:
* if_info_t struct: addition of friendly_name
* Dumpcap Interface list format changes:
+ Win32: "dumpcap -D" shows friendly_name in place of descript if known
+ All: machine interface "dumpcap -D -Z none" includes friendly_name in the
list in addition to the existing parameters
* interface_options struct: addition of console_display_name
+ When an interface name is displayed in a console, it will typically be the
console_display_name (instead of name).
+ console_display_name is used as the basis of the autogenerated temp
filenames
+ console_display_name is typically set to the friendly_name if known,
otherwise it is set to the interface name
* Enhancements to capture_opts_add_iface_opt() (the function which process -i
options).
+ Can now specify the interface using its name and friendly_name
+ Interface name matching is case insenstive
+ Name matching first attempts exact matching, then falls back to prefix
matching
(e.g. dumpcap -i local)
+ Validates interface names, instead of blindly sending them off to
winpcap/libpcap
+ Interface specification by number is still supported.
* capture_opts_trim_iface() has been refactored:
+ Instead of repeating a decent chunk of the cost in
capture_opts_add_iface_opt(), it calls capture_opts_trim_iface() to specify the
interface.
* introduction of capture_win_ifnames.[ch] (windows only code)
+ Implements static function GetInterfaceFriendlyNameFromDeviceGuid() - a
windows version independant function to convert an interface guid into its
friendly name. Uses published api functions on windows vista and higher, but
falls back to unpublished API functions on older windows releases.
+ void get_windows_interface_friendlyname(/* IN */ char
*interface_devicename, /* OUT */char **interface_friendlyname); - extracts the
GUID from the interface_devicename, then uses
GetInterfaceFriendlyNameFromDeviceGuid() to do the resolution
* Auto temp filename generation:
+ Now uses wireshark_pcapng_* or wireshark_pcap_* depending on file format
+ Basis temp filename format on console_display_name
+ Win32: if console_display_name is a windows interface guid, extracts
numbers from GUID here (instead of in interface option processing)
GUI CHANGES:
* Dialog that displays when you click the "Manage Interfaces" button (within
Capture Options dialog) has been renamed from "Add new interfaces" to
"Interface Management"
* ui/gtk/capture_dlg.c: new_interfaces_w variable renamed to
interface_management_w
* Win32: Local Interfaces tab on Interface Management dialog, shows includes
friendly name as far left column
* Interface Management dialog defaults to larger size on win32 - so it fits
without resizing local interfaces tab
* Interface Management dialog now saves preferences when you click the apply
button (local hidden interfaces was not persisting across restarts)
* Tweaks: "Interface Details" dialog (Interface list->Capture Interfaces ->
Details):
+ "Friendly Name" renamed to "NDIS Friendly Name"
+ Added "OS Friendly Name" to the top of the list
* Win32: The "Capture Interfaces" dialog now shows the friendly name instead of
device guid
* Welcome screen:
+ The height of the interface list scrollbox dynamically adjusts & updates to
the number visible interfaces.
Up to 10 interfaces can be listed without a scroll bar, the minimum height
is for 2 interfaces.
+ Win32: now shows just the Friendly Name if known - in place of
"Interfacename_Guid:(Description)"
svn path=/trunk/; revision=46083
2012-11-19 20:07:27 +00:00
|
|
|
#endif
|
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
if_info_t *
|
2012-11-23 22:28:06 +00:00
|
|
|
if_info_new(const char *name, const char *description, gboolean loopback)
|
2004-07-18 00:24:25 +00:00
|
|
|
{
|
|
|
|
if_info_t *if_info;
|
2012-11-24 18:55:06 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
const char *guid_text;
|
|
|
|
GUID guid;
|
|
|
|
#endif
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2010-03-04 09:37:05 +00:00
|
|
|
if_info = (if_info_t *)g_malloc(sizeof (if_info_t));
|
2004-07-18 00:24:25 +00:00
|
|
|
if_info->name = g_strdup(name);
|
2012-11-23 22:28:06 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
/*
|
|
|
|
* On Windows, the "description" is a vendor description,
|
|
|
|
* and the friendly name isn't returned by WinPcap.
|
|
|
|
* Fetch it ourselves.
|
|
|
|
*/
|
2012-11-24 18:55:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip over the "\Device\NPF_" prefix in the device name,
|
|
|
|
* if present.
|
|
|
|
*/
|
|
|
|
if (strncmp("\\Device\\NPF_", name, 12) == 0)
|
|
|
|
guid_text = name + 12;
|
|
|
|
else
|
|
|
|
guid_text = name;
|
|
|
|
|
|
|
|
/* Now try to parse what remains as a GUID. */
|
|
|
|
if (parse_as_guid(guid_text, &guid)) {
|
|
|
|
/*
|
|
|
|
* Success. Try to get a friendly name using the GUID.
|
|
|
|
* As this is a regular interface, the description is a
|
|
|
|
* vendor description.
|
|
|
|
*/
|
|
|
|
if_info->friendly_name = get_interface_friendly_name_from_device_guid(&guid);
|
|
|
|
if_info->vendor_description = g_strdup(description);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* This is probably not a regular interface; we only
|
|
|
|
* support NT 5 (W2K) and later, so all regular interfaces
|
|
|
|
* should have GUIDs at the end of the name. Therefore,
|
|
|
|
* the description, if supplied, is a friendly name
|
|
|
|
* provided by WinPcap, and there is no vendor
|
|
|
|
* description.
|
|
|
|
*/
|
|
|
|
if_info->friendly_name = g_strdup(description);
|
2012-11-24 19:08:28 +00:00
|
|
|
if_info->vendor_description = NULL;
|
2012-11-24 18:55:06 +00:00
|
|
|
}
|
2012-11-23 22:28:06 +00:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* On UN*X, if there is a description, it's a friendly
|
|
|
|
* name, and there is no vendor description.
|
|
|
|
* If there's no description, fetch a friendly name
|
|
|
|
* if we can; if that fails, then, for a loopback
|
|
|
|
* interface, give it the friendly name "Loopback".
|
|
|
|
*/
|
|
|
|
if_info->friendly_name = g_strdup(description);
|
|
|
|
if (if_info->friendly_name == NULL) {
|
|
|
|
if_info->friendly_name = get_unix_interface_friendly_name(name);
|
|
|
|
if (if_info->friendly_name == NULL) {
|
|
|
|
/*
|
|
|
|
* If this is a loopback interface, give it a
|
|
|
|
* "friendly name" of "Loopback".
|
|
|
|
*/
|
|
|
|
if (loopback)
|
|
|
|
if_info->friendly_name = g_strdup("Loopback");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if_info->vendor_description = NULL;
|
|
|
|
#endif
|
2012-11-22 06:02:49 +00:00
|
|
|
if_info->loopback = loopback;
|
2010-03-04 01:12:04 +00:00
|
|
|
if_info->addrs = NULL;
|
2004-07-18 00:24:25 +00:00
|
|
|
return if_info;
|
|
|
|
}
|
|
|
|
|
2004-07-18 02:34:45 +00:00
|
|
|
void
|
|
|
|
if_info_add_address(if_info_t *if_info, struct sockaddr *addr)
|
2004-07-18 00:24:25 +00:00
|
|
|
{
|
2010-03-04 01:12:04 +00:00
|
|
|
if_addr_t *if_addr;
|
2004-07-18 23:07:04 +00:00
|
|
|
struct sockaddr_in *ai;
|
2004-07-19 01:06:06 +00:00
|
|
|
#ifdef INET6
|
|
|
|
struct sockaddr_in6 *ai6;
|
|
|
|
#endif
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2004-07-18 02:34:45 +00:00
|
|
|
switch (addr->sa_family) {
|
|
|
|
|
|
|
|
case AF_INET:
|
2011-04-26 02:47:52 +00:00
|
|
|
ai = (struct sockaddr_in *)(void *)addr;
|
2010-03-04 09:37:05 +00:00
|
|
|
if_addr = (if_addr_t *)g_malloc(sizeof(*if_addr));
|
2010-03-04 01:12:04 +00:00
|
|
|
if_addr->ifat_type = IF_AT_IPv4;
|
|
|
|
if_addr->addr.ip4_addr =
|
2004-07-18 23:07:04 +00:00
|
|
|
*((guint32 *)&(ai->sin_addr.s_addr));
|
2010-03-04 01:12:04 +00:00
|
|
|
if_info->addrs = g_slist_append(if_info->addrs, if_addr);
|
2004-07-18 18:47:44 +00:00
|
|
|
break;
|
|
|
|
|
2004-07-19 01:06:06 +00:00
|
|
|
#ifdef INET6
|
2004-07-18 18:47:44 +00:00
|
|
|
case AF_INET6:
|
2011-04-26 02:47:52 +00:00
|
|
|
ai6 = (struct sockaddr_in6 *)(void *)addr;
|
2010-03-04 09:37:05 +00:00
|
|
|
if_addr = (if_addr_t *)g_malloc(sizeof(*if_addr));
|
2010-03-04 01:12:04 +00:00
|
|
|
if_addr->ifat_type = IF_AT_IPv6;
|
|
|
|
memcpy((void *)&if_addr->addr.ip6_addr,
|
2004-07-19 01:06:06 +00:00
|
|
|
(void *)&ai6->sin6_addr.s6_addr,
|
2010-03-04 01:12:04 +00:00
|
|
|
sizeof if_addr->addr.ip6_addr);
|
|
|
|
if_info->addrs = g_slist_append(if_info->addrs, if_addr);
|
2004-07-18 02:34:45 +00:00
|
|
|
break;
|
2004-07-18 18:47:44 +00:00
|
|
|
#endif
|
2004-07-18 02:34:45 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_PCAP_FINDALLDEVS
|
2004-07-18 02:34:45 +00:00
|
|
|
/*
|
2012-11-22 06:02:49 +00:00
|
|
|
* Get all IP address information for the given interface.
|
2004-07-18 02:34:45 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
if_info_ip(if_info_t *if_info, pcap_if_t *d)
|
|
|
|
{
|
|
|
|
pcap_addr_t *a;
|
|
|
|
|
|
|
|
/* All addresses */
|
|
|
|
for (a = d->addresses; a != NULL; a = a->next) {
|
|
|
|
if (a->addr != NULL)
|
|
|
|
if_info_add_address(if_info, a->addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-04 11:19:29 +00:00
|
|
|
#ifdef HAVE_PCAP_REMOTE
|
|
|
|
GList *
|
|
|
|
get_interface_list_findalldevs_ex(const char *source,
|
|
|
|
struct pcap_rmtauth *auth,
|
|
|
|
int *err, char **err_str)
|
2008-11-03 20:04:01 +00:00
|
|
|
{
|
|
|
|
GList *il = NULL;
|
|
|
|
pcap_if_t *alldevs, *dev;
|
|
|
|
if_info_t *if_info;
|
|
|
|
char errbuf[PCAP_ERRBUF_SIZE];
|
|
|
|
|
|
|
|
if (pcap_findalldevs_ex((char *)source, auth, &alldevs, errbuf) == -1) {
|
|
|
|
*err = CANT_GET_INTERFACE_LIST;
|
|
|
|
if (err_str != NULL)
|
|
|
|
*err_str = cant_get_if_list_error_message(errbuf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alldevs == NULL) {
|
|
|
|
/*
|
|
|
|
* No interfaces found.
|
|
|
|
*/
|
|
|
|
*err = NO_INTERFACES_FOUND;
|
|
|
|
if (err_str != NULL)
|
|
|
|
*err_str = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dev = alldevs; dev != NULL; dev = dev->next) {
|
2012-11-23 22:28:06 +00:00
|
|
|
if_info = if_info_new(dev->name, dev->description,
|
|
|
|
(dev->flags & PCAP_IF_LOOPBACK) ? TRUE : FALSE);
|
2008-11-03 20:04:01 +00:00
|
|
|
il = g_list_append(il, if_info);
|
|
|
|
if_info_ip(if_info, dev);
|
|
|
|
}
|
|
|
|
pcap_freealldevs(alldevs);
|
|
|
|
|
|
|
|
return il;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
GList *
|
2007-01-21 23:45:36 +00:00
|
|
|
get_interface_list_findalldevs(int *err, char **err_str)
|
2004-07-18 00:24:25 +00:00
|
|
|
{
|
|
|
|
GList *il = NULL;
|
|
|
|
pcap_if_t *alldevs, *dev;
|
|
|
|
if_info_t *if_info;
|
2007-01-21 23:45:36 +00:00
|
|
|
char errbuf[PCAP_ERRBUF_SIZE];
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2007-01-21 23:45:36 +00:00
|
|
|
if (pcap_findalldevs(&alldevs, errbuf) == -1) {
|
2004-07-18 00:24:25 +00:00
|
|
|
*err = CANT_GET_INTERFACE_LIST;
|
2007-01-21 23:45:36 +00:00
|
|
|
if (err_str != NULL)
|
|
|
|
*err_str = cant_get_if_list_error_message(errbuf);
|
2004-07-18 00:24:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alldevs == NULL) {
|
|
|
|
/*
|
|
|
|
* No interfaces found.
|
|
|
|
*/
|
|
|
|
*err = NO_INTERFACES_FOUND;
|
2007-01-21 23:45:36 +00:00
|
|
|
if (err_str != NULL)
|
|
|
|
*err_str = NULL;
|
2004-07-18 00:24:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dev = alldevs; dev != NULL; dev = dev->next) {
|
2012-11-23 22:28:06 +00:00
|
|
|
if_info = if_info_new(dev->name, dev->description,
|
|
|
|
(dev->flags & PCAP_IF_LOOPBACK) ? TRUE : FALSE);
|
2004-07-18 00:24:25 +00:00
|
|
|
il = g_list_append(il, if_info);
|
|
|
|
if_info_ip(if_info, dev);
|
|
|
|
}
|
|
|
|
pcap_freealldevs(alldevs);
|
|
|
|
|
|
|
|
return il;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_PCAP_FINDALLDEVS */
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_if_info_addr_cb(gpointer addr, gpointer user_data _U_)
|
|
|
|
{
|
2004-07-18 18:47:44 +00:00
|
|
|
g_free(addr);
|
2004-07-18 00:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_if_cb(gpointer data, gpointer user_data _U_)
|
|
|
|
{
|
2010-03-04 09:37:05 +00:00
|
|
|
if_info_t *if_info = (if_info_t *)data;
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
g_free(if_info->name);
|
2012-11-22 06:02:49 +00:00
|
|
|
g_free(if_info->friendly_name);
|
|
|
|
g_free(if_info->vendor_description);
|
2004-07-18 00:24:25 +00:00
|
|
|
|
2010-03-04 01:12:04 +00:00
|
|
|
g_slist_foreach(if_info->addrs, free_if_info_addr_cb, NULL);
|
|
|
|
g_slist_free(if_info->addrs);
|
2006-11-02 09:45:12 +00:00
|
|
|
g_free(if_info);
|
2004-07-18 00:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
free_interface_list(GList *if_list)
|
|
|
|
{
|
|
|
|
g_list_foreach(if_list, free_if_cb, NULL);
|
|
|
|
g_list_free(if_list);
|
|
|
|
}
|
|
|
|
|
2008-12-21 23:22:12 +00:00
|
|
|
#if !defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) || !defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || !defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
|
|
|
|
struct dlt_choice {
|
|
|
|
const char *name;
|
|
|
|
const char *description;
|
|
|
|
int dlt;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DLT_CHOICE(code, description) { #code, description, code }
|
|
|
|
#define DLT_CHOICE_SENTINEL { NULL, NULL, 0 }
|
|
|
|
|
|
|
|
static struct dlt_choice dlt_choices[] = {
|
|
|
|
DLT_CHOICE(DLT_NULL, "BSD loopback"),
|
|
|
|
DLT_CHOICE(DLT_EN10MB, "Ethernet"),
|
|
|
|
DLT_CHOICE(DLT_IEEE802, "Token ring"),
|
|
|
|
DLT_CHOICE(DLT_ARCNET, "ARCNET"),
|
|
|
|
DLT_CHOICE(DLT_SLIP, "SLIP"),
|
|
|
|
DLT_CHOICE(DLT_PPP, "PPP"),
|
|
|
|
DLT_CHOICE(DLT_FDDI, "FDDI"),
|
|
|
|
DLT_CHOICE(DLT_ATM_RFC1483, "RFC 1483 IP-over-ATM"),
|
|
|
|
DLT_CHOICE(DLT_RAW, "Raw IP"),
|
|
|
|
DLT_CHOICE(DLT_SLIP_BSDOS, "BSD/OS SLIP"),
|
|
|
|
DLT_CHOICE(DLT_PPP_BSDOS, "BSD/OS PPP"),
|
|
|
|
DLT_CHOICE(DLT_ATM_CLIP, "Linux Classical IP-over-ATM"),
|
|
|
|
DLT_CHOICE(DLT_PPP_SERIAL, "PPP over serial"),
|
|
|
|
DLT_CHOICE(DLT_PPP_ETHER, "PPPoE"),
|
|
|
|
DLT_CHOICE(DLT_C_HDLC, "Cisco HDLC"),
|
|
|
|
DLT_CHOICE(DLT_IEEE802_11, "802.11"),
|
|
|
|
DLT_CHOICE(DLT_FRELAY, "Frame Relay"),
|
|
|
|
DLT_CHOICE(DLT_LOOP, "OpenBSD loopback"),
|
|
|
|
DLT_CHOICE(DLT_ENC, "OpenBSD encapsulated IP"),
|
|
|
|
DLT_CHOICE(DLT_LINUX_SLL, "Linux cooked"),
|
|
|
|
DLT_CHOICE(DLT_LTALK, "Localtalk"),
|
|
|
|
DLT_CHOICE(DLT_PFLOG, "OpenBSD pflog file"),
|
|
|
|
DLT_CHOICE(DLT_PRISM_HEADER, "802.11 plus Prism header"),
|
|
|
|
DLT_CHOICE(DLT_IP_OVER_FC, "RFC 2625 IP-over-Fibre Channel"),
|
|
|
|
DLT_CHOICE(DLT_SUNATM, "Sun raw ATM"),
|
|
|
|
DLT_CHOICE(DLT_IEEE802_11_RADIO, "802.11 plus BSD radio information header"),
|
|
|
|
DLT_CHOICE(DLT_APPLE_IP_OVER_IEEE1394, "Apple IP-over-IEEE 1394"),
|
|
|
|
DLT_CHOICE(DLT_ARCNET_LINUX, "Linux ARCNET"),
|
|
|
|
DLT_CHOICE(DLT_LINUX_IRDA, "Linux IrDA"),
|
|
|
|
DLT_CHOICE(DLT_IEEE802_11_RADIO_AVS, "802.11 plus AVS radio information header"),
|
|
|
|
DLT_CHOICE_SENTINEL
|
|
|
|
};
|
|
|
|
|
|
|
|
#if !defined(HAVE_PCAP_DATALINK_NAME_TO_VAL)
|
|
|
|
static int
|
|
|
|
pcap_datalink_name_to_val(const char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; dlt_choices[i].name != NULL; i++) {
|
|
|
|
if (g_ascii_strcasecmp(dlt_choices[i].name + sizeof("DLT_") - 1,
|
|
|
|
name) == 0)
|
|
|
|
return (dlt_choices[i].dlt);
|
|
|
|
}
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
#endif /* defined(HAVE_PCAP_DATALINK_NAME_TO_VAL) */
|
|
|
|
|
|
|
|
#if !defined(HAVE_PCAP_DATALINK_VAL_TO_NAME)
|
|
|
|
static const char *
|
|
|
|
pcap_datalink_val_to_name(int dlt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; dlt_choices[i].name != NULL; i++) {
|
|
|
|
if (dlt_choices[i].dlt == dlt)
|
|
|
|
return (dlt_choices[i].name + sizeof("DLT_") - 1);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
#endif /* defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) */
|
|
|
|
|
|
|
|
#if !defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION)
|
|
|
|
const char *
|
|
|
|
pcap_datalink_val_to_description(int dlt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; dlt_choices[i].name != NULL; i++) {
|
|
|
|
if (dlt_choices[i].dlt == dlt)
|
|
|
|
return (dlt_choices[i].description);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
#endif /* defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION) */
|
|
|
|
|
|
|
|
#endif /* !defined(HAVE_PCAP_DATALINK_VAL_TO_NAME) || !defined(HAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION) */
|
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
static void
|
|
|
|
free_linktype_cb(gpointer data, gpointer user_data _U_)
|
|
|
|
{
|
2010-03-04 09:37:05 +00:00
|
|
|
data_link_info_t *linktype_info = (data_link_info_t *)data;
|
2004-07-18 00:24:25 +00:00
|
|
|
|
|
|
|
g_free(linktype_info->name);
|
2009-03-15 18:08:46 +00:00
|
|
|
g_free(linktype_info->description);
|
2004-07-18 00:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-14 00:49:28 +00:00
|
|
|
free_if_capabilities(if_capabilities_t *caps)
|
2004-07-18 00:24:25 +00:00
|
|
|
{
|
2010-05-13 17:37:39 +00:00
|
|
|
g_list_foreach(caps->data_link_types, free_linktype_cb, NULL);
|
|
|
|
g_list_free(caps->data_link_types);
|
|
|
|
g_free(caps);
|
2004-07-18 00:24:25 +00:00
|
|
|
}
|
|
|
|
|
2006-02-17 02:18:48 +00:00
|
|
|
const char *
|
|
|
|
linktype_val_to_name(int dlt)
|
|
|
|
{
|
|
|
|
return pcap_datalink_val_to_name(dlt);
|
|
|
|
}
|
|
|
|
|
|
|
|
int linktype_name_to_val(const char *linktype)
|
|
|
|
{
|
|
|
|
return pcap_datalink_name_to_val(linktype);
|
|
|
|
}
|
|
|
|
|
2004-07-18 00:24:25 +00:00
|
|
|
#endif /* HAVE_LIBPCAP */
|