1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//! Module containg code to define the extcap interfaces. These are data used to
//! popuplate the `Capture` or interface list in the main page of Wireshark.
use cratePrintSentence;
use Cow;
use TypedBuilder;
/// Enum defining the data link types.
pub use DataLink;
/// Metadata for this extcap program. The version will be used for displaying
/// the version information of the extcap interface in the about dialog of
/// Wireshark.
///
/// A default implementation of `Metadata` is provided as `Metadata::default()`,
/// which extracts these information from the `version`, `homepage`, and
/// `description` attributes in the cargo manifest.
/// ## Example
///
/// ```
/// # use r_extcap::ExtcapFormatter;
/// use r_extcap::interface::Metadata;
///
/// let metadata = Metadata {
/// version: "3.2.1-test".into(),
/// help_url: "http://www.wireshark.org".into(),
/// display_description: "Just for testing".into(),
/// };
/// assert_eq!(
/// format!("{}", ExtcapFormatter(&metadata)),
/// "extcap {version=3.2.1-test}{help=http://www.wireshark.org}{display=Just for testing}\n"
/// )
/// ```
/// Definition of an interface for this extcap program. An interface is an entry
/// in the Wireshark homepage, similar to `Wi-Fi: en0`. Instances of this should
/// be passed to
/// [`InterfacesStep::list_interfaces`][crate::InterfacesStep::list_interfaces].
/// ```
/// use r_extcap::config::ExtcapFormatter;
/// use r_extcap::interface::{DataLink, Dlt, Interface};
/// # let dlt = Dlt {
/// # data_link_type: DataLink::ETHERNET,
/// # name: "ETHERNET".into(),
/// # display: "IEEE 802.3 Ethernet".into(),
/// # };
/// assert_eq!(
/// ExtcapFormatter(&Interface{ value: "MyInterface".into(), display: "My interface".into(), dlt }).to_string(),
/// "interface {value=MyInterface}{display=My interface}\n",
/// );
/// ```
/// Struct defining the DLT to be used for this extcap. Typically the DLT is
/// defined together with the [`Interface`][crate::interface::Interface] and
/// passed into
/// [`InterfacesStep::list_interfaces`][crate::InterfacesStep::list_interfaces].
/// But you can also use this class standalone and print out the resulting
/// config using the [`print_sentence`][crate::PrintSentence::print_sentence]
/// method.
/// Print the configuration line suitable for use with `--extcap-dlts`.
///
/// ## Example
/// ```
/// use r_extcap::config::ExtcapFormatter;
/// use r_extcap::interface::{DataLink, Dlt};
///
/// let dlt = Dlt {
/// data_link_type: DataLink::ETHERNET,
/// name: "ETHERNET".into(),
/// display: "IEEE 802.3 Ethernet".into(),
/// };
/// assert_eq!(
/// ExtcapFormatter(&dlt).to_string(),
/// "dlt {number=1}{name=ETHERNET}{display=IEEE 802.3 Ethernet}\n",
/// );
/// ```