Package java.net

Examples of java.net.NetworkInterface


            e = NetworkInterface.getNetworkInterfaces();
        } catch (SocketException ex) {
            throw new UnknownHostException("127.0.0.1");
        }
        while (e.hasMoreElements()) {
            NetworkInterface ni = (NetworkInterface) e.nextElement();
            for (Enumeration e2 = ni.getInetAddresses(); e2.hasMoreElements();) {
                addresses.add(e2.nextElement());
            }
        }
        InetAddress[] iAddresses = new InetAddress[addresses.size()];
        for (int i = 0; i < iAddresses.length; i++) {
View Full Code Here


                    break;
                case SO_TRANSMIT_IF:
                    if (val == null) {
                        device = null;
                    } else {
                        final NetworkInterface netIf = (NetworkInterface) val;
                        try {
                            device = DeviceUtils.getDevice(netIf.getName());
                        } catch (DeviceNotFoundException ex) {
                            throw new SocketException("Unknown networkinterface " + netIf.getName());
                        }
                    }
                    break;
                case SO_TIMEOUT:
                    timeout = (Integer) val;
View Full Code Here

    harness.check(ifs.hasMoreElements(), "getNetworkInterfaces returns something");
   
    HashSet names = new HashSet();
    while (ifs.hasMoreElements())
      {
        NetworkInterface netif = (NetworkInterface) ifs.nextElement();
        harness.checkPoint("consistency - " + netif.getName());
        harness.check(!names.contains(netif.getName()), "duplicate entries");
        names.add(netif.getName());

        try
          {
            NetworkInterface netif2 = NetworkInterface.getByName(netif.getName());
            harness.check(netif2 != null);
            harness.check(netif.equals(netif2));
          }
        catch (Exception x)
          {
            harness.fail("getByName unexpected exception");
            harness.debug(x);
          }
       
        Enumeration addrs = netif.getInetAddresses();
        harness.check(addrs.hasMoreElements());
       
        while (addrs.hasMoreElements())
          {
            try
              {
                InetAddress addr = (InetAddress) addrs.nextElement();
                NetworkInterface netif2 = NetworkInterface.getByInetAddress(addr);
                harness.check(netif2 != null);
                harness.check(netif.equals(netif2));
              }
            catch (Exception x)
              {
View Full Code Here

      harness.checkPoint("setup");

      LinkedList list = new LinkedList();
      for (Enumeration e = NetworkInterface.getNetworkInterfaces();
     e.hasMoreElements(); ) {
  NetworkInterface nif = (NetworkInterface) e.nextElement();
  for (Enumeration f = nif.getInetAddresses(); f.hasMoreElements(); )
    list.add(f.nextElement());
      }
      harness.check(!list.isEmpty());

      Permission[] checks = new Permission[list.size()];
      for (int i = 0; i < list.size(); i++) {
  InetAddress addr = (InetAddress) list.get(i);
  checks[i] = new SocketPermission(addr.getHostAddress(), "resolve");
      }

      TestSecurityManager sm = new TestSecurityManager(harness);
      try {
  sm.install();

   // throwpoint: java.net.NetworkInterface-getInetAddresses
  harness.checkPoint("getInetAddresses");
  try {
    sm.prepareChecks(checks);
    for (Enumeration e = NetworkInterface.getNetworkInterfaces();
         e.hasMoreElements(); ) {
      NetworkInterface nif = (NetworkInterface) e.nextElement();
      nif.getInetAddresses();
    }
    sm.checkAllChecked();
  }
  catch (SecurityException ex) {
    harness.debug(ex);
View Full Code Here

public class getByName
  implements Testlet
{
  public void test(TestHarness h)
  {
    NetworkInterface netif;
   
    try {
     netif = NetworkInterface.getByName(null);
     
      h.fail("- 1 - NullPointerException expected");
View Full Code Here

    try {
      nets = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
      return null;
    }
    NetworkInterface netinf;
    while (nets.hasMoreElements()) {
      netinf = nets.nextElement();

      Enumeration<InetAddress> addresses = netinf.getInetAddresses();

      while (addresses.hasMoreElements()) {
        InetAddress address = addresses.nextElement();
        if (!address.isAnyLocalAddress() && !address.isMulticastAddress() && !(address instanceof Inet6Address)) {
          return address.getHostAddress();
View Full Code Here

  private static String getMacAddress() {
    if (MAC_ADRESS == null) {
      InetAddress ip;
      try {
        ip = InetAddress.getLocalHost();
        NetworkInterface network = NetworkInterface
            .getByInetAddress(ip);

        byte[] mac = network.getHardwareAddress();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < mac.length; i++) {
          sb.append(String.format("%02X%s", mac[i],
              (i < mac.length - 1) ? "-" : ""));
        }
View Full Code Here

        List<InetAddress> ipAddresses = new ArrayList<InetAddress>();
        String ipAddress = null;

        Enumeration e = NetworkInterface.getNetworkInterfaces();
        while (e.hasMoreElements()) {
            NetworkInterface ni = (NetworkInterface) e.nextElement();
            // Clustering doesn't work for loop-back addresses, so we are not interested
            // we are not interested in inactive interfaces either
            // if (ni.isLoopback() || !ni.isUp()) continue;

            Enumeration e2 = ni.getInetAddresses();
            while (e2.hasMoreElements()) {
                InetAddress ip = (InetAddress) e2.nextElement();
                ipAddresses.add(ip);
            }
        }
View Full Code Here

      socket = new MulticastSocket(Constants.discoveryPort);
      if (multicastInterfaces != null) {
    Level failureLogLevel = multicastInterfacesSpecified ?
        Level.WARNING : Levels.HANDLED;
    for (int i = 0; i < multicastInterfaces.length; i++) {
        NetworkInterface nic = multicastInterfaces[i];
        try {
      socket.setNetworkInterface(nic);
      socket.joinGroup(requestAddr);
        } catch (IOException e) {
      failedInterfaces.add(nic);
View Full Code Here

   * succeeds.  The null value is used to indicate the default network
   * interface.
   */
  private void retryFailedInterfaces() {
      for (Iterator i = failedInterfaces.iterator(); i.hasNext(); ) {
    NetworkInterface nic = (NetworkInterface) i.next();
    try {
        if (nic != null) {
      socket.setNetworkInterface(nic);
        }
        socket.joinGroup(requestAddr);
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.