comparison src/com/trilead/ssh2/packets/PacketOpenSessionChannel.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 package com.trilead.ssh2.packets;
2
3 import java.io.IOException;
4
5 /**
6 * PacketOpenSessionChannel.
7 *
8 * @author Christian Plattner, plattner@trilead.com
9 * @version $Id: PacketOpenSessionChannel.java,v 1.1 2007/10/15 12:49:55 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, int initialWindowSize,
19 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) throws IOException {
26 this.payload = new byte[len];
27 System.arraycopy(payload, off, this.payload, 0, len);
28 TypesReader tr = new TypesReader(payload);
29 int packet_type = tr.readByte();
30
31 if (packet_type != Packets.SSH_MSG_CHANNEL_OPEN)
32 throw new IOException("This is not a SSH_MSG_CHANNEL_OPEN! ("
33 + packet_type + ")");
34
35 channelID = tr.readUINT32();
36 initialWindowSize = tr.readUINT32();
37 maxPacketSize = tr.readUINT32();
38
39 if (tr.remain() != 0)
40 throw new IOException("Padding in SSH_MSG_CHANNEL_OPEN packet!");
41 }
42
43 public byte[] getPayload() {
44 if (payload == null) {
45 TypesWriter tw = new TypesWriter();
46 tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN);
47 tw.writeString("session");
48 tw.writeUINT32(channelID);
49 tw.writeUINT32(initialWindowSize);
50 tw.writeUINT32(maxPacketSize);
51 payload = tw.getBytes();
52 }
53
54 return payload;
55 }
56 }