function cidrv4BroadcastAddress
cidrv4BroadcastAddress(cidr: Cidrv4): number

Returns the directed broadcast address of a CIDR block.

The broadcast address is the block's last address — the one whose host part is all ones. It addresses every machine on the subnet at once, so it is not assignable to an interface (RFC 1812 section 5.3.5); cidrv4LastUsableAddress is the last address that is. The exception is a /31 or /32, where the whole block is assignable.

Same address as cidrv4LastAddress, under the IPv4 name for it. IPv6 has no broadcast address at all, so there is deliberately no cidrv6BroadcastAddress to pair with this one.

Examples

Getting broadcast address

import { assertEquals } from "@std/assert";
import { cidrv4BroadcastAddress, parseCidrv4 } from "@hertzg/ip/cidrv4";
import { parseAddressv4 } from "@hertzg/ip/addressv4";

const cidr = parseCidrv4("192.168.1.0/24");
assertEquals(cidrv4BroadcastAddress(cidr), parseAddressv4("192.168.1.255").address);

The broadcast address is not assignable, the one before it is

import { assertEquals } from "@std/assert";
import {
  cidrv4BroadcastAddress,
  cidrv4LastUsableAddress,
  parseCidrv4,
} from "@hertzg/ip/cidrv4";
import { stringifyAddressv4 } from "@hertzg/ip/addressv4";

const cidr = parseCidrv4("10.0.0.0/24");
assertEquals(stringifyAddressv4(cidrv4BroadcastAddress(cidr)), "10.0.0.255");
assertEquals(stringifyAddressv4(cidrv4LastUsableAddress(cidr)), "10.0.0.254");

Parameters

cidr: Cidrv4

The CIDR block

Return Type

number

The broadcast address as a 32-bit unsigned integer