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 * PacketServiceRequest. 11 * 12 * @author Christian Plattner 13 * @version 2.50, 03/15/10 14 */ 15 public class PacketServiceRequest 16 { 17 byte[] payload; 18 19 String serviceName; 20 21 public PacketServiceRequest(String serviceName) 22 { 23 this.serviceName = serviceName; 24 } 25 26 public PacketServiceRequest(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_REQUEST) 36 throw new IOException("This is not a SSH_MSG_SERVICE_REQUEST! (" 37 + packet_type + ")"); 38 39 serviceName = tr.readString(); 40 41 if (tr.remain() != 0) 42 throw new IOException("Padding in SSH_MSG_SERVICE_REQUEST packet!"); 43 } 44 45 public byte[] getPayload() 46 { 47 if (payload == null) 48 { 49 TypesWriter tw = new TypesWriter(); 50 tw.writeByte(Packets.SSH_MSG_SERVICE_REQUEST); 51 tw.writeString(serviceName); 52 payload = tw.getBytes(); 53 } 54 return payload; 55 } 56 } 57