KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > ssh2 > packets > PacketOpenSessionChannel


1 package ch.ethz.ssh2.packets;
2
3 import java.io.IOException JavaDoc;
4
5 /**
6  * PacketOpenSessionChannel.
7  *
8  * @author Christian Plattner, plattner@inf.ethz.ch
9  * @version $Id: PacketOpenSessionChannel.java,v 1.2 2005/08/24 17:54:10 cplattne Exp $
10  */

11 public class PacketOpenSessionChannel
12 {
13     byte[] payload;
14
15     int channelID;
16     int initialWindowSize;
17     int maxPacketSize;
18
19     public PacketOpenSessionChannel(int channelID, int initialWindowSize,
20             int maxPacketSize)
21     {
22         this.channelID = channelID;
23         this.initialWindowSize = initialWindowSize;
24         this.maxPacketSize = maxPacketSize;
25     }
26
27     public PacketOpenSessionChannel(byte payload[], int off, int len) throws IOException JavaDoc
28     {
29         this.payload = new byte[len];
30         System.arraycopy(payload, off, this.payload, 0, len);
31
32         TypesReader tr = new TypesReader(payload);
33
34         int packet_type = tr.readByte();
35
36         if (packet_type != Packets.SSH_MSG_CHANNEL_OPEN)
37             throw new IOException JavaDoc("This is not a SSH_MSG_CHANNEL_OPEN! ("
38                     + packet_type + ")");
39
40         channelID = tr.readUINT32();
41         initialWindowSize = tr.readUINT32();
42         maxPacketSize = tr.readUINT32();
43
44         if (tr.remain() != 0)
45             throw new IOException JavaDoc("Padding in SSH_MSG_CHANNEL_OPEN packet!");
46     }
47
48     public byte[] getPayload()
49     {
50         if (payload == null)
51         {
52             TypesWriter tw = new TypesWriter();
53             tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN);
54             tw.writeString("session");
55             tw.writeUINT32(channelID);
56             tw.writeUINT32(initialWindowSize);
57             tw.writeUINT32(maxPacketSize);
58             payload = tw.getBytes();
59         }
60         return payload;
61     }
62 }
63
Popular Tags