Example usage for java.net InetAddress getAddress

List of usage examples for java.net InetAddress getAddress

Introduction

In this page you can find the example usage for java.net InetAddress getAddress.

Prototype

public byte[] getAddress() 

Source Link

Document

Returns the raw IP address of this InetAddress object.

Usage

From source file:org.opendaylight.netvirt.dhcpservice.api.DHCP.java

public DHCP setYiaddr(InetAddress dhcpYiaddr) {
    byte[] yiaddr = dhcpYiaddr.getAddress();
    fieldValues.put(YIADDR, yiaddr);/*  w ww .  j  a v a  2 s .co m*/
    return this;
}

From source file:org.opendaylight.netvirt.dhcpservice.api.DHCP.java

public DHCP setSiaddr(InetAddress dhcpSiaddr) {
    byte[] siaddr = dhcpSiaddr.getAddress();
    fieldValues.put(SIADDR, siaddr);//from w  w  w.j  av  a 2s.  co m
    return this;
}

From source file:org.opendaylight.netvirt.dhcpservice.api.DHCP.java

public DHCP setGiaddr(InetAddress dhcpGiaddr) {
    byte[] giaddr = dhcpGiaddr.getAddress();
    fieldValues.put(GIADDR, giaddr);/*from w ww .j  a v  a2  s . c o m*/
    return this;
}

From source file:com.mobiperf.measurements.PingTask.java

@Override
public MeasurementResult call() throws MeasurementError {
    PingDesc desc = (PingDesc) measurementDesc;
    int ipByteLength;
    try {//from   w w  w.ja va 2 s .c o m
        InetAddress addr = InetAddress.getByName(desc.target);
        // Get the address length
        ipByteLength = addr.getAddress().length;
        Logger.i("IP address length is " + ipByteLength);
        // All ping methods ping against targetIp rather than desc.target
        targetIp = addr.getHostAddress();
        Logger.i("IP is " + targetIp);
    } catch (UnknownHostException e) {
        throw new MeasurementError("Unknown host " + desc.target);
    }

    try {
        Logger.i("running ping command");
        // Prevents the phone from going to low-power mode where WiFi turns off
        return executePingCmdTask(ipByteLength);
    } catch (MeasurementError e) {
        try {
            Logger.i("running java ping");
            return executeJavaPingTask();
        } catch (MeasurementError ee) {
            Logger.i("running http ping");
            return executeHttpPingTask();
        }
    }
}

From source file:org.opendaylight.controller.sal.packet.IPv4.java

/**
 * Stores the IP source address from the header
 * @param sourceAddress the sourceAddress to set
 * @return IPv4/*www .ja  v  a2s .co  m*/
 */
public IPv4 setSourceAddress(InetAddress ipSourceAddress) {
    byte[] sourceAddress = ipSourceAddress.getAddress();
    fieldValues.put(SIP, sourceAddress);
    return this;
}

From source file:com.poinsart.votar.VotarMain.java

public String getWifiIp() {
    Enumeration<NetworkInterface> en = null;
    try {//from w w w  .  j a va 2  s  .  c  o  m
        en = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
        return null;
    }
    while (en.hasMoreElements()) {
        NetworkInterface intf = en.nextElement();
        if (intf.getName().contains("wlan")) {
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress() && (inetAddress.getAddress().length == 4)) {
                    //Log.d("VotAR Main", inetAddress.getHostAddress());
                    return inetAddress.getHostAddress().toString();
                }
            }
        }
    }
    return null;
}

From source file:org.opendaylight.controller.sal.packet.IPv4.java

/**
 * Stores the IP destination address from the header
 * @param the destination Address to set
 * @return IPv4//from  w  w w. ja va 2s  .co m
 */
public IPv4 setDestinationAddress(InetAddress ipDestinationAddress) {
    byte[] sourceAddress = ipDestinationAddress.getAddress();
    fieldValues.put(DIP, sourceAddress);
    return this;
}

