请教在linux下snmp++ set操作的问题

caven caven 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
snmp++ set值错误(为空值),导致agent无响应。代码是按照标准例子改的,不知道为什么不对。

运行结果
[root@bwas1 consoleExamples]# ./test_app
Created session successfully
20090814.17:12:49: 10111: (4)DEBUG : SNMPMessage: return value for build message: (0)
Oid = 1.3.6.1.4.1.4976.6.1.1.3.224
Current Value = An oldstyle table text
20090814.17:12:49: 10111: (4)DEBUG : SNMPMessage: return value for build message: (0)
20090814.17:12:51: 10111: (6)INFO : MsgQueue: Message timed out, removed id from v3MP cache (rid): (26825)
Set Status = SNMP++: SNMP request timed out


抓包 set 消息的部分内容
object identifier: 1: 1.3.6.1.4.1.4976.6.1.1.3.224
value: oid : SNMPv2-SMI:: zeroDotZero


源代码
#include <stdlib.h> // For exit() function prototype
#include "snmp_pp/snmp_pp.h"

#include <iostream.h>


// default request oids
#define NUM_SYS_VBS 1
//#define sysDescr "1.3.6.1.2.1.1.1.0"
#define sysDescr "1.3.6.1.4.1.4976.6.1.1.3.224"

void Set()
{
int status;

UdpAddress ipAddr("127.0.0.1/4700");
if (!ipAddr.valid()) {
// cout << "Invalid destination: " << genAddrStr << endl;
return;
}

// 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;
}
cout << "Created session successfully" << endl;


CTarget target(ipAddr);
if (! target.valid()) {
cout << "Invalid target" << endl;
return;
}

snmp_version version=version1; // default is v1
OctetStr community("public"); // community name

target.set_version( version); // set the SNMP version SNMPV1 or V2

target.set_readcommunity( community); // set the read community name
target.set_writecommunity( community);// set the write community name

Pdu pdu; // construct a Pdu object
Vb vb; // construct a Vb object
vb.set_oid( sysDescr); // set the Oid portion of the Vb
pdu += vb; // add the vb to the Pdu

if (( status = snmp.get( pdu,target))== SNMP_CLASS_SUCCESS) {
pdu.get_vb( vb,0);
cout << "Oid = " << vb.get_printable_oid() << endl
<< "Current Value = " << vb.get_printable_value() << endl;
Pdu setpdu;
vb.set_oid( sysDescr); // use the same oid as the inquire
vb.set_value("This is a test");
setpdu += vb;
status = snmp.set( setpdu, target);
cout << "Set Status = " << snmp.error_msg( status) << "\n";
}


}

int main(int argc, char **argv)
{
Set();
return(0);
}
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
caven
C++ 语言 65,214 成员 250,514 内容