Hasty Briefsbeta

Fun with IP Address Parsing

a month ago
  • #IPv4
  • #IPv6
  • #networking
  • IPv4 and IPv6 have canonical forms: dotted quad for IPv4 (e.g., 192.168.0.1) and colon-hex for IPv6 (e.g., 1:2:3:4:5:6:7:8).
  • IPv6 allows eliding zeros with `::` (e.g., `1:2::3:4` expands to `1:2:0:0:0:0:3:4`).
  • IPv6 permits embedding IPv4 addresses in the last 32 bits (e.g., `1:2:3:4:5:6:77.77.88.88`).
  • IPv4 has historical quirks: it can be written as a single 32-bit integer (e.g., 3232271615 for 192.168.140.255).
  • IPv4 supports octal (e.g., 0300.0250.0214.0377) and hex (e.g., 0xc0.0xa8.0x8c.0xff) notations.
  • Class A/B notation allows coalescing trailing bytes (e.g., 192.168.36095 for 192.168.140.255).
  • Leading zeros in IPv4/IPv6 fields are often allowed but inconsistently handled (e.g., 000001::00001.00002.00003.00004).
  • Modern parsers often ignore outdated notations like Class A/B or hex/octal IPv4 formats.