当前位置: 首页>>代码示例>>C++>>正文


C++ Vb类代码示例

本文整理汇总了C++中Vb的典型用法代码示例。如果您正苦于以下问题:C++ Vb类的具体用法?C++ Vb怎么用?C++ Vb使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Vb类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SetRequest

/////////////////////////////////////////////////////////////////////////////
// 函数:SetRequest                                                        //
// 说明:设置简单变量的结果                                                //
// 参数:无                                                                //
// 返回值:                                                                //
//      成功返回0,否则返回一个非0 值                                      //
/////////////////////////////////////////////////////////////////////////////
int BasicSNMP::SetRequest()
{
	int nResult = 0;
	Pdu pdu;                               // construct a Pdu object
	Vb vb;                                 // construct a Vb object
	vb.set_oid(oid);                      // set the Oid portion of the Vb
	vb.set_value(m_nOIDValue);                      // set the Oid portion of the Vb
	pdu += vb;   

	SnmpTarget *target;// = &ctarget;
	if(version ==version3)
	{//If SNMP Version Is 3
		nResult = InitUTarget();//Init UTarget
		pdu.set_security_level( m_nSecurityLevel);//Set the Security Level portion of Pdu
		pdu.set_context_name (contextName);//Set the Context Name portion of Pdu
		pdu.set_context_engine_id(contextEngineID);//Set the Context Engine ID portion of Pdu
		target = &utarget; //Set SNMP Target
	}
	else
	{
		target = &ctarget; //Set SNMP Target
	}

	nResult = pSnmp->set(pdu,*target);//Get Reques

	return nResult;
}
开发者ID:chengxingyu123,项目名称:ecc814,代码行数:34,代码来源:SNMP_lib.cpp

示例2: load_vbs

int wpdu::load_vbs(snmp_pdu *raw_pdu, const Pdu& pdu)
{
  int status = 0;

   // load up the payload
   // for all Vbs in list, add them to the pdu
   int vb_count;
   Vb tempvb;
   Oid tempoid;
   SmiLPOID smioid;
   SmiVALUE smival;

   vb_count = pdu.get_vb_count();

   for (int z = 0; z < vb_count; z++) {
      pdu.get_vb( tempvb, z);
      tempvb.get_oid( tempoid);
      smioid = tempoid.oidval();
      // what are we trying to convert here (vb oid part or value part)
      status = convert_vb_to_smival( tempvb, &smival );
      if ( status != SNMP_CLASS_SUCCESS)
         return status;

      // add the var to the raw pdu
      cmu_snmp::add_var(raw_pdu, smioid->ptr, (int) smioid->len, &smival);
      free_smival_descriptor( &smival);
    }

  return status;
}
开发者ID:helixum,项目名称:wow-cata,代码行数:30,代码来源:wpdu.cpp

示例3: iter

void getapp::result(Snmp *, int rc)
{
    Vb vb;
    if (rc < 0)
    {
      const char *ptr = snmp_.error_string();
      cout << "ASNMP:ERROR: get command failed reason: " << ptr << endl;
    }
    else
    {
      // check to see if there are any errors
      if (pdu_.get_error_status())
      {
        cout << "ERROR: agent replied as follows\n";
        cout << pdu_.agent_error_reason() << endl;
      }
      else
      {
        VbIter iter(pdu_);
        while (iter.next(vb))
        {
          cout << "\tOid = " << vb.to_string_oid() << "\n";
          cout << "\tValue = " << vb.to_string_value() << "\n";
        }
      }
    }
    cout << "\nASNMP:INFO: command completed normally.\n"<< endl;
    ACE_Reactor::instance()->end_reactor_event_loop();
}
开发者ID:Kintoun,项目名称:POSA,代码行数:29,代码来源:get_async.cpp

示例4: valid_

