@Test public void parseBundleMaxLength() { InetPacket testPacket = new InetPacket(new byte[] { 1, 2, 3 }); byte[] bundle = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1 }; assertFalse(testPacket.parseBundle(bundle)); }
public boolean parseBundle(byte[] bundle) { if ( bundle == null || bundle.length < MIN_BUNDLE_LENGTH ) return false; ByteBuffer buffer = ByteBuffer.wrap(bundle); int magic = buffer.getInt(); if ( magic != MAGIC_NUMBER ) return false; int port = buffer.getInt(); byte type = buffer.get(); int addressLength = type == 1 ? 16 : 4; if ( buffer.remaining() < addressLength + 2 ) return false; if ( !CrcCccitt.isValidMsgCRC(bundle, 0, MIN_BUNDLE_LENGTH - 4 + addressLength) ) return false; byte[] address = new byte[addressLength]; buffer.get(address,0,addressLength); buffer.getShort(); point = new InetPoint(address, port, true); int payloadLength = bundle.length - MIN_BUNDLE_LENGTH + 4 - addressLength; payload = new byte[payloadLength]; buffer.get(payload,0,payloadLength); return true; }
InetPacket { public boolean parseBundle(byte[] bundle) { if ( bundle == null || bundle.length < MIN_BUNDLE_LENGTH ) return false; ByteBuffer buffer = ByteBuffer.wrap(bundle); int magic = buffer.getInt(); if ( magic != MAGIC_NUMBER ) return false; int port = buffer.getInt(); byte type = buffer.get(); int addressLength = type == 1 ? 16 : 4; if ( buffer.remaining() < addressLength + 2 ) return false; if ( !CrcCccitt.isValidMsgCRC(bundle, 0, MIN_BUNDLE_LENGTH - 4 + addressLength) ) return false; byte[] address = new byte[addressLength]; buffer.get(address,0,addressLength); buffer.getShort(); point = new InetPoint(address, port, true); int payloadLength = bundle.length - MIN_BUNDLE_LENGTH + 4 - addressLength; payload = new byte[payloadLength]; buffer.get(payload,0,payloadLength); return true; } }
InetPacket { public boolean parseBundle(byte[] bundle) { if ( bundle == null || bundle.length < MIN_BUNDLE_LENGTH ) return false; ByteBuffer buffer = ByteBuffer.wrap(bundle); int magic = buffer.getInt(); if ( magic != MAGIC_NUMBER ) return false; int port = buffer.getInt(); byte type = buffer.get(); int addressLength = type == 1 ? 16 : 4; if ( buffer.remaining() < addressLength + 2 ) return false; if ( !CrcCccitt.isValidMsgCRC(bundle, 0, MIN_BUNDLE_LENGTH - 4 + addressLength) ) return false; byte[] address = new byte[addressLength]; buffer.get(address,0,addressLength); buffer.getShort(); point = new InetPoint(address, port, true); int payloadLength = bundle.length - MIN_BUNDLE_LENGTH + 4 - addressLength; payload = new byte[payloadLength]; buffer.get(payload,0,payloadLength); return true; } InetPacket(String host, int port, byte[] payload);  InetPacket(InetAddress ipAddress, int port, byte[] payload);  InetPacket(InetPoint point, byte[] payload);  InetPacket(DatagramPacket packet);  InetPacket(byte[] bundle); }
InetPacket { public boolean parseBundle(byte[] bundle) { if ( bundle == null || bundle.length < MIN_BUNDLE_LENGTH ) return false; ByteBuffer buffer = ByteBuffer.wrap(bundle); int magic = buffer.getInt(); if ( magic != MAGIC_NUMBER ) return false; int port = buffer.getInt(); byte type = buffer.get(); int addressLength = type == 1 ? 16 : 4; if ( buffer.remaining() < addressLength + 2 ) return false; if ( !CrcCccitt.isValidMsgCRC(bundle, 0, MIN_BUNDLE_LENGTH - 4 + addressLength) ) return false; byte[] address = new byte[addressLength]; buffer.get(address,0,addressLength); buffer.getShort(); point = new InetPoint(address, port, true); int payloadLength = bundle.length - MIN_BUNDLE_LENGTH + 4 - addressLength; payload = new byte[payloadLength]; buffer.get(payload,0,payloadLength); return true; } InetPacket(String host, int port, byte[] payload);  InetPacket(InetAddress ipAddress, int port, byte[] payload);  InetPacket(InetPoint point, byte[] payload);  InetPacket(DatagramPacket packet);  InetPacket(byte[] bundle); InetPoint getPoint(); byte[] getPayload(); byte[] getBundle(); boolean parseBundle(byte[] bundle); String toHexString(); }
InetPacket { public boolean parseBundle(byte[] bundle) { if ( bundle == null || bundle.length < MIN_BUNDLE_LENGTH ) return false; ByteBuffer buffer = ByteBuffer.wrap(bundle); int magic = buffer.getInt(); if ( magic != MAGIC_NUMBER ) return false; int port = buffer.getInt(); byte type = buffer.get(); int addressLength = type == 1 ? 16 : 4; if ( buffer.remaining() < addressLength + 2 ) return false; if ( !CrcCccitt.isValidMsgCRC(bundle, 0, MIN_BUNDLE_LENGTH - 4 + addressLength) ) return false; byte[] address = new byte[addressLength]; buffer.get(address,0,addressLength); buffer.getShort(); point = new InetPoint(address, port, true); int payloadLength = bundle.length - MIN_BUNDLE_LENGTH + 4 - addressLength; payload = new byte[payloadLength]; buffer.get(payload,0,payloadLength); return true; } InetPacket(String host, int port, byte[] payload);  InetPacket(InetAddress ipAddress, int port, byte[] payload);  InetPacket(InetPoint point, byte[] payload);  InetPacket(DatagramPacket packet);  InetPacket(byte[] bundle); InetPoint getPoint(); byte[] getPayload(); byte[] getBundle(); boolean parseBundle(byte[] bundle); String toHexString();  }