PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/capture_opts.h

https://gitlab.com/crondaemon/wireshark-legacy
C Header | 394 lines | 249 code | 49 blank | 96 comment | 0 complexity | 68ad2e738093eb5f9ab35df1765bf418 MD5 | raw file
  1. /* capture_opts.h
  2. * Capture options (all parameters needed to do the actual capture)
  3. *
  4. * Wireshark - Network traffic analyzer
  5. * By Gerald Combs <gerald@wireshark.org>
  6. * Copyright 1998 Gerald Combs
  7. *
  8. * SPDX-License-Identifier: GPL-2.0-or-later
  9. */
  10. /** @file
  11. *
  12. * Capture options (all parameters needed to do the actual capture)
  13. *
  14. */
  15. #ifndef __CAPTURE_OPTS_H__
  16. #define __CAPTURE_OPTS_H__
  17. #include <sys/types.h> /* for gid_t */
  18. #include <caputils/capture_ifinfo.h>
  19. #ifdef _WIN32
  20. #include <windows.h>
  21. #endif
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif /* __cplusplus */
  25. /*
  26. * Long options.
  27. * We do not currently have long options corresponding to all short
  28. * options; we should probably pick appropriate option names for them.
  29. *
  30. * NOTE:
  31. * for tshark, we're using a leading - in the optstring to prevent getopt()
  32. * from permuting the argv[] entries, in this case, unknown argv[] entries
  33. * will be returned as parameters to a dummy-option 1.
  34. * In short: we must not use 1 here, which is another reason to use
  35. * values outside the range of ASCII graphic characters.
  36. */
  37. #define LONGOPT_NUM_CAP_COMMENT LONGOPT_BASE_CAPTURE+1
  38. #define LONGOPT_LIST_TSTAMP_TYPES LONGOPT_BASE_CAPTURE+2
  39. #define LONGOPT_SET_TSTAMP_TYPE LONGOPT_BASE_CAPTURE+3
  40. /*
  41. * Options for capturing common to all capturing programs.
  42. */
  43. #ifdef HAVE_PCAP_REMOTE
  44. #define OPTSTRING_A "A:"
  45. #else
  46. #define OPTSTRING_A
  47. #endif
  48. #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
  49. #define LONGOPT_BUFFER_SIZE \
  50. {"buffer-size", required_argument, NULL, 'B'},
  51. #define OPTSTRING_B "B:"
  52. #else
  53. #define LONGOPT_BUFFER_SIZE
  54. #define OPTSTRING_B
  55. #endif
  56. #ifdef HAVE_PCAP_CREATE
  57. #define LONGOPT_MONITOR_MODE {"monitor-mode", no_argument, NULL, 'I'},
  58. #define OPTSTRING_I "I"
  59. #else
  60. #define LONGOPT_MONITOR_MODE
  61. #define OPTSTRING_I
  62. #endif
  63. #define LONGOPT_CAPTURE_COMMON \
  64. {"capture-comment", required_argument, NULL, LONGOPT_NUM_CAP_COMMENT}, \
  65. {"autostop", required_argument, NULL, 'a'}, \
  66. {"ring-buffer", required_argument, NULL, 'b'}, \
  67. LONGOPT_BUFFER_SIZE \
  68. {"list-interfaces", no_argument, NULL, 'D'}, \
  69. {"interface", required_argument, NULL, 'i'}, \
  70. LONGOPT_MONITOR_MODE \
  71. {"list-data-link-types", no_argument, NULL, 'L'}, \
  72. {"no-promiscuous-mode", no_argument, NULL, 'p'}, \
  73. {"snapshot-length", required_argument, NULL, 's'}, \
  74. {"linktype", required_argument, NULL, 'y'}, \
  75. {"list-time-stamp-types", no_argument, NULL, LONGOPT_LIST_TSTAMP_TYPES}, \
  76. {"time-stamp-type", required_argument, NULL, LONGOPT_SET_TSTAMP_TYPE},
  77. #define OPTSTRING_CAPTURE_COMMON \
  78. "a:" OPTSTRING_A "b:" OPTSTRING_B "c:Df:i:" OPTSTRING_I "Lps:y:"
  79. #ifdef HAVE_PCAP_REMOTE
  80. /* Type of capture source */
  81. typedef enum {
  82. CAPTURE_IFLOCAL, /**< Local network interface */
  83. CAPTURE_IFREMOTE /**< Remote network interface */
  84. } capture_source;
  85. /* Type of RPCAPD Authentication */
  86. typedef enum {
  87. CAPTURE_AUTH_NULL, /**< No authentication */
  88. CAPTURE_AUTH_PWD /**< User/password authentication */
  89. } capture_auth;
  90. #endif
  91. #ifdef HAVE_PCAP_SETSAMPLING
  92. /**
  93. * Method of packet sampling (dropping some captured packets),
  94. * may require additional integer parameter, marked here as N
  95. */
  96. typedef enum {
  97. CAPTURE_SAMP_NONE, /**< No sampling - capture all packets */
  98. CAPTURE_SAMP_BY_COUNT, /**< Counter-based sampling -
  99. capture 1 packet from every N */
  100. CAPTURE_SAMP_BY_TIMER /**< Timer-based sampling -
  101. capture no more than 1 packet
  102. in N milliseconds */
  103. } capture_sampling;
  104. #endif
  105. #ifdef HAVE_PCAP_REMOTE
  106. struct remote_host_info {
  107. gchar *remote_host; /**< Host name or network address for remote capturing */
  108. gchar *remote_port; /**< TCP port of remote RPCAP server */
  109. capture_auth auth_type; /**< Authentication type */
  110. gchar *auth_username; /**< Remote authentication parameters */
  111. gchar *auth_password; /**< Remote authentication parameters */
  112. gboolean datatx_udp;
  113. gboolean nocap_rpcap;
  114. gboolean nocap_local;
  115. };
  116. struct remote_host {
  117. gchar *r_host; /**< Host name or network address for remote capturing */
  118. gchar *remote_port; /**< TCP port of remote RPCAP server */
  119. capture_auth auth_type; /**< Authentication type */
  120. gchar *auth_username; /**< Remote authentication parameters */
  121. gchar *auth_password; /**< Remote authentication parameters */
  122. };
  123. typedef struct remote_options_tag {
  124. capture_source src_type;
  125. struct remote_host_info remote_host_opts;
  126. #ifdef HAVE_PCAP_SETSAMPLING
  127. capture_sampling sampling_method;
  128. int sampling_param;
  129. #endif
  130. } remote_options;
  131. #endif /* HAVE_PCAP_REMOTE */
  132. typedef struct interface_tag {
  133. gchar *name;
  134. gchar *display_name;
  135. gchar *friendly_name;
  136. gchar *vendor_description;
  137. guint type;
  138. gchar *addresses;
  139. gint no_addresses;
  140. gchar *cfilter;
  141. GList *links;
  142. gint active_dlt;
  143. gboolean pmode;
  144. gboolean has_snaplen;
  145. int snaplen;
  146. gboolean local;
  147. #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
  148. gint buffer;
  149. #endif
  150. #ifdef HAVE_PCAP_CREATE
  151. gboolean monitor_mode_enabled;
  152. gboolean monitor_mode_supported;
  153. #endif
  154. #ifdef HAVE_PCAP_REMOTE
  155. remote_options remote_opts;
  156. #endif
  157. guint32 last_packets;
  158. guint32 packet_diff;
  159. if_info_t if_info;
  160. gboolean selected;
  161. gboolean hidden;
  162. /* External capture cached data */
  163. GHashTable *external_cap_args_settings;
  164. gchar *timestamp_type;
  165. } interface_t;
  166. typedef struct link_row_tag {
  167. gchar *name;
  168. gint dlt;
  169. } link_row;
  170. typedef struct interface_options_tag {
  171. gchar *name; /* the name of the interface supplied to libpcap/WinPcap/Npcap to specify the interface */
  172. gchar *descr; /* a more user-friendly description of the interface; may be NULL if none */
  173. gchar *hardware; /* description of the hardware */
  174. gchar *display_name; /* the name displayed in the console and title bar */
  175. gchar *cfilter;
  176. gboolean has_snaplen;
  177. int snaplen;
  178. int linktype;
  179. gboolean promisc_mode;
  180. interface_type if_type;
  181. gchar *extcap;
  182. gchar *extcap_fifo;
  183. GHashTable *extcap_args;
  184. GPid extcap_pid; /* pid of running process or WS_INVALID_PID */
  185. gpointer extcap_pipedata;
  186. guint extcap_child_watch;
  187. #ifdef _WIN32
  188. HANDLE extcap_pipe_h;
  189. HANDLE extcap_control_in_h;
  190. HANDLE extcap_control_out_h;
  191. #endif
  192. gchar *extcap_control_in;
  193. gchar *extcap_control_out;
  194. #ifdef CAN_SET_CAPTURE_BUFFER_SIZE
  195. int buffer_size;
  196. #endif
  197. gboolean monitor_mode;
  198. #ifdef HAVE_PCAP_REMOTE
  199. capture_source src_type;
  200. gchar *remote_host;
  201. gchar *remote_port;
  202. capture_auth auth_type;
  203. gchar *auth_username;
  204. gchar *auth_password;
  205. gboolean datatx_udp;
  206. gboolean nocap_rpcap;
  207. gboolean nocap_local;
  208. #endif
  209. #ifdef HAVE_PCAP_SETSAMPLING
  210. capture_sampling sampling_method;
  211. int sampling_param;
  212. #endif
  213. gchar *timestamp_type; /* requested timestamp as string */
  214. int timestamp_type_id; /* Timestamp type to pass to pcap_set_tstamp_type.
  215. only valid if timestamp_type != NULL */
  216. } interface_options;
  217. /** Capture options coming from user interface */
  218. typedef struct capture_options_tag {
  219. /* general */
  220. GArray *ifaces; /**< the interfaces to use for the
  221. next capture, entries are of
  222. type interface_options */
  223. GArray *all_ifaces; /**< all interfaces, entries are
  224. of type interface_t */
  225. int ifaces_err; /**< if all_ifaces is null, the error
  226. when it was fetched, if any */
  227. gchar *ifaces_err_info; /**< error string for that error */
  228. guint num_selected;
  229. /*
  230. * Options to be applied to all interfaces.
  231. *
  232. * Some of these can be set from the GUI, others can't; setting
  233. * the link-layer header type, for example, doesn't necessarily
  234. * make sense, as different interfaces may support different sets
  235. * of link-layer header types.
  236. *
  237. * Some that can't be set from the GUI can be set from the command
  238. * line, by specifying them before any interface is specified.
  239. * This includes the link-layer header type, so if somebody asks
  240. * for a link-layer header type that an interface on which they're
  241. * capturing doesn't support, we should report an error and fail
  242. * to capture.
  243. *
  244. * These can be overridden per-interface.
  245. */
  246. interface_options default_options;
  247. gboolean saving_to_file; /**< TRUE if capture is writing to a file */
  248. gchar *save_file; /**< the capture file name */
  249. gboolean group_read_access; /**< TRUE is group read permission needs to be set */
  250. gboolean use_pcapng; /**< TRUE if file format is pcapng */
  251. /* GUI related */
  252. gboolean real_time_mode; /**< Update list of packets in real time */
  253. gboolean show_info; /**< show the info dialog. */
  254. gboolean restart; /**< restart after closing is done */
  255. gchar *orig_save_file; /**< the original capture file name (saved for a restart) */
  256. /* multiple files (and ringbuffer) */
  257. gboolean multi_files_on; /**< TRUE if ring buffer in use */
  258. gboolean has_file_duration; /**< TRUE if ring duration specified */
  259. gdouble file_duration; /**< Switch file after n seconds */
  260. gboolean has_file_interval; /**< TRUE if ring interval specified */
  261. gint32 file_interval; /**< Create time intervals of n seconds */
  262. gboolean has_file_packets; /**< TRUE if ring packet count is
  263. specified */
  264. int file_packets; /**< Switch file after n packets */
  265. gboolean has_ring_num_files; /**< TRUE if ring num_files specified */
  266. guint32 ring_num_files; /**< Number of multiple buffer files */
  267. /* autostop conditions */
  268. gboolean has_autostop_files; /**< TRUE if maximum number of capture files
  269. are specified */
  270. int autostop_files; /**< Maximum number of capture files */
  271. gboolean has_autostop_packets; /**< TRUE if maximum packet count is
  272. specified */
  273. int autostop_packets; /**< Maximum packet count */
  274. gboolean has_autostop_filesize; /**< TRUE if maximum capture file size
  275. is specified */
  276. guint32 autostop_filesize; /**< Maximum capture file size in kB */
  277. gboolean has_autostop_duration; /**< TRUE if maximum capture duration
  278. is specified */
  279. gdouble autostop_duration; /**< Maximum capture duration */
  280. gchar *capture_comment; /** capture comment to write to the
  281. output file */
  282. gboolean print_file_names; /**< TRUE if printing names of completed
  283. files as we close them */
  284. gchar *print_name_to; /**< output file name */
  285. /* internally used (don't touch from outside) */
  286. gboolean output_to_pipe; /**< save_file is a pipe (named or stdout) */
  287. gboolean capture_child; /**< hidden option: Wireshark child mode */
  288. } capture_options;
  289. /* initialize the capture_options with some reasonable values */
  290. extern void
  291. capture_opts_init(capture_options *capture_opts);
  292. /* clean internal structures */
  293. extern void
  294. capture_opts_cleanup(capture_options *capture_opts);
  295. /* set a command line option value */
  296. extern int
  297. capture_opts_add_opt(capture_options *capture_opts, int opt, const char *optarg, gboolean *start_capture);
  298. /* log content of capture_opts */
  299. extern void
  300. capture_opts_log(const char *log_domain, GLogLevelFlags log_level, capture_options *capture_opts);
  301. enum caps_query {
  302. CAPS_MONITOR_MODE = 0x1,
  303. CAPS_QUERY_LINK_TYPES = 0x2,
  304. CAPS_QUERY_TIMESTAMP_TYPES = 0x4
  305. };
  306. /* print interface capabilities, including link layer types */
  307. extern void
  308. capture_opts_print_if_capabilities(if_capabilities_t *caps, char *name, int queries);
  309. /* print list of interfaces */
  310. extern void
  311. capture_opts_print_interfaces(GList *if_list);
  312. /* trim the snaplen entry */
  313. extern void
  314. capture_opts_trim_snaplen(capture_options *capture_opts, int snaplen_min);
  315. /* trim the ring_num_files entry */
  316. extern void
  317. capture_opts_trim_ring_num_files(capture_options *capture_opts);
  318. /* pick default interface if none was specified */
  319. extern int
  320. capture_opts_default_iface_if_necessary(capture_options *capture_opts,
  321. const char *capture_device);
  322. extern void
  323. capture_opts_del_iface(capture_options *capture_opts, guint if_index);
  324. extern void
  325. collect_ifaces(capture_options *capture_opts);
  326. extern void
  327. capture_opts_free_interface_t(interface_t *device);
  328. /* Default capture buffer size in Mbytes. */
  329. #define DEFAULT_CAPTURE_BUFFER_SIZE 2
  330. #ifdef __cplusplus
  331. }
  332. #endif /* __cplusplus */
  333. #endif /* __CAPTURE_OPTS_H__ */
  334. /*
  335. * Editor modelines - https://www.wireshark.org/tools/modelines.html
  336. *
  337. * Local variables:
  338. * c-basic-offset: 4
  339. * tab-width: 8
  340. * indent-tabs-mode: nil
  341. * End:
  342. *
  343. * vi: set shiftwidth=4 tabstop=8 expandtab:
  344. * :indentSize=4:tabSize=8:noTabs=true:
  345. */