File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -392,6 +392,16 @@ export function unregisterChannelzRef(ref: ChannelRef | SubchannelRef | ServerRe
392
392
}
393
393
}
394
394
395
+ /**
396
+ * Parses a single section of an IPv6 address as two bytes
397
+ * @param addressSection A hexadecimal string of length up to 4
398
+ * @returns The pair of bytes representing this address section
399
+ */
400
+ function parseIPv6Section ( addressSection : string ) : [ number , number ] {
401
+ const numberValue = Number . parseInt ( addressSection , 16 ) ;
402
+ return [ numberValue / 256 | 0 , numberValue % 256 ] ;
403
+ }
404
+
395
405
/**
396
406
* Converts an IPv4 or IPv6 address from string representation to binary
397
407
* representation
@@ -412,8 +422,8 @@ function ipAddressStringToBuffer(ipAddress: string): Buffer | null {
412
422
leftSection = ipAddress . substring ( 0 , doubleColonIndex ) ;
413
423
rightSection = ipAddress . substring ( doubleColonIndex + 2 ) ;
414
424
}
415
- const leftBuffer = Uint8Array . from ( leftSection . split ( ':' ) . map ( segment => Number . parseInt ( segment , 16 ) ) ) ;
416
- const rightBuffer = rightSection ? Uint8Array . from ( rightSection . split ( ':' ) . map ( segment => Number . parseInt ( segment , 16 ) ) ) : new Uint8Array ( ) ;
425
+ const leftBuffer = Buffer . from ( leftSection . split ( ':' ) . map ( segment => parseIPv6Section ( segment ) ) . flat ( ) ) ;
426
+ const rightBuffer = rightSection ? Buffer . from ( rightSection . split ( ':' ) . map ( segment => parseIPv6Section ( segment ) ) . flat ( ) ) : Buffer . alloc ( 0 ) ;
417
427
const middleBuffer = Buffer . alloc ( 16 - leftBuffer . length - rightBuffer . length , 0 ) ;
418
428
return Buffer . concat ( [ leftBuffer , middleBuffer , rightBuffer ] ) ;
419
429
} else {
You can’t perform that action at this time.
0 commit comments