Canonicalize CIDR: Difference between revisions

Content added Content deleted
(Add more examples.)
m (→‎{{header|REXX}}: changed a comment, updated example nodes.)
Line 434: Line 434:
parse arg a . /*obtain optional argument from the CL.*/
parse arg a . /*obtain optional argument from the CL.*/
if a=='' | a=="," then a= '87.70.141.1/22' , /*Not specified? Then use the defaults*/
if a=='' | a=="," then a= '87.70.141.1/22' , /*Not specified? Then use the defaults*/
'100.68.0.18/18' ,
'36.18.154.103/12' ,
'10.4.30.77/30' ,
'62.62.197.11/29' ,
'10.207.219.251/32' ,
'67.137.119.181/4' ,
'10.207.219.251' ,
'161.214.74.21/24' ,
'110.200.21/4' ,
'184.232.176.184/18'
'10.11.12.13/8'


do i=1 for words(a); z= word(a, i) /*process each IPv4 address in the list*/
do i=1 for words(a); z= word(a, i) /*process each IPv4 address in the list*/
Line 453: Line 452:
##= left(##, 32, 0) /*replace cropped bits with binary '0's*/
##= left(##, 32, 0) /*replace cropped bits with binary '0's*/
do j=8 by 8 for 4 /* [↓] parse the four nodes of address*/
do j=8 by 8 for 4 /* [↓] parse the four nodes of address*/
$= $ || . || b2d(substr(##, j-7, 8)) /*reconstitute decimal nodes.*/
$= $ || . || b2d(substr(##, j-7, 8)) /*reconstitute the decimal nodes. */
end /*j*/ /* [↑] and insert a dot between nodes.*/
end /*j*/ /* [↑] and insert a dot between nodes.*/
say /*introduce a blank line between IPv4's*/
say /*introduce a blank line between IPv4's*/
Line 469: Line 468:
canonicalized address: 87.70.140.0/22
canonicalized address: 87.70.140.0/22


original IPv4 address: 100.68.0.18/18
original IPv4 address: 36.18.154.103/12
canonicalized address: 100.68.0.0/18
canonicalized address: 36.16.0.0/12


original IPv4 address: 10.4.30.77/30
original IPv4 address: 62.62.197.11/29
canonicalized address: 10.4.30.76/30
canonicalized address: 62.62.197.8/29


original IPv4 address: 10.207.219.251/32
original IPv4 address: 67.137.119.181/4
canonicalized address: 10.207.219.251/32
canonicalized address: 64.0.0.0/4


original IPv4 address: 10.207.219.251
original IPv4 address: 161.214.74.21/24
canonicalized address: 10.207.219.251
canonicalized address: 161.214.74.0/24


original IPv4 address: 110.200.21/4
original IPv4 address: 184.232.176.184/18
canonicalized address: 96.0.0.0/4
canonicalized address: 184.232.128.0/18

original IPv4 address: 10.11.12.13/8
canonicalized address: 10.0.0.0/8
</pre>
</pre>