2 * Utility definitions 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
11 #ifndef __CAPTURE_PCAP_UTIL_H__
12 #define __CAPTURE_PCAP_UTIL_H__
16 #endif /* __cplusplus */
20 #include <wsutil/wspcap.h>
22 #include "capture_opts.h"
25 * A snapshot length of 0 is useless - and libpcap/WinPcap don't guarantee
26 * that a snapshot length of 0 will work, and, on some platforms, it won't
27 * (with BPF, for example, the kernel is told the snapshot length via the
28 * return value of the BPF program, and a return value of 0 means "drop
29 * the packet"), so the minimum packet size is 1 byte.
31 #define MIN_PACKET_SIZE 1 /* minimum amount of packet data we can read */
33 GList *get_interface_list(int *err, char **err_str);
34 #ifdef HAVE_PCAP_REMOTE
35 GList *get_remote_interface_list(const char *hostname, const char *port,
36 int auth_type, const char *username,
37 const char *passwd, int *err, char **err_str);
38 #endif /* HAVE_PCAP_REMOTE */
40 const char *linktype_val_to_name(int dlt);
41 int linktype_name_to_val(const char *linktype);
43 int get_pcap_datalink(pcap_t *pch, const char *devicename);
45 gboolean set_pcap_datalink(pcap_t *pcap_h, int datalink, char *name,
46 char *errmsg, size_t errmsg_len,
47 char *secondary_errmsg, size_t secondary_errmsg_len);
49 #ifdef HAVE_PCAP_SET_TSTAMP_PRECISION
51 * Return TRUE if the pcap_t in question is set up for high-precision
52 * time stamps, FALSE otherwise.
54 gboolean have_high_resolution_timestamp(pcap_t *pcap_h);
55 #endif /* HAVE_PCAP_SET_TSTAMP_PRECISION */
61 CAP_DEVICE_OPEN_NO_ERR, /* No error */
62 CAP_DEVICE_OPEN_ERR_PERMISSIONS, /* Error is known to be a permissions error */
63 CAP_DEVICE_OPEN_ERR_NOT_PERMISSIONS, /* Error is known not to be a permissions error */
64 CAP_DEVICE_OPEN_ERR_GENERIC /* Error is not known to be one or the other */
65 } cap_device_open_err;
66 extern if_capabilities_t *get_if_capabilities(interface_options *interface_opts,
67 cap_device_open_err *err, char **err_str);
68 extern pcap_t *open_capture_device(capture_options *capture_opts,
69 interface_options *interface_opts,
70 int timeout, cap_device_open_err *open_err,
71 char (*open_err_str)[PCAP_ERRBUF_SIZE]);
73 #endif /* HAVE_LIBPCAP */
75 extern void get_compiled_caplibs_version(GString *str);
78 * Append to a GString an indication of the version of capture libraries
79 * with which we're running, or an indication that we're not running
80 * with capture libraries, if we were compiled with WinPcap but
81 * WinPcap wasn't loaded, or nothing, if we weren't compiled with
84 extern void get_runtime_caplibs_version(GString *str);
88 #endif /* __cplusplus */
90 #endif /* __CAPTURE_PCAP_UTIL_H__ */