如何更改默认MIB搜索路径?

问题描述 投票:0回答:1

我有以下代码来解析名为 mibp 的文件夹中的 mib。

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <string.h>
#include<stdlib.h>

int main(int argc, char ** argv)
{

FILE *fp=NULL;
fp=fopen("/root/mib2.txt","w");
if (fp == NULL )
{
printf("error");;
exit(2);
}  

netsnmp_init_mib();

add_mibdir("/home/pradipta/snmp/share/snmp/mibp");
//netsnmp_set_mib_directory( "/home/pradipta/snmp/share/snmp/mibp" );

struct tree *node;
//node=read_all_mibs();
node=read_mib("/home/pradipta/snmp/share/snmp/mibp/EtherLike-MIB.txt");
print_subtree(fp,node,0);
}

当我运行这个时,我的错误如下

 MIB search path: /root/.snmp/mibs:/home/pradipta/snmp/share/snmp/mibs
Cannot find module (SNMPv2-MIB): At line 1 in (none)
Cannot find module (IF-MIB): At line 1 in (none)
Cannot find module (IP-MIB): At line 1 in (none)
Cannot find module (TCP-MIB): At line 1 in (none)
Cannot find module (UDP-MIB): At line 1 in (none)
Cannot find module (SNMP-VIEW-BASED-ACM-MIB): At line 1 in (none)
Cannot find module (SNMP-COMMUNITY-MIB): At line 1 in (none)
Cannot find module (SNMPv2-SMI): At line 6 in /home/pradipta/snmp/share/snmp/mibp/EtherLike-MIB.txt
Cannot find module (SNMPv2-TC): At line 10 in /home/pradipta/snmp/share/snmp/mibp/EtherLike-MIB.txt
Cannot find module (IF-MIB): At line 12 in /home/pradipta/snmp/share/snmp/mibp/EtherLike-MIB.txt
Did not find 'mib-2' in module #-1 (/home/pradipta/snmp/share/snmp/mibp/EtherLike-MIB.txt)
Did not find 'transmission' in module #-1 (/home/pradipta/snmp/share/snmp/mibp/EtherLike-MIB.txt)
Did not find 'TruthValue' in module #-1 (/home/pradipta/snmp/share/snmp/mibp/EtherLike-MIB.txt)
Did not find 'ifIndex' in module #-1 (/home/pradipta/snmp/share/snmp/mibp/EtherLike-MIB.txt)
Did not find 'InterfaceIndex' in module #-1 (/home/pradipta/snmp/share/snmp/mibp/EtherLike-MIB.txt)
Unlinked OID in EtherLike-MIB: etherMIB ::= { mib-2 35 }
Undefined identifier: mib-2 near line 14 of /home/pradipta/snmp/share/snmp/mibp/EtherLike-MIB.txt
Unlinked OID in EtherLike-MIB: dot3 ::= { transmission 7 }
Undefined identifier: transmission near line 118 of /home/pradipta/snmp/share/snmp/mibp/EtherLike-MIB.txt

我已将文件夹名称

mibs
更改为
mibp
并在代码中添加上述内容以测试 mib 搜索路径的更改是否有效。为什么会出现此错误。

有什么用

netsnmp_init_mib();

也告诉我

  1. 我将使用哪个功能来更改 MIB 搜索目录。
  2. 函数有什么用
    netsnmp_set_mib_directory()
    .
  3. 如果我想添加一个 MIB,那么是否可以仅提供该 MIB 的路径,或者必须将其包含在先前存在所有 MIB 的路径中,因为这样做时我会出错。
  4. 还有什么区别
    read_all_mibs() and read_mib()
    ;

请告诉我一些想法。

c snmp net-snmp mib
1个回答
0
投票

它试图包含您的 MIB 所依赖的其他 MIB。它可能会找到您的特定 MIB。只需在默认 MIB 所在的位置添加另一个

add_mibdir()

add_mibdir("/usr/local/where/my/default/RFC/mibs/are");

© www.soinside.com 2019 - 2024. All rights reserved.