123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package de.tudarmstadt.informatik.hostage.wrapper;
- import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
- /**
- * Wrapper class for the payload of a network packet.
- *
- * @author Mihai Plasoianu
- * @author Wulf Pfeiffer
- */
- public class Packet {
- private byte[] payload;
- private String protocol;
- /**
- * Constructs Packet from byte[]
- *
- * @param payload
- * The byte[] payload
- */
- public Packet(byte[] payload, String protocol) {
- this.payload = payload;
- this.protocol = protocol;
- }
- /**
- * Constructs Packet from String
- *
- * @param payload
- * The String payload
- */
- public Packet(String payload, String protocol) {
- this.payload = payload.getBytes();
- this.protocol = protocol;
- }
- /**
- * Returns a byte[] representation of the payload.
- *
- * @return byte[] representation.
- */
- public byte[] getBytes() {
- return payload;
- }
- /**
- * Returns a String representation of the payload.
- * Depending on the protocol, the String will be represented
- * as a String of it's byte values.
- * E.g.: the byte[] {0x01, 0x4A, 0x03} would look like
- * the String "01, 4A, 03", or
- * otherwise a normal String will be created with the payload.
- *
- * @return String representation.
- */
- @Override
- public String toString() {
- if (protocol.equals("FTP")
- || protocol.equals("HTTP")
- || protocol.equals("HTTPS")
- || protocol.equals("SIP")) {
- return new String(payload);
- } else {
- return HelperUtils.bytesToHexString(payload);
- }
- }
- }
|