calmh/node-snmp-native

truncated 64bit counters

bangert opened this issue · 7 comments

Apparently node-snmp-native stores SNMPs Counter64 values in javascripts native type, which stores integers internally in a 64bit floating point type. As a result all values above 2^53 are truncated which at minimum is a bit surprising.

See also:
http://stackoverflow.com/questions/9643626/javascript-cant-handle-64-bit-integers-can-it

Thanks

calmh commented

I guess the level of surprise is up to the individual, as you say it returns numbers as numbers and javascript is what it is.

fair enough ;-)

are you interested in a fix, though?
Would a dependency on long.js be a no go?
https://www.npmjs.com/package/long

calmh commented

I think that would be fine. We'd have to decide between breaking the interface (returning a long) or just adding it as a new attribute. There are arguments in both directions of course.

ok.

in the meantime we have found valueHex, and will use that for now.
Thanks for having this exposed from the beginning.

Can it be that valueHex contains more than one value when using getAll? It seems like then retrieving 2 values, the first value is much longer than expected and contains own value, next value header and next value.

I think line 320 in lib/snmp.js needs to be changed to:
vb.valueRaw = bvb.slice(vbhdr.header, vbhdr.len);

calmh commented

I was going to suggest valueHex, but I bet it's in ASN1 format which is less than optimally convenient.

@MortenGuldager that may well be the case

Just for the record, valueHex and valueRaw have been fixed in #35 so these can be used to parse the full 64bit without truncation.