[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luasnmp and Counter64
- From: hleuwer <herbert.leuwer@...>
- Date: Wed, 17 Feb 2010 00:36:16 +0100
Am 16.02.2010 12:43, schrieb Yuri Kozlov:
Hello.
Linux 32-bit, luasnmp 1.0.5
yuray@yuray:~$ lua -l snmp -i
Lua 5.1.3 Copyright (C) 1994-2008 Lua.org, PUC-Rio
=snmp.newvar("1.3.6.1.2.1.31.1.1.1.10.51", 33)
IF-MIB::ifHCOutOctets.51 = Counter64: 33
=snmp.newvar("1.3.6.1.2.1.31.1.1.1.10.51", 34)
IF-MIB::ifHCOutOctets.51 = Counter64: 4294967296
Very strange result. :(
How to fix this?
This is a bug in src/nm_util.c during the conversion of the value into net-snmp
internal Counter64 representation - patch attached.
Herbert
Index: src/nm_util.c
===================================================================
--- src/nm_util.c (Revision 326)
+++ src/nm_util.c (Arbeitskopie)
@@ -872,15 +872,15 @@
{
struct counter64 *var = (struct counter64*) strbuf;
double val;
- u_long hi,lo;
- int ul_bits = sizeof(u_long) * 8;
+ double hi,lo;
+ double ul_bits = (double) sizeof(u_long) * 8;
if (!lua_isnumber(L, -1))
return NULL;
val = lua_tonumber(L, -1);
- hi = (u_long) floor(val / (double)(2 ^ ul_bits));
- lo = (u_long) (val - hi * (double)(2 ^ ul_bits));
- *(&var->high) = hi;
- *(&var->low) = lo;
+ hi = floor(val / pow(2.0, ul_bits));
+ lo = val - hi * pow(2, ul_bits);
+ *(&var->high) = (u_long) hi;
+ *(&var->low) = (u_long) lo;
len = sizeof(struct counter64);
break;
}