1 /* capture-pcap-util-unix.c
2 * UN*X-specific utility routines for packet capture
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include <wireshark.h>
16 #include <ws_attributes.h>
17 #include <wsutil/feature_list.h>
24 # include <sys/capability.h>
27 #include "capture/capture_ifinfo.h"
28 #include "capture/capture-pcap-util.h"
29 #include "capture/capture-pcap-util-int.h"
31 #ifdef HAVE_PCAP_REMOTE
33 get_remote_interface_list(const char *hostname
, const char *port
,
34 int auth_type
, const char *username
,
35 const char *passwd
, int *err
, char **err_str
)
37 return get_interface_list_findalldevs_ex(hostname
, port
, auth_type
,
38 username
, passwd
, err
, err_str
);
43 get_interface_list(int *err
, char **err_str
)
45 return get_interface_list_findalldevs(err
, err_str
);
49 * Get an error message string for a CANT_GET_INTERFACE_LIST error from
50 * "get_interface_list()".
53 cant_get_if_list_error_message(const char *err_str
)
55 return ws_strdup_printf("Can't get list of interfaces: %s", err_str
);
59 get_if_capabilities_local(interface_options
*interface_opts
,
60 cap_device_open_status
*status
, char **status_str
)
62 #ifdef HAVE_PCAP_CREATE
63 return get_if_capabilities_pcap_create(interface_opts
, status
,
66 return get_if_capabilities_pcap_open_live(interface_opts
, status
,
72 open_capture_device_local(capture_options
*capture_opts
73 #ifndef HAVE_PCAP_CREATE
77 interface_options
*interface_opts
, int timeout
,
78 cap_device_open_status
*open_status
,
79 char (*open_status_str
)[PCAP_ERRBUF_SIZE
])
82 * We're not opening a remote device; use pcap_create() and
83 * pcap_activate() if we have them, so that we can set various
84 * options, otherwise use pcap_open_live().
86 #ifdef HAVE_PCAP_CREATE
87 return open_capture_device_pcap_create(capture_opts
,
88 interface_opts
, timeout
, open_status
, open_status_str
);
90 return open_capture_device_pcap_open_live(interface_opts
, timeout
,
91 open_status
, open_status_str
);
96 * Get the versions of libpcap, libpcap, and libnl with which we were
97 * compiled, and append them to a GString.
100 gather_caplibs_compile_info(feature_list l
)
103 * NOTE: in *some* flavors of UN*X, the data from a shared
104 * library might be linked into executable images that are
105 * linked with that shared library, in which case you could
106 * look at pcap_version[] to get the version with which
107 * the program was compiled.
109 * In other flavors of UN*X, that doesn't happen, so
110 * pcap_version[] gives you the version the program is
111 * running with, not the version it was built with, and,
112 * in at least some of them, if the length of a data item
113 * referred to by the executable - such as the pcap_version[]
114 * string - isn't the same in the version of the library
115 * with which the program was built and the version with
116 * which it was run, the run-time linker will complain,
119 * So, for now, we just give up on reporting the version
120 * of libpcap with which we were compiled.
122 #ifdef HAVE_PCAP_REMOTE
124 * We have remote pcap support in libpcap.
126 with_feature(l
, "libpcap (including remote capture support)");
128 with_feature(l
, "libpcap");
132 * XXX - these libraries are actually used only by dumpcap,
133 * but we mention them here so that a user reporting a bug
134 * can get information about dumpcap's libraries without
135 * having to run dumpcap.
139 #ifdef _LINUX_CAPABILITY_VERSION
140 with_feature(l
, "POSIX capabilities (Linux)");
141 #else /* _LINUX_CAPABILITY_VERSION */
142 with_feature(l
, "POSIX capabilities");
143 #endif /* _LINUX_CAPABILITY_VERSION */
144 #else /* HAVE_LIBCAP */
145 without_feature(l
, "POSIX capabilities");
146 #endif /* HAVE_LIBCAP */
149 /* This is a Linux-specific library. */
151 #if defined(HAVE_LIBNL1)
152 with_feature(l
, "libnl 1");
153 #elif defined(HAVE_LIBNL2)
154 with_feature(l
, "libnl 2");
155 #elif defined(HAVE_LIBNL3)
156 with_feature(l
, "libnl 3");
158 without_feature(l
, "libnl");
159 #endif /* libnl version */
160 #endif /* __linux__ */
164 gather_caplibs_runtime_info(feature_list l
)
166 const char *vstr
= pcap_lib_version();
169 * Remove the substring "version" from the output of pcap_lib_version()
170 * to be consistent with our format.
172 if (g_str_has_prefix(vstr
, "libpcap version ")) /* Sanity check */
173 with_feature(l
, "libpcap %s", vstr
+ strlen("libpcap version "));
175 with_feature(l
, "%s", vstr
);
178 #else /* HAVE_LIBPCAP */
181 * Append an indication that we were not compiled with libpcap
182 * to a GString. Don't even bother mentioning the other
186 gather_caplibs_compile_info(feature_list l
)
188 without_feature(l
, "libpcap");
192 gather_caplibs_runtime_info(feature_list l _U_
)
196 #endif /* HAVE_LIBPCAP */
199 * Editor modelines - https://www.wireshark.org/tools/modelines.html
204 * indent-tabs-mode: t
207 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
208 * :indentSize=8:tabSize=8:noTabs=false: