A high-performance, dependency-free traceroute implementation in pure C

Blazingly fast network diagnostics with minimal footprint

Terminal
$ sudo ./fastrace google.com
Tracing route to google.com (142.250.180.174)
Maximum hops: 30, Protocol: UDP
TTL │ IP Address         (RTT ms)    Hostname
────┼───────────────────────────────────────────
1   │ → 192.168.1.1     (  3.58 ms)
2   │ * * * (timeout)
3   │ * * * (timeout)
4   │ → 185.89.159.5    (  7.34 ms)
5   │ → 213.250.43.77   ( 38.62 ms) bsn-250-43-77.static.siol.net
6   │ → 193.77.107.46   ( 51.31 ms) bsn-77-107-46.static.siol.net
7   │ * * * (timeout)
8   │ → 142.251.235.172 ( 36.53 ms)
      └→ 142.251.235.174 ( 35.54 ms)

Overview

Fastrace is a blazingly fast traceroute utility designed for network diagnostics and performance analysis. It maps the route that packets take across an IP network from source to destination, providing detailed timing information and identifying potential bottlenecks or routing issues.

Zero Dependencies

Relies solely on standard C libraries and system calls

Maximum Performance

Optimized for speed with parallel probing and efficient packet handling

Low Memory Footprint

Minimizes memory allocation and operates with a small, fixed memory budget

Dual Socket Implementation

Uses UDP for probes and raw sockets for response capture

Visual Route Mapping

Displays network topology with a structured, tree-like representation

Security-Focused Design

Implements secure socket handling with comprehensive bounds checking

Technical Architecture

Dual Socket Architecture

Fastrace uses two socket types for maximum effectiveness:

  • UDP socket (SOCK_DGRAM) for sending probe packets
  • Raw ICMP socket (SOCK_RAW) for receiving router responses
send_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
recv_sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);

Probe Structure

Each probe is tracked using a specialized structure:

typedef struct {
    int ttl;                /* Time-to-Live value */
    int probe;              /* Probe sequence number */
    struct timeval sent_time; /* Timestamp when sent */
    int received;           /* Whether response was received */
    struct in_addr addr;    /* Address of responding hop */
    double rtt;             /* Round-trip time in ms */
    int port;              /* UDP port used for this probe */
} probe_t;

Concurrent Route Discovery

Fastrace implements a multi-TTL probing system that maintains multiple active TTL probes:

#define MAX_ACTIVE_TTLS 5   /* Maximum number of TTLs probed concurrently */

While standard traceroute sequentially probes one TTL at a time, Fastrace processes multiple TTLs concurrently, dramatically reducing total trace time.

Efficient Response Processing

The response processor uses select() with configurable timeouts to efficiently handle incoming packets without blocking:

int process_responses(int timeout_ms) {
    fd_set readfds;
    FD_ZERO(&readfds);
    FD_SET(recv_sock, &readfds);
    
    struct timeval timeout;
    timeout.tv_sec = timeout_ms / 1000;
    timeout.tv_usec = (timeout_ms % 1000) * 1000;
    
    int ret = select(recv_sock + 1, &readfds, NULL, NULL, &timeout);
    /* ... */
}

RTT calculations are performed with microsecond precision using the timersub macro:

struct timeval diff;
timersub(&recv_time, &probes[idx].sent_time, &diff);
double rtt = ((double)diff.tv_sec * 1000.0) + 
            ((double)diff.tv_usec / 1000.0);

Visual Path Representation

Fastrace provides a structured visual representation of network paths:

  • Tree-like format shows branching at load-balanced routes
  • Clear arrows indicate path progression
  • Distinct formatting for primary and alternative routes
7   │→ 72.14.209.224    ( 60.76 ms)
      └→ 72.14.223.184   ( 61.65 ms)
8   │→ 142.251.244.109  ( 59.57 ms)
      └→ 216.239.62.49   ( 71.36 ms)
      └→ 142.250.210.95  ( 70.25 ms)

Performance Benchmarks

Fastrace significantly outperforms standard traceroute in several key metrics:

Metric Standard Traceroute Fastrace Improvement
Total trace time (30 hops) ~15-20 seconds ~5-8 seconds 60-70% faster
Memory usage ~400-600 KB ~120-150 KB 70-75% less memory
CPU utilization 5-8% 2-3% 60% less CPU
Packet efficiency 1 TTL at a time Up to 5 TTLs concurrently 5x throughput
Response waiting Fixed timeouts Adaptive timeouts Better adaptation
Visual clarity Flat output Hierarchical tree view Improved readability
RTT accuracy Variable Highly accurate Matches standard tools
Security features Basic Comprehensive Enhanced protection

Usage

Using Makefile

The project includes a Makefile for easy compilation and installation:

# Standard optimized build
make

# Build with debugging symbols
make debug

# Build with maximum performance optimizations
make optimized

# Install to system (default: /usr/local/bin)
sudo make install

# Uninstall from system
sudo make uninstall

# Clean build artifacts
make clean

Manual Compilation

gcc -O3 -o fastrace fastrace.c

For maximum performance:

gcc -O3 -march=native -mtune=native -flto -o fastrace fastrace.c

Basic Usage

sudo ./fastrace <target>

Example:

sudo ./fastrace google.com

Technical Requirements

System Requirements

  • Operating System: Linux, macOS, or other Unix-like systems with raw socket support
  • Permissions: Root/sudo access required (raw sockets)
  • Compiler: GCC with C99 support or later
  • Architecture: x86, x86_64, ARM, or any platform with standard C library support

Header Dependencies

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/udp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>
#include <signal.h>
#include <stdarg.h>