Skip to content

Commit

Permalink
can bus detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jvde-github committed Feb 22, 2025
1 parent c99a084 commit ea98ce2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Device/N2KsktCAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
#include "N2KsktCAN.h"
#include "N2KInterface.h"

#ifdef __linux__
#include <ifaddrs.h>
#include <vector>
#include <string>
#include <iostream>
#endif

#ifdef HASNMEA2000
namespace Device {

Expand Down Expand Up @@ -60,7 +67,24 @@ namespace Device {
}

void N2KSCAN::getDeviceList(std::vector<Description>& DeviceList) {
// DeviceList.push_back(Description(v, p, s, (uint64_t)i, Type::RTLSDR));
struct ifaddrs *ifaddr = nullptr, *ifa = nullptr;

if (getifaddrs(&ifaddr) == -1) {
return;
}

for (uint64_t i = 0, ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next, i++) {
if (ifa->ifa_addr == nullptr)
continue;

if (ifa->ifa_addr->sa_family == AF_CAN) {
DeviceList.push_back(Description(ifa->ifa_name, "", "", i, Type::N2KSCAN));
available_intefaces.push_back(ifa->ifa_name);
}
}

freeifaddrs(ifaddr);
}

}
Expand Down

0 comments on commit ea98ce2

Please sign in to comment.