Skip to content

This is not working with HEX-String #2

Closed
wants to merge 1 commit into from

2 participants

@fmgdias
fmgdias commented Mar 30, 2012

snmpwalk -v 2c -c public 10.0.0.2 1.3.6.1.2.1.17.1.1.0
SNMPv2-SMI::mib-2.17.1.1.0 = Hex-STRING: 00 0A 73 F4 47 C5
Now its Ok...
// buf =
output value: "\u0000\nsôGÅ", its is OK because is HEX.

@fmgdias fmgdias This is not working with HEX-String
>snmpwalk -v 2c -c public 10.0.0.2 1.3.6.1.2.1.17.1.1.0
SNMPv2-SMI::mib-2.17.1.1.0 = Hex-STRING: 00 0A 73 F4 47 C5
Now its Ok...
// buf = <Buffer 04 06 00 0a 73 f4 47 c5>
output value: "\u0000\nsôGÅ", its is OK because is HEX.
f0aa5b7
@calmh
Owner
calmh commented Mar 31, 2012

What exactly does this patch do? It looks like it just interprets each byte as a character (in what character set?)... Should we instead look for a "hex string" varbind type and output that as snmpwalk does?

@fmgdias
fmgdias commented Apr 2, 2012

If in Buffer contains the following string: buf = "04 06 00 0a 73 f4 47 c5", ( [0] = 4, (Type: String), [1] = Length of String, [2 to sizeof] = String.).
When using buf.toString('utf-8',....);, information is lost because of F4 and C5, which is not a valid character....
And using foreach...String.fromCharCode...the character (F4 e C5) is not lost...where found "\u0000\nsôGÅ", instead of "\u0000\ns�G�"...can you see the "�"?...is invalid character...

@calmh
Owner
calmh commented Apr 2, 2012

Sure. But if it is to be a hex string, maybe it should be presented as "04 06 00 0a 73 f4 47 c5" or similar, and not interpreted as a string at all. Do you have an example OID that contains a hex string like this?

@fmgdias
fmgdias commented Apr 2, 2012

ok, but the oid (1.3.6.1.2.1.17.1.1.0) is sent from the equipment, as String (type 4), and the local Library MIB converts into HEX String...like this...

snmpwalk -v 2c -c public 10.0.0.2 1.3.6.1.2.1.17.1.1.0
SNMPv2-SMI::mib-2.17.1.1.0 = Hex-STRING: 00 0A 73 F4 47 C5
PS: this oid is from cable modem, and is not available to common users...

@calmh
Owner
calmh commented Apr 2, 2012
@fmgdias
fmgdias commented Apr 2, 2012

yes...i used this function after varbins ...this convert..."\u0000\nsôGÅ" to "00-0A-73-F4-47-C5"

function ( value ) {
_value = "";
for ( i=0; i<value.length; i++ ) {
var hex = value.charCodeAt(i).toString(16).pad(2);
_value = _value.concat(hex);
}
return _value.toUpperCase();
}

/** Extend Padding **/
String.prototype.pad = Number.prototype.pad = function(length){
value = String(this);
while ( value.length < length ) {
value = '0'+value;
}
return value;
}

@calmh
Owner
calmh commented Apr 2, 2012

Check out the just pushed/published version 1.0.1. (Note the difference in parameters and return values if you currently use a 0.x version!) The returned varbinds now contain properties valueRaw (a raw Buffer) and valueHex (a hex string) for octet strings. I believe valueHex is what you need to use here instead of the "interpreted" value.

@calmh calmh closed this Apr 2, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.