Here you can find the source of long2InetAddress(long val)
Parameter | Description |
---|---|
val | int representation of IPv4 address |
public static final InetAddress long2InetAddress(long val)
//package com.java2s; /**/*from ww w .j a va2 s . c o m*/ * Copyright (c) 2014-2016 openHAB UG (haftungsbeschraenkt) 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; import java.net.UnknownHostException; public class Main { /** * Converts 32 bits int packaged into a 64bits long to IPv4 <tt>InetAddress</tt>. * * @param val int representation of IPv4 address * @return the address object */ public static final InetAddress long2InetAddress(long val) { if ((val < 0) || (val > 0xFFFFFFFFL)) { // TODO exception ??? } return int2InetAddress((int) val); } /** * Converts 32 bits int to IPv4 <tt>InetAddress</tt>. * * @param val int representation of IPv4 address * @return the address object */ public static final InetAddress int2InetAddress(int val) { byte[] value = { (byte) ((val & 0xFF000000) >>> 24), (byte) ((val & 0X00FF0000) >>> 16), (byte) ((val & 0x0000FF00) >>> 8), (byte) ((val & 0x000000FF)) }; try { return InetAddress.getByAddress(value); } catch (UnknownHostException e) { return null; } } }