Bill Weng
2014-10-02 16:34:49 UTC
Hi,
I am trying to snmpget on an object of "Ipv6Address" type from our
application. The response got it from agent look like this,
300200000000000000000000ac123803,
a 16-byte octet string. But the final display shows in ascii string of
every char, separated by colon in the group of 2, 3330:3032:3030:3030:
3030:3030:3030:3030:3030:3030:3030:3030:6163:3132:3338:3033. I expect this
3002:0000:0000:0000:0000:0000:ac12:3803. What can be wrong? With the
limitation of my application can send only string data in response, what
can be done to correct this ipv6 address display problem?
Thanks for the help.
Bill
Excerpt of sprint_realloc_octet_string function from snmplib/mib.c
(5.7.2.1 net-snmp). (Line 489 - 496 block was added to make sure what agent
response).
479
480
481 if (hint) {
482 int repeat, width = 1;
483 long value;
484 char code = 'd', separ = 0, term = 0, ch,
intbuf[32];
485 #define HEX2DIGIT_NEED_INIT 3
486 char hex2digit = HEX2DIGIT_NEED_INIT;
487 u_char *ecp;
488
489 int count=1;
490 if (var->type == ASN_OCTET_STR ) {
491 char *sp = malloc(1 + var->val_len);
492 memcpy(sp, var->val.string, var->val_len);
493 sp[var->val_len] = '\0';
494 printf(" my value %d is a string: %s\n", count, sp);
495 } else
496 printf(" value is NOT a strng\n");
497
498 if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID,
NETSNMP_DS_LIB_QUICK_PRINT)) {
499 if (!snmp_cstrcat(buf, buf_len, out_len, allow_realloc,
"STRING: ")) {
500 return 0;
501 }
502 }
503 cp = var->val.string;
504 ecp = cp + var->val_len;
505
506 while (cp < ecp) {
507 repeat = 1;
508 if (*hint) {
Sample run of snmpget:
[***@4GPMSGW net-snmp-5.7.2.1]# ./apps/snmpget -v3 -u FMS -n FMS -m
/opt/conf/FGW.mib 127.0.0.1 FGW-MIB::henbmastercpIpAddressHeNBCpLocal2V6.1
my value 1 is a string: 300200000000000000000000ac123803
FGW-MIB::henbmastercpIpAddressHeNBCpLocal2V6.1 = STRING:
3330:3032:3030:3030:3030:3030:3030:3030:3030:3030:3030:3030:6163:3132:3338:3033
I am trying to snmpget on an object of "Ipv6Address" type from our
application. The response got it from agent look like this,
300200000000000000000000ac123803,
a 16-byte octet string. But the final display shows in ascii string of
every char, separated by colon in the group of 2, 3330:3032:3030:3030:
3030:3030:3030:3030:3030:3030:3030:3030:6163:3132:3338:3033. I expect this
3002:0000:0000:0000:0000:0000:ac12:3803. What can be wrong? With the
limitation of my application can send only string data in response, what
can be done to correct this ipv6 address display problem?
Thanks for the help.
Bill
Excerpt of sprint_realloc_octet_string function from snmplib/mib.c
(5.7.2.1 net-snmp). (Line 489 - 496 block was added to make sure what agent
response).
479
480
481 if (hint) {
482 int repeat, width = 1;
483 long value;
484 char code = 'd', separ = 0, term = 0, ch,
intbuf[32];
485 #define HEX2DIGIT_NEED_INIT 3
486 char hex2digit = HEX2DIGIT_NEED_INIT;
487 u_char *ecp;
488
489 int count=1;
490 if (var->type == ASN_OCTET_STR ) {
491 char *sp = malloc(1 + var->val_len);
492 memcpy(sp, var->val.string, var->val_len);
493 sp[var->val_len] = '\0';
494 printf(" my value %d is a string: %s\n", count, sp);
495 } else
496 printf(" value is NOT a strng\n");
497
498 if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID,
NETSNMP_DS_LIB_QUICK_PRINT)) {
499 if (!snmp_cstrcat(buf, buf_len, out_len, allow_realloc,
"STRING: ")) {
500 return 0;
501 }
502 }
503 cp = var->val.string;
504 ecp = cp + var->val_len;
505
506 while (cp < ecp) {
507 repeat = 1;
508 if (*hint) {
Sample run of snmpget:
[***@4GPMSGW net-snmp-5.7.2.1]# ./apps/snmpget -v3 -u FMS -n FMS -m
/opt/conf/FGW.mib 127.0.0.1 FGW-MIB::henbmastercpIpAddressHeNBCpLocal2V6.1
my value 1 is a string: 300200000000000000000000ac123803
FGW-MIB::henbmastercpIpAddressHeNBCpLocal2V6.1 = STRING:
3330:3032:3030:3030:3030:3030:3030:3030:3030:3030:3030:3030:6163:3132:3338:3033