Search in sources :

Example 1 with Inet6Address

use of java.net.Inet6Address in project elasticsearch by elastic.

the class IfConfig method doLogging.

/** perform actual logging: might throw exception if things go wrong */
private static void doLogging() throws IOException {
    StringBuilder msg = new StringBuilder();
    for (NetworkInterface nic : NetworkUtils.getInterfaces()) {
        msg.append(System.lineSeparator());
        // ordinary name
        msg.append(nic.getName());
        msg.append(System.lineSeparator());
        // display name (e.g. on windows)
        if (!nic.getName().equals(nic.getDisplayName())) {
            msg.append(INDENT);
            msg.append(nic.getDisplayName());
            msg.append(System.lineSeparator());
        }
        // addresses: v4 first, then v6
        List<InterfaceAddress> addresses = nic.getInterfaceAddresses();
        for (InterfaceAddress address : addresses) {
            if (address.getAddress() instanceof Inet6Address == false) {
                msg.append(INDENT);
                msg.append(formatAddress(address));
                msg.append(System.lineSeparator());
            }
        }
        for (InterfaceAddress address : addresses) {
            if (address.getAddress() instanceof Inet6Address) {
                msg.append(INDENT);
                msg.append(formatAddress(address));
                msg.append(System.lineSeparator());
            }
        }
        // hardware address
        byte[] hardware = nic.getHardwareAddress();
        if (hardware != null) {
            msg.append(INDENT);
            msg.append("hardware ");
            for (int i = 0; i < hardware.length; i++) {
                if (i > 0) {
                    msg.append(":");
                }
                msg.append(String.format(Locale.ROOT, "%02X", hardware[i]));
            }
            msg.append(System.lineSeparator());
        }
        // attributes
        msg.append(INDENT);
        msg.append(formatFlags(nic));
        msg.append(System.lineSeparator());
    }
    logger.debug("configuration:{}{}", System.lineSeparator(), msg);
}
Also used : InterfaceAddress(java.net.InterfaceAddress) NetworkInterface(java.net.NetworkInterface) Inet6Address(java.net.Inet6Address)

Example 2 with Inet6Address

use of java.net.Inet6Address in project android_frameworks_base by ResurrectionRemix.

the class CommonTimeUtils method transactSetSockaddr.

public int transactSetSockaddr(int method_code, InetSocketAddress addr) {
    android.os.Parcel data = android.os.Parcel.obtain();
    android.os.Parcel reply = android.os.Parcel.obtain();
    int ret_val = ERROR;
    try {
        data.writeInterfaceToken(mInterfaceDesc);
        if (null == addr) {
            data.writeInt(0);
        } else {
            data.writeInt(1);
            final InetAddress a = addr.getAddress();
            final byte[] b = a.getAddress();
            final int p = addr.getPort();
            if (a instanceof Inet4Address) {
                int v4addr = (((int) b[0] & 0xFF) << 24) | (((int) b[1] & 0xFF) << 16) | (((int) b[2] & 0xFF) << 8) | ((int) b[3] & 0xFF);
                data.writeInt(AF_INET);
                data.writeInt(v4addr);
                data.writeInt(p);
            } else if (a instanceof Inet6Address) {
                int i;
                Inet6Address v6 = (Inet6Address) a;
                data.writeInt(AF_INET6);
                for (i = 0; i < 4; ++i) {
                    int aword = (((int) b[(i * 4) + 0] & 0xFF) << 24) | (((int) b[(i * 4) + 1] & 0xFF) << 16) | (((int) b[(i * 4) + 2] & 0xFF) << 8) | ((int) b[(i * 4) + 3] & 0xFF);
                    data.writeInt(aword);
                }
                data.writeInt(p);
                // flow info
                data.writeInt(0);
                data.writeInt(v6.getScopeId());
            } else {
                return ERROR_BAD_VALUE;
            }
        }
        mRemote.transact(method_code, data, reply, 0);
        ret_val = reply.readInt();
    } catch (RemoteException e) {
        ret_val = ERROR_DEAD_OBJECT;
    } finally {
        reply.recycle();
        data.recycle();
    }
    return ret_val;
}
Also used : Inet4Address(java.net.Inet4Address) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Example 3 with Inet6Address

use of java.net.Inet6Address in project voltdb by VoltDB.

the class RealVoltDB method collectLocalNetworkMetadata.

