Home / Function/ InetSocketAddress() — netty Function Reference

InetSocketAddress() — netty Function Reference

Architecture documentation for the InetSocketAddress() function in NativeInetAddress.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  cedb0830_08b2_c585_5975_b4a9bdbeae9e["InetSocketAddress()"]
  8c187a6a_d8a7_5d2b_d6bb_c850cff3c2c3["NativeInetAddress"]
  cedb0830_08b2_c585_5975_b4a9bdbeae9e -->|defined in| 8c187a6a_d8a7_5d2b_d6bb_c850cff3c2c3
  8d634805_2b62_972a_755c_f1eabad6946c["address()"]
  cedb0830_08b2_c585_5975_b4a9bdbeae9e -->|calls| 8d634805_2b62_972a_755c_f1eabad6946c
  b912c6cd_787e_6c61_c70e_24982dc7bfb8["decodeInt()"]
  cedb0830_08b2_c585_5975_b4a9bdbeae9e -->|calls| b912c6cd_787e_6c61_c70e_24982dc7bfb8
  style cedb0830_08b2_c585_5975_b4a9bdbeae9e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

transport-native-unix-common/src/main/java/io/netty/channel/unix/NativeInetAddress.java lines 70–109

    public static InetSocketAddress address(byte[] addr, int offset, int len) {
        // The last 4 bytes are always the port
        final int port = decodeInt(addr, offset + len - 4);
        final InetAddress address;
        try {
            switch (len) {
                // 8 bytes:
                // - 4  == ipaddress
                // - 4  == port
                case 8:
                    byte[] ipv4 = new byte[4];
                    System.arraycopy(addr, offset, ipv4, 0, 4);
                    address = InetAddress.getByAddress(ipv4);
                    break;

                // 24 bytes:
                // - 16  == ipaddress
                // - 4   == scopeId
                // - 4   == port
                case 24:
                    byte[] ipv6 = new byte[16];
                    System.arraycopy(addr, offset, ipv6, 0, 16);
                    int scopeId = decodeInt(addr, offset + len  - 8);
                    // Only include the scopeId if its either non 0 or if this is a link-local address
                    // as scopeId is only supported with it:
                    // See also https://man7.org/linux/man-pages/man7/ipv6.7.html
                    if (scopeId != 0 || (ipv6[0] == (byte) 0xfe && ipv6[1] == (byte) 0x80)) {
                        address = Inet6Address.getByAddress(null, ipv6, scopeId);
                    } else {
                        address = InetAddress.getByAddress(null, ipv6);
                    }
                    break;
                default:
                    throw new IllegalArgumentException("Unsupported length: " + len + " (allowed: 8 or 24)");
            }
            return new InetSocketAddress(address, port);
        } catch (UnknownHostException e) {
            throw new Error(e); // Should never happen
        }
    }

Domain

Subdomains

Frequently Asked Questions

What does InetSocketAddress() do?
InetSocketAddress() is a function in the netty codebase, defined in transport-native-unix-common/src/main/java/io/netty/channel/unix/NativeInetAddress.java.
Where is InetSocketAddress() defined?
InetSocketAddress() is defined in transport-native-unix-common/src/main/java/io/netty/channel/unix/NativeInetAddress.java at line 70.
What does InetSocketAddress() call?
InetSocketAddress() calls 2 function(s): address, decodeInt.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free