Thursday, February 15, 2007
There's more wierdness to this than reported, but this will be fine for now
ospfquery is written using the older CMU
SNMP library.
I want to update it to use the currently maintained Net SNMP library, but I've been having
problems getting it to work. The problematic bit of code seems to be:
netsnmp_session session;
int r;
init_snmp("snmpapp");
snmp_enable_stderrlog();
snmp_sess_init(&session);
session.version = SNMP_VERSION_1;
session.peername = "XXXXXXXXXXXXXXXXXXXXXXX";
session.community = "XXXXXXXXX";
session.community_len = strlen(session.community);
gss = snmp_open(&session);
Everytime I try to run it (and by “it” I mean a small test program that
just queries the system id), I get “snmpget: Too long”. Yet,
if I change the above to:
netsnmp_session session; int r; snmp_parse_args(argc,argv,&session,"",NULL); gss = snmp_open(&session);
it (and by “it” I mean a small test program that just queries the
system id) works fine. And as far as I can tell, all that
snmp_parse_args() is doing is the code in the first example,
distilled down to just what's required to initialize session
(so why don't I just use snmp_parse_args() and be done with it?
snmp_parse_args() exists to parse the command line for the
various tools like snmpget and snmpwalk which I
don't need—ospfquery has its own command line that doesn't
need replacing).
So, I recompiled Net SNMP to include debugging information so I could trace
down into the various calls, and for some reason, the debugging information
isn't being generated (or else there's some other problem with
gdb that I don't know about).
Okay, so I decided to just link directly against the object files that make up Net SNMP, and that's when things got wierd:
[spc]royal-oak:~/source/snmp>gcc -o sysid3 sysid3.c -lnetsnmp -lcrypto [spc]royal-oak:~/source/snmp>./sysid3 snmpget: Too long XXXXXXXXXXXXXXXXXXXXXXX is unknown [spc]royal-oak:~/source/snmp>gcc -o sysid3 sysid3.c \ ~/apps/net-snmp-5.2.1/snmplib/*.o -lcrypto [spc]royal-oak:~/source/snmp>./sysid3 XXXXXXXXXXXXXXXXXXXXXXX is a riverstone [spc]royal-oak:~/source/snmp>
So let me get this straight: I link against the library, and the program doesn't work. I link against the object files, and it works just fine.
Okay.
Anybody care to explain?
![Glasses. Titanium, not steel. [Self-portrait with my new glasses]](https://www.conman.org/people/spc/about/2025/0925.t.jpg)