本文整理汇总了C++中OctetStr::len方法的典型用法代码示例。如果您正苦于以下问题:C++ OctetStr::len方法的具体用法?C++ OctetStr::len怎么用?C++ OctetStr::len使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OctetStr
的用法示例。
在下文中一共展示了OctetStr::len方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: from_hex_string
//=======[ create an octet string from a hex string ]===================
OctetStr OctetStr::from_hex_string(const OctetStr &hex_string)
{
OctetStr val;
unsigned int p;
unsigned int hex_len = 0;
// make sure the string has at least one byte
if (hex_string.len() == 0) return val;
// allocate max needed space for copy without spaces
unsigned char *hex, *hex_ptr;
hex = hex_ptr = new unsigned char[hex_string.len()];
if (!hex) return val;
// delete spaces
const unsigned char *ptr = hex_string.smival.value.string.ptr;
for (p = hex_string.len(); p > 0; p--)
{
unsigned char c = *ptr++;
if (c != ' ')
{
*hex_ptr++ = c;
++hex_len;
}
}
// leading 0 may be omitted
if (hex_len % 2)
{
unsigned char c = hex[0];
ATOI(c);
val += c;
p = 1;
}
else
{
p = 0;
}
while (p < hex_len)
{
unsigned char c = hex[p++];
unsigned char d = hex[p++];
ATOI(c);
ATOI(d);
val += (c*16 + d);
}
delete[] hex;
return val;
}
示例2: vb
int agentppTestSparseCol3::prepare_set_request(Request* req, int& ind)
{
int status;
if ((status = MibLeaf::prepare_set_request(req, ind)) !=
SNMP_ERROR_SUCCESS) return status;
Vb vb(req->get_value(ind));
OctetStr v;
vb.get_value(v);
if (!(((v.len() >= 0) && (v.len() <= 255))))
return SNMP_ERROR_WRONG_LENGTH;
//--AgentGen BEGIN=agentppTestSparseCol3::prepare_set_request
//--AgentGen END
return SNMP_ERROR_SUCCESS;
}
示例3: get_entry
// Get the engine_id of the SNMP entity at the given host/port.
int v3MP::EngineIdTable::get_entry(OctetStr &engine_id,
const OctetStr &hostport) const
{
int port;
char host[MAX_HOST_NAME_LENGTH + 1];
char *ptr;
/* Check length */
if (hostport.len() > MAX_HOST_NAME_LENGTH)
return SNMPv3_MP_ERROR;
/* split up port from hostport */
strcpy(host, hostport.get_printable());
ptr = strstr((char*)host,"/");
if (!ptr)
return SNMPv3_MP_ERROR;
*ptr = '\0';
port = atol(ptr + 1);
/* Check for IPv6 address with [] */
if (host[0] == '[')
{
if (*(ptr -1) == ']')
{
*(ptr-1) = '\0';
return get_entry(engine_id, &(host[1]), port);
}
else
return SNMPv3_MP_ERROR;
}
return get_entry(engine_id, host, port);
}
示例4: usm
// Initialize the v3MP.
v3MP::v3MP(const OctetStr& snmpEngineID,
unsigned int engineBoots, int &construct_status)
: own_engine_id(0), usm(0)
{
if (I)
{
debugprintf(0, "v3MP: You must not create two objects of this class!");
construct_status = SNMPv3_MP_ERROR;
return;
}
I = this;
snmpUnknownSecurityModels = 0;
snmpInvalidMsgs = 0;
snmpUnknownPDUHandlers = 0;
int length = snmpEngineID.len();
if (length > MAXLENGTH_ENGINEID)
length = MAXLENGTH_ENGINEID;
own_engine_id = v3strcpy(snmpEngineID.data(), length);
own_engine_id_len = length;
own_engine_id_oct = snmpEngineID;
int result;
usm = new USM(engineBoots, snmpEngineID, this, &cur_msg_id, result);
if (cur_msg_id >= MAX_MPMSGID)
cur_msg_id = 1;
if ((!own_engine_id) || (!usm) || (result != SNMPv3_USM_OK))
{
construct_status = SNMPv3_MP_ERROR;
return;
}
cache.set_usm(usm);
construct_status = SNMPv3_MP_OK;
}
示例5: InitUTarget
/////////////////////////////////////////////////////////////////////////////
// 函数:InitUTarget //
// 说明:当SNMP版本是3时,初始化Utarget //
// 参数: //
// 无 //
// 返回: //
// 成功返回0,否则返回1 //
/////////////////////////////////////////////////////////////////////////////
int BasicSNMP::InitUTarget()
{
int nResult = 0;
utarget = address;//construct UTarger By address Class
utarget.set_version(version); // set the SNMP version SNMPV1 or V2 or V3
utarget.set_retry(retries); // set the number of auto retries
utarget.set_timeout(timeout); // set timeout
utarget.set_security_model(m_nSecurityModel);//Set Security Model
utarget.set_security_name( securityName);//Set Security Name (Auth Name)
OctetStr EgID;//Engine ID
//Get Engine ID
nResult = pSnmp->unicast_discovery(EgID,
(timeout + 99) / 100,
address, version, &community);
if(EgID.len()>0)
{//Engine ID Length Big Than 0
utarget.set_engine_id(EgID);//Set Engine ID
}
else
{//Less Than 0
return 1;//return Failed
}
return 0;//retrun Successed
}
示例6: debugprintf
// Parse the given buffer as a SNMPv3-Message.
int v3MP::snmp_parse(Snmp *snmp_session,
struct snmp_pdu *pdu,
unsigned char *inBuf,
int inBufLength,
OctetStr &securityEngineID,
OctetStr &securityName,
OctetStr &contextEngineID,
OctetStr &contextName,
long &securityLevel,
long &msgSecurityModel,
snmp_version &spp_version,
UdpAddress from_address)
{
debugprintf(3, "mp is parsing incoming message:");
debughexprintf(25, inBuf, inBufLength);
if (inBufLength > MAX_SNMP_PACKET)
return SNMPv3_MP_ERROR;
unsigned char type;
long version;
int origLength = inBufLength;
unsigned char *inBufPtr = inBuf;
long msgID, msgMaxSize;
unsigned char msgFlags;
Buffer<unsigned char> msgSecurityParameters(MAX_SNMP_PACKET);
Buffer<unsigned char> msgData(MAX_SNMP_PACKET);
int msgSecurityParametersLength = inBufLength, msgDataLength = inBufLength;
Buffer<unsigned char> scopedPDU(MAX_SNMP_PACKET);
int scopedPDULength = MAX_SNMP_PACKET;
long maxSizeResponseScopedPDU = 0;
struct SecurityStateReference *securityStateReference = NULL;
int securityParametersPosition;
int rc;
int errorCode = 0;
// get the type
inBuf = asn_parse_header( inBuf, &inBufLength, &type);
if (inBuf == NULL){
debugprintf(0, "snmp_parse: bad header");
return SNMPv3_MP_PARSE_ERROR;
}
if (type != (ASN_SEQ_CON)){
debugprintf(0, "snmp_parse: wrong auth header type");
return SNMPv3_MP_PARSE_ERROR;
}
if (origLength != inBufLength + (inBuf - inBufPtr)) {
debugprintf(0, "snmp_parse: wrong length of received packet");
return SNMPv3_MP_PARSE_ERROR;
}
// get the version
inBuf = asn_parse_int(inBuf, &inBufLength, &type, &version);
if (inBuf == NULL){
debugprintf(0, "snmp_parse: bad parse of version");
return SNMPv3_MP_PARSE_ERROR;
}
debugprintf(3, "Parsed length(%x), version(0x%lx)", inBufLength, version);
if ( version != SNMP_VERSION_3 )
return SNMPv3_MP_PARSE_ERROR;
spp_version = (snmp_version) version;
inBuf = asn1_parse_header_data(inBuf, &inBufLength,
&msgID, &msgMaxSize,
&msgFlags, &msgSecurityModel);
if (inBuf == NULL){
debugprintf(0, "snmp_parse: bad parse of msgHeaderData");
return SNMPv3_MP_PARSE_ERROR;
}
pdu->msgid = msgID;
if ((msgMaxSize < 484) || (msgMaxSize > 0x7FFFFFFF)) {
debugprintf(0, "snmp_parse: bad parse of msgMaxSize");
return SNMPv3_MP_PARSE_ERROR;
}
// do not allow larger messages than this entity can handle
if (msgMaxSize > MAX_SNMP_PACKET) msgMaxSize = MAX_SNMP_PACKET;
pdu->maxsize_scopedpdu = msgMaxSize;
inBuf = asn_parse_string( inBuf, &inBufLength, &type,
msgSecurityParameters.get_ptr(),
&msgSecurityParametersLength);
if (inBuf == NULL){
debugprintf(0, "snmp_parse: bad parse of msgSecurityParameters");
return SNMPv3_MP_PARSE_ERROR;
}
securityParametersPosition= SAFE_INT_CAST(inBuf - inBufPtr) - msgSecurityParametersLength;
// the rest of the message is passed directly to the security module
//.........这里部分代码省略.........
示例7: scopedPDU
// Do the complete process of encoding the given values into the buffer
// ready to send to the target.
int v3MP::snmp_build(struct snmp_pdu *pdu,
unsigned char *packet,
int *out_length, // maximum Bytes in packet
const OctetStr &securityEngineID,
const OctetStr &securityName,
int securityModel,
int securityLevel,
const OctetStr &contextEngineID,
const OctetStr &contextName)
{
Buffer<unsigned char> scopedPDU(MAX_SNMP_PACKET);
unsigned char *scopedPDUPtr = scopedPDU.get_ptr();
unsigned char globalData[MAXLENGTH_GLOBALDATA];
int globalDataLength = MAXLENGTH_GLOBALDATA;
int scopedPDULength, maxLen = *out_length;
Buffer<unsigned char> buf(MAX_SNMP_PACKET);
unsigned char *bufPtr = buf.get_ptr();
long bufLength = 0, rc;
int msgID;
int cachedErrorCode = SNMPv3_MP_OK;
struct SecurityStateReference *securityStateReference = NULL;
int isRequestMessage = 0;
if ((pdu->command == GET_REQ_MSG) || (pdu->command == GETNEXT_REQ_MSG) ||
(pdu->command == SET_REQ_MSG) || (pdu->command == GETBULK_REQ_MSG) ||
(pdu->command == TRP_REQ_MSG) || (pdu->command == INFORM_REQ_MSG) ||
(pdu->command == TRP2_REQ_MSG))
isRequestMessage = 1;
if (isRequestMessage) {
if (securityEngineID.len() == 0) {
// First Contact => use user noAuthNoPriv and USM
securityLevel = SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV;
securityModel = SNMP_SECURITY_MODEL_USM;
}
cur_msg_id_lock.lock();
msgID = cur_msg_id;
cur_msg_id++;
if (cur_msg_id >= MAX_MPMSGID)
cur_msg_id = 1;
cur_msg_id_lock.unlock();
#ifdef INVALID_MSGID
LOG_BEGIN(loggerModuleName, ERROR_LOG | 1);
LOG("*** WARNING: Using constant MessageID! ***");
LOG_END;
msgID = 0xdead;
#endif
if (securityEngineID.len() == 0) {
// length==0 => SecurityLevel == noAuthNoPriv
// => we do not send any management information
// => delete VariableBinding
clear_pdu(pdu);
}
}
else {
// it is a response => search for request
debugprintf(3, "Looking up cache");
msgID = pdu->msgid;
rc = cache.get_entry(msgID, CACHE_REMOTE_REQ,
&cachedErrorCode, &securityStateReference);
if (rc != SNMPv3_MP_OK) {
debugprintf(0, "mp: Cache lookup error");
return SNMPv3_MP_MATCH_ERROR;
}
}
LOG_BEGIN(loggerModuleName, DEBUG_LOG | 5);
LOG("v3MP: Building message with (SecurityEngineID) (securityName) (securityLevel) (contextEngineID) (contextName)");
LOG(securityEngineID.get_printable());
LOG(securityName.get_printable());
LOG(securityLevel);
LOG(contextEngineID.get_printable());
LOG(contextName.get_printable());
LOG_END;
// encode vb in buf
scopedPDUPtr = build_vb(pdu, scopedPDUPtr, &maxLen);
if (!scopedPDUPtr)
{
LOG_BEGIN(loggerModuleName, WARNING_LOG | 1);
LOG("v3MP: Error encoding vbs into buffer");
LOG_END;
return SNMPv3_MP_BUILD_ERROR;
}
scopedPDULength = SAFE_INT_CAST(scopedPDUPtr - scopedPDU.get_ptr());
//build dataPDU in buf
maxLen = *out_length;
scopedPDUPtr = scopedPDU.get_ptr();
bufPtr = build_data_pdu(pdu, bufPtr, &maxLen, scopedPDUPtr, scopedPDULength);
//.........这里部分代码省略.........
示例8: AddEntry
int CNotifyEventQueue::AddEntry(Snmp *snmp,
const OidCollection &trapids,
const TargetCollection &targets)
{
SnmpSynchronize _synchronize(*this); // instead of REENTRANT()
if (snmp != m_snmpSession)
{
debugprintf(0, "WARNING: Adding notification event for other Snmp object");
}
if (!m_msgCount)
{
m_notify_addr = snmp->get_listen_address();
m_notify_addr.set_port(m_listen_port);
int status = SNMP_CLASS_SUCCESS;
// This is the first request to receive notifications
// Set up the socket for the snmp trap port (162) or the
// specified port through set_listen_port()
bool is_v4_address = (m_notify_addr.get_ip_version() == Address::version_ipv4);
if (is_v4_address)
{
struct sockaddr_in mgr_addr;
// open a socket to be used for the session
if ((m_notify_fd = socket(AF_INET, SOCK_DGRAM,0)) < 0)
{
#ifdef WIN32
int werr = WSAGetLastError();
if (EMFILE == werr ||WSAENOBUFS == werr || ENFILE == werr)
status = SNMP_CLASS_RESOURCE_UNAVAIL;
else if (WSAEHOSTDOWN == werr)
status = SNMP_CLASS_TL_FAILED;
else
status = SNMP_CLASS_TL_UNSUPPORTED;
#else
if (EMFILE == errno || ENOBUFS == errno || ENFILE == errno)
status = SNMP_CLASS_RESOURCE_UNAVAIL;
else if (EHOSTDOWN == errno)
status = SNMP_CLASS_TL_FAILED;
else
status = SNMP_CLASS_TL_UNSUPPORTED;
#endif
cleanup();
return status;
}
// set up the manager socket attributes
unsigned long inaddr = inet_addr(IpAddress(m_notify_addr).get_printable());
memset(&mgr_addr, 0, sizeof(mgr_addr));
mgr_addr.sin_family = AF_INET;
mgr_addr.sin_addr.s_addr = inaddr; // was htonl( INADDR_ANY);
mgr_addr.sin_port = htons(m_notify_addr.get_port());
#ifdef CYGPKG_NET_OPENBSD_STACK
mgr_addr.sin_len = sizeof(mgr_addr);
#endif
// bind the socket
if (bind(m_notify_fd, (struct sockaddr *) &mgr_addr,
sizeof(mgr_addr)) < 0)
{
#ifdef WIN32
int werr = WSAGetLastError();
if (WSAEADDRINUSE == werr)
status = SNMP_CLASS_TL_IN_USE;
else if (WSAENOBUFS == werr)
status = SNMP_CLASS_RESOURCE_UNAVAIL;
else if (werr == WSAEAFNOSUPPORT)
status = SNMP_CLASS_TL_UNSUPPORTED;
else if (werr == WSAENETUNREACH)
status = SNMP_CLASS_TL_FAILED;
else if (werr == EACCES)
status = SNMP_CLASS_TL_ACCESS_DENIED;
else
status = SNMP_CLASS_INTERNAL_ERROR;
#else
if (EADDRINUSE == errno)
status = SNMP_CLASS_TL_IN_USE;
else if (ENOBUFS == errno)
status = SNMP_CLASS_RESOURCE_UNAVAIL;
else if (errno == EAFNOSUPPORT)
status = SNMP_CLASS_TL_UNSUPPORTED;
else if (errno == ENETUNREACH)
status = SNMP_CLASS_TL_FAILED;
else if (errno == EACCES)
status = SNMP_CLASS_TL_ACCESS_DENIED;
else
{
debugprintf(0, "Uncatched errno value %d, returning internal error.",
errno);
status = SNMP_CLASS_INTERNAL_ERROR;
}
#endif
debugprintf(0, "Fatal: could not bind to %s",
m_notify_addr.get_printable());
cleanup();
return status;
}
//.........这里部分代码省略.........
示例9: saveBootCounter
// Store the bootCounter of the given engineID in the given file.
int saveBootCounter(const char *fileName,
const OctetStr &engineId, const unsigned int boot)
{
char line[MAX_LINE_LEN];
char tmpFileName[MAXLENGTH_FILENAME];
char encoded[MAXLENGTH_ENGINEID * 2 + 2];
int found = FALSE;
int len = engineId.len();
FILE *file_in, *file_out;
tmpFileName[0] = 0;
sprintf(tmpFileName, "%s.tmp",fileName);
if (len > MAXLENGTH_ENGINEID)
{
LOG_BEGIN(ERROR_LOG | 3);
LOG("saveBootCounter: engine id too long, ignoring last bytes (len) (max)");
LOG(len);
LOG(MAXLENGTH_ENGINEID);
LOG_END;
len = MAXLENGTH_ENGINEID;
}
file_in = fopen(fileName, "r");
if (!file_in)
{
file_in = fopen(fileName, "w");
if (!file_in)
{
LOG_BEGIN(ERROR_LOG | 3);
LOG("saveBootCounter: could not create new file (file)");
LOG(fileName);
LOG_END;
return SNMPv3_FILECREATE_ERROR;
}
LOG_BEGIN(INFO_LOG | 3);
LOG("saveBootCounter: created new file (file)");
LOG(fileName);
LOG_END;
fputs("# \n",file_in);
fputs("# This file was created by an SNMP++v3 application,\n", file_in);
fputs("# it is used to store the snmpEngineBoots counters.\n", file_in);
fputs("# \n",file_in);
fputs("# Lines starting with '#' are comments.\n", file_in);
fputs("# The snmpEngineBoots counters are stored as\n", file_in);
fputs("# <encoded snmpEngineId> <bootCounter>\n", file_in);
fputs("# \n", file_in);
fclose(file_in);
file_in = fopen(fileName, "r");
}
file_out = fopen(tmpFileName, "w");
if ((file_in) && (file_out))
{
encodeString(engineId.data(), len, encoded);
encoded[len*2] = ' ';
encoded[len*2 + 1] = 0;
while (fgets(line, MAX_LINE_LEN, file_in))
{
line[MAX_LINE_LEN - 1] = 0;
if (!strncmp(encoded, line, len*2 + 1))
{
if (found)
{
LOG_BEGIN(WARNING_LOG | 3);
LOG("saveBootCounter: Removing doubled entry (file) (line)");
LOG(fileName);
LOG(line);
LOG_END;
continue;
}
sprintf(line,"%s%i\n", encoded, boot);
fputs(line, file_out);
found = TRUE;
continue;
}
fputs(line, file_out);
}
if (!found)
{
sprintf(line, "%s%i\n", encoded, boot);
fputs(line, file_out);
}
fclose(file_in);
fclose(file_out);
#ifdef WIN32
_unlink(fileName);
#endif
if (rename(tmpFileName, fileName))
{
LOG_BEGIN(ERROR_LOG | 1);
LOG("saveBootCounter: Failed to rename temporary file (tmp file) (file)");
LOG(tmpFileName);
//.........这里部分代码省略.........
示例10: getBootCounter
// Read the bootCounter of the given engineID stored in the given file.
int getBootCounter(const char *fileName,
const OctetStr &engineId, unsigned int &boot)
{
char line[MAX_LINE_LEN];
char encoded[MAXLENGTH_ENGINEID * 2 + 2];
int len = engineId.len();
FILE *file;
boot = 0;
file = fopen(fileName, "r");
if (!file)
{
LOG_BEGIN(ERROR_LOG | 1);
LOG("getBootCounter: Could not open (file)");
LOG(fileName);
LOG_END;
return SNMPv3_FILEOPEN_ERROR;
}
if (len > MAXLENGTH_ENGINEID)
{
LOG_BEGIN(ERROR_LOG | 3);
LOG("getBootCounter: engine id too long, ignoring last bytes (len) (max)");
LOG(len);
LOG(MAXLENGTH_ENGINEID);
LOG_END;
len = MAXLENGTH_ENGINEID;
}
encodeString(engineId.data(), len, encoded);
encoded[2*len]=' ';
encoded[2*len + 1] = 0;
while (fgets(line, MAX_LINE_LEN, file))
{
line[MAX_LINE_LEN - 1] = 0;
/* ignore comments */
if (line[0]=='#')
continue;
if (!strncmp(encoded, line, len*2 + 1))
{
/* line starts with engineId */
char* ptr = line;
/* skip until first space */
while (*ptr != 0 && *ptr != ' ')
ptr++;
if (*ptr == 0)
{
fclose(file);
LOG_BEGIN(ERROR_LOG | 3);
LOG("getBootCounter: Illegal line: (file) (line)");
LOG(fileName);
LOG(line);
LOG_END;
return SNMPv3_FILE_ERROR;
}
boot = atoi(ptr);
fclose(file);
LOG_BEGIN(DEBUG_LOG | 3);
LOG("getBootCounter: found entry (file) (engine id) (boot counter)");
LOG(fileName);
LOG(engineId.get_printable());
LOG(boot);
LOG_END;
return SNMPv3_OK;
}
}
fclose(file);
LOG_BEGIN(WARNING_LOG | 3);
LOG("getBootCounter: No entry found (file) (engine id)");
LOG(fileName);
LOG(engineId.get_printable());
LOG_END;
return SNMPv3_NO_ENTRY_ERROR;
}
示例11: convertVbToSmival
//------------[ convert SNMP++ VB to WinSNMP smiVALUE ]----------------
int convertVbToSmival( const Vb &tempvb, SmiVALUE *smival )
{
smival->syntax = tempvb.get_syntax();
switch ( smival->syntax ) {
// case sNMP_SYNTAX_NULL
case sNMP_SYNTAX_NULL:
case sNMP_SYNTAX_NOSUCHOBJECT:
case sNMP_SYNTAX_NOSUCHINSTANCE:
case sNMP_SYNTAX_ENDOFMIBVIEW:
break;
// case sNMP_SYNTAX_INT32:
case sNMP_SYNTAX_INT:
tempvb.get_value(smival->value.sNumber);
break;
// case sNMP_SYNTAX_UINT32:
case sNMP_SYNTAX_GAUGE32:
case sNMP_SYNTAX_CNTR32:
case sNMP_SYNTAX_TIMETICKS:
// case sNMP_SYNTAX_UINT32:
tempvb.get_value(smival->value.uNumber);
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;
case sNMP_SYNTAX_BITS:
case sNMP_SYNTAX_OCTETS:
case sNMP_SYNTAX_OPAQUE:
case sNMP_SYNTAX_IPADDR:
{
OctetStr os;
tempvb.get_value(os);
smival->value.string.ptr = NULL;
smival->value.string.len = os.len();
if ( smival->value.string.len > 0 )
{
smival->value.string.ptr
= (SmiLPBYTE) new unsigned char [smival->value.string.len];
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;
case sNMP_SYNTAX_OID:
{
Oid oid;
tempvb.get_value(oid);
smival->value.oid.ptr = NULL;
smival->value.oid.len = oid.len();
if ( smival->value.oid.len > 0 )
{
smival->value.oid.ptr
= (SmiLPUINT32) new unsigned long [ smival->value.oid.len];
if ( smival->value.oid.ptr )
{
for (int i=0; i<(int)smival->value.oid.len ; i++)
smival->value.oid.ptr[i] = oid[i];
}
else
{
smival->syntax = sNMP_SYNTAX_NULL; // invalidate the smival
return SNMP_CLASS_RESOURCE_UNAVAIL;
}
}
}
break;
default:
return SNMP_CLASS_INTERNAL_ERROR;
}
return SNMP_CLASS_SUCCESS;
}
示例12: load
//.........这里部分代码省略.........
char addrString[256];
if (gethostname(addrString, 255) == 0)
{
ip_addr = addrString;
addr_set = TRUE;
}
}
struct sockaddr_in agent_addr; // agent address socket struct
// prepare the agent address
memset(&agent_addr, 0, sizeof(agent_addr));
agent_addr.sin_family = AF_INET;
if (addr_set)
{
agent_addr.sin_addr.s_addr
= inet_addr(((IpAddress &)ip_addr).IpAddress::get_printable());
LOG_BEGIN(INFO_LOG | 7);
LOG("SNMPMessage: Setting v1 trap address");
LOG(((IpAddress &)ip_addr).IpAddress::get_printable());
LOG_END;
}
raw_pdu->agent_addr = agent_addr;
//-----[ compute generic trap value ]-------------------------------
// determine the generic value
// 0 - cold start
// 1 - warm start
// 2 - link down
// 3 - link up
// 4 - authentication failure
// 5 - egpneighborloss
// 6 - enterprise specific
Oid trapid;
pdu->get_notify_id( trapid);
if ( !trapid.valid() || trapid.len() < 2 )
{
snmp_free_pdu( raw_pdu);
return SNMP_CLASS_INVALID_NOTIFYID;
}
raw_pdu->specific_type=0;
if ( trapid == coldStart)
raw_pdu->trap_type = 0; // cold start
else if ( trapid == warmStart)
raw_pdu->trap_type = 1; // warm start
else if( trapid == linkDown)
raw_pdu->trap_type = 2; // link down
else if ( trapid == linkUp)
raw_pdu->trap_type = 3; // link up
else if ( trapid == authenticationFailure )
raw_pdu->trap_type = 4; // authentication failure
else if ( trapid == egpNeighborLoss)
raw_pdu->trap_type = 5; // egp neighbor loss
else {
raw_pdu->trap_type = 6; // 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.len()-1)];
trapid.trim(1);
if ( trapid[(int)(trapid.len()-1)] == 0 )
trapid.trim(1);
enterprise = trapid;
}
if ( raw_pdu->trap_type !=6)
pdu->get_notify_enterprise( enterprise);