Move function from network manager to utility function

Function which fetches the interface address from the system.
Add some types to types.hpp

Change-Id: Ie2c02980a9fd7a0aaeafa22d93bc758b5c79fd04
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/network_manager.cpp b/network_manager.cpp
index ee88c3f..e1bfa41 100644
--- a/network_manager.cpp
+++ b/network_manager.cpp
@@ -1,5 +1,6 @@
 #include "config.h"
 #include "config_parser.hpp"
+#include "util.hpp"
 #include "network_manager.hpp"
 #include "network_config.hpp"
 #include "xyz/openbmc_project/Common/error.hpp"
@@ -133,95 +134,6 @@
     return;
 }
 
-IntfAddrMap Manager::getInterfaceAddrs() const
-{
-    IntfAddrMap intfMap{};
-    AddrList addrList{};
-    struct ifaddrs* ifaddr = nullptr;
-
-    // attempt to fill struct with ifaddrs
-    if (getifaddrs(&ifaddr) == -1)
-    {
-        auto error = errno;
-        log<level::ERR>("Error occurred during the getifaddrs call",
-                        entry("ERRNO=%s", strerror(error)));
-        elog<InternalFailure>();
-    }
-
-    details::AddrPtr ifaddrPtr(ifaddr);
-    ifaddr = nullptr;
-
-    std::string intfName{};
-
-    for (ifaddrs* ifa = ifaddrPtr.get(); ifa != nullptr; ifa = ifa->ifa_next)
-    {
-        // walk interfaces
-        if (ifa->ifa_addr == nullptr)
-        {
-            continue;
-        }
-
-        // get only INET interfaces not ipv6
-        if (ifa->ifa_addr->sa_family == AF_INET ||
-            ifa->ifa_addr->sa_family == AF_INET6)
-        {
-            // if loopback, or not running ignore
-            if ((ifa->ifa_flags & IFF_LOOPBACK) ||
-                !(ifa->ifa_flags & IFF_RUNNING))
-            {
-                continue;
-            }
-            // if the interface name is  not same as the  previous
-            // iteration then add the addr list into
-            // the map.
-            if (intfName != "" && intfName != std::string(ifa->ifa_name))
-            {
-                intfMap.emplace(intfName, addrList);
-                addrList.clear();
-            }
-            intfName = ifa->ifa_name;
-            AddrInfo info{};
-            char ip[INET6_ADDRSTRLEN] = { 0 };
-            char subnetMask[INET6_ADDRSTRLEN] = { 0 };
-
-            if (ifa->ifa_addr->sa_family == AF_INET)
-            {
-
-                inet_ntop(ifa->ifa_addr->sa_family,
-                          &(((struct sockaddr_in*)(ifa->ifa_addr))->sin_addr),
-                          ip,
-                          sizeof(ip));
-
-                inet_ntop(ifa->ifa_addr->sa_family,
-                          &(((struct sockaddr_in*)(ifa->ifa_netmask))->sin_addr),
-                          subnetMask,
-                          sizeof(subnetMask));
-
-            }
-            else
-            {
-                inet_ntop(ifa->ifa_addr->sa_family,
-                          &(((struct sockaddr_in6*)(ifa->ifa_addr))->sin6_addr),
-                          ip,
-                          sizeof(ip));
-
-                inet_ntop(ifa->ifa_addr->sa_family,
-                          &(((struct sockaddr_in6*)(ifa->ifa_netmask))->sin6_addr),
-                          subnetMask,
-                          sizeof(subnetMask));
-
-            }
-
-            info.addrType = ifa->ifa_addr->sa_family;
-            info.ipaddress = ip;
-            info.prefix = toCidr(info.addrType, std::string(subnetMask));
-            addrList.emplace_back(info);
-        }
-    }
-    intfMap.emplace(intfName, addrList);
-    return intfMap;
-}
-
 // Need to merge the below function with the code which writes the
 // config file during factory reset.
 //TODO openbmc/openbmc#1751