Ok, I figured it out.
Maybe my findings will come in handy to someone.

The code that is generated by mib2c with mib2c.iterate.conf style in
the _get_next_data_point
function there is a call to snmp_set_var_value( idx, entry->myIndex,
sizeof(entry->myIndex) ).

sizeof will not work with strings obviously.
changing it to entry->myIndex_len does the trick.



On Wed, Feb 11, 2015 at 11:35 AM, Mattias Barthel <mbart...@accedian.com>
wrote:

> I tried to do the same with an Unsigned32 index. And this worked fine.
>
> ENDPOINT-MGMT-MIB::endpointMgmtSEPIndex.1 = Gauge32: 1
> ENDPOINT-MGMT-MIB::endpointMgmtSEPIndex.2 = Gauge32: 2
> ENDPOINT-MGMT-MIB::endpointMgmtSEPName.1 = STRING: Actuator-1
> ENDPOINT-MGMT-MIB::endpointMgmtSEPName.2 = STRING: Actuator-2
> ENDPOINT-MGMT-MIB::endpointMgmtSEPState.1 = INTEGER: disconnected(1)
> ENDPOINT-MGMT-MIB::endpointMgmtSEPState.2 = INTEGER: connected(2)
>
> Are stringed indices supported?
> If so, is there something I might be missing?
>
>
> On Tue, Feb 10, 2015 at 7:03 PM, Mattias Barthel <mbart...@accedian.com>
> wrote:
>
>> Hey,
>>
>> From a mail conversation dug up from 2006,
>> I am trying to do exactly what Qiang was doing, namely initialise the
>> table just to test the mechanism.
>> My table has an OCTET_STRING as index.
>> I have this code:
>>
>>   char *name, *endPointSEPName = "Endpoint-%d";
>>     int i;
>> ............
>>   /* Initialise the contents of the table here */
>>     for (i = 0; i < 25; i++) {
>>         name = (char*)malloc(20);
>>         sprintf(name,  endPointSEPName, i + 1);
>>         endpointMgmtSEPTable_addEntry(name, strlen(name), (i % 5) + 1);
>>         free(name);
>>     }
>> ............
>> /* create a new row in the (unsorted) table */
>> struct endpointMgmtSEPTable_entry *
>> endpointMgmtSEPTable_addEntry(
>>                  char* endpointMgmtSEPName,
>>                  size_t endpointMgmtSEPName_len,
>>                  long endpointMgmtSEPState
>>                 ) {
>>     struct endpointMgmtSEPTable_entry *entry;
>>
>>     entry = SNMP_MALLOC_TYPEDEF(struct endpointMgmtSEPTable_entry);
>>     if (!entry)
>> return NULL;
>>
>>     memcpy(entry->endpointMgmtSEPName, endpointMgmtSEPName,
>> endpointMgmtSEPName_len);
>>     entry->endpointMgmtSEPName_len = endpointMgmtSEPName_len;
>>
>>     entry->endpointMgmtSEPState = endpointMgmtSEPState;
>>
>>     entry->next = endpointMgmtSEPTable_head;
>>     endpointMgmtSEPTable_head = entry;
>>     entry->valid = 1;
>>     return entry;
>> }
>>
>>
>> This aint working as I expected, though. I only get one row, i.e the last
>> one added to the table.
>> snmpwalk -v2c public <host> .1 | grep ENDPOINT
>> ENDPOINT-MGMT-MIB::endpointMgmtSEPName = STRING: Actuator-24
>> ENDPOINT-MGMT-MIB::endpointMgmtSEPState = INTEGER: upgradeonly(5)
>>
>>
>> I dont understand why.
>>
>> Please help.
>>
>>
>> Best regards,
>> Mattias
>>
>>
>> --
>>
>> 蔷<Qiang Hu>
>> <https://www.mail-archive.com/search?l=net-snmp-users@lists.sourceforge.net&q=from:%22%E8%94%B7%26lt%3BQiang+Hu%26gt%3B%22>
>>  Fri, 11 Aug 2006 01:15:51 -0700
>> <https://www.mail-archive.com/search?l=net-snmp-users@lists.sourceforge.net&q=date:20060811>
>> i saw this routine and i'm pulzzled about "table_entry = (struct
>> tbModuleTable_entry *)netsnmp_extract_iterator_context(request);" it seems
>> that table_entry get relevant datas from this
>> netsnmp_extract_iterator_context;and how can i initial contents of table in
>> iterator.i can't understand the iterator operation mechanism. i saw an
>> exitent mib handler code of net-snmp which initials in this way
>> as following:
>>
>>     iinfo->make_data_context = netSnmpHostsTable_context_convert_function;
>>     iinfo->free_data_context = netSnmpHostsTable_data_free;
>>     iinfo->free_loop_context_at_end = netSnmpHostsTable_loop_free;
>>
>> is there any examples mibs for how to modify the generater code by
>> mib2c.iterate.conf?
>>
>>  that's my generated code for my mib(not modified),can you tell me how to
>> set the datas of table?
>>
>> /*
>>  * Note: this file originally auto-generated by mib2c using
>>  *  : mib2c.iterate.conf,v 5.17 2005/05/09 08:13:45 dts12 Exp $
>>  */
>>
>> #include <net-snmp/net-snmp-config.h>
>> #include <net-snmp/net-snmp-includes.h>
>> #include <net-snmp/agent/net-snmp-agent-includes.h>
>> #include "tb.h"
>>
>> /** Initializes the tb module */
>> void
>> init_tb(void)
>> {
>>     /*
>>      * here we initialize all the tables we're planning on supporting
>>      */
>>     initialize_table_tbModuleTable();
>>     initialize_table_tbHwVersionTable();
>> }
>>
>> /** Initialize the tbModuleTable table by defining its contents and how
>> it's structured */
>> void
>> initialize_table_tbModuleTable(void)
>> {
>>     static oid      tbModuleTable_oid[] =
>>         { 1, 3, 6, 1, 4, 1, 21776, 1, 1 };
>>     size_t          tbModuleTable_oid_len = OID_LENGTH(tbModuleTable_oid);
>>     netsnmp_handler_registration *reg;
>>     netsnmp_iterator_info *iinfo;
>>     netsnmp_table_registration_info *table_info;
>>
>>     reg =
>>         netsnmp_create_handler_registration("tbModuleTable",
>>                                             tbModuleTable_handler,
>>                                             tbModuleTable_oid,
>>                                             tbModuleTable_oid_len,
>>                                             HANDLER_CAN_RWRITE);
>>
>>     table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
>>     netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER,   /* index:
>> tbModuleIndex */
>>                                      0);
>>     table_info->min_column = XXX;
>>     table_info->max_column = YYY;
>>
>>     iinfo = SNMP_MALLOC_TYPEDEF(netsnmp_iterator_info);
>>     iinfo->get_first_data_point = tbModuleTable_get_first_data_point;
>>     iinfo->get_next_data_point = tbModuleTable_get_next_data_point;
>>     iinfo->table_reginfo = table_info;
>>
>>     netsnmp_register_table_iterator(reg, iinfo);
>>
>>     /*
>>      * Initialise the contents of the table here
>>      */
>> }
>>
>>     /*
>>      * Typical data structure for a row entry
>>      */
>> struct tbModuleTable_entry {
>>     /*
>>      * Index values
>>      */
>>     long            tbModuleIndex;
>>
>>     /*
>>      * Column values
>>      */
>>     long            tbModuleIndex;
>>     u_long          tbModuleID;
>>     char            tbModuleDescription;
>>     char            old_tbModuleDescription;
>>
>>     /*
>>      * Illustrate using a simple linked list
>>      */
>>     int             valid;
>>     struct tbModuleTable_entry *next;
>> };
>>
>> struct tbModuleTable_entry *tbModuleTable_head;
>>
>> /*
>>  * create a new row in the (unsorted) table
>>  */
>> struct tbModuleTable_entry *
>> tbModuleTable_createEntry(long tbModuleIndex,)
>> {
>>     struct tbModuleTable_entry *entry;
>>
>>     entry = SNMP_MALLOC_TYPEDEF(struct tbModuleTable_entry);
>>     if (!entry)
>>         return NULL;
>>
>>     entry->tbModuleIndex = tbModuleIndex;
>>     entry->next = tbModuleTable_head;
>>     tbModuleTable_head = entry;
>>     return entry;
>> }
>>
>> /*
>>  * remove a row from the table
>>  */
>> void
>> tbModuleTable_removeEntry(struct tbModuleTable_entry *entry)
>> {
>>     struct tbModuleTable_entry *ptr, *prev;
>>
>>     if (!entry)
>>         return;                 /* Nothing to remove */
>>
>>     for (ptr = tbModuleTable_head, prev = NULL;
>>          ptr != NULL; prev = ptr, ptr = ptr->next) {
>>         if (ptr == entry)
>>             break;
>>     }
>>     if (!ptr)
>>         return;                 /* Can't find it */
>>
>>     if (prev == NULL)
>>         tbModuleTable_head = ptr->next;
>>     else
>>         prev->next = ptr->next;
>>
>>     SNMP_FREE(entry);           /* XXX - release any other internal
>> resources */
>> }
>>
>>
>> /*
>>  * Example iterator hook routines - using 'get_next' to do most of the
>> work
>>  */
>> netsnmp_variable_list *
>> tbModuleTable_get_first_data_point(void **my_loop_context,
>>                                    void **my_data_context,
>>                                    netsnmp_variable_list * put_index_data,
>>                                    netsnmp_iterator_info *mydata)
>> {
>>     *my_loop_context = tbModuleTable_head;
>>     return tbModuleTable_get_next_data_point(my_loop_context,
>>                                              my_data_context,
>>                                              put_index_data, mydata);
>> }
>>
>> netsnmp_variable_list *
>> tbModuleTable_get_next_data_point(void **my_loop_context,
>>                                   void **my_data_context,
>>                                   netsnmp_variable_list * put_index_data,
>>                                   netsnmp_iterator_info *mydata)
>> {
>>     struct tbModuleTable_entry *entry =
>>         (struct tbModuleTable_entry *) *my_loop_context;
>>     netsnmp_variable_list *idx = put_index_data;
>>
>>     if (entry) {
>>         snmp_set_var_value(idx, entry->tbModuleIndex,
>>                            sizeof(entry->tbModuleIndex));
>>         idx = idx->next_variable;
>>         *my_data_context = (void *) entry;
>>         *my_loop_context = (void *) entry->next;
>>     } else {
>>         return NULL;
>>     }
>> }
>>
>>
>> /** handles requests for the tbModuleTable table */
>> int
>> tbModuleTable_handler(netsnmp_mib_handler *handler,
>>                       netsnmp_handler_registration *reginfo,
>>                       netsnmp_agent_request_info *reqinfo,
>>                       netsnmp_request_info *requests)
>> {
>>
>>     netsnmp_request_info *request;
>>     netsnmp_table_request_info *table_info;
>>     struct tbModuleTable_entry *table_entry;
>>
>>     switch (reqinfo->mode) {
>>         /*
>>          * Read-support (also covers GetNext requests)
>>          */
>>     case MODE_GET:
>>         for (request = requests; request; request = request->next) {
>>             table_entry = (struct tbModuleTable_entry *)
>>                 netsnmp_extract_iterator_context(request);
>>             table_info = netsnmp_extract_table_info(request);
>>
>>             switch (table_info->colnum) {
>>             case COLUMN_TBMODULEINDEX:
>>                 snmp_set_var_typed_value(request->requestvb, ASN_INTEGER,
>>                                          table_entry->tbModuleIndex,
>>                                          sizeof(table_entry->
>>                                                 tbModuleIndex));
>>                 break;
>>             case COLUMN_TBMODULEID:
>>                 snmp_set_var_typed_value(request->requestvb,
>> ASN_UNSIGNED,
>>                                          table_entry->tbModuleID,
>>                                          sizeof(table_entry->tbModuleID));
>>                 break;
>>             case COLUMN_TBMODULEDESCRIPTION:
>>                 snmp_set_var_typed_value(request->requestvb,
>> ASN_OCTET_STR,
>>                                          table_entry->tbModuleDescription,
>>                                          sizeof(table_entry->
>>                                                 tbModuleDescription));
>>                 break;
>>             }
>>         }
>>         break;
>>
>>         /*
>>          * Write-support
>>          */
>>     case MODE_SET_RESERVE1:
>>         for (request = requests; request; request = request->next) {
>>             table_entry = (struct tbModuleTable_entry *)
>>                 netsnmp_extract_iterator_context(request);
>>             table_info = netsnmp_extract_table_info(request);
>>
>>             switch (table_info->colnum) {
>>             case COLUMN_TBMODULEDESCRIPTION:
>>                 if (request->requestvb->type != ASN_OCTET_STR) {
>>                     netsnmp_set_request_error(reqinfo, request,
>>                                               SNMP_ERR_WRONGTYPE);
>>                     return SNMP_ERR_NOERROR;
>>                 }
>>                 /*
>>                  * Also may need to check size/value
>>                  */
>>                 break;
>>             default:
>>                 netsnmp_set_request_error(reqinfo, request,
>>                                           SNMP_ERR_NOTWRITABLE);
>>                 return SNMP_ERR_NOERROR;
>>             }
>>         }
>>         break;
>>
>>     case MODE_SET_RESERVE2:
>>         break;
>>
>>     case MODE_SET_FREE:
>>         break;
>>
>>     case MODE_SET_ACTION:
>>         for (request = requests; request; request = request->next) {
>>             table_entry = (struct tbModuleTable_entry *)
>>                 netsnmp_extract_iterator_context(request);
>>             table_info = netsnmp_extract_table_info(request);
>>
>>             switch (table_info->colnum) {
>>             case COLUMN_TBMODULEDESCRIPTION:
>>                 /*
>>                  * Need to save old 'table_entry->tbModuleDescription'
>> value.
>>                  * May need to use 'memcpy'
>>                  */
>>                 table_entry->old_tbModuleDescription =
>>                     table_entry->tbModuleDescription;
>>                 table_entry->tbModuleDescription =
>>                     request->requestvb-> val.YYY;
>>                 break;
>>             }
>>         }
>>         break;
>>
>>     case MODE_SET_UNDO:
>>         for (request = requests; request; request = request->next) {
>>             table_entry = (struct tbModuleTable_entry *)
>>                 netsnmp_extract_iterator_context(request);
>>             table_info = netsnmp_extract_table_info(request);
>>
>>             switch (table_info->colnum) {
>>             case COLUMN_TBMODULEDESCRIPTION:
>>                 /*
>>                  * Need to restore old 'table_entry->tbModuleDescription'
>> value.
>>                  * May need to use 'memcpy'
>>                  */
>>                 table_entry->tbModuleDescription =
>>                     table_entry->old_tbModuleDescription;
>>                 break;
>>             }
>>         }
>>         break;
>>
>>     case MODE_SET_COMMIT:
>>         break;
>>     }
>>     return SNMP_ERR_NOERROR;
>> }
>>
>> thanks in advance !
>>
>>
>>
>> On 8/10/06, Dave Shield <[EMAIL PROTECTED]> wrote:
>>>
>>> On 10/08/06, qiang<Qiang Hu> <[EMAIL PROTECTED]> wrote:
>>> > I generated mib2c files by mib2c.conf also with iterator option.and
>>> now i
>>> > wanted to know how to Initialise the contents of the table
>>>
>>> If you look at the generated code, you should see a routine
>>> 'tbModuleTable_createEntry()'.  Call this with the relevant values for
>>> each row you wish to create.
>>>
>>> The only unexpected thing is you'll need to explicitly set the 'valid'
>>> flag for each row.
>>> Something like:
>>>
>>> struct tbModuleTable_entry *entry;
>>>
>>> entry = tbModuleTable_createEntry(1, 256, "eenie");
>>> entry->valid = 1;
>>> entry = tbModuleTable_createEntry(3, 128, "meenie");
>>> entry->valid = 1;
>>> entry = tbModuleTable_createEntry(4, 64, "mynie");
>>> entry->valid = 1;
>>> entry = tbModuleTable_createEntry(2, 32, "mo");
>>> entry->valid = 1;
>>>
>>>
>>> Dave
>>>
>>
>>
>

-- 


Avis de confidentialité

Les informations contenues dans le présent message et dans toute pièce qui 
lui est jointe sont confidentielles et peuvent être protégées par le secret 
professionnel. Ces informations sont à l’usage exclusif de son ou de ses 
destinataires. Si vous recevez ce message par erreur, veuillez s’il vous 
plait communiquer immédiatement avec l’expéditeur et en détruire tout 
exemplaire. De plus, il vous est strictement interdit de le divulguer, de 
le distribuer ou de le reproduire sans l’autorisation de l’expéditeur. 
Merci.

Confidentiality notice

This e-mail message and any attachment hereto contain confidential 
information which may be privileged and which is intended for the exclusive 
use of its addressee(s). If you receive this message in error, please 
inform sender immediately and destroy any copy thereof. Furthermore, any 
disclosure, distribution or copying of this message and/or any attachment 
hereto without the consent of the sender is strictly prohibited. Thank you.
------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
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