From fbed730dac8e18179e4692d439c6f6cb86bd4e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 13 Oct 2024 21:32:09 +0800 Subject: [PATCH] Netif (Linux): don't use fseek Turns out that `fseek` generates two extra syscalls, which causes unnecessary overhead. --- src/common/netif/netif_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/netif/netif_linux.c b/src/common/netif/netif_linux.c index 5e1b818f5..71ec5ff4d 100644 --- a/src/common/netif/netif_linux.c +++ b/src/common/netif/netif_linux.c @@ -12,8 +12,8 @@ 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 #1336 - fseek(netRoute, 128, SEEK_SET); + // skip first line + 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)