Fork netif_linux to netif_gnu.

netif_linux now uses linux specifics which do not work on GNU.
This commit is contained in:
Yelninei
2025-08-06 07:36:32 +00:00
committed by Carter Li
parent 71fbe04367
commit e968bca89d
2 changed files with 46 additions and 1 deletions
+1 -1
View File
@@ -1198,7 +1198,7 @@ elseif(GNU)
list(APPEND LIBFASTFETCH_SRC
src/common/dbus.c
src/common/io/io_unix.c
src/common/netif/netif_linux.c
src/common/netif/netif_gnu.c
src/common/networking/networking_linux.c
src/common/processing_linux.c
src/detection/battery/battery_nosupport.c
+45
View File
@@ -0,0 +1,45 @@
#include "netif.h"
#include "common/io/io.h"
#include <net/if.h>
#include <stdio.h>
#define FF_STR_INDIR(x) #x
#define FF_STR(x) FF_STR_INDIR(x)
static bool getDefaultRouteIPv4(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex, uint32_t* preferredSourceAddr)
{
if (preferredSourceAddr)
*preferredSourceAddr = 0;
// Based on netif_linux.c before 5e770dc8b019702ca458cc0cad46161ebec608a4
FILE* FF_AUTO_CLOSE_FILE netRoute = fopen("/proc/route", "r");
if (!netRoute) return false;
// skip first line
FF_UNUSED(fscanf(netRoute, "%*[^\n]\n"));
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;
*ifIndex = if_nametoindex(iface);
return true;
}
iface[0] = '\0';
return false;
}
static bool getDefaultRouteIPv6(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex, uint32_t* preferredSourceAddr)
{
// TODO ipv6
return false;
}
bool ffNetifGetDefaultRouteImpl(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex, uint32_t* preferredSourceAddr)
{
if (getDefaultRouteIPv4(iface, ifIndex, preferredSourceAddr))
return true;
return getDefaultRouteIPv6(iface, ifIndex, preferredSourceAddr);
}