本文整理汇总了C++中Pdu::get_vblist方法的典型用法代码示例。如果您正苦于以下问题:C++ Pdu::get_vblist方法的具体用法?C++ Pdu::get_vblist怎么用?C++ Pdu::get_vblist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pdu
的用法示例。
在下文中一共展示了Pdu::get_vblist方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
int status;
char *req_str = (char*) "get";
// char *dflt_req_oid = (char*) sysDescr;
char *dflt_trp_oid = (char*) coldStart;
char *genAddrStr = (char*) "127.0.0.1" ; // localhost
char *oid_str = (char*) NULL;
if (argc > 1) genAddrStr = argv[1];
if (argc > 2) req_str = argv[2];
if (argc > 3) oid_str = argv[3];
Snmp::socket_startup(); // Initialize socket subsystem
IpAddress ipAddr(genAddrStr);
if (!ipAddr.valid()) {
cout << "Invalid destination: " << genAddrStr << endl;
return(1);
}
// bind to any port and use IPv6 if needed
Snmp snmp(status, 0, (ipAddr.get_ip_version() == Address::version_ipv6));
if (status) {
cout << "Failed to create SNMP Session: " << status << endl;
return(1);
}
cout << "Created session successfully" << endl;
CTarget target(ipAddr);
if (! target.valid()) {
cout << "Invalid target" << endl;
return(1);
}
Pdu pdu;
Vb vb;
if ( strcmp(req_str, "get") == 0 ) {
Vb vbl[NUM_SYS_VBS];
vbl[0].set_oid(sysDescr);
vbl[1].set_oid(sysObjectID);
vbl[2].set_oid(sysUpTime);
vbl[3].set_oid(sysContact);
vbl[4].set_oid(sysName);
vbl[5].set_oid(sysLocation);
// vbl[6].set_oid(sysServices);
cout << "Send a GET-REQUEST to: " << ipAddr.get_printable() << endl;
if ( ! oid_str ) {
if ( strcmp(genAddrStr,"localhost" ) == 0 ||
strcmp(genAddrStr, "127.0.0.1") == 0 ) {
pdu.set_vblist(vbl, NUM_SYS_VBS);
} else {
for (int i=0; i<NUM_SYS_VBS; i++)
pdu += vbl[i];
}
}
else {
Oid req_oid(oid_str);
if ( ! req_oid.valid() ) {
cout << "Request oid constructor failed for:" << oid_str << endl;
return(1);
}
vb.set_oid(req_oid);
pdu += vb;
}
status = snmp.get(pdu, target);
if (status) {
cout << "Failed to issue SNMP Get: (" << status << ") "
<< snmp.error_msg(status) << endl;
return(1);
}
else {
cout << "Issued get successfully" << endl;
int vbcount = pdu.get_vb_count();
if ( vbcount == NUM_SYS_VBS ) {
pdu.get_vblist(vbl, vbcount);
for ( int i=0; i<vbcount ; i++ ) {
cout << vbl[i].get_printable_oid() << " : " <<
vbl[i].get_printable_value() << endl;
}
} else {
for ( int i=0; i<vbcount ; i++ ) {
pdu.get_vb(vb, i);
cout << vb.get_printable_oid() << " : " <<
vb.get_printable_value() << endl;
}
}
}
}
else if ( strcmp(req_str, "trap") == 0 ) {
cout << "Send a TRAP to: " << ipAddr.get_printable() << endl;
if ( ! oid_str )
oid_str = dflt_trp_oid;
Oid notify_oid(oid_str);
if ( ! notify_oid.valid() ) {
//.........这里部分代码省略.........