01: package ch.ethz.ssh2.packets;
02:
03: import java.io.IOException;
04:
05: /**
06: * PacketServiceRequest.
07: *
08: * @author Christian Plattner, plattner@inf.ethz.ch
09: * @version $Id: PacketServiceRequest.java,v 1.2 2005/08/24 17:54:09 cplattne Exp $
10: */
11: public class PacketServiceRequest {
12: byte[] payload;
13:
14: String serviceName;
15:
16: public PacketServiceRequest(String serviceName) {
17: this .serviceName = serviceName;
18: }
19:
20: public PacketServiceRequest(byte payload[], int off, int len)
21: throws IOException {
22: this .payload = new byte[len];
23: System.arraycopy(payload, off, this .payload, 0, len);
24:
25: TypesReader tr = new TypesReader(payload, off, len);
26:
27: int packet_type = tr.readByte();
28:
29: if (packet_type != Packets.SSH_MSG_SERVICE_REQUEST)
30: throw new IOException(
31: "This is not a SSH_MSG_SERVICE_REQUEST! ("
32: + packet_type + ")");
33:
34: serviceName = tr.readString();
35:
36: if (tr.remain() != 0)
37: throw new IOException(
38: "Padding in SSH_MSG_SERVICE_REQUEST packet!");
39: }
40:
41: public byte[] getPayload() {
42: if (payload == null) {
43: TypesWriter tw = new TypesWriter();
44: tw.writeByte(Packets.SSH_MSG_SERVICE_REQUEST);
45: tw.writeString(serviceName);
46: payload = tw.getBytes();
47: }
48: return payload;
49: }
50: }
|