我有以下代码来解析mib文件夹中的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();有什么用

还告诉我


我将使用哪个功能来更改MIB搜索目录。
netsnmp_set_mib_directory()函数的用途是什么。
如果我想添加一个MIB,则可以仅给出该MIB的路径,还是必须将其包括在以前所有MIB都存在的路径中,因为这样做时我会出错。
read_all_mibs() and read_mib()和有什么不一样?


请告诉我一些想法。

最佳答案

它试图包含您的MIB依赖的其他MIB。可能是找到了您特定的MIB。只要在您的默认MIB所在的位置添加另一个add_mibdir()

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

关于c - 如何更改默认的MIB搜索路径?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13284316/

10-11 08:09