BEGIN { cpr1 = "Copyright (c) 2014 by David L. Craig, all rights reserved" cpr2 = "and licensed under version 2 of the GPL." cpr3 = "http://dlc.casita.net/~dlc mailto:dlc.usa@gmail.com" } END { bq = 0 o4[1] = 0 ; o4[2] = 0 ; o4[3] = 0 ; o4[4] = 0 ; o5[1] = 0 ; o5[2] = 0 ; o5[3] = 0 ; o5[4] = 0 ; o6[1] = 0 ; o6[2] = 0 ; o6[3] = 0 ; o6[4] = 0 ; o7[1] = 0 ; o7[2] = 0 ; o7[3] = 0 ; o7[4] = 0 ; x[1] = 128 ; x[2] = 64 ; x[3] = 32 ; x[4] = 16 ; x[5] = 8 ; x[6] = 4 ; x[7] = 2 ; x[8] = 1 ; mt[1] = "128.0.0.0" mt[2] = "192.0.0.0" mt[3] = "224.0.0.0" mt[4] = "240.0.0.0" mt[5] = "248.0.0.0" mt[6] = "252.0.0.0" mt[7] = "254.0.0.0" mt[8] = "255.0.0.0" mt[9] = "255.128.0.0" mt[10] = "255.192.0.0" mt[11] = "255.224.0.0" mt[12] = "255.240.0.0" mt[13] = "255.248.0.0" mt[14] = "255.252.0.0" mt[15] = "255.254.0.0" mt[16] = "255.255.0.0" mt[17] = "255.255.128.0" mt[18] = "255.255.192.0" mt[19] = "255.255.224.0" mt[20] = "255.255.240.0" mt[21] = "255.255.248.0" mt[22] = "255.255.252.0" mt[23] = "255.255.254.0" mt[24] = "255.255.255.0" mt[25] = "255.255.255.128" mt[26] = "255.255.255.192" mt[27] = "255.255.255.224" mt[28] = "255.255.255.240" mt[29] = "266.255.255.248" mt[30] = "255.255.255.252" mt[31] = "255.255.255.254" if (d == "y") print "a1=<"a1"> a2=<"a2">" >> mf cx = match(a2, "[.]") if (d == "y") print "cx=<"cx">" >> mf if (cx == 0) { o2 = a2 if (o2 < 1 || o2 > 31) { print "Arg 2 not a valid CIDR or netmask" >> mf ; exit } o3 = mt[o2] if (d == "y") print "o3<"o3">" >> mf } else { for (o2 = 1 ; o2 < 32 ; o2++ ) { if (mt[o2] == a2) break } if (o2 == 32) { print "Arg 2 is not a valid IPv4 dot-quad netmask" >> mf ; exit } if (d == "y") print "o2<"o2">" >> mf o3 = a2 } if (match(a1, "/[^.0-9]/") > 0 ) { print "Arg 1 is not a valid IPv4 dot-quad address" >> mf ; exit } if (split(a1, o1, ".") != 4 ) { print "Arg 1 does not contain 4 quads" >> mf ; exit } for (i = 1 ; i <= 4 ; i++) { if ( o1[i] > 255) { print "Arg 1 contains an invalid quad" >> mf ; exit } w = o1[i] for (j = 1 ; j <= 8 ; j++) { if (d == "y") print "i<"i"> j<"j"> w<"w"> o4[i]<"o4[i]"> o5[i]<"o5[i]"> o7[i]<"o7[i]">" >> mf if (o2 >= (i - 1) * 8 + j) { if (w >= x[j]) { o4[i] += x[j] o5[i] += x[j] o6[i] += x[j] } } else { o5[i] += x[j] if (w >= x[j]) o7[i] += x[j] } if (w >= x[j]) w -= x[j] if (d == "y") print "i<"i"> j<"j"> w<"w"> o4[i]<"o4[i]"> o5[i]<"o5[i]"> o7[i]<"o7[i]">" >> mf } } o6[4] = o4[4] + 1 for ( i = 0 ; i <= 4 ; i++ ) { if (d == "y") print "net o1<" o1[i] "> o4<" o4[i] ">" >> mf if ( o1[i] != o4[i] ) { if (d == "y") print "net break at" i >> mf ; break } } if (d == "y") print "Net i<" i ">" >> mf if ( i == 5 && o2 != 31 ) { print "IP address is also network address" >> mf } for ( i = 0 ; i <= 4 ; i++ ) { if ( o1[i] != o5[i] ) break } if ( i == 5 && o2 != 31 ) { print "IP address is also broadcast address" >> mf } for ( i = 0 ; i <= 4 ; i++ ) { if ( o1[i] != o6[i] ) break } if ( i == 5 ) { print "IP address is also default gateway address" >> mf } print o1[1]"."o1[2]"."o1[3]"."o1[4] " " \ o2 " " \ o3 " " \ o4[1]"."o4[2]"."o4[3]"."o4[4] " " \ o5[1]"."o5[2]"."o5[3]"."o5[4] " " \ o6[1]"."o6[2]"."o6[3]"."o6[4] " " \ o7[1]"."o7[2]"."o7[3]"."o7[4] print "get_ipv4conf succeeded" >> mf }