Get OID's type (syntax) from MIB using Net-SNMP API

自作多情 提交于 2019-12-12 09:43:08

问题


How can I get the syntax type and read/write access for an OID using NET-SNMP API?

I am writing an SNMP tool that reads and sets values on a remote machine using SNMP protocol. Before setting the value, I need to check its type and access permissions (whether it is allowed to write this value on the server or not) from the MIB file.

Unfortunately, I could not find any mention regarding how to do this in the Net-SNMP documentation.


回答1:


Roughly speaking:

  oid name[128];
  size_t name_length = OID_LENGTH(name);
  strict tree *tp;

  read_objid("sysContact.0", &name, &name_length);
  tp = get_tree(name, name_length, get_tree_head();
  

Then look through the net-snmp/library/parse.h file for the tree structure and all the good data you need is inside it.

Also see the apps/snmptranslate.c file for further examples.




回答2:


What Wes said should probably work for what you're trying to do. Alternatively, in your implementation, to check the input type of the set value explicitly, use netsnmp_check_vb_type(). For checking permissions, net-snmp will throw a notWritable error if you try to modify a field without write access (as defined in the relevant MIB).



来源:https://stackoverflow.com/questions/4786682/get-oids-type-syntax-from-mib-using-net-snmp-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!