From 3a914f2d276d0095dca3ec62f22bc6231c5c91d4 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 08:55:03 +0800 Subject: [PATCH] LocalIP (Linux): simplify ffNetifGetDefaultRouteImpl Fix #1336 --- src/common/netif/netif_linux.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/common/netif/netif_linux.c b/src/common/netif/netif_linux.c index f645b0a0b..5e1b818f5 100644 --- a/src/common/netif/netif_linux.c +++ b/src/common/netif/netif_linux.c @@ -12,12 +12,10 @@ 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, + // skip first line #1336 + fseek(netRoute, 128, SEEK_SET); + 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;