wsutil/wsgcrypt.c decrypt_des_ecb
[wireshark-sm.git] / capture / capture-pcap-util-unix.c
blob8fa943061bd57494ce34373b4af7404ac5485655
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
9 */
11 #include "config.h"
13 #include <wireshark.h>
15 #include <string.h>
16 #include <ws_attributes.h>
17 #include <wsutil/feature_list.h>
19 #ifdef HAVE_LIBPCAP
21 #include <pcap.h>
23 #ifdef HAVE_LIBCAP
24 # include <sys/capability.h>
25 #endif
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
32 GList *
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);
40 #endif
42 GList *
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()".
52 char *
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);
58 if_capabilities_t *
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,
64 status_str);
65 #else
66 return get_if_capabilities_pcap_open_live(interface_opts, status,
67 status_str);
68 #endif
71 pcap_t *
72 open_capture_device_local(capture_options *capture_opts
73 #ifndef HAVE_PCAP_CREATE
74 _U_
75 #endif
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);
89 #else
90 return open_capture_device_pcap_open_live(interface_opts, timeout,
91 open_status, open_status_str);
92 #endif
96 * Get the versions of libpcap, libpcap, and libnl with which we were
97 * compiled, and append them to a GString.
99 void
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,
117 * which is Not Good.
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)");
127 #else
128 with_feature(l, "libpcap");
129 #endif
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.
137 /* LIBCAP */
138 #ifdef HAVE_LIBCAP
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 */
148 #ifdef __linux__
149 /* This is a Linux-specific library. */
150 /* LIBNL */
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");
157 #else /* no libnl */
158 without_feature(l, "libnl");
159 #endif /* libnl version */
160 #endif /* __linux__ */
163 void
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 "));
174 else
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
183 * libraries.
185 void
186 gather_caplibs_compile_info(feature_list l)
188 without_feature(l, "libpcap");
191 void
192 gather_caplibs_runtime_info(feature_list l _U_)
196 #endif /* HAVE_LIBPCAP */
199 * Editor modelines - https://www.wireshark.org/tools/modelines.html
201 * Local variables:
202 * c-basic-offset: 8
203 * tab-width: 8
204 * indent-tabs-mode: t
205 * End:
207 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
208 * :indentSize=8:tabSize=8:noTabs=false: