zmqip now uint

This commit is contained in:
Erik Frojdh 2019-06-06 18:17:04 +02:00
parent c86a1e7d48
commit 170aca0e1f
6 changed files with 90 additions and 176 deletions

View File

@ -16,6 +16,7 @@
class multiSlsDetector;
class ServerInterface;
#define SLS_SHMVERSION 0x190515
@ -176,10 +177,10 @@ struct sharedSlsDetector {
int rxReadFreq;
/** zmq tcp src ip address in client (only data) **/
char zmqip[MAX_STR_LENGTH];
sls::IpAddr zmqip;
/** zmq tcp src ip address in receiver (only data) **/
char rxZmqip[MAX_STR_LENGTH];
sls::IpAddr rxZmqip;
/** gap pixels enable */
int gappixels;

View File

@ -348,9 +348,9 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
(detId * ((shm()->myDetectorType == EIGER) ? 2 : 1));
shm()->rxUpstream = false;
shm()->rxReadFreq = 0;
memset(shm()->zmqip, 0, MAX_STR_LENGTH);
memset(shm()->rxZmqip, 0, MAX_STR_LENGTH);
shm()->gappixels = 0;
shm()->zmqip = 0u;
shm()->rxZmqip = 0u;
shm()->gappixels = 0u;
memset(shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH);
shm()->detectorControlAPIVersion = 0;
shm()->detectorStopAPIVersion = 0;
@ -413,7 +413,7 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
// update #nchans and databytes, as it depends on #samples, adcmask,
// readoutflags (ctb only)
updateTotalNumberOfChannels();
updateTotalNumberOfChannels();
}
int slsDetector::sendModule(sls_detector_module *myMod,
@ -474,8 +474,7 @@ int slsDetector::sendModule(sls_detector_module *myMod,
int slsDetector::receiveModule(sls_detector_module *myMod,
sls::ClientSocket &client) {
int ts = 0;
ts +=
client.Receive(&(myMod->serialnumber), sizeof(myMod->serialnumber));
ts += client.Receive(&(myMod->serialnumber), sizeof(myMod->serialnumber));
ts += client.Receive(&(myMod->nchan), sizeof(myMod->nchan));
ts += client.Receive(&(myMod->nchip), sizeof(myMod->nchip));
ts += client.Receive(&(myMod->ndac), sizeof(myMod->ndac));
@ -511,7 +510,7 @@ slsDetectorDefs::detectorType slsDetector::getDetectorTypeFromShm(int multi_id,
std::ostringstream ss;
ss << "Single shared memory (" << multi_id << "-" << detId
<< ":)version mismatch (expected 0x" << std::hex << SLS_SHMVERSION
<< " but got 0x" << shm()->shmversion << ")" << std::dec
<< " but got 0x" << shm()->shmversion << ")" << std::dec
<< ". Clear Shared memory to continue.";
shm.UnmapSharedMemory();
throw SharedMemoryError(ss.str());
@ -591,24 +590,26 @@ void slsDetector::updateTotalNumberOfChannels() {
++nachans;
}
}
adatabytes = nachans * (shm()->dynamicRange / 8) *
shm()->timerValue[ANALOG_SAMPLES];
FILE_LOG(logDEBUG1)
<< "#Analog Channels:" << nachans << " Databytes: " << adatabytes;
adatabytes = nachans * (shm()->dynamicRange / 8) *
shm()->timerValue[ANALOG_SAMPLES];
FILE_LOG(logDEBUG1) << "#Analog Channels:" << nachans
<< " Databytes: " << adatabytes;
}
// digital channels (ctb only, digital, analog/digital readout)
if (shm()->myDetectorType == CHIPTESTBOARD &&
(((shm()->roFlags & DIGITAL_ONLY) != 0) || ((shm()->roFlags & ANALOG_AND_DIGITAL) != 0))) {
(((shm()->roFlags & DIGITAL_ONLY) != 0) ||
((shm()->roFlags & ANALOG_AND_DIGITAL) != 0))) {
ndchans = 64;
ddatabytes = (sizeof(uint64_t) * shm()->timerValue[DIGITAL_SAMPLES]);
ddatabytes =
(sizeof(uint64_t) * shm()->timerValue[DIGITAL_SAMPLES]);
FILE_LOG(logDEBUG1) << "#Digital Channels:" << ndchans
<< " Databytes: " << ddatabytes;
}
shm()->nChans = nachans + ndchans;
shm()->dataBytes = adatabytes + ddatabytes;
FILE_LOG(logDEBUG1) << "# Total #Channels:" << shm()->nChans
<< " Databytes: " << shm()->dataBytes;
FILE_LOG(logDEBUG1) << "# Total #Channels:" << shm()->nChans
<< " Databytes: " << shm()->dataBytes;
}
}
@ -884,7 +885,7 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) {
if (i64 >= 0) {
shm()->timerValue[ANALOG_SAMPLES] = i64;
}
// digital samples
n += client.Receive(&i64, sizeof(i64));
if (i64 >= 0) {
@ -897,9 +898,9 @@ int slsDetector::updateDetectorNoWait(sls::ClientSocket &client) {
shm()->adcEnableMask = u32;
if (shm()->myDetectorType == MOENCH)
setAdditionalJsonParameter("adcmask", std::to_string(u32));
// update #nchans and databytes, as it depends on #samples, adcmask,
// readoutflags
// readoutflags
updateTotalNumberOfChannels();
}
@ -1472,7 +1473,7 @@ int slsDetector::configureMAC() {
ret = client.sendCommandThenRead(fnum, args, sizeof(args), retvals,
sizeof(retvals));
//TODO!(Erik) Send as int already from detector
// TODO!(Erik) Send as int already from detector
uint64_t detector_mac = 0;
uint32_t detector_ip = 0;
sscanf(retvals[0], "%lx", &detector_mac);
@ -1537,7 +1538,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) {
FILE_LOG(logDEBUG1) << getTimerType(index) << ": " << retval;
shm()->timerValue[index] = retval;
// update #nchans and databytes, as it depends on #samples, adcmask,
// readoutflags
// readoutflags
if (index == ANALOG_SAMPLES || index == DIGITAL_SAMPLES) {
updateTotalNumberOfChannels();
}
@ -1729,7 +1730,7 @@ int slsDetector::setReadOutFlags(readOutFlags flag) {
FILE_LOG(logDEBUG1) << "Readout flag: " << retval;
shm()->roFlags = retval;
// update #nchans and databytes, as it depends on #samples, adcmask,
// readoutflags
// readoutflags
if (shm()->myDetectorType == CHIPTESTBOARD) {
updateTotalNumberOfChannels();
}
@ -1904,7 +1905,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
<< (shm()->timerValue[SUBFRAME_ACQUISITION_TIME])
<< "\nsub dead time:" << (shm()->timerValue[SUBFRAME_DEADTIME])
<< "\nasamples:" << (shm()->timerValue[ANALOG_SAMPLES])
<< "\ndsamples:" << (shm()->timerValue[DIGITAL_SAMPLES])
<< "\ndsamples:" << (shm()->timerValue[DIGITAL_SAMPLES])
<< "\ndynamic range:" << shm()->dynamicRange
<< "\nflippeddatax:" << (shm()->flippedData[X])
<< "\nactivated: " << shm()->activated
@ -1919,8 +1920,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
<< "\nrx additional json header:" << shm()->rxAdditionalJsonHeader
<< "\nrx_datastream:" << enableDataStreamingFromReceiver(-1)
<< "\nrx_dbitlistsize:" << shm()->rxDbitList.size()
<< "\nrx_DbitOffset:" << shm()->rxDbitOffset
<< std::endl;
<< "\nrx_DbitOffset:" << shm()->rxDbitOffset << std::endl;
if (setDetectorType(shm()->myDetectorType) != GENERIC) {
sendMultiDetectorSize();
@ -1959,7 +1959,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
enableTenGigabitEthernet(shm()->tenGigaEnable);
setReadOutFlags(GET_READOUT_FLAGS);
break;
case CHIPTESTBOARD:
setTimer(ANALOG_SAMPLES, shm()->timerValue[ANALOG_SAMPLES]);
setTimer(DIGITAL_SAMPLES, shm()->timerValue[DIGITAL_SAMPLES]);
@ -1977,8 +1977,8 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
break;
case GOTTHARD:
sendROI(-1, nullptr);
break;
sendROI(-1, nullptr);
break;
default:
break;
@ -2141,25 +2141,17 @@ void slsDetector::setReceiverStreamingPort(int port) {
int slsDetector::getReceiverStreamingPort() { return shm()->rxZmqport; }
void slsDetector::setClientStreamingIP(const std::string &sourceIP) {
struct addrinfo *result;
// on failure to convert to a valid ip
if (sls::ConvertHostnameToInternetAddress(sourceIP.c_str(), &result) != 0) {
throw RuntimeError("Could not convert zmqip into a valid IP" +
sourceIP);
auto ip = HostnameToIp(sourceIP.c_str());
if (ip != 0) {
shm()->zmqip = ip;
} else {
throw sls::RuntimeError("Could not set zmqip");
}
// on success put IP as std::string into arg
memset(shm()->zmqip, 0, MAX_STR_LENGTH);
sls::ConvertInternetAddresstoIpString(result, shm()->zmqip, MAX_STR_LENGTH);
}
std::string slsDetector::getClientStreamingIP() {
return std::string(shm()->zmqip);
}
std::string slsDetector::getClientStreamingIP() { return shm()->zmqip.str(); }
void slsDetector::setReceiverStreamingIP(std::string sourceIP) {
char args[MAX_STR_LENGTH]{};
char retvals[MAX_STR_LENGTH]{};
// if empty, give rx_hostname
if (sourceIP.empty()) {
if (strcmp(shm()->rxHostname, "none") == 0) {
@ -2171,40 +2163,28 @@ void slsDetector::setReceiverStreamingIP(std::string sourceIP) {
FILE_LOG(logDEBUG1) << "Sending receiver streaming IP to receiver: "
<< sourceIP;
// verify the ip
{
struct addrinfo *result;
// on failure to convert to a valid ip
if (sls::ConvertHostnameToInternetAddress(sourceIP.c_str(), &result) !=
0) {
throw RuntimeError("Could not convert rx_zmqip into a valid IP" +
sourceIP);
}
// on success put IP as std::string into arg
sls::ConvertInternetAddresstoIpString(result, args, sizeof(args));
}
shm()->rxZmqip = HostnameToIp(sourceIP.c_str());
// set it anyway, else it is lost if rx_hostname is not set yet
memset(shm()->rxZmqip, 0, MAX_STR_LENGTH);
sls::strcpy_safe(shm()->rxZmqip, args);
// if zmqip is empty, update it
if (shm()->zmqip != 0u) {
sls::strcpy_safe(shm()->zmqip, args);
if (shm()->zmqip == 0) {
shm()->zmqip = shm()->rxZmqip;
}
FILE_LOG(logDEBUG1) << "Sending receiver streaming IP to receiver: "
<< args;
// send to receiver
if (shm()->rxOnlineFlag == ONLINE_FLAG) {
char retvals[MAX_STR_LENGTH]{};
char args[MAX_STR_LENGTH]{};
sls::strcpy_safe(args, shm()->rxZmqip.str()); //TODO send int
FILE_LOG(logDEBUG1)
<< "Sending receiver streaming IP to receiver: " << args;
sendToReceiver(F_RECEIVER_STREAMING_SRC_IP, args, retvals);
FILE_LOG(logDEBUG1) << "Receiver streaming port: " << retvals;
memset(shm()->rxZmqip, 0, MAX_STR_LENGTH);
sls::strcpy_safe(shm()->rxZmqip, retvals);
FILE_LOG(logDEBUG1) << "Receiver streaming ip: " << retvals;
shm()->rxZmqip = retvals;
}
}
std::string slsDetector::getReceiverStreamingIP() {
return std::string(shm()->rxZmqip);
return shm()->rxZmqip.str();
}
int slsDetector::setDetectorNetworkParameter(networkParameter index,
@ -2645,25 +2625,28 @@ int slsDetector::sendROI(int n, ROI roiLimits[]) {
void slsDetector::setADCEnableMask(uint32_t mask) {
uint32_t arg = mask;
FILE_LOG(logDEBUG1) << "Setting ADC Enable mask to 0x" << std::hex << arg << std::dec;
FILE_LOG(logDEBUG1) << "Setting ADC Enable mask to 0x" << std::hex << arg
<< std::dec;
if (shm()->onlineFlag == ONLINE_FLAG) {
sendToDetector(F_SET_ADC_ENABLE_MASK, &arg, sizeof(arg), nullptr, 0);
shm()->adcEnableMask = mask;
}
// update #nchans and databytes, as it depends on #samples, adcmask, readoutflags
// update #nchans and databytes, as it depends on #samples, adcmask,
// readoutflags
updateTotalNumberOfChannels();
// send to processor
if (shm()->myDetectorType == MOENCH)
setAdditionalJsonParameter("adcmask", std::to_string(shm()->adcEnableMask));
setAdditionalJsonParameter("adcmask",
std::to_string(shm()->adcEnableMask));
if (shm()->rxOnlineFlag == ONLINE_FLAG) {
int fnum = F_RECEIVER_SET_ADC_MASK;
int retval = -1;
mask = shm()->adcEnableMask;
FILE_LOG(logDEBUG1)
<< "Setting ADC Enable mask to 0x" << std:: hex << mask << std::dec << " in receiver";
FILE_LOG(logDEBUG1) << "Setting ADC Enable mask to 0x" << std::hex
<< mask << std::dec << " in receiver";
sendToReceiver(fnum, &mask, sizeof(mask), &retval, sizeof(retval));
}
}
@ -2672,15 +2655,18 @@ uint32_t slsDetector::getADCEnableMask() {
uint32_t retval = -1;
FILE_LOG(logDEBUG1) << "Getting ADC Enable mask";
if (shm()->onlineFlag == ONLINE_FLAG) {
sendToDetector(F_GET_ADC_ENABLE_MASK, nullptr, 0, &retval, sizeof(retval));
sendToDetector(F_GET_ADC_ENABLE_MASK, nullptr, 0, &retval,
sizeof(retval));
shm()->adcEnableMask = retval;
FILE_LOG(logDEBUG1) << "ADC Enable Mask: 0x" << std::hex << retval << std::dec;
FILE_LOG(logDEBUG1)
<< "ADC Enable Mask: 0x" << std::hex << retval << std::dec;
}
return shm()->adcEnableMask;
}
void slsDetector::setADCInvert(uint32_t value) {
FILE_LOG(logDEBUG1) << "Setting ADC Invert to 0x" << std::hex << value << std::dec;
FILE_LOG(logDEBUG1) << "Setting ADC Invert to 0x" << std::hex << value
<< std::dec;
if (shm()->onlineFlag == ONLINE_FLAG) {
sendToDetector(F_SET_ADC_INVERT, value, nullptr);
}
@ -2691,7 +2677,8 @@ uint32_t slsDetector::getADCInvert() {
FILE_LOG(logDEBUG1) << "Getting ADC Invert";
if (shm()->onlineFlag == ONLINE_FLAG) {
sendToDetector(F_GET_ADC_INVERT, nullptr, retval);
FILE_LOG(logDEBUG1) << "ADC Invert: 0x" << std::hex << retval << std::dec;
FILE_LOG(logDEBUG1)
<< "ADC Invert: 0x" << std::hex << retval << std::dec;
}
return retval;
}
@ -2722,9 +2709,7 @@ int slsDetector::setExternalSampling(int value) {
return retval;
}
int slsDetector::getExternalSampling() {
return setExternalSampling(-1);
}
int slsDetector::getExternalSampling() { return setExternalSampling(-1); }
void slsDetector::setReceiverDbitList(std::vector<int> list) {
FILE_LOG(logDEBUG1) << "Setting Receiver Dbit List";
@ -2734,7 +2719,8 @@ void slsDetector::setReceiverDbitList(std::vector<int> list) {
}
for (auto &it : list) {
if (it < 0 || it > 63) {
throw sls::RuntimeError("Dbit list value must be between 0 and 63\n");
throw sls::RuntimeError(
"Dbit list value must be between 0 and 63\n");
}
}
shm()->rxDbitList = list;
@ -2749,7 +2735,7 @@ std::vector<int> slsDetector::getReceiverDbitList() {
if (shm()->rxOnlineFlag == ONLINE_FLAG) {
sendToReceiver(F_GET_RECEIVER_DBIT_LIST, nullptr, retval);
shm()->rxDbitList = retval;
}
}
return shm()->rxDbitList;
}
@ -2757,7 +2743,8 @@ int slsDetector::setReceiverDbitOffset(int value) {
int retval = -1;
if (value >= 0)
shm()->rxDbitOffset = value;
FILE_LOG(logDEBUG1) << "Setting digital bit offset in receiver to " << value;
FILE_LOG(logDEBUG1) << "Setting digital bit offset in receiver to "
<< value;
if (shm()->rxOnlineFlag == ONLINE_FLAG) {
sendToReceiver(F_RECEIVER_DBIT_OFFSET, value, retval);
FILE_LOG(logDEBUG1) << "Receiver digital bit offset: " << retval;
@ -2765,9 +2752,7 @@ int slsDetector::setReceiverDbitOffset(int value) {
return shm()->rxDbitOffset;
}
int slsDetector::getReceiverDbitOffset() {
return shm()->rxDbitOffset;
}
int slsDetector::getReceiverDbitOffset() { return shm()->rxDbitOffset; }
int slsDetector::writeAdcRegister(uint32_t addr, uint32_t val) {
uint32_t args[]{addr, val};
@ -3375,7 +3360,7 @@ int slsDetector::updateCachedReceiverVariables() const {
// streaming source ip
n += receiver.Receive(cstring, sizeof(cstring));
sls::strcpy_safe(shm()->rxZmqip, cstring);
shm()->rxZmqip = cstring;
// additional json header
n += receiver.Receive(cstring, sizeof(cstring));
@ -3643,7 +3628,8 @@ bool slsDetector::getFileWrite() const { return shm()->rxFileWrite; }
bool slsDetector::setMasterFileWrite(bool value) {
int arg = static_cast<int>(value);
int retval = -1;
FILE_LOG(logDEBUG1) << "Sending enable master file write to receiver: " << arg;
FILE_LOG(logDEBUG1) << "Sending enable master file write to receiver: "
<< arg;
if (shm()->rxOnlineFlag == ONLINE_FLAG) {
sendToReceiver(F_ENABLE_RECEIVER_MASTER_FILE_WRITE, arg, retval);
FILE_LOG(logDEBUG1) << "Receiver master file write enable: " << retval;
@ -3652,7 +3638,9 @@ bool slsDetector::setMasterFileWrite(bool value) {
return getMasterFileWrite();
}
bool slsDetector::getMasterFileWrite() const { return shm()->rxMasterFileWrite; }
bool slsDetector::getMasterFileWrite() const {
return shm()->rxMasterFileWrite;
}
bool slsDetector::setFileOverWrite(bool value) {
int arg = static_cast<int>(value);

View File

@ -3,10 +3,13 @@
#include <cstddef>
#include <cstdint>
#include <netdb.h>
#include <string>
#include <numeric>
#include <string>
namespace sls {
/* Base class for TCP socket, this is used to send data between detector, client
and receiver. Specific protocols inherit from this class.*/
class DataSocket {
public:
DataSocket(int socketId);
@ -14,27 +17,28 @@ class DataSocket {
virtual ~DataSocket();
DataSocket &operator=(DataSocket &&move) noexcept;
void swap(DataSocket &other) noexcept;
//No copy since the class manage the underlying socket
DataSocket(const DataSocket &) = delete;
DataSocket &operator=(DataSocket const &) = delete;
int getSocketId() const { return socketId_; }
int Send(const void *buffer, size_t size);
template <typename T> int Send(T &&data) {
return Send(&data, sizeof(data));
}
// Trick to send all
// Variadic template to send all arguments
template <class... Args> int SendAll(Args &&... args) {
auto l = std::initializer_list<int>{Send(args)...};
auto sum = std::accumulate(begin(l), end(l), 0);
return sum;
}
int Receive(void *buffer, size_t size);
template <typename T> int Receive(T &arg) {
return Receive(&arg, sizeof(arg));
}
template <typename T> T Receive() {
T arg;
Receive(&arg, sizeof(arg));
@ -52,12 +56,4 @@ class DataSocket {
int socketId_ = -1;
};
int ConvertHostnameToInternetAddress(const char *const hostname,
struct ::addrinfo **res);
int ConvertInternetAddresstoIpString(struct ::addrinfo *res, char *ip,
const int ipsize);
struct ::sockaddr_in
ConvertHostnameToInternetAddress(const std::string &hostname);
}; // namespace sls

View File

@ -56,7 +56,7 @@ class MacAddr {
constexpr uint64_t uint64() const noexcept { return addr_; }
};
uint32_t HostnameToIp(const char *hostname);
IpAddr HostnameToIp(const char *hostname);
std::string IpToInterfaceName(const std::string& ip);
MacAddr InterfaceNameToMac(std::string inf);

View File

@ -27,7 +27,6 @@ DataSocket::~DataSocket() {
try {
close();
} catch (...) {
// pass
}
}
}
@ -73,7 +72,7 @@ int DataSocket::Send(const void *buffer, size_t size) {
break;
bytes_sent += this_send;
}
if (bytes_sent != data_size){
if (bytes_sent != data_size) {
std::ostringstream ss;
ss << "TCP socket sent " << bytes_sent << " bytes instead of "
<< data_size << " bytes";
@ -127,7 +126,6 @@ void DataSocket::close() {
throw SocketError("could not close socket");
}
socketId_ = -1;
} else {
throw std::runtime_error("Socket ERROR: close called on bad socket\n");
}
@ -138,73 +136,4 @@ void DataSocket::shutDownSocket() {
close();
}
struct sockaddr_in
ConvertHostnameToInternetAddress(const std::string &hostname) {
struct addrinfo hints, *result;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags |= AI_CANONNAME;
struct sockaddr_in serverAddr {};
if (getaddrinfo(hostname.c_str(), nullptr, &hints, &result) != 0) {
freeaddrinfo(result);
std::string msg = "ClientSocket cannot decode host:" + hostname + "\n";
throw SocketError(msg);
}
serverAddr.sin_family = AF_INET;
memcpy((char *)&serverAddr.sin_addr.s_addr,
&((struct sockaddr_in *)result->ai_addr)->sin_addr,
sizeof(in_addr_t));
freeaddrinfo(result);
return serverAddr;
}
int ConvertHostnameToInternetAddress(const char *const hostname,
struct ::addrinfo **res) {
// criteria in selecting socket address structures returned by res
struct ::addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
// get host info into res
int errcode = getaddrinfo(hostname, nullptr, &hints, res);
if (errcode != 0) {
FILE_LOG(logERROR) << "Could not convert hostname (" << hostname
<< ") to internet address (zmq):"
<< gai_strerror(errcode);
} else {
if (*res == nullptr) {
FILE_LOG(logERROR) << "Could not converthostname (" << hostname
<< ") to internet address (zmq):"
"gettaddrinfo returned null";
} else {
return 0;
}
}
FILE_LOG(logERROR) << "Could not convert hostname to internet address";
return 1;
};
/**
* Convert Internet Address structure pointer to ip string (char*)
* Clears the internet address structure as well
* @param res pointer to internet address structure
* @param ip pointer to char array to store result in
* @param ipsize size available in ip buffer
* @return 1 for fail, 0 for success
*/
// Do not make this static (for multi threading environment)
int ConvertInternetAddresstoIpString(struct ::addrinfo *res, char *ip,
const int ipsize) {
if (inet_ntop(res->ai_family,
&((struct sockaddr_in *)res->ai_addr)->sin_addr, ip,
ipsize) != nullptr) {
::freeaddrinfo(res);
return 0;
}
FILE_LOG(logERROR) << "Could not convert internet address to ip string";
return 1;
}
} // namespace sls

View File

@ -75,7 +75,7 @@ std::ostream &operator<<(std::ostream &out, const MacAddr &addr) {
return out << addr.str();
}
uint32_t HostnameToIp(const char *hostname) {
IpAddr HostnameToIp(const char *hostname) {
addrinfo hints;
addrinfo *result = nullptr;
memset(&hints, 0, sizeof(hints));
@ -87,7 +87,7 @@ uint32_t HostnameToIp(const char *hostname) {
}
uint32_t ip = ((sockaddr_in *)result->ai_addr)->sin_addr.s_addr;
freeaddrinfo(result);
return ip;
return IpAddr(ip);
}
std::string IpToInterfaceName(const std::string &ip) {