Making applications IPv6-ready
Use protocol-independent socket APIs so code works over IPv4 and IPv6 (RFC 3493). Handle IPv6 literals in URLs with brackets and let users enter zone identifiers (RFC 3986, RFC 9844). Store, compare and log addresses in canonical form (RFC 5952).
Take the quiz · pass mark 70% · 9 questions
Explanation
Networks can be perfectly dual-stack and still fail because the application assumes IPv4. Making software IPv6-ready is mostly about removing IPv4 assumptions from code, URLs, storage and logs.
Protocol-independent sockets (RFC 3493)
The classic IPv4 socket code hard-codes AF_INET, struct sockaddr_in, gethostbyname() and 32-bit address fields. The IPv6 Basic Socket API (RFC 3493) gives address-family-independent calls: use getaddrinfo() to resolve a name to a list of candidate addresses (A and AAAA), loop over them opening sockets with the family each returns, and use getnameinfo() in reverse. Prefer AF_UNSPEC so the code never needs to know whether it got IPv4 or IPv6, and store addresses in struct sockaddr_storage, large enough for either family. This single change makes most code dual-stack.
IPv6 literals in URLs and zone IDs (RFC 3986, RFC 9844)
An IPv6 literal contains colons, which collide with the URL's host:port separator. RFC 3986 requires the literal to be wrapped in square brackets: http://[2001:db8::1]:8080/. Code that builds or parses URLs by splitting on the last colon breaks on IPv6 — use a real URL parser and emit brackets.
Link-local addresses need a zone identifier (the interface, e.g. fe80::1%eth0). Letting users type and see zone IDs in a UI is awkward; RFC 9844 gives current guidance on entering IPv6 zone identifiers in user interfaces so link-local input is handled consistently rather than each app inventing its own syntax.
Store, compare and log canonically (RFC 5952)
The same address has many text forms (2001:0DB8:0:0:0:0:0:1, 2001:db8::1, 2001:DB8::1). If you store or compare the text, you get duplicates and missed matches. Two rules:
- Store addresses as their binary value (16 bytes) or always normalise to RFC 5952 canonical form (lowercase, zero-compress the longest run, no leading zeros) before storing, comparing or logging. A database column should hold the normalised value, and
INET6/inet6types or a fixed-width binary column are better than free text. - Size fields for IPv6: an IPv6 address is 16 bytes (128 bits); a text column must hold up to 45-plus characters (including a zone ID or embedded IPv4). Old schemas with a 15-character "IP" column are an IPv4 assumption to fix.
ictNetworks scenario
ictNetworks' app team fixed its customer portal by switching to getaddrinfo()/AF_UNSPEC (RFC 3493), wrapping IPv6 literals in brackets in every generated URL (RFC 3986), accepting zone identifiers in the diagnostics UI per RFC 9844, and migrating the client_ip column to a binary/inet6 type that stores RFC 5952-canonical values so logs and abuse lookups match regardless of the text form the client presented.
Drawing diagram…
Worked examples
Example 1: The bracketed literal and its port
In the URL http://[2001:db8::1]:8080/, the brackets delimit the IPv6 literal so the colon before 8080 is correctly read as the port separator. The TCP port is 8080 (RFC 3986).
Example 2: Canonical form for storage
The address 2001:db8:0:0:1:0:0:1 has two equal-length zero runs. RFC 5952 compresses the first longest run, giving the canonical 2001:db8::1:0:0:1 — the single form to store, compare and log.
Example 3: Sizing the field
An IPv6 address is 16 bytes of binary. A schema storing addresses as a 15-character string (built for IPv4 dotted-quad) cannot hold an IPv6 literal and must be widened or, better, changed to a binary/inet6 type.
Lab
Goal: Fix a deliberately IPv4-only web app and its database schema so it works dual-stack and IPv6-only.
You need: the sample Python web app (hard-codes AF_INET, splits URLs on the colon, stores client_ip as a short string), a dual-stack and an IPv6-only test environment, and a NAT64 path for any IPv4-literal test.
- Replace the hard-coded IPv4 socket code with
getaddrinfo()/AF_UNSPECandsockaddr_storage; confirm the app connects over both families (RFC 3493). - Fix URL building/parsing to bracket IPv6 literals and read the port correctly (RFC 3986).
- Accept a zone identifier in the diagnostics input per RFC 9844.
- Migrate the
client_ipcolumn to a binary/inet6type (or normalise to RFC 5952 on write); show that two text forms of the same address now match. - Run the app in the IPv6-only environment and confirm it works (through NAT64/CLAT for any IPv4-only dependency).
What to submit: the code diffs, the schema migration, before/after evidence that both families and the IPv6-only environment work, and a canonical-form matching test.
Summary
- Use
getaddrinfo()/AF_UNSPECandsockaddr_storage(RFC 3493) so code is address-family-independent. - Bracket IPv6 literals in URLs (RFC 3986) and accept zone identifiers in UIs (RFC 9844).
- Store, compare and log addresses as binary or RFC 5952-canonical text, never as arbitrary strings; an IPv6 address is 16 bytes.
- Most "IPv6 doesn't work" app bugs are IPv4 assumptions in sockets, URL parsing or the schema.
- Next lesson (L6.08): testing and validating IPv6 readiness.
Quiz imported · 9 questions · pass mark 70%. Lab questions are not auto-marked.