getIPv6ByName() — netty Function Reference
Architecture documentation for the getIPv6ByName() function in NetUtil.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD b30e6fa5_6204_a80f_b331_d6314fb87ddb["getIPv6ByName()"] 40fb3f7d_c2dd_316b_f965_bdef8e0dad94["NetUtil"] b30e6fa5_6204_a80f_b331_d6314fb87ddb -->|defined in| 40fb3f7d_c2dd_316b_f965_bdef8e0dad94 9dd33ef5_da27_82d2_b43a_42b0859ae8c2["createByteArrayFromIpAddressString()"] 9dd33ef5_da27_82d2_b43a_42b0859ae8c2 -->|calls| b30e6fa5_6204_a80f_b331_d6314fb87ddb cc85d9b2_7b73_14a5_b35e_ad071f8fc178["InetAddress()"] cc85d9b2_7b73_14a5_b35e_ad071f8fc178 -->|calls| b30e6fa5_6204_a80f_b331_d6314fb87ddb 1be4a845_b922_a33b_8034_774b740d2784["Inet6Address()"] 1be4a845_b922_a33b_8034_774b740d2784 -->|calls| b30e6fa5_6204_a80f_b331_d6314fb87ddb ee51fe53_d370_5533_daaf_2852a2295f8c["isValidIPv4Mapped()"] b30e6fa5_6204_a80f_b331_d6314fb87ddb -->|calls| ee51fe53_d370_5533_daaf_2852a2295f8c 3aae2752_d601_a5dd_3b06_fd014179e854["isValidNumericChar()"] b30e6fa5_6204_a80f_b331_d6314fb87ddb -->|calls| 3aae2752_d601_a5dd_3b06_fd014179e854 e2630fbb_38fc_e090_ae00_8810e0f7283b["isValidHexChar()"] b30e6fa5_6204_a80f_b331_d6314fb87ddb -->|calls| e2630fbb_38fc_e090_ae00_8810e0f7283b style b30e6fa5_6204_a80f_b331_d6314fb87ddb fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
common/src/main/java/io/netty/util/NetUtil.java lines 726–890
static byte[] getIPv6ByName(CharSequence ip, boolean ipv4Mapped) {
final byte[] bytes = new byte[IPV6_BYTE_COUNT];
final int ipLength = ip.length();
int compressBegin = 0;
int compressLength = 0;
int currentIndex = 0;
int value = 0;
int begin = -1;
int i = 0;
int ipv6Separators = 0;
int ipv4Separators = 0;
int tmp;
for (; i < ipLength; ++i) {
final char c = ip.charAt(i);
switch (c) {
case ':':
++ipv6Separators;
if (i - begin > IPV6_MAX_CHAR_BETWEEN_SEPARATOR ||
ipv4Separators > 0 || ipv6Separators > IPV6_MAX_SEPARATORS ||
currentIndex + 1 >= bytes.length) {
return null;
}
value <<= (IPV6_MAX_CHAR_BETWEEN_SEPARATOR - (i - begin)) << 2;
if (compressLength > 0) {
compressLength -= 2;
}
// The value integer holds at most 4 bytes from right (most significant) to left (least significant).
// The following bit shifting is used to extract and re-order the individual bytes to achieve a
// left (most significant) to right (least significant) ordering.
bytes[currentIndex++] = (byte) (((value & 0xf) << 4) | ((value >> 4) & 0xf));
bytes[currentIndex++] = (byte) ((((value >> 8) & 0xf) << 4) | ((value >> 12) & 0xf));
tmp = i + 1;
if (tmp < ipLength && ip.charAt(tmp) == ':') {
++tmp;
if (compressBegin != 0 || (tmp < ipLength && ip.charAt(tmp) == ':')) {
return null;
}
++ipv6Separators;
compressBegin = currentIndex;
compressLength = bytes.length - compressBegin - 2;
++i;
}
value = 0;
begin = -1;
break;
case '.':
++ipv4Separators;
tmp = i - begin; // tmp is the length of the current segment.
if (tmp > IPV4_MAX_CHAR_BETWEEN_SEPARATOR
|| begin < 0
|| ipv4Separators > IPV4_SEPARATORS
|| (ipv6Separators > 0 && (currentIndex + compressLength < 12))
|| i + 1 >= ipLength
|| currentIndex >= bytes.length
|| ipv4Separators == 1 &&
// We also parse pure IPv4 addresses as IPv4-Mapped for ease of use.
((!ipv4Mapped || currentIndex != 0 && !isValidIPv4Mapped(bytes, currentIndex,
compressBegin, compressLength)) ||
(tmp == 3 && (!isValidNumericChar(ip.charAt(i - 1)) ||
!isValidNumericChar(ip.charAt(i - 2)) ||
!isValidNumericChar(ip.charAt(i - 3))) ||
tmp == 2 && (!isValidNumericChar(ip.charAt(i - 1)) ||
!isValidNumericChar(ip.charAt(i - 2))) ||
tmp == 1 && !isValidNumericChar(ip.charAt(i - 1))))) {
return null;
}
value <<= (IPV4_MAX_CHAR_BETWEEN_SEPARATOR - tmp) << 2;
// The value integer holds at most 3 bytes from right (most significant) to left (least significant).
// The following bit shifting is to restructure the bytes to be left (most significant) to
// right (least significant) while also accounting for each IPv4 digit is base 10.
begin = (value & 0xf) * 100 + ((value >> 4) & 0xf) * 10 + ((value >> 8) & 0xf);
if (begin > 255) {
return null;
}
bytes[currentIndex++] = (byte) begin;
value = 0;
begin = -1;
break;
Domain
Subdomains
Source
Frequently Asked Questions
What does getIPv6ByName() do?
getIPv6ByName() is a function in the netty codebase, defined in common/src/main/java/io/netty/util/NetUtil.java.
Where is getIPv6ByName() defined?
getIPv6ByName() is defined in common/src/main/java/io/netty/util/NetUtil.java at line 726.
What does getIPv6ByName() call?
getIPv6ByName() calls 3 function(s): isValidHexChar, isValidIPv4Mapped, isValidNumericChar.
What calls getIPv6ByName()?
getIPv6ByName() is called by 3 function(s): Inet6Address, InetAddress, createByteArrayFromIpAddressString.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free