Skip to content

Commit fc3f477

Browse files
committed
NetIO (Haiku): code cleanup
1 parent 1d2b6c0 commit fc3f477

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/detection/netio/netio_haiku.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
extern "C" {
22
#include "netio.h"
3-
43
#include "common/netif/netif.h"
5-
#include "util/mallocHelper.h"
64
}
75

86
#include <NetworkInterface.h>
@@ -15,27 +13,27 @@ const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options)
1513
BNetworkInterface interface;
1614
uint32 cookie = 0;
1715

18-
const char* defaultRouteIfName = ffNetifGetDefaultRouteIfName();
16+
uint32_t defaultRouteIfIndex = ffNetifGetDefaultRouteIfIndex();
1917

2018
while (roster.GetNextInterface(&cookie, interface) == B_OK)
2119
{
2220
if (!interface.Exists())
2321
continue;
2422

25-
if (options->defaultRouteOnly && strcmp(interface.Name(), defaultRouteIfName) != 0)
23+
bool defaultRoute = interface.Index() == defaultRouteIfIndex;
24+
if (options->defaultRouteOnly && !defaultRoute)
2625
continue;
2726

2827
if (options->namePrefix.length && strncmp(interface.Name(), options->namePrefix.chars, options->namePrefix.length) != 0)
2928
continue;
3029

31-
ifreq_stats stats;
32-
memset(&stats, 0, sizeof(stats));
33-
interface.GetStats(stats);
30+
ifreq_stats stats = {};
31+
if (interface.GetStats(stats) != B_OK) continue;
3432

3533
FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result);
3634
*counters = (FFNetIOResult) {
3735
.name = ffStrbufCreateS(interface.Name()),
38-
.defaultRoute = strcmp(interface.Name(), defaultRouteIfName) == 0,
36+
.defaultRoute = defaultRoute,
3937
.txBytes = stats.send.bytes,
4038
.rxBytes = stats.receive.bytes,
4139
.txPackets = stats.send.packets,

0 commit comments

Comments
 (0)