1#[cfg(test)]
2mod tcp_type_test;
3
4use std::fmt;
5
6#[derive(PartialEq, Eq, Debug, Copy, Clone)]
9pub enum TcpType {
10 Unspecified,
12 Active,
14 Passive,
16 SimultaneousOpen,
18}
19
20impl From<&str> for TcpType {
22 fn from(raw: &str) -> Self {
23 match raw {
24 "active" => Self::Active,
25 "passive" => Self::Passive,
26 "so" => Self::SimultaneousOpen,
27 _ => Self::Unspecified,
28 }
29 }
30}
31
32impl fmt::Display for TcpType {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 let s = match *self {
35 Self::Active => "active",
36 Self::Passive => "passive",
37 Self::SimultaneousOpen => "so",
38 Self::Unspecified => "unspecified",
39 };
40 write!(f, "{s}")
41 }
42}
43
44impl Default for TcpType {
45 fn default() -> Self {
46 Self::Unspecified
47 }
48}