From ad1c00ef7527f7690a368522398802930e21ea78 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 24 Jul 2005 01:34:27 +0000 Subject: [PATCH] who_list impl for win32 --- src/sigar.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/src/sigar.c b/src/sigar.c index 6da12417..61ec41e4 100644 --- a/src/sigar.c +++ b/src/sigar.c @@ -744,10 +744,76 @@ SIGAR_DECLARE(int) sigar_who_list_destroy(sigar_t *sigar, } #ifdef WIN32 + +#include + +static int sigar_who_net_sessions(sigar_t *sigar, + sigar_who_list_t *wholist) +{ + NET_API_STATUS status; + LPSESSION_INFO_10 buffer=NULL, ptr; + DWORD entries=0, total_entries=0; + DWORD resume_handle=0; + DWORD i; + + do { + status = NetSessionEnum(NULL, /* server name */ + NULL, /* client name */ + NULL, /* user name */ + 10, /* level */ + (LPBYTE*)&buffer, + MAX_PREFERRED_LENGTH, + &entries, + &total_entries, + &resume_handle); + + if ((status == NERR_Success) || (status == ERROR_MORE_DATA)) { + if ((ptr = buffer)) { + for (i=0; idata[wholist->number++]; + + who->time = (time() - ptr->sesi10_time); + SIGAR_W2A((LPCWSTR)ptr->sesi10_cname, + who->user, sizeof(who->user)); + SIGAR_W2A((LPCWSTR)ptr->sesi10_username, + who->host, sizeof(who->host)); + SIGAR_SSTRCPY(who->device, "network share"); + + ptr++; + } + } + } + else { + break; + } + + if (buffer) { + NetApiBufferFree(buffer); + } + } while (status == ERROR_MORE_DATA); + + if (buffer) { + NetApiBufferFree(buffer); + } + + return SIGAR_OK; +} + SIGAR_DECLARE(int) sigar_who_list_get(sigar_t *sigar, sigar_who_list_t *wholist) { - return SIGAR_ENOTIMPL; + sigar_who_list_create(wholist); + + sigar_who_net_sessions(sigar, wholist); + + return SIGAR_OK; } SIGAR_DECLARE(int) sigar_resource_limit_get(sigar_t *sigar,