SNMPTrap: SNMPTrap address support hostname

The address of snmptrap only supports IP(such as 192.168.1.1), not
support hostname(such as www.snmptrap.com). This commit enables the
snmptrap address to support hostname.

Tested:
1.Creat snmp trap client with hostname "snmp.prashanth.com" :
  busctl call xyz.openbmc_project.Network.SNMP
  /xyz/openbmc_project/network/snmp/manager
  xyz.openbmc_project.Network.Client.Create
  Client sq "snmp.prashanth.com" 162

  busctl introspect xyz.openbmc_project.Network.SNMP
  /xyz/openbmc_project/network/snmp/manager/1
  xyz.openbmc_project.Network.Client
  NAME     TYPE      SIGNATURE RESULT/VALUE
  .Address property  s         "snmp.prashanth.com"
  .Port    property  q         162

2.Create an error log, and then I received snmptrap on the computer
  with address "snmp.prashanth.com".

Signed-off-by: Chicago Duan <duanzhijia01@inspur.com>
Change-Id: I38e0963735036bf2bbaa102822f735345a3087d1
diff --git a/snmp_util.cpp b/snmp_util.cpp
index e09a32b..3d5dad9 100644
--- a/snmp_util.cpp
+++ b/snmp_util.cpp
@@ -72,6 +72,25 @@
         elog<InternalFailure>();
     }
 
+    unsigned char buf[sizeof(struct in6_addr)];
+    int isValid = inet_pton(AF_INET, ipaddress, buf);
+    if (isValid < 0)
+    {
+        log<level::ERR>("Invalid address",
+                        entry("ADDRESS=%s", address.c_str()));
+        elog<InternalFailure>();
+    }
+    if (isValid == 0)
+    {
+        int isValid6 = inet_pton(AF_INET6, ipaddress, buf);
+        if (isValid6 < 1)
+        {
+            log<level::ERR>("Invalid address",
+                            entry("ADDRESS=%s", address.c_str()));
+            elog<InternalFailure>();
+        }
+    }
+
     return ipaddress;
 }