Title: Message
I am attempting to implement a mib module where there is a table indexed by a string (version 5.0.6).  For demo purposes, it is currently a table of books indexed by titles.
I have attempted to implement the bookTable_get_first_data_point and bookTable_get_next_data_point methods similar to how I have implemented similar methods when the table was indexed by a integer (only using character arrays rather than integers):
 
/*****************************************************************/
bookTable_get_first_data_point(void **my_loop_context,
                               void **my_data_context,
                               netsnmp_variable_list * put_index_data,
                               netsnmp_iterator_info *mydata)
{
    netsnmp_variable_list *vptr;
    subtree_context_cache *context_ptr;
    context_ptr = get_top_context_cache();
    if (!context_ptr)
        return NULL;
 
    vptr = put_index_data;
    char this_index[SPRINT_MAX_LEN]  = "title1";
    snmp_set_var_value(vptr, (u_char *) &this_index ,
                       sizeof(this_index) );

    *my_loop_context = (void *)this_index;
    *my_data_context = (void *)this_index;
 
    return put_index_data;
}
/*****************************************************************/

bookTable_get_next_data_point(void **my_loop_context,
                              void **my_data_context,
                              netsnmp_variable_list * put_index_data,
                              netsnmp_iterator_info *mydata)
{
    netsnmp_variable_list *vptr;
    subtree_context_cache *context_ptr;
   
    if (!my_loop_context || !*my_loop_context){
        return NULL;
     }
    char this_index[SPRINT_MAX_LEN];
    snprintf(this_index,SPRINT_MAX_LEN,(const char*)*my_loop_context); 

    if(strcmp(this_index,"title1")==0){
       snprintf(this_index,SPRINT_MAX_LEN,"title2");   
    } else if (strcmp(this_index,"title2")==0){
       snprintf(this_index,SPRINT_MAX_LEN,"title3");       
    }else{
       return NULL;
    }
 
    snmp_set_var_value(vptr, (u_char *) &this_index ,
                       sizeof(this_index) );
    *my_loop_context = (void *)this_index;
    *my_data_context = (void *)this_index;
    return put_index_data;
}
/*****************************************************************/
 
This will compile and run the agent, a walk will result in a core dump in the get_next_data_point method, at the snmp_set_var_value call.
 
Am I implementing this correctly?  This is essentially how I implemented similar methods when the index was an integer. 
 
-------------------------------------------------------------------------
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-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to