--- perl/agent/agent.xs.perl-counter64	2007-01-06 03:35:12.000000000 +0300
+++ perl/agent/agent.xs	2009-11-02 11:16:13.000000000 +0300
@@ -769,6 +769,8 @@
         netsnmp_request_info *request;
         u_long utmp;
         long ltmp;
+	unsigned long long ulltmp;
+	struct counter64 c64tmp;
 	oid myoid[MAX_OID_LEN];
 	size_t myoid_len;
         STRLEN stringlen;
@@ -823,7 +825,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)) {
@@ -856,6 +857,35 @@
 		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);
+	      }
+	      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_COUNTER64: type was %d\n",
+			SvTYPE(value));
+		RETVAL = 0;
+		break;
+	      }
+	      c64tmp.high = ulltmp >> 32;
+	      c64tmp.low = ulltmp & 0xfffffffful;
+	      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:
 	      /* Check that we have been passed something with a string value (or a blessed scalar) */
