base-files: ipcalc.sh: trim for statement

For gawk compatibility.

Signed-off-by: Leon M. George <leon@georgemail.eu>
This commit is contained in:
Leon M. George 2022-10-14 14:08:19 +02:00 committed by Christian Marangi
parent e4bd3de1be
commit 2903924b57
No known key found for this signature in database
GPG Key ID: AC001D09ADBFEAD7

View File

@ -10,14 +10,20 @@ function bitcount(c) {
} }
function ip2int(ip) { function ip2int(ip) {
for (ret=0,n=split(ip,a,"\."),x=1;x<=n;x++) ret=or(lshift(ret,8),a[x]) ret=0
n=split(ip,a,"\.")
for (x=1;x<=n;x++)
ret=or(lshift(ret,8),a[x])
return ret return ret
} }
function int2ip(ip,ret,x) { function int2ip(ip,ret,x) {
ret=and(ip,255) ret=and(ip,255)
ip=rshift(ip,8) ip=rshift(ip,8)
for(;x<3;ret=and(ip,255)"."ret,ip=rshift(ip,8),x++); for(;x<3;x++) {
ret=and(ip,255)"."ret
ip=rshift(ip,8)
}
return ret return ret
} }