Hi,
I wrote my own MIB file and compiled the module into the agent.When I ran 
"snmpwalk -v2c localhost -m ALL -t 3 -c public sysConfigMib" and got 
"SYS-CONFIG-MIB::sysConfigMib = No Such Object available on this agent at this 
OID".
Before "make install",I ran the newly-compiled agent in a 'testing' mode:" $ 
agent/snmpd -f -L -d -p 9999",in another terminal I ran "snmpgetnext 
localhost:9999 -c public system" and I saw the agent received the packages but 
did not reply to them.
Where is the problem?Please help me.Thanks!

Here is my code:
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "sysConfigMib.h"

//reserved value allocate
static char def_potType[8]        = "linux";
.. //some allocaeted values

/** Initializes the sysConfigMib module */
void
init_sysConfigMib(void)
{
    static oid      nodeType_oid[] = { 1, 3, 6, 1, 4, 1, 9953, 0, 10 };
     ....  //some oids                
                                                                                
                           
    DEBUGMSGTL(("sysConfigMib", "Initializing\n"));                             
                           
                                                                                
                           
    netsnmp_register_scalar(netsnmp_create_handler_registration                 
                           
                            ("nodeType", handle_nodeType, nodeType_oid,         
                           
                             OID_LENGTH(nodeType_oid),                          
                           
                             HANDLER_CAN_RWRITE));                              
                           
     .....// some scalar registration                               
}                                                                               
                           
                                                                                
                           
int                                                                             
                           
handle_nodeType(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.       
                           
     */                                                                         
                           
                                                                                
                           
    switch (reqinfo->mode) {                                                    
                           
                                                                                
                           
    case MODE_GET:                                                              
                           
        snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR,            
                           
                                 (u_char *)def_nodeType                         
                           
                                 /* XXX: a pointer to the scalar's data */      
                           
                                 ,strlen(def_nodeType)                          
                           
                                 /*                                             
                           
                                  * 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:                                                     
                           
            netsnmp_set_request_error(reqinfo, requests,SNMP_ERR_WRONGTYPE      
                           
                                      );                                        
                           
        }                                                                       
                           
        break;                                                                  
                           
                                                                                
                           
    case MODE_SET_RESERVE2:                                                     
                           
        /*                                                                      
                           
         * XXX malloc "undo" storage buffer                                     
                           
         */                                                                     
                           
//        if ( /* 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 ( strlen(def_nodeType) < strlen(requests->requestvb->val.string)/* 
XXX: error? */ ) {           
            netsnmp_set_request_error(reqinfo, requests, /* some error */       
                           
                                      SNMP_ERR_WRONGLENGTH);                    
                           
        }                                                                       
                           
        strcpy(def_nodeType , (u_char *)requests->requestvb->val.string);       
                           
        break;                                                                  
                           
                                                                                
                           
    case MODE_SET_COMMIT:                                                       
                           
        /*                                                                      
                           
         * XXX: delete temporary storage                                        
                           
         */                                                                     
                           
//        if ( /* XXX: error? */ ) {
            /*                                                                  
                           
             * 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? */ ) {                                            
                           
            /*                                                                  
                           
             * 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              
                           
         */                                                                     
                           
        return SNMP_ERR_GENERR;                                                 
                           
    }                                                                           
                           
                                                                                
                           
    return SNMP_ERR_NOERROR;                                                    
                           
}   
...//functions
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to