--- agent.xs Mon Apr 23 11:56:44 2007 +++ /home/mux/agent.xs Mon Apr 23 11:57:22 2007 @@ -767,6 +767,8 @@ u_char *oidbuf = NULL; size_t ob_len = 0, oo_len = 0; netsnmp_request_info *request; + struct counter64 c64tmp; + unsigned long long ulltmp; u_long utmp; long ltmp; oid myoid[MAX_OID_LEN]; @@ -823,12 +825,11 @@ 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)) { /* Good - got a real one (or a blessed scalar which we have to hope will turn out OK) */ - utmp = SvIV(value); + utmp = SvUV(value); snmp_set_var_typed_value(request->requestvb, (u_char)type, (u_char *) &utmp, sizeof(utmp)); RETVAL = 1; @@ -855,6 +856,41 @@ RETVAL = 0; break; } + + case ASN_UNSIGNED64: + 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 = SvUV(value); + } + 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; + } + } + else { + snmp_log(LOG_ERR, "Non-unsigned-integer value passed to setValue with ASN_UNSIGNED64/ASN_COUNTER64: type was %d\n", + SvTYPE(value)); + RETVAL = 0; + break; + } +#ifdef WORDS_BIGENDIAN + c64tmp.low = (ulltmp >> 32) & 0xffffffff; + c64tmp.high = ulltmp & 0xffffffff; +#else + c64tmp.high = (ulltmp >> 32) & 0xffffffff; + c64tmp.low = ulltmp & 0xffffffff; +#endif + snmp_set_var_typed_value(request->requestvb, (u_char)type, + (u_char *) &c64tmp, sizeof(c64tmp)); + RETVAL = 1; + break; case ASN_OCTET_STR: case ASN_BIT_STR: