0

I'd like to get the IP address of the standard gateway on BSD/OS X systems.

That's a simple question, however, I have enormous difficulties getting an answer.

This post: Getting gateway to use for a given ip in ANSI C already answered the question, but only for non-BSD/-OSX systems.

As it's difficult to create Raw sockets on BSD systems and there is no PF_NETLINK family, I don't know where or how to start.

The only thing I found out is that there is a family called PF_ROUTE, which seems to be the correct family for this purpose (/* Internal Routing Protocol */). I still don't know the corresponding protocol.

There's nothing I've really tried so far since I have no idea how to start.

j3141592653589793238
  • 1,810
  • 2
  • 16
  • 38
  • 1
    The BSD documentation for the programmatic interface to the kernel's routing table is in chapter [*route(4)*](https://man.openbsd.org/route.4). I've linked the OpenBSD version of those docs, which seems to be more complete and up to date than the most recent docs released by Apple. Basically, you open a socket of the appropriate type, and use it to communicate with the kernel about routing properties. If you're asking for details then your question is too broad, but you could consider studying the source for a BSD's `route` command. – John Bollinger Dec 11 '18 at 14:08
  • Looks good as a point to start with. Thanks. – j3141592653589793238 Dec 11 '18 at 14:16

0 Answers0