android.net.DhcpInfo

Here are the examples of the java api class android.net.DhcpInfo taken from open source projects.

1. WifiUtils#getBroadcastIPAddressRaw()

Project: tilt-game-android
File: WifiUtils.java
public static byte[] getBroadcastIPAddressRaw(final Context pContext) throws WifiUtilsException {
    final WifiManager wifiManager = WifiUtils.getWifiManager(pContext);
    final DhcpInfo dhcp = wifiManager.getDhcpInfo();
    // TODO handle null somehow...
    final int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    final byte[] broadcastIP = new byte[IPUtils.IPV4_LENGTH];
    for (int k = 0; k < IPUtils.IPV4_LENGTH; k++) {
        broadcastIP[k] = (byte) ((broadcast >> (k * 8)) & 0xFF);
    }
    return broadcastIP;
}

2. NetworkUtils#getBroadcastAddress()

Project: Protocoder
File: NetworkUtils.java
// Get broadcast Address
public static InetAddress getBroadcastAddress(Context c) throws UnknownHostException {
    WifiManager wifi = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();
    if (dhcp == null) {
        return InetAddress.getByAddress(null);
    }
    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++) {
        quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
    }
    return InetAddress.getByAddress(quads);
}

3. WifiUtils#getServerIPAddress()

Project: WifiChat
File: WifiUtils.java
public static String getServerIPAddress() {
    DhcpInfo mDhcpInfo = mWifiManager.getDhcpInfo();
    return intToIp(mDhcpInfo.gateway);
}

4. GDMService#getBroadcastAddress()

Project: serenity-android
File: GDMService.java
// Builds the broadcast address based on the local network
protected InetAddress getBroadcastAddress() throws IOException {
    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    DhcpInfo dhcp = wifi.getDhcpInfo();
    // handle null somehow
    int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
    byte[] quads = new byte[4];
    for (int k = 0; k < 4; k++) quads[k] = (byte) (broadcast >> k * 8);
    return InetAddress.getByAddress(quads);
}

5. NetworkUtils#getGatewayIpAddress()

Project: Protocoder
File: NetworkUtils.java
public static void getGatewayIpAddress(Context c) {
    // get wifi ip
    final WifiManager manager = (WifiManager) c.getSystemService(Context.WIFI_SERVICE);
    final DhcpInfo dhcp = manager.getDhcpInfo();
    final String address = Formatter.formatIpAddress(dhcp.gateway);
    StringBuilder IFCONFIG = new StringBuilder();
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress() && inetAddress.isSiteLocalAddress()) {
                    IFCONFIG.append(inetAddress.getHostAddress().toString() + "\n");
                }
            }
        }
    } catch (SocketException ex) {
        Log.e("LOG_TAG", ex.toString());
    }
    MLog.d(TAG, "ifconfig " + IFCONFIG.toString());
    MLog.d(TAG, "hotspot address is " + address);
}