Get mac / IP address of a device from C

I'm new to OpenWrt and am porting a simple C application from a Linux-based RTOS.

One of the functions in the application simply retrieves and displays the MAC address and IP address of one of the local network devices and was using ioctl() to retrieve them (SIOCGIFHWADDR and SIOCGIFADDR).

On OpenWrt, the SIOCGIFHWADDR ioctl() is returning garbage data for ifr_hwaddr.sa_data while the SIOCGIFADDR ioctl() returns an error status when invoked.

Yet, if I use uci show network or ifconfig from the CLI, these do have valid data.

Is there a preferred / recommended manner from a C application on OpenWrt to obtain the current network configuration data / addreses?


I think the preferred way on Linux is to use rtnetlink today.

On OpenWrt you can also use the ubus api. To see the info that is available try ubus -v call network.interface.wan status and ubus -v call network.device status '{"name":"eth0"}'.