本文整理汇总了C++中OctetStr::get_printable方法的典型用法代码示例。如果您正苦于以下问题:C++ OctetStr::get_printable方法的具体用法?C++ OctetStr::get_printable怎么用?C++ OctetStr::get_printable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OctetStr
的用法示例。
在下文中一共展示了OctetStr::get_printable方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: debugprintf
//.........这里部分代码省略.........
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: {
counterVb.set_oid(oidSnmpUnknownSecurityModels);
counterVb.set_value(Counter32(get_stats_unknown_security_models()));
sModel = SNMP_SECURITY_MODEL_USM;
sLevel = SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV;
break;
}
case SNMPv3_USM_UNKNOWN_SECURITY_NAME: {
counterVb.set_oid(oidUsmStatsUnknownUserNames);
counterVb.set_value(Counter32(usm->get_stats_unknown_user_names()));
sLevel = SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV;
debugprintf(2, "Report: SecurityName: %s",sName.get_printable());
break;
}
case SNMPv3_USM_UNSUPPORTED_SECURITY_LEVEL: {
counterVb.set_oid(oidUsmStatsUnsupportedSecLevels);
counterVb.set_value(Counter32(usm->get_stats_unsupported_sec_levels()));
sLevel = SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV;
break;
}
default: {
counterVb.set_oid(oidSnmpInvalidMsgs);
counterVb.set_value(Counter32(get_stats_invalid_msgs()));
sModel = SNMP_SECURITY_MODEL_USM;
sLevel = SNMP_SECURITY_LEVEL_NOAUTH_NOPRIV;
sName.set_data(0, 0);
debugprintf(2, "ErrorCode was %i in snmp_parse", errorCode);
}
} // end switch
counterVb.get_oid(counterOid);
smioid = counterOid.oidval();
int status = convertVbToSmival(counterVb, &smival);
if (status != SNMP_CLASS_SUCCESS) {
return SNMPv3_MP_ERROR;
}
snmp_add_var(pdu, smioid->ptr,
(int) smioid->len, &smival);
freeSmivalDescriptor(&smival);
Buffer<unsigned char> sendbuffer(MAX_SNMP_PACKET);
int sendbufferlen= MAX_SNMP_PACKET;
status = snmp_build( pdu, sendbuffer.get_ptr(), &sendbufferlen,
own_engine_id_oct, sName, sModel, sLevel,
OctetStr(cEngineID, cEngineIDLength),
OctetStr(cName, cNameLength));
if (status != SNMPv3_MP_OK) {
debugprintf(2, "v3MP::send_report: error serializing message (mpSnmpBuild returns: %i).", status);
return SNMPv3_MP_ERROR;
}
SnmpSocket send_fd = INVALID_SOCKET;
if (pdu_type == sNMP_PDU_INFORM)
{
debugprintf(4, "Received a snmpInform pdu.");
if (snmp_session->get_eventListHolder()->notifyEventList())
send_fd = snmp_session->get_eventListHolder()->notifyEventList()->get_notify_fd();
}
status = snmp_session->send_raw_data(sendbuffer.get_ptr(),
(size_t)sendbufferlen,// pdu to send
destination, // target address
send_fd); // the fd to use
if ( status != 0)
{
debugprintf(1, "v3MP::send_report: error sending message (%i)", status);
return SNMPv3_MP_ERROR;
}
debugprintf(3, "v3MP::send_report: Report sent.");
return SNMPv3_MP_OK;
}
示例4: 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);
//.........这里部分代码省略.........
示例5: 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;
}
//.........这里部分代码省略.........
示例6: saveBootCounter
//.........这里部分代码省略.........
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);
LOG(fileName);
LOG_END;
return SNMPv3_FILERENAME_ERROR;
}
LOG_BEGIN(INFO_LOG | 5);
LOG("saveBootCounter: Saved counter (file) (engine id) (boot)");
LOG(fileName);
LOG(engineId.get_printable());
LOG(boot);
LOG_END;
return SNMPv3_OK;
}
LOG_BEGIN(ERROR_LOG | 1);
LOG("saveBootCounter: Failed to open both files (file) (tmp file)");
LOG(fileName);
LOG(tmpFileName);
LOG_END;
return SNMPv3_FILEOPEN_ERROR;
}
示例7: 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;
}
示例8: runable
void* runable(void *data) {
//--------[ build up SNMP++ object needed ]-------------------------------
ssync.lock();
printf("HELLO:%s\n", community.get_printable());
int t = *((int*)data);
Pdu pdu; // construct a Pdu object
Vb vb; // construct a Vb object
vb.set_oid("1"); // set the Oid portion of the Vb
pdu += vb; // add the vb to the Pdu
CTarget ctarget(address[t]); // make a target using the address
#ifdef _SNMPv3
UTarget utarget(address[t]);
if (version == version3) {
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( securityModel);
utarget.set_security_name( securityName);
pdu.set_security_level( securityLevel);
pdu.set_context_name (contextName);
pdu.set_context_engine_id(contextEngineID);
}
else {
#endif
ctarget.set_version( version); // set the SNMP version SNMPV1 or V2 or V3
ctarget.set_retry( retries); // set the number of auto retries
ctarget.set_timeout( timeout); // set timeout
ctarget.set_readcommunity( community); // set the read community to use
ctarget.set_writecommunity( community);
#ifdef _SNMPv3
}
#endif
//-------[ issue the request, blocked mode ]-----------------------------
cout << "(" << t << "): "
<< "SNMP++ snmpWalk to " << address[t].get_printable() << " SNMPV"
#ifdef _SNMPv3
<< ((version==version3) ? (version) : (version+1))
#else
<< (version+1)
#endif
<< " Retries=" << retries
<< " Timeout=" << timeout <<"ms";
#ifdef _SNMPv3
if (version == version3)
cout << endl
<< "securityName= " << securityName.get_printable()
<< ", securityLevel= " << securityLevel
<< ", securityModel= " << securityModel << endl
<< "contextName= " << contextName.get_printable()
<< ", contextEngineID= " << contextEngineID.get_printable()
<< endl;
else
#endif
cout << " Community=" << community.get_printable() << endl << flush;
SnmpTarget *target;
#ifdef _SNMPv3
if (version == version3)
target = &utarget;
else
#endif
target = &ctarget;
int status = 0;
int requests = 0;
int objects = 0;
ssync.unlock();
while (( status = snmp->get_bulk( pdu,*target,0,BULK_MAX))
== SNMP_CLASS_SUCCESS)
{
requests++;
ssync.lock();
for ( int z=0;z<pdu.get_vb_count(); z++) {
pdu.get_vb( vb,z);
#ifdef _SNMPv3
if (pdu.get_type() == REPORT_MSG) {
Oid tmp;
vb.get_oid(tmp);
cout << "(" << t << "): " << "Received a reportPdu: "
<< snmp->error_msg( tmp)
<< endl
<< vb.get_printable_oid() << " = "
<< vb.get_printable_value() << endl;
ssync.unlock();
return 0;
}
#endif
objects++;
// look for var bind exception, applies to v2 only
if ( vb.get_syntax() != sNMP_SYNTAX_ENDOFMIBVIEW) {
cout << "(" << t << "): "
<< vb.get_printable_oid() << " = ";
cout << vb.get_printable_value() << "\n";
}
else {
cout << "(" << t << "): "
<< "End of MIB Reached\n";
cout << "(" << t << "): "
//.........这里部分代码省略.........
示例9: main_walkThreads_jun
int main_walkThreads_jun( int argc, char **argv) {
//---------[ check the arg count ]----------------------------------------
if ( argc < 2) {
cout << "Usage:\n";
cout << "snmpWalkThreads host/port [host/port]... [options]\n";
cout << "StartOid: 1\n";
cout << "options: -v1 , use SNMPV1, default\n";
cout << " -v2 , use SNMPV2\n";
#ifdef _SNMPv3
cout << " -v3 , use SNMPV3\n";
#endif
cout << " -pPort , remote port to use\n";
cout << " -CCommunity_name, specify community default is 'public' \n";
cout << " -rN , retries default is N = 1 retry\n";
cout << " -tN , timeout in hundredths of seconds; default is N = 100\n";
#ifdef _SNMPv3
cout << " -snSecurityName, " << endl;
cout << " -slN , securityLevel to use, default N = 3 = authPriv" << endl;
cout << " -smN , securityModel to use, only default N = 3 = USM possible\n";
cout << " -cnContextName, default """"" << endl;
cout << " -ceContextEngineID, default """"" << endl;
cout << " -md5 , use MD5 authentication protocol\n";
cout << " -sha , use SHA authentication protocol\n";
cout << " -des , use DES privacy protocol\n";
cout << " -idea, use IDEA privacy protocol\n";
cout << " -aes128, use AES128 privacy protocol\n";
cout << " -aes192, use AES192 privacy protocol\n";
cout << " -aes256, use AES256 privacy protocol\n";
cout << " -uaAuthPassword\n";
cout << " -upPrivPassword\n";
#endif
return 0;
}
Snmp::socket_startup(); // Initialize socket subsystem
//---------[ make a GenAddress and Oid object to retrieve ]---------------
address[0] = UdpAddress(argv[1]);
if ( !address[0].valid()) { // check validity of address
cout << "Invalid Address or DNS Name, " << argv[1] << "\n";
return -1;
}
int x=2;
while ((x<argc) && (x<100) && (strstr(argv[x],"-")==0)) {
address[x-1] = UdpAddress(argv[x]);
if ( !address[x-1].valid()) { // check validity of address
cout << "Invalid Address or DNS Name, " << argv[x] << "\n";
return -1;
}
x++;
}
int threads = x-1;
cout << community.get_printable() << endl;
//---------[ determine options to use ]-----------------------------------
char *ptr;
for(;x<argc;x++) { // parse for version
if ( strstr( argv[x],"-v2")!= 0) {
version = version2c;
continue;
}
if ( strstr( argv[x],"-r")!= 0) { // parse for retries
ptr = argv[x]; ptr++; ptr++;
retries = atoi(ptr);
if (( retries<0)|| (retries>5)) retries=1;
continue;
}
if ( strstr( argv[x], "-t")!=0) { // parse for timeout
ptr = argv[x]; ptr++; ptr++;
timeout = atoi( ptr);
if (( timeout < 100)||( timeout>500)) timeout=100;
continue;
}
if ( strstr( argv[x],"-C")!=0) {
ptr = argv[x]; ptr++; ptr++;
community = ptr;
continue;
}
if ( strstr( argv[x],"-p")!=0) {
ptr = argv[x]; ptr++; ptr++;
sscanf(ptr, "%hu", &port);
continue;
}
#ifdef _SNMPv3
if ( strstr( argv[x],"-v3")!= 0) {
version = version3;
continue;
}
if ( strstr( argv[x],"-idea") != 0) {
ptr = argv[x]; ptr++; ptr++;
privProtocol = SNMPv3_usmIDEAPrivProtocol;
continue;
}
if ( strstr( argv[x],"-aes128") != 0) {
ptr = argv[x]; ptr++; ptr++;
privProtocol = SNMPv3_usmAES128PrivProtocol;
continue;
//.........这里部分代码省略.........