Skip to content

Add conversions from IPv4 to IPv4-Mapped IPv6 addresses. #13

@jgonian

Description

@jgonian

As mentioned in #9, extending the library in order to support conversions of an IPv4 address to an IPv4-Mapped IPv6 address and vice-versa could be useful in the case where we want to use IPv6 for dealing with both IPv4 and IPv6. Conversion should be according to section 2.5.5 of RFC 4291.

As an example:

// IP addresses
Ipv4 ipv4Address = Ipv4.parse("192.168.0.0");
Ipv6 ipv6Address = Ipv6.of(ipv4Address)            // ::ffff:c0a8:0
Ipv6 ipv6Address = ipv4Address.asIpv4MappedIpv6(); // ::ffff:c0a8:0
boolean ... = ipv6Address.isIpv4MappedIpv6()       // true

// IP ranges
Ipv4Range ipv4Range = Ipv4Range.parse("192.168.0.0/32")
Ipv6Range ipv6Range = ipv4range.asIpv4MappedIpv6();  // ::ffff:c0a8:0/120
...

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions