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