c++ - 使用 snmpSET 和 netsnmp lib 无法设置请求
问题描述
感谢 netsnmp 库,我有一个代理,它对 Getrequest 工作正常,我使用 MibIreasonning 对 get 和 set 进行测试,但是我对 set 有一个大问题,当我做 snmp set 时,我没有响应和值剂量变化,我使用命令行:snmpset -v2c -cprivate 127.0.0.1:10181 1.3.6.1.4.1.4045.61005681.20.2.3.0.0 i 1,我得到:超时:127.0.0.1:10181没有响应
如果我在公共场合做 snmpset,我得到:数据包错误,原因 noAccess
这是我的代码,如果你能帮助我:
//-------------------------------------------------------------------------------------------------
// ValueOID
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <iostream>
#include <string>
int handle_AgentSNMP15 (
netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests) {
int value=0 ;
switch (reqinfo->mode) {
case MODE_GET:
std::cout<<"GETSNMP15"<<std::endl;
std::cout<<"get value "<<*(requests->requestvb->val.integer)<<std::endl;
snmp_set_var_typed_value(
requests->requestvb,
ASN_INTEGER,
(u_char*)&value,
sizeof(value));
break;
case MODE_SET_RESERVE1:
std::cout<<*(requests->requestvb->val.integer)<<std::endl;
case MODE_SET_RESERVE2:
value = *(requests->requestvb->val.integer);
std::cout<<"RESERVE2"<<std::endl;
break;
case MODE_SET_FREE:
break;
case MODE_SET_ACTION:
std::cout<<"SETACTION"<<std::endl;
value = *(requests->requestvb->val.integer);
break;
case MODE_SET_COMMIT:
std::cout<<"SETCOMMIT"<<std::endl;
value = *(requests->requestvb->val.integer);
break;
case MODE_SET_UNDO:
break;
default:
{
snmp_log(
LOG_ERR,
"Unknown mode (%d) in handle_dot1dBaseType\n",
reqinfo->mode);
std::cout<<"ERROR OTHER THAN GET";
return SNMP_ERR_GENERR;
}
}
return SNMP_ERR_NOERROR;
}
void init_Value() {
static oid AgentSNMP15[]={1,3,6,1,4,1,4045,61005681,20,2,3,0};
netsnmp_register_scalar(netsnmp_create_handler_registration(
"agentSNMP15",
handle_AgentSNMP15,
AgentSNMP15,
OID_LENGTH(AgentSNMP15),
HANDLER_CAN_RWRITE));
}
谢谢你的帮助
解决方案
推荐阅读
- mongodb - 使用副本成员作为独立服务器?MongoDB
- excel - 如何找到工作表中存在的所有值?
- pandas - 在 jupyterlab 中的 pandas df 中呈现超链接
- java - 如何将 JSON 消息转换为具有可为空字段的 avro 模式的有效 JSON?
- stored-procedures - 在我的 MySQL 存储过程中使用事务和更新查询如何确保更新完成
- hibernate - 如何使用 spring-data-jpa 和复合键保存多对多关系
- java - 如何计算肯定会在某个点结束的无限循环的时间复杂度?
- node.js - 如何从这些输入中获取数据
- prestashop - 如何修复 ContextErrorException:警告:声明
- c# - C# 引用指针