/[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 25 - (hide annotations)
Sat Jan 6 03:47:04 2001 UTC (23 years, 4 months ago) by matty
Original Path: sourceforge.net/trunk/rdesktop/iso.c
File MIME type: text/plain
File size: 2995 byte(s)
Changed indentation style (-psl).

1 matty 3 /*
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 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     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     return False;
56    
57     in_uint8(s, version);
58     if (version != 3)
59 matty 3 {
60 matty 10 ERROR("TPKT v%d\n", version);
61     return False;
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     return False;
70    
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     iso_recv()
119 matty 3 {
120 matty 10 STREAM s;
121 matty 3 uint8 code;
122    
123 matty 10 s = iso_recv_msg(&code);
124     if ((s == NULL) || (code != ISO_PDU_DT))
125 matty 3 {
126 matty 10 ERROR("expected DT, got %d\n", code);
127 matty 3 return False;
128     }
129    
130 matty 10 return s;
131 matty 3 }
132    
133 matty 10 /* Establish a connection up to the ISO layer */
134 matty 25 BOOL
135     iso_connect(char *server)
136 matty 3 {
137 matty 10 uint8 code;
138 matty 3
139 matty 10 if (!tcp_connect(server))
140     return False;
141 matty 3
142 matty 10 iso_send_msg(ISO_PDU_CR);
143 matty 3
144 matty 10 if ((iso_recv_msg(&code) == NULL) || (code != ISO_PDU_CC))
145 matty 3 {
146 matty 10 ERROR("expected CC, got %d\n", code);
147     tcp_disconnect();
148 matty 3 return False;
149     }
150    
151     return True;
152     }
153    
154 matty 10 /* Disconnect from the ISO layer */
155 matty 25 void
156     iso_disconnect()
157 matty 3 {
158 matty 10 iso_send_msg(ISO_PDU_DR);
159     tcp_disconnect();
160 matty 3 }

  ViewVC Help
Powered by ViewVC 1.1.26