Tools: hv: Gather subnet information
K. Y. Srinivasan [Fri, 17 Aug 2012 01:32:16 +0000 (18:32 -0700)]
Now, gather sub-net information for the specified interface.

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 13ae098..de1724c 100644 (file)
@@ -534,6 +534,7 @@ kvp_get_ip_address(int family, char *if_name, int op,
        struct ifaddrs *ifap;
        struct ifaddrs *curp;
        int offset = 0;
+       int sn_offset = 0;
        const char *str;
        int error = 0;
        char *buffer;
@@ -594,12 +595,38 @@ kvp_get_ip_address(int family, char *if_name, int op,
                         * Gather info other than the IP address.
                         * IP address info will be gathered later.
                         */
-                       if (curp->ifa_addr->sa_family == AF_INET)
+                       if (curp->ifa_addr->sa_family == AF_INET) {
                                ip_buffer->addr_family |= ADDR_FAMILY_IPV4;
-                       else
+                               /*
+                                * Get subnet info.
+                                */
+                               error = kvp_process_ip_address(
+                                                            curp->ifa_netmask,
+                                                            AF_INET,
+                                                            (char *)
+                                                            ip_buffer->sub_net,
+                                                            length,
+                                                            &sn_offset);
+                               if (error)
+                                       goto gather_ipaddr;
+                       } else {
                                ip_buffer->addr_family |= ADDR_FAMILY_IPV6;
+                               /*
+                                * Get subnet info.
+                                */
+                               error = kvp_process_ip_address(
+                                                            curp->ifa_netmask,
+                                                            AF_INET6,
+                                                            (char *)
+                                                            ip_buffer->sub_net,
+                                                            length,
+                                                            &sn_offset);
+                               if (error)
+                                       goto gather_ipaddr;
+                       }
                }
 
+gather_ipaddr:
                error = kvp_process_ip_address(curp->ifa_addr,
                                                curp->ifa_addr->sa_family,
                                                buffer,