免费注册 查看新帖 |

Chinaunix

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

【请教】ucd-snmp处理两个index表的问题,在线等 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-09-27 15:04 |只看该作者 |倒序浏览
表信息如下:
Sequences:       
                1: rhZoneEntId - Integer32(2 - integer (32 bit))
                2: rhZoneIPId - Integer32(2 - integer (32 bit))
                3: rhZoneIPAddr - IpAddress(64 - IP address)
                4: rhZoneIPMask - IpAddress(64 - IP address)
                5: rhZoneIPIsPrimary - TruthValue(2 - integer (32 bit))
                6: rhZoneIPIsExclude - TruthValue(2 - integer (32 bit))
Indexes:  1: rhZoneEntId
                2: rhZoneIPId
该表中有两个index,1: rhZoneEntId和2: rhZoneIPId
现在的情况是,我返回值之后,发现oid少了一个index:rhZoneIPId ,比如我获取其中一个ip地址:
.1.3.6.1.4.1.9816.2.3.1.3.1 = 1.1.1.1
实际上加上rhZoneIPId 这个index,应该是:.1.3.6.1.4.1.9816.2.3.1.3.1 .1= 1.1.1.1

代码如下:

unsigned char *
var_rhZonesIPTable(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 unsigned char string[SPRINT_MAX_LEN];
//  static oid objid[MAX_OID_LEN];

        int zone_num,zone_iptable,i;
        unsigned char zoneip[4];
        unsigned char zonenetmask[4];
        unsigned char ipmask[16];
        struct in_addr ipaddr;
        char line[512];
       
        rc = sqlite_get_table_printf(db_conf, "select id,name,ip,netmask,active from %s order by id",&result, &nrow, &ncol, &errmsg, TABLE_ANTIATK);
        if(rc != SQLITE_OK)
                return NULL;

        if(nrow > 0)
        {
                zone_iptable=atoi(result[nrow*ncol]);
                for(i=1;i<=nrow;i++)
                {
                        db_rc.id=atoi(result[i*ncol]);
                        strcpy(db_rc.name,result[i*ncol+1]);
                        strcpy(db_rc.ip,result[i*ncol+2]);
                        strcpy(db_rc.netmask,result[i*ncol+3]);
                        db_rc.active=atoi(result[i*ncol+4]);
                }
                sqlite_free_table(result);
        }

  /*
   * This assumes that the table is a 'simple' table.
   *        See the implementation documentation for the meaning of this.
   *        You will need to provide the correct value for the TABLE_SIZE parameter
   *
   * If this table does not meet the requirements for a simple table,
   *        you will need to provide the replacement code yourself.
   *        Mib2c is not smart enough to write this for you.
   *    Again, see the implementation documentation for what is required.
   */
  if (header_simple_table(vp,name,length,exact,var_len,write_method, zone_iptable)
                                                == MATCH_FAILED )
    return NULL;

        zone_num=name[*length-1];

  /*
   * this is where we do the value assignments for the mib results.
   */
  switch(vp->magic) {


    case RHZONEENTID:
        
        long_ret=db_rc[zone_num].id;
        return (unsigned char *) &long_ret;

    case RHZONEIPID:
        
        long_ret = 1;
        return (unsigned char *) &long_ret;

    case RHZONEIPADDR:
        
        strcpy(ipmask,db_rc[zone_num].ip);

        sprintf(line,"echo %s %s > /dev/null",ipmask,db_rc[zone_num].ip);
        system(line);

        inet_aton(ipmask,&ipaddr);
        strcpy(zoneip,&ipaddr);

        *var_len = 4;
        return (unsigned char *) zoneip;

    case RHZONEIPMASK:
        
        strcpy(ipmask,db_rc[zone_num].netmask);
       
        inet_aton(ipmask,&ipaddr);
        strcpy(zonenetmask,&ipaddr);

        *var_len = 4;
        return (unsigned char *) zonenetmask;

    case RHZONEIPISPRIMARY:
        
        long_ret = 1;
        return (unsigned char *) &long_ret;

    case RHZONEIPISEXCLUDE:
        
        long_ret = 2;
        return (unsigned char *) &long_ret;


    default:
      ERROR_MSG("");
  }
  return NULL;
}


请问怎样才能正确的返回oid呢?即红色部分:.1.3.6.1.4.1.9816.2.3.1.3.1 .1= 1.1.1.1
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP