本文整理汇总了C++中OctetStr类的典型用法代码示例。如果您正苦于以下问题:C++ OctetStr类的具体用法?C++ OctetStr怎么用?C++ OctetStr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OctetStr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: 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;
}
示例4: LOG
// Get the engineID of the SNMP entity at the given host/port.
int v3MP::EngineIdTable::get_entry(OctetStr &engine_id,
const OctetStr &host, int port) const
{
if (!table)
return SNMPv3_MP_NOT_INITIALIZED;
BEGIN_REENTRANT_CODE_BLOCK_CONST;
int i, found = 0;
for (i = 0; i < entries; i++)
if ((table[i].port == port) &&
(table[i].host == host))
{
found=1;
break;
}
if (!found)
{
LOG_BEGIN(loggerModuleName, INFO_LOG | 4);
LOG("v3MP::EngineIdTable: Dont know engine id for (host) (port)");
LOG(host.get_printable());
LOG(port);
LOG_END;
return SNMPv3_MP_ERROR;
}
engine_id = table[i].engine_id;
return SNMPv3_MP_OK;
}
示例5: to
//===============[ not equivlence operator overloaded ]===============
int operator!=(const OctetStr &lhs, const char *rhs)
{
OctetStr to(rhs);
if (lhs.smival.value.string.len != to.smival.value.string.len)
return true;
return (lhs.nCompare(to.smival.value.string.len, to) != 0);
}
示例6:
//===============[ greater than > overloaded ]========================
bool operator>( const OctetStr &lhs, const OctetStr &rhs)
{
if( lhs.left_comparison( rhs.smival.value.string.len, rhs)>0)
return true;
else
return false;
}
示例7: to
//===============[ greater than > operator overloaded ]===============
bool operator>( const OctetStr &lhs,const char *rhs)
{
OctetStr to( rhs);
if ( lhs.left_comparison( to.smival.value.string.len,to)>0)
return true;
else
return false;
}
示例8: 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;
}
示例9: Name
/////////////////////////////////////////////////////////////////////////////
// 函数: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
}
示例10: debugprintf
// Send a report message.
int v3MP::send_report(unsigned char* scopedPDU, int scopedPDULength,
struct snmp_pdu *pdu, int errorCode, int sLevel,
int sModel, OctetStr &sName,
UdpAddress &destination, Snmp *snmp_session)
{
debugprintf(2, "v3MP::send_report: Sending report message.");
unsigned char *data;
int dataLength;
int pdu_type = 0;
unsigned char cEngineID[MAXLENGTH_ENGINEID+1];
unsigned char cName[MAXLENGTH_CONTEXT_NAME+1];
int cEngineIDLength = MAXLENGTH_ENGINEID+1;
int cNameLength = MAXLENGTH_CONTEXT_NAME+1;
debugprintf(2, "v3MP::send_report: securityLevel %d",sLevel);
if (scopedPDULength != MAX_SNMP_PACKET)
{
// try to get scopedPDU and PDU
data = asn1_parse_scoped_pdu(scopedPDU, &scopedPDULength,
cEngineID, &cEngineIDLength,
cName, &cNameLength);
if (data == NULL) {
debugprintf(1, "mp: Error while trying to parse scopedPDU!");
cEngineID[0] = '\0';
cEngineIDLength = 0;
cName[0] = '\0';
cNameLength = 0;
// Dont send encrypted report if decryption failed:
//if (sLevel == SNMP_SECURITY_LEVEL_AUTH_PRIV)
// sLevel = SNMP_SECURITY_LEVEL_AUTH_NOPRIV;
}
else { // data != NULL
dataLength = scopedPDULength;
// parse data of scopedPDU
snmp_parse_data_pdu(pdu, data, dataLength);
pdu_type = pdu->command;
if (!data) {
debugprintf(0, "mp: Error while trying to parse PDU!");
}
} // end of: if (data == NULL)
} // end if (scopedPDULength != MAX_SNMP_PACKET)
else { // scopedPDULength == MAX_SNMP_PACKET
cEngineID[0] = '\0';
cEngineIDLength = 0;
cName[0] = '\0';
cNameLength = 0;
pdu->reqid = 0;
}
clear_pdu(pdu); // Clear pdu and free all content
debugprintf(4, "pdu->reqid = %ld",pdu->reqid);
pdu->errstat = 0;
pdu->errindex = 0;
pdu->command = REPORT_MSG;
Vb counterVb;
Oid counterOid;
SmiLPOID smioid;
SmiVALUE smival;
switch (errorCode) {
case SNMPv3_MP_INVALID_MESSAGE:
case SNMPv3_USM_PARSE_ERROR: {
counterVb.set_oid(oidSnmpInvalidMsgs);
counterVb.set_value(Counter32(get_stats_invalid_msgs()));
break;
}
case SNMPv3_USM_NOT_IN_TIME_WINDOW:
case SNMPv3_MP_NOT_IN_TIME_WINDOW: {
counterVb.set_oid(oidUsmStatsNotInTimeWindows);
counterVb.set_value(Counter32(usm->get_stats_not_in_time_windows()));
break;
}
case SNMPv3_USM_DECRYPTION_ERROR: {
counterVb.set_oid(oidUsmStatsDecryptionErrors);
counterVb.set_value(Counter32(usm->get_stats_decryption_errors()));
//sLevel = SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV;
break;
}
case SNMPv3_USM_AUTHENTICATION_ERROR:
case SNMPv3_USM_AUTHENTICATION_FAILURE: {
counterVb.set_oid(oidUsmStatsWrongDigests);
counterVb.set_value(Counter32(usm->get_stats_wrong_digests()));
//sLevel = SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV;
break;
}
case SNMPv3_USM_UNKNOWN_ENGINEID:
case SNMPv3_MP_INVALID_ENGINEID: {
//sLevel = SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV;
counterVb.set_oid(oidUsmStatsUnknownEngineIDs);
counterVb.set_value(Counter32(usm->get_stats_unknown_engine_ids()));
break;
}
case SNMPv3_MP_UNSUPPORTED_SECURITY_MODEL: {
//.........这里部分代码省略.........
示例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: 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;
}
示例13: 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);
//.........这里部分代码省略.........
示例14: _synchronize
//.........这里部分代码省略.........
else if (EHOSTDOWN == errno)
status = SNMP_CLASS_TL_FAILED;
else
status = SNMP_CLASS_TL_UNSUPPORTED;
#endif
cleanup();
return status;
}
#ifdef NOTIFY_SET_IPV6_V6ONLY
int on = 1;
if (setsockopt(m_notify_fd, IPPROTO_IPV6, IPV6_V6ONLY,
(char *)&on, sizeof(on)) == -1)
{
LOG_BEGIN(loggerModuleName, WARNING_LOG | 1);
LOG("Could not set option IPV6_V6ONLY on notify socket (errno)");
LOG(errno);
LOG_END;
}
else
{
LOG_BEGIN(loggerModuleName, INFO_LOG | 3);
LOG("Have set IPV6_V6ONLY option on notify socket");
LOG_END;
}
#endif
// set up the manager socket attributes
struct sockaddr_in6 mgr_addr;
memset(&mgr_addr, 0, sizeof(mgr_addr));
unsigned int scope = 0;
OctetStr addrstr = ((IpAddress &)m_notify_addr).IpAddress::get_printable();
if (m_notify_addr.has_ipv6_scope())
{
scope = m_notify_addr.get_scope();
int y = addrstr.len() - 1;
while ((y>0) && (addrstr[y] != '%'))
{
addrstr.set_len(addrstr.len() - 1);
y--;
}
if (addrstr[y] == '%')
addrstr.set_len(addrstr.len() - 1);
}
if (inet_pton(AF_INET6, addrstr.get_printable(),
&mgr_addr.sin6_addr) < 0)
{
LOG_BEGIN(loggerModuleName, ERROR_LOG | 1);
LOG("Notify transport: inet_pton returns (errno) (str)");
LOG(errno);
LOG(strerror(errno));
LOG_END;
cleanup();
return SNMP_CLASS_INVALID_ADDRESS;
}
mgr_addr.sin6_family = AF_INET6;
mgr_addr.sin6_port = htons(m_notify_addr.get_port());
mgr_addr.sin6_scope_id = scope;
// bind the socket
示例15: return
//===============[ greater than >= overloaded ]=======================
int operator>=(const OctetStr &lhs, const OctetStr &rhs)
{
int maxlen = lhs.smival.value.string.len > rhs.smival.value.string.len
? lhs.smival.value.string.len : rhs.smival.value.string.len;
return (lhs.nCompare(maxlen, rhs) >=0);
}