Home / Class/ NetUtilInitializations Class — netty Architecture

NetUtilInitializations Class — netty Architecture

Architecture documentation for the NetUtilInitializations class in NetUtilInitializations.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  079fd0dd_85b4_85e3_2cd2_da5d5fb2b78e["NetUtilInitializations"]
  b7777aef_a6d7_7caa_9c13_ddf7ecda9a3f["NetUtilInitializations.java"]
  079fd0dd_85b4_85e3_2cd2_da5d5fb2b78e -->|defined in| b7777aef_a6d7_7caa_9c13_ddf7ecda9a3f
  6eda98d3_251b_1030_cdd6_53d78d56538d["NetUtilInitializations()"]
  079fd0dd_85b4_85e3_2cd2_da5d5fb2b78e -->|method| 6eda98d3_251b_1030_cdd6_53d78d56538d
  a85db25a_8b8e_22ea_ec4a_339d1e373422["Inet4Address()"]
  079fd0dd_85b4_85e3_2cd2_da5d5fb2b78e -->|method| a85db25a_8b8e_22ea_ec4a_339d1e373422
  5073a988_15c0_e7bb_1892_e169f2ecdec6["Inet6Address()"]
  079fd0dd_85b4_85e3_2cd2_da5d5fb2b78e -->|method| 5073a988_15c0_e7bb_1892_e169f2ecdec6
  dc20874e_8c2a_2f94_66ae_08e7dbbc0007["networkInterfaces()"]
  079fd0dd_85b4_85e3_2cd2_da5d5fb2b78e -->|method| dc20874e_8c2a_2f94_66ae_08e7dbbc0007
  be9dca2c_7524_b878_d24c_6807f688d42e["NetworkIfaceAndInetAddress()"]
  079fd0dd_85b4_85e3_2cd2_da5d5fb2b78e -->|method| be9dca2c_7524_b878_d24c_6807f688d42e

Relationship Graph

Source Code

common/src/main/java/io/netty/util/NetUtilInitializations.java lines 34–188

final class NetUtilInitializations {
    /**
     * The logger being used by this class
     */
    private static final InternalLogger logger = InternalLoggerFactory.getInstance(NetUtilInitializations.class);

    private NetUtilInitializations() {
    }

    static Inet4Address createLocalhost4() {
        byte[] LOCALHOST4_BYTES = {127, 0, 0, 1};

        Inet4Address localhost4 = null;
        try {
            localhost4 = (Inet4Address) InetAddress.getByAddress("localhost", LOCALHOST4_BYTES);
        } catch (Exception e) {
            // We should not get here as long as the length of the address is correct.
            PlatformDependent.throwException(e);
        }

        return localhost4;
    }

    static Inet6Address createLocalhost6() {
        byte[] LOCALHOST6_BYTES = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};

        Inet6Address localhost6 = null;
        try {
            localhost6 = (Inet6Address) InetAddress.getByAddress("localhost", LOCALHOST6_BYTES);
        } catch (Exception e) {
            // We should not get here as long as the length of the address is correct.
            PlatformDependent.throwException(e);
        }

        return localhost6;
    }

    static Collection<NetworkInterface> networkInterfaces() {
        List<NetworkInterface> networkInterfaces = new ArrayList<NetworkInterface>();
        try {
            Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
            if (interfaces != null) {
                while (interfaces.hasMoreElements()) {
                    networkInterfaces.add(interfaces.nextElement());
                }
            }
        } catch (SocketException e) {
            logger.warn("Failed to retrieve the list of available network interfaces", e);
        } catch (NullPointerException e) {
            if (!PlatformDependent.isAndroid()) {
                throw e;
            }
            // Might happen on earlier version of Android.
            // See https://developer.android.com/reference/java/net/NetworkInterface#getNetworkInterfaces()
        }
        return Collections.unmodifiableList(networkInterfaces);
    }

    static NetworkIfaceAndInetAddress determineLoopback(
            Collection<NetworkInterface> networkInterfaces, Inet4Address localhost4, Inet6Address localhost6) {
        // Retrieve the list of available network interfaces.
        List<NetworkInterface> ifaces = new ArrayList<NetworkInterface>();
        for (NetworkInterface iface: networkInterfaces) {
            // Use the interface with proper INET addresses only.
            if (SocketUtils.addressesFromNetworkInterface(iface).hasMoreElements()) {
                ifaces.add(iface);
            }
        }

        // Find the first loopback interface available from its INET address (127.0.0.1 or ::1)
        // Note that we do not use NetworkInterface.isLoopback() in the first place because it takes long time
        // on a certain environment. (e.g. Windows with -Djava.net.preferIPv4Stack=true)
        NetworkInterface loopbackIface = null;
        InetAddress loopbackAddr = null;
        loop: for (NetworkInterface iface: ifaces) {
            for (Enumeration<InetAddress> i = SocketUtils.addressesFromNetworkInterface(iface); i.hasMoreElements();) {
                InetAddress addr = i.nextElement();
                if (addr.isLoopbackAddress()) {
                    // Found
                    loopbackIface = iface;
                    loopbackAddr = addr;

Frequently Asked Questions

What is the NetUtilInitializations class?
NetUtilInitializations is a class in the netty codebase, defined in common/src/main/java/io/netty/util/NetUtilInitializations.java.
Where is NetUtilInitializations defined?
NetUtilInitializations is defined in common/src/main/java/io/netty/util/NetUtilInitializations.java at line 34.

Analyze Your Own Codebase

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

Try Supermodel Free