replace udpDestination struct with a class that accepts ipaddr

This commit is contained in:
2021-09-07 12:21:25 +02:00
parent 905b40c76c
commit 82c5bf15a6
11 changed files with 123 additions and 98 deletions

View File

@@ -69,6 +69,26 @@ std::string MacAddr::str() const { return to_hex(':'); }
std::string MacAddr::hex() const { return to_hex(); }
std::string UdpDestination::str() const {
std::ostringstream oss;
oss << '[' << std::endl
<< "entry " << entry_ << std::endl
<< "ip " << ip_ << std::endl
<< "mac " << mac_ << std::endl
<< "port " << port_ << std::endl;
if (port2_ != 0) {
oss << "port2 " << port2_ << std::endl;
}
if (ip2_ != 0) {
oss << "ip2 " << ip2_ << std::endl;
}
if (mac2_ != 0) {
oss << "mac2 " << mac2_ << std::endl;
}
oss << ']';
return oss.str();
}
std::ostream &operator<<(std::ostream &out, const IpAddr &addr) {
return out << addr.str();
}
@@ -77,6 +97,10 @@ std::ostream &operator<<(std::ostream &out, const MacAddr &addr) {
return out << addr.str();
}
std::ostream &operator<<(std::ostream &out, const UdpDestination &dest) {
return out << dest.str();
}
IpAddr HostnameToIp(const char *hostname) {
addrinfo hints;
addrinfo *result = nullptr;