1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include "StdAfx.h"
#include "snmp_pdu.h"
#using <mscorlib.dll>
#define WINAPI __stdcall
snmp_pdu::snmp_pdu(LPSTR lpAgentAddress1,LPSTR lpAgentCommunity1){
lpAgentAddress=(LPSTR)SNMP_malloc(strlen(lpAgentAddress1));
strcpy(lpAgentAddress,lpAgentAddress1);
lpAgentCommunity1=(LPSTR)SNMP_malloc(strlen(lpAgentCommunity1)); strcpy(lpAgentCommunity,lpAgentCommunity1);
ntimeout=NULL;
nretries=NULL;
//ntimeout=WINAPI::SnmpGetTimeout(lpAgentAddress,NULL,NULL);
//nretries=WINAPI::SnmpGetRetry(lpAgentAddress,NULL,NULL);
variableBindings.list=NULL;
variableBindings.len=0;
}
LPSNMP_MGR_SESSION snmp_pdu::ouvrir_session()
{
LPSNMP_MGR_SESSION session;
if((session==WINAPI::SnmpMgrOpen(lpAgentAddress,lpAgentCommunity,ntimeout,nretries)==NULL))return NULL;
return session;
}
snmp_pdu::obtenir_oid(char *string)
{
AsnObjectIdentifier reqObject;
if(!WINAPI::SnmpMgrStrToOid(string,&reqObject))return 1;
else{variableBindings.len++;
if((variableBindings.list==(RFC1157VarBind *)SNMP_realloc(variableBindings.list,sizeof(RFC1157VarBind) * variableBindings.len)==NULL))return 1;
variableBindings.list[variableBindings.len-1].name=reqObject;variableBindings.list[variableBindings.len-1].value.asnType=ASN_NULL;
}
return 0;
}
snmp_pdu::~snmp_pdu()
{
delete(lpAgentAddress);
delete(lpAgentCommunity);
delete(&variableBindings);
} |