text: #include <sys/types.h>
  #include <arpa/inet.h>
  
  #include <stdbool.h>
  #include <stddef.h>
  #include <stdio.h>
  
  #include "dat.h"
  #include "fns.h"
  
  void
  test(char *snetmask, int expected)
  {
  	if (isvalidnetmask(ntohl(inet_addr(snetmask))) != expected) {
  		printf("isvalidnetmask(\"%s\") != %d\n", snetmask, expected);
  	}
  }
  
  int
  main(void)
  {
  	// Test all valid netmasks explicitly.
  	test("255.255.255.255", true);
  	test("255.255.255.254", true);
  	test("255.255.255.252", true);
  	test("255.255.255.248", true);
  	test("255.255.255.240", true);
  	test("255.255.255.224", true);
  	test("255.255.255.192", true);
  	test("255.255.255.128", true);
  	test("255.255.255.0", true);
  	test("255.255.254.0", true);
  	test("255.255.252.0", true);
  	test("255.255.248.0", true);
  	test("255.255.240.0", true);
  	test("255.255.224.0", true);
  	test("255.255.192.0", true);
  	test("255.255.128.0", true);
  	test("255.255.0.0", true);
  	test("255.254.0.0", true);
  	test("255.252.0.0", true);
  	test("255.248.0.0", true);
  	test("255.240.0.0", true);
  	test("255.224.0.0", true);
  	test("255.192.0.0", true);
  	test("255.128.0.0", true);
  	test("255.0.0.0", true);
  	test("254.0.0.0", true);
  	test("252.0.0.0", true);
  	test("248.0.0.0", true);
  	test("240.0.0.0", true);
  	test("224.0.0.0", true);
  	test("192.0.0.0", true);
  	test("128.0.0.0", true);
  	test("0.0.0.0", true);
  
  	// Test all permutations of the last octet.
  	test("255.255.255.1", false);
  	test("255.255.255.2", false);
  	test("255.255.255.3", false);
  	test("255.255.255.4", false);
  	test("255.255.255.5", false);
  	test("255.255.255.6", false);
  	test("255.255.255.7", false);
  	test("255.255.255.8", false);
  	test("255.255.255.9", false);
  	test("255.255.255.10", false);
  	test("255.255.255.11", false);
  	test("255.255.255.12", false);
  	test("255.255.255.13", false);
  	test("255.255.255.14", false);
  	test("255.255.255.15", false);
  	test("255.255.255.16", false);
  	test("255.255.255.17", false);
  	test("255.255.255.18", false);
  	test("255.255.255.19", false);
  	test("255.255.255.20", false);
  	test("255.255.255.21", false);
  	test("255.255.255.22", false);
  	test("255.255.255.23", false);
  	test("255.255.255.24", false);
  	test("255.255.255.25", false);
  	test("255.255.255.26", false);
  	test("255.255.255.27", false);
  	test("255.255.255.28", false);
  	test("255.255.255.29", false);
  	test("255.255.255.30", false);
  	test("255.255.255.31", false);
  	test("255.255.255.32", false);
  	test("255.255.255.33", false);
  	test("255.255.255.34", false);
  	test("255.255.255.35", false);
  	test("255.255.255.36", false);
  	test("255.255.255.37", false);
  	test("255.255.255.38", false);
  	test("255.255.255.39", false);
  	test("255.255.255.40", false);
  	test("255.255.255.41", false);
  	test("255.255.255.42", false);
  	test("255.255.255.43", false);
  	test("255.255.255.44", false);
  	test("255.255.255.45", false);
  	test("255.255.255.46", false);
  	test("255.255.255.47", false);
  	test("255.255.255.48", false);
  	test("255.255.255.49", false);
  	test("255.255.255.50", false);
  	test("255.255.255.51", false);
  	test("255.255.255.52", false);
  	test("255.255.255.53", false);
  	test("255.255.255.54", false);
  	test("255.255.255.55", false);
  	test("255.255.255.56", false);
  	test("255.255.255.57", false);
  	test("255.255.255.58", false);
  	test("255.255.255.59", false);
  	test("255.255.255.60", false);
  	test("255.255.255.61", false);
  	test("255.255.255.62", false);
  	test("255.255.255.63", false);
  	test("255.255.255.64", false);
  	test("255.255.255.65", false);
  	test("255.255.255.66", false);
  	test("255.255.255.67", false);
  	test("255.255.255.68", false);
  	test("255.255.255.69", false);
  	test("255.255.255.70", false);
  	test("255.255.255.71", false);
  	test("255.255.255.72", false);
  	test("255.255.255.73", false);
  	test("255.255.255.74", false);
  	test("255.255.255.75", false);
  	test("255.255.255.76", false);
  	test("255.255.255.77", false);
  	test("255.255.255.78", false);
  	test("255.255.255.79", false);
  	test("255.255.255.80", false);
  	test("255.255.255.81", false);
  	test("255.255.255.82", false);
  	test("255.255.255.83", false);
  	test("255.255.255.84", false);
  	test("255.255.255.85", false);
  	test("255.255.255.86", false);
  	test("255.255.255.87", false);
  	test("255.255.255.88", false);
  	test("255.255.255.89", false);
  	test("255.255.255.90", false);
  	test("255.255.255.91", false);
  	test("255.255.255.92", false);
  	test("255.255.255.93", false);
  	test("255.255.255.94", false);
  	test("255.255.255.95", false);
  	test("255.255.255.96", false);
  	test("255.255.255.97", false);
  	test("255.255.255.98", false);
  	test("255.255.255.99", false);
  	test("255.255.255.100", false);
  	test("255.255.255.101", false);
  	test("255.255.255.102", false);
  	test("255.255.255.103", false);
  	test("255.255.255.104", false);
  	test("255.255.255.105", false);
  	test("255.255.255.106", false);
  	test("255.255.255.107", false);
  	test("255.255.255.108", false);
  	test("255.255.255.109", false);
  	test("255.255.255.110", false);
  	test("255.255.255.111", false);
  	test("255.255.255.112", false);
  	test("255.255.255.113", false);
  	test("255.255.255.114", false);
  	test("255.255.255.115", false);
  	test("255.255.255.116", false);
  	test("255.255.255.117", false);
  	test("255.255.255.118", false);
  	test("255.255.255.119", false);
  	test("255.255.255.120", false);
  	test("255.255.255.121", false);
  	test("255.255.255.122", false);
  	test("255.255.255.123", false);
  	test("255.255.255.124", false);
  	test("255.255.255.125", false);
  	test("255.255.255.126", false);
  	test("255.255.255.127", false);
  	test("255.255.255.129", false);
  	test("255.255.255.130", false);
  	test("255.255.255.131", false);
  	test("255.255.255.132", false);
  	test("255.255.255.133", false);
  	test("255.255.255.134", false);
  	test("255.255.255.135", false);
  	test("255.255.255.136", false);
  	test("255.255.255.137", false);
  	test("255.255.255.138", false);
  	test("255.255.255.139", false);
  	test("255.255.255.140", false);
  	test("255.255.255.141", false);
  	test("255.255.255.142", false);
  	test("255.255.255.143", false);
  	test("255.255.255.144", false);
  	test("255.255.255.145", false);
  	test("255.255.255.146", false);
  	test("255.255.255.147", false);
  	test("255.255.255.148", false);
  	test("255.255.255.149", false);
  	test("255.255.255.150", false);
  	test("255.255.255.151", false);
  	test("255.255.255.152", false);
  	test("255.255.255.153", false);
  	test("255.255.255.154", false);
  	test("255.255.255.155", false);
  	test("255.255.255.156", false);
  	test("255.255.255.157", false);
  	test("255.255.255.158", false);
  	test("255.255.255.159", false);
  	test("255.255.255.160", false);
  	test("255.255.255.161", false);
  	test("255.255.255.162", false);
  	test("255.255.255.163", false);
  	test("255.255.255.164", false);
  	test("255.255.255.165", false);
  	test("255.255.255.166", false);
  	test("255.255.255.167", false);
  	test("255.255.255.168", false);
  	test("255.255.255.169", false);
  	test("255.255.255.170", false);
  	test("255.255.255.171", false);
  	test("255.255.255.172", false);
  	test("255.255.255.173", false);
  	test("255.255.255.174", false);
  	test("255.255.255.175", false);
  	test("255.255.255.176", false);
  	test("255.255.255.177", false);
  	test("255.255.255.178", false);
  	test("255.255.255.179", false);
  	test("255.255.255.180", false);
  	test("255.255.255.181", false);
  	test("255.255.255.182", false);
  	test("255.255.255.183", false);
  	test("255.255.255.184", false);
  	test("255.255.255.185", false);
  	test("255.255.255.186", false);
  	test("255.255.255.187", false);
  	test("255.255.255.188", false);
  	test("255.255.255.189", false);
  	test("255.255.255.190", false);
  	test("255.255.255.191", false);
  	test("255.255.255.193", false);
  	test("255.255.255.194", false);
  	test("255.255.255.195", false);
  	test("255.255.255.196", false);
  	test("255.255.255.197", false);
  	test("255.255.255.198", false);
  	test("255.255.255.199", false);
  	test("255.255.255.200", false);
  	test("255.255.255.201", false);
  	test("255.255.255.202", false);
  	test("255.255.255.203", false);
  	test("255.255.255.204", false);
  	test("255.255.255.205", false);
  	test("255.255.255.206", false);
  	test("255.255.255.207", false);
  	test("255.255.255.208", false);
  	test("255.255.255.209", false);
  	test("255.255.255.210", false);
  	test("255.255.255.211", false);
  	test("255.255.255.212", false);
  	test("255.255.255.213", false);
  	test("255.255.255.214", false);
  	test("255.255.255.215", false);
  	test("255.255.255.216", false);
  	test("255.255.255.217", false);
  	test("255.255.255.218", false);
  	test("255.255.255.219", false);
  	test("255.255.255.220", false);
  	test("255.255.255.221", false);
  	test("255.255.255.222", false);
  	test("255.255.255.223", false);
  	test("255.255.255.225", false);
  	test("255.255.255.226", false);
  	test("255.255.255.227", false);
  	test("255.255.255.228", false);
  	test("255.255.255.229", false);
  	test("255.255.255.230", false);
  	test("255.255.255.231", false);
  	test("255.255.255.232", false);
  	test("255.255.255.233", false);
  	test("255.255.255.234", false);
  	test("255.255.255.235", false);
  	test("255.255.255.236", false);
  	test("255.255.255.237", false);
  	test("255.255.255.238", false);
  	test("255.255.255.239", false);
  	test("255.255.255.241", false);
  	test("255.255.255.242", false);
  	test("255.255.255.243", false);
  	test("255.255.255.244", false);
  	test("255.255.255.245", false);
  	test("255.255.255.246", false);
  	test("255.255.255.247", false);
  	test("255.255.255.249", false);
  	test("255.255.255.250", false);
  	test("255.255.255.251", false);
  	test("255.255.255.253", false);
  	test("255.255.255.255", true);
  
  	// Probe a few other values.
  	test("44.0.0.1", false);
  	test("127.0.0.1", false);
  	test("255.255.191.0", false);
  	test("255.255.254.1", false);
  	test("255.255.254.2", false);
  	test("255.255.254.3", false);
  	test("255.255.254.4", false);
  	test("255.255.254.5", false);
  	test("255.255.254.6", false);
  	test("255.255.254.7", false);
  	test("255.255.254.8", false);
  	test("255.255.254.9", false);
  	test("255.255.254.10", false);
  	test("255.255.254.11", false);
  	test("255.255.254.12", false);
  	test("255.255.254.13", false);
  	test("255.255.254.14", false);
  	test("255.255.254.15", false);
  	test("255.255.254.16", false);
  	test("255.255.254.17", false);
  	test("255.255.254.18", false);
  	test("255.255.254.19", false);
  	test("255.255.254.20", false);
  	test("255.255.254.21", false);
  	test("255.255.254.22", false);
  	test("255.255.254.23", false);
  	test("255.255.254.24", false);
  	test("255.255.254.25", false);
  	test("255.255.254.26", false);
  	test("255.255.254.27", false);
  	test("255.255.254.28", false);
  	test("255.255.254.29", false);
  	test("255.255.254.30", false);
  	test("255.255.254.31", false);
  	test("255.255.254.32", false);
  	test("255.255.254.33", false);
  	test("255.255.254.34", false);
  	test("255.255.254.35", false);
  	test("255.255.254.36", false);
  	test("255.255.254.37", false);
  	test("255.255.254.38", false);
  	test("255.255.254.39", false);
  	test("255.255.254.40", false);
  	test("255.255.254.41", false);
  	test("255.255.254.42", false);
  	test("255.255.254.43", false);
  	test("255.255.254.44", false);
  	test("255.255.254.45", false);
  	test("255.255.254.46", false);
  	test("255.255.254.47", false);
  	test("255.255.254.48", false);
  	test("255.255.254.49", false);
  	test("255.255.254.50", false);
  	test("255.255.254.51", false);
  	test("255.255.254.52", false);
  	test("255.255.254.53", false);
  	test("255.255.254.54", false);
  	test("255.255.254.55", false);
  	test("255.255.254.56", false);
  	test("255.255.254.57", false);
  	test("255.255.254.58", false);
  	test("255.255.254.59", false);
  	test("255.255.254.60", false);
  	test("255.255.254.61", false);
  	test("255.255.254.62", false);
  	test("255.255.254.63", false);
  	test("255.255.254.64", false);
  	test("255.255.254.65", false);
  	test("255.255.254.66", false);
  	test("255.255.254.67", false);
  	test("255.255.254.68", false);
  	test("255.255.254.69", false);
  	test("255.255.254.70", false);
  	test("255.255.254.71", false);
  	test("255.255.254.72", false);
  	test("255.255.254.73", false);
  	test("255.255.254.74", false);
  	test("255.255.254.75", false);
  	test("255.255.254.76", false);
  	test("255.255.254.77", false);
  	test("255.255.254.78", false);
  	test("255.255.254.79", false);
  	test("255.255.254.80", false);
  	test("255.255.254.81", false);
  	test("255.255.254.82", false);
  	test("255.255.254.83", false);
  	test("255.255.254.84", false);
  	test("255.255.254.85", false);
  	test("255.255.254.86", false);
  	test("255.255.254.87", false);
  	test("255.255.254.88", false);
  	test("255.255.254.89", false);
  	test("255.255.254.90", false);
  	test("255.255.254.91", false);
  	test("255.255.254.92", false);
  	test("255.255.254.93", false);
  	test("255.255.254.94", false);
  	test("255.255.254.95", false);
  	test("255.255.254.96", false);
  	test("255.255.254.97", false);
  	test("255.255.254.98", false);
  	test("255.255.254.99", false);
  	test("255.255.254.100", false);
  	test("255.255.254.101", false);
  	test("255.255.254.102", false);
  	test("255.255.254.103", false);
  	test("255.255.254.104", false);
  	test("255.255.254.105", false);
  	test("255.255.254.106", false);
  	test("255.255.254.107", false);
  	test("255.255.254.108", false);
  	test("255.255.254.109", false);
  	test("255.255.254.110", false);
  	test("255.255.254.111", false);
  	test("255.255.254.112", false);
  	test("255.255.254.113", false);
  	test("255.255.254.114", false);
  	test("255.255.254.115", false);
  	test("255.255.254.116", false);
  	test("255.255.254.117", false);
  	test("255.255.254.118", false);
  	test("255.255.254.119", false);
  	test("255.255.254.120", false);
  	test("255.255.254.121", false);
  	test("255.255.254.122", false);
  	test("255.255.254.123", false);
  	test("255.255.254.124", false);
  	test("255.255.254.125", false);
  	test("255.255.254.126", false);
  	test("255.255.254.127", false);
  	test("255.255.254.128", false);
  	test("255.255.254.129", false);
  	test("255.255.254.130", false);
  	test("255.255.254.131", false);
  	test("255.255.254.132", false);
  	test("255.255.254.133", false);
  	test("255.255.254.134", false);
  	test("255.255.254.135", false);
  	test("255.255.254.136", false);
  	test("255.255.254.137", false);
  	test("255.255.254.138", false);
  	test("255.255.254.139", false);
  	test("255.255.254.140", false);
  	test("255.255.254.141", false);
  	test("255.255.254.142", false);
  	test("255.255.254.143", false);
  	test("255.255.254.144", false);
  	test("255.255.254.145", false);
  	test("255.255.254.146", false);
  	test("255.255.254.147", false);
  	test("255.255.254.148", false);
  	test("255.255.254.149", false);
  	test("255.255.254.150", false);
  	test("255.255.254.151", false);
  	test("255.255.254.152", false);
  	test("255.255.254.153", false);
  	test("255.255.254.154", false);
  	test("255.255.254.155", false);
  	test("255.255.254.156", false);
  	test("255.255.254.157", false);
  	test("255.255.254.158", false);
  	test("255.255.254.159", false);
  	test("255.255.254.160", false);
  	test("255.255.254.161", false);
  	test("255.255.254.162", false);
  	test("255.255.254.163", false);
  	test("255.255.254.164", false);
  	test("255.255.254.165", false);
  	test("255.255.254.166", false);
  	test("255.255.254.167", false);
  	test("255.255.254.168", false);
  	test("255.255.254.169", false);
  	test("255.255.254.170", false);
  	test("255.255.254.171", false);
  	test("255.255.254.172", false);
  	test("255.255.254.173", false);
  	test("255.255.254.174", false);
  	test("255.255.254.175", false);
  	test("255.255.254.176", false);
  	test("255.255.254.177", false);
  	test("255.255.254.178", false);
  	test("255.255.254.179", false);
  	test("255.255.254.180", false);
  	test("255.255.254.181", false);
  	test("255.255.254.182", false);
  	test("255.255.254.183", false);
  	test("255.255.254.184", false);
  	test("255.255.254.185", false);
  	test("255.255.254.186", false);
  	test("255.255.254.187", false);
  	test("255.255.254.188", false);
  	test("255.255.254.189", false);
  	test("255.255.254.190", false);
  	test("255.255.254.191", false);
  	test("255.255.254.192", false);
  	test("255.255.254.193", false);
  	test("255.255.254.194", false);
  	test("255.255.254.195", false);
  	test("255.255.254.196", false);
  	test("255.255.254.197", false);
  	test("255.255.254.198", false);
  	test("255.255.254.199", false);
  	test("255.255.254.200", false);
  	test("255.255.254.201", false);
  	test("255.255.254.202", false);
  	test("255.255.254.203", false);
  	test("255.255.254.204", false);
  	test("255.255.254.205", false);
  	test("255.255.254.206", false);
  	test("255.255.254.207", false);
  	test("255.255.254.208", false);
  	test("255.255.254.209", false);
  	test("255.255.254.210", false);
  	test("255.255.254.211", false);
  	test("255.255.254.212", false);
  	test("255.255.254.213", false);
  	test("255.255.254.214", false);
  	test("255.255.254.215", false);
  	test("255.255.254.216", false);
  	test("255.255.254.217", false);
  	test("255.255.254.218", false);
  	test("255.255.254.219", false);
  	test("255.255.254.220", false);
  	test("255.255.254.221", false);
  	test("255.255.254.222", false);
  	test("255.255.254.223", false);
  	test("255.255.254.224", false);
  	test("255.255.254.225", false);
  	test("255.255.254.226", false);
  	test("255.255.254.227", false);
  	test("255.255.254.228", false);
  	test("255.255.254.229", false);
  	test("255.255.254.230", false);
  	test("255.255.254.231", false);
  	test("255.255.254.232", false);
  	test("255.255.254.233", false);
  	test("255.255.254.234", false);
  	test("255.255.254.235", false);
  	test("255.255.254.236", false);
  	test("255.255.254.237", false);
  	test("255.255.254.238", false);
  	test("255.255.254.239", false);
  	test("255.255.254.240", false);
  	test("255.255.254.241", false);
  	test("255.255.254.242", false);
  	test("255.255.254.243", false);
  	test("255.255.254.244", false);
  	test("255.255.254.245", false);
  	test("255.255.254.246", false);
  	test("255.255.254.247", false);
  	test("255.255.254.248", false);
  	test("255.255.254.249", false);
  	test("255.255.254.250", false);
  	test("255.255.254.251", false);
  	test("255.255.254.252", false);
  	test("255.255.254.253", false);
  	test("255.255.254.254", false);
  	test("255.255.254.255", false);
  
  	return 0;
  }
  