Here you can find the source of getBroadcastAddress(Context context)
public static String getBroadcastAddress(Context context)
//package com.java2s; import java.net.InetAddress; import java.net.UnknownHostException; import android.content.Context; import android.net.DhcpInfo; import android.net.wifi.WifiManager; public class Main { public static String getBroadcastAddress(Context context) { WifiManager wifi = (WifiManager) context .getSystemService(Context.WIFI_SERVICE); DhcpInfo dhcp = wifi.getDhcpInfo(); 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)); try {//from w ww . j av a2s . c om return InetAddress.getByAddress(quads).getHostAddress(); } catch (UnknownHostException e) { e.printStackTrace(); } return "255.255.255.255"; } }