Closed
Description
Specification
There are multiple ways to represent IP addresses. IPv4
specifically has 3 ways, IPv6
mapped form ::ffff:127.0.0.1
, normal form, 127.0.0.1
and the hex form ::ffff:7f00:1
. Theses 3 forms represent the same IPv4
address.
If we need to store this address in the database we can't use all 3 representations although they are equivalent. We need a canonical form for storing and manipulating the address.
To this end we need to create a helper class that stores the address as the canonical form, we can use the raw byte form representing an A
address for IPv4
and an AAAA
address for IPv6
. Theses are 4 and 16 bytes respectively.
From the canonical byte form we can map the address to all supported formats.
Additional context
Tasks
- Create a canonical format for IP addresses for comparing and storing in a database.
- Create mapping functions for converting between formats using the canonical form as the in-between.