This commit is contained in:
Erik Fröjdh
2025-05-30 16:57:16 +02:00
parent e14d307a42
commit 5093472aa1
5 changed files with 36 additions and 31 deletions

View File

@ -29,7 +29,6 @@ target_link_libraries(slsDetectorObject
slsProjectOptions
slsSupportStatic
pthread
rt
PRIVATE
slsProjectWarnings
)
@ -98,9 +97,7 @@ if(SLS_USE_TEXTCLIENT)
add_executable(${val1} src/CmdApp.cpp)
target_link_libraries(${val1}
slsDetectorStatic
pthread
rt
slsDetectorStatic
)
SET_SOURCE_FILES_PROPERTIES( src/Caller.cpp PROPERTIES COMPILE_FLAGS "-Wno-unused-variable -Wno-unused-but-set-variable")

View File

@ -1203,7 +1203,7 @@ void Module::setDestinationUDPIP(const IpAddr ip) {
}
sendToDetector(F_SET_DEST_UDP_IP, ip, nullptr);
if (shm()->useReceiverFlag) {
MacAddr retval(0LU);
MacAddr retval{uint64_t(0)};
sendToReceiver(F_SET_RECEIVER_UDP_IP, ip, retval);
LOG(logINFO) << "Setting destination udp mac of Module " << moduleIndex
<< " to " << retval;
@ -1226,7 +1226,7 @@ void Module::setDestinationUDPIP2(const IpAddr ip) {
}
sendToDetector(F_SET_DEST_UDP_IP2, ip, nullptr);
if (shm()->useReceiverFlag) {
MacAddr retval(0LU);
MacAddr retval{uint64_t(0)};
sendToReceiver(F_SET_RECEIVER_UDP_IP2, ip, retval);
LOG(logINFO) << "Setting destination udp mac2 of Module " << moduleIndex
<< " to " << retval;

View File

@ -25,8 +25,12 @@
#include <unistd.h>
namespace sls {
#define SHM_DETECTOR_PREFIX "/slsDetectorPackage_detector_"
#ifdef __APPLE__
// On macOS SHM_NAME_MAX is 31 so we need the shortest possible prefix
#define SHM_DETECTOR_PREFIX "/sls_"
#else
#define SHM_DETECTOR_PREFIX "/slsDetectorPackage_detector_"
#endif
#define SHM_MODULE_PREFIX "_module_"
#define SHM_ENV_NAME "SLSDETNAME"
@ -203,6 +207,11 @@ template <typename T> class SharedMemory {
throw SharedMemoryError(msg);
}
#ifdef __APPLE__
// On macOS, fstat returns the allocated size and not the requested size.
// This means we can't check for size since we always get for example 16384 bytes.
return;
#endif
auto actual_size = static_cast<size_t>(sb.st_size);
auto expected_size = sizeof(T);
if (actual_size != expected_size) {

View File

@ -15,7 +15,7 @@
#include <netdb.h>
#include <sstream>
#include <sys/ioctl.h>
#include <sys/prctl.h>
// #include <sys/prctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
@ -178,30 +178,30 @@ IpAddr InterfaceNameToIp(const std::string &ifn) {
MacAddr InterfaceNameToMac(const std::string &inf) {
// TODO! Copied from genericSocket needs to be refactored!
struct ifreq ifr;
char mac[32];
const int mac_len = sizeof(mac);
memset(mac, 0, mac_len);
// struct ifreq ifr;
// char mac[32];
// const int mac_len = sizeof(mac);
// memset(mac, 0, mac_len);
int sock = socket(PF_INET, SOCK_STREAM, 0);
strncpy(ifr.ifr_name, inf.c_str(), sizeof(ifr.ifr_name) - 1);
ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
// int sock = socket(PF_INET, SOCK_STREAM, 0);
// strncpy(ifr.ifr_name, inf.c_str(), sizeof(ifr.ifr_name) - 1);
// ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
if (-1 == ioctl(sock, SIOCGIFHWADDR, &ifr)) {
perror("ioctl(SIOCGIFHWADDR) ");
return MacAddr{};
}
for (int j = 0, k = 0; j < 6; j++) {
k += snprintf(
mac + k, mac_len - k - 1, j ? ":%02X" : "%02X",
(int)(unsigned int)(unsigned char)ifr.ifr_hwaddr.sa_data[j]);
}
mac[mac_len - 1] = '\0';
// if (-1 == ioctl(sock, SIOCGIFHWADDR, &ifr)) {
// perror("ioctl(SIOCGIFHWADDR) ");
// return MacAddr{};
// }
// for (int j = 0, k = 0; j < 6; j++) {
// k += snprintf(
// mac + k, mac_len - k - 1, j ? ":%02X" : "%02X",
// (int)(unsigned int)(unsigned char)ifr.ifr_hwaddr.sa_data[j]);
// }
// mac[mac_len - 1] = '\0';
if (sock != 1) {
close(sock);
}
return MacAddr(mac);
// if (sock != 1) {
// close(sock);
// }
return MacAddr();
}
void validatePortNumber(uint16_t port) {

View File

@ -25,7 +25,6 @@ target_link_libraries(tests
slsProjectOptions
slsSupportStatic
pthread
rt
PRIVATE
slsProjectWarnings
)