[Agentx] How can I get the variable passed by the set command?

林志平 <solyn123@gmail.com> Wed, 27 January 2010 04:28 UTC

Return-Path: <solyn123@gmail.com>
X-Original-To: agentx@core3.amsl.com
Delivered-To: agentx@core3.amsl.com
Received: from localhost (localhost [127.0.0.1]) by core3.amsl.com (Postfix) with ESMTP id 1E0893A6881 for <agentx@core3.amsl.com>; Tue, 26 Jan 2010 20:28:22 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: 2.991
X-Spam-Level: **
X-Spam-Status: No, score=2.991 tagged_above=-999 required=5 tests=[BAYES_05=-1.11, CHARSET_FARAWAY_HEADER=3.2, HTML_MESSAGE=0.001, J_CHICKENPOX_83=0.6, MIME_8BIT_HEADER=0.3]
Received: from mail.ietf.org ([64.170.98.32]) by localhost (core3.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FV-yNsz5ltyB for <agentx@core3.amsl.com>; Tue, 26 Jan 2010 20:28:20 -0800 (PST)
Received: from mail-pz0-f178.google.com (mail-pz0-f178.google.com [209.85.222.178]) by core3.amsl.com (Postfix) with ESMTP id C3CC23A659B for <agentx@ietf.org>; Tue, 26 Jan 2010 20:28:20 -0800 (PST)
Received: by pzk8 with SMTP id 8so2184428pzk.29 for <agentx@ietf.org>; Tue, 26 Jan 2010 20:28:33 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=K/LRzG90x9s8SDDwYjiJozf7VqBQdycAFnraZ3o1Bok=; b=wWG/CZiCueIsC3ikX4Ee2eEMhOVJQI0GD2BCDtXms1a1Uaz0zt2iLvnup5fK49c7qK r9i610b3VET6pjdbLoG276SO6SJD6CMqivdkPsGtbYqZcwob7cpiq/aSrLRFHlOxGqM/ 0S+JjekUjRGzVcI1/tqsdu9qfni1V6kloXGyU=
DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=k6wt995xPkhYYfaJ/rxLghxBodg+eBx91xZbvm1wD8D6WkTslvnOQC4fM4Sfun4pgs s/KYR6YfnwnSFIxqiC7IZso9rl0qhvbAwPqI9unAtIp14cZqo5HQaLR9+vt5QUtUxX0/ fFSod7bO6HC9nWuwgthVSAm9RpuOnIlsdjCBg=
MIME-Version: 1.0
Received: by 10.142.61.33 with SMTP id j33mr1606692wfa.61.1264566513399; Tue, 26 Jan 2010 20:28:33 -0800 (PST)
Date: Wed, 27 Jan 2010 12:28:33 +0800
Message-ID: <8148211e1001262028p6d46e1a3p23eddb7e2a4288f7@mail.gmail.com>
From: 林志平 <solyn123@gmail.com>
To: agentx@ietf.org, linzhiping_zhiqi@126.com
Content-Type: multipart/alternative; boundary="001636e1f93dd379ec047e1dd510"
Subject: [Agentx] How can I get the variable passed by the set command?
X-BeenThere: agentx@ietf.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: SNMP Agent Extensibility <agentx.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/listinfo/agentx>, <mailto:agentx-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/agentx>
List-Post: <mailto:agentx@ietf.org>
List-Help: <mailto:agentx-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/agentx>, <mailto:agentx-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 27 Jan 2010 04:28:22 -0000

Hi,all
I am using netsnmp5.5, and I get a MIB file ,using the mib2c tool I got some
.c and .h files.
Now, I want to set the variable,but I donot how netsnmp passes it.
Does the variable setted passed in reqinfo or reginfo structure?
thanks
Part of the code:
*int
handle_mySysResetNo(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info   *reqinfo,
                          netsnmp_request_info         *requests)
{
    int ret;
    int ResetNo=16;
    /* 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. */

    switch(reqinfo->mode) {

        case MODE_GET:
            snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                     (u_char *)&ResetNo /* XXX: a pointer to
the scalar's data */,
                                     strlen(&ResetNo)/* XXX: the length of
the data in bytes */);
            break;

        /*
         * SET REQUEST
         *
         * multiple states in the transaction.  See:
         *
http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
         */
        case MODE_SET_RESERVE1:
                /* or you could use netsnmp_check_vb_type_and_size instead
*/
            ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
            if ( ret != SNMP_ERR_NOERROR ) {
                netsnmp_set_request_error(reqinfo, requests, ret );
            }
            break;

        case MODE_SET_RESERVE2:
            /* XXX malloc "undo" storage buffer */
            if (0/* XXX if malloc, or whatever, failed: */) {
                netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_RESOURCEUNAVAILABLE);
            }
            break;

        case MODE_SET_FREE:
            /* XXX: free resources allocated in RESERVE1 and/or
               RESERVE2.  Something failed somewhere, and the states
               below won't be called. */
            break;

        case MODE_SET_ACTION:
            /* XXX: perform the value change here */
            if (0/* XXX: error? */) {
                netsnmp_set_request_error(reqinfo, requests, 0/* some error
*/);
            }
            break;

        case MODE_SET_COMMIT:
            /* XXX: delete temporary storage */
            if (/* XXX: error? */0) {
                /* try _really_really_ hard to never get to this point */
                netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_COMMITFAILED);
            }
            break;

        case MODE_SET_UNDO:
            /* XXX: UNDO and return to previous value for the object */
            if (/* XXX: error? */0) {
                /* try _really_really_ hard to never get to this point */
                netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_UNDOFAILED);
            }
            break;

        default:
            /* we should never get here, so this is a really bad error */
            snmp_log(LOG_ERR, "unknown mode (%d) in handle_mySysResetNo\n",
reqinfo->mode );
            return SNMP_ERR_GENERR;
    }

    return SNMP_ERR_NOERROR;
}*