VOL-2854: Add command line option to specify interface name in openolt on which gRPC server will run
          - OLT management interface or inband interface can be given as command line input and gRPC
            server will listen on given interface's IP address
          - If no interface name given gRPC server will listen on "0.0.0.0:9191"

Change-Id: I506fabf7ae81bf4d4ed8f6199107801daff62941
diff --git a/agent/src/core_utils.cc b/agent/src/core_utils.cc
index 32de09d..6570c2f 100644
--- a/agent/src/core_utils.cc
+++ b/agent/src/core_utils.cc
@@ -1267,3 +1267,28 @@
     return Status::OK;
 }
 
+std::string get_ip_address(const char* nw_intf){
+    std::string ipAddress = "0.0.0.0";
+    struct ifaddrs *interfaces = NULL;
+    struct ifaddrs *temp_addr = NULL;
+    int success = 0;
+   /* retrieve the current interfaces - returns 0 on success */
+    success = getifaddrs(&interfaces);
+    if (success == 0) {
+        /* Loop through linked list of interfaces */
+        temp_addr = interfaces;
+        while(temp_addr != NULL) {
+            if(temp_addr->ifa_addr->sa_family == AF_INET) {
+                /* Check if interface given present in OLT, if yes return its IP Address */
+                if(strcmp(temp_addr->ifa_name, nw_intf) == 0){
+                    ipAddress=inet_ntoa(((struct sockaddr_in*)temp_addr->ifa_addr)->sin_addr);
+                    break;
+                }
+            }
+            temp_addr = temp_addr->ifa_next;
+        }
+    }
+    /* Free memory */
+    freeifaddrs(interfaces);
+    return ipAddress;
+}