Hello everybody, for my Case I needed to change one Octett of my NAS-IP-Address ( like from x.x.4.x to x.x.5.x )! I don't really found an function to change only one octett from the NAS-IP-Address, so I did it with Bit-Shifting ;) You could use the following Code Snipet in an C or C++ Module My Code looks so: VALUE_PAIR *vp; vp = pairfind(request->packet->vps,1); while(vp) { // Default Operations to Change the NAS-IP-Addres on certain value // if (...) ... VALUE_PAIR *state; state = pairfind(request->packet->vps, 4); if(state != NULL) { int octett = 77; struct in_addr addr; addr.s_addr = ((octett << 16) | (state->vp_ipaddr & 0xff00ffff)) // Change the third octett from the NAS-IP-Address to 77 state->data.ipaddr = addr; } { Greetz Patrick
On Tue, Mar 12, 2013 at 07:57:48AM +0100, Patrick Kowalik wrote:
Hello everybody, for my Case I needed to change one Octett of my NAS-IP-Address ( like from x.x.4.x to x.x.5.x )!
In what way did you want to change the third octet? Only replace 4 with 5? Replace any value with that value plus one?
I don't really found an function to change only one octett from the NAS-IP-Address
Sure, you can easily do it in unlang. For example to change x.x.4.x to x.x.5.x: if (NAS-IP-Address =~ /^([0-9]+\.[0-9]+)\.4\.([0-9]+)$/) { update request { NAS-IP-Address := "%{1}.5.%{2}" } } If you wanted to add 1 to an octet you can use the expr module to do that, e.g. %{eval: %{2} + 1}. See 'man rlm_expr' for more examples. Anyway, this is really a user question not a devel question. Regards, Brian.
participants (2)
-
Brian Candler -
Patrick Kowalik