0

I'm using RTNETLINK to identify the current gateway, so as to remember the firewall settings based on the Access Point I'm connected to.

WLAN connections give an ESSID that I can use for this purpose, but LAN connections don't, so I fallback to using the MAC address of the gateway as an identifier. But when I use this process on a phone's WWAN data connection, I can't retrieve any MAC address of the gateway.

I found out that in C I can use if_indextoname() on rtmsg->rta_dst->rta_oif to retrieve the outgoing interface name, like in this example, but I guess that there is no guarantee that it will conform to the interface type - it won't translate 1:1 to either WWAN, WLAN or LAN.

Is there a way to find this out in RTNETLINK ? If not, are there other kernel interfaces usable for this purpose ?

la Fleur
  • 426
  • 3
  • 11
  • What you can do is to map the interface name to the kernel driver controlling it (by looking at `/sys/class/net//device/driver` for example). From there, you can either recognize the driver name (e.g. `iwlwifi`) or walk the sysfs tree and check the hardware id of the underlying device controlled by the said driver. However, no method will work reliably in every conceivable situation, because the answer to your question is not well defined (think of it). :-) – oakad Dec 26 '21 at 14:59
  • Of course, the above comment implies a generic Linux system. Some platforms, such as Android (and other mobiles), do provide the information you're seeking via some sort of custom API. – oakad Dec 26 '21 at 15:04

0 Answers0