Найти следующий OID в файле mib с помощью net-snmp api

Я пытаюсь найти следующий Oid в файле MIB с помощью Net-Snmp C++ API. У меня есть скалярное значение и таблица в моем 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;
}

Как я могу найти следующий Oid в файле MIB

0 ответов

Другие вопросы по тегам