From 4fdcee363593f33e6265ade292bc349c4161fec4 Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Thu, 13 Aug 2009 23:38:45 -0700 Subject: [PATCH] Tweaking based on feedback: default_interface gets a more appropriate name and sigar_get_default_gateway now gathers both pieces of information. --- bindings/SigarWrapper.pm | 2 +- include/sigar.h | 2 +- src/sigar.c | 39 +++++++-------------------------------- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/bindings/SigarWrapper.pm b/bindings/SigarWrapper.pm index 2150c7c1..f7ed8d17 100644 --- a/bindings/SigarWrapper.pm +++ b/bindings/SigarWrapper.pm @@ -936,7 +936,7 @@ use vars qw(%classes %cmds); plat => '' }, { - name => 'default_interface', type => 'String', + name => 'default_gateway_interface', type => 'String', desc => '', plat => '' }, diff --git a/include/sigar.h b/include/sigar.h index 31e4810f..e1192949 100644 --- a/include/sigar.h +++ b/include/sigar.h @@ -527,7 +527,7 @@ typedef struct { typedef struct { char default_gateway[SIGAR_INET6_ADDRSTRLEN]; - char default_interface[16]; + char default_gateway_interface[16]; char host_name[SIGAR_MAXHOSTNAMELEN]; char domain_name[SIGAR_MAXDOMAINNAMELEN]; char primary_dns[SIGAR_INET6_ADDRSTRLEN]; diff --git a/src/sigar.c b/src/sigar.c index 6914ea40..3ea3ea50 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -1236,7 +1236,7 @@ int sigar_who_list_get(sigar_t *sigar, #endif static int sigar_get_default_gateway(sigar_t *sigar, - char *gateway) + sigar_net_info_t *netinfo) { int status, i; sigar_net_route_list_t routelist; @@ -1252,7 +1252,11 @@ static int sigar_get_default_gateway(sigar_t *sigar, { sigar_net_address_to_string(sigar, &routelist.data[i].gateway, - gateway); + netinfo->default_gateway); + + SIGAR_STRNCPY(netinfo->default_gateway_interface, + routelist.data[i].ifname, + sizeof(netinfo->default_gateway_interface)); break; } } @@ -1262,33 +1266,6 @@ static int sigar_get_default_gateway(sigar_t *sigar, return SIGAR_OK; } -static int sigar_get_default_interface(sigar_t *sigar, - char *interface, int interfacelen) -{ - int status, i; - char *ifname; - sigar_net_route_list_t routelist; - - status = sigar_net_route_list_get(sigar, &routelist); - if (status != SIGAR_OK) { - return status; - } - - for (i=0; idomain_name[0] = '\0'; } - sigar_get_default_gateway(sigar, netinfo->default_gateway); - sigar_get_default_interface(sigar, netinfo->default_interface, - sizeof(netinfo->default_interface)); + sigar_get_default_gateway(sigar, netinfo); return SIGAR_OK; }