Hi,


I am running Debian 6.0 with netsnmp 5.4.3. I developed a snmp agent with
dlmod. The basic agent source code is generated using mib2c tool and I
modified the source files for my project. The problem what I have is when I
send a snmpget request to agent, snmp agent is not responding for one
specific OID which is related to TIMETICKS but responds to all other
OIDs  (like
INTEGER and STRING)  which are not TIMETICK based OIDs . SNMP agent also
prints the following error information on the console when I request that
OID.

Error: "snmp_build: unknown failuresend response: Error building ASN.1
representation (build uint size 9: s/b 4)"


The following the implementation to retrieve the system uptime from
/proc/uptime for the OID. Please suggest a work around for this issue or
suggest how can I implement a TIMETICK related OID in the SNMP.

handle_xyzUptime(netsnmp_mib_handler *handler,

                          netsnmp_handler_registration *reginfo,

                          netsnmp_agent_request_info   *reqinfo,

                          netsnmp_request_info         *requests)

{

    /* We are never called for a GETNEXT if it's registered as a

       "instance", as it's "magically" handled for us.  */



    /* a instance handler also only hands us one request at a time, so

       we don't need to loop over a list of requests; we'll only get one. */


    char return_val[256];

    FILE *fp = NULL;

           char line[256];

           /* set the defalut value */

    strncpy (return_val, "N/A", 4);

    char cmd[] = "cut -s -d' ' -f 1 /proc/uptime";



           /* Open the command for reading. */

          fp = popen(cmd, "r");

          if (fp != NULL)

          {

                  /* read the line from file */

                  fgets (line, 256, fp);

                        /* copy the data */

                        strncpy(return_val, line, strnlen (line, 256));


                  /* close the file */

            pclose (fp);

    }

    switch(reqinfo->mode) {



        case MODE_GET:

            snmp_set_var_typed_value(requests->requestvb, ASN_TIMETICKS,

                                     (u_char *)& return_val,

                                     strnlen (return_val,256));

            break;





        default:

            /* we should never get here, so this is a really bad error */

            snmp_log(LOG_ERR, "unknown mode (%d) in handle_xyzUptime\n",
reqinfo->mode );

            return SNMP_ERR_GENERR;

    }



    return SNMP_ERR_NOERROR;

}


-- 
Thank you,
Ravi Depa
------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to