1
1
use std:: collections:: { HashMap , HashSet } ;
2
- use std:: io:: Stdout ;
3
2
use std:: net:: { IpAddr , Ipv4Addr } ;
4
3
use std:: time:: Duration ;
5
4
use std:: { fmt, vec} ;
@@ -45,6 +44,21 @@ impl fmt::Display for OutputFormat {
45
44
}
46
45
}
47
46
47
+ #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , ValueEnum , Debug ) ]
48
+ enum ProtocolArg {
49
+ ICMP ,
50
+ UDP ,
51
+ }
52
+
53
+ impl From < ProtocolArg > for caracat:: models:: L4 {
54
+ fn from ( protocol : ProtocolArg ) -> Self {
55
+ match protocol {
56
+ ProtocolArg :: UDP => caracat:: models:: L4 :: UDP ,
57
+ ProtocolArg :: ICMP => caracat:: models:: L4 :: ICMP ,
58
+ }
59
+ }
60
+ }
61
+
48
62
#[ derive( Parser , Debug ) ]
49
63
#[ command( author, version, about, long_about = None ) ]
50
64
struct Args {
@@ -92,6 +106,10 @@ struct Args {
92
106
#[ arg( long, default_value_t = 100 ) ]
93
107
probing_rate : u64 ,
94
108
109
+ /// Protocol to use (ICMP or UDP)
110
+ #[ arg( short, long, value_enum, default_value_t = ProtocolArg :: ICMP ) ]
111
+ protocol : ProtocolArg ,
112
+
95
113
/// Network interface to use
96
114
#[ arg( short, long) ]
97
115
interface : Option < String > ,
@@ -112,7 +130,7 @@ fn main() -> Result<()> {
112
130
let max_ttl = args. max_ttl ;
113
131
let src_port = args. src_port ;
114
132
let dst_port = args. dst_port ;
115
- let protocol = caracat :: models :: L4 :: ICMP ;
133
+ let protocol = args . protocol . into ( ) ;
116
134
let confidence = args. confidence ;
117
135
let max_round = args. max_round ;
118
136
let estimate_successsors = args. estimate_successors ;
@@ -264,7 +282,7 @@ fn main() -> Result<()> {
264
282
OutputFormat :: Atlas => {
265
283
debug ! ( "--- ATLAS output ---" ) ;
266
284
let stdout = std:: io:: stdout ( ) ;
267
- let mut atlas_writer: AtlasWriter < Stdout > = AtlasWriter :: new ( stdout) ;
285
+ let mut atlas_writer = AtlasWriter :: new ( stdout) ;
268
286
atlas_writer. write_traceroute ( & traceroute) ?;
269
287
}
270
288
OutputFormat :: Iris => {
0 commit comments