Canonicalize CIDR: Difference between revisions
Content deleted Content added
m →{{header|Wren}}: Removed an unnecessary space. |
→{{header|Go}}: Changed to cope with the extra examples. |
||
Line 203:
"fmt"
"log"
"os"▼
"strconv"
"strings"
)
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {▼
func canonicalize(cidr string) string {
▲ // canonicalize a CIDR block: make sure none of the host bits are set
var cidr string▼
} else {▼
// dotted-decimal / bits in network part
split := strings.Split(cidr, "/")
Line 249 ⟶ 241:
}
// and
}
▲func main() {
"87.70.141.1/22",
"36.18.154.103/12",
"62.62.197.11/29",
"67.137.119.181/4",
"161.214.74.21/24",
"184.232.176.184/18",
for _, test := range tests {
fmt.Printf("%-18s -> %s\n", test, canonicalize(test))
}</lang>
{{out}}
<pre>
36.18.154.103/12 -> 36.16.0.0/12
62.62.197.11/29 -> 62.62.197.8/29
67.137.119.181/4 -> 64.0.0.0/4
161.214.74.21/24 -> 161.214.74.0/24
184.232.176.184/18 -> 184.232.128.0/18
</pre>
|