void collectLocalNetworkMetadata() {
    boolean threw = false;
    JSONStringer stringer = new JSONStringer();
    try {
        stringer.object();
        stringer.key("interfaces").array();
        if (m_config.m_externalInterface.equals("")) {
            LinkedList<NetworkInterface> interfaces = new LinkedList<>();
            try {
                Enumeration<NetworkInterface> intfEnum = NetworkInterface.getNetworkInterfaces();
                while (intfEnum.hasMoreElements()) {
                    NetworkInterface intf = intfEnum.nextElement();
                    if (intf.isLoopback() || !intf.isUp()) {
                        continue;
                    }
                    interfaces.offer(intf);
                }
            } catch (SocketException e) {
                throw new RuntimeException(e);
            }
            if (interfaces.isEmpty()) {
                stringer.value("localhost");
            } else {
                boolean addedIp = false;
                while (!interfaces.isEmpty()) {
                    NetworkInterface intf = interfaces.poll();
                    Enumeration<InetAddress> inetAddrs = intf.getInetAddresses();
                    Inet6Address inet6addr = null;
                    Inet4Address inet4addr = null;
                    while (inetAddrs.hasMoreElements()) {
                        InetAddress addr = inetAddrs.nextElement();
                        if (addr instanceof Inet6Address) {
                            inet6addr = (Inet6Address) addr;
                            if (inet6addr.isLinkLocalAddress()) {
                                inet6addr = null;
                            }
                        } else if (addr instanceof Inet4Address) {
                            inet4addr = (Inet4Address) addr;
                        }
                    }
                    if (inet4addr != null) {
                        stringer.value(inet4addr.getHostAddress());
                        addedIp = true;
                    }
                    if (inet6addr != null) {
                        stringer.value(inet6addr.getHostAddress());
                        addedIp = true;
                    }
                }
                if (!addedIp) {
                    stringer.value("localhost");
                }
            }
        } else {
            stringer.value(m_config.m_externalInterface);
        }
    } catch (Exception e) {
        threw = true;
        hostLog.warn("Error while collecting data about local network interfaces", e);
    }
    try {
        if (threw) {
            stringer = new JSONStringer();
            stringer.object();
            stringer.key("interfaces").array();
            stringer.value("localhost");
            stringer.endArray();
        } else {
            stringer.endArray();
        }
        stringer.keySymbolValuePair("clientPort", m_config.m_port);
        stringer.keySymbolValuePair("clientInterface", m_config.m_clientInterface);
        stringer.keySymbolValuePair("adminPort", m_config.m_adminPort);
        stringer.keySymbolValuePair("adminInterface", m_config.m_adminInterface);
        stringer.keySymbolValuePair("httpPort", m_config.m_httpPort);
        stringer.keySymbolValuePair("httpInterface", m_config.m_httpPortInterface);
        stringer.keySymbolValuePair("internalPort", m_config.m_internalPort);
        stringer.keySymbolValuePair("internalInterface", m_config.m_internalInterface);
        String[] zkInterface = m_config.m_zkInterface.split(":");
        stringer.keySymbolValuePair("zkPort", zkInterface[1]);
        stringer.keySymbolValuePair("zkInterface", zkInterface[0]);
        stringer.keySymbolValuePair("drPort", VoltDB.getReplicationPort(m_catalogContext.cluster.getDrproducerport()));
        stringer.keySymbolValuePair("drInterface", VoltDB.getDefaultReplicationInterface());
        stringer.keySymbolValuePair("publicInterface", m_config.m_publicInterface);
        stringer.endObject();
        JSONObject obj = new JSONObject(stringer.toString());
        // possibly atomic swap from null to realz
        m_localMetadata = obj.toString(4);
        hostLog.debug("System Metadata is: " + m_localMetadata);
    } catch (Exception e) {
        hostLog.warn("Failed to collect data about lcoal network interfaces", e);
    }
}
Also used : SocketException(java.net.SocketException) Inet4Address(java.net.Inet4Address) NetworkInterface(java.net.NetworkInterface) Inet6Address(java.net.Inet6Address) LinkedList(java.util.LinkedList) SocketException(java.net.SocketException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.json_voltpatches.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KeeperException(org.apache.zookeeper_voltpatches.KeeperException) SettingsException(org.voltdb.settings.SettingsException) JSONObject(org.json_voltpatches.JSONObject) JSONStringer(org.json_voltpatches.JSONStringer) InetAddress(java.net.InetAddress)

Example 4 with Inet6Address

use of java.net.Inet6Address in project android_frameworks_base by ResurrectionRemix.

the class RtNetlinkNeighborMessage method newNewNeighborMessage.

/**
     * A convenience method to create an RTM_NEWNEIGH message, to modify
     * the kernel's state information for a specific neighbor.
     */
public static byte[] newNewNeighborMessage(int seqNo, InetAddress ip, short nudState, int ifIndex, byte[] llAddr) {
    final StructNlMsgHdr nlmsghdr = new StructNlMsgHdr();
    nlmsghdr.nlmsg_type = NetlinkConstants.RTM_NEWNEIGH;
    nlmsghdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_REPLACE;
    nlmsghdr.nlmsg_seq = seqNo;
    final RtNetlinkNeighborMessage msg = new RtNetlinkNeighborMessage(nlmsghdr);
    msg.mNdmsg = new StructNdMsg();
    msg.mNdmsg.ndm_family = (byte) ((ip instanceof Inet6Address) ? OsConstants.AF_INET6 : OsConstants.AF_INET);
    msg.mNdmsg.ndm_ifindex = ifIndex;
    msg.mNdmsg.ndm_state = nudState;
    msg.mDestination = ip;
    // might be null
    msg.mLinkLayerAddr = llAddr;
    final byte[] bytes = new byte[msg.getRequiredSpace()];
    nlmsghdr.nlmsg_len = bytes.length;
    final ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
    byteBuffer.order(ByteOrder.nativeOrder());
    msg.pack(byteBuffer);
    return bytes;
}
Also used : StructNlMsgHdr(android.net.netlink.StructNlMsgHdr) StructNdMsg(android.net.netlink.StructNdMsg) Inet6Address(java.net.Inet6Address) ByteBuffer(java.nio.ByteBuffer)

Example 5 with Inet6Address

use of java.net.Inet6Address in project android_frameworks_base by ResurrectionRemix.

the class IPv6TetheringCoordinator method getIPv6OnlyLinkProperties.

private static LinkProperties getIPv6OnlyLinkProperties(LinkProperties lp) {
    final LinkProperties v6only = new LinkProperties();
    if (lp == null) {
        return v6only;
    }
    // NOTE: At this time we don't copy over any information about any
    // stacked links. No current stacked link configuration has IPv6.
    v6only.setInterfaceName(lp.getInterfaceName());
    v6only.setMtu(lp.getMtu());
    for (LinkAddress linkAddr : lp.getLinkAddresses()) {
        if (linkAddr.isGlobalPreferred() && linkAddr.getPrefixLength() == 64) {
            v6only.addLinkAddress(linkAddr);
        }
    }
    for (RouteInfo routeInfo : lp.getRoutes()) {
        final IpPrefix destination = routeInfo.getDestination();
        if ((destination.getAddress() instanceof Inet6Address) && (destination.getPrefixLength() <= 64)) {
            v6only.addRoute(routeInfo);
        }
    }
    for (InetAddress dnsServer : lp.getDnsServers()) {
        if (isIPv6GlobalAddress(dnsServer)) {
            // For now we include ULAs.
            v6only.addDnsServer(dnsServer);
        }
    }
    v6only.setDomains(lp.getDomains());
    return v6only;
}
Also used : LinkAddress(android.net.LinkAddress) IpPrefix(android.net.IpPrefix) Inet6Address(java.net.Inet6Address) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Aggregations

Inet6Address (java.net.Inet6Address)286 InetAddress (java.net.InetAddress)196 Inet4Address (java.net.Inet4Address)110 NetworkInterface (java.net.NetworkInterface)54 UnknownHostException (java.net.UnknownHostException)51 SocketException (java.net.SocketException)32 InetSocketAddress (java.net.InetSocketAddress)31 IOException (java.io.IOException)29 LinkAddress (android.net.LinkAddress)28 Test (org.junit.Test)26 RouteInfo (android.net.RouteInfo)21 IpPrefix (android.net.IpPrefix)19 ArrayList (java.util.ArrayList)19 LinkProperties (android.net.LinkProperties)15 ByteBuffer (java.nio.ByteBuffer)9 InterfaceAddress (java.net.InterfaceAddress)7 StringJoiner (java.util.StringJoiner)7 PrintWriter (java.io.PrintWriter)6 HashMap (java.util.HashMap)6 Test (org.junit.jupiter.api.Test)6