net-address
    Preparing search index...

    Class Ipv4Addr

    Represents an IPv4 address.

    const addr1Res = Ipv4Addr.from('192.168.0.1');
    const addr1 = Ipv4Addr.fromOrThrow('192.168.0.1');
    const addr2 = new Ipv4Addr(192, 168, 0, 1);
    const addr3 = new Ipv4Addr(0xc0a80001);

    v0.0.1

    Index
    • Creates a new IPv4 address from four octets.

      Parameters

      • num1: number

        The first octet.

      • num2: number

        The second octet.

      • num3: number

        The third octet.

      • num4: number

        The fourth octet.

      Returns Ipv4Addr

      If the integer values are not in the range of 0 to 255 for each octet.

      If the input is not a number.

      new Ipv4Addr(192, 168, 0, 1) // creates the address `192.168.0.1`
      
    • Creates a new IPv4 address from an integer value.

      Parameters

      • integerValue: number

        The integer representation of the IPv4 address.

      Returns Ipv4Addr

      If the integer value is not in the range of 0 to 0xffffffff.

      If the input is not a number.

      new Ipv4Addr(0xc0a80001) // creates the address `192.168.0.1` from the integer value `0xc0a80001`
      
    family: "ipv4" = 'ipv4'

    The address family identifier for IPv4 addresses.

    v0.0.1

    BITS: 32

    The number of bits in an IPv4 address.

    BROADCAST: Ipv4Addr = ...

    The broadcast address 255.255.255.255.

    LOCALHOST: Ipv4Addr = ...

    The localhost address 127.0.0.1.

    UNSPECIFIED: Ipv4Addr = ...

    The unspecified address 0.0.0.0.

    • get value(): number

      Gets the raw integer representation of the IPv4 address.

      Returns number

    • Compares this IPv4 address with another for equality.

      Parameters

      • Optionalother: unknown

        instance of another address like to compare with.

      Returns boolean

      true if both addresses are equal, otherwise false.

      v0.1.0

    • Encodes this address to a 4-byte buffer.

      Parameters

      • OptionallittleEndian: boolean

      Returns ArrayBuffer

      An ArrayBuffer containing the IPv4 integer value.

      v0.0.1

      const buffer: ArrayBuffer = addr.toBuffer();
      
    • Formats this address as dotted-decimal text.

      Returns string

      The IPv4 string representation, such as 192.168.0.1.

      v0.0.1

    • Creates an IPv4 address from a 4-byte buffer and throws an error if the buffer cannot be read.

      Parameters

      • buffer: ArrayBuffer

        The 4-byte buffer containing the IPv4 address.

      • OptionallittleEndian: boolean

        Whether the buffer is in little-endian format. Defaults to false (big-endian).

      Returns Ipv4Addr

      The Ipv4Addr instance.

      If the buffer cannot be read.

      const addr: Ipv4Addr = Ipv4Addr.fromBufferOrThrow(buffer);
      

      v0.2.0

    • Creates an IPv4 address from text and throws an error if the input is invalid.

      Parameters

      • value: string

        The IPv4 address in string format.

      Returns Ipv4Addr

      The Ipv4Addr instance.

      If the input is not a valid IPv4 address.

      const addr: Ipv4Addr = Ipv4Addr.fromOrThrow('192.168.0.1');
      

      v0.2.0