addressv6FromBytes(bytes: Uint8Array,offset?: number): bigint
Reads a 16-byte IPv6 address from a buffer.
The sixteen bytes at offset are read in network order (big-endian) and
combined into the 128-bit bigint representation used throughout this
package. IPv4-mapped byte sequences (::ffff:x.x.x.x) are returned as the
full 128-bit value, not unwrapped to a number.
Read an address out of a packet
Read an address out of a packet
import { assertEquals } from "@std/assert"; import { addressv6FromBytes } from "@hertzg/ip/bytesv6"; import { stringifyAddressv6 } from "@hertzg/ip/addressv6"; // deno-fmt-ignore const bytes = new Uint8Array([ 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, ]); assertEquals(stringifyAddressv6(addressv6FromBytes(bytes)), "2001:db8::1");
IPv4-mapped bytes stay a 128-bit value
IPv4-mapped bytes stay a 128-bit value
import { assertEquals } from "@std/assert"; import { addressv6FromBytes } from "@hertzg/ip/bytesv6"; import { stringifyAddressv6 } from "@hertzg/ip/addressv6"; // deno-fmt-ignore const bytes = new Uint8Array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 192, 168, 1, 1, ]); assertEquals(stringifyAddressv6(addressv6FromBytes(bytes)), "::ffff:c0a8:101");
bytes: Uint8Array
The buffer to read from