I’m running v5.2.1 on LinuxES3.0 and trying to get the tutorial demo running.  But as you can see by the output at the end of this email, I’m getting an error.  Any thoughts?  snmpget from the command line works.  thx.  pd :-(

 

cosvrua:/var/net-snmp$ snmpget -c public localhost system.sysDescr.0

SNMPv2-MIB::sysDescr.0 = STRING: Linux cosvrua 2.4.21-9.EL #1 Thu Jan 8 17:24:12 EST 2004 i686

 

 

 

 

#include <net-snmp/net-snmp-config.h>

#include <net-snmp/net-snmp-includes.h>

 

int main( int argc, char* arvg[] )

{

  struct snmp_session   Session;

  struct snmp_session*  pSession;

  struct snmp_pdu*      pPdu;

  struct snmp_pdu*      pResponse;

  oid                   Oid[MAX_OID_LEN];

  size_t                OidLen = MAX_OID_LEN;

  struct variable_list* pVars;

  int                   Status;

 

  printf("START test\n");

  printf("init_snmp(\"snmpget\")\n");

  init_snmp("snmpget");

  snmp_sess_init( &Session );

 

  printf("opening session\n");

  Session.peername = "localhost";

  Session.version  = SNMP_VERSION_1;

  Session.community = "public";

  Session.community_len = strlen(Session.community);

  pSession = snmp_open(&Session);

  if( !pSession )

  {

    snmp_perror("ack");

    snmp_log(LOG_ERR, "bad stuff happened !!!\n");

    exit(2);

  }

 

  printf("creating and filling PDU with get sysDescr.0\n");

  pPdu = snmp_pdu_create(SNMP_MSG_GET);

  //get_node("sysDescr.0", Oid, &OidLen);

  //read_objid("system.sysDescr.0", Oid, &OidLen);

  read_objid(".1.3.6.1.2.1.1.1.0", Oid, &OidLen);

  snmp_add_null_var(pPdu, Oid, OidLen);

 

  printf("sending request, waiting for response\n");

  Status = snmp_synch_response(pSession, pPdu, &pResponse);

  if( Status == STAT_SUCCESS && pResponse->errstat == SNMP_ERR_NOERROR )

  {

    for( pVars = pResponse->variables; pVars; pVars = pVars->next_variable )

      print_variable( pVars->name, pVars->name_length, pVars);

  }

  else

  {

    if( Status == STAT_SUCCESS )

      printf("Error in packet; Reason: %s\n", snmp_errstring(pResponse->errstat));

    else

     snmp_sess_perror("snmpget", pSession);

  }

 

  if( pResponse )

  {

    printf("freeing response\n");

    snmp_free_pdu(pResponse);

  }

  printf("closing session\n");

  snmp_close(pSession);

 

  printf("END test\n");

}

 

START test

init_snmp("snmpget")

opening session

creating and filling PDU with get sysDescr.0

sending request, waiting for response

snmpget: Too long

closing session

END test

Reply via email to