OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / pluto / test / bin / ipnext
1
2 # ipnext: increment a dotted quad IP address
3
4 set -u
5
6 for i
7 do
8
9         INC=/bin/true
10
11         n="$i"
12
13         while $INC
14         do
15
16             # check that we have a dotted quad
17
18             if expr match "X$n" 'X[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null
19             then
20                     :
21             else
22                     echo "\"$n\" isn't a dotted quad" >&2
23                     exit 1
24             fi
25
26             # break out fields of dotted quad
27             q1=`expr match "X$n" 'X\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$'`
28             q2=`expr match "X$n" 'X[0-9][0-9]*\.\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*$'`
29             q3=`expr match "X$n" 'X[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)\.[0-9][0-9]*$'`
30             q4=`expr match "X$n" 'X[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)$'`
31
32             # increment by 7.123.59.229 (arbitrary)
33             q1=`expr $q1 + 7`
34             q2=`expr $q2 + 123`
35             q3=`expr $q3 + 59`
36             q4=`expr $q4 + 229`
37
38             # perform carry
39             q1=`expr '(' $q1 + $q2 / 256 ')' % 256`
40             q2=`expr '(' $q2 + $q3 / 256 ')' % 256`
41             q3=`expr '(' $q3 + $q4 / 256 ')' % 256`
42             q4=`expr $q4 % 256`
43
44             # around again if unroutable address
45             n="$q1.$q2.$q3.$q4"
46             case "$n" in
47             10.*|192.168.*|172.16.[0-9].*|172.16.1[0-5].*|127.*)
48                 ;;
49             *)  INC=/bin/false
50             esac
51         done
52
53         echo "$n"
54 done