/ R. Matthew Emerson / blog

Determining the default route

February 6, 2007

A subscriber on cocoa-dev@lists.apple.com was asking whether there was some way to programmatically determine the default route.

The cheap and sleazy way would be to read the output of netstat, but that’s not very aesthetically appealing.

Here is some sample code, derived from the source for netstat, which will find and print the IPv4 default route.