paullouisageneau / libplum

Multi-protocol Port Mapping client library
Mozilla Public License 2.0
40 stars 5 forks source link

Add net_get_default_gateway() support for Apple platforms #17

Closed past-due closed 4 months ago

past-due commented 5 months ago

Rewritten approach using sysctl {CTL_NET, PF_ROUTE, 0, family, NET_RT_FLAGS, RTF_GATEWAY} on Apple platforms, supporting IPv4 and IPv6.

Like the other implementations in this library, this returns as soon as it finds the first gateway. When testing on an IPv4-only network, this returned the desired result.

past-due commented 5 months ago

After consulting the documentation and system headers (and a bunch of testing), I've re-implemented the Apple platform version to use an adjusted approach, which is also more in line with the behavior of the other platform net_get_default_interface() implementations (and included directly in net.c).

past-due commented 4 months ago

Implemented your suggestions. Also added a check for link-local IPv6 gateway addresses, which helps filter some default macOS link-local results (that we do not want returned in any case).