Hi Dave,
      I have attached the code which i little bit modified to learn abt
set function scalar_int.c is the example file that i took from the
net-snmp code and modified.
      
On Tue, 2005-06-14 at 18:22, Dave Shield wrote:
> On Tue, 2005-06-14 at 13:23, Sasikumar Bodathula wrote:
> > I am having doubt do i need to set requests->delegated to zero.
> 
> You shouldn't normally need to touch the 'delegated' flag.
> This is a very specialised requirement, and isn't relevant
> for a simple watched instance, as you've been describing.
> 
> > for me the function netsnmp_check_for_delegated() is returning 1.
> 
> Hmmm...  strange.
> Can you post the exact code file that you're using,
> so I can give it a whirl?
> 
> Dave
> 
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>

static int      example1 = 42;  /* default value */

int setFunc();
void
init_scalar_int(void)
{
    oid             my_registration_oid[] =
        { 1, 3, 6, 1, 4, 1, 8072, 2, 1, 1, 0 };
printf("Default value is %d\n", example1);
    netsnmp_register_int_instance("my example int variable",
                                  my_registration_oid,
                                  OID_LENGTH(my_registration_oid),
                                  &example1, setFunc);

    DEBUGMSGTL(("example_scalar_int",
                "Done initalizing example scalar int\n"));
}

int setFunc(netsnmp_mib_handler *handler,
            netsnmp_handler_registration *reginfo,
            netsnmp_agent_request_info *reqinfo,
            netsnmp_request_info *requests)
{
    printf("***********INSIDE setFunc*********\n");
    int *pexample = NULL;
    switch(reqinfo->mode)
    {
         case MODE_GET:
        snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
                                 (u_char *)&example1
                                 ,sizeof(int)
                                  );
           break;
         case MODE_SET_RESERVE1:
             printf( "inside MODE_SET_RESERVE1\n");
    requests->delegated = 0;
            if ( requests->requestvb->type != ASN_INTEGER  ) {
                printf( "wrong type\n");
                netsnmp_set_request_error(reqinfo, requests,
                                          SNMP_ERR_WRONGTYPE
                                         );
                return SNMP_ERR_WRONGTYPE;
             }
             if ( (*(requests->requestvb->val.integer) > 1 ) || (*(requests->requestvb->val.integer) < 0))
             {
                 printf( "wrong value\n");
                 netsnmp_set_request_error(reqinfo, requests,
                                          SNMP_ERR_WRONGVALUE
                                          );
                 return SNMP_ERR_WRONGVALUE;
             }
            break;
       case MODE_SET_RESERVE2:
            printf( "inside MODE_SET_RESERVE2\n");
            memdup((u_char **)&pexample, (u_char *)&example1, sizeof(example1));
            if ( pexample == NULL ) {
               netsnmp_set_request_error(reqinfo, requests,
                                         SNMP_ERR_RESOURCEUNAVAILABLE);
           }
           break;
        case MODE_SET_FREE:
             printf( "inside MODE_SET_FREE \n");
          break;
    case MODE_SET_ACTION:
        printf( "Inside MODE_SET_ACTION\n");
        example1 = *(requests->requestvb->val.integer);
        break;
                                                                                                                            
    case MODE_SET_COMMIT:
        printf( "Inside MODE_SET_COMMIT\n");
        break;
                                                                                                                            
    case MODE_SET_UNDO:
        printf("Inside MODE_SET_UNDO\n");
        break;
                                                                                                                            
    default:
        printf( "inside default\n");
        return SNMP_ERR_GENERR;
    }
    return SNMP_ERR_NOERROR;
}

Reply via email to