无法使用Net-SNMP从给定的OID访问数据

发布于 2025-01-28 03:45:07 字数 1320 浏览 5 评论 0原文

我将简单的Net-SNMP简单应用程序实现到我的项目中。当我尝试使用网站上给出的示例:.1.3.6.1.2.1.1.1.1.0效果很好。 现在,我需要从这些OID中获取数据: htttps:htttps:htttps:// wwwww。 sysadmin.md/snmp-most-siaseful-linux-oids.html 。当我尝试将这些OID实现到我的代码中时,我会遇到错误:过程完成了出口代码139(由信号11:sigsegv中断)。 简单的应用程序代码: add_mibdir(“。”);

pdu = snmp_pdu_create(SNMP_MSG_GET);//creating a get pdu
if(read_objid(".1.3.6.1.4.1.2021.11.9", id_oid, &id_len)==1)//specifying the oid we want to receive
    cout<<"oid read"<<endl;
else
    cout<<"couldnt read oid"<<endl;
snmp_add_null_var(pdu, id_oid, id_len);//making room for the response
status = snmp_synch_response(session_handle, pdu, &response);//getting the response
cout<<"status: "<<status<<endl;
string ReturnBuffer;
cout<<"vars: "<<vars->val.string<<endl;
for(vars = response->variables; vars; vars = vars->next_variable)//printing the values we got back
{
    cout<<vars->val.string<<endl;
    ReturnBuffer.append(reinterpret_cast<char*>(vars->val.string));
}
ReturnBuffer.append("\0"); //test
return ReturnBuffer;

根据代码,OID本身已读取,响应的状态为0,但我没有得到任何数据并在上面收到错误,我感谢提前的任何帮助。 语言:C ++ OS:Linux(Ubuntu)

i implemented the simple net-snmp simple application into my project. when i tried to use the example OID given at the site: .1.3.6.1.2.1.1.1.0 it worked just fine.
now i need to get data from these oids: https://www.sysadmin.md/snmp-most-useful-linux-oids.html. when i tried to implement these oids into my code i got error: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV).
the simple application code:
add_mibdir(".");

pdu = snmp_pdu_create(SNMP_MSG_GET);//creating a get pdu
if(read_objid(".1.3.6.1.4.1.2021.11.9", id_oid, &id_len)==1)//specifying the oid we want to receive
    cout<<"oid read"<<endl;
else
    cout<<"couldnt read oid"<<endl;
snmp_add_null_var(pdu, id_oid, id_len);//making room for the response
status = snmp_synch_response(session_handle, pdu, &response);//getting the response
cout<<"status: "<<status<<endl;
string ReturnBuffer;
cout<<"vars: "<<vars->val.string<<endl;
for(vars = response->variables; vars; vars = vars->next_variable)//printing the values we got back
{
    cout<<vars->val.string<<endl;
    ReturnBuffer.append(reinterpret_cast<char*>(vars->val.string));
}
ReturnBuffer.append("\0"); //test
return ReturnBuffer;

according to the code the oid itself is read and the status of the response is 0 and yet im not getting any of the data and got the error above, i'd appreciate any help thanks in advance.
language: c++
os: linux(ubuntu)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文