Hello All!

 

I am trying to figure out how my_test_handler works.

When a Net-Snmp with oid {1,2,3,4} , my_test_handler is called .

The oid which appears inside my_test_handler is not the one which this
fuction is registered on .

Why is that ?

What is the use of the OID inside that function ?

Why do we have to compare it to the original oid before setting the call
to snmp_set_var_typed_value(var, ASN_INTEGER,

                                         (u_char *) & accesses,

                                         sizeof(accesses));

?

 

Thanks

Dan Porat

 

 

.

.

.

.

.

.

static oid      my_test_oid[4] = { 1, 2, 3, 4 };

.

.

.

.

netsnmp_register_handler(netsnmp_create_handler_registration

                             ("myTest", my_test_handler, my_test_oid, 4,

                              HANDLER_CAN_RONLY));

.

.

.

.

.

 

int

my_test_handler(netsnmp_mib_handler *handler,

                netsnmp_handler_registration *reginfo,

                netsnmp_agent_request_info *reqinfo,

                netsnmp_request_info *requests)

{

 

    oid             myoid1[] = { 1, 2, 3, 4, 5, 6 };

    static u_long   accesses = 0;

 

    DEBUGMSGTL(("testhandler", "Got request:\n"));

    /*

     * loop through requests 

     */

    while (requests) {

        netsnmp_variable_list *var = requests->requestvb;

 

        DEBUGMSGTL(("testhandler", "  oid:"));

        DEBUGMSGOID(("testhandler", var->name, var->name_length));

        DEBUGMSG(("testhandler", "\n"));

 

        switch (reqinfo->mode) {

        case MODE_GET:

            if (netsnmp_oid_equals(var->name, var->name_length, myoid1,
6)

                == 0) {

                snmp_set_var_typed_value(var, ASN_INTEGER,

                                         (u_char *) & accesses,

                                         sizeof(accesses));

                return SNMP_ERR_NOERROR;

            }

            break;

 

        case MODE_GETNEXT:

            if (snmp_oid_compare(var->name, var->name_length, myoid1, 6)

                < 0) {

                snmp_set_var_objid(var, myoid1, 6);

                snmp_set_var_typed_value(var, ASN_INTEGER,

                                         (u_char *) & accesses,

                                         sizeof(accesses));

                return SNMP_ERR_NOERROR;

            }

            break;

 

        default:

            netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_GENERR);

            break;

        }

 

        requests = requests->next;

    }

    return SNMP_ERR_NOERROR;

}

 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to