我正在尝试使用Net-Snmp C ++ API在MIB文件中找到下一个Oid。我的MIB文件中有标量值和表格,想要在MIB文件中走不进SNMP代理。
现在我可以找到下一个Oid,当它在MIB文件中排序时,当请求的Oid以“.0”结尾时它不起作用(这意味着这个Oid没有子节点)。
void FindNextOid(AsnObjectIdentifier* pAsnOid, MIB_ENTRY* pResultMib) {
char * szOidTemp;
char * pch;
oid root[MAX_OID_LEN];
size_t rootlen;
SnmpMgrOidToStr(pAsnOid, &szOidTemp);
memset(root, 0, sizeof(root));
rootlen = MAX_OID_LEN;
if (snmp_parse_oid(szOidTemp, root, &rootlen) == NULL) {
snmp_perror(szOidTemp);
return;
}
struct tree *tbl = NULL;
tbl = get_tree(root, rootlen, get_tree_head());
if (tbl) {
struct tree foundTp = crawlForNextOid(tbl);
// Do Something
}
return;
}
tree crawlForNextOid(struct tree *tpp)
{
struct tree *tp;
tree tpx;
clear_tree_flags(tpp);
for (tp = tpp; tp; tp = tp->next_peer) {
tpx = crawlForNestedOids(tp);
if (tpx.type == 0)
tpx = crawlForNextOid(&tpx);
break;
}
return tpx;
}
tree crawlForNestedOids(struct tree *tree)
{
struct tree *tp;
struct tree tpx;
char* tmpOid;
/*
* sanity check
*/
if (!tree) {
return tpx;
}
while (1) {
register struct tree *ntp;
tp = NULL;
for (ntp = tree->child_list; ntp; ntp = ntp->next_peer) {
if (ntp->reported)
continue;
if (!tp || (tp->subid > ntp->subid))
tp = ntp;
tmpOid = GetOid(tp);
if (tp->type == TYPE_SIMPLE_LAST) {
strcat(tmpOid, ".0");
}
}
if (!tp)
break;
tp->reported = 1;
tpx = *tp;
break;
}
return tpx;
}
如何在MIB文件中找到下一个Oid