273
|
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: PacketServiceRequest.java 160 2014-05-01 14:30:26Z dkocher@sudo.ch $
|
|
15 */
|
|
16 public final class PacketServiceRequest {
|
|
17 private final byte[] payload;
|
|
18
|
|
19 private final String serviceName;
|
|
20
|
|
21 public PacketServiceRequest(String serviceName) {
|
|
22 this.serviceName = serviceName;
|
|
23 TypesWriter tw = new TypesWriter();
|
|
24 tw.writeByte(Packets.SSH_MSG_SERVICE_REQUEST);
|
|
25 tw.writeString(serviceName);
|
|
26 payload = tw.getBytes();
|
|
27 }
|
|
28
|
|
29 public String getServiceName() {
|
|
30 return serviceName;
|
|
31 }
|
|
32
|
|
33 public PacketServiceRequest(byte payload[]) throws IOException {
|
|
34 this.payload = payload;
|
|
35 TypesReader tr = new TypesReader(payload);
|
|
36 int packet_type = tr.readByte();
|
|
37
|
307
|
38 if (packet_type != Packets.SSH_MSG_SERVICE_REQUEST) {
|
273
|
39 throw new PacketTypeException(packet_type);
|
|
40 }
|
|
41
|
|
42 serviceName = tr.readString();
|
|
43
|
307
|
44 if (tr.remain() != 0) {
|
273
|
45 throw new PacketFormatException(String.format("Padding in %s", Packets.getMessageName(packet_type)));
|
|
46 }
|
|
47 }
|
|
48
|
|
49 public byte[] getPayload() {
|
|
50 return payload;
|
|
51 }
|
|
52 }
|