Page 1 of 1

:len fails to count after 4095

Posted: Wed May 02, 2012 4:24 pm
by rviteri
Hi I am following this script to add routes to an address-list:

http://www.mikrotik-routeros.com/2010/0 ... -mikrotik/

The script downloads a text fiel and then uses the function :len to count the characters in the file. I noticed that :len works up to 4095 beyond that it returns 0 instead of the actual number.

Is this a Mikrotik limitation?

PS: I am using a RB751u-2HnD
PS2: I tested using :len on a separate script pointing to the downloaded file.

Thanks,

Re: :len fails to count after 4095

Posted: Wed May 02, 2012 6:09 pm
by jandafields
4096 is the limit of a 12-bit integer, so that would be a hardcoded limitation of the mikrotik software.

If you really need to go above this, use a second counter to count the number of times it "rolls-over", and then calculate it that way.

So, for example, if $a is your rollover counter, and $b is your regular counter, then:

$a=5
$b=500

$total = ($a * 4096) + $b = 20980

This would give you a total number of 24-bits, which is over 16 million.

Re: :len fails to count after 4095

Posted: Wed May 02, 2012 7:58 pm
by rviteri
I am trying to use the :len function. How can I resolve this using this function?

Re: :len fails to count after 4095

Posted: Wed May 02, 2012 9:29 pm
by jandafields
With some creative scripting based on the approach I gave above... you will have to do something to monitor the value of len so you know how many times it rolls over.

Re: :len fails to count after 4095

Posted: Thu May 03, 2012 4:07 am
by rviteri
Alright, thanks. I'll give it a shot.

Re: :len fails to count after 4095

Posted: Fri May 11, 2012 2:08 pm
by omega-00
Unfortunately if you are trying to read a file longer than this size you're not going to have much luck. If it's just variables on the router you're working with the there's ways to break these up however drawing in content from a file requires being able to read the thing; which is not possible without the reintroduction of LUA which was originally proposed for v4 but pulled before release.


http://wiki.mikrotik.com/wiki/Manual:Lua