net-snmp 示例代码解析 MIB 文件并从中提取陷阱相关信息

发布于 2024-12-03 16:47:21 字数 176 浏览 9 评论 0原文

我在 Windows 上使用 net-snmp C 库。我想从 MIB 文件中解析与陷阱相关的信息。

我需要一些示例代码来执行此操作。我在 http://www.net-snmp.org/ 上没有找到任何有用的内容

I am using the net-snmp C library on Windows. I want to parse trap-related information from the MIB files.

I need some sample code to do this. I didn't find anything useful on http://www.net-snmp.org/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梅倚清风 2024-12-10 16:47:21

以下是使用 net-snmp 库解析 MIB 文件的一些示例代码。
在使用此代码之前,您需要在项目属性中引用或添加 net-snmp 的 Include 和 Lib 目录:

#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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文