fix set ipv4 netmask failed
Before `createIfAddr`, we accept the address is nullopt when set the
ipv4 netmask,
so, if the address is not null, check the address is `0.0.0.0`,
if null, use the `ifaddr->address`.
Tested:
1. Set netmask.
~# ipmitool lan set 1 netmask 255.255.255.0
2. Check the netmask.
~# ipmitool lan print 1 | grep -i sub
Subnet Mask : 255.255.255.0
Signed-off-by: Jian Zhang <zhangjian.3032@bytedance.com>
Change-Id: I7b5967cb8c00bc9a1507c04df06e7898478b079f
diff --git a/transporthandler.cpp b/transporthandler.cpp
index 61960d2..a533e8c 100644
--- a/transporthandler.cpp
+++ b/transporthandler.cpp
@@ -389,7 +389,8 @@
deleteObjectIfExists(bus, params.service, ifaddr->path);
}
- if (struct in_addr nullIPv4{0}; address.value().s_addr != nullIPv4.s_addr)
+ if (struct in_addr nullIPv4{0};
+ (address == std::nullopt || address.value().s_addr != nullIPv4.s_addr))
{
createIfAddr<AF_INET>(bus, params, address.value_or(ifaddr->address),
prefix.value_or(fallbackPrefix));