ethernet_interface: Normalize IPs for nameservers
Change-Id: I44956d59aa7a93468c84715da16c39df50efb2d9
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 4398926..76bbe78 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -563,15 +563,19 @@
ServerList EthernetInterface::staticNameServers(ServerList value)
{
- for (const auto& nameserverip : value)
+ for (auto& ip : value)
{
- if (!isValidIP(nameserverip))
+ try
{
- log<level::ERR>("Not a valid IP address"),
- entry("ADDRESS=%s", nameserverip.c_str());
- elog<InvalidArgument>(
- Argument::ARGUMENT_NAME("StaticNameserver"),
- Argument::ARGUMENT_VALUE(nameserverip.c_str()));
+ ip = std::to_string(ToAddr<InAddrAny>{}(ip));
+ }
+ catch (const std::exception& e)
+ {
+ auto msg =
+ fmt::format("Not a valid IP address `{}`: {}", ip, e.what());
+ log<level::ERR>(msg.c_str()), entry("ADDRESS=%s", ip.c_str());
+ elog<InvalidArgument>(Argument::ARGUMENT_NAME("StaticNameserver"),
+ Argument::ARGUMENT_VALUE(ip.c_str()));
}
}
try