fix net_info

This commit is contained in:
Doug MacEachern 2005-07-11 23:54:39 +00:00
parent 6b238421e7
commit 77a51da4b6
1 changed files with 21 additions and 14 deletions

View File

@ -1609,35 +1609,43 @@ SIGAR_DECLARE(int) sigar_cpu_info_list_get(sigar_t *sigar,
SIGAR_DECLARE(int) sigar_net_info_get(sigar_t *sigar, SIGAR_DECLARE(int) sigar_net_info_get(sigar_t *sigar,
sigar_net_info_t *netinfo) sigar_net_info_t *netinfo)
{ {
FIXED_INFO info; FIXED_INFO *info;
ULONG len; ULONG len = 0;
IP_ADDR_STRING *ip; IP_ADDR_STRING *ip;
DWORD rc;
if (!sigar->get_net_params) { if (!sigar->get_net_params) {
return SIGAR_ENOTIMPL; return SIGAR_ENOTIMPL;
} }
SIGAR_ZERO(netinfo); SIGAR_ZERO(netinfo);
len = sizeof(info); rc = sigar->get_net_params(NULL, &len);
if (rc != ERROR_BUFFER_OVERFLOW) {
if (sigar->get_net_params(&info, &len) != ERROR_SUCCESS) { return rc;
return GetLastError();
} }
SIGAR_SSTRCPY(netinfo->host_name, info.HostName); info = malloc(len);
SIGAR_SSTRCPY(netinfo->domain_name, info.DomainName); rc = sigar->get_net_params(info, &len);
SIGAR_SSTRCPY(netinfo->primary_dns, if (rc != NO_ERROR) {
info.DnsServerList.IpAddress.String); free(info);
return rc;
}
if ((ip = info.DnsServerList.Next)) { SIGAR_SSTRCPY(netinfo->host_name, info->HostName);
SIGAR_SSTRCPY(netinfo->domain_name, info->DomainName);
SIGAR_SSTRCPY(netinfo->primary_dns,
info->DnsServerList.IpAddress.String);
if ((ip = info->DnsServerList.Next)) {
SIGAR_SSTRCPY(netinfo->secondary_dns, SIGAR_SSTRCPY(netinfo->secondary_dns,
ip->IpAddress.String); ip->IpAddress.String);
} }
free(info);
if (sigar->get_adapters_info) { if (sigar->get_adapters_info) {
PIP_ADAPTER_INFO buffer, info; PIP_ADAPTER_INFO buffer, info;
DWORD rc;
len = 0; len = 0;
rc = sigar->get_adapters_info(NULL, &len); rc = sigar->get_adapters_info(NULL, &len);
@ -1670,7 +1678,6 @@ SIGAR_DECLARE(int) sigar_net_info_get(sigar_t *sigar,
free(buffer); free(buffer);
} }
return SIGAR_OK; return SIGAR_OK;
} }