|
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_IPADDR: // 不能和OCTETS一起编码IPADDR,要独立编码
case sNMP_SYNTAX_OCTETS:
{
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 = os;
}
else {
smival->syntax = sNMP_SYNTAX_NULL; // invalidate the smival
return SNMP_CLASS_RESOURCE_UNAVAIL;
}
}
}
break;
case sNMP_SYNTAX_IPADDR: // 独立编码IPADDR
{
IpAddress address;
OctetStr os;
tempvb.get_value(address);
address.to_octet(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 = os;
}
else {
smival->syntax = sNMP_SYNTAX_NULL; // invalidate the smival
return SNMP_CLASS_RESOURCE_UNAVAIL;
}
}
}
default:
ACE_DEBUG((LM_DEBUG, "wpdu::convert_vb_to_smival did not convert vb\n"));
// ACE_ASSERT(0);
} // switch
return 0;
} |
|