Home | History | Annotate | Download | only in packets
      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 /**
     10  * PacketChannelOpenConfirmation.
     11  *
     12  * @author Christian Plattner
     13  * @version 2.50, 03/15/10
     14  */
     15 public class PacketChannelOpenConfirmation
     16 {
     17 	byte[] payload;
     18 
     19 	public int recipientChannelID;
     20 	public int senderChannelID;
     21 	public int initialWindowSize;
     22 	public int maxPacketSize;
     23 
     24 	public PacketChannelOpenConfirmation(int recipientChannelID, int senderChannelID, int initialWindowSize,
     25 			int maxPacketSize)
     26 	{
     27 		this.recipientChannelID = recipientChannelID;
     28 		this.senderChannelID = senderChannelID;
     29 		this.initialWindowSize = initialWindowSize;
     30 		this.maxPacketSize = maxPacketSize;
     31 	}
     32 
     33 	public PacketChannelOpenConfirmation(byte payload[], int off, int len) throws IOException
     34 	{
     35 		this.payload = new byte[len];
     36 		System.arraycopy(payload, off, this.payload, 0, len);
     37 
     38 		TypesReader tr = new TypesReader(payload, off, len);
     39 
     40 		int packet_type = tr.readByte();
     41 
     42 		if (packet_type != Packets.SSH_MSG_CHANNEL_OPEN_CONFIRMATION)
     43 			throw new IOException(
     44 					"This is not a SSH_MSG_CHANNEL_OPEN_CONFIRMATION! ("
     45 							+ packet_type + ")");
     46 
     47 		recipientChannelID = tr.readUINT32();
     48 		senderChannelID = tr.readUINT32();
     49 		initialWindowSize = tr.readUINT32();
     50 		maxPacketSize = tr.readUINT32();
     51 
     52 		if (tr.remain() != 0)
     53 			throw new IOException("Padding in SSH_MSG_CHANNEL_OPEN_CONFIRMATION packet!");
     54 	}
     55 
     56 	public byte[] getPayload()
     57 	{
     58 		if (payload == null)
     59 		{
     60 			TypesWriter tw = new TypesWriter();
     61 			tw.writeByte(Packets.SSH_MSG_CHANNEL_OPEN_CONFIRMATION);
     62 			tw.writeUINT32(recipientChannelID);
     63 			tw.writeUINT32(senderChannelID);
     64 			tw.writeUINT32(initialWindowSize);
     65 			tw.writeUINT32(maxPacketSize);
     66 			payload = tw.getBytes();
     67 		}
     68 		return payload;
     69 	}
     70 }
     71