为什么snmp oid的描述给出“null”?

时间:2012-11-30 08:55:16

标签: c linux net-snmp mib

我的以下代码无效,因为我想使用Net-Snmp库获取节点的描述。

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

我得到所有节点的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.10oid的{​​{1}},但您可以在上面看到我的程序中的节点为snmpFrameworkMIB的null。

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

1 个答案:

答案 0 :(得分:2)

默认情况下,net-snmp MIB解析器无法启用DESCRIPTION字符串存储 特别是因为它需要更多的内存。

打印说明书:

snmp_set_save_descriptions(1);

在致电init_snmp()以强制保存DESCRIPTION子句之前。

函数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()因此,如果正在呼叫netsnmp_init_mib() <,则无需明确调用init_snmp() / p>