Skip to content

fix(packet): IPv6 compression for leading-zero addresses#123

Merged
msimerson merged 1 commit into
lsongdev:masterfrom
NicTool:fix-ipv6-compression
May 26, 2026
Merged

fix(packet): IPv6 compression for leading-zero addresses#123
msimerson merged 1 commit into
lsongdev:masterfrom
NicTool:fix-ipv6-compression

Conversation

@msimerson
Copy link
Copy Markdown
Collaborator

const toIPv6 = buffer => buffer
  .map(part => (part > 0 ? part.toString(16) : '0'))
  .join(':')
  .replace(/\b(?:0+:){1,}/, ':');

The regex replaces the first run of 0: groups with a single :. For an address that starts with zeros, the resulting string begins with : instead of ::, producing an invalid text representation. Examples:

Real address toIPv6 output Correct
::1 :1 ::1
:: :0 ::
fe80::1 fe80::1 fe80::1

Parsed AAAA records for loopback, unspecified, and other leading-zero addresses will display incorrectly, and round-tripping them through fromIPv6toIPv6 will fail.

@msimerson msimerson marked this pull request as ready for review May 26, 2026 00:28
@msimerson msimerson changed the title fix(packet): IPv6 compression was wrong for leading-zero addresses fix(packet): IPv6 compression for leading-zero addresses May 26, 2026
@msimerson msimerson force-pushed the fix-ipv6-compression branch from acadaf0 to 833f228 Compare May 26, 2026 01:53
- fix(packet): Name decode rejects pointer cycles (RFC 1035)
- fix(packet): EDNS exposes extendedRcode/version/doFlag; udpPayloadSize configurable (RFC 6891)
- fix(packet): Header initializes ancount; AD/CD bits split from Z (RFC 4035)
- fix(packet): ECS encoder truncates address to ceil(prefix/8) octets, adds IPv6 family (RFC 7871)
@msimerson msimerson force-pushed the fix-ipv6-compression branch from 833f228 to 07a86e5 Compare May 26, 2026 01:54
@msimerson msimerson merged commit a29f39a into lsongdev:master May 26, 2026
5 checks passed
@msimerson msimerson deleted the fix-ipv6-compression branch May 26, 2026 01:55
@msimerson msimerson mentioned this pull request May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant