扩展net-snmp[难道我的真的有问题]
问题:
一下代码可以通过编译。通过MIB浏览器可以获得第一个值,但是没有办法获得第二个值,请教各位,为什么啊?
浏览器提示:
- Sent get request to 192.168.124.42 : 161
- Request Failed: Get Response PDU received from 192.168.124.42
- Error Indication in response: There is no such variable name in this mib.
- Errindex: 1
复制代码
一下是源代码
- /*
- * Note: this file originally auto-generated by mib2c using
- * : mib2c.old-api.conf 14476 2006-04-18 17:36:51Z hardaker $
- */
- #include <net-snmp/net-snmp-config.h>
- #include <net-snmp/net-snmp-includes.h>
- #include <net-snmp/agent/net-snmp-agent-includes.h>
- #include "netSNMPMIB.h"
- /*
- * netSNMPMIB_variables_oid:
- * this is the top level oid that we want to register under. This
- * is essentially a prefix, with the suffix appearing in the
- * variable below.
- */
- oid netSNMPMIB_variables_oid[] = { 1, 3, 6, 1, 4, 1, 8888 };
- /*
- * variable4 netSNMPMIB_variables:
- * this variable defines function callbacks and type return information
- * for the netSNMPMIB mib section
- */
- struct variable7 netSNMPMIB_variables[] = {
- /*
- * magic number , variable type , ro/rw , callback fn , L, oidsuffix
- */
- #define VER 1
- {VER, ASN_OCTET_STR, RONLY, var_netSNMPMIB, 3, {1, 1, 1}},
- #define READCOM 2
- {READCOM, ASN_OCTET_STR, RONLY, var_netSNMPMIB, 3, {1, 1, 2}},
- };
- /*
- * (L = length of the oidsuffix)
- */
- /** Initializes the netSNMPMIB module */
- void
- init_netSNMPMIB(void)
- {
- DEBUGMSGTL(("netSNMPMIB", "Initializing\n"));
- /*
- * register ourselves with the agent to handle our mib tree
- */
- REGISTER_MIB("netSNMPMIB", netSNMPMIB_variables, variable4,
- netSNMPMIB_variables_oid);
- /*
- * place any other initialization junk you need here
- */
- }
- /*
- * var_netSNMPMIB():
- * This function is called every time the agent gets a request for
- * a scalar variable that might be found within your mib section
- * registered above. It is up to you to do the right thing and
- * return the correct value.
- * You should also correct the value of "var_len" if necessary.
- *
- * Please see the documentation for more information about writing
- * module extensions, and check out the examples in the examples
- * and mibII directories.
- */
- unsigned char *
- var_netSNMPMIB(struct variable *vp,
- oid * name,
- size_t *length,
- int exact, size_t *var_len, WriteMethod ** write_method)
- {
- /*
- * variables we may use later
- */
- static long long_ret;
- static u_long ulong_ret;
- static unsigned char string[SPRINT_MAX_LEN];
- static oid objid[MAX_OID_LEN];
- static struct counter64 c64;
- if (header_generic(vp, name, length, exact, var_len, write_method)
- == MATCH_FAILED)
- return NULL;
- /*
- * this is where we do the value assignments for the mib results.
- */
- switch (vp->magic) {
- //×××××××××××××××××××××××××从这里开始修改的
- case VER:
- {
- sprintf(string,"testjjj"); /* XXX */
- *var_len = strlen(string);
- return (u_char *) & long_ret;
- }
- break;
- case READCOM:
- {
- sprintf(string,"com");
- long_ret = atol(string); /* XXX */
- return (u_char *) &long_ret;
- }
- break;
- //*****************************修改结束
- default:
- ERROR_MSG("");
- }
- return NULL;
- }
复制代码
各位高手帮帮忙啦
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
定义mib:
struct variable3 netSNMPMIB_variables
REGISTER_MIB("netSNMPMIB", netSNMPMIB_variables, variable3,
netSNMPMIB_variables_oid);
楼上的可以说清楚一点吗?我还是不知道怎么修改我的代码啊!
多谢回复了
你在1.3.6.1.4.1.8888.1.1.1想放入 testjjj,1.3.6.1.4.1.8888.1.1.2放入com,
case VER:
{
sprintf(string,"testjjj"); /* XXX */
*var_len = strlen(string);
return (u_char *) & long_ret;
}
break;
返回时,该给long_ret赋值吧