Crates.io | rfc6052 |
lib.rs | rfc6052 |
version | 1.0.0 |
source | src |
created_at | 2024-02-12 14:56:10.868776 |
updated_at | 2024-02-12 14:56:10.868776 |
description | Rust functions for interacting with RFC6052 IPv4-Embedded IPv6 Addresses |
homepage | https://github.com/ewpratten/protomask/tree/master/libs/rfc6052 |
repository | https://github.com/ewpratten/protomask |
max_upload_size | |
id | 1137019 |
size | 15,101 |
RFC6052 defines "the algorithmic translation of an IPv6 address to a corresponding IPv4 address, and vice versa, using only statically configured information". In simpler terms, this means embedding IPv4 address into IPv6 addresses. The primary use case of which being NAT64 translators.
The RFC defines the following scheme for embedding IPv4 addresses into IPv6 addresses:
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|PL| 0-------------32--40--48--56--64--72--80--88--96--104---------|
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|32| prefix |v4(32) | u | suffix |
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|40| prefix |v4(24) | u |(8)| suffix |
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|48| prefix |v4(16) | u | (16) | suffix |
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|56| prefix |(8)| u | v4(24) | suffix |
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|64| prefix | u | v4(32) | suffix |
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
|96| prefix | v4(32) |
+--+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
PL
is the prefix lengthu
is a reserved byte that must be set to 0
This library provides both a "regular" and "unchecked" version of the functions for embedding and extracting IPv4 addresses from IPv6 addresses.
The "regular" functions enforce the restricted set of IPv6 prefix lengths allowed by the RFC (32, 40, 48, 56, 64, and 96 bits long). The "unchecked" functions do not enforce this restriction, and will happily accept any prefix length at the cost of non-compliance with the RFC.