@Test public void testCopyTo() { ByteBuffer buffer = createMockTCPHeader(); TCPHeader header = new TCPHeader(buffer); ByteBuffer target = ByteBuffer.allocate(40); target.position(12); TCPHeader copy = header.copyTo(target); copy.setSourcePort(9999); Assert.assertEquals(32, target.position()); Assert.assertEquals("Header must modify target", 9999, target.getShort(12)); Assert.assertEquals("Header must not modify buffer", 0x1234, buffer.getShort(0)); }
@Override public TCPHeader copyTo(ByteBuffer target) { raw.rewind(); ByteBuffer slice = Binary.slice(target, target.position(), getHeaderLength()); target.put(raw); return new TCPHeader(slice); }
TCPHeader implements TransportHeader { @Override public TCPHeader copyTo(ByteBuffer target) { raw.rewind(); ByteBuffer slice = Binary.slice(target, target.position(), getHeaderLength()); target.put(raw); return new TCPHeader(slice); } }
TCPHeader implements TransportHeader { @Override public TCPHeader copyTo(ByteBuffer target) { raw.rewind(); ByteBuffer slice = Binary.slice(target, target.position(), getHeaderLength()); target.put(raw); return new TCPHeader(slice); } TCPHeader(ByteBuffer raw); }
TCPHeader implements TransportHeader { @Override public TCPHeader copyTo(ByteBuffer target) { raw.rewind(); ByteBuffer slice = Binary.slice(target, target.position(), getHeaderLength()); target.put(raw); return new TCPHeader(slice); } TCPHeader(ByteBuffer raw); int getWindow(); @Override int getSourcePort(); @Override int getDestinationPort(); @Override void setSourcePort(int sourcePort); @Override void setDestinationPort(int destinationPort); int getSequenceNumber(); void setSequenceNumber(int sequenceNumber); int getAcknowledgementNumber(); void setAcknowledgementNumber(int acknowledgementNumber); @Override int getHeaderLength(); @Override void setPayloadLength(int payloadLength); int getFlags(); void setFlags(int flags); void shrinkOptions(); boolean isFin(); boolean isSyn(); boolean isRst(); boolean isPsh(); boolean isAck(); boolean isUrg(); @Override ByteBuffer getRaw(); @Override TCPHeader copyTo(ByteBuffer target); TCPHeader copy(); @Override void computeChecksum(IPv4Header ipv4Header, ByteBuffer payload); short getChecksum(); }
TCPHeader implements TransportHeader { @Override public TCPHeader copyTo(ByteBuffer target) { raw.rewind(); ByteBuffer slice = Binary.slice(target, target.position(), getHeaderLength()); target.put(raw); return new TCPHeader(slice); } TCPHeader(ByteBuffer raw); int getWindow(); @Override int getSourcePort(); @Override int getDestinationPort(); @Override void setSourcePort(int sourcePort); @Override void setDestinationPort(int destinationPort); int getSequenceNumber(); void setSequenceNumber(int sequenceNumber); int getAcknowledgementNumber(); void setAcknowledgementNumber(int acknowledgementNumber); @Override int getHeaderLength(); @Override void setPayloadLength(int payloadLength); int getFlags(); void setFlags(int flags); void shrinkOptions(); boolean isFin(); boolean isSyn(); boolean isRst(); boolean isPsh(); boolean isAck(); boolean isUrg(); @Override ByteBuffer getRaw(); @Override TCPHeader copyTo(ByteBuffer target); TCPHeader copy(); @Override void computeChecksum(IPv4Header ipv4Header, ByteBuffer payload); short getChecksum(); static final int FLAG_FIN; static final int FLAG_SYN; static final int FLAG_RST; static final int FLAG_PSH; static final int FLAG_ACK; static final int FLAG_URG; }