COUNTER64 support for perl
"Peter Martin" <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <01fa01c5c834$870a2210$66f1a8c0@endeavour> |
Hi, I am using the perl agent code and need to return some data of type Counter64. Using net-snmp-5.2 from several months ago, I was getting an error: 'Error building ASN.1 representation (build uint64 size 4 s/b 8).' Hunting around I found that the code in agent.xs sends 4 byte integers to the encoder for all INTEGER and COUNTER types, which is incorrect for counter64. To get COUNTER64 to work the attached patch sends 8 byte long longs instead and all appears to work as expected. I have not handled the other 64 bits values here. Only very limited testing on Fedora core 3. BTW, I have looked in the latest 5.2.2-pre2 and this does not appear have been added. Regards Pete Martin
agent.xs-counter64.patch
(application/octet-stream, 2 KB)
--- agent.xs~ 2004-06-14 18:34:58.000000000 +0100
+++ agent.xs 2005-10-03 15:21:23.000000000 +0100
@@ -732,6 +732,7 @@
size_t ob_len = 0, oo_len = 0;
netsnmp_request_info *request;
u_long utmp;
+ unsigned long long ulltmp;
long ltmp;
oid myoid[MAX_OID_LEN];
size_t myoid_len;
@@ -775,7 +776,6 @@
case ASN_UNSIGNED:
case ASN_COUNTER:
- case ASN_COUNTER64:
case ASN_TIMETICKS:
/* We want an integer here */
if ((SvTYPE(value) == SVt_IV) || (SvTYPE(value) == SVt_PVMG)) {
@@ -808,6 +808,38 @@
break;
}
+ case ASN_COUNTER64:
+ /* We want an integer here */
+ if ((SvTYPE(value) == SVt_IV) || (SvTYPE(value) == SVt_PVMG)) {
+ /* Good - got a real one (or a blessed scalar which we have to hope will turn out OK) */
+ ulltmp = SvIV(value);
+ snmp_set_var_typed_value(request->requestvb, (u_char)type,
+ (u_char *) &ulltmp, sizeof(ulltmp));
+ RETVAL = 1;
+ break;
+ }
+ else if (SvPOKp(value)) {
+ /* Might be OK - got a string, so try to convert it, allowing base 10, octal, and hex forms */
+ stringptr = SvPV(value, stringlen);
+ ulltmp = strtoull( stringptr, NULL, 0 );
+ if (errno == EINVAL) {
+ snmp_log(LOG_ERR, "Could not convert string to number in setValue: '%s'", stringptr);
+ RETVAL = 0;
+ break;
+ }
+
+ snmp_set_var_typed_value(request->requestvb, (u_char)type,
+ (u_char *) &ulltmp, sizeof(ulltmp));
+ RETVAL = 1;
+ break;
+ }
+ else {
+ snmp_log(LOG_ERR, "Non-unsigned-integer value passed to setValue with ASN_UNSIGNED/ASN_COUNTER/ASN_TIMETICKS: type was %d\n",
+ SvTYPE(value));
+ RETVAL = 0;
+ break;
+ }
+
case ASN_OCTET_STR:
case ASN_BIT_STR:
/* Check that we have been passed something with a string value (or a blessed scalar) */