Collect the default interface as part of net_info_get.

This commit is contained in:
Matthew Kent 2009-08-09 02:13:45 -07:00
parent c007175b21
commit d9f37b39a4
3 changed files with 35 additions and 0 deletions

View File

@ -935,6 +935,11 @@ use vars qw(%classes %cmds);
desc => '', desc => '',
plat => '' plat => ''
}, },
{
name => 'default_interface', type => 'String',
desc => '',
plat => ''
},
{ {
name => 'host_name', type => 'String', name => 'host_name', type => 'String',
desc => '', desc => '',

View File

@ -527,6 +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 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

@ -1262,6 +1262,33 @@ 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)
{ {
@ -1317,6 +1344,8 @@ int sigar_net_info_get(sigar_t *sigar,
} }
sigar_get_default_gateway(sigar, netinfo->default_gateway); sigar_get_default_gateway(sigar, netinfo->default_gateway);
sigar_get_default_interface(sigar, netinfo->default_interface,
sizeof(netinfo->default_interface));
return SIGAR_OK; return SIGAR_OK;
} }