Search in sources :

Example 6 with PacketSocketAddress

use of android.system.PacketSocketAddress in project platform_frameworks_base by android.

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)

Example 7 with PacketSocketAddress

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

the class ApfFilter method maybeStartFilter.

/**
     * Attempt to start listening for RAs and, if RAs are received, generating and installing
     * filters to ignore useless RAs.
     */
@VisibleForTesting
void maybeStartFilter() {
    FileDescriptor socket;
    try {
        mHardwareAddress = mNetworkInterface.getHardwareAddress();
        synchronized (this) {
            // Install basic filters
            installNewProgramLocked();
        }
        socket = Os.socket(AF_PACKET, SOCK_RAW, ETH_P_IPV6);
        PacketSocketAddress addr = new PacketSocketAddress((short) ETH_P_IPV6, mNetworkInterface.getIndex());
        Os.bind(socket, addr);
        NetworkUtils.attachRaFilter(socket, mApfCapabilities.apfPacketFormat);
    } catch (SocketException | ErrnoException e) {
        Log.e(TAG, "Error starting filter", e);
        return;
    }
    mReceiveThread = new ReceiveThread(socket);
    mReceiveThread.start();
}
Also used : SocketException(java.net.SocketException) PacketSocketAddress(android.system.PacketSocketAddress) ErrnoException(android.system.ErrnoException) FileDescriptor(java.io.FileDescriptor) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 8 with PacketSocketAddress

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

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 9 with PacketSocketAddress

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

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)

Example 10 with PacketSocketAddress

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

the class ApfFilter method maybeStartFilter.

/**
     * Attempt to start listening for RAs and, if RAs are received, generating and installing
     * filters to ignore useless RAs.
     */
@VisibleForTesting
void maybeStartFilter() {
    FileDescriptor socket;
    try {
        mHardwareAddress = mNetworkInterface.getHardwareAddress();
        synchronized (this) {
            // Install basic filters
            installNewProgramLocked();
        }
        socket = Os.socket(AF_PACKET, SOCK_RAW, ETH_P_IPV6);
        PacketSocketAddress addr = new PacketSocketAddress((short) ETH_P_IPV6, mNetworkInterface.getIndex());
        Os.bind(socket, addr);
        NetworkUtils.attachRaFilter(socket, mApfCapabilities.apfPacketFormat);
    } catch (SocketException | ErrnoException e) {
        Log.e(TAG, "Error starting filter", e);
        return;
    }
    mReceiveThread = new ReceiveThread(socket);
    mReceiveThread.start();
}
Also used : SocketException(java.net.SocketException) PacketSocketAddress(android.system.PacketSocketAddress) ErrnoException(android.system.ErrnoException) FileDescriptor(java.io.FileDescriptor) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

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