comparison src/com/trilead/ssh2/packets/PacketServiceAccept.java @ 0:0ce5cc452d02

initial version
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 10:41:19 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0ce5cc452d02
1
2 package com.trilead.ssh2.packets;
3
4 import java.io.IOException;
5
6 /**
7 * PacketServiceAccept.
8 *
9 * @author Christian Plattner, plattner@trilead.com
10 * @version $Id: PacketServiceAccept.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $
11 */
12 public class PacketServiceAccept {
13 byte[] payload;
14
15 String serviceName;
16
17 public PacketServiceAccept(String serviceName) {
18 this.serviceName = serviceName;
19 }
20
21 public PacketServiceAccept(byte payload[], int off, int len) throws IOException {
22 this.payload = new byte[len];
23 System.arraycopy(payload, off, this.payload, 0, len);
24 TypesReader tr = new TypesReader(payload, off, len);
25 int packet_type = tr.readByte();
26
27 if (packet_type != Packets.SSH_MSG_SERVICE_ACCEPT)
28 throw new IOException("This is not a SSH_MSG_SERVICE_ACCEPT! (" + packet_type + ")");
29
30 /* Be clever in case the server is not. Some servers seem to violate RFC4253 */
31
32 if (tr.remain() > 0) {
33 serviceName = tr.readString();
34 }
35 else {
36 serviceName = "";
37 }
38
39 if (tr.remain() != 0)
40 throw new IOException("Padding in SSH_MSG_SERVICE_ACCEPT packet!");
41 }
42
43 public byte[] getPayload() {
44 if (payload == null) {
45 TypesWriter tw = new TypesWriter();
46 tw.writeByte(Packets.SSH_MSG_SERVICE_ACCEPT);
47 tw.writeString(serviceName);
48 payload = tw.getBytes();
49 }
50
51 return payload;
52 }
53 }