$sess->getnext($varbind) does honor UseLongNames, but $sess->getnext($varbind, $cb) does not.
I've taken a look at __snmp_cb SNMP.xs, where I found this:
if (SvIV(*hv_fetch((HV*)SvRV(sess_ref),"UseLongNames", 12, 1))) {
fprintf(stderr, "setting true\n");
getlabel_flag |= USE_LONG_NAMES;
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_FULL_OID, 1);
}
So I would've expected it to work. However, it doesn't. Here is a little test script to reproduce the problem:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 | #!/usr/bin/perl -w
use strict;
use Data::Dumper;
use SNMP;
use Test::More;
# This didn't help me out much
# $SNMP::debugging=2;
# For good measure, but shouldn't be required
$SNMP::use_long_names=1;
my $sess = SNMP::Session->new(
'DestHost' => '127.0.0.1',
'Community' => 'public',
'Version' => '2c',
# This should do the trick, but doesn't for async
'UseLongNames' => 1,
);
# $varlist = new SNMP::VarList(['ifIndex']);
my $varlist;
$varlist = new SNMP::VarList(['ifDescr']);
print STDERR "### Getting sync\n";
my @results = $sess->getnext($varlist);
print Dumper([ 'sync', $varlist, \@results ]);
# These two pass for sync
like($varlist->[0][0], qr/^\.iso\./, '$varlist now respects UseLongNames');
unlike($varlist->[0][0], qr/^ifDescr/, '$varlist has ifDescr');
$varlist = new SNMP::VarList(['ifDescr']);
print STDERR "### Getting async\n";
$sess->getnext($varlist, sub {
my ($result) = @_;
print Dumper([ 'async', $varlist, $result ]);
# Expect either one of these to respect UseLongNames
like($varlist->[0][0], qr/^\.iso\./, '$varlist now respects UseLongNames');
like($result->[0][0], qr/^\.iso\./, '$varlist now respects UseLongNames');
# Instead these match. That's not right...
unlike($varlist->[0][0], qr/^ifDescr/, '$varlist has ifDescr');
unlike($result->[0][0], qr/^ifDescr/, '$varlist has ifDescr');
SNMP::finish();
});
SNMP::MainLoop();
done_testing();
|