public Packet(byte[] buf, InetAddress addr) {
		this.addr = addr;
		boolean crFound = false;
		byte[] header = null;
		byte[] data = null;

		for(int i = 0; i < buf.length; i++) {
			if(buf[i] == (byte) 0x0D) {
				crFound = true;

				if(i + 3 < buf.length) {
					if (buf[i+1] == (byte) 0x0A && buf[i+2] == (byte) 0x0D && buf[i+3] == (byte) 0x0A) {
						header = Arrays.copyOfRange(buf, 0, i+4);
						if(i+4 < buf.length)
							data = Arrays.copyOfRange(buf, i+4, buf.length);
						else
							data = null;

						break;
					}
				}
			}
		}
		
		if(!crFound) {
			System.out.println("Error, missing crlf");
		}
		else {
		
			this.data = data;
			String msg = new String(header, StandardCharsets.US_ASCII);
			
			if(msg.split(" ")[0].equals("PUTCHUNK")) {
				this.packetType = "PUTCHUNK";
				String[] packOptions = msg.split(" ");
				String version = packOptions[1];
				String fileID = packOptions[2];
				String chunkNo = packOptions[3];
				String repDeg = packOptions[4];
				this.fileID = hexToByte(fileID);
				this.version = version;
				this.chunkNo = Integer.parseInt(chunkNo);
				this.replicationDeg = Integer.parseInt(repDeg.split("\\r\\n")[0]);
			}
			else if(msg.split(" ")[0].equals("CHUNK")) {
				this.packetType = "CHUNK";
				String[] packOptions = msg.split(" ");
				String version = packOptions[1];
				String fileID = packOptions[2];
				String chunkNo = packOptions[3];

				this.fileID = hexToByte(fileID);
				this.version = version;
				this.chunkNo = Integer.parseInt(chunkNo.split("\\r\\n")[0]);
			}
			else if(msg.split(" ")[0].equals("GETCHUNK")) {
				this.packetType = "GETCHUNK";
				String[] packOptions = msg.split(" ");
				String version = packOptions[1];
				String fileID = packOptions[2];
				String chunkNo = packOptions[3];
				this.fileID = hexToByte(fileID);
				this.version = version;
				this.chunkNo = Integer.parseInt(chunkNo.split("\\r\\n")[0]);
			}
			else if(msg.contains("REMOVED")) {
				this.packetType = "REMOVED";
				String[] packOptions = msg.split(" ");
				String version = packOptions[1];
				String fileID = packOptions[2];
				String chunkNo = packOptions[3];
				
				this.fileID = hexToByte(fileID);
				this.version = version;
				this.chunkNo = Integer.parseInt(chunkNo.split("\\r\\n")[0]);
			}
			else if(msg.contains("STORED")) {
				String[] packOptions = msg.split(" ");
				String version = packOptions[1];
				String fileID = packOptions[2];
				String chunkNo = packOptions[3];
				this.fileID = Packet.hexToByte(fileID);
				this.version = version;
				this.packetType = "STORED";
				this.chunkNo = Integer.parseInt(chunkNo.split("\\r\\n")[0]);
			}
			else if(msg.contains("DELETE")) {
				this.packetType = "DELETE";
				String[] packOptions = msg.split(" ");
				String fileID = packOptions[1].split("\\r\\n")[0];
				this.fileID = hexToByte(fileID);
			}
		}
	}