net_info dhcp_server and default_gateway for windows

This commit is contained in:
Doug MacEachern 2005-07-11 23:24:00 +00:00
parent b3ca673da2
commit 6b238421e7
2 changed files with 63 additions and 0 deletions

View File

@ -74,6 +74,27 @@ typedef struct {
UINT EnableDns; UINT EnableDns;
} FIXED_INFO, *PFIXED_INFO; } FIXED_INFO, *PFIXED_INFO;
typedef struct _IP_ADAPTER_INFO {
struct _IP_ADAPTER_INFO* Next;
DWORD ComboIndex;
char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
UINT AddressLength;
BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];
DWORD Index;
UINT Type;
UINT DhcpEnabled;
PIP_ADDR_STRING CurrentIpAddress;
IP_ADDR_STRING IpAddressList;
IP_ADDR_STRING GatewayList;
IP_ADDR_STRING DhcpServer;
BOOL HaveWins;
IP_ADDR_STRING PrimaryWinsServer;
IP_ADDR_STRING SecondaryWinsServer;
time_t LeaseObtained;
time_t LeaseExpires;
} IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;
/* end iptypes.h */ /* end iptypes.h */
#include <iprtrmib.h> #include <iprtrmib.h>
@ -122,6 +143,8 @@ typedef DWORD (CALLBACK *LPGETUDPEXTABLE)(PMIB_UDPEXTABLE *, BOOL, HANDLE,
typedef DWORD (CALLBACK *LPNETPARAMS)(PFIXED_INFO, PULONG); typedef DWORD (CALLBACK *LPNETPARAMS)(PFIXED_INFO, PULONG);
typedef DWORD (CALLBACK *LPADAPTERSINFO)(PIP_ADAPTER_INFO, PULONG);
typedef DWORD (CALLBACK *LPSYSINFO)(DWORD, PVOID, ULONG, PULONG); typedef DWORD (CALLBACK *LPSYSINFO)(DWORD, PVOID, ULONG, PULONG);
typedef BOOL (CALLBACK *LPENUMMODULES)(HANDLE, HMODULE*, typedef BOOL (CALLBACK *LPENUMMODULES)(HANDLE, HMODULE*,
@ -171,6 +194,7 @@ struct sigar_t {
LPGETUDPTABLE get_udp_table; LPGETUDPTABLE get_udp_table;
LPGETUDPEXTABLE get_udpx_table; LPGETUDPEXTABLE get_udpx_table;
LPNETPARAMS get_net_params; LPNETPARAMS get_net_params;
LPADAPTERSINFO get_adapters_info;
LPSYSINFO get_ntsys_info; LPSYSINFO get_ntsys_info;
LPENUMMODULES enum_modules; LPENUMMODULES enum_modules;
LPGETMODULENAME get_module_name; LPGETMODULENAME get_module_name;

View File

@ -227,6 +227,8 @@ int sigar_os_open(sigar_t **sigar)
"UdpExTableFromStack"); "UdpExTableFromStack");
(*sigar)->get_net_params = (*sigar)->get_net_params =
(LPNETPARAMS)GetProcAddress(h, "GetNetworkParams"); (LPNETPARAMS)GetProcAddress(h, "GetNetworkParams");
(*sigar)->get_adapters_info =
(LPADAPTERSINFO)GetProcAddress(h, "GetAdaptersInfo");
(*sigar)->ip_handle = h; (*sigar)->ip_handle = h;
} }
else { else {
@ -1633,6 +1635,43 @@ SIGAR_DECLARE(int) sigar_net_info_get(sigar_t *sigar,
ip->IpAddress.String); ip->IpAddress.String);
} }
if (sigar->get_adapters_info) {
PIP_ADAPTER_INFO buffer, info;
DWORD rc;
len = 0;
rc = sigar->get_adapters_info(NULL, &len);
if (rc != ERROR_BUFFER_OVERFLOW) {
return rc;
}
buffer = malloc(len);
rc = sigar->get_adapters_info(buffer, &len);
if (rc != NO_ERROR) {
free(buffer);
return rc;
}
info = buffer;
while (info) {
/* should only be 1 */
if (info->GatewayList.IpAddress.String[0]) {
SIGAR_SSTRCPY(netinfo->default_gateway,
info->GatewayList.IpAddress.String);
}
if (info->DhcpEnabled) {
SIGAR_SSTRCPY(netinfo->dhcp_server,
info->DhcpServer.IpAddress.String);
}
info = info->Next;
}
free(buffer);
}
return SIGAR_OK; return SIGAR_OK;
} }