Hi i'm a C++ Noob,

i'm trying to write a c++ function to listen for snmp traffic and send back some variables to the source.

i'm not 100% sure of what i'm doing :o i'm including Wsnmp.h and also linking to Wsnmp32.lib from within visual c++ however it doesn't recognise SnmpSetPort and also the Listen function.

any help you can give me would be fantastic

thank you very much

Martin

-------------------------------


HSNMP_SESSION hSession;
HSNMP_ENTITY hDst;
HSNMP_CONTEXT hContext;
HSNMP_VBL hVbl;
HSNMP_PDU hPdu, hPduRecv;
SNMPAPI_CALLBACK cB;
SNMPAPI_STATUS lPort;
smiOCTETS dContext;
smiINT32  j;
smiUINT32 lStat;


smiUINT32 sysUpTime[]          = {1,3,6,1,2,1,1,3,0};
smiUINT32 snmpTrapOid[]        = {1,3,6,1,6,3,1,1,4,1,0};
smiUINT32 trapValue[]          = {1,3,6,1,6,3,1,1,5,3};
smiUINT32 snmpTrapEnterprise[] = {1,3,6,1,6,3,1,1,4,3,0};
smiUINT32 enterpriseValue[]    = {1,3,6,1,4,1,1057};
smiUINT32 acecObject[]         = {1,3,6,1,4,1,1057,1,0};


smiOID dSysUpTimeName   = {9, sysUpTime};
smiOID dTrapName        = {11, snmpTrapOid};
smiOID dEnterpriseName  = {11, snmpTrapEnterprise};
smiOID dAcecName        = {9, acecObject};


smiVALUE valSysUpTime;


lStat = SnmpStartup (&lStat, &lStat, &lStat, &lStat, &lStat);
hSession = SnmpCreateSession (NULL, 0, cB, NULL);
lStat = SnmpSetTranslateMode (SNMPAPI_UNTRANSLATED_V1);
hDst = SnmpStrToEntity (hSession, "15.145.151.45");


lPort = SnmpSetPort (hDst, 161);


//lStat = SnmpListen (hDst, SNMPAPI_ON);
//hPduRecv = SnmpGetPduData(hSession, SNMP_PDU_GETNEXT, NULL, SNMP_ERROR_NOERROR, NULL, NULL);


//hContext = SnmpStrToContext (hSession, &dContext);
//hVbl = SnmpCreateVbl (hSession, NULL, NULL);


//valSysUpTime.syntax = SNMP_SYNTAX_TIMETICKS;
//valSysUpTime.value.uNumber = GetTickCount() / 10;
//lStat = SnmpSetVb (hVbl, 0, &dSysUpTimeName, &valSysUpTime);


//hPdu = SnmpCreatePdu (hSession, SNMP_PDU_TRAP, 1, 0, 0, hVbl);


//lStat = SnmpSetPduData (hPdu, NULL,&j, NULL, NULL, NULL);


//lStat = SnmpRecvMsg(hSession, , , );


//lStat = SnmpSendMsg (hSession, NULL, hDst, hContext, hPdu);

Make sure that you are using the winsnmp.h file and library that has the correct function definitions. SnmpSetPort and SnmpListen are in v2.0 of the file. The version that ships with VC++ 6.0 is the older version without these functions (i believe).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.