01: package ch.ethz.ssh2.packets;
02:
03: import java.io.IOException;
04:
05: /**
06: * PacketDisconnect.
07: *
08: * @author Christian Plattner, plattner@inf.ethz.ch
09: * @version $Id: PacketDisconnect.java,v 1.3 2005/08/29 14:24:58 cplattne Exp $
10: */
11: public class PacketDisconnect {
12: byte[] payload;
13:
14: int reason;
15: String desc;
16: String lang;
17:
18: public PacketDisconnect(byte payload[], int off, int len)
19: throws IOException {
20: this .payload = new byte[len];
21: System.arraycopy(payload, off, this .payload, 0, len);
22:
23: TypesReader tr = new TypesReader(payload, off, len);
24:
25: int packet_type = tr.readByte();
26:
27: if (packet_type != Packets.SSH_MSG_DISCONNECT)
28: throw new IOException("This is not a Disconnect Packet! ("
29: + packet_type + ")");
30:
31: reason = tr.readUINT32();
32: desc = tr.readString();
33: lang = tr.readString();
34: }
35:
36: public PacketDisconnect(int reason, String desc, String lang) {
37: this .reason = reason;
38: this .desc = desc;
39: this .lang = lang;
40: }
41:
42: public byte[] getPayload() {
43: if (payload == null) {
44: TypesWriter tw = new TypesWriter();
45: tw.writeByte(Packets.SSH_MSG_DISCONNECT);
46: tw.writeUINT32(reason);
47: tw.writeString(desc);
48: tw.writeString(lang);
49: payload = tw.getBytes();
50: }
51: return payload;
52: }
53: }
|