function cidrv4NetworkAddress
cidrv4NetworkAddress(cidr: Cidrv4): number

Returns the network address of a CIDR block.

The network address is the block's first address — the one whose host part is all zeros. It names the subnet itself rather than a machine on it, so it is not assignable to an interface (RFC 1812 section 5.3.5); cidrv4FirstUsableAddress is the first address that is. The exception is a /31 or /32, where the whole block is assignable.

Same address as cidrv4FirstAddress, under the IPv4 name for it. IPv6 has no counterpart to the cidrv4BroadcastAddress half of this pair, which is why the cidrv6 side stays with first/last only.

Examples

Getting network address

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

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

The network address is not assignable, the next one is

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

const cidr = parseCidrv4("10.0.0.0/24");
assertEquals(stringifyAddressv4(cidrv4NetworkAddress(cidr)), "10.0.0.0");
assertEquals(stringifyAddressv4(cidrv4FirstUsableAddress(cidr)), "10.0.0.1");

Parameters

cidr: Cidrv4

The CIDR block

Return Type

number

The network address as a 32-bit unsigned integer

Usage

import { cidrv4NetworkAddress } from "cidrv4.ts";