Java InetAddress Check isLinkLocalIPv4Address(InetAddress add)

Here you can find the source of isLinkLocalIPv4Address(InetAddress add)

Description

Determines whether the address is an IPv4 link local address.

License

LGPL

Parameter

Parameter Description
add the address to inspect

Return

true if add is a link local ipv4 address and false if not.

Declaration

public static boolean isLinkLocalIPv4Address(InetAddress add) 

Method Source Code


//package com.java2s;
/*//from w w w  .  j ava 2s  . c  o m
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

import java.net.*;

public class Main {
    /**
     * Determines whether the address is an IPv4 link local address. IPv4 link
     * local addresses are those in the following networks:
     *
     * 10.0.0.0    to 10.255.255.255
     * 172.16.0.0  to 172.31.255.255
     * 192.168.0.0 to 192.168.255.255
     *
     * @param add the address to inspect
     * @return true if add is a link local ipv4 address and false if not.
     */
    public static boolean isLinkLocalIPv4Address(InetAddress add) {
        if (add instanceof Inet4Address) {
            byte address[] = add.getAddress();
            if ((address[0] & 0xFF) == 10)
                return true;
            if ((address[0] & 0xFF) == 172 && (address[1] & 0xFF) >= 16 && address[1] <= 31)
                return true;
            if ((address[0] & 0xFF) == 192 && (address[1] & 0xFF) == 168)
                return true;
            return false;
        }
        return false;
    }
}

Related

  1. isIPLocal(final InetAddress adr)
  2. isIPv6(final InetAddress ip)
  3. isIPv6(InetAddress addr)
  4. isIPv6UniqueSiteLocal(InetAddress address)
  5. isLikelyBroadcast(InetAddress address)
  6. isLinkLocalNetwork(InetAddress addr)
  7. isLocal(InetAddress a)
  8. isLocalAddress(InetAddress addr)
  9. isLocalAddress(InetAddress addr)