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