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

时间:2012-11-08 07:19:19

标签: c snmp net-snmp mib

我有以下代码来解析名为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都存在的路径中,因为这样做时会出现错误。< / LI>
  4. read_all_mibs() and read_mib();
  5. 之间的区别是什么?

    请告诉我一些想法。

1 个答案:

答案 0 :(得分:0)

它正在尝试包含您的MIB所依赖的其他MIB。它可能会找到你特定的MIB。只需在默认MIB中添加另一个add_mibdir()

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