jojochuang commented on code in PR #8851:
URL: https://github.com/apache/hadoop/pull/8851#discussion_r4364575054
##########
hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/datatransfer/sasl/DataTransferSaslUtil.java:
##########
@@ -160,15 +160,22 @@ public static char[] encryptionKeyToPassword(byte[]
encryptionKey) {
* Returns InetAddress from peer. The getRemoteAddressString has the form
* [host][/ip-address]:port. The host may be missing. The IP address (and
* preceding '/') may be missing. The port preceded by ':' is always
present.
+ * An IPv6 address may be enclosed in brackets.
*
* @return InetAddress from peer
*/
public static InetAddress getPeerAddress(Peer peer) {
- String remoteAddr = peer.getRemoteAddressString().split(":")[0];
- int slashIdx = remoteAddr.indexOf('/');
- return InetAddresses.forString(slashIdx != -1 ?
- remoteAddr.substring(slashIdx + 1, remoteAddr.length()) :
- remoteAddr);
+ String remoteAddr = peer.getRemoteAddressString();
+ // The port follows the last ':', IPv6 addresses contain ':' themselves.
+ int colonIdx = remoteAddr.lastIndexOf(':');
+ if (colonIdx != -1) {
+ remoteAddr = remoteAddr.substring(0, colonIdx);
+ }
+ remoteAddr = remoteAddr.substring(remoteAddr.indexOf('/') + 1);
+ if (remoteAddr.startsWith("[") && remoteAddr.endsWith("]")) {
Review Comment:
deal with IPv6 string for JDK14+ case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]