2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2015 Tycho Nightingale <tycho.nightingale@pluribusnetworks.com>
5 * Copyright (c) 2015 Leon Dang
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #ifndef WITHOUT_CAPSICUM
35 #include <sys/capsicum.h>
37 #include <sys/endian.h>
38 #include <sys/socket.h>
39 #include <sys/select.h>
41 #include <arpa/inet.h>
42 #include <machine/cpufunc.h>
43 #include <machine/specialreg.h>
44 #include <netinet/in.h>
50 #include <pthread_np.h>
64 #include "sockstream.h"
67 #include <openssl/des.h>
70 static int rfb_debug = 0;
71 #define DPRINTF(params) if (rfb_debug) printf params
72 #define WPRINTF(params) printf params
74 #define AUTH_LENGTH 16
75 #define PASSWD_LENGTH 8
77 #define SECURITY_TYPE_NONE 1
78 #define SECURITY_TYPE_VNC_AUTH 2
80 #define AUTH_FAILED_UNAUTH 1
81 #define AUTH_FAILED_ERROR 2
107 uint32_t *crc; /* WxH crc cells */
108 uint32_t *crc_tmp; /* buffer to store single crc row */
109 int crc_width, crc_height;
126 struct rfb_srvr_info {
129 struct rfb_pixfmt pixfmt;
133 struct rfb_pixfmt_msg {
136 struct rfb_pixfmt pixfmt;
139 #define RFB_ENCODING_RAW 0
140 #define RFB_ENCODING_ZLIB 6
141 #define RFB_ENCODING_RESIZE -223
143 #define RFB_MAX_WIDTH 2000
144 #define RFB_MAX_HEIGHT 1200
145 #define RFB_ZLIB_BUFSZ RFB_MAX_WIDTH*RFB_MAX_HEIGHT*4
147 /* percentage changes to screen before sending the entire screen */
148 #define RFB_SEND_ALL_THRESH 25
156 struct rfb_updt_msg {
179 struct rfb_srvr_updt_msg {
185 struct rfb_srvr_rect_hdr {
193 struct rfb_cuttext_msg {
201 rfb_send_server_init_msg(int cfd)
203 struct bhyvegc_image *gc_image;
204 struct rfb_srvr_info sinfo;
206 gc_image = console_get_image();
208 sinfo.width = htons(gc_image->width);
209 sinfo.height = htons(gc_image->height);
210 sinfo.pixfmt.bpp = 32;
211 sinfo.pixfmt.depth = 32;
212 sinfo.pixfmt.bigendian = 0;
213 sinfo.pixfmt.truecolor = 1;
214 sinfo.pixfmt.red_max = htons(255);
215 sinfo.pixfmt.green_max = htons(255);
216 sinfo.pixfmt.blue_max = htons(255);
217 sinfo.pixfmt.red_shift = 16;
218 sinfo.pixfmt.green_shift = 8;
219 sinfo.pixfmt.blue_shift = 0;
220 sinfo.namelen = htonl(strlen("bhyve"));
221 (void)stream_write(cfd, &sinfo, sizeof(sinfo));
222 (void)stream_write(cfd, "bhyve", strlen("bhyve"));
226 rfb_send_resize_update_msg(struct rfb_softc *rc, int cfd)
228 struct rfb_srvr_updt_msg supdt_msg;
229 struct rfb_srvr_rect_hdr srect_hdr;
231 /* Number of rectangles: 1 */
234 supdt_msg.numrects = htons(1);
235 stream_write(cfd, &supdt_msg, sizeof(struct rfb_srvr_updt_msg));
237 /* Rectangle header */
238 srect_hdr.x = htons(0);
239 srect_hdr.y = htons(0);
240 srect_hdr.width = htons(rc->width);
241 srect_hdr.height = htons(rc->height);
242 srect_hdr.encoding = htonl(RFB_ENCODING_RESIZE);
243 stream_write(cfd, &srect_hdr, sizeof(struct rfb_srvr_rect_hdr));
247 rfb_recv_set_pixfmt_msg(struct rfb_softc *rc, int cfd)
249 struct rfb_pixfmt_msg pixfmt_msg;
251 (void)stream_read(cfd, ((void *)&pixfmt_msg)+1, sizeof(pixfmt_msg)-1);
256 rfb_recv_set_encodings_msg(struct rfb_softc *rc, int cfd)
258 struct rfb_enc_msg enc_msg;
262 assert((sizeof(enc_msg) - 1) == 3);
263 (void)stream_read(cfd, ((void *)&enc_msg)+1, sizeof(enc_msg)-1);
265 for (i = 0; i < htons(enc_msg.numencs); i++) {
266 (void)stream_read(cfd, &encoding, sizeof(encoding));
267 switch (htonl(encoding)) {
268 case RFB_ENCODING_RAW:
269 rc->enc_raw_ok = true;
271 case RFB_ENCODING_ZLIB:
272 rc->enc_zlib_ok = true;
273 deflateInit(&rc->zstream, Z_BEST_SPEED);
275 case RFB_ENCODING_RESIZE:
276 rc->enc_resize_ok = true;
283 * Calculate CRC32 using SSE4.2; Intel or AMD Bulldozer+ CPUs only
285 static __inline uint32_t
286 fast_crc32(void *buf, int len, uint32_t crcval)
288 uint32_t q = len / sizeof(uint32_t);
289 uint32_t *p = (uint32_t *)buf;
293 ".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;"
295 :"0" (crcval), "c" (*p)
305 rfb_send_rect(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc,
306 int x, int y, int w, int h)
308 struct rfb_srvr_updt_msg supdt_msg;
309 struct rfb_srvr_rect_hdr srect_hdr;
311 ssize_t nwrite, total;
317 * Send a single rectangle of the given x, y, w h dimensions.
320 /* Number of rectangles: 1 */
323 supdt_msg.numrects = htons(1);
324 nwrite = stream_write(cfd, &supdt_msg,
325 sizeof(struct rfb_srvr_updt_msg));
330 /* Rectangle header */
331 srect_hdr.x = htons(x);
332 srect_hdr.y = htons(y);
333 srect_hdr.width = htons(w);
334 srect_hdr.height = htons(h);
337 w *= sizeof(uint32_t);
338 if (rc->enc_zlib_ok) {
340 rc->zstream.total_in = 0;
341 rc->zstream.total_out = 0;
342 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
343 rc->zstream.next_in = (Bytef *)p;
344 rc->zstream.avail_in = w;
345 rc->zstream.next_out = (Bytef *)zbufp;
346 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16 -
347 rc->zstream.total_out;
348 rc->zstream.data_type = Z_BINARY;
350 /* Compress with zlib */
351 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
353 WPRINTF(("zlib[rect] deflate err: %d\n", err));
354 rc->enc_zlib_ok = false;
355 deflateEnd(&rc->zstream);
358 zbufp = rc->zbuf + rc->zstream.total_out;
361 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
362 nwrite = stream_write(cfd, &srect_hdr,
363 sizeof(struct rfb_srvr_rect_hdr));
367 zlen = htonl(rc->zstream.total_out);
368 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
371 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
378 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
385 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
386 nwrite = stream_write(cfd, &srect_hdr,
387 sizeof(struct rfb_srvr_rect_hdr));
391 total = stream_write(cfd, rc->zbuf, total);
397 rfb_send_all(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc)
399 struct rfb_srvr_updt_msg supdt_msg;
400 struct rfb_srvr_rect_hdr srect_hdr;
406 * Send the whole thing
409 /* Number of rectangles: 1 */
412 supdt_msg.numrects = htons(1);
413 nwrite = stream_write(cfd, &supdt_msg,
414 sizeof(struct rfb_srvr_updt_msg));
418 /* Rectangle header */
421 srect_hdr.width = htons(gc->width);
422 srect_hdr.height = htons(gc->height);
423 if (rc->enc_zlib_ok) {
424 rc->zstream.next_in = (Bytef *)gc->data;
425 rc->zstream.avail_in = gc->width * gc->height *
427 rc->zstream.next_out = (Bytef *)rc->zbuf;
428 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16;
429 rc->zstream.data_type = Z_BINARY;
431 rc->zstream.total_in = 0;
432 rc->zstream.total_out = 0;
434 /* Compress with zlib */
435 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
437 WPRINTF(("zlib deflate err: %d\n", err));
438 rc->enc_zlib_ok = false;
439 deflateEnd(&rc->zstream);
443 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
444 nwrite = stream_write(cfd, &srect_hdr,
445 sizeof(struct rfb_srvr_rect_hdr));
449 zlen = htonl(rc->zstream.total_out);
450 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
453 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
457 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
458 nwrite = stream_write(cfd, &srect_hdr,
459 sizeof(struct rfb_srvr_rect_hdr));
463 nwrite = stream_write(cfd, gc->data,
464 gc->width * gc->height * sizeof(uint32_t));
469 #define PIX_PER_CELL 32
470 #define PIXCELL_SHIFT 5
471 #define PIXCELL_MASK 0x1F
474 rfb_send_screen(struct rfb_softc *rc, int cfd, int all)
476 struct bhyvegc_image *gc_image;
479 int celly, cellwidth;
483 int rem_x, rem_y; /* remainder for resolutions not x32 pixels ratio */
485 uint32_t *crc_p, *orig_crc;
489 gc_image = console_get_image();
491 pthread_mutex_lock(&rc->mtx);
493 pthread_mutex_unlock(&rc->mtx);
497 pthread_mutex_unlock(&rc->mtx);
502 retval = rfb_send_all(rc, cfd, gc_image);
507 * Calculate the checksum for each 32x32 cell. Send each that
508 * has changed since the last scan.
511 /* Resolution changed */
513 rc->crc_width = gc_image->width;
514 rc->crc_height = gc_image->height;
518 xcells = howmany(rc->crc_width, PIX_PER_CELL);
519 ycells = howmany(rc->crc_height, PIX_PER_CELL);
521 rem_x = w & PIXCELL_MASK;
523 rem_y = h & PIXCELL_MASK;
525 rem_y = PIX_PER_CELL;
530 * Go through all cells and calculate crc. If significant number
531 * of changes, then send entire screen.
532 * crc_tmp is dual purpose: to store the new crc and to flag as
533 * a cell that has changed.
535 crc_p = rc->crc_tmp - xcells;
536 orig_crc = rc->crc - xcells;
538 memset(rc->crc_tmp, 0, sizeof(uint32_t) * xcells * ycells);
539 for (y = 0; y < h; y++) {
540 if ((y & PIXCELL_MASK) == 0) {
545 for (x = 0; x < xcells; x++) {
546 if (x == (xcells - 1) && rem_x > 0)
549 cellwidth = PIX_PER_CELL;
552 crc_p[x] = fast_crc32(p,
553 cellwidth * sizeof(uint32_t),
556 crc_p[x] = (uint32_t)crc32(crc_p[x],
558 cellwidth * sizeof(uint32_t));
562 /* check for crc delta if last row in cell */
563 if ((y & PIXCELL_MASK) == PIXCELL_MASK || y == (h-1)) {
564 if (orig_crc[x] != crc_p[x]) {
565 orig_crc[x] = crc_p[x];
575 /* If number of changes is > THRESH percent, send the whole screen */
576 if (((changes * 100) / (xcells * ycells)) >= RFB_SEND_ALL_THRESH) {
577 retval = rfb_send_all(rc, cfd, gc_image);
581 /* Go through all cells, and send only changed ones */
583 for (y = 0; y < h; y += PIX_PER_CELL) {
584 /* previous cell's row */
585 celly = (y >> PIXCELL_SHIFT);
587 /* Delta check crc to previous set */
588 for (x = 0; x < xcells; x++) {
592 if (x == (xcells - 1) && rem_x > 0)
595 cellwidth = PIX_PER_CELL;
596 nwrite = rfb_send_rect(rc, cfd,
599 celly * PIX_PER_CELL,
601 y + PIX_PER_CELL >= h ? rem_y : PIX_PER_CELL);
611 pthread_mutex_lock(&rc->mtx);
613 pthread_mutex_unlock(&rc->mtx);
620 rfb_recv_update_msg(struct rfb_softc *rc, int cfd, int discardonly)
622 struct rfb_updt_msg updt_msg;
623 struct bhyvegc_image *gc_image;
625 (void)stream_read(cfd, ((void *)&updt_msg) + 1 , sizeof(updt_msg) - 1);
628 gc_image = console_get_image();
630 updt_msg.x = htons(updt_msg.x);
631 updt_msg.y = htons(updt_msg.y);
632 updt_msg.width = htons(updt_msg.width);
633 updt_msg.height = htons(updt_msg.height);
635 if (updt_msg.width != gc_image->width ||
636 updt_msg.height != gc_image->height) {
637 rc->width = gc_image->width;
638 rc->height = gc_image->height;
639 if (rc->enc_resize_ok)
640 rfb_send_resize_update_msg(rc, cfd);
646 rfb_send_screen(rc, cfd, 1);
650 rfb_recv_key_msg(struct rfb_softc *rc, int cfd)
652 struct rfb_key_msg key_msg;
654 (void)stream_read(cfd, ((void *)&key_msg) + 1, sizeof(key_msg) - 1);
656 console_key_event(key_msg.down, htonl(key_msg.code));
660 rfb_recv_ptr_msg(struct rfb_softc *rc, int cfd)
662 struct rfb_ptr_msg ptr_msg;
664 (void)stream_read(cfd, ((void *)&ptr_msg) + 1, sizeof(ptr_msg) - 1);
666 console_ptr_event(ptr_msg.button, htons(ptr_msg.x), htons(ptr_msg.y));
670 rfb_recv_cuttext_msg(struct rfb_softc *rc, int cfd)
672 struct rfb_cuttext_msg ct_msg;
673 unsigned char buf[32];
676 len = stream_read(cfd, ((void *)&ct_msg) + 1, sizeof(ct_msg) - 1);
677 ct_msg.length = htonl(ct_msg.length);
678 while (ct_msg.length > 0) {
679 len = stream_read(cfd, buf, ct_msg.length > sizeof(buf) ?
680 sizeof(buf) : ct_msg.length);
681 ct_msg.length -= len;
686 timeval_delta(struct timeval *prev, struct timeval *now)
689 n1 = now->tv_sec * 1000000 + now->tv_usec;
690 n2 = prev->tv_sec * 1000000 + prev->tv_usec;
695 rfb_wr_thr(void *arg)
697 struct rfb_softc *rc;
700 struct timeval prev_tv;
710 while (rc->cfd >= 0) {
716 err = select(cfd+1, &rfds, NULL, NULL, &tv);
720 /* Determine if its time to push screen; ~24hz */
721 gettimeofday(&tv, NULL);
722 tdiff = timeval_delta(&prev_tv, &tv);
724 prev_tv.tv_sec = tv.tv_sec;
725 prev_tv.tv_usec = tv.tv_usec;
726 if (rfb_send_screen(rc, cfd, 0) <= 0) {
731 usleep(40000 - tdiff);
739 rfb_handle(struct rfb_softc *rc, int cfd)
741 const char *vbuf = "RFB 003.008\n";
742 unsigned char buf[80];
743 unsigned char *message = NULL;
746 unsigned char challenge[AUTH_LENGTH];
747 unsigned char keystr[PASSWD_LENGTH];
748 unsigned char crypt_expected[AUTH_LENGTH];
761 /* 1a. Send server version */
762 stream_write(cfd, vbuf, strlen(vbuf));
764 /* 1b. Read client version */
765 len = read(cfd, buf, sizeof(buf));
767 /* 2a. Send security type */
771 buf[1] = SECURITY_TYPE_VNC_AUTH;
773 buf[1] = SECURITY_TYPE_NONE;
775 buf[1] = SECURITY_TYPE_NONE;
778 stream_write(cfd, buf, 2);
780 /* 2b. Read agreed security type */
781 len = stream_read(cfd, buf, 1);
783 /* 2c. Do VNC authentication */
785 case SECURITY_TYPE_NONE:
788 case SECURITY_TYPE_VNC_AUTH:
790 * The client encrypts the challenge with DES, using a password
791 * supplied by the user as the key.
792 * To form the key, the password is truncated to
793 * eight characters, or padded with null bytes on the right.
794 * The client then sends the resulting 16-bytes response.
797 strncpy(keystr, rc->password, PASSWD_LENGTH);
799 /* VNC clients encrypts the challenge with all the bit fields
800 * in each byte of the password mirrored.
801 * Here we flip each byte of the keystr.
803 for (i = 0; i < PASSWD_LENGTH; i++) {
804 keystr[i] = (keystr[i] & 0xF0) >> 4
805 | (keystr[i] & 0x0F) << 4;
806 keystr[i] = (keystr[i] & 0xCC) >> 2
807 | (keystr[i] & 0x33) << 2;
808 keystr[i] = (keystr[i] & 0xAA) >> 1
809 | (keystr[i] & 0x55) << 1;
812 /* Initialize a 16-byte random challenge */
813 arc4random_buf(challenge, sizeof(challenge));
814 stream_write(cfd, challenge, AUTH_LENGTH);
816 /* Receive the 16-byte challenge response */
817 stream_read(cfd, buf, AUTH_LENGTH);
819 memcpy(crypt_expected, challenge, AUTH_LENGTH);
821 /* Encrypt the Challenge with DES */
822 DES_set_key((const_DES_cblock *)keystr, &ks);
823 DES_ecb_encrypt((const_DES_cblock *)challenge,
824 (const_DES_cblock *)crypt_expected,
826 DES_ecb_encrypt((const_DES_cblock *)(challenge + PASSWD_LENGTH),
827 (const_DES_cblock *)(crypt_expected +
831 if (memcmp(crypt_expected, buf, AUTH_LENGTH) != 0) {
832 message = "Auth Failed: Invalid Password.";
838 WPRINTF(("Auth not supported, no OpenSSL in your system"));
844 /* 2d. Write back a status */
845 stream_write(cfd, &sres, 4);
848 be32enc(buf, strlen(message));
849 stream_write(cfd, buf, 4);
850 stream_write(cfd, message, strlen(message));
854 /* 3a. Read client shared-flag byte */
855 len = stream_read(cfd, buf, 1);
857 /* 4a. Write server-init info */
858 rfb_send_server_init_msg(cfd);
861 rc->zbuf = malloc(RFB_ZLIB_BUFSZ + 16);
862 assert(rc->zbuf != NULL);
865 rfb_send_screen(rc, cfd, 1);
867 perror = pthread_create(&tid, NULL, rfb_wr_thr, rc);
869 pthread_set_name_np(tid, "rfbout");
871 /* Now read in client requests. 1st byte identifies type */
873 len = read(cfd, buf, 1);
875 DPRINTF(("rfb client exiting\r\n"));
881 rfb_recv_set_pixfmt_msg(rc, cfd);
884 rfb_recv_set_encodings_msg(rc, cfd);
887 rfb_recv_update_msg(rc, cfd, 1);
890 rfb_recv_key_msg(rc, cfd);
893 rfb_recv_ptr_msg(rc, cfd);
896 rfb_recv_cuttext_msg(rc, cfd);
899 WPRINTF(("rfb unknown cli-code %d!\n", buf[0] & 0xff));
906 pthread_join(tid, NULL);
908 deflateEnd(&rc->zstream);
914 struct rfb_softc *rc;
922 sigaddset(&set, SIGPIPE);
923 if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0) {
924 perror("pthread_sigmask");
929 rc->enc_raw_ok = false;
930 rc->enc_zlib_ok = false;
931 rc->enc_resize_ok = false;
933 cfd = accept(rc->sfd, NULL, NULL);
935 pthread_mutex_lock(&rc->mtx);
936 pthread_cond_signal(&rc->cond);
937 pthread_mutex_unlock(&rc->mtx);
949 sse42_supported(void)
951 u_int cpu_registers[4], ecx;
953 do_cpuid(1, cpu_registers);
955 ecx = cpu_registers[2];
957 return ((ecx & CPUID2_SSE42) != 0);
961 rfb_init(char *hostname, int port, int wait, char *password)
963 struct rfb_softc *rc;
964 struct sockaddr_in sin;
966 #ifndef WITHOUT_CAPSICUM
970 rc = calloc(1, sizeof(struct rfb_softc));
972 rc->crc = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
974 rc->crc_tmp = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
976 rc->crc_width = RFB_MAX_WIDTH;
977 rc->crc_height = RFB_MAX_HEIGHT;
979 rc->password = password;
981 rc->sfd = socket(AF_INET, SOCK_STREAM, 0);
987 setsockopt(rc->sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
989 sin.sin_len = sizeof(sin);
990 sin.sin_family = AF_INET;
991 sin.sin_port = port ? htons(port) : htons(5900);
992 if (hostname && strlen(hostname) > 0)
993 inet_pton(AF_INET, hostname, &(sin.sin_addr));
995 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
997 if (bind(rc->sfd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
1002 if (listen(rc->sfd, 1) < 0) {
1007 #ifndef WITHOUT_CAPSICUM
1008 cap_rights_init(&rights, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE);
1009 if (cap_rights_limit(rc->sfd, &rights) == -1 && errno != ENOSYS)
1010 errx(EX_OSERR, "Unable to apply rights for sandbox");
1013 rc->hw_crc = sse42_supported();
1015 rc->conn_wait = wait;
1017 pthread_mutex_init(&rc->mtx, NULL);
1018 pthread_cond_init(&rc->cond, NULL);
1021 pthread_create(&rc->tid, NULL, rfb_thr, rc);
1022 pthread_set_name_np(rc->tid, "rfb");
1025 DPRINTF(("Waiting for rfb client...\n"));
1026 pthread_mutex_lock(&rc->mtx);
1027 pthread_cond_wait(&rc->cond, &rc->mtx);
1028 pthread_mutex_unlock(&rc->mtx);