lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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;
     }