Forum Discussion

Ralf_Bruenig_74's avatar
Ralf_Bruenig_74
Historic F5 Account
Jun 02, 2008

workaround for 32 bit integer limitation

Hi all,

 

 

I need to extract the IP address out of the insert cookie. For this I found the following example on your page:

 

http://devcentral.f5.com/wiki/default.aspx/iRules/Persistence_Cookie_Logger.html

 

 

The problem is this works only for members with IP addresses a.b.c.d where d is < 128. This is most likely, because the integer of tcl is limited to 32 bit minus 1 bit for the sign.

 

 

Is there any way around this problem?

 

 

Thanks for your answer.

 

Ralf

 

  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    I found an interesting post with some suggestions to force from integer to float - Click here

     

     

     

    I guess I'd try forcing to scientific notation first:

     

    Hume Smith gave a clever solution in news:comp.lang.tcl :

     

     

    append i "e0"

     

     

    makes it look like scientific notation, meaning "multiplied by 10 to the 0th power, which is 1", which forces the string to a floatstring (i.e. that expr interprets as double) with pure string manipulation.

     

    If I understand the recommendation correctly, you might be able to just change these 2 lines of code:

     

     
         set myIpH [format %08x $myIpE] 
      
         set myPortH [format %x $myPortE] 
     

     

    to this:

     

     
         set myIpH [format %08x $myIpE] 
         append "e0" myIpH 
      
         set myPortH [format %x $myPortE] 
         append "e0" myPortH 
     

     

     

    HTH, and please post back your results and/or update the codeshare with a better soluiton.

     

     

    thx

     

    /deb
  • Ralf_Bruenig_74's avatar
    Ralf_Bruenig_74
    Historic F5 Account
    Hi deb,

     

     

    Thanks for your answer.

     

     

    Actually it didn’t solve the problem since we have the issue already at the following line:

     

     

    scan [HTTP::cookie $::myCookieName] "%d.%d.%d" myIpE myPortE unused

     

     

     

    The problem is, that the string will be changed to integer with the %d statement. I did some further research and found that there is also a way to get the unsigned integer with the %u parameter. I really wonder why I haven’t seen that before.

     

    With the following line it works fine:

     

     

    scan [HTTP::cookie $::myCookieName] "%u.%d.%d" myIpE myPortE unused

     

     

     

    It is actually not necessary to do the same thing with the ports since they anyway limited to 16 bits.

     

     

    It would be great when somebody could fix this iRule in the iRules Samples list.

     

     

    Cheers

     

    Ralf