2012-11-30 104 views
0

我的下面的代码不工作,因为我想使用Net-Snmp库来获取节点的描述。为什么描述snmp oid给出“null”?

#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) 
......... 
........ 

我正在为所有节点空,

请告诉我为什么我不能够得到节点的描述,因为它是可用的。当我使用的命令行选项如下

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.10snmpFrameworkMIBoid但你可以看到上面的节点在我的程序作为其description了空。

任何人都可以知道这里有什么问题。

回答

2

默认情况下,net-snmpMIB解析器无法打开说明字符串存储器 ,因为它需要更多的内存。

要打印的说明电话:

snmp_set_save_descriptions(1); 

之前调用init_snmp()迫使说明条款的储蓄。

功能void snmp_set_save_descriptions(int);

include/net-snmp/mib_api.h声明并在snmplib/ucd_compat.c定义。

定义

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

编辑:

呼叫snmp_set_save_descriptions(1);init_snmp()还.. init_snmp()电话netsnmp_init_mib()所以如果没有一个叫init_snmp()

+0

谢谢,Grijesh需要调用netsnmp_init_mib()明确,为答案。 – pradipta