本文整理汇总了C++中OctetStr::length方法的典型用法代码示例。如果您正苦于以下问题:C++ OctetStr::length方法的具体用法?C++ OctetStr::length怎么用?C++ OctetStr::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OctetStr
的用法示例。
在下文中一共展示了OctetStr::length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: set_trap_info
int wpdu::set_trap_info(snmp_pdu *raw_pdu, const Pdu& pdu) const
{
Oid enterprise;
Oid trapid; // validate caller has set this correctly
pdu.get_notify_id( trapid);
if ( !trapid.valid() || trapid.length() < 2 ) {
cmu_snmp::free_pdu( raw_pdu);
return SNMP_CLASS_INVALID_NOTIFYID;
}
raw_pdu->specific_type=0;
// TODO: object should emit numeric instead of this kind of mess...
if ( trapid == coldStart)
raw_pdu->trap_type = V1_COLD_START; // cold start
else if ( trapid == warmStart)
raw_pdu->trap_type = V1_WARM_START; // warm start
else if( trapid == linkDown)
raw_pdu->trap_type = V1_LINK_DOWN; // link down
else if ( trapid == linkUp)
raw_pdu->trap_type = V1_LINK_UP; // link up
else if ( trapid == authenticationFailure )
raw_pdu->trap_type = V1_AUTH_FAILURE; // authentication failure
else if ( trapid == egpNeighborLoss)
raw_pdu->trap_type = V1_EGP_NEIGHBOR_LOSS; // egp neighbor loss
else {
raw_pdu->trap_type = V1_ENT_SPECIFIC; // enterprise specific
// last oid subid is the specific value
// if 2nd to last subid is "0", remove it
// enterprise is always the notify oid prefix
raw_pdu->specific_type = (int) trapid[(int) (trapid.length() - 1)];
trapid.trim(1);
if ( trapid[(int)(trapid.length() - 1)] == 0 )
trapid.trim(1);
enterprise = trapid;
}
if ( raw_pdu->trap_type != V1_ENT_SPECIFIC)
pdu.get_notify_enterprise( enterprise);
if ( enterprise.length() > 0) {
// note!! To the contrary, enterprise OID val is
// copied here and raw_pdu->enterprise is freed in free_pdu
// as it should be (HDN)
// these are hooks into an SNMP++ oid
// and therefor the raw_pdu enterprise
// should not free them. null them out!!
SmiLPOID rawOid;
rawOid = enterprise.oidval();
// HDN - enterprise is a local object, cannot simply assign pointer
//raw_pdu->enterprise = rawOid->ptr;
raw_pdu->enterprise_length = (int) rawOid->len;
ACE_NEW_RETURN(raw_pdu->enterprise,
oid[raw_pdu->enterprise_length],-1);
ACE_OS::memcpy((char *)raw_pdu->enterprise,(char *)rawOid->ptr,
raw_pdu->enterprise_length * sizeof(oid));
}
TimeTicks timestamp;
pdu.get_notify_timestamp( timestamp);
raw_pdu->time = ( unsigned long) timestamp;
// HDN - set agent addr using the local hostname if possible
char localHostName[MAXHOSTNAMELEN];
Snmp::get_host_name(localHostName, MAXHOSTNAMELEN);
if (ACE_OS::strlen(localHostName) > 0) {
GenAddress addr(localHostName);
OctetStr octet;
addr.to_octet(octet);
ACE_OS::memcpy(&(raw_pdu->agent_addr.sin_addr),
octet.data(),
octet.length());
}
return 0;
}