2023-09-26 16:26:15 +08:00
|
|
|
#include "netif.h"
|
|
|
|
|
#include "common/io/io.h"
|
|
|
|
|
|
2023-09-26 21:49:01 +08:00
|
|
|
#include <net/if.h>
|
2023-09-26 16:26:15 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2023-09-26 21:49:01 +08:00
|
|
|
#define FF_STR_INDIR(x) #x
|
|
|
|
|
#define FF_STR(x) FF_STR_INDIR(x)
|
|
|
|
|
|
|
|
|
|
bool ffNetifGetDefaultRouteImpl(char iface[IF_NAMESIZE + 1])
|
2023-09-26 16:26:15 +08:00
|
|
|
{
|
|
|
|
|
FILE* FF_AUTO_CLOSE_FILE netRoute = fopen("/proc/net/route", "r");
|
|
|
|
|
if (!netRoute) return false;
|
|
|
|
|
|
|
|
|
|
// skip first line
|
|
|
|
|
flockfile(netRoute);
|
|
|
|
|
while (getc_unlocked(netRoute) != '\n');
|
|
|
|
|
funlockfile(netRoute);
|
|
|
|
|
unsigned long long destination; //, gateway, flags, refCount, use, metric, mask, mtu,
|
|
|
|
|
|
2023-09-26 21:49:01 +08:00
|
|
|
while (fscanf(netRoute, "%" FF_STR(IF_NAMESIZE) "s%llx%*[^\n]", iface, &destination) == 2)
|
2023-09-26 16:26:15 +08:00
|
|
|
{
|
|
|
|
|
if (destination != 0) continue;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|