Package java.net

Examples of java.net.NetworkInterface


            }
            catch(BindException bind_ex) {
                if(start_port == end_port)
                    throw new BindException("No available port to bind to");
                if(bind_addr != null) {
                    NetworkInterface nic=NetworkInterface.getByInetAddress(bind_addr);
                    if(nic == null)
                      log.warn("bind_addr " + bind_addr + " is not a valid interface: " + bind_ex);
                }
                start_port++;
                continue;
View Full Code Here


      // now check other interfaces.
      try
      {
         for (Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces(); nics.hasMoreElements();)
         {
            NetworkInterface i = nics.nextElement();
            for (Enumeration<InetAddress> addrs = i.getInetAddresses(); addrs.hasMoreElements();)
            {
               InetAddress addr = addrs.nextElement();
               if (addr.equals(inetC)) return true;
            }
         }
View Full Code Here

                (inetAddress.isLinkLocalAddress() || inetAddress.isSiteLocalAddress())) {
            final Inet6Address inet6Address = (Inet6Address) inetAddress;
            if (inet6Address.getScopeId() <= 0 && inet6Address.getScopedInterface() == null) {
                Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
                while (interfaces.hasMoreElements()) {
                    NetworkInterface ni = interfaces.nextElement();
                    Enumeration<InetAddress> addresses = ni.getInetAddresses();
                    while (addresses.hasMoreElements()) {
                        InetAddress address = addresses.nextElement();
                        if (address instanceof Inet6Address &&
                                Arrays.equals(address.getAddress(), inet6Address.getAddress())) {
                            if (resultInetAddress != null) {
View Full Code Here

                && inet6Address.getScopeId() <= 0 && inet6Address.getScopedInterface() == null) {
            final LinkedList<Inet6Address> possibleAddresses = new LinkedList<Inet6Address>();
            try {
                final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
                while (interfaces.hasMoreElements()) {
                    NetworkInterface ni = interfaces.nextElement();
                    Enumeration<InetAddress> addresses = ni.getInetAddresses();
                    while (addresses.hasMoreElements()) {
                        InetAddress address = addresses.nextElement();
                        if (address instanceof Inet4Address) {
                            continue;
                        }
View Full Code Here

    private AddressDefinition pickMatchingAddress(final Collection<InterfaceDefinition> interfaces) throws SocketException {
        final Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
        final boolean preferIPv4Stack = preferIPv4Stack();
        while (networkInterfaces.hasMoreElements()) {
            final NetworkInterface ni = networkInterfaces.nextElement();
            final Enumeration<InetAddress> e = ni.getInetAddresses();
            while (e.hasMoreElements()) {
                final InetAddress inetAddress = e.nextElement();
                if (preferIPv4Stack && inetAddress instanceof Inet6Address) {
                    continue;
                }
View Full Code Here

         // lets get a few more interfaces from the current host
         Enumeration en = NetworkInterface.getNetworkInterfaces();
         while (en.hasMoreElements())
         {
            NetworkInterface i = (NetworkInterface) en.nextElement();
            for (Enumeration en2 = i.getInetAddresses(); en2.hasMoreElements();)
            {
               InetAddress addr = (InetAddress) en2.nextElement();
               if (addr.isLoopbackAddress() || addr instanceof Inet6Address) continue;
               buddies_same_host_different_nic.add(new IpAddress(addr, 1000));
            }
View Full Code Here

            }
        }

        Enumeration<NetworkInterface> nics = nic.getSubInterfaces();
        while (nics.hasMoreElements()) {
            NetworkInterface next = nics.nextElement();
            boolean matches = matches(next, match);
            if (matches) {
                return true;
            }
        }
View Full Code Here

    @BeforeClass
    public static void setup() throws Exception {
        Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
        while (nifs.hasMoreElements()) {
            NetworkInterface nif = nifs.nextElement();
            processNetworkInterface(nif);
            Enumeration<NetworkInterface> subs = nif.getSubInterfaces();
            while (subs.hasMoreElements()) {
                NetworkInterface sub = subs.nextElement();
                processNetworkInterface(sub);
            }
        }
        System.out.println("loopback: " + loopbackInterface + " " + loopbackAddress);
        for (Map.Entry<NetworkInterface, Set<Inet6Address>> entry : addresses.entrySet()) {
View Full Code Here

    @Test
    public void testNonLoopback() throws Exception {

        for (Map.Entry<NetworkInterface, Set<Inet6Address>> entry : addresses.entrySet()) {
            NetworkInterface nif = entry.getKey();
            for (Inet6Address address : entry.getValue()) {
                String hostAddress = address.getHostAddress();
                int pos = hostAddress.indexOf('%');
                if (pos > -1) {
                    hostAddress = hostAddress.substring(0, pos);
                }
                InetAddressMatchInterfaceCriteria criteria = new InetAddressMatchInterfaceCriteria(new ModelNode(hostAddress));
                assertEquals(address, criteria.isAcceptable(nif, address));
                criteria = new InetAddressMatchInterfaceCriteria(new ModelNode(hostAddress + "%" + nif.getName()));
                assertEquals(address, criteria.isAcceptable(nif, address));
                criteria = new InetAddressMatchInterfaceCriteria(new ModelNode(hostAddress + "%" + address.getScopeId()));
                assertEquals(address, criteria.isAcceptable(nif, address));
                criteria = new InetAddressMatchInterfaceCriteria(new ModelNode(hostAddress + "%" + (address.getScopeId() + 1)));
                assertNull(criteria.isAcceptable(nif, address));
View Full Code Here

                final int localBindPort = CommonAttributes.LOCAL_BIND_PORT.resolveModelAttribute(context, model).asInt();

                try {

                    final InetAddress inet = localAddress != null ? InetAddress.getByName(localAddress) : InetAddressUtil.getLocalHost();
                    final NetworkInterface intf = NetworkInterface.getByInetAddress(inet);
                    final NetworkInterfaceBinding b = new NetworkInterfaceBinding(Collections.singleton(intf), inet);
                    final InetAddress group = InetAddress.getByName(groupAddress);

                    final SocketBinding socketBinding = new SocketBinding(name, localBindPort, false, group, groupPort, b, null, null);
View Full Code Here

TOP

Related Classes of java.net.NetworkInterface

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.