traceroute
traceroute reports responding IPv4 hops inside Ok; Linux and macOS use UDP probes with increasing TTL values and receive ICMP responses, while Windows uses ICMP Echo probes with increasing TTL values. Recoverable probe failures are returned as Err(NetError).
The result contains at most 30 hops. A hop that does not answer before the timeout is represented by "*". The function is available when supportsIcmp() is true. macOS requires permission to open a raw ICMP socket.
Signature
traceroute(address: string, timeoutMs?: u64): Promise<Result<string[], NetError>>tyrus
import { NetError, supportsIcmp, traceroute } from "tyrus:net";
async function trace(): Promise<void> {
if (supportsIcmp()) {
const result: Result<string[], NetError> = await traceroute("127.0.0.1", 1000);
match (result) {
Ok(hops) => { print(hops.length); } // 1
Err(error) => { printError(error.code); } // ERR_NET_TIMEOUT
}
}
}Error Handling
error
tyrus
import { NetError, traceroute } from "tyrus:net";
async function trace(): Promise<void> {
const result: Result<string[], NetError> = await traceroute("invalid host\n", 1000);
match (result) {
Ok(_) => {}
Err(error) => { printError(error.code); } // ERR_NET_RESOLVE
}
}Failures use ERR_NET_INVALID_ADDRESS, ERR_NET_PERMISSION, ERR_NET_TIMEOUT, or ERR_NET_UNSUPPORTED.
