3 #define SHORT(p) (((p)[0]<<8)|((p)[1]))
4 #define LONG(p) ((SHORT(p)<<16)|SHORT(p+2))
9 vncinit(int fd, int cfd, Vnc *v)
12 v = mallocz(sizeof(*v), 1);
13 Binit(&v->in, fd, OREAD);
14 Binit(&v->out, fd, OWRITE);
30 if(Bflush(&v->out) < 0){
32 fprint(2, "hungup while sending flush: %r\n");
42 vncrdbytes(v, buf, 1);
51 vncrdbytes(v, buf, 2);
60 vncrdbytes(v, buf, 4);
79 r.min.x = vncrdshort(v);
80 r.min.y = vncrdshort(v);
81 r.max.x = r.min.x + vncrdshort(v);
82 r.max.y = r.min.y + vncrdshort(v);
91 r.min.x = vncrdchar(v);
92 r.min.y = vncrdchar(v);
93 r.max.x = r.min.x + vncrdchar(v);
94 r.max.y = r.min.y + vncrdchar(v);
99 vncrdbytes(Vnc *v, void *a, int n)
101 if(Bread(&v->in, a, n) != n){
103 fprint(2, "hungup while reading\n");
114 fmt.bpp = vncrdchar(v);
115 fmt.depth = vncrdchar(v);
116 fmt.bigendian = vncrdchar(v);
117 fmt.truecolor = vncrdchar(v);
118 fmt.red.max = vncrdshort(v);
119 fmt.green.max = vncrdshort(v);
120 fmt.blue.max = vncrdshort(v);
121 fmt.red.shift = vncrdchar(v);
122 fmt.green.shift = vncrdchar(v);
123 fmt.blue.shift = vncrdchar(v);
124 vncrdbytes(v, pad, 3);
138 vncrdbytes(v, s, len);
144 * on the server side of the negotiation protocol, we read
145 * the client response and then run the negotiated function.
146 * in some cases (e.g., TLS) the negotiated function needs to
147 * use v->datafd directly and be sure that no data has been
148 * buffered away in the Bio. since we know the client is waiting
149 * for our response, it won't have sent any until we respond.
150 * thus we read the response with vncrdstringx, which goes
160 assert(Bbuffered(&v->in) == 0);
161 if(readn(v->datafd, tmp, 4) != 4){
162 fprint(2, "cannot rdstringx: %r");
168 if(readn(v->datafd, s, len) != len){
169 fprint(2, "cannot rdstringx len %lud: %r", len);
177 vncwrstring(Vnc *v, char *s)
183 vncwrbytes(v, s, len);
187 vncwrbytes(Vnc *v, void *a, int n)
189 if(Bwrite(&v->out, a, n) < 0){
191 fprint(2, "hungup while writing bytes\n");
197 vncwrlong(Vnc *v, ulong u)
205 vncwrbytes(v, buf, 4);
209 vncwrshort(Vnc *v, ushort u)
215 vncwrbytes(v, buf, 2);
219 vncwrchar(Vnc *v, uchar c)
221 vncwrbytes(v, &c, 1);
225 vncwrpixfmt(Vnc *v, Pixfmt *fmt)
227 vncwrchar(v, fmt->bpp);
228 vncwrchar(v, fmt->depth);
229 vncwrchar(v, fmt->bigendian);
230 vncwrchar(v, fmt->truecolor);
231 vncwrshort(v, fmt->red.max);
232 vncwrshort(v, fmt->green.max);
233 vncwrshort(v, fmt->blue.max);
234 vncwrchar(v, fmt->red.shift);
235 vncwrchar(v, fmt->green.shift);
236 vncwrchar(v, fmt->blue.shift);
237 vncwrbytes(v, zero, 3);
241 vncwrrect(Vnc *v, Rectangle r)
243 vncwrshort(v, r.min.x);
244 vncwrshort(v, r.min.y);
245 vncwrshort(v, r.max.x-r.min.x);
246 vncwrshort(v, r.max.y-r.min.y);
250 vncwrpoint(Vnc *v, Point p)
269 hexdump(void *a, int n)
282 vncgobble(Vnc *v, long n)
291 vncrdbytes(v, buf, m);