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 * PacketServiceAccept. 11 * 12 * @author Christian Plattner 13 * @version 2.50, 03/15/10 14 */ 15 public class PacketServiceAccept 16 { 17 byte[] payload; 18 19 String serviceName; 20 PacketServiceAccept(String serviceName)21 public PacketServiceAccept(String serviceName) 22 { 23 this.serviceName = serviceName; 24 } 25 PacketServiceAccept(byte payload[], int off, int len)26 public PacketServiceAccept(byte payload[], int off, int len) throws IOException 27 { 28 this.payload = new byte[len]; 29 System.arraycopy(payload, off, this.payload, 0, len); 30 31 TypesReader tr = new TypesReader(payload, off, len); 32 33 int packet_type = tr.readByte(); 34 35 if (packet_type != Packets.SSH_MSG_SERVICE_ACCEPT) 36 throw new IOException("This is not a SSH_MSG_SERVICE_ACCEPT! (" 37 + packet_type + ")"); 38 39 serviceName = ""; 40 41 if (tr.remain() != 0) 42 { 43 serviceName = tr.readString(); 44 } 45 } 46 getPayload()47 public byte[] getPayload() 48 { 49 if (payload == null) 50 { 51 TypesWriter tw = new TypesWriter(); 52 tw.writeByte(Packets.SSH_MSG_SERVICE_ACCEPT); 53 tw.writeString(serviceName); 54 payload = tw.getBytes(); 55 } 56 return payload; 57 } 58 } 59