/[rdesktop]/jpeg/rdesktop/trunk/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

Annotation of /jpeg/rdesktop/trunk/iso.c

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26