comparison src/ch/ethz/ssh2/packets/PacketChannelOpenConfirmation.java @ 273:91a31873c42a ganymed

start conversion from trilead to ganymed
author Carl Byington <carl@five-ten-sg.com>
date Fri, 18 Jul 2014 11:21:46 -0700
parents
children 071eccdff8ea
comparison
equal deleted inserted replaced
272:ce2f4e397703 273:91a31873c42a
1 /*
2 * Copyright (c) 2006-2011 Christian Plattner. All rights reserved.
3 * Please refer to the LICENSE.txt for licensing details.
4 */
5 package ch.ethz.ssh2.packets;
6
7 import java.io.IOException;
8
9 import ch.ethz.ssh2.PacketFormatException;
10 import ch.ethz.ssh2.PacketTypeException;
11
12 /**
13 * @author Christian Plattner
14 * @version $Id: PacketChannelOpenConfirmation.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $
15 */
16 public final class PacketChannelOpenConfirmation {
17
18 private final byte[] payload;
19
20 private final int recipientChannelID;
21 private final int senderChannelID;
22 private final int initialWindowSize;
23 private final int maxPacketSize;
24
25 public PacketChannelOpenConfirmation(int recipientChannelID, int senderChannelID, int initialWindowSize,
26 int maxPacketSize) {
27 this.recipientChannelID = recipientChannelID;
28 this.senderChannelID = senderChannelID;
29 this.initialWindowSize = initialWindowSize;
30 this.maxPacketSize = maxPacketSize;
31 TypesWriter tw = new TypesWriter();
32 tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
33 tw.writeUINT32(recipientChannelID);
34 tw.writeUINT32(senderChannelID);
35 tw.writeUINT32(initialWindowSize);
36 tw.writeUINT32(maxPacketSize);
37 payload = tw.getBytes();
38 }
39
40 public PacketChannelOpenConfirmation(byte payload[]) throws IOException {
41 this.payload = payload;
42
43 TypesReader tr = new TypesReader(payload);
44
45 int packet_type = tr.readByte();
46
47 if(packet_type != Packets.SSH_MSG_CHANNEL_OPEN_CONFIRMATION) {
48 throw new PacketTypeException(packet_type);
49 }
50
51 recipientChannelID = tr.readUINT32();
52 senderChannelID = tr.readUINT32();
53 initialWindowSize = tr.readUINT32();
54 maxPacketSize = tr.readUINT32();
55
56 if(tr.remain() != 0) {
57 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type)));
58 }
59 }
60
61 public int getRecipientChannelID() {
62 return recipientChannelID;
63 }
64
65 public int getSenderChannelID() {
66 return senderChannelID;
67 }
68
69 public int getInitialWindowSize() {
70 return initialWindowSize;
71 }
72
73 public int getMaxPacketSize() {
74 return maxPacketSize;
75 }
76
77 public byte[] getPayload() {
78 return payload;
79 }
80 }