Skip to content

Commit a8596a5

Browse files
committed
upd: add protocol arg
1 parent c1aa32d commit a8596a5

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ caracat = { git = "https://github.com/maxmouchet/caracat", branch = "main" }
1111
chrono = "0.4.38"
1212
clap = { version = "4.5.16", features = ["derive"] }
1313
env_logger = "0.11.5"
14-
# caracat = "1.0.0"
1514
ip_network = "0.4.1"
1615
itertools = "0.12.0"
1716
log = "0.4.21"

src/algorithms/diamond_miner.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ mod types;
44

55
use caracat::models::{Probe, Reply, L4};
66
use itertools::Itertools;
7-
use log::{debug, warn};
8-
// use log::debug;
7+
use log::debug;
8+
// use log::{debug, warn};
99
pub use sequential_mapper::*;
1010

1111
use std::collections::{HashMap, HashSet};
@@ -125,6 +125,8 @@ impl DiamondMiner {
125125
.map(|&node| (node, node_replies(&self.replies(), node, ttl)))
126126
.collect();
127127

128+
debug!("TTL {}: Link_dist: {:?}", ttl, link_dist);
129+
128130
let total: usize = link_dist.values().sum();
129131

130132
let link_dist: HashMap<IpAddr, f64> = if total > 0 {

src/main.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::collections::{HashMap, HashSet};
2-
use std::io::Stdout;
32
use std::net::{IpAddr, Ipv4Addr};
43
use std::time::Duration;
54
use std::{fmt, vec};
@@ -45,6 +44,21 @@ impl fmt::Display for OutputFormat {
4544
}
4645
}
4746

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+
4862
#[derive(Parser, Debug)]
4963
#[command(author, version, about, long_about = None)]
5064
struct Args {
@@ -92,6 +106,10 @@ struct Args {
92106
#[arg(long, default_value_t = 100)]
93107
probing_rate: u64,
94108

109+
/// Protocol to use (ICMP or UDP)
110+
#[arg(short, long, value_enum, default_value_t = ProtocolArg::ICMP)]
111+
protocol: ProtocolArg,
112+
95113
/// Network interface to use
96114
#[arg(short, long)]
97115
interface: Option<String>,
@@ -112,7 +130,7 @@ fn main() -> Result<()> {
112130
let max_ttl = args.max_ttl;
113131
let src_port = args.src_port;
114132
let dst_port = args.dst_port;
115-
let protocol = caracat::models::L4::ICMP;
133+
let protocol = args.protocol.into();
116134
let confidence = args.confidence;
117135
let max_round = args.max_round;
118136
let estimate_successsors = args.estimate_successors;
@@ -264,7 +282,7 @@ fn main() -> Result<()> {
264282
OutputFormat::Atlas => {
265283
debug!("--- ATLAS output ---");
266284
let stdout = std::io::stdout();
267-
let mut atlas_writer: AtlasWriter<Stdout> = AtlasWriter::new(stdout);
285+
let mut atlas_writer = AtlasWriter::new(stdout);
268286
atlas_writer.write_traceroute(&traceroute)?;
269287
}
270288
OutputFormat::Iris => {

0 commit comments

Comments
 (0)