Java InetAddress Create getMieleUUIDLowerPart(int deviceType50523, InetAddress address)

Here you can find the source of getMieleUUIDLowerPart(int deviceType50523, InetAddress address)

Description

get Miele UUID Lower Part

License

Open Source License

Declaration

public static long getMieleUUIDLowerPart(int deviceType50523, InetAddress address) throws Exception 

Method Source Code


//package com.java2s;
/*/*  w w  w.ja  va 2  s.  c  o m*/
 ************************************************************************************************* 
 * OrganicSmartHome [Version 2.0] is a framework for energy management in intelligent buildings
 * Copyright (C) 2014  Florian Allerding (florian.allerding@kit.edu) and Kaibin Bao and
 *                     Ingo Mauser and Till Schuberth
 * 
 * 
 * This file is part of the OrganicSmartHome.
 * 
 * OrganicSmartHome 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.
 * 
 * OrganicSmartHome 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 OrganicSmartHome.  
 * 
 * If not, see <http://www.gnu.org/licenses/>.
 * 
 *************************************************************************************************
 */

import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;

public class Main {
    public static long getMieleUUIDLowerPart(int deviceType50523, InetAddress address) throws Exception {
        return getHomeApplianceUUIDLowerPart(deviceType50523, address);
    }

    public static long getHomeApplianceUUIDLowerPart(int deviceType50523, InetAddress address) throws Exception {
        byte[] b_addr = address.getAddress();

        if (address instanceof Inet4Address || address instanceof Inet6Address)
            return getUUIDLowerPart(b_addr, deviceType50523);
        else {
            throw new Exception("Unknown IP version");
        }
    }

    private static long getUUIDLowerPart(byte[] low_array, int high_part) {
        // keep brackets and 0xff because of negative numbers
        if (low_array.length >= 8) {
            return (((long) high_part & 0xffffffff) << 32) ^ // just don't ask why...
                    ((((long) low_array[0] & 0xff) << 48) | (((long) low_array[1] & 0xff) << 32)
                            | (((long) low_array[2] & 0xff) << 24) | // EUI-64 ... byte 4..5 are skipped
                            (((long) low_array[5] & 0xff) << 16) | (((long) low_array[6] & 0xff) << 8)
                            | (((long) low_array[7] & 0xff) << 0));
        } else if (low_array.length >= 4) {
            return (((long) high_part & 0xffffffff) << 32) | (((long) low_array[0] & 0xff) << 24)
                    | (((long) low_array[1] & 0xff) << 16) | (((long) low_array[2] & 0xff) << 8)
                    | (((long) low_array[3] & 0xff) << 0);
        } else {
            return (((long) high_part & 0xffffffff) << 32);
        }
    }
}

Related

  1. getLocalInetAddresses()
  2. getLocalInetAddresses()
  3. getLocalInetAddresses(boolean includeLoopback)
  4. getMacAddress(InetAddress addr)
  5. getMacAddress(InetAddress address)
  6. getNatType(final InetAddress localAdr, final InetAddress publicAdr)
  7. getNetwork(InetAddress start, InetAddress end)
  8. getNetworkCIDR(InetAddress addr, short prefixLength)
  9. getNetworkInterface(InetAddress localAddress)