Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/common/netif/netif_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@

#define FF_STR_INDIR(x) #x
#define FF_STR(x) FF_STR_INDIR(x)
// /proc/net/route has a fixed 128 chars line size, +1 for the NUL
#define NET_ROUTE_LINE_SIZE 129

bool ffNetifGetDefaultRouteImpl(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex)
{
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,
char skippedLine[NET_ROUTE_LINE_SIZE];
if (!fgets(skippedLine, NET_ROUTE_LINE_SIZE, netRoute)) return false;

unsigned long long destination; //, gateway, flags, refCount, use, metric, mask, mtu,
while (fscanf(netRoute, "%" FF_STR(IF_NAMESIZE) "s%llx%*[^\n]", iface, &destination) == 2)
{
if (destination != 0) continue;
Expand Down
Loading