/* Get the last host in a CIDR block */ CIDR * cidr_addr_hostmax(const CIDR *addr) { CIDR *toret; toret = cidr_addr_broadcast(addr); if(toret==NULL) return(NULL); /* Preserve errno */ toret->addr[15] &= 0xfe; return(toret); }
/* Is it an IPv4 broadcast address? */ int is_ipv4_broadcast(CIDR *address) { int result; /* The very concept of broadcast address doesn't apply to IPv6 and point-to-point or /32 IPv4 */ if( (cidr_get_proto(address) == CIDR_IPV4) && (cidr_equals(address, cidr_addr_broadcast(address)) == 0 ) && (cidr_get_pflen(address) < 31) ) { result = RESULT_SUCCESS; } else { result = RESULT_FAILURE; } return(result); }