Java InetAddress Check isValidAddress(InetAddress i, boolean includeLocalAddressesInNoderefs)

Here you can find the source of isValidAddress(InetAddress i, boolean includeLocalAddressesInNoderefs)

Description

is Valid Address

License

GNU General Public License

Declaration

public static boolean isValidAddress(InetAddress i, boolean includeLocalAddressesInNoderefs) 

Method Source Code


//package com.java2s;
/* This code is part of Freenet. It is distributed under the GNU General
 * Public License, version 2 (or at your option any later version). See
 * http://www.gnu.org/ for further details of the GPL. */

import java.net.InetAddress;

public class Main {
    public static boolean isValidAddress(InetAddress i, boolean includeLocalAddressesInNoderefs) {
        if (i.isAnyLocalAddress()) {
            // Wildcard address, 0.0.0.0, ignore.
            return false;
        } else if (i.isLinkLocalAddress() || i.isLoopbackAddress() || i.isSiteLocalAddress()) {
            if (includeLocalAddressesInNoderefs) {
                return true;
            } else
                return false;
        } else if (i.isMulticastAddress()) {
            // Ignore
            return false;
        } else {//w w w  . j a  v a 2 s  .  c  o  m
            byte[] ipAddressBytes = i.getAddress();
            if (ipAddressBytes.length == 4 && ipAddressBytes[0] == 0) {
                return false; // First octet of IPv4 address cannot be zero as 0.0.0.0/8 has been reserved since at least RFC790 (also, Java throws an IOException when they're used)
            }
            return true;
        }
    }
}

Related

  1. isThisMyIpAddress(InetAddress addr)
  2. isThisMyIpAddress(InetAddress addr)
  3. isUDPPortFree(int port, InetAddress addr)
  4. isUnicastAddress(@CheckForNull InetAddress address)
  5. isValidAddress(InetAddress address, int timeoutMs)
  6. isValidAddress(InetAddress i, boolean includeLocalAddressesInNoderefs)
  7. isValidCiscoWildcard(InetAddress wildcard)
  8. isValidInetAddress(String address)
  9. isValidInetAddress(String IP)