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

caven 2011-02-14 05:26:09
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);
}
...全文
602 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
caven 2011-02-16
  • 打赏
  • 举报
回复
谁能帮下载这个例子,发到我的邮箱。 caven0773a1@21cn.com
http://download.csdn.net/source/2320355
我也给分
caven 2011-02-15
  • 打赏
  • 举报
回复
谁能给个 agent端的 set 例子啊
justkk 2011-02-15
  • 打赏
  • 举报
回复
不懂 你可以贴到Linux专区看看
caven 2011-02-15
  • 打赏
  • 举报
回复
谁能帮下载这个例子,发到我的邮箱。 caven0773a1@21cn.com
http://download.csdn.net/source/2320355
我也给分

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