Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7752875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:54:37+00:00 2026-06-01T11:54:37+00:00

I’ve written an AgentX app (Linux, gcc, g++) which works well at sending back

  • 0

I’ve written an AgentX app (Linux, gcc, g++) which works well at sending back scalers. Here is what I’m doing now:

init_agent( "blah" );
netsnmp_register_read_only_scalar( netsnmp_create_handler_registration( "foo1", handle_foo1, oid, oid.size(), HANDLER_CAN_RONLY ) );
init_snmp( "blah" );
while ( true )
{
    // internal stuff
    agent_check_and_process(1); // where 1==block
}

The functions like handle_foo1(...) call snmp_set_var_typed_value(...) to return the values which are cached in a global C struct within the application.

What I’m trying to do now is modify this code to also support a SNMP table. The content of the table is stored/cached as a STL container within the application. This is a relatively simple SNMP table, with consecutive rows, and all columns are composed of types like Integer32, Gauge32, InetAddress, and TruthValue. The problem is I don’t see great code examples on the net-snmp web site, just a lot of doxygen pages.

My question:

What API should I be looking at? Are these the right calls:

netsnmp_register_read_only_table_data();
netsnmp_create_table_data();
netsnmp_create_table_data_row();
netsnmp_table_data_add_row();

…or is there something simpler I should be using?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:54:39+00:00Added an answer on June 1, 2026 at 11:54 am

    I think the biggest pain when it comes to net-snmp is all those Doxygen pages the Google indexes but which provides near-zero usable content. Reading the .h files is probably already obvious to most developers, and the truth is that net-snmp provides many different layers of APIs with very little documentation I found useful. What we need isn’t several dozen identical copies of web sites hosting Doxygen, but instead some good examples.

    In the end, the mib2c tool is how I got enough example code to get the whole thing working. I think I tried running mib2c with every single net-snmp .conf file, and spent a lot of time reading the code it generated to get a better understanding. Here are the ones I found gave me the best hints:

    • mib2c -c mib2c.create-dataset.conf MyMib
    • mib2c -c mib2c.table_data.conf MyMib

    The .conf files are here: /etc/snmp/mib2c.*

    Also useful were the following pages:

    • FAQ: http://www.net-snmp.org/FAQ.html
    • Example code for tables: http://www.net-snmp.org/dev/agent/data__set_8c-example.html
    • Doxygen pages: http://www.net-snmp.org/dev/agent/group__library.html

    From what I understand, there are many helpers/layers available in the net-snmp API. So this example pseudocode may not work for everyone, but this is how I personally got my tables to work using net-snmp v5.4:

    Variable needed across several functions (make it global, or a member of a struct?)

    netsnmp_tdata *table = NULL;
    

    Structure to represent one row of the table (must match the MIB definition)

    struct MyTable_entry
    {
        long myTableIndex;
        ...insert one line here for each column of the table...
        int valid; // add this one to the end
    }
    

    Initialize the table with snmpd

    std::string name( "name_of_the_table_from_mib" );
    table = netsnmp_tdata_create_table( name.c_str(), 0 );
    netsnmp_table_registration_info *table_info = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
    netsnmp_table_helper_add_indexes( table_info, ASN_INTEGER, 0 ); // index: myTableIndex
    // specify the number of columns in the table (exclude the index which was already added)
    table_info->min_column = COLUMN_BLAH;
    table_info->max_column = MAX_COLUMN_INDEX;
    netsnmp_handler_registration *reg = netsnmp_create_handler_registration( name.c_str(), MyTable_handler, oid, oid.size(), HANDLER_CAN_RONLY );
    netsnmp_tdata_register( reg, table, table_info );
    

    Handler to process requests

    int myTable_handler( netsnmp_mib_handler *handler, netsnmp_handler_registration *reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests )
    {
        if ( reqInfo->mode != MODE_GET ) return SNMP_ERR_NOERROR;
        for ( netsnmp_request_info *request = requests; request; request = request->next )
        {
            MyTable_entry *table_entry  = (MyTable_entry*)netsnmp_tdata_extract_entry( request );
            netsnmp_table_request_info *table_info = netsnmp_extract_table_info( request );
    
            if ( table_entry == NULL ) { netsnmp_set_request_error( reqinfo, request, SNMP_NOSUCHINSTANCE); continue; }
    
            switch ( table_info->colnum )
            {
                // ...this is similar to non-table situations, eg:
                case COLUMN_BLAH:
                    snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER, table_entry->blah ); break;
                // ...
                default: netsnmp_set_request_error( reqinfo, request, SNMP_NOSUCHOBJECT );
            }
        }
        return SNMP_ERR_NOERROR;
    }
    

    Building/adding rows to the table

    if ( table == NULL ) return;   // remember our "global" variable named "table"?
    
    // start by deleting all of the existing rows
    while ( netsnmp_tdata_row_count(table) > 0 )
    {
        netsnmp_tdata_row *row = netsnmp_tdata_row_first( table );
        netsnmp_tdata_remove_and_delete_row( table, row );
    }
    
    for ( ...loop through all the data you want to add as rows into the table... )
    {
        MyTable_entry *entry = SNMP_MALLOC_TYPEDEF( MyTable_entry );
        if ( entry == NULL ) ... return;
        netsnmp_tdata_row *row = netsnmp_tdata_create_row();
        if ( row == NULL ) SNMP_FREE( entry ); .... return;
    
        entry->myTableIndex = 123; // the row index number
        // populate the table the way you need
        entry->blah = 456;
        // ...
    
        // add the data into the row, then add the row to the table
        entry->valid = 1;
        row->data = entry;
        netsnmp_tdata_row_add_index( row, ASN_INTEGER, &(entry->myTableIndex), sizeof(entry->myTableIndex) );
        netsnmp_tdata_add_row( table, row );
    }
    

    Putting it together

    In my case, that last function that builds the rows is triggered periodically by some other events in the system. So every once in a while when new stats are available, the table is rebuilt, all old rows are removed, and the new ones are inserted. I didn’t bother trying to modify existing rows. Instead, I found it was easier to just rebuild the table from scratch.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.