Skip to content

convertIPv4MappedIPv6ToIPv4

reference
1 min readUpdated

Kind: Function

Source: src/utils/ipaddr.ts

Part of: Utils

Extract the IPv4 portion from an IPv4-mapped IPv6 address

convertIPv4MappedIPv6ToIPv4 extracts the IPv4 address portion from an IPv4-mapped IPv6 address. It is intended for address-handling paths where network inputs may represent IPv4 clients in IPv6 notation.

Signature

ts
function convertIPv4MappedIPv6ToIPv4(ipv6binary: bigint): bigint

Parameters

NameType
ipv6binarybigint

Returns: bigint

Diagram

mermaid
graph LR
  A[Network address input] --> B[convertIPv4MappedIPv6ToIPv4]
  B --> C[IPv4 address portion]

Usage

ts
import { convertIPv4MappedIPv6ToIPv4 } from './utils/ipaddr';

const remoteAddress = request.socket.remoteAddress;

if (remoteAddress) {
  const clientAddress = convertIPv4MappedIPv6ToIPv4(remoteAddress);

  console.log(clientAddress);
}

AI Coding Instructions

  • Call this function when processing network addresses from sockets, proxies, or request metadata.
  • Pass the raw address string into the function before comparing it with IPv4 allowlists or blocklists.
  • Do not treat this function as a general IPv6 parser or formatter.
  • Add tests for IPv4-mapped IPv6 inputs and address inputs that are not IPv4-mapped.

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
convertIPv4MappedIPv6ToIPv4 — Hono (narrator proof)