Search in sources :

Example 51 with Inet6Address

use of java.net.Inet6Address in project EngineDriver by JMRI.

the class ServiceInfoImpl method getURLs.

/*
     * (non-Javadoc)
     * @see javax.jmdns.ServiceInfo#getURLs(java.lang.String)
     */
@Override
public String[] getURLs(String protocol) {
    InetAddress[] addresses = this.getInetAddresses();
    List<String> urls = new ArrayList<String>(addresses.length);
    for (InetAddress address : addresses) {
        String hostAddress = address.getHostAddress();
        if (address instanceof Inet6Address) {
            hostAddress = "[" + hostAddress + "]";
        }
        String url = protocol + "://" + hostAddress + ":" + getPort();
        String path = getPropertyString("path");
        if (path != null) {
            if (path.indexOf("://") >= 0) {
                url = path;
            } else {
                url += path.startsWith("/") ? path : "/" + path;
            }
        }
        urls.add(url);
    }
    return urls.toArray(new String[urls.size()]);
}
Also used : ArrayList(java.util.ArrayList) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Example 52 with Inet6Address

use of java.net.Inet6Address in project EngineDriver by JMRI.

the class ServiceInfoImpl method clone.

/*
     * (non-Javadoc)
     * @see javax.jmdns.ServiceInfo#clone()
     */
@Override
public ServiceInfoImpl clone() {
    ServiceInfoImpl serviceInfo = new ServiceInfoImpl(this.getQualifiedNameMap(), _port, _weight, _priority, _persistent, _text);
    Inet6Address[] ipv6Addresses = this.getInet6Addresses();
    for (Inet6Address address : ipv6Addresses) {
        serviceInfo._ipv6Addresses.add(address);
    }
    Inet4Address[] ipv4Addresses = this.getInet4Addresses();
    for (Inet4Address address : ipv4Addresses) {
        serviceInfo._ipv4Addresses.add(address);
    }
    return serviceInfo;
}
Also used : Inet4Address(java.net.Inet4Address) Inet6Address(java.net.Inet6Address)

Example 53 with Inet6Address

use of java.net.Inet6Address in project netvirt by opendaylight.

the class BgpUtil method getAFItranslatedfromPrefix.

/**
 * get a translation from prefix ipv6 to afi<br>.
 * "ffff::1/128" sets afi as 2 because is an IPv6 value
 * @param argPrefix ip address as ipv4 or ipv6
 * @return afi 1 for AFI_IP 2 for AFI_IPV6
 */
public static int getAFItranslatedfromPrefix(String argPrefix) {
    // default afiValue is 1 (= ipv4)
    int retValue = af_afi.AFI_IP.getValue();
    String prefixOnly;
    if (argPrefix.indexOf("/") == -1) {
        prefixOnly = argPrefix;
    } else {
        prefixOnly = argPrefix.substring(0, argPrefix.indexOf("/"));
    }
    try {
        InetAddress address = InetAddress.getByName(prefixOnly);
        if (address instanceof Inet6Address) {
            retValue = af_afi.AFI_IPV6.getValue();
        } else if (address instanceof Inet4Address) {
            retValue = af_afi.AFI_IP.getValue();
        }
    } catch (java.net.UnknownHostException e) {
        /*if exception is catched then the prefix is not an IPv6 and IPv4*/
        LOG.error("Unrecognized ip address ipAddress: {}", argPrefix);
        // default afiValue is 1 (= ipv4)
        retValue = af_afi.AFI_IP.getValue();
    }
    return retValue;
}
Also used : Inet4Address(java.net.Inet4Address) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress)

Example 54 with Inet6Address

use of java.net.Inet6Address in project netvirt by opendaylight.

the class SubnetGwMacChangeListener method handleSubnetGwIpChange.

private void handleSubnetGwIpChange(LearntVpnVipToPort learntVpnVipToPort) {
    String macAddress = learntVpnVipToPort.getMacAddress();
    if (macAddress == null) {
        LOG.error("handleSubnetGwIpChange : Mac address is null for LearntVpnVipToPort for vpn {} prefix {}", learntVpnVipToPort.getVpnName(), learntVpnVipToPort.getPortFixedip());
        return;
    }
    String fixedIp = learntVpnVipToPort.getPortFixedip();
    if (fixedIp == null) {
        LOG.error("handleSubnetGwIpChange : Fixed ip is null for LearntVpnVipToPort for vpn {}", learntVpnVipToPort.getVpnName());
        return;
    }
    try {
        InetAddress address = InetAddress.getByName(fixedIp);
        if (address instanceof Inet6Address) {
            // TODO: Revisit when IPv6 North-South communication support is added.
            LOG.debug("handleSubnetGwIpChange : Skipping ipv6 address {}.", address);
            return;
        }
    } catch (UnknownHostException e) {
        LOG.warn("handleSubnetGwIpChange : Invalid ip address {}", fixedIp, e);
        return;
    }
    for (Uuid subnetId : nvpnManager.getSubnetIdsForGatewayIp(new IpAddress(new Ipv4Address(fixedIp)))) {
        LOG.trace("handleSubnetGwIpChange : Updating MAC resolution on vpn {} for GW ip {} to {}", learntVpnVipToPort.getVpnName(), fixedIp, macAddress);
        extNetworkInstaller.installExtNetGroupEntries(subnetId, macAddress);
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) UnknownHostException(java.net.UnknownHostException) Inet6Address(java.net.Inet6Address) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) InetAddress(java.net.InetAddress) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)

Example 55 with Inet6Address

use of java.net.Inet6Address in project netvirt by opendaylight.

the class VpnUtil method getIpVersionFromString.

/**
 *Get IpVersionChoice from String IP like x.x.x.x or an representation IPv6.
 * @param ipAddress String of an representation IP address V4 or V6
 * @return the IpVersionChoice of the version or IpVersionChoice.UNDEFINED otherwise
 */
public static IpVersionChoice getIpVersionFromString(String ipAddress) {
    IpVersionChoice ipchoice = IpVersionChoice.UNDEFINED;
    int indexIpAddress = ipAddress.indexOf('/');
    if (indexIpAddress >= 0) {
        ipAddress = ipAddress.substring(0, indexIpAddress);
    }
    try {
        InetAddress address = InetAddress.getByName(ipAddress);
        if (address instanceof Inet4Address) {
            return IpVersionChoice.IPV4;
        } else if (address instanceof Inet6Address) {
            return IpVersionChoice.IPV6;
        }
    } catch (UnknownHostException | SecurityException e) {
        ipchoice = IpVersionChoice.UNDEFINED;
    }
    return ipchoice;
}
Also used : Inet4Address(java.net.Inet4Address) UnknownHostException(java.net.UnknownHostException) Inet6Address(java.net.Inet6Address) InetAddress(java.net.InetAddress) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

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