Files
fastfetch/src/common/impl/netif_gnu.c
T

35 lines
962 B
C
Raw Normal View History

2026-01-06 09:48:38 +08:00
#include "common/netif.h"
#include "common/io.h"
2026-06-13 08:25:59 +08:00
#include "common/strutil.h"
2025-08-06 07:36:32 +00:00
#include <net/if.h>
#include <stdio.h>
2026-03-29 09:28:49 +08:00
bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result) {
2026-07-25 18:27:52 +08:00
FF_AUTO_CLOSE_FILE FILE* netRoute = fopen("/proc/route", "r");
2025-08-06 07:36:32 +00:00
2026-03-29 09:28:49 +08:00
if (!netRoute) {
return false;
}
2025-08-06 07:36:32 +00:00
// skip first line
FF_UNUSED(fscanf(netRoute, "%*[^\n]\n"));
unsigned long long destination; //, gateway, flags, refCount, use, metric, mask, mtu, ...
2026-03-29 09:28:49 +08:00
while (fscanf(netRoute, "%" FF_STR(IF_NAMESIZE) "s%llx%*[^\n]", result->ifName, &destination) == 2) {
if (destination != 0) {
continue;
}
2025-08-07 09:17:32 +00:00
result->ifIndex = if_nametoindex(result->ifName);
2025-08-24 19:09:51 +08:00
// TODO: Get the preferred source address
2025-08-06 07:36:32 +00:00
return true;
}
2026-04-28 00:48:09 +08:00
result->ifName[0] = '\0';
2025-08-06 07:36:32 +00:00
return false;
}
2026-03-29 09:28:49 +08:00
bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result) {
2025-08-07 09:17:32 +00:00
// TODO: AF_INET6
2025-08-25 09:25:25 +08:00
FF_UNUSED(result);
2025-08-06 07:36:32 +00:00
return false;
}