/[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 207 - (show annotations)
Thu Sep 26 14:26:46 2002 UTC (21 years, 7 months ago) by matthewc
File MIME type: text/plain
File size: 3035 byte(s)
Update copyright dates on all files that have changed.
Bump version to 1.2-cvs.

1 /*
2 rdesktop: A Remote Desktop Protocol client.
3 Protocol services - ISO layer
4 Copyright (C) Matthew Chapman 1999-2002
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
25 iso_send_msg(uint8 code)
26 {
27 STREAM s;
28
29 s = tcp_init(11);
30
31 out_uint8(s, 3); /* version */
32 out_uint8(s, 0); /* reserved */
33 out_uint16_be(s, 11); /* length */
34
35 out_uint8(s, 6); /* hdrlen */
36 out_uint8(s, code);
37 out_uint16(s, 0); /* dst_ref */
38 out_uint16(s, 0); /* src_ref */
39 out_uint8(s, 0); /* class */
40
41 s_mark_end(s);
42 tcp_send(s);
43 }
44
45 /* Receive a message on the ISO layer, return code */
46 static STREAM
47 iso_recv_msg(uint8 * code)
48 {
49 STREAM s;
50 uint16 length;
51 uint8 version;
52
53 s = tcp_recv(4);
54 if (s == NULL)
55 return NULL;
56
57 in_uint8(s, version);
58 if (version != 3)
59 {
60 error("TPKT v%d\n", version);
61 return NULL;
62 }
63
64 in_uint8s(s, 1); /* pad */
65 in_uint16_be(s, length);
66
67 s = tcp_recv(length - 4);
68 if (s == NULL)
69 return NULL;
70
71 in_uint8s(s, 1); /* hdrlen */
72 in_uint8(s, *code);
73
74 if (*code == ISO_PDU_DT)
75 {
76 in_uint8s(s, 1); /* eot */
77 return s;
78 }
79
80 in_uint8s(s, 5); /* dst_ref, src_ref, class */
81 return s;
82 }
83
84 /* Initialise ISO transport data packet */
85 STREAM
86 iso_init(int length)
87 {
88 STREAM s;
89
90 s = tcp_init(length + 7);
91 s_push_layer(s, iso_hdr, 7);
92
93 return s;
94 }
95
96 /* Send an ISO data PDU */
97 void
98 iso_send(STREAM s)
99 {
100 uint16 length;
101
102 s_pop_layer(s, iso_hdr);
103 length = s->end - s->p;
104
105 out_uint8(s, 3); /* version */
106 out_uint8(s, 0); /* reserved */
107 out_uint16_be(s, length);
108
109 out_uint8(s, 2); /* hdrlen */
110 out_uint8(s, ISO_PDU_DT); /* code */
111 out_uint8(s, 0x80); /* eot */
112
113 tcp_send(s);
114 }
115
116 /* Receive ISO transport data packet */
117 STREAM
118 iso_recv(void)
119 {
120 STREAM s;
121 uint8 code;
122
123 s = iso_recv_msg(&code);
124 if (s == NULL)
125 return NULL;
126
127 if (code != ISO_PDU_DT)
128 {
129 error("expected DT, got 0x%x\n", code);
130 return NULL;
131 }
132
133 return s;
134 }
135
136 /* Establish a connection up to the ISO layer */
137 BOOL
138 iso_connect(char *server)
139 {
140 uint8 code;
141
142 if (!tcp_connect(server))
143 return False;
144
145 iso_send_msg(ISO_PDU_CR);
146
147 if (iso_recv_msg(&code) == NULL)
148 return False;
149
150 if (code != ISO_PDU_CC)
151 {
152 error("expected CC, got 0x%x\n", code);
153 tcp_disconnect();
154 return False;
155 }
156
157 return True;
158 }
159
160 /* Disconnect from the ISO layer */
161 void
162 iso_disconnect(void)
163 {
164 iso_send_msg(ISO_PDU_DR);
165 tcp_disconnect();
166 }

  ViewVC Help
Powered by ViewVC 1.1.26