Response title
This is preview!
Click on Join Now to Sign Up
U_CHAR *GetSysDescr(INT32 *varValLen, U_CHAR *status)
{
DEBUGMSG1("\n\t@@@@@ Inside GetSysDescr() @@@@@\n");
CHECK_FOR_NULL(gv_sysDescr);
SnmpPdu *pdu;
SnmpPdu *rcvdPdu;
Node *nodePtr;
VarBind *varBindPtr;
Vector *varBindVect;
OID varName[] = {1, 3, 6, 1, 2, 1, 1, 1,0};
INT32 varNameLen = 9;
//CHAR status;
/* Incase of GET, GETNEXT, GETBULK request use the below declaration */
U_CHAR *value = NULL;
/* Incase of SET request use the below declaration */
/* U_CHAR *value = "Chennai"; */
DEBUGMSG1("\n\t@@@@@ Inside ManagerExample() @@@@@\n");
varBindVect = (Vector *) __Calloc(1, __Sizeof(Vector) );
if (varBindVect == NULL)
{
DEBUGMSG1("Unable to allocate memory\n");
return;
}
InitVector(varBindVect, NULL);
varBindPtr = CreateAVarBind(varName, varNameLen, ASN_OCTET_STR, (U_CHAR *) value, __Strlen(value));
if (varBindPtr == NULL)
{
ERRMSG1("Error while creating Varbind for agent location in AGENT-SAMPLE-MIB\n");
FreeVector(varBindVect);
return;
}
nodePtr = (Node *) __Calloc(1, sizeof(Node));
nodePtr->refPtr = varBindPtr;
/* Add the created varbind in the pdu */
AddElement(varBindVect, nodePtr);
if (varBindVect == NULL)
{
DEBUGMSG1("Error while creating varbind vector!!!\n");
return;
}
/* Incase of GET request use the below line to create the snmp Pdu */
pdu = CreateSnmpPdu(SNMP_VERSION_1, "public", SNMP_MSG_GET, 1, 0, 0, varBindVect);
/* Incase of GET-NEXT request use the below line to create the snmp Pdu */
/* Pdu = CreateSnmpPdu(SNMP_VERSION_1, "public", SNMP_MSG_GETNEXT, 1, 0, 0, varBindVect); */
/*
* Incase of GET-BULK request use the below line to create the snmp Pdu.
* -----------------------------------
* Error status can be used for Non-Repeaters and error index is used for Max-Repititions
*/
/* Pdu = CreateSnmpPdu(SNMP_VERSION_2c, "public", SNMP_MSG_GETBULK, 1, 0, 3, varBindVect); */
/* Incase of SET request use the below line to create the snmp Pdu */
/* pdu = CreateSnmpPdu(SNMP_VERSION_1, "public", SNMP_MSG_SET, 1, 0, 0, varBindVect); */
if (pdu == NULL)
{
ERRMSG1("Unable to create the SnmpPdu!!!\n");
return;
}
rcvdPdu = SendAndReceiveSnmpPdu(pdu, "127.0.0.1", 9001, &status);
__Strcpy(gv_sysDescr, rcvdPdu);
FreeSnmpPduResources(pdu);
if (rcvdPdu != NULL)
{
FreeSnmpPdu(rcvdPdu);
}
/* Please provide your code to instrument "sysDescr" here */
*varValLen = __Strlen((CHAR *)gv_sysDescr);
return (U_CHAR *)gv_sysDescr;
}