Tools: hv: Gather DHCP information
K. Y. Srinivasan [Wed, 5 Sep 2012 20:50:11 +0000 (13:50 -0700)]
Collect information on dhcp setting for the specified interface.
We invoke an external (Distro specific)  script to get this information.

Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

tools/hv/hv_kvp_daemon.c

index cfa23a1..6fb2c1c 100644 (file)
@@ -524,6 +524,9 @@ static void kvp_get_ipconfig_info(char *if_name,
                                 struct hv_kvp_ipaddr_value *buffer)
 {
        char cmd[512];
+       char dhcp_info[128];
+       char *p;
+       FILE *file;
 
        /*
         * Get the address of default gateway (ipv4).
@@ -572,6 +575,34 @@ static void kvp_get_ipconfig_info(char *if_name,
         */
        kvp_process_ipconfig_file(cmd, (char *)buffer->dns_addr,
                                (MAX_IP_ADDR_SIZE * 2), INET_ADDRSTRLEN, 0);
+
+       /*
+        * Gather the DHCP state.
+        * We will gather this state by invoking an external script.
+        * The parameter to the script is the interface name.
+        * Here is the expected output:
+        *
+        * Enabled: DHCP enabled.
+        */
+
+       sprintf(cmd, "%s %s", "hv_get_dhcp_info", if_name);
+
+       file = popen(cmd, "r");
+       if (file == NULL)
+               return;
+
+       p = fgets(dhcp_info, sizeof(dhcp_info), file);
+       if (p == NULL) {
+               pclose(file);
+               return;
+       }
+
+       if (!strncmp(p, "Enabled", 7))
+               buffer->dhcp_enabled = 1;
+       else
+               buffer->dhcp_enabled = 0;
+
+       pclose(file);
 }