30ae48030566706a89fef0f5c5b5d47f94bd9668
6 if [ -z "$__n" -o -n "${__n//[0-9]/}" ]; then
7 printf "Not a decimal integer (%s)\n" "$__n ">&2
11 if [ "$__n" -gt $uint_max ]; then
12 printf "Out of range (%s)\n" "$__n" >&2
16 if [ "$((__n + 0))" != "$__n" ]; then
17 printf "Not normalized notation (%s)\n" "$__n" >&2
25 local __var
="$1" __c
="$2"
26 assert_uint32
"$__c" ||
return 1
28 __c
=$
((((__c
>> 1) & 0x55555555) + (__c
& 0x55555555)))
29 __c
=$
((((__c
>> 2) & 0x33333333) + (__c
& 0x33333333)))
30 __c
=$
((((__c
>> 4) & 0x0f0f0f0f) + (__c
& 0x0f0f0f0f)))
31 __c
=$
((((__c
>> 8) & 0x00ff00ff) + (__c
& 0x00ff00ff)))
32 __c
=$
((((__c
>> 16) & 0x0000ffff) + (__c
& 0x0000ffff)))
34 export -- "$__var=$__c"
37 # tedious but portable with busybox's limited shell
39 local __var
="$1" __ip
="$2" __n __val
=0
50 1[0-9][0-9].
*|
2[0-4][0-9].
*|
25[0-5].
*)
55 printf "Not a dotted quad (%s)\n" "$2" >&2
71 1[0-9][0-9].*|2[0-4][0-9].*|25[0-5].*)
76 printf "Not a dotted quad (%s)\n" "$2" >&2
81 __val=$((__val + (__n << 16)))
92 1[0-9][0-9].*|2[0-4][0-9].*|25[0-5].*)
97 printf "Not a dotted quad (%s)\n" "$2" >&2
102 __val=$((__val + (__n << 8)))
113 1[0-9][0-9]|2[0-4][0-9]|25[0-5])
118 printf "Not a dotted quad (%s)\n" "$2" >&2
123 __val=$((__val + __n))
125 if [ -n "$__ip" ]; then
126 printf "Not a dotted quad (%s)\n" "$2" >&2
130 export -- "$__var=$__val"
135 local __var="$1" __n="$2"
136 assert_uint32 "$__n" || return 1
138 export -- "$__var=$((__n >> 24)).$
(((__n
>> 16) & 255)).$
(((__n
>> 8) & 255)).$
((__n
& 255))"