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