/[rdesktop]/sourceforge.net/trunk/rdesktop/iso.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /sourceforge.net/trunk/rdesktop/iso.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations)
Tue Aug 15 10:23:24 2000 UTC (23 years, 8 months ago) by matty
File MIME type: text/plain
File size: 2999 byte(s)
Major commit of work from laptop - done in various free moments.
Implemented encryption layer and some basic licensing negotiation.
Reorganised code somewhat. While this is not quite as clean, it is
a lot faster - our parser speed was becoming a bottle-neck.

1 /*
2 rdesktop: A Remote Desktop Protocol client.
3 Protocol services - ISO layer
4 Copyright (C) Matthew Chapman 1999-2000
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "rdesktop.h"
22
23 /* Send a self-contained ISO PDU */
24 static void iso_send_msg(uint8 code)
25 {
26 STREAM s;
27
28 s = tcp_init(11);
29
30 out_uint8(s, 3); /* version */
31 out_uint8(s, 0); /* reserved */
32 out_uint16_be(s, 11); /* length */
33
34 out_uint8(s, 6); /* hdrlen */
35 out_uint8(s, code);
36 out_uint16(s, 0); /* dst_ref */
37 out_uint16(s, 0); /* src_ref */
38 out_uint8(s, 0); /* class */
39
40 s_mark_end(s);
41 tcp_send(s);
42 }
43
44 /* Receive a message on the ISO layer, return code */
45 static STREAM iso_recv_msg(uint8 *code)
46 {
47 STREAM s;
48 uint16 length;
49 uint8 version;
50
51 s = tcp_recv(4);
52 if (s == NULL)
53 return False;
54
55 in_uint8(s, version);
56 if (version != 3)
57 {
58 ERROR("TPKT v%d\n", version);
59 return False;
60 }
61
62 in_uint8s(s, 1); /* pad */
63 in_uint16_be(s, length);
64
65 s = tcp_recv(length - 4);
66 if (s == NULL)
67 return False;
68
69 in_uint8s(s, 1); /* hdrlen */
70 in_uint8(s, *code);
71
72 if (*code == ISO_PDU_DT)
73 {
74 in_uint8s(s, 1); /* eot */
75 return s;
76 }
77
78 in_uint8s(s, 5); /* dst_ref, src_ref, class */
79 return s;
80 }
81
82 /* Initialise ISO transport data packet */
83 STREAM iso_init(int length)
84 {
85 STREAM s;
86
87 s = tcp_init(length + 7);
88 s_push_layer(s, iso_hdr, 7);
89
90 return s;
91 }
92
93 /* Send an ISO data PDU */
94 void iso_send(STREAM s)
95 {
96 uint16 length;
97
98 s_pop_layer(s, iso_hdr);
99 length = s->end - s->p;
100
101 out_uint8(s, 3); /* version */
102 out_uint8(s, 0); /* reserved */
103 out_uint16_be(s, length);
104
105 out_uint8(s, 2); /* hdrlen */
106 out_uint8(s, ISO_PDU_DT); /* code */
107 out_uint8(s, 0x80); /* eot */
108
109 tcp_send(s);
110 }
111
112 /* Receive ISO transport data packet */
113 STREAM iso_recv()
114 {
115 STREAM s;
116 uint8 code;
117
118 s = iso_recv_msg(&code);
119 if ((s == NULL) || (code != ISO_PDU_DT))
120 {
121 ERROR("expected DT, got %d\n", code);
122 return False;
123 }
124
125 return s;
126 }
127
128 /* Establish a connection up to the ISO layer */
129 BOOL iso_connect(char *server)
130 {
131 uint8 code;
132
133 if (!tcp_connect(server))
134 return False;
135
136 iso_send_msg(ISO_PDU_CR);
137
138 if ((iso_recv_msg(&code) == NULL) || (code != ISO_PDU_CC))
139 {
140 ERROR("expected CC, got %d\n", code);
141 tcp_disconnect();
142 return False;
143 }
144
145 return True;
146 }
147
148 /* Disconnect from the ISO layer */
149 void iso_disconnect()
150 {
151 iso_send_msg(ISO_PDU_DR);
152 tcp_disconnect();
153 }

  ViewVC Help
Powered by ViewVC 1.1.26