/*
This program being compiled in MS VC6.0 as console Win32 application gets and show from working NV list of hosts, their states, writes, reads then deletes test metavariable, then
switches to mode of the waiting NV events, showing event codes, parameters and times. Used API functions: NVGetHostA, NVGetMetaVarA, NVSetMetaVarA,
NVSetEventHandlerProc, NVGetNetViewStatus.
(с)Killer{R}, 2004
*/
// nvcall.cpp : Defines the entry point for the console application.
//
#pragma pack(1)
#include "stdafx.h"
#include "windows.h"
#include "nvplugn.h"
#include "malloc.h"
typedef DWORD (WINAPI *NVGetHostx)(void *Reserved, NVHOST *nvh,DWORD flags);
typedef DWORD (WINAPI *NVGetMetaVarx)(void *Reserved, DWORD HostID,char *VarName, char *DataBuff,DWORD *BuffSize);
typedef DWORD (WINAPI *NVSetMetaVarx)(void *Reserved, DWORD HostID,char *VarName, char *DataBuff,DWORD BuffSize);
typedef DWORD (WINAPI *NVGetNetViewStatusx)(void *Reserved);
typedef DWORD (WINAPI *NVSetEventHandlerProcx)(void *proc);
NVGetHostx NVGetHost;
NVGetMetaVarx NVGetMetaVar;
NVSetMetaVarx NVSetMetaVar;
NVGetNetViewStatusx NVGetNetViewStatus;
NVSetEventHandlerProcx NVSetEventHandlerProc;
int stopped=0;
LRESULT CALLBACK eventproc(DWORD msg, DWORD wp, DWORD lp, DWORD tm)
{
printf("Event=%u WP=%u LP=%u TIME=%u\n",msg,wp,lp,tm);
if(msg==WM_QUIT)
{
printf("NetView stopped\n");
stopped=1;
}
return 1;
}
int main(int argc, char* argv[])
{
HINSTANCE lib=LoadLibrary("nvapi.dll");
if(!lib){printf("Can't load NVAPI.DLL\n");return -1;};
NVGetHost=(NVGetHostx)GetProcAddress(lib,"NVGetHostA");
NVGetMetaVar=(NVGetMetaVarx)GetProcAddress(lib,"NVGetMetaVarA");
NVSetMetaVar=(NVSetMetaVarx)GetProcAddress(lib,"NVSetMetaVarA");
NVGetNetViewStatus=(NVGetNetViewStatusx)GetProcAddress(lib,"NVGetNetViewStatus");
NVSetEventHandlerProc=(NVSetEventHandlerProcx)GetProcAddress(lib,"NVSetEventHandlerProc");
NVSetEventHandlerProc(&eventproc);
DWORD ret=NVGetNetViewStatus(0);
DWORD ver=HIWORD(ret);
DWORD verh=(ver>>8)&0xff;
DWORD verl=(ver)&0xff;
bool IsFullAccess=false;
switch(LOWORD(ret))
{
case 0:printf("NetView is not accessible\n");return -1;break;
case 1:printf("NetView v%u.%u in read-only mode\n",verh,verl);break;
case 2:printf("NetView v%u.%u in full access mode\n",verh,verl);IsFullAccess=true;break;
}
NVHOST hst; ZeroMemory(&hst,sizeof(hst));
do
{
hst.id=hst.nextid;hst.nextid=0;
NVGetHost(0,&hst,0);
if(hst.id)
{
char buff[1024];sprintf(buff+1,"%s\x09%s",hst.hostname,hst.hostip);
char varbuf[256];
ZeroMemory(varbuf,256);DWORD bufsz=255;
NVGetMetaVar(0,hst.id,"ison",varbuf,&bufsz);
buff[0]='?';
if(!strcmp(varbuf,"off"))buff[0]='-';
if(!strcmp(varbuf,"on"))buff[0]='+';
ZeroMemory(varbuf,256);bufsz=255;
NVGetMetaVar(0,hst.id,"ctime",varbuf,&bufsz);
strcat(buff,"\x09");strcat(buff,varbuf);
if(IsFullAccess)
{
NVSetMetaVar(0,hst.id,"mytestvar","TeSt",4);
ZeroMemory(varbuf,256);bufsz=255;
NVGetMetaVar(0,hst.id,"mytestvar",varbuf,&bufsz);
strcat(buff,"\x09");strcat(buff,varbuf);
NVSetMetaVar(0,hst.id,"mytestvar",0,0);
}
strcat(buff,"\n");
printf(buff);
}
}while(hst.nextid);
printf("Enumeration completed. Waiting for NetView events. Press Ctrl+C for exit.\n");
while(!stopped)Sleep(300);
return 0;
}
Top
|