net autodetect
This commit is contained in:
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
static constexpr uint8_t lcd_contrast = 250;
|
static constexpr uint8_t lcd_contrast = 250;
|
||||||
static constexpr uint16_t refresh_interval_ms = 1000;
|
static constexpr uint16_t refresh_interval_ms = 1000;
|
||||||
static constexpr char netif[] = "enp10s0";
|
|
||||||
static constexpr char cpu_pcidev[] = "/sys/bus/pci/devices/0000:00:18.3";
|
static constexpr char cpu_pcidev[] = "/sys/bus/pci/devices/0000:00:18.3";
|
||||||
static constexpr char gpu_pcidev[] = "/sys/class/drm/renderD128/device";
|
static constexpr char gpu_pcidev[] = "/sys/class/drm/renderD128/device";
|
||||||
|
|
||||||
@@ -52,7 +51,7 @@ static void *sensors_thread(void *arg) {
|
|||||||
/* set up paths for the sensors */
|
/* set up paths for the sensors */
|
||||||
strcpy(sensors->home.mountpoint, "/home/drath");
|
strcpy(sensors->home.mountpoint, "/home/drath");
|
||||||
strcpy(sensors->gry.mountpoint, "/var/mnt/gry");
|
strcpy(sensors->gry.mountpoint, "/var/mnt/gry");
|
||||||
strcpy(sensors->net.device, netif);
|
// strcpy(sensors->net.device, netif);
|
||||||
cpu_detect(&sensors->cpu, cpu_pcidev);
|
cpu_detect(&sensors->cpu, cpu_pcidev);
|
||||||
gpu_detect(&sensors->gpu, gpu_pcidev);
|
gpu_detect(&sensors->gpu, gpu_pcidev);
|
||||||
sys_detect(&sensors->sys, "nct6775.656");
|
sys_detect(&sensors->sys, "nct6775.656");
|
||||||
|
|||||||
26
src/sys.c
26
src/sys.c
@@ -2,6 +2,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <net/if.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
@@ -91,7 +94,28 @@ void sys_get_network(struct network_t *network) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sys_netdev_detect(struct network_t *network) {
|
void sys_netdev_detect(struct network_t *network) {
|
||||||
applog(LOG_INF, "Opening netdev %s", network->device);
|
struct ifaddrs *ifaddr;
|
||||||
|
getifaddrs(&ifaddr);
|
||||||
|
char addr[INET_ADDRSTRLEN];
|
||||||
|
for (const struct ifaddrs *ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) {
|
||||||
|
// ugliest fucking if
|
||||||
|
if (!ifa->ifa_addr ||
|
||||||
|
ifa->ifa_addr->sa_family != AF_INET ||
|
||||||
|
!(ifa->ifa_flags & IFF_UP) ||
|
||||||
|
!(ifa->ifa_flags & IFF_RUNNING) ||
|
||||||
|
ifa->ifa_flags & IFF_LOOPBACK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const struct sockaddr_in *sin = (struct sockaddr_in *)ifa->ifa_addr;
|
||||||
|
inet_ntop(AF_INET, &sin->sin_addr, addr, sizeof(addr));
|
||||||
|
if (strncmp("10.0.1.", addr, 7) == 0) {
|
||||||
|
strcpy(network->device, ifa->ifa_name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
freeifaddrs(ifaddr);
|
||||||
|
|
||||||
|
applog(LOG_INF, "Detected %s with addr %s", network->device, addr);
|
||||||
static char path[128];
|
static char path[128];
|
||||||
snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/", network->device);
|
snprintf(path, sizeof(path), "/sys/class/net/%s/statistics/", network->device);
|
||||||
open_sensor(&network->f_rx, path, "rx_bytes", nullptr, 1, SENSOR_U64);
|
open_sensor(&network->f_rx, path, "rx_bytes", nullptr, 1, SENSOR_U64);
|
||||||
|
|||||||
Reference in New Issue
Block a user