[EXT] Convert an integer to a MAC address in unlang / expr
Brian Julin
BJulin at clarku.edu
Thu Aug 27 17:02:01 CEST 2020
James Wood <james.wood at purplewifi.com>
> Thanks Brian and Alan for your advice.
>
> If I just perform the mask transform on the last octet this works but of
> course it returns the result as an int, so I can't find any built in
> function to get that back to hex.
> This is what I've ended up with; please let me know if you feel there is a
> better/cleaner way without needing the IF statement
Take only the first digit into %{6}. Then mask with 0xC. Then divide by 16.
0/16 is 0, 64/16 is 4, 128/16 is 8 and 192/16 is 12.
So then just one if statement makes 12 into "C" and you can just put
that back in with a hard coded 0 after it... no need to convert 0 to "0"
or 4 to "4" or 8 to "8", they should stringify on their own.
More information about the Freeradius-Users
mailing list