Java InetAddress Create getHashFromAddress(final InetAddress address)

Here you can find the source of getHashFromAddress(final InetAddress address)

Description

get Hash From Address

License

Open Source License

Declaration

public static final long getHashFromAddress(final InetAddress address) 

Method Source Code


//package com.java2s;
/*//  w w  w. j  a  v  a 2 s . c  o m
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */

import java.net.InetAddress;

public class Main {
    public static final long getHashFromAddress(final InetAddress address) {
        return getHashFromIP(address.getAddress());
    }

    public static final long getHashFromIP(final byte[] ip) {
        if (ip.length == 4) {
            return (ip[0] & 0xFF | ip[1] << 8 & 0xFF00 | ip[2] << 16 & 0xFF0000 | ip[3] << 24 & 0xFF000000)
                    & 0xFFFFFFFFL;
        } else {
            final int i1 = ip[0] & 0xFF | ip[1] << 8 & 0xFF00 | ip[2] << 16 & 0xFF0000 | ip[3] << 24 & 0xFF000000;
            final int i2 = ip[4] & 0xFF | ip[5] << 8 & 0xFF00;
            return -(i1 & 0xFFFFFFFFL | (i2 & 0xFFFFFFFFL) << 32);
        }
    }
}

Related

  1. getFQDN(final InetAddress addr)
  2. getFreePort(InetAddress ipAddress)
  3. getFreeSocket(InetAddress bindAddress, int portRangeStart, int portRangeEnd)
  4. getFreeTCPPort(InetAddress ipAddress)
  5. getFullHostName(InetAddress netAddress)
  6. getHostAddress(InetAddress address)
  7. getHostAddress(InetAddress anAddress)
  8. getHostAddress(InetAddress host)
  9. getHostName(InetAddress address)