walkapp::walkapp(int argc, char *argv[]): valid_(0)
{
   Oid req, def_oid("1.3.6.1.2.1.1.1.0"); // default begin walk with MIBII
   if ( argc < 2)
     return;

   address_ = argv[argc - 1];
   if ( !address_.valid()) {
      cout << "ERROR: Invalid IPv4 address or DNS hostname: " \
     << argv[argc] << "\n";
      return;
   }

   ACE_Argv_Type_Converter to_tchar (argc, argv);
   ACE_Get_Opt get_opt (argc,
                        to_tchar.get_TCHAR_argv (),
                        ACE_TEXT ("o:c:r:t:"));
   for (int c; (c = get_opt ()) != -1; )
     switch (c)
       {
       case 'o':
         req = ACE_TEXT_ALWAYS_CHAR (get_opt.opt_arg());
         if (req.valid() == 0)
         cout << "ERROR: oid value: "
              << ACE_TEXT_ALWAYS_CHAR (get_opt.opt_arg())
              << "is not valid. using default.\n";
         break;

       case 'c':
         community_ = ACE_TEXT_ALWAYS_CHAR (get_opt.opt_arg());
         target_.set_read_community(community_);
         break;

       case 'r':
         target_.set_retry(ACE_OS::atoi (get_opt.opt_arg()));
         break;

       case 't':
         target_.set_timeout(ACE_OS::atoi (get_opt.opt_arg()));
         break;

       default:
         break;
       }

  Vb vb;                                  // construct a Vb object
  if (req.valid())
     vb.set_oid( req);                    // set the Oid portion of the Vb
  else {
     vb.set_oid( def_oid);               // set the Oid portion of the Vb
  }
  pdu_ += vb;
  vb.get_oid(oid_); // store for later use
  valid_ = 1;
}
开发者ID:asir6,项目名称:Colt,代码行数:55,代码来源:walk.cpp

示例5: gethostbyname

int getapp::run()
{

   //----------[ create a ASNMP session ]-----------------------------------
   if ( snmp_.valid() != SNMP_CLASS_SUCCESS) {
      cout << "\nASNMP:ERROR:Create session failed: "<<
          snmp_.error_string()<< "\n";
      return 1;
   }

   //--------[ build up ASNMP object needed ]-------------------------------
   if (address_.get_port() == 0)
     address_.set_port(DEF_AGENT_PORT);
   target_.set_address( address_);         // make a target using the address

   //-------[ issue the request, blocked mode ]-----------------------------
   cout << "\nASNMP:INFO:SNMP Version " << (target_.get_version()+ 1) << \
       " GET SAMPLE PROGRAM \nOID: " << oid_.to_string() << "\n";
   target_.get_address(address_); // target updates port used
   int rc;
   const char *name = address_.resolve_hostname(rc);

   cout << "Device: " << address_ << " ";

   //FUZZ: disable check_for_lack_ACE_OS
   cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n";
   //FUZZ: enable check_for_lack_ACE_OS

   cout << "[ Retries=" << target_.get_retry() << " \
        Timeout=" << target_.get_timeout() <<" ms " << "Community=" << \
         community_.to_string() << " ]"<< endl;

   if (snmp_.get( pdu_, target_) == SNMP_CLASS_SUCCESS) {
       Vb vb;
      // check to see if there are any errors
      if (pdu_.get_error_status()) {
        cout << "ERROR: agent replied as follows\n";
        cout << pdu_.agent_error_reason() << endl;
      }
      else {
        VbIter iter(pdu_);
        while (iter.next(vb)) {
 	  cout << "\tOid = " << vb.to_string_oid() << "\n";
 	  cout << "\tValue = " << vb.to_string_value() << "\n";
       }
     }
   }
   else {
    const char *ptr = snmp_.error_string();
    cout << "ASNMP:ERROR: get command failed reason: " << ptr << endl;
  }

  cout << "\nASNMP:INFO: command completed normally.\n"<< endl;
  return 0;
}
开发者ID:azraelly,项目名称:knetwork,代码行数:55,代码来源:get.cpp

示例6: snmp_

MibIter::MibIter(Snmp* snmp, Pdu& pdu, UdpTarget *target):
  snmp_(snmp), target_(target), pdu_(pdu), first_(0),
 valid_(0)
{
  // verify we have a valid oid to begin iterating with
  Oid oid;
  Vb vb;
  pdu.get_vb(vb, 0);
  vb.get_oid(oid);
  if (oid.valid())
    valid_ = 1;
}
开发者ID:asir6,项目名称:Colt,代码行数:12,代码来源:walk.cpp