From source file:org.apache.cassandra.db.clock.IncrementCounterContext.java

public byte[] update(byte[] context, InetAddress node, long delta) {
    // update timestamp
    FBUtilities.copyIntoBytes(context, 0, System.currentTimeMillis());

    // calculate node id
    byte[] nodeId = node.getAddress();

    // look for this node id
    for (int offset = HEADER_LENGTH; offset < context.length; offset += stepLength) {
        if (FBUtilities.compareByteSubArrays(context, offset, nodeId, 0, idLength) != 0)
            continue;

        // node id found: increment count, shift to front
        long count = FBUtilities.byteArrayToLong(context, offset + idLength);

        System.arraycopy(context, HEADER_LENGTH, context, HEADER_LENGTH + stepLength, offset - HEADER_LENGTH);
        writeElement(context, nodeId, count + delta);

        return context;
    }//w ww  .j a va2s  .  c  om

    // node id not found: widen context
    byte[] previous = context;
    context = new byte[previous.length + stepLength];

    System.arraycopy(previous, 0, context, 0, HEADER_LENGTH);
    writeElement(context, nodeId, delta);
    System.arraycopy(previous, HEADER_LENGTH, context, HEADER_LENGTH + stepLength,
            previous.length - HEADER_LENGTH);

    return context;
}

From source file:com.cloud.utils.net.NetUtils.java

public static String ipFromInetAddress(final InetAddress addr) {
    assert addr != null;

    final byte[] ipBytes = addr.getAddress();
    final StringBuffer sb = new StringBuffer();
    sb.append(ipBytes[0] & 0xff).append(".");
    sb.append(ipBytes[1] & 0xff).append(".");
    sb.append(ipBytes[2] & 0xff).append(".");
    sb.append(ipBytes[3] & 0xff);//from  ww  w . j a  v a 2 s.c  o  m

    return sb.toString();
}

From source file:org.eclipse.smila.processing.pipelets.xmlprocessing.util.XMLUtils.java

/**
 * A 32 byte GUID generator (Globally Unique ID). These artificial keys SHOULD <strong>NOT </strong> be seen by the
 * user, not even touched by the DBA but with very rare exceptions, just manipulated by the database and the programs.
 * /*w w w.  ja  v a 2s. c o  m*/
 * Usage: Add an id field (type java.lang.String) to your EJB, and add setId(XXXUtil.generateGUID(this)); to the
 * ejbCreate method.
 * 
 * @param o
 *          a Object
 * @return a String
 */
public static final String generateGUID(Object o) {
    final Log log = LogFactory.getLog(XMLUtils.class);
    final StringBuffer tmpBuffer = new StringBuffer(16);
    if (s_hexServerIP == null) {
        java.net.InetAddress localInetAddress = null;
        try {
            // get the inet address
            localInetAddress = java.net.InetAddress.getLocalHost();
        } catch (java.net.UnknownHostException uhe) {
            // todo: find better way to get around this...
            final String msg = "ConfigurationUtil: Could not get the local IP address using InetAddress.getLocalHost()!";
            System.err.println(msg);
            if (log.isErrorEnabled()) {
                log.error(uhe);
            }
            return null;
        }
        final byte[] serverIP = localInetAddress.getAddress();
        s_hexServerIP = hexFormat(getInt(serverIP), 8);
    }
    final String hashcode = hexFormat(System.identityHashCode(o), 8);
    tmpBuffer.append(s_hexServerIP);
    tmpBuffer.append(hashcode);

    final long timeNow = System.currentTimeMillis();
    final int timeLow = (int) timeNow & 0xFFFFFFFF;
    final int node = SEEDER.nextInt();

    final StringBuffer guid = new StringBuffer(32);
    guid.append(hexFormat(timeLow, 8));
    guid.append(tmpBuffer.toString());
    guid.append(hexFormat(node, 8));
    return guid.toString();
}