mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-06 13:14:21 +01:00
Network: code refactor & bug fixes
This commit is contained in:
@@ -10,8 +10,8 @@ typedef struct FFNetworkResult
|
||||
FFstrbuf name;
|
||||
FFstrbuf type;
|
||||
FFstrbuf address;
|
||||
int32_t mtu;
|
||||
bool on;
|
||||
uint32_t mtu;
|
||||
bool up;
|
||||
} FFNetworkResult;
|
||||
|
||||
const char* ffDetectNetwork(FFinstance* instance, FFlist* result);
|
||||
|
||||
@@ -29,11 +29,11 @@ const char* ffDetectNetwork(FFinstance* instance, FFlist* result)
|
||||
ffStrbufInit(&item->name);
|
||||
ffStrbufInit(&item->address);
|
||||
item->mtu = 0;
|
||||
item->on = true;
|
||||
item->up = true;
|
||||
|
||||
ffCfStrGetString(SCNetworkInterfaceGetLocalizedDisplayName(ni), &item->name);
|
||||
ffCfStrGetString(SCNetworkInterfaceGetHardwareAddressString(ni), &item->address);
|
||||
SCNetworkInterfaceCopyMTU(ni, &item->mtu, nil, nil);
|
||||
SCNetworkInterfaceCopyMTU(ni, (int*) &item->mtu, nil, nil);
|
||||
}
|
||||
|
||||
if (result->length == 0)
|
||||
|
||||
@@ -92,14 +92,14 @@ const char* ffDetectNetwork(FFinstance* instance, FFlist* result)
|
||||
ffStrbufInitS(&item->name, i->if_name);
|
||||
ffStrbufInit(&item->address);
|
||||
item->mtu = 0;
|
||||
item->on = isUp;
|
||||
item->up = isUp;
|
||||
|
||||
ffStrbufSetF(&path, "/sys/class/net/%s/address", i->if_name);
|
||||
ffReadFileBuffer(path.chars, &item->address);
|
||||
|
||||
ffStrbufSetF(&path, "/sys/class/net/%s/mtu", i->if_name);
|
||||
if (ffReadFileBuffer(path.chars, &fileContent))
|
||||
item->mtu = (int32_t) ffStrbufToUInt16(&fileContent, 0);
|
||||
item->mtu = ffStrbufToUInt16(&fileContent, 0);
|
||||
}
|
||||
|
||||
if_freenameindex(infs);
|
||||
|
||||
@@ -44,8 +44,8 @@ const char* ffDetectNetwork(FFinstance* instance, FFlist* result)
|
||||
if (adapter->IfType == IF_TYPE_SOFTWARE_LOOPBACK)
|
||||
continue;
|
||||
|
||||
bool isOn = adapter->OperStatus == IfOperStatusUp;
|
||||
if (!isOn && !instance->config.networkAll)
|
||||
bool isUp = adapter->OperStatus == IfOperStatusUp;
|
||||
if (!isUp && !instance->config.networkAll)
|
||||
continue;
|
||||
|
||||
const char* strType = NULL;
|
||||
@@ -87,12 +87,12 @@ const char* ffDetectNetwork(FFinstance* instance, FFlist* result)
|
||||
ffStrbufInitS(&item->type, strType);
|
||||
ffStrbufInit(&item->name);
|
||||
ffStrbufInit(&item->address);
|
||||
item->mtu = (int32_t) adapter->Mtu;
|
||||
item->on = isOn;
|
||||
item->mtu = adapter->Mtu;
|
||||
item->up = isUp;
|
||||
|
||||
ffStrbufSetWS(&item->name, adapter->FriendlyName);
|
||||
for (ULONG i = 0; i < adapter->PhysicalAddressLength; i++)
|
||||
ffStrbufAppendF(&item->address, "%.2X-", (int) adapter->PhysicalAddress[i]);
|
||||
ffStrbufAppendF(&item->address, "%.2x-", (int) adapter->PhysicalAddress[i]);
|
||||
ffStrbufTrimRight(&item->address, '-');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user