Add validation of IP address

With the current implementation, when configuring a wrong ip,
there no error thrown, instead that ip address is being configured.

POST -d '{"data":["10.10.10",162]}' https://${bmc}/xyz/openbmc_project/network/snmp/manager/action/Client
{
  "data": "/xyz/openbmc_project/network/snmp/manager/27",
  "message": "200 OK",
  "status": "ok"
}

This commit adds the validation of the ip address during
the configuration.

Tested-By:

Failure case:
POST -d '{"data":["10.10.10",162]}' https://${bmc}/xyz/openbmc_project/network/snmp/manager/action/Client
{
  "data": {
    "description": "xyz.openbmc_project.Common.Error.InvalidArgument"
  },
  "message": "Invalid argument was given.",
  "status": "error"
}

Few more cases that are tested:
"10.10.10.10.10"
"10.10.10.100000"
"10.10.10.bb"
"10.10.10.10.bb"
"10.10.bb.aa"

Success case:
POST -d '{"data":["10.10.10.101",162]}' https://${bmc}/xyz/openbmc_project/network/snmp/manager/action/Client
{
  "data": "/xyz/openbmc_project/network/snmp/manager/1",
  "message": "200 OK",
  "status": "ok"
}

Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
Change-Id: Ia08e6eeaa70e3ce45eb055cf927901b36bc4f845
diff --git a/snmp_conf_manager.cpp b/snmp_conf_manager.cpp
index 8e42507..f7edfe0 100644
--- a/snmp_conf_manager.cpp
+++ b/snmp_conf_manager.cpp
@@ -74,6 +74,15 @@
                               Argument::ARGUMENT_VALUE(address.c_str()));
     }
 
+    unsigned char buf[sizeof(struct in6_addr)];
+    int isValid = inet_pton(AF_INET, address.c_str(), buf);
+    if (isValid < 1)
+    {
+        log<level::ERR>("Invalid address");
+        elog<InvalidArgument>(Argument::ARGUMENT_NAME("ADDRESS"),
+                              Argument::ARGUMENT_VALUE(address.c_str()));
+    }
+
     for (const auto& val : clients)
     {
         if (val.second.get()->address() == address &&