fixed looking up interface

This commit is contained in:
Erik Frojdh 2020-02-06 08:51:34 +01:00
parent a5cdd687e6
commit 4dc14bf9d6
2 changed files with 21 additions and 3 deletions

View File

@ -53,6 +53,8 @@ class UdpRxSocket {
hints.ai_protocol = 0;
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
struct addrinfo *res = 0;
std::cout << "HOSTNAME: " << hostname << '\n';
if (getaddrinfo(hostname, portname.c_str(), &hints, &res)) {
throw RuntimeError("Failed getaddinfo");
}
@ -106,15 +108,28 @@ class UdpRxSocket {
// Not sure we keep this
bool ReceivePacket(char *dst) {
ssize_t count = recvfrom(fd, buff, packet_size, 0, nullptr, nullptr);
return count == packet_size;
}
// Only for backwards compatibility will be removed
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 {
uint64_t ret_size = 0;
socklen_t optlen = sizeof(uint64_t);

View File

@ -125,8 +125,7 @@ IpAddr InterfaceNameToIp(const std::string &ifn) {
char host[NI_MAXHOST];
if (getifaddrs(&ifaddr) == -1) {
perror("getifaddrs");
exit(EXIT_FAILURE);
return {};
}
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) &&
(ifa->ifa_addr->sa_family == AF_INET)) {
if (s != 0) {
return {};
}
break;
}
}