Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 324392
b: refs/heads/master
c: 4a52c4a
h: refs/heads/master
v: v3
  • Loading branch information
K. Y. Srinivasan authored and Greg Kroah-Hartman committed Aug 17, 2012
1 parent aac0c22 commit 7876109
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6a60a6a8ea97795a288469c21262522894a1e6db
refs/heads/master: 4a52c4af48a2a35282ddc4dcf2df83486d636754
68 changes: 68 additions & 0 deletions trunk/tools/hv/hv_kvp_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,68 @@ void kvp_get_os_info(void)
return;
}

static void kvp_process_ipconfig_file(char *cmd,
char *config_buf, int len,
int element_size, int offset)
{
char buf[256];
char *p;
char *x;
FILE *file;

/*
* First execute the command.
*/
file = popen(cmd, "r");
if (file == NULL)
return;

if (offset == 0)
memset(config_buf, 0, len);
while ((p = fgets(buf, sizeof(buf), file)) != NULL) {
if ((len - strlen(config_buf)) < (element_size + 1))
break;

x = strchr(p, '\n');
*x = '\0';
strcat(config_buf, p);
strcat(config_buf, ";");
}
pclose(file);
}

static void kvp_get_ipconfig_info(char *if_name,
struct hv_kvp_ipaddr_value *buffer)
{
char cmd[512];

/*
* Get the address of default gateway (ipv4).
*/
sprintf(cmd, "%s %s", "ip route show dev", if_name);
strcat(cmd, " | awk '/default/ {print $3 }'");

/*
* Execute the command to gather gateway info.
*/
kvp_process_ipconfig_file(cmd, (char *)buffer->gate_way,
(MAX_GATEWAY_SIZE * 2), INET_ADDRSTRLEN, 0);

/*
* Get the address of default gateway (ipv6).
*/
sprintf(cmd, "%s %s", "ip -f inet6 route show dev", if_name);
strcat(cmd, " | awk '/default/ {print $3 }'");

/*
* Execute the command to gather gateway info (ipv6).
*/
kvp_process_ipconfig_file(cmd, (char *)buffer->gate_way,
(MAX_GATEWAY_SIZE * 2), INET6_ADDRSTRLEN, 1);

}


static unsigned int hweight32(unsigned int *w)
{
unsigned int res = *w - ((*w >> 1) & 0x55555555);
Expand Down Expand Up @@ -650,6 +712,12 @@ kvp_get_ip_address(int family, char *if_name, int op,
strcat((char *)ip_buffer->sub_net, ";");
sn_offset += strlen(sn_str) + 1;
}

/*
* Collect other ip related configuration info.
*/

kvp_get_ipconfig_info(if_name, ip_buffer);
}

gather_ipaddr:
Expand Down

0 comments on commit 7876109

Please sign in to comment.