我需要测试基于snmp ++库的驱动程序代码。启动该驱动程序代码时,我打印了以下错误日志
我正在使用SNMP ++ v3.2.25。我在网络上找到了一个SNMP仿真器,并将其发送到SNMP驱动程序。仍然打印出错误日志
我使用的SNMP模拟器是SnmpTrapGen V1.1。我在CMD命令中发送了
int ScsSnmp::init_snmp()
{
Snmp::socket_startup();
int status;
// UdpAddress address(m_local_addr);
m_snmp = new Snmp(status/*,address*/);
if (( m_snmp == NULL) || ( status != SNMP_CLASS_SUCCESS))
{
printlog(LOGE_SNMP + m_link,"constructing Snmp Object failed ");
}
else
{
TargetCollection targets;
OidCollection trapids;
Oid trapoid = OidAlarmReportNotificationType;
Oid heartoid = OidHeartbeatNotificationType;
trapids += trapoid;
trapids += heartoid;
m_snmp->notify_set_listen_port(TRAP_LISTEN_PORT);
ScsSnmp* myself = this;
if ( status = m_snmp->notify_register( trapids, targets,my_trap_callback,myself) != SNMP_CLASS_SUCCESS)
{
printlog(LOGE_SNMP + m_link,"Snmp Trap Register Error : %s ",m_snmp->error_msg(status));
return -1;
}
m_snmp->start_poll_thread(1000); //1000ms
}
return 0;
}
void ScsSnmp::my_trap_callback (int reason, Snmp *session,Pdu &pdu, SnmpTarget &target, void *data)
{
ScsSnmp* scssnmp = (ScsSnmp*)data;
printlog(LOGE_SNMP + scssnmp->m_link,"start my_trap_callback");
if ( reason == SNMP_CLASS_NOTIFICATION)
{
Vb nextVb;
GenAddress addr;
target.get_address(addr);
IpAddress from(addr);
Oid notify_id,ent;
pdu.get_notify_id(notify_id);
pdu.get_notify_enterprise(ent);
if (notify_id == OidAlarmReportNotificationType)
{
memset(scssnmp->m_alarm_msg,0,128);
memset(scssnmp->m_alarm_info.station,0,64);
memset(scssnmp->m_alarm_info.subsystem,0,64);
memset(scssnmp->m_alarm_info.devicetype,0,64);
memset(scssnmp->m_alarm_info.device,0,64);
memset(scssnmp->m_alarm_info.alarm_msg,0,128);
for (int i = 0;i<pdu.get_vb_count();i++)
{
pdu.get_vb(nextVb, i);
scssnmp->process_alarm_vb(nextVb);
}
memset(scssnmp->m_alarm_buf,0,512);
memcpy(scssnmp->m_alarm_buf,&scssnmp->m_alarm_head,sizeof(alarm_head));
memcpy(scssnmp->m_alarm_buf+sizeof(alarm_head),&scssnmp->m_alarm_info,sizeof(alarm_event_info));
bool ret = scssnmp->m_ctrl_inf->addAlarm(scssnmp->m_alarm_buf,512);
if (ret)
{
printlog(LOGE_SNMP + scssnmp->m_link,"add an event alarm success !");
}
else
{
printlog(LOGE_SNMP + scssnmp->m_link,"add an event alarm failed !");
}
}
else if (notify_id == OidHeartbeatNotificationType)
{
printlog(LOGE_SNMP + scssnmp->m_link,"get a heartbeat !");
}
else
{
printlog(LOGE_SNMP + scssnmp->m_link,"Trap notify id is wrong,id=%s",notify_id.get_printable());
}
}
else
{
printlog(LOGE_SNMP + scssnmp->m_link,"Trap Receive Error = ",session->error_msg(reason));
}
printlog(LOGE_SNMP + scssnmp->m_link,"end my_trap_callback");
}
我想通过仿真器发送SNMP陷阱,然后SNMP驱动程序接收数据并将其打印出来。简而言之,您要测试数据接口是否正常工作,但实际的接收接口会不断打印出错误日志>
答案 0 :(得分:0)
我们之前遇到过此问题,但它在snmp get响应中。这始终表明响应pdu大于65535字节。在端口162上捕获数据包将提供更清晰的验证。当我们在snmp get请求中遇到此问题时,我们减少了每个请求中发送的OID数量以解决此问题。