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.
By default the
net-snmpMIBparser does not turn on DESCRIPTION string storagein particular because it takes more memory.
To print description call:
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.hand defined insnmplib/ucd_compat.c.Definition:
EDIT:
call
snmp_set_save_descriptions(1);beforeinit_snmp()Also ..init_snmp()callsnetsnmp_init_mib()So not need to callnetsnmp_init_mib()explicitly if one is callinginit_snmp()