@Override protected void finalize() throws Throwable { try { if (guard != null) { guard.warnIfOpen(); } close(); } finally { super.finalize(); } } }
/** * Creates a socket on the specified interface. */ public RawSocket(String interfaceName, short protocolType) throws SocketException { mInterfaceName = interfaceName; mProtocolType = protocolType; fd = new FileDescriptor(); create(fd, mProtocolType, mInterfaceName); guard.open("close"); }
/** * Reads a raw packet into the specified buffer, with the * specified timeout. If the destPort is -1, then the IP * destination port is not verified, otherwise only packets * destined for the specified UDP port are returned. Returns the * length actually read. No indication of overflow is signaled. * The packet data will start at the IP header (EthernetII * dest/source/type headers are removed). */ public int read(byte[] packet, int offset, int byteCount, int destPort, int timeoutMillis) { if (packet == null) { throw new NullPointerException("packet == null"); } Arrays.checkOffsetAndCount(packet.length, offset, byteCount); if (destPort > 65535) { throw new IllegalArgumentException("Port out of range: " + destPort); } return recvPacket(fd, packet, offset, byteCount, destPort, timeoutMillis); }
/** * Writes a raw packet to the desired interface. A L2 header will * be added which includes the specified destination address, our * source MAC, and the specified protocol type. The caller is responsible * for computing correct IP-header and payload checksums. */ public int write(byte[] destMac, byte[] packet, int offset, int byteCount) { if (destMac == null) { throw new NullPointerException("destMac == null"); } if (packet == null) { throw new NullPointerException("packet == null"); } Arrays.checkOffsetAndCount(packet.length, offset, byteCount); if (destMac.length != 6) { throw new IllegalArgumentException("MAC length must be 6: " + destMac.length); } return sendPacket(fd, mInterfaceName, mProtocolType, destMac, packet, offset, byteCount); }
/** * Writes a raw packet to the desired interface. A L2 header will * be added which includes the specified destination address, our * source MAC, and the specified protocol type. The caller is responsible * for computing correct IP-header and payload checksums. */ public int write(byte[] destMac, byte[] packet, int offset, int byteCount) { if (destMac == null) { throw new NullPointerException("destMac == null"); } if (packet == null) { throw new NullPointerException("packet == null"); } Arrays.checkOffsetAndCount(packet.length, offset, byteCount); if (destMac.length != 6) { throw new IllegalArgumentException("MAC length must be 6: " + destMac.length); } return sendPacket(fd, mInterfaceName, mProtocolType, destMac, packet, offset, byteCount); }
@Override protected void finalize() throws Throwable { try { if (guard != null) { guard.warnIfOpen(); } close(); } finally { super.finalize(); } } }
/** * Creates a socket on the specified interface. */ public RawSocket(String interfaceName, short protocolType) throws SocketException { mInterfaceName = interfaceName; mProtocolType = protocolType; fd = new FileDescriptor(); create(fd, mProtocolType, mInterfaceName); guard.open("close"); }
/** * Writes a raw packet to the desired interface. A L2 header will * be added which includes the specified destination address, our * source MAC, and the specified protocol type. The caller is responsible * for computing correct IP-header and payload checksums. */ public int write(byte[] destMac, byte[] packet, int offset, int byteCount) { if (destMac == null) { throw new NullPointerException("destMac == null"); } if (packet == null) { throw new NullPointerException("packet == null"); } Arrays.checkOffsetAndCount(packet.length, offset, byteCount); if (destMac.length != 6) { throw new IllegalArgumentException("MAC length must be 6: " + destMac.length); } return sendPacket(fd, mInterfaceName, mProtocolType, destMac, packet, offset, byteCount); }
/** * Reads a raw packet into the specified buffer, with the * specified timeout. If the destPort is -1, then the IP * destination port is not verified, otherwise only packets * destined for the specified UDP port are returned. Returns the * length actually read. No indication of overflow is signaled. * The packet data will start at the IP header (EthernetII * dest/source/type headers are removed). */ public int read(byte[] packet, int offset, int byteCount, int destPort, int timeoutMillis) { if (packet == null) { throw new NullPointerException("packet == null"); } Arrays.checkOffsetAndCount(packet.length, offset, byteCount); if (destPort > 65535) { throw new IllegalArgumentException("Port out of range: " + destPort); } return recvPacket(fd, packet, offset, byteCount, destPort, timeoutMillis); }
@Override protected void finalize() throws Throwable { try { if (guard != null) { guard.warnIfOpen(); } close(); } finally { super.finalize(); } } }
/** * Creates a socket on the specified interface. */ public RawSocket(String interfaceName, short protocolType) throws SocketException { mInterfaceName = interfaceName; mProtocolType = protocolType; fd = new FileDescriptor(); create(fd, mProtocolType, mInterfaceName); guard.open("close"); }
/** * Writes a raw packet to the desired interface. A L2 header will * be added which includes the specified destination address, our * source MAC, and the specified protocol type. The caller is responsible * for computing correct IP-header and payload checksums. */ public int write(byte[] destMac, byte[] packet, int offset, int byteCount) { if (destMac == null) { throw new NullPointerException("destMac == null"); } if (packet == null) { throw new NullPointerException("packet == null"); } Arrays.checkOffsetAndCount(packet.length, offset, byteCount); if (destMac.length != 6) { throw new IllegalArgumentException("MAC length must be 6: " + destMac.length); } return sendPacket(fd, mInterfaceName, mProtocolType, destMac, packet, offset, byteCount); }
/** * Reads a raw packet into the specified buffer, with the * specified timeout. If the destPort is -1, then the IP * destination port is not verified, otherwise only packets * destined for the specified UDP port are returned. Returns the * length actually read. No indication of overflow is signaled. * The packet data will start at the IP header (EthernetII * dest/source/type headers are removed). */ public int read(byte[] packet, int offset, int byteCount, int destPort, int timeoutMillis) { if (packet == null) { throw new NullPointerException("packet == null"); } Arrays.checkOffsetAndCount(packet.length, offset, byteCount); if (destPort > 65535) { throw new IllegalArgumentException("Port out of range: " + destPort); } return recvPacket(fd, packet, offset, byteCount, destPort, timeoutMillis); }
@Override protected void finalize() throws Throwable { try { if (guard != null) { guard.warnIfOpen(); } close(); } finally { super.finalize(); } } }
/** * Creates a socket on the specified interface. */ public RawSocket(String interfaceName, short protocolType) throws SocketException { mInterfaceName = interfaceName; mProtocolType = protocolType; fd = new FileDescriptor(); create(fd, mProtocolType, mInterfaceName); guard.open("close"); }
/** * Writes a raw packet to the desired interface. A L2 header will * be added which includes the specified destination address, our * source MAC, and the specified protocol type. The caller is responsible * for computing correct IP-header and payload checksums. */ public int write(byte[] destMac, byte[] packet, int offset, int byteCount) { if (destMac == null) { throw new NullPointerException("destMac == null"); } if (packet == null) { throw new NullPointerException("packet == null"); } Arrays.checkOffsetAndCount(packet.length, offset, byteCount); if (destMac.length != 6) { throw new IllegalArgumentException("MAC length must be 6: " + destMac.length); } return sendPacket(fd, mInterfaceName, mProtocolType, destMac, packet, offset, byteCount); }
/** * Reads a raw packet into the specified buffer, with the * specified timeout. If the destPort is -1, then the IP * destination port is not verified, otherwise only packets * destined for the specified UDP port are returned. Returns the * length actually read. No indication of overflow is signaled. * The packet data will start at the IP header (EthernetII * dest/source/type headers are removed). */ public int read(byte[] packet, int offset, int byteCount, int destPort, int timeoutMillis) { if (packet == null) { throw new NullPointerException("packet == null"); } Arrays.checkOffsetAndCount(packet.length, offset, byteCount); if (destPort > 65535) { throw new IllegalArgumentException("Port out of range: " + destPort); } return recvPacket(fd, packet, offset, byteCount, destPort, timeoutMillis); }
@Override protected void finalize() throws Throwable { try { if (guard != null) { guard.warnIfOpen(); } close(); } finally { super.finalize(); } } }
/** * Creates a socket on the specified interface. */ public RawSocket(String interfaceName, short protocolType) throws SocketException { mInterfaceName = interfaceName; mProtocolType = protocolType; fd = new FileDescriptor(); create(fd, mProtocolType, mInterfaceName); guard.open("close"); }
/** * Writes a raw packet to the desired interface. A L2 header will * be added which includes the specified destination address, our * source MAC, and the specified protocol type. The caller is responsible * for computing correct IP-header and payload checksums. */ public int write(byte[] destMac, byte[] packet, int offset, int byteCount) { if (destMac == null) { throw new NullPointerException("destMac == null"); } if (packet == null) { throw new NullPointerException("packet == null"); } Arrays.checkOffsetAndCount(packet.length, offset, byteCount); if (destMac.length != 6) { throw new IllegalArgumentException("MAC length must be 6: " + destMac.length); } return sendPacket(fd, mInterfaceName, mProtocolType, destMac, packet, offset, byteCount); }