Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rtraceroute

A Rust reimplementation of the classic traceroute utility, written for a Computer Networking final project. It traces the route IP packets take across the network to a destination host by sending probes with progressively increasing TTL values and recording the ICMP Time Exceeded / Destination Unreachable replies it gets back from each hop.

The CLI surface is modeled after the standard Linux traceroute tool, so most of its short flags work the same way (-n, -q, -m, -f, -w, -p, etc.).

Status

  • UDP probing — implemented (this is the default mode).
  • ICMP probing (-I) — module stub; not yet implemented.
  • TCP SYN probing (-T) — module stub; not yet implemented.
  • UDP-Lite, raw IP, MTU discovery, AS-path lookup, gateway routing, per-probe send-wait, alternate source addresses — flags are parsed but the corresponding behavior is marked TODO in src/args.rs.

In practice, the working subset today is: UDP traceroute over IPv4 or IPv6 with configurable TTL range, query count, ports, packet size, and numeric vs. reverse-DNS output.

Project structure

rtraceroute/
├── Cargo.toml          # Crate manifest — declares clap, dns-lookup, and pnet
├── Cargo.lock
└── src/
    ├── main.rs         # Entry point: parses args, resolves the host,
    │                   #  drives the probe loop, formats hop output
    ├── args.rs         # clap-derived `Args` struct + `Config` it lowers into,
    │                   #  plus the `Method` / `ResolvedMethod` enums
    ├── dns.rs          # Forward (`resolve_hostname`) and reverse
    │                   #  (`reverse_resolve`) name resolution helpers
    └── probe/
        ├── mod.rs      # `Prober` trait, `ProbeResult`, `ProbeReply` types —
        │               #  the abstraction every transport implements
        ├── udp.rs      # `UdpProber` — the only fully implemented backend.
        │               #  Sends UDP packets, listens on a raw ICMP socket,
        │               #  and matches replies back to probes by inspecting
        │               #  the original UDP header echoed in the ICMP payload
        ├── icmp.rs     # `IcmpProber` placeholder (stub)
        └── tcp.rs      # `TcpProber` placeholder (stub)

How the pieces fit together

  1. main.rs parses command-line arguments via args::Args::parse() and lowers them into a Config struct.
  2. The destination hostname is resolved through dns::resolve_hostname, honoring -4 / -6 if the user forced an address family.
  3. A UdpProber is constructed against the resolved IP. It opens two raw sockets via pnet::transport: one for sending UDP and one for receiving ICMP error replies.
  4. The main loop walks TTL values from first_ttl up to max_ttl. For each TTL it calls prober.probe(...), which sends queries_per_hop UDP packets at that TTL and collects replies (or timeouts) for each.
  5. Each ProbeReply is formatted into a traceroute-style line and printed. The loop terminates when a reply comes back from the destination itself.

The Prober abstraction

probe/mod.rs defines:

pub trait Prober<T>: Sized {
    fn new(destination: IpAddr, opts: T) -> Result<Self>;
    fn probe(
        &mut self,
        force_src_port: Option<u16>,
        force_dst_port: Option<u16>,
        packet_len: u16,
        hops: u8,
        probes: u8,
    ) -> Result<Option<ProbeReply>>;
}

This is the seam where future ICMP and TCP backends will plug in. Each implementation is responsible for owning whatever sockets it needs and turning a (TTL, port, count) request into a ProbeReply containing one ProbeResult (Reply { ip, rtt } or Timeout) per probe sent.

Dependencies

  • clap 4.5 — derive-style CLI parsing.
  • pnet 0.35 — raw socket transport channels and packet construction (UDP, ICMP).
  • dns-lookup 3.0 — reverse DNS via getnameinfo.

See also

  • HOWTO.md for build and usage instructions.

About

A Rust reimplementation of the classic traceroute utility, written for a Computer Networking final project.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages