net-snmp示例代码来解析MIB文件并从中提取陷阱相关信息 [英] net-snmp sample code to parse MIB file and extract trap related information from it
本文介绍了net-snmp示例代码来解析MIB文件并从中提取陷阱相关信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Windows上使用net-snmp C库。我想从MIB文件解析陷阱相关的信息。
I am using the net-snmp C library on Windows. I want to parse trap-related information from the MIB files.
我需要一些示例代码来做到这一点。我在 http://www.net-snmp.org/ 上找不到任何有用的内容。 p>
I need some sample code to do this. I didn't find anything useful on http://www.net-snmp.org/
推荐答案
这里是一些使用net-snmp库解析MIB文件的示例代码。
在使用此代码之前,您需要在项目属性中引用或添加net-snmp的Include和Lib目录:
Here is some sample code to parse MIB files using the net-snmp library. Before you use this code you need to refer or add the Include and Lib directories of net-snmp in your project properties:
#include "stdafx.h"
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/definitions.h>
#include <net-snmp/library/tools.h>
#include <net-snmp/mib_api.h>
#include <net-snmp/library/mib.h>
#include <net-snmp/library/parse.h>
int _tmain(int argc, _TCHAR* argv[])
{
struct tree *tp;
struct tree *tree_head = NULL ;
FILE *fp = NULL;
char str[] = "c:\\MyMIBFileDir\\My.mib";
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_WARNINGS , 2);
netsnmp_ds_toggle_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_SAVE_MIB_DESCRS);
netsnmp_init_mib();
add_mibdir("c:\\MyMIBFileDir\\");
tree_head = read_mib(str);
if ( tree_head )
{
//Successfully parsed the MIB
}
// Full traversal of the subtree
for (tp = tree_head; tp; tp = tp->next_peer)
// Here you can do custom parsing
fclose(fp);
return 0;
}
这篇关于net-snmp示例代码来解析MIB文件并从中提取陷阱相关信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文