Question

My following code is not working as I want to get the description of a node using the Net-Snmp library.

#include "net-snmp/net-snmp-config.h"
#include "net-snmp/net-snmp-includes.h"

void  print_s(struct tree *);

    int main(int argc, char ** argv)
    {
        char buff[100]; 
        struct tree *node=NULL;

        init_mib();
        node=read_all_mibs();
        if( node == NULL )
        {
        exit(2);
        }
        print_s(node);  
    } 


void  print_s(struct tree *tree)
    {       
    struct tree    *tp; 

    for (tp = tree->child_list; tp; tp = tp->next_peer) 
    {
printf("%s:%s\n",tp->label,tp->description); 
    }
    for (tp = tree->child_list; tp; tp = tp->next_peer) 
          {           
              if (tp->child_list)
                  print_s(tp);
          }           

    }




    o/p-
org:(null)
dod:(null)
internet:(null)
snmpV2:(null)
security:(null)
private:(null)
experimental:(null)
mgmt:(null)
directory:(null)
snmpModules:(null)
snmpProxys:(null)
snmpDomains:(null)
snmpMIB:(null)
snmpFrameworkMIB:(null)
.........
........

I am getting the null for all the nodes,

Kindly tell me why I am not able to get the description of nodes as it is available .when I am using the command line option as follow

snmptranslate -On -Td 1.3.6.1.6.3.10

Result
-----------
 .1.3.6.1.6.3.10
snmpFrameworkMIB MODULE-IDENTITY
  -- FROM       SNMP-FRAMEWORK-MIB
  DESCRIPTION   "The SNMP Management Architecture MIB

                     Copyright (C) The Internet Society (2002). This
                     version of this MIB module is part of RFC 3411;
                     see the RFC itself for full legal notices.
                    "
::= { iso(1) org(3) dod(6) internet(1) snmpV2(6) snmpModules(3) 10 }

1.3.6.1.6.3.10 is the oid of the snmpFrameworkMIB but you can see above the node in my program got null as its description.

Can any one know what is the problem here.

Was it helpful?

Solution

By default the net-snmp MIB parser does not turn on DESCRIPTION string storage in particular because it takes more memory.

To print description call:

snmp_set_save_descriptions(1);

before calling init_snmp() to force saving of the DESCRIPTION clauses.

The function void snmp_set_save_descriptions(int);

declared in include/net-snmp/mib_api.h and defined in snmplib/ucd_compat.c.

Definition:

void
snmp_set_save_descriptions(int save)
{
   netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, 
                          NETSNMP_DS_LIB_SAVE_MIB_DESCRS, save);
}

EDIT:

call snmp_set_save_descriptions(1); before init_snmp() Also ..init_snmp() calls netsnmp_init_mib() So not need to call netsnmp_init_mib() explicitly if one is calling init_snmp()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top