DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::utilities Namespace Reference

Classes

class  Named
 A Named is a DAQ object (Queue or DAQModule) which has an instance name. More...
 
class  NamedObject
 Implements the Named interface. More...
 
class  ReusableThread
 
class  TimestampEstimatorBase
 TimestampEstimatorBase is the base class for timestamp-based logic in test systems where the current timestamp must be estimated somehow (eg, because there is no hardware timing system). More...
 
class  TimestampEstimatorSystem
 TimestampEstimatorSystem is an implementation of TimestampEstimatorBase that uses the system clock to give the current timestamp. More...
 
class  TimestampEstimatorTimeSync
 TimestampEstimatorTimeSync is an implementation of TimestampEstimatorBase that uses TimeSync messages from an input queue to estimate the current timestamp. More...
 
class  WorkerThread
 WorkerThread contains a thread which runs the do_work() function. More...
 
struct  ZmqUri
 

Enumerations

enum  { TLVL_TIME_SYNC_PROPERTIES = 17 , TLVL_TIME_SYNC_NOTES = 18 , TLVL_TIME_SYNC_NEW_ESTIMATE = 19 }
 

Functions

std::vector< std::string > get_hostname_ips (std::string hostname)
 
std::string get_interface_ip (std::string eth_device_name, bool throw_if_missing=false)
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
TLVL_TIME_SYNC_PROPERTIES 
TLVL_TIME_SYNC_NOTES 
TLVL_TIME_SYNC_NEW_ESTIMATE 

Definition at line 24 of file TimestampEstimatorTimeSync.hpp.

Function Documentation

◆ get_hostname_ips()

std::vector< std::string > dunedaq::utilities::get_hostname_ips ( std::string hostname)
inline

Definition at line 31 of file get_ips.hpp.

32{
33 std::vector<std::string> output;
34
35 TLOG_DEBUG(12) << "Name is " << hostname;
36
37 struct addrinfo* addrinfo = nullptr;
38 auto s = getaddrinfo(hostname.c_str(), nullptr, nullptr, &addrinfo);
39
40 if (s != 0) {
41 ers::error(NameNotFound(ERS_HERE, hostname, std::string(gai_strerror(s))));
42 return output;
43 }
44
45 for (auto rp = addrinfo; rp != nullptr; rp = rp->ai_next) {
46 char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; // NOLINT
47
48 // Let's skip all the IPv6 here
49 if (rp->ai_family == AF_INET6)
50 continue;
51
52 getnameinfo(rp->ai_addr, rp->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
53 auto ipaddr = std::string(hbuf);
54 bool duplicate = false;
55 for (auto& ip : output) {
56 if (ip == ipaddr) {
57 duplicate = true;
58 break;
59 }
60 }
61 if (!duplicate) {
62 TLOG_DEBUG(13) << "Found address " << ipaddr << " for hostname " << hostname;
63 output.push_back(ipaddr);
64 }
65 }
66
67 freeaddrinfo(addrinfo);
68
69 return output;
70}
#define ERS_HERE
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
NameNotFound
Definition Issues.hpp:24
void error(const Issue &issue)
Definition ers.hpp:81

◆ get_interface_ip()

std::string dunedaq::utilities::get_interface_ip ( std::string eth_device_name,
bool throw_if_missing = false )
inline

Definition at line 73 of file get_ips.hpp.

74{
75 std::string ipaddr = "0.0.0.0";
76 char hostname[NI_MAXHOST]; // NOLINT This is a char array for interfacing with the C networking API
77 if (gethostname(&hostname[0], NI_MAXHOST) == 0) {
78 ipaddr = std::string(hostname);
79 }
80 bool eth_found = false;
81 if (eth_device_name != "") {
82 // Work out which ip address goes with this device
83 struct ifaddrs* ifaddr = nullptr;
84 getifaddrs(&ifaddr);
85
86 for (auto ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next) {
87 if (ifa->ifa_addr == nullptr || std::string(ifa->ifa_name) != eth_device_name) {
88 continue;
89 }
90
91 char ip[NI_MAXHOST]; // NOLINT This is a char array for interfacing with the C networking API
92 int status = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), ip, NI_MAXHOST, nullptr, 0, NI_NUMERICHOST);
93 if (status != 0) {
94 continue;
95 }
96 eth_found = true;
97 ipaddr = std::string(ip);
98 break;
99 }
100 freeifaddrs(ifaddr);
101
102 if (!eth_found) {
103 auto err = InterfaceNotFound(ERS_HERE, eth_device_name);
104
105 if (throw_if_missing)
106 throw err;
107 else
108 ers::warning(err);
109 }
110 }
111
112 return ipaddr;
113}
void warning(const Issue &issue)
Definition ers.hpp:115