Tweaking based on feedback: default_interface gets a more appropriate name and

sigar_get_default_gateway now gathers both pieces of information.
This commit is contained in:
Matthew Kent 2009-08-13 23:38:45 -07:00
parent d9f37b39a4
commit 4fdcee3635
3 changed files with 9 additions and 34 deletions

View File

@ -936,7 +936,7 @@ use vars qw(%classes %cmds);
plat => '' plat => ''
}, },
{ {
name => 'default_interface', type => 'String', name => 'default_gateway_interface', type => 'String',
desc => '', desc => '',
plat => '' plat => ''
}, },

View File

@ -527,7 +527,7 @@ typedef struct {
typedef struct { typedef struct {
char default_gateway[SIGAR_INET6_ADDRSTRLEN]; char default_gateway[SIGAR_INET6_ADDRSTRLEN];
char default_interface[16]; char default_gateway_interface[16];
char host_name[SIGAR_MAXHOSTNAMELEN]; char host_name[SIGAR_MAXHOSTNAMELEN];
char domain_name[SIGAR_MAXDOMAINNAMELEN]; char domain_name[SIGAR_MAXDOMAINNAMELEN];
char primary_dns[SIGAR_INET6_ADDRSTRLEN]; char primary_dns[SIGAR_INET6_ADDRSTRLEN];

View File

@ -1236,7 +1236,7 @@ int sigar_who_list_get(sigar_t *sigar,
#endif #endif
static int sigar_get_default_gateway(sigar_t *sigar, static int sigar_get_default_gateway(sigar_t *sigar,
char *gateway) sigar_net_info_t *netinfo)
{ {
int status, i; int status, i;
sigar_net_route_list_t routelist; 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, sigar_net_address_to_string(sigar,
&routelist.data[i].gateway, &routelist.data[i].gateway,
gateway); netinfo->default_gateway);
SIGAR_STRNCPY(netinfo->default_gateway_interface,
routelist.data[i].ifname,
sizeof(netinfo->default_gateway_interface));
break; break;
} }
} }
@ -1262,33 +1266,6 @@ static int sigar_get_default_gateway(sigar_t *sigar,
return SIGAR_OK; 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; i<routelist.number; i++) {
if ((routelist.data[i].flags & SIGAR_RTF_GATEWAY) &&
(routelist.data[i].destination.addr.in == 0))
{
SIGAR_STRNCPY(interface, routelist.data[i].ifname, interfacelen);
break;
}
}
sigar_net_route_list_destroy(sigar, &routelist);
return SIGAR_OK;
}
int sigar_net_info_get(sigar_t *sigar, int sigar_net_info_get(sigar_t *sigar,
sigar_net_info_t *netinfo) sigar_net_info_t *netinfo)
{ {
@ -1343,9 +1320,7 @@ int sigar_net_info_get(sigar_t *sigar,
netinfo->domain_name[0] = '\0'; netinfo->domain_name[0] = '\0';
} }
sigar_get_default_gateway(sigar, netinfo->default_gateway); sigar_get_default_gateway(sigar, netinfo);
sigar_get_default_interface(sigar, netinfo->default_interface,
sizeof(netinfo->default_interface));
return SIGAR_OK; return SIGAR_OK;
} }