@@ -46,12 +46,26 @@ function parseAddress (address) {
4646 */
4747function parseIPv6 ( address ) {
4848 const buffer = Buffer . alloc ( 16 )
49+ let normalizedAddress = address
50+
51+ // Expand an embedded IPv4 tail into the last two IPv6 groups.
52+ if ( address . includes ( '.' ) ) {
53+ const lastColonIndex = address . lastIndexOf ( ':' )
54+ const ipv4Part = address . slice ( lastColonIndex + 1 )
55+
56+ if ( net . isIPv4 ( ipv4Part ) ) {
57+ const octets = ipv4Part . split ( '.' ) . map ( Number )
58+ const high = ( ( octets [ 0 ] << 8 ) | octets [ 1 ] ) . toString ( 16 )
59+ const low = ( ( octets [ 2 ] << 8 ) | octets [ 3 ] ) . toString ( 16 )
60+ normalizedAddress = `${ address . slice ( 0 , lastColonIndex ) } :${ high } :${ low } `
61+ }
62+ }
4963
5064 // Handle compressed notation (::)
51- const doubleColonIndex = address . indexOf ( '::' )
65+ const doubleColonIndex = normalizedAddress . indexOf ( '::' )
5266 if ( doubleColonIndex !== - 1 ) {
53- const before = address . slice ( 0 , doubleColonIndex )
54- const after = address . slice ( doubleColonIndex + 2 )
67+ const before = normalizedAddress . slice ( 0 , doubleColonIndex )
68+ const after = normalizedAddress . slice ( doubleColonIndex + 2 )
5569 const beforeParts = before === '' ? [ ] : before . split ( ':' )
5670 const afterParts = after === '' ? [ ] : after . split ( ':' )
5771
@@ -66,7 +80,7 @@ function parseIPv6 (address) {
6680 bufferIndex += 2
6781 }
6882 } else {
69- const parts = address . split ( ':' )
83+ const parts = normalizedAddress . split ( ':' )
7084 for ( let i = 0 ; i < parts . length ; i ++ ) {
7185 buffer . writeUInt16BE ( parseInt ( parts [ i ] , 16 ) , i * 2 )
7286 }
0 commit comments