TTL, ICMP errors, and how a sandboxed app does this anyway
An IPv4 header carries an 8-bit TTL field (IPv6 calls it Hop Limit) whose only purpose is to stop packets circulating forever. Every router that forwards a packet decrements it by one; when it reaches zero the router discards the packet and returns an ICMP Time Exceeded message, type 11 code 0, sourced from the interface the packet arrived on.
Traceroute turns that failure mode into a measurement. It sends a probe with TTL 1, which dies at the first router and elicits an error naming it. Then TTL 2, then TTL 3, walking outward one hop at a time. Three probes per TTL produce the three timings on each line. How the target is recognised depends on the probe type: the BSD traceroute on macOS sends UDP datagrams to unlikely high ports starting at 33434 and treats an ICMP Port Unreachable (type 3, code 3) as the arrival signal, while Windows tracert sends ICMP Echo Requests and stops on an Echo Reply. That difference is not cosmetic. Firewalls treat UDP probes and ICMP Echo very differently, so the same destination legitimately produces different asterisk hops from a Mac and from a Windows machine: worth checking both before you blame a router.
Which brings us to the question everyone gets wrong, including an earlier version of this page: can a sandboxed app do this at all?
The reasoning that says no goes like this. /usr/sbin/traceroute on macOS is installed setuid root while /sbin/ping is not, so traceroute must need privileges ping does not; the App Sandbox grants no such privileges; therefore no traceroute in an App Store app. Every step sounds reasonable and the conclusion is still wrong, because the premise conflates the BSD traceroute's chosen probe type with traceroute as a technique. That binary probes with UDP datagrams and needs a raw socket to read the ICMP errors those provoke, hence setuid. Probe with ICMP Echo instead, and the replies arrive on the same datagram ICMP socket that ping already uses without privileges. setsockopt(IP_TTL) is not a privileged call.
So SSHive does not drive the system binary at all. It opens socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP), sets the TTL, sends three Echo Requests per hop, and reads whatever comes back: a Time Exceeded naming a router, an Echo Reply meaning the destination answered, or nothing within two seconds, which prints as an asterisk. That was measured under sandbox-exec with the app's real entitlements before any of it shipped, and it revealed one trap worth repeating: with com.apple.security.network.client alone, the probe goes out and the reply is refused with EPERM, a silent failure that looks exactly like a filtering network. com.apple.security.network.server is required as well. SSHive declares both, which is why the sandboxed App Store build traces at all instead of printing a column of asterisks.
iOS reaches the same place by the same route. Network.framework exposes TCP, UDP, QUIC and TLS and no ICMP at all, but it is not the only API available: the BSD socket layer underneath accepts the identical datagram ICMP socket, and Apple's own SimplePing sample has demonstrated it for years. The iPhone and iPad builds run the same thirty-hop, three-probe loop as the Mac.
Know the limits before you lean on it. The hop ceiling is fixed at 30, there are no protocol, port or probe-count switches, and there is no ASN or geolocation enrichment. Because the probes are ICMP Echo rather than UDP, a firewall that permits one and drops the other can produce a different asterisk pattern than /usr/sbin/traceroute would; neither result is wrong, and comparing the two is occasionally how you find the firewall.