示例7: valid_

getapp::getapp(int argc, char *argv[]): valid_(0)
{
   Oid req, def_oid("1.3.6.1.2.1.1.1.0");      // default is sysDescr
   if ( argc < 2) 
     return; 
    
   address_ = argv[argc - 1];
   if ( !address_.valid()) {
      cout << "ERROR: Invalid IPv4 address or DNS hostname: " \
     << argv[argc] << "\n";
      return;
   }

   ACE_Get_Opt get_opt (argc, argv, "o:c:r:t:p:");
   for (int c; (c = get_opt ()) != -1; )
     switch (c)
       {
       case 'o':
         req = get_opt.optarg;
         if (req.valid() == 0) 
         cout << "ERROR: oid value: " <<get_opt.optarg  \
              << "is not valid. using default.\n";
         break;

       case 'c':
         community_ = get_opt.optarg;
         target_.set_read_community(community_);
         break;

       case 'r':
         target_.set_retry(ACE_OS::atoi (get_opt.optarg));
         break;

       case 't':
         target_.set_timeout(ACE_OS::atoi (get_opt.optarg));
         break;

       default:
         break;
       }

  Vb vb;                                  // construct a Vb object
  if (req.valid()) 
     vb.set_oid( req);                    // set the Oid portion of the Vb
  else { 
     vb.set_oid( def_oid);               // set the Oid portion of the Vb
  }
  pdu_ += vb;
  vb.get_oid(oid_); // store for later use
  valid_ = 1;
}
开发者ID:dariuskylin,项目名称:utilityLib,代码行数:51,代码来源:get_async.cpp

示例8: gethostbyname

int walkapp::run()
{

   //----------[ create a ASNMP session ]-----------------------------------
   if ( snmp_.valid() != SNMP_CLASS_SUCCESS) {
      cout << "\nASNMP:ERROR:Create session failed: "<<
          snmp_.error_string()<< "\n";
      return 1;
   }

   //--------[ build up ASNMP object needed ]-------------------------------
   if (address_.get_port() == 0)
     address_.set_port(DEF_AGENT_PORT);
   target_.set_address( address_);         // make a target using the address

   //-------[ issue the request, blocked mode ]-----------------------------
   cout << "\nASNMP:INFO:SNMP Version " << (target_.get_version()+ 1) << \
       " WALK SAMPLE PROGRAM \nOID: " << oid_.to_string() << "\n";
   target_.get_address(address_); // target updates port used
   int rc;
   const char *name = address_.resolve_hostname(rc);

   cout << "Device: " << address_ << " ";

   //FUZZ: disable check_for_lack_ACE_OS
   cout << (rc ? "<< did not resolve via gethostbyname() >>" : name) << "\n";
   //FUZZ: enable check_for_lack_ACE_OS

   cout << "[ Retries=" << target_.get_retry() << " \
        Timeout=" << target_.get_timeout() <<" ms " << "Community=" << \
         community_.to_string() << " ]"<< endl;

   MibIter iter(&snmp_, pdu_, &target_);
   char *err_str = 0;
   Vb vb;
   unsigned ctr = 0;
   while (iter.next(vb, err_str))  {
     cout << "\tOid = " << vb.to_string_oid() << "\n";
     cout << "\tValue = " << vb.to_string_value() << "\n";
     ctr++;
   }

   if (!err_str) {
     cout << "ERROR: walk: " << err_str << endl;
     return 0;
   }

  cout << "ASNMP:INFO:command completed normally. ACE Rocks...\n"<< endl;
  return 0;
}
开发者ID:asir6,项目名称:Colt,代码行数:50,代码来源:walk.cpp

示例9: address

