Skip to content

isIPv4MappedIPv6

reference
1 min readUpdated

Kind: Function

Source: src/utils/ipaddr.ts

Part of: Utils

Check if a binary IPv6 address is an IPv4-mapped IPv6 address (::ffff

.x.x.x)

isIPv4MappedIPv6 checks whether a binary IPv6 address matches the IPv4-mapped IPv6 form: ::ffff:x.x.x.x. It helps address parsing and routing code identify IPv6 byte arrays that represent embedded IPv4 addresses.

Signature

ts
function isIPv4MappedIPv6(ipv6binary: bigint): boolean

Parameters

NameType
ipv6binarybigint

Returns: boolean

Diagram

mermaid
graph LR
  A[Binary IPv6 address] --> B[isIPv4MappedIPv6]
  B --> C{Matches ::ffff IPv4-mapped prefix?}
  C -->|Yes| D[true]
  C -->|No| E[false]

Usage

ts
import { isIPv4MappedIPv6 } from './utils/ipaddr.js'

function handleAddress(binaryAddress: Uint8Array): void {
  if (isIPv4MappedIPv6(binaryAddress)) {
    console.log('Address is an IPv4-mapped IPv6 address')
    return
  }

  console.log('Address is not IPv4-mapped')
}

AI Coding Instructions

  • Pass the binary IPv6 byte representation; do not pass a textual IP address directly.
  • Keep this check before extracting or handling the embedded IPv4 portion of an address.
  • Preserve the byte order produced by the IPv6 parser when passing addresses to this function.
  • Test both IPv4-mapped and non-mapped IPv6 byte arrays when changing address parsing code.

Used by

1 reference from 1 file. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (1)

  • IPRestrictionRulesrc/middleware/ip-restriction/index.ts:38

Was this page helpful?

Download as PDF
isIPv4MappedIPv6 — Hono (narrator proof)