Java InetAddress convertInetAddressToLong(InetAddress address)

Here you can find the source of convertInetAddressToLong(InetAddress address)

Description

convert Inet Address To Long

License

Open Source License

Declaration

public static long convertInetAddressToLong(InetAddress address) 

Method Source Code

//package com.java2s;
/*//from  w  w w.j  av a  2  s.c  om
 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

import java.net.InetAddress;

public class Main {
    public static long convertInetAddressToLong(InetAddress address) {
        byte[] ipAddressRaw = address.getAddress();
        return (((ipAddressRaw[0] & 0xFF) << (3 * 8))
                + ((ipAddressRaw[1] & 0xFF) << (2 * 8))
                + ((ipAddressRaw[2] & 0xFF) << (1 * 8)) + (ipAddressRaw[3] & 0xFF)) & 0xffffffffL;
    }
}

Related

  1. compareInetAddresses(InetAddress a, InetAddress b)
  2. compareInetAddresses(InetAddress a1, InetAddress a2)
  3. CompareIP(InetAddress ip1, InetAddress ip2)
  4. contains(InetAddress network, InetAddress netmask, InetAddress ip)
  5. convertInetAddressToLong(InetAddress addr)
  6. convertLongToInetAddress(long address)
  7. createAbsoluteURL(InetAddress address, int localStreamPort, URI relativeOrNot)
  8. createDatagramSocket(InetAddress addr, int port)
  9. createInetSocketAddress(final InetAddress address)