const string & SnmpDG::GetMibObject(const snmp_version  version, const SnmpPara& spr,  const string oid) const
{
	if(!m_inited_success)
	{
		return m_empty_object;
	}
	Snmp::socket_startup();

	UdpAddress address(spr.ip.c_str());
	//string myoid = oid;

	Pdu pdu;
	Vb vb;
	vb.set_oid(oid.c_str());//(myoid.c_str());
	pdu += vb;

	CTarget ctarget(address); 
	ctarget.set_version( version );
	ctarget.set_retry(spr.retry);           
	ctarget.set_timeout(spr.timeout); 
	ctarget.set_readcommunity(spr.community.c_str());
	SnmpTarget *target;
	target = &ctarget;

	int status;
	Snmp snmp(status, 0, false);
	if (status == SNMP_CLASS_SUCCESS)
	{
		if ((status = snmp.get( pdu, *target)) == SNMP_CLASS_SUCCESS)
		{
			pdu.get_vb( vb,0);
			//string oid_tmp = vb.get_printable_oid();
			m_mib_object = vb.get_printable_value();
		}
		else
		{
			m_mib_object = string("");
			SetLastError(status);
		}
	}
	else
	{
		m_mib_object = string("");
		SetLastError(status);
	}
	Snmp::socket_cleanup();  // Shut down socket subsystem
	return m_mib_object;
}
开发者ID:SiteView,项目名称:NNMQT,代码行数:48,代码来源:SnmpDG.cpp

示例10: get_error_status

const char *Pdu::agent_error_reason()
{
    int pdu_err = get_error_status();
    if (pdu_err == 0) // any real error?
        return "not in error state";

    int n_vbs = get_vb_count();
    Vb bad;
    get_vb(bad, get_error_index() -1); // not zero based??
    const char *pmsg =   Snmp::error_string(get_error_status());
    const char *id =   bad.to_string_oid();
    const char *val =  bad.to_string_value();
    const int HDR_SZ = 100;

    if (!output_) {
      int size = ACE_OS::strlen(pmsg) + ACE_OS::strlen(id) +
           ACE_OS::strlen(val);
      ACE_NEW_RETURN(output_, char[size + HDR_SZ], "");
    }
开发者ID:azraelly,项目名称:knetwork,代码行数:19,代码来源:pdu.cpp

示例11: get_response

// this routine makes up the brains of the agent
// it knows only the MIB II system group set of variables for a get operation
int agent_impl::get_response(Vb& vb)
{
  // these objects represent the MIB II system group per RFC 1213
   static Oid sysDescr("1.3.6.1.2.1.1.1.0"),
   sysObjectID("1.3.6.1.2.1.1.2.0"), sysUpTime("1.3.6.1.2.1.1.3.0"),
   sysContact("1.3.6.1.2.1.1.4.0"), sysName("1.3.6.1.2.1.1.5.0"),
   sysLocation("1.3.6.1.2.1.1.6.0"), sysServices("1.3.6.1.2.1.1.7.0");

  Oid oid;
  vb.get_oid(oid);
  if (oid == sysDescr) {
    OctetStr desc("ASNMP Prototype Agent 1.0");
    vb.set_value(desc);
  }
  else if (oid == sysObjectID) { // the IANA gives assigns Enterprise Numbers
    // see ftp://ftp.isi.edu/in-notes/iana/assignments/enterprise-numbers
    // for the official list of enterprise numbers. Then under this tree
    // assign a unique subtree to identify this agent
    Oid id("1.3.6.1.4.1.2533.9.1");
    vb.set_value(id);
  }
  else if (oid == sysUpTime) {
    ACE_Time_Value tv;
    agent_clock_.elapsed_time (tv);
    TimeTicks tt(tv.msec());
    vb.set_value(tt);
  }
  else if (oid == sysContact) {
    OctetStr contact("[email protected]");
    vb.set_value(contact);
  }
  else if (oid == sysName) {
    OctetStr fqdn("foo.org"); // extract this from the gethostbyname() TODO
    vb.set_value(fqdn);
  }
  else if (oid == sysLocation) {
    OctetStr loc("");
    vb.set_value(loc);
  }
  else if (oid == sysServices) {
    SnmpInt32 svcs(72);
    vb.set_value(svcs);
  }
  else
    return 1; // noSuchName

  return 0;
}
开发者ID:DOCGroup,项目名称:ACE_TAO,代码行数:50,代码来源:agent_impl.cpp

示例12: determine_vb

// determine the smi type and get a value from the user
int determine_vb( SmiUINT32 val, Vb &vb)
{
  char buffer[255];

  if (val == sNMP_SYNTAX_NOSUCHINSTANCE)
  {
    cout << "Instance does not exists but can be created.\n";
    cout << "Please enter one of the following types:\n\n";
    cout << "Integer:  " << sNMP_SYNTAX_INT << "\n";
    cout << "Bits:     " << sNMP_SYNTAX_BITS << "\n";
    cout << "STRING:   " << sNMP_SYNTAX_OCTETS << "\n";
    cout << "Oid:      " << sNMP_SYNTAX_OID << "\n";
    cout << "IpAddress:" << sNMP_SYNTAX_IPADDR << "\n\n";
    cout << "Please choose value type: ";
    cin >> val;
    vb.set_syntax(val);
  }
开发者ID:hajuli,项目名称:test_codes,代码行数:18,代码来源:snmpSet.cpp

示例13: nextvb

// return vb of next oid in agent tree, return 1 else return 0, reason set
int MibIter::next(Vb& vb, char *& reason)
{
  int rc;

  if (valid_ == 0) // not valid object
     return -1;

  // 1. poll for value
  if (first_ == 0) {
    rc = snmp_->get( pdu_, *target_);
    first_++;
  }
  else {
   rc = snmp_->get_next( pdu_, *target_);
  }

  if (rc != SNMP_CLASS_SUCCESS) {
       reason = const_cast <char*> (snmp_->error_string());
       return 0;
  }

  // 2. check for problems
  if (pdu_.get_error_status()) {
     reason = const_cast <char*> (pdu_.agent_error_reason());
     return 0;
  }

  // 3. return vb to caller
  pdu_.get_vb(vb, 0);
  Oid nextoid;
  vb.get_oid(nextoid); // and setup next oid to get
  Vb nextvb(nextoid);
  pdu_.delete_all_vbs();
  pdu_ += nextvb; // can't do set_vb as there are no entries to replace

  return 1; // ok
}
开发者ID:asir6,项目名称:Colt,代码行数:38,代码来源:walk.cpp

示例14: restore_vbs

int wpdu::restore_vbs(Pdu& pdu, const snmp_pdu *raw_pdu) const
{
   Vb tempvb;
   Oid tempoid;
   struct variable_list *vp;

   for(vp = raw_pdu->variables; vp; vp = vp->next_variable) {

    // extract the oid portion
    tempoid.set_data( (unsigned long *)vp->name,
                       ( unsigned int) vp->name_length);
    tempvb.set_oid( tempoid);

    // extract the value portion
    switch(vp->type) {

    // octet string
    case sNMP_SYNTAX_OCTETS:
     case sNMP_SYNTAX_OPAQUE:
    {
       OctetStr octets( (char *) vp->val.string,
                         (long) vp->val_len);
       tempvb.set_value( octets);
    }
    break;

    // object id
    case sNMP_SYNTAX_OID:
    {
         Oid oid( (unsigned long*) vp->val.objid,
              (int) vp->val_len);
      tempvb.set_value( oid);
    }
     break;

    // timeticks
    case sNMP_SYNTAX_TIMETICKS:
    {
       TimeTicks timeticks( (unsigned long) *(vp->val.integer));
       tempvb.set_value( timeticks);
    }
    break;

    // Gauge32
    case sNMP_SYNTAX_GAUGE32:
    {
       Gauge32 gauge32( (unsigned long) *(vp->val.integer));
       tempvb.set_value( gauge32);
    }
    break;

    // 32 bit counter
    case sNMP_SYNTAX_CNTR32:
    {
        Counter32 counter32( (unsigned long) *(vp->val.integer));
       tempvb.set_value( counter32);
      }
    break;

    // ip address
    case sNMP_SYNTAX_IPADDR:
    {
       char buffer[20];
       ACE_OS::sprintf( buffer,"%d.%d.%d.%d",
                        vp->val.string[0],
                        vp->val.string[1],
                        vp->val.string[2],
                        vp->val.string[3]);
       IpAddress ipaddress( buffer);
       tempvb.set_value( ipaddress);
    }
    break;

    // 32 bit integer
    case sNMP_SYNTAX_INT:
    {
       SnmpInt32 int32( (long) *(vp->val.integer));
      tempvb.set_value( int32);
    }
    break;

    // 32 bit unsigned integer
    case sNMP_SYNTAX_UINT32:
    {
      SnmpUInt32 uint32( (unsigned long) *(vp->val.integer));
      tempvb.set_value( uint32);
    }
     break;

    // v2 counter 64's
    case sNMP_SYNTAX_CNTR64:
     break;

    case sNMP_SYNTAX_NULL:
      tempvb.set_null();
    break;

    // v2 vb exceptions
    case sNMP_SYNTAX_NOSUCHOBJECT:
    case sNMP_SYNTAX_NOSUCHINSTANCE:
//.........这里部分代码省略.........
开发者ID:helixum,项目名称:wow-cata,代码行数:101,代码来源:wpdu.cpp

示例15: convert_vb_to_smival

int wpdu::convert_vb_to_smival( Vb &tempvb, SmiVALUE *smival )
{
  smival->syntax = tempvb.get_syntax();

  switch ( smival->syntax ) {

  case sNMP_SYNTAX_NULL:
    break;

    // case sNMP_SYNTAX_INT32:
  case sNMP_SYNTAX_INT:
    {
      SnmpInt32 tmp;
      tempvb.get_value(tmp);
      smival->value.sNumber = tmp;
    }
    break;

    //    case sNMP_SYNTAX_UINT32:
  case sNMP_SYNTAX_GAUGE32:
  case sNMP_SYNTAX_CNTR32:
  case sNMP_SYNTAX_TIMETICKS:
    {
      SnmpUInt32 tmp;
      tempvb.get_value(tmp);
      smival->value.uNumber = tmp;
    }
    break;

    // case Counter64
  case sNMP_SYNTAX_CNTR64:
    {
      Counter64 c64;
      tempvb.get_value(c64);
      smival->value.hNumber.hipart = c64.high();
      smival->value.hNumber.lopart = c64.low();
    }
    break;

   // OID syntax
  case sNMP_SYNTAX_OID:
    {
      Oid tmpoid;
      tmpoid.oidval();
      tempvb.get_value(tmpoid);
      SmiLPOID smi = tmpoid.oidval();
      smival->value.oid.len = tmpoid.length();
      ACE_NEW_RETURN(smival->value.oid.ptr,
                SmiUINT32 [smival->value.oid.len], 1);
      ACE_OS::memcpy(smival->value.oid.ptr, smi->ptr,
                     smival->value.oid.len *sizeof(SmiUINT32));
    }
    break;

  case sNMP_SYNTAX_BITS:
  case sNMP_SYNTAX_OCTETS:
  case sNMP_SYNTAX_IPADDR:
    {
      OctetStr os;
      tempvb.get_value(os);
      smival->value.string.ptr = 0;
      smival->value.string.len = os.length();
      if ( smival->value.string.len > 0 ) {
        ACE_NEW_RETURN(smival->value.string.ptr,
                SmiBYTE [smival->value.string.len], 1);
        if ( smival->value.string.ptr )  {
          for (int i=0; i<(int) smival->value.string.len ; i++)
            smival->value.string.ptr[i] = os[i];
        }
        else   {
          smival->syntax = sNMP_SYNTAX_NULL;  // invalidate the smival
          return SNMP_CLASS_RESOURCE_UNAVAIL;
        }
      }
    }
    break;

    default:
     ACE_DEBUG((LM_DEBUG, "wpdu::convert_vb_to_smival did not convert vb\n"));
     // ACE_ASSERT(0);
  } // switch

  return 0;
}
开发者ID:helixum,项目名称:wow-cata,代码行数:84,代码来源:wpdu.cpp


注:本文中的Vb类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。