public NativeRawSocket(int protocolFamily, int protocol) throws IOException { socket = __socket(protocolFamily, protocol); if (socket < 0) { throwIOException(socket); } family = protocolFamily; }
public void close() throws IOException { int result = __close(socket); if (result != 0) { throwIOException(result); } }
public int read(byte[] data, int offset, int length, byte[] address) throws IOException { if (offset < 0 || length < 0 || length > data.length - offset) throw new IllegalArgumentException("Invalid offset or length"); if ((address != null) && (((family == PF_INET) && (address.length != 4)) || ((family == PF_INET6) && (address.length != 16)))) { throw new IllegalArgumentException("Invalid address length"); } int result = (address == null) ? __recvfrom1(socket, data, offset, length, family) : __recvfrom2(socket, data, offset, length, family, address); if (result < 0) { throwIOException(result); } return result; }
public int write(byte[] address, byte[] data, int offset, int length) throws IOException { int scope_id = getScopeId(address); if ((offset < 0) || (length < 0) || (length > data.length - offset)) { throw new IllegalArgumentException("Invalid offset or length"); } int result = __sendto(socket, data, offset, length, family, address, scope_id); if (result < 0) { throwIOException(result); } return result; }
public void bind(byte[] address) throws IOException { int scope_id = getScopeId(address); int result = __bind(socket, family, address, scope_id); if (result != 0) { throwIOException(result); } }