private boolean checkForErrors(DatagramPacket packet, int expectedtype, DatagramSocket socket){
    	DatagramPacket err = null;
    	boolean goodPacket = true;
    	
    	if(packet.getData()[1] == 5){
    		System.out.println(ExtractErrorMsg(packet));
    		return false;
    	}
    	
    	if(packet.getData()[0] != 0){
    		err = FormError.illegalTFTP("First Opcode digit must be 0");
    		goodPacket= false;
    	} else if(expectedtype != packet.getData()[1] ) {             
    		err = FormError.illegalTFTP("Wrong opcode got " + (packet.getData()[1]) + " expected " + PACKETTYPES[expectedtype -1]);
    		goodPacket= false;
    	} else if((packet.getData()[1]) < 1 || (packet.getData()[1])> 5) {
    		err = FormError.illegalTFTP((packet.getData()[1]) + " is an invalid Opcode");
    		goodPacket= false;
    	}
    	
    	if((packet.getData()[1]) == 5){
    		goodPacket= false;
    		return goodPacket; //dont repond to error packets
    	}
    	
    	if(err!= null){
    		err.setAddress(packet.getAddress());
    		err.setPort(packet.getPort());
    		try{
    			socket.send(err);
    		} catch(java.net.SocketException se) {
    			se.printStackTrace();
    			System.exit(1);
    		}catch(java.io.IOException io) {
    			io.printStackTrace();
    			System.exit(1);
    		}
    	}
    	return goodPacket;
    }