有大佬注释下代码吗?特别是有关snmp的

qq_45057567 2020-05-20 09:29:40
源码如下:
CMibBrowserView::OnGet()

{

HTREEITEM hNode; MibNode* pNodeData;

CString ipadd,community,oidstr; m_ipadd.GetWindowText(ipadd); if(m_ipadd.IsBlank())

{

AfxMessageBox("IP 地址错误!"); return ;

}

m_ipadd.GetWindowText(ipadd); m_community.GetWindowText(community); m_oid.GetWindowText(oidstr); ipadd+=":161";

Snmp::socket_startup();

UdpAddress address((LPCTSTR)ipadd); Oid oid((LPCTSTR)oidstr); snmp_version version=version1;

int status;

Snmp snmp(status, 0, false); Pdu pdu;
Vb vb; vb.set_oid(oid); pdu += vb;

CTarget ctarget(address); ctarget.set_version(version); ctarget.set_retry(1); ctarget.set_timeout(100);


ctarget.set_readcommunity((LPCTSTR)community); SnmpTarget *target;

target = &ctarget;

status = snmp.get(pdu, *target);

if (status == SNMP_CLASS_SUCCESS)

{

pdu.get_vb(vb,0);

CString reply_oid=vb.get_printable_oid(); CString reply_value=vb.get_printable_value(); hNode=SearchNode(reply_oid);

if (hNode!=NULL)

{

pNodeData=(MibNode*)m_tree.GetItemData(hNode); reply_oid.Replace((LPCTSTR)pNodeData->POid,

(LPCTSTR)m_tree.GetItemText(hNode)); if (pNodeData->PInteger!=NULL)

{

POSITION index=pNodeData->PInteger->Find(reply_value); if (index!=NULL)
{

pNodeData->PInteger->GetNext(index); reply_value=pNodeData->PInteger->GetNext(index);

}

}

}

if (m_list.GetItemCount()>0) m_list.DeleteAllItems();

int row=m_list.InsertItem(1,reply_oid); m_list.SetItemText(row,1,reply_value);

}

Snmp::socket_cleanup();

CMainFrame *pF=(CMainFrame *)AfxGetMainWnd(); int num=m_list.GetItemCount(); oidstr.Format("%d",num);

oidstr="共取回 "+oidstr+" 个对象"; pF->m_wndStatusBar.SetPaneText(0,oidstr);

}
...全文
63 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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