rfc6052 1.0.0

Rust functions for interacting with RFC6052 IPv4-Embedded IPv6 Addresses
Documentation
  • Coverage
  • 75%
    6 out of 8 items documented4 out of 4 items with examples
  • Size
  • Source code size: 16.37 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.72 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • ewpratten/protomask
    1 0 3
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ewpratten

RFC6052 for Rust

Crates.io Docs.rs

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 length
  • u is a reserved byte that must be set to 0

Safe vs. Unsafe

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.