免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3239 | 回复: 3
打印 上一主题 下一主题

扩展net-snmp[难道我的真的有问题] [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-08-30 11:45 |只看该作者 |倒序浏览
问题:
一下代码可以通过编译。通过MIB浏览器可以获得第一个值,但是没有办法获得第二个值,请教各位,为什么啊?
浏览器提示:

  1. Sent get request to 192.168.124.42 : 161
  2. Request Failed: Get Response PDU received from 192.168.124.42
  3. Error Indication in response: There is no such variable name in this mib.
  4. Errindex: 1
复制代码



一下是源代码

  1. /*
  2. * Note: this file originally auto-generated by mib2c using
  3. *        : mib2c.old-api.conf 14476 2006-04-18 17:36:51Z hardaker $
  4. */

  5. #include <net-snmp/net-snmp-config.h>
  6. #include <net-snmp/net-snmp-includes.h>
  7. #include <net-snmp/agent/net-snmp-agent-includes.h>
  8. #include "netSNMPMIB.h"

  9. /*
  10. * netSNMPMIB_variables_oid:
  11. *   this is the top level oid that we want to register under.  This
  12. *   is essentially a prefix, with the suffix appearing in the
  13. *   variable below.
  14. */

  15. oid             netSNMPMIB_variables_oid[] = { 1, 3, 6, 1, 4, 1, 8888 };

  16. /*
  17. * variable4 netSNMPMIB_variables:
  18. *   this variable defines function callbacks and type return information
  19. *   for the netSNMPMIB mib section
  20. */

  21. struct variable7 netSNMPMIB_variables[] = {
  22.     /*
  23.      * magic number        , variable type , ro/rw , callback fn  , L, oidsuffix
  24.      */
  25. #define VER                1
  26.     {VER, ASN_OCTET_STR, RONLY, var_netSNMPMIB, 3, {1, 1, 1}},
  27. #define READCOM                2
  28.     {READCOM, ASN_OCTET_STR, RONLY, var_netSNMPMIB, 3, {1, 1, 2}},

  29. };

  30. /*
  31. * (L = length of the oidsuffix)
  32. */


  33. /** Initializes the netSNMPMIB module */
  34. void
  35. init_netSNMPMIB(void)
  36. {

  37.     DEBUGMSGTL(("netSNMPMIB", "Initializing\n"));

  38.     /*
  39.      * register ourselves with the agent to handle our mib tree
  40.      */
  41.     REGISTER_MIB("netSNMPMIB", netSNMPMIB_variables, variable4,
  42.                  netSNMPMIB_variables_oid);

  43.     /*
  44.      * place any other initialization junk you need here
  45.      */
  46. }

  47. /*
  48. * var_netSNMPMIB():
  49. *   This function is called every time the agent gets a request for
  50. *   a scalar variable that might be found within your mib section
  51. *   registered above.  It is up to you to do the right thing and
  52. *   return the correct value.
  53. *     You should also correct the value of "var_len" if necessary.
  54. *
  55. *   Please see the documentation for more information about writing
  56. *   module extensions, and check out the examples in the examples
  57. *   and mibII directories.
  58. */
  59. unsigned char  *
  60. var_netSNMPMIB(struct variable *vp,
  61.                oid * name,
  62.                size_t *length,
  63.                int exact, size_t *var_len, WriteMethod ** write_method)
  64. {
  65.     /*
  66.      * variables we may use later
  67.      */
  68.     static long     long_ret;
  69.     static u_long   ulong_ret;
  70.     static unsigned char string[SPRINT_MAX_LEN];
  71.     static oid      objid[MAX_OID_LEN];
  72.     static struct counter64 c64;

  73.     if (header_generic(vp, name, length, exact, var_len, write_method)
  74.         == MATCH_FAILED)
  75.         return NULL;
  76.                
  77.     /*
  78.      * this is where we do the value assignments for the mib results.
  79.      */
  80.     switch (vp->magic) {

  81. //×××××××××××××××××××××××××从这里开始修改的
  82.     case VER:       
  83.             {
  84.         sprintf(string,"testjjj");            /* XXX */
  85.         *var_len = strlen(string);
  86.         return (u_char *) & long_ret;
  87.        }
  88.       break;
  89.     case READCOM:
  90.             {       
  91.         sprintf(string,"com");
  92.         long_ret = atol(string);         /* XXX */
  93.         
  94.         return (u_char *) &long_ret;
  95.        }
  96.       break;
  97. //*****************************修改结束
  98.     default:
  99.         ERROR_MSG("");
  100.     }
  101.     return NULL;
  102. }

复制代码


各位高手帮帮忙啦

论坛徽章:
0
2 [报告]
发表于 2007-08-30 17:04 |只看该作者
定义mib:
struct variable3 netSNMPMIB_variables

REGISTER_MIB("netSNMPMIB", netSNMPMIB_variables, variable3,
                 netSNMPMIB_variables_oid);

论坛徽章:
0
3 [报告]
发表于 2007-09-03 10:21 |只看该作者
楼上的可以说清楚一点吗?我还是不知道怎么修改我的代码啊!
多谢回复了

论坛徽章:
0
4 [报告]
发表于 2007-09-03 13:41 |只看该作者
你在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赋值吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP