Search in sources :

Example 11 with PacketSocketAddress

use of android.system.PacketSocketAddress in project android_frameworks_base by crdroidandroid.

the class DhcpClient method initInterface.

private boolean initInterface() {
    try {
        mIface = NetworkInterface.getByName(mIfaceName);
        mHwAddr = mIface.getHardwareAddress();
        mInterfaceBroadcastAddr = new PacketSocketAddress(mIface.getIndex(), DhcpPacket.ETHER_BROADCAST);
        return true;
    } catch (SocketException | NullPointerException e) {
        Log.e(TAG, "Can't determine ifindex or MAC address for " + mIfaceName, e);
        return false;
    }
}
Also used : SocketException(java.net.SocketException) PacketSocketAddress(android.system.PacketSocketAddress)

Example 12 with PacketSocketAddress

use of android.system.PacketSocketAddress in project android_frameworks_base by crdroidandroid.

the class DhcpClient method initPacketSocket.

private boolean initPacketSocket() {
    try {
        mPacketSock = Os.socket(AF_PACKET, SOCK_RAW, ETH_P_IP);
        PacketSocketAddress addr = new PacketSocketAddress((short) ETH_P_IP, mIface.getIndex());
        Os.bind(mPacketSock, addr);
        NetworkUtils.attachDhcpFilter(mPacketSock);
    } catch (SocketException | ErrnoException e) {
        Log.e(TAG, "Error creating packet socket", e);
        return false;
    }
    return true;
}
Also used : SocketException(java.net.SocketException) PacketSocketAddress(android.system.PacketSocketAddress) ErrnoException(android.system.ErrnoException)

Aggregations

PacketSocketAddress (android.system.PacketSocketAddress)12 SocketException (java.net.SocketException)12 ErrnoException (android.system.ErrnoException)8 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)4 FileDescriptor (java.io.FileDescriptor)4