Skip to content

Commit 1a2f4b4

Browse files
yelnineiCarterLi
authored andcommitted
Port netif_gnu to the new api.
1 parent e968bca commit 1a2f4b4

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/common/netif/netif_gnu.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,29 @@
77
#define FF_STR_INDIR(x) #x
88
#define FF_STR(x) FF_STR_INDIR(x)
99

10-
static bool getDefaultRouteIPv4(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex, uint32_t* preferredSourceAddr)
10+
bool ffNetifGetDefaultRouteImplV4(FFNetifDefaultRouteResult* result)
1111
{
12-
if (preferredSourceAddr)
13-
*preferredSourceAddr = 0;
1412
// Based on netif_linux.c before 5e770dc8b019702ca458cc0cad46161ebec608a4
1513
FILE* FF_AUTO_CLOSE_FILE netRoute = fopen("/proc/route", "r");
1614

1715
if (!netRoute) return false;
1816

1917
// skip first line
2018
FF_UNUSED(fscanf(netRoute, "%*[^\n]\n"));
21-
2219
unsigned long long destination; //, gateway, flags, refCount, use, metric, mask, mtu, ...
23-
while (fscanf(netRoute, "%" FF_STR(IF_NAMESIZE) "s%llx%*[^\n]", iface, &destination) == 2)
20+
while (fscanf(netRoute, "%" FF_STR(IF_NAMESIZE) "s%llx%*[^\n]", result->ifName, &destination) == 2)
2421
{
2522
if (destination != 0) continue;
26-
*ifIndex = if_nametoindex(iface);
23+
result->ifIndex = if_nametoindex(result->ifName);
24+
// TODO: Get the preferred source address
2725
return true;
2826
}
29-
iface[0] = '\0';
27+
result->ifName[0] = '0';
3028
return false;
3129
}
3230

33-
static bool getDefaultRouteIPv6(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex, uint32_t* preferredSourceAddr)
31+
bool ffNetifGetDefaultRouteImplV6(FFNetifDefaultRouteResult* result)
3432
{
35-
// TODO ipv6
33+
// TODO: AF_INET6
3634
return false;
3735
}
38-
39-
bool ffNetifGetDefaultRouteImpl(char iface[IF_NAMESIZE + 1], uint32_t* ifIndex, uint32_t* preferredSourceAddr)
40-
{
41-
if (getDefaultRouteIPv4(iface, ifIndex, preferredSourceAddr))
42-
return true;
43-
44-
return getDefaultRouteIPv6(iface, ifIndex, preferredSourceAddr);
45-
}

0 commit comments

Comments
 (0)