繁体   English   中英

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

[英]Why the description of the snmp oid giving “null”?

我的以下代码无法正常工作,因为我想使用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.10snmpFrameworkMIBoid ,但是你可以看到上面我程序中的节点得到了null作为description

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

默认情况下, 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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM