c - net-snmp解析代码,如何解析MIB?

标签 c network-programming snmp net-snmp nms

我在学习 net-snmp 代码库。解析MIB。

parse.c 和 parse.h 代码中保留了一个哈希桶。 (索引桶(树列表))
还有一个树结构,它包含一个 next 指针,指向 名称哈希列表中的下一个节点。

struct tree{  
    .
    .
    struct tree    *next;       // Next node in hashed list of names 
    int             modid;     // The module containing this node 
}

我打印了 MIB,

SNMP-FRAMEWORK-MIB:snmpFrameworkMIB(10) type=24 Next-> ' ipSystemStatsHCOctetGroup ipSystemStatsOutFragReqds ifStackGroup2 ifOutErrors '

我不明白 Next-> 之后出现的对象名称之间有什么关系?

对象名称在一起的标准是什么? 我目前还不清楚代码。

什么是调制解调器?它的值不等于模块 OID!

注意:为了纯粹遍历 MIB 树中的目的,给出了 *child、*parent 和 *peer!此外,modid 不是 OID 的一部分。

parse.h 中名为“模块兼容性”的数据结构:

struct module_compatability {
        const char     *old_module;
        const char     *new_module;
        const char     *tag;    /* NULL implies unconditional replacement,
                                 * otherwise node identifier or prefix */
        size_t          tag_len;        /* 0 implies exact match (or unconditional) */
        struct module_compatability *next;      /* linked list */
    };

这个结构有什么用?在什么意义上兼容?

最佳答案

我也使用 Net-snmp 有一段时间了,我与您分享我的观察。
可能这会对你有所帮助。

<强>1。结构树 *next;

struct tree    * next; /* Next node in hashed list of names */   

Net-snmp 功能提供通过模块的“名称”进行查询,
Object 当查询的对象名称(字符串)为ASCII时,

$ snmptranslate -On -IR bundleSize  
  -   
  -  
  .1.3.6.1.4.1.26149.2.1.2.2.1.9  

它有一个大小为 128 的哈希表(内部)数据结构“桶”。

哈希函数:

name_hash(str*) - return some of ASCII value. 

然后这个哈希值被传递到宏NBUCKET(x) - 返回索引(0-127)。 冲突通过如下链接解决。 bucket[i]->next->next->next.......


此代码存在于 parse.c --

tree->next'bucket' 以下列方式管理:

 tp->hash = name_hash(tp->name); // Fist find hash value as some of ASCII
 b = BUCKET(tp->hash);           // map hash value into (0-127)
 if (buckets[b])                 // check for collision 
     tp->next = buckets[b];     // collision is resolved ny chan chain 
 buckets[b] = tp;           // new coming node become first node in chain

<强>2。 int modid;

  • 包含这个节点的模块。
    • 有一个'struct module'类型的链表
    • modid 是模块链表中的序号。
    • 序列号从0开始。
    • modid=模块开始读取的编号
    • parse.h 中定义的函数 'find_module(int modid)' 返回节点地址 存储有关模块的信息。

parse.h 中名为“模块兼容性”的数据结构:

This is an array of structre 'module compatability' use to store compatible 
basic MIB name (RFC's defined).   

const char     *old_module;   // snmp-v1  
const char     *new_module;   // snmp-v2

关于c - net-snmp解析代码,如何解析MIB?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12798871/

相关文章:

c - 将数组传递给 C 中的函数

c - 这是怎么编译的

network-programming - 有没有人使用 UDP jumbograms 实现了解决方案?

c++ - 日期格式的时间标记?

c - 发送到 : Operation not permitted: netsnmp

c - net-snmp api 使用用户的凭据

c - 在 C 语言的 GTK+ TreeView 中使用 Pango 标记

c - 在同一行中包含 Ctrl+Z 后,getchar() 继续接受输入

linux - 源 IP 地址过滤应该在应用层本身实现还是由应用层委托(delegate)给防火墙

python - 如何为 python 客户端提供来自 python 服务器的端口号