Libmi on Debian - resolve numeric OIDs into human readable format

Hi.
I am trying to use libsmi, on Debian, to resolve numeric OIDs (e.g.1.3.6.1.2.1.2.2.1.6.1) into human readable format (e.g. IF-MIB::ifPhysAddress.1).
I installed libsmi2:
neolink@debian:~$ dpkg --list | grep libsmi ii libsmi2-common 0.4.7+dfsg-0.1 A library to access SMI MIB information (MIB module files) ii libsmi2-dev 0.4.7+dfsg-0.1 A library to access SMI MIB information (development files) ii libsmi2ldbl 0.4.7+dfsg-0.1 A library to access SMI MIB information
I tried to use this function:
SmiNode *smiGetNodeByOID(unsigned int oidlen, SmiSubid oid[]);
#include <stdio.h> #include <string.h> #include <smi.h>
int main(int argc, char *argv[]) { SmiNode *smiNode; int oidlen, first = 1;
smiInit(NULL);
SmiSubid oidArray[11] = {1,3,6,1,2,1,2,2,1,6,1};
for((smiNode = smiGetNodeByOID(11,oidArray)) && (oidlen = smiNode->oidlen); smiNode && (first || smiNode->oidlen > oidlen); smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ANY),first = 0) { printf("%*s%-32s\n",(smiNode->oidlen - oidlen + 1) * 2, " ",smiNode->name); };
exit(0); }
root@debian:/home/neolink# gcc -o libsmi_code_test libsmi_code_test.c -lsmi root@debian:/home/neolink# ./libsmi_code_test iso root@debian:/home/neolink#
Anybody can help me?
Thank.

On Thu, Jun 04, 2009 at 10:56:25AM +0200, Andr? Nogueira wrote:
I tried to use this function:
SmiNode *smiGetNodeByOID(unsigned int oidlen, SmiSubid oid[]);
[...]
root@debian:/home/neolink# gcc -o libsmi_code_test libsmi_code_test.c -lsmi root@debian:/home/neolink# ./libsmi_code_test ?iso
Your program is not loading any MIB modules and hence the only thing libsmi knows are the root nodes of the OID tree and this is what smiGetNodeByOID() returns.
/js

Juergen Schoenwaelder wrote:
Your program is not loading any MIB modules and hence the only thing libsmi knows are the root nodes of the OID tree and this is what smiGetNodeByOID() returns.
Hello,
Can you have a look at the example libsmi program on the libsmi(3) manpage? I think the confusion comes from there. For me, that example program returns only "iso" for variety of inputs.
I have added this to the example program:
--- a/example.c Thu Jun 04 13:40:03 2009 +0200 +++ b/example.c Thu Jun 04 14:27:13 2009 +0200 @@ -5,14 +5,20 @@ int main(int argc, char *argv[]) { SmiNode *smiNode; - int oidlen, first = 1; - + int i, oidlen, first = 1; + const char *modules[] = { + "SNMPv2-SMI", "SNMPv2-TC", "SNMPv2-CONF", + "SNMPv2-MIB", "IF-MIB", NULL}; + if (argc != 2) { fprintf(stderr, "Usage: smisubtree oid\n"); exit(1); }
smiInit(NULL); + for (i = 0; modules[i]; i++) + fprintf(stderr, "Loading module: %s\n", + smiLoadModule(modules[i]));
for((smiNode = smiGetNode(NULL, argv[1])) && (oidlen = smiNode->oidlen);
And now it seems to return something reasonable for the inputs like "internet", "org", "mib-2".
However it dumps core in smiGetNextNode() for "iso", "ccitt" and "joint-iso-ccitt" values.
The attached patch-rootedge fixed coredumps for some edge cases like above and "0", "." etc., although I have a feeling that results are not correct - the "iso" and root ("0") trees do not get expanded properly).
The proper fix might be a different initialization of the root nodes.

On Thu, Jun 04, 2009 at 02:28:07PM +0200, Marcin Cieslak wrote:
Can you have a look at the example libsmi program on the libsmi(3) manpage? I think the confusion comes from there. For me, that example program returns only "iso" for variety of inputs.
[...]
I have updated the example program. I hope it is more robust now.
[...]
The attached patch-rootedge fixed coredumps for some edge cases like above and "0", "." etc., although I have a feeling that results are not correct - the "iso" and root ("0") trees do not get expanded properly).
I have integrated the patches to make the API functions more robust. I am not sure yet about the root node.
/js
participants (3)
-
André Nogueira
-
Juergen Schoenwaelder
-
Marcin Cieslak