请教个问题.scalar_int.c 获取值的问题.
时间:2010-09-03
来源:互联网
本帖最后由 unix_pro 于 2010-09-03 11:07 编辑
小弟纯粹新手,各位多多指教.
我想让 test这个函数能够 得到 example1这个值.
example1这个值不是 已经定义好的,而是 snmp set过的值.
http://linux.die.net/man/3/netsnmp_instance 这里有 netsnmp_register_int_instance 定义.
复制代码
小弟纯粹新手,各位多多指教.
我想让 test这个函数能够 得到 example1这个值.
example1这个值不是 已经定义好的,而是 snmp set过的值.
http://linux.die.net/man/3/netsnmp_instance 这里有 netsnmp_register_int_instance 定义.
- /** @example scalar_int.c
- * This example creates some scalar registrations that allows
- * some simple variables to be accessed via SNMP. In a more
- * realistic example, it is likely that these variables would also be
- * manipulated in other ways outside of SNMP gets/sets.
- *
- * If this module is compiled into an agent, you should be able to
- * issue snmp commands that look something like (authentication
- * information not shown in these commands):
- *
- * - snmpget localhost netSnmpExampleInteger.0
- * - netSnmpExampleScalars = 42
- *
- * - snmpset localhost netSnmpExampleInteger.0 = 1234
- * - netSnmpExampleScalars = 1234
- *
- * - snmpget localhost netSnmpExampleInteger.0
- * - netSnmpExampleScalars = 1234
- *
- */
-
- /*
- * start be including the appropriate header files
- */
-
- #include <net-snmp/net-snmp-config.h>
- #include <net-snmp/net-snmp-includes.h>
- #include <net-snmp/agent/net-snmp-agent-includes.h>
-
- /*
- * Then, we declare the variables we want to be accessed
- */
- static int example1 = 42; /* default value */
- //int test(int);
- void test (int);
- /*
- * our initialization routine, automatically called by the agent
- * (to get called, the function name must match init_FILENAME())
- */
- void
- init_scalar_int(void)
- {
- /*
- * the OID we want to register our integer at. This should be a
- * fully qualified instance. In our case, it's a scalar at:
- * NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger.0 (note the
- * trailing 0 which is required for any instantiation of any
- * scalar object)
- */
- oid my_registration_oid[] =
- { 1, 3, 6, 1, 4, 1, 17711, 2, 1, 1, 0 };
-
- /*
- * a debugging statement. Run the agent with -Dexample_scalar_int to see
- * the output of this debugging statement.
- */
- DEBUGMSGTL(("example_scalar_int",
- "Initalizing example scalar int. Default value = %d\n",
- example1));
-
- /*
- * the line below registers our "example1" variable above as
- * accessible and makes it writable. A read only version of the
- * same registration would merely call
- * register_read_only_int_instance() instead.
- *
- * If we wanted a callback when the value was retrieved or set
- * (even though the details of doing this are handled for you),
- * you could change the NULL pointer below to a valid handler
- * function.
- */
- netsnmp_register_int_instance("my example int variable",
- my_registration_oid,
- OID_LENGTH(my_registration_oid),
- &example1, test(example1)); //调用其他执行函数
-
- DEBUGMSGTL(("example_scalar_int",
- "Done initalizing example scalar int\n"));
-
-
- }
-
-
- void test (int example1){
- static char tmp[50];
- sprintf(tmp,"iwconfig ath1 essid eth%d",&example1);
- system(tmp);
- }
-
- /*
- int test (void){
- static char tmp[50];
- int essidvar = &example1;
- sprintf(tmp,"iwconfig ath1 essid eth%d",essidvar);
- system(tmp);
- }
- */
- //int test (void)
- //{
- // system("echo b > /var/sys.conf");
- //return EXIT_SUCCESS;
- //}
作者: unix_pro 发布时间: 2010-09-03
- int
- netsnmp_register_int_instance(const char *name,
- oid * reg_oid, size_t reg_oid_len,
- int *it, Netsnmp_Node_Handler * subhandler)
- {
- netsnmp_handler_registration *myreg;
-
- myreg = get_reg(name, "int_handler", reg_oid, reg_oid_len, it,
- HANDLER_CAN_RWRITE, netsnmp_instance_int_handler,
- subhandler, NULL);
- return netsnmp_register_instance(myreg);
- }
作者: unix_pro 发布时间: 2010-09-03
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28