Home / Function/ NetworkIfaceAndInetAddress() — netty Function Reference

NetworkIfaceAndInetAddress() — netty Function Reference

Architecture documentation for the NetworkIfaceAndInetAddress() function in NetUtilInitializations.java from the netty codebase.

Function java CommonUtil Concurrent calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  be9dca2c_7524_b878_d24c_6807f688d42e["NetworkIfaceAndInetAddress()"]
  079fd0dd_85b4_85e3_2cd2_da5d5fb2b78e["NetUtilInitializations"]
  be9dca2c_7524_b878_d24c_6807f688d42e -->|defined in| 079fd0dd_85b4_85e3_2cd2_da5d5fb2b78e
  ca37d113_99bd_db60_c807_53fb1935d12c["NetworkIfaceAndInetAddress()"]
  ca37d113_99bd_db60_c807_53fb1935d12c -->|calls| be9dca2c_7524_b878_d24c_6807f688d42e
  ca37d113_99bd_db60_c807_53fb1935d12c["NetworkIfaceAndInetAddress()"]
  be9dca2c_7524_b878_d24c_6807f688d42e -->|calls| ca37d113_99bd_db60_c807_53fb1935d12c
  style be9dca2c_7524_b878_d24c_6807f688d42e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

common/src/main/java/io/netty/util/NetUtilInitializations.java lines 92–169

    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;
                    break loop;
                }
            }
        }

        // If failed to find the loopback interface from its INET address, fall back to isLoopback().
        if (loopbackIface == null) {
            try {
                for (NetworkInterface iface: ifaces) {
                    if (iface.isLoopback()) {
                        Enumeration<InetAddress> i = SocketUtils.addressesFromNetworkInterface(iface);
                        if (i.hasMoreElements()) {
                            // Found the one with INET address.
                            loopbackIface = iface;
                            loopbackAddr = i.nextElement();
                            break;
                        }
                    }
                }

                if (loopbackIface == null) {
                    logger.warn("Failed to find the loopback interface");
                }
            } catch (SocketException e) {
                logger.warn("Failed to find the loopback interface", e);
            }
        }

        if (loopbackIface != null) {
            // Found the loopback interface with an INET address.
            logger.debug(
                    "Loopback interface: {} ({}, {})",
                    loopbackIface.getName(), loopbackIface.getDisplayName(), loopbackAddr.getHostAddress());
        } else {
            // Could not find the loopback interface, but we can't leave LOCALHOST as null.
            // Use LOCALHOST6 or LOCALHOST4, preferably the IPv6 one.
            if (loopbackAddr == null) {
                try {
                    if (NetworkInterface.getByInetAddress(localhost6) != null) {
                        logger.debug("Using hard-coded IPv6 localhost address: {}", localhost6);
                        loopbackAddr = localhost6;
                    }
                } catch (Exception e) {
                    // Ignore
                } finally {
                    if (loopbackAddr == null) {
                        logger.debug("Using hard-coded IPv4 localhost address: {}", localhost4);
                        loopbackAddr = localhost4;
                    }
                }
            }
        }

        return new NetworkIfaceAndInetAddress(loopbackIface, loopbackAddr);
    }

Domain

Subdomains

Frequently Asked Questions

What does NetworkIfaceAndInetAddress() do?
NetworkIfaceAndInetAddress() is a function in the netty codebase, defined in common/src/main/java/io/netty/util/NetUtilInitializations.java.
Where is NetworkIfaceAndInetAddress() defined?
NetworkIfaceAndInetAddress() is defined in common/src/main/java/io/netty/util/NetUtilInitializations.java at line 92.
What does NetworkIfaceAndInetAddress() call?
NetworkIfaceAndInetAddress() calls 1 function(s): NetworkIfaceAndInetAddress.
What calls NetworkIfaceAndInetAddress()?
NetworkIfaceAndInetAddress() is called by 1 function(s): NetworkIfaceAndInetAddress.

Analyze Your Own Codebase

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

Try Supermodel Free