comparison src/com/trilead/ssh2/packets/PacketDisconnect.java @ 0:0ce5cc452d02

initial version
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 10:41:19 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0ce5cc452d02
1
2 package com.trilead.ssh2.packets;
3
4 import java.io.IOException;
5
6 /**
7 * PacketDisconnect.
8 *
9 * @author Christian Plattner, plattner@trilead.com
10 * @version $Id: PacketDisconnect.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $
11 */
12 public class PacketDisconnect {
13 byte[] payload;
14
15 int reason;
16 String desc;
17 String lang;
18
19 public PacketDisconnect(byte payload[], int off, int len) throws IOException {
20 this.payload = new byte[len];
21 System.arraycopy(payload, off, this.payload, 0, len);
22 TypesReader tr = new TypesReader(payload, off, len);
23 int packet_type = tr.readByte();
24
25 if (packet_type != Packets.SSH_MSG_DISCONNECT)
26 throw new IOException("This is not a Disconnect Packet! (" + packet_type + ")");
27
28 reason = tr.readUINT32();
29 desc = tr.readString();
30 lang = tr.readString();
31 }
32
33 public PacketDisconnect(int reason, String desc, String lang) {
34 this.reason = reason;
35 this.desc = desc;
36 this.lang = lang;
37 }
38
39 public byte[] getPayload() {
40 if (payload == null) {
41 TypesWriter tw = new TypesWriter();
42 tw.writeByte(Packets.SSH_MSG_DISCONNECT);
43 tw.writeUINT32(reason);
44 tw.writeString(desc);
45 tw.writeString(lang);
46 payload = tw.getBytes();
47 }
48
49 return payload;
50 }
51 }