Home | History | Annotate | Download | only in packets
      1 /*
      2  * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
      3  * Please refer to the LICENSE.txt for licensing details.
      4  */
      5 package ch.ethz.ssh2.packets;
      6 import java.io.IOException;
      7 
      8 /**
      9  * PacketDisconnect.
     10  *
     11  * @author Christian Plattner
     12  * @version 2.50, 03/15/10
     13  */
     14 public class PacketDisconnect
     15 {
     16 	byte[] payload;
     17 
     18 	int reason;
     19 	String desc;
     20 	String lang;
     21 
     22 	public PacketDisconnect(byte payload[], int off, int len) throws IOException
     23 	{
     24 		this.payload = new byte[len];
     25 		System.arraycopy(payload, off, this.payload, 0, len);
     26 
     27 		TypesReader tr = new TypesReader(payload, off, len);
     28 
     29 		int packet_type = tr.readByte();
     30 
     31 		if (packet_type != Packets.SSH_MSG_DISCONNECT)
     32 			throw new IOException("This is not a Disconnect Packet! ("
     33 					+ packet_type + ")");
     34 
     35 		reason = tr.readUINT32();
     36 		desc = tr.readString();
     37 		lang = tr.readString();
     38 	}
     39 
     40 	public PacketDisconnect(int reason, String desc, String lang)
     41 	{
     42 		this.reason = reason;
     43 		this.desc = desc;
     44 		this.lang = lang;
     45 	}
     46 
     47 	public byte[] getPayload()
     48 	{
     49 		if (payload == null)
     50 		{
     51 			TypesWriter tw = new TypesWriter();
     52 			tw.writeByte(Packets.SSH_MSG_DISCONNECT);
     53 			tw.writeUINT32(reason);
     54 			tw.writeString(desc);
     55 			tw.writeString(lang);
     56 			payload = tw.getBytes();
     57 		}
     58 		return payload;
     59 	}
     60 }
     61