mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 21:37:13 +02:00
fixed looking up interface
This commit is contained in:
@ -53,6 +53,8 @@ class UdpRxSocket {
|
|||||||
hints.ai_protocol = 0;
|
hints.ai_protocol = 0;
|
||||||
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
|
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
|
||||||
struct addrinfo *res = 0;
|
struct addrinfo *res = 0;
|
||||||
|
|
||||||
|
std::cout << "HOSTNAME: " << hostname << '\n';
|
||||||
if (getaddrinfo(hostname, portname.c_str(), &hints, &res)) {
|
if (getaddrinfo(hostname, portname.c_str(), &hints, &res)) {
|
||||||
throw RuntimeError("Failed getaddinfo");
|
throw RuntimeError("Failed getaddinfo");
|
||||||
}
|
}
|
||||||
@ -106,15 +108,28 @@ class UdpRxSocket {
|
|||||||
|
|
||||||
// Not sure we keep this
|
// Not sure we keep this
|
||||||
bool ReceivePacket(char *dst) {
|
bool ReceivePacket(char *dst) {
|
||||||
|
|
||||||
ssize_t count = recvfrom(fd, buff, packet_size, 0, nullptr, nullptr);
|
ssize_t count = recvfrom(fd, buff, packet_size, 0, nullptr, nullptr);
|
||||||
return count == packet_size;
|
return count == packet_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only for backwards compatibility will be removed
|
// Only for backwards compatibility will be removed
|
||||||
ssize_t ReceiveDataOnly(char *dst) {
|
ssize_t ReceiveDataOnly(char *dst) {
|
||||||
return recvfrom(fd, dst, packet_size, 0, nullptr, nullptr);
|
// TODO! Clean up?
|
||||||
|
// which detector do have a header packet?
|
||||||
|
// logic should probably be in another place?
|
||||||
|
ssize_t r = 0;
|
||||||
|
r = recvfrom(fd, dst, packet_size, 0, nullptr, nullptr);
|
||||||
|
|
||||||
|
// if we read an eiger header pkg read again
|
||||||
|
if (r==40){
|
||||||
|
r = recvfrom(fd, dst, packet_size, 0, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ssize_t getBufferSize() const {
|
ssize_t getBufferSize() const {
|
||||||
uint64_t ret_size = 0;
|
uint64_t ret_size = 0;
|
||||||
socklen_t optlen = sizeof(uint64_t);
|
socklen_t optlen = sizeof(uint64_t);
|
||||||
|
@ -125,8 +125,7 @@ IpAddr InterfaceNameToIp(const std::string &ifn) {
|
|||||||
char host[NI_MAXHOST];
|
char host[NI_MAXHOST];
|
||||||
|
|
||||||
if (getifaddrs(&ifaddr) == -1) {
|
if (getifaddrs(&ifaddr) == -1) {
|
||||||
perror("getifaddrs");
|
return {};
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
|
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
|
||||||
@ -138,6 +137,10 @@ IpAddr InterfaceNameToIp(const std::string &ifn) {
|
|||||||
|
|
||||||
if ((strcmp(ifa->ifa_name, ifn.c_str()) == 0) &&
|
if ((strcmp(ifa->ifa_name, ifn.c_str()) == 0) &&
|
||||||
(ifa->ifa_addr->sa_family == AF_INET)) {
|
(ifa->ifa_addr->sa_family == AF_INET)) {
|
||||||
|
if (s != 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user