Re: perl agent problem with COUNTER64

"Neptune Ning (plan)" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
I have managed to modify "perl/agent/agent.xs" and it seems working right so
far.
Here's the patch.

Best regards,
Neptune Ning

2009/6/14 Neptune Ning (plan) <[email protected]>

> HI, All:
>
> I'am recently writing extension using perl. I've came across a problem with
> ASN_COUNTER64 type.
> when I use COUNTER64 to return a value, I will get a wired value from
> snmpwalk.  The machine I used is X86_64 and perl was compiled to support a
> 64bit number.
> Even when I uses setValue (ASN_COUNTER64, 1) ,  the value I get from
> snmpwalk is quite large.
>
> I've looked into the code of net-snmp-5.4.2.1 for some answers.
> In "perl/agent/agent.xs:833-863":  it gets a numeric "utmp" from SvIV or
> converts from a string. and call
>
> snmp_set_var_typed_value(request->requestvb, (u_char)type,
>                                        (u_char *) &utmp, sizeof(utmp));
>
> I printed the value of "utmp", it was right.
> then I followed into "snmp_set_var_value()" which called by
> snmp_set_var_typed_value(), between line 916-925 handels COUNTER64 type:
>
>  vars->val_len = sizeof(struct counter64);
>  memmove(vars->val.counter64, value, vars->val_len);
>
> It seemed directly copy the 64bit value into a struct counter64,
> but I found the definition of struct counter64 in
> "include/net-snmp/library/asn1.h"
>
>    struct counter64 {
>         u_long          high;
>         u_long          low;
>    };
>
> In X86_64 platform sizeof (struct counter64) will be 16 (128bit), therefor
> setValue (ASN_COUNTER64, 0x100000002),
> might get :
> high=0x100000002, low=unexpected value
>
> If I change the definition of struct counter64 into
>
> struct counter64 {
>         uint32_t        low;
>         uint32_t        high;
> }
>
> my perl extension which use counter64 will work, but other OIDs  like
> IF-MIB::ifHCInOctets will be broken. the log was like:
>
> snmp_build: unknown failuresend response: Error building ASN.1
> representation (build uint64 size 16: s/b 8)
>     -- ifHCInOctets.1
>
> Do you have any suggestion? I would appreciate a quick solution because the
> time I get for my project is limited.
>
> -------------------
>
> Best regards,
> Neptune Ning
>
>

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
net-snmp-5.4.2.1-perl-counter64.patch (text/x-patch, 1.8 KB)
*** net-snmp-5.4.2.1-1/perl/agent/agent.xs	2009-06-14 22:14:31.000000000 +0800
--- net-snmp-5.4.2.1-2/perl/agent/agent.xs	2009-06-14 22:15:49.000000000 +0800
***************
*** 771,776 ****
--- 771,777 ----
          u_char *oidbuf = NULL;
          size_t ob_len = 0, oo_len = 0;
          netsnmp_request_info *request;
+ 	struct counter64 _c64;
          u_long utmp;
          long ltmp;
  	oid myoid[MAX_OID_LEN];
***************
*** 835,842 ****
                     SvIOK(value)) {
  		  /* Good - got a real one (or a blessed scalar which we have to hope will turn out OK) */
  		  utmp = SvIV(value);
                    snmp_set_var_typed_value(request->requestvb, (u_char)type,
!                                        (u_char *) &utmp, sizeof(utmp));
  		  RETVAL = 1;
  		  break;
  	      }
--- 836,846 ----
                     SvIOK(value)) {
  		  /* Good - got a real one (or a blessed scalar which we have to hope will turn out OK) */
  		  utmp = SvIV(value);
+ 		  _c64.high = utmp >> 32;
+ 		  _c64.low = utmp & 0xFFFFFFFF;
                    snmp_set_var_typed_value(request->requestvb, (u_char)type,
!                                        (u_char *) &_c64, sizeof(_c64));
! 
  		  RETVAL = 1;
  		  break;
  	      }
***************
*** 849,857 ****
  			RETVAL = 0;
  			break;
  		  }
! 
                    snmp_set_var_typed_value(request->requestvb, (u_char)type,
!                                        (u_char *) &utmp, sizeof(utmp));
  		  RETVAL = 1;
  		  break;
  	      }
--- 853,863 ----
  			RETVAL = 0;
  			break;
  		  }
! 		  _c64.high = utmp >> 32;
! 		  _c64.low = utmp & 0xFFFFFFFF;
                    snmp_set_var_typed_value(request->requestvb, (u_char)type,
!                                        (u_char *) &_c64, sizeof(_c64));
! 
  		  RETVAL = 1;
  		  break;
  	      }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.