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>
48 #ifndef WITHOUT_CAPSICUM
49 #include <capsicum_helpers.h>
54 #include <pthread_np.h>
68 #include "sockstream.h"
71 #include <openssl/des.h>
74 static int rfb_debug = 0;
75 #define DPRINTF(params) if (rfb_debug) printf params
76 #define WPRINTF(params) printf params
78 #define AUTH_LENGTH 16
79 #define PASSWD_LENGTH 8
81 #define SECURITY_TYPE_NONE 1
82 #define SECURITY_TYPE_VNC_AUTH 2
84 #define AUTH_FAILED_UNAUTH 1
85 #define AUTH_FAILED_ERROR 2
111 uint32_t *crc; /* WxH crc cells */
112 uint32_t *crc_tmp; /* buffer to store single crc row */
113 int crc_width, crc_height;
130 struct rfb_srvr_info {
133 struct rfb_pixfmt pixfmt;
137 struct rfb_pixfmt_msg {
140 struct rfb_pixfmt pixfmt;
143 #define RFB_ENCODING_RAW 0
144 #define RFB_ENCODING_ZLIB 6
145 #define RFB_ENCODING_RESIZE -223
147 #define RFB_MAX_WIDTH 2000
148 #define RFB_MAX_HEIGHT 1200
149 #define RFB_ZLIB_BUFSZ RFB_MAX_WIDTH*RFB_MAX_HEIGHT*4
151 /* percentage changes to screen before sending the entire screen */
152 #define RFB_SEND_ALL_THRESH 25
160 struct rfb_updt_msg {
183 struct rfb_srvr_updt_msg {
189 struct rfb_srvr_rect_hdr {
197 struct rfb_cuttext_msg {
205 rfb_send_server_init_msg(int cfd)
207 struct bhyvegc_image *gc_image;
208 struct rfb_srvr_info sinfo;
210 gc_image = console_get_image();
212 sinfo.width = htons(gc_image->width);
213 sinfo.height = htons(gc_image->height);
214 sinfo.pixfmt.bpp = 32;
215 sinfo.pixfmt.depth = 32;
216 sinfo.pixfmt.bigendian = 0;
217 sinfo.pixfmt.truecolor = 1;
218 sinfo.pixfmt.red_max = htons(255);
219 sinfo.pixfmt.green_max = htons(255);
220 sinfo.pixfmt.blue_max = htons(255);
221 sinfo.pixfmt.red_shift = 16;
222 sinfo.pixfmt.green_shift = 8;
223 sinfo.pixfmt.blue_shift = 0;
224 sinfo.namelen = htonl(strlen("bhyve"));
225 (void)stream_write(cfd, &sinfo, sizeof(sinfo));
226 (void)stream_write(cfd, "bhyve", strlen("bhyve"));
230 rfb_send_resize_update_msg(struct rfb_softc *rc, int cfd)
232 struct rfb_srvr_updt_msg supdt_msg;
233 struct rfb_srvr_rect_hdr srect_hdr;
235 /* Number of rectangles: 1 */
238 supdt_msg.numrects = htons(1);
239 stream_write(cfd, &supdt_msg, sizeof(struct rfb_srvr_updt_msg));
241 /* Rectangle header */
242 srect_hdr.x = htons(0);
243 srect_hdr.y = htons(0);
244 srect_hdr.width = htons(rc->width);
245 srect_hdr.height = htons(rc->height);
246 srect_hdr.encoding = htonl(RFB_ENCODING_RESIZE);
247 stream_write(cfd, &srect_hdr, sizeof(struct rfb_srvr_rect_hdr));
251 rfb_recv_set_pixfmt_msg(struct rfb_softc *rc, int cfd)
253 struct rfb_pixfmt_msg pixfmt_msg;
255 (void)stream_read(cfd, ((void *)&pixfmt_msg)+1, sizeof(pixfmt_msg)-1);
260 rfb_recv_set_encodings_msg(struct rfb_softc *rc, int cfd)
262 struct rfb_enc_msg enc_msg;
266 assert((sizeof(enc_msg) - 1) == 3);
267 (void)stream_read(cfd, ((void *)&enc_msg)+1, sizeof(enc_msg)-1);
269 for (i = 0; i < htons(enc_msg.numencs); i++) {
270 (void)stream_read(cfd, &encoding, sizeof(encoding));
271 switch (htonl(encoding)) {
272 case RFB_ENCODING_RAW:
273 rc->enc_raw_ok = true;
275 case RFB_ENCODING_ZLIB:
276 if (!rc->enc_zlib_ok) {
277 deflateInit(&rc->zstream, Z_BEST_SPEED);
278 rc->enc_zlib_ok = true;
281 case RFB_ENCODING_RESIZE:
282 rc->enc_resize_ok = true;
289 * Calculate CRC32 using SSE4.2; Intel or AMD Bulldozer+ CPUs only
291 static __inline uint32_t
292 fast_crc32(void *buf, int len, uint32_t crcval)
294 uint32_t q = len / sizeof(uint32_t);
295 uint32_t *p = (uint32_t *)buf;
299 ".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;"
301 :"0" (crcval), "c" (*p)
311 rfb_send_rect(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc,
312 int x, int y, int w, int h)
314 struct rfb_srvr_updt_msg supdt_msg;
315 struct rfb_srvr_rect_hdr srect_hdr;
317 ssize_t nwrite, total;
323 * Send a single rectangle of the given x, y, w h dimensions.
326 /* Number of rectangles: 1 */
329 supdt_msg.numrects = htons(1);
330 nwrite = stream_write(cfd, &supdt_msg,
331 sizeof(struct rfb_srvr_updt_msg));
336 /* Rectangle header */
337 srect_hdr.x = htons(x);
338 srect_hdr.y = htons(y);
339 srect_hdr.width = htons(w);
340 srect_hdr.height = htons(h);
343 w *= sizeof(uint32_t);
344 if (rc->enc_zlib_ok) {
346 rc->zstream.total_in = 0;
347 rc->zstream.total_out = 0;
348 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
349 rc->zstream.next_in = (Bytef *)p;
350 rc->zstream.avail_in = w;
351 rc->zstream.next_out = (Bytef *)zbufp;
352 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16 -
353 rc->zstream.total_out;
354 rc->zstream.data_type = Z_BINARY;
356 /* Compress with zlib */
357 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
359 WPRINTF(("zlib[rect] deflate err: %d\n", err));
360 rc->enc_zlib_ok = false;
361 deflateEnd(&rc->zstream);
364 zbufp = rc->zbuf + rc->zstream.total_out;
367 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
368 nwrite = stream_write(cfd, &srect_hdr,
369 sizeof(struct rfb_srvr_rect_hdr));
373 zlen = htonl(rc->zstream.total_out);
374 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
377 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
384 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
391 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
392 nwrite = stream_write(cfd, &srect_hdr,
393 sizeof(struct rfb_srvr_rect_hdr));
397 total = stream_write(cfd, rc->zbuf, total);
403 rfb_send_all(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc)
405 struct rfb_srvr_updt_msg supdt_msg;
406 struct rfb_srvr_rect_hdr srect_hdr;
412 * Send the whole thing
415 /* Number of rectangles: 1 */
418 supdt_msg.numrects = htons(1);
419 nwrite = stream_write(cfd, &supdt_msg,
420 sizeof(struct rfb_srvr_updt_msg));
424 /* Rectangle header */
427 srect_hdr.width = htons(gc->width);
428 srect_hdr.height = htons(gc->height);
429 if (rc->enc_zlib_ok) {
430 rc->zstream.next_in = (Bytef *)gc->data;
431 rc->zstream.avail_in = gc->width * gc->height *
433 rc->zstream.next_out = (Bytef *)rc->zbuf;
434 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16;
435 rc->zstream.data_type = Z_BINARY;
437 rc->zstream.total_in = 0;
438 rc->zstream.total_out = 0;
440 /* Compress with zlib */
441 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
443 WPRINTF(("zlib deflate err: %d\n", err));
444 rc->enc_zlib_ok = false;
445 deflateEnd(&rc->zstream);
449 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
450 nwrite = stream_write(cfd, &srect_hdr,
451 sizeof(struct rfb_srvr_rect_hdr));
455 zlen = htonl(rc->zstream.total_out);
456 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
459 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
463 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
464 nwrite = stream_write(cfd, &srect_hdr,
465 sizeof(struct rfb_srvr_rect_hdr));
469 nwrite = stream_write(cfd, gc->data,
470 gc->width * gc->height * sizeof(uint32_t));
475 #define PIX_PER_CELL 32
476 #define PIXCELL_SHIFT 5
477 #define PIXCELL_MASK 0x1F
480 rfb_send_screen(struct rfb_softc *rc, int cfd, int all)
482 struct bhyvegc_image *gc_image;
485 int celly, cellwidth;
489 int rem_x, rem_y; /* remainder for resolutions not x32 pixels ratio */
491 uint32_t *crc_p, *orig_crc;
495 gc_image = console_get_image();
497 pthread_mutex_lock(&rc->mtx);
499 pthread_mutex_unlock(&rc->mtx);
503 pthread_mutex_unlock(&rc->mtx);
508 retval = rfb_send_all(rc, cfd, gc_image);
513 * Calculate the checksum for each 32x32 cell. Send each that
514 * has changed since the last scan.
517 /* Resolution changed */
519 rc->crc_width = gc_image->width;
520 rc->crc_height = gc_image->height;
524 xcells = howmany(rc->crc_width, PIX_PER_CELL);
525 ycells = howmany(rc->crc_height, PIX_PER_CELL);
527 rem_x = w & PIXCELL_MASK;
529 rem_y = h & PIXCELL_MASK;
531 rem_y = PIX_PER_CELL;
536 * Go through all cells and calculate crc. If significant number
537 * of changes, then send entire screen.
538 * crc_tmp is dual purpose: to store the new crc and to flag as
539 * a cell that has changed.
541 crc_p = rc->crc_tmp - xcells;
542 orig_crc = rc->crc - xcells;
544 memset(rc->crc_tmp, 0, sizeof(uint32_t) * xcells * ycells);
545 for (y = 0; y < h; y++) {
546 if ((y & PIXCELL_MASK) == 0) {
551 for (x = 0; x < xcells; x++) {
552 if (x == (xcells - 1) && rem_x > 0)
555 cellwidth = PIX_PER_CELL;
558 crc_p[x] = fast_crc32(p,
559 cellwidth * sizeof(uint32_t),
562 crc_p[x] = (uint32_t)crc32(crc_p[x],
564 cellwidth * sizeof(uint32_t));
568 /* check for crc delta if last row in cell */
569 if ((y & PIXCELL_MASK) == PIXCELL_MASK || y == (h-1)) {
570 if (orig_crc[x] != crc_p[x]) {
571 orig_crc[x] = crc_p[x];
581 /* If number of changes is > THRESH percent, send the whole screen */
582 if (((changes * 100) / (xcells * ycells)) >= RFB_SEND_ALL_THRESH) {
583 retval = rfb_send_all(rc, cfd, gc_image);
587 /* Go through all cells, and send only changed ones */
589 for (y = 0; y < h; y += PIX_PER_CELL) {
590 /* previous cell's row */
591 celly = (y >> PIXCELL_SHIFT);
593 /* Delta check crc to previous set */
594 for (x = 0; x < xcells; x++) {
598 if (x == (xcells - 1) && rem_x > 0)
601 cellwidth = PIX_PER_CELL;
602 nwrite = rfb_send_rect(rc, cfd,
605 celly * PIX_PER_CELL,
607 y + PIX_PER_CELL >= h ? rem_y : PIX_PER_CELL);
617 pthread_mutex_lock(&rc->mtx);
619 pthread_mutex_unlock(&rc->mtx);
626 rfb_recv_update_msg(struct rfb_softc *rc, int cfd, int discardonly)
628 struct rfb_updt_msg updt_msg;
629 struct bhyvegc_image *gc_image;
631 (void)stream_read(cfd, ((void *)&updt_msg) + 1 , sizeof(updt_msg) - 1);
634 gc_image = console_get_image();
636 updt_msg.x = htons(updt_msg.x);
637 updt_msg.y = htons(updt_msg.y);
638 updt_msg.width = htons(updt_msg.width);
639 updt_msg.height = htons(updt_msg.height);
641 if (updt_msg.width != gc_image->width ||
642 updt_msg.height != gc_image->height) {
643 rc->width = gc_image->width;
644 rc->height = gc_image->height;
645 if (rc->enc_resize_ok)
646 rfb_send_resize_update_msg(rc, cfd);
652 rfb_send_screen(rc, cfd, 1);
656 rfb_recv_key_msg(struct rfb_softc *rc, int cfd)
658 struct rfb_key_msg key_msg;
660 (void)stream_read(cfd, ((void *)&key_msg) + 1, sizeof(key_msg) - 1);
662 console_key_event(key_msg.down, htonl(key_msg.code));
666 rfb_recv_ptr_msg(struct rfb_softc *rc, int cfd)
668 struct rfb_ptr_msg ptr_msg;
670 (void)stream_read(cfd, ((void *)&ptr_msg) + 1, sizeof(ptr_msg) - 1);
672 console_ptr_event(ptr_msg.button, htons(ptr_msg.x), htons(ptr_msg.y));
676 rfb_recv_cuttext_msg(struct rfb_softc *rc, int cfd)
678 struct rfb_cuttext_msg ct_msg;
679 unsigned char buf[32];
682 len = stream_read(cfd, ((void *)&ct_msg) + 1, sizeof(ct_msg) - 1);
683 ct_msg.length = htonl(ct_msg.length);
684 while (ct_msg.length > 0) {
685 len = stream_read(cfd, buf, ct_msg.length > sizeof(buf) ?
686 sizeof(buf) : ct_msg.length);
687 ct_msg.length -= len;
692 timeval_delta(struct timeval *prev, struct timeval *now)
695 n1 = now->tv_sec * 1000000 + now->tv_usec;
696 n2 = prev->tv_sec * 1000000 + prev->tv_usec;
701 rfb_wr_thr(void *arg)
703 struct rfb_softc *rc;
706 struct timeval prev_tv;
716 while (rc->cfd >= 0) {
722 err = select(cfd+1, &rfds, NULL, NULL, &tv);
726 /* Determine if its time to push screen; ~24hz */
727 gettimeofday(&tv, NULL);
728 tdiff = timeval_delta(&prev_tv, &tv);
730 prev_tv.tv_sec = tv.tv_sec;
731 prev_tv.tv_usec = tv.tv_usec;
732 if (rfb_send_screen(rc, cfd, 0) <= 0) {
737 usleep(40000 - tdiff);
745 rfb_handle(struct rfb_softc *rc, int cfd)
747 const char *vbuf = "RFB 003.008\n";
748 unsigned char buf[80];
749 unsigned char *message = NULL;
752 unsigned char challenge[AUTH_LENGTH];
753 unsigned char keystr[PASSWD_LENGTH];
754 unsigned char crypt_expected[AUTH_LENGTH];
767 /* 1a. Send server version */
768 stream_write(cfd, vbuf, strlen(vbuf));
770 /* 1b. Read client version */
771 len = read(cfd, buf, sizeof(buf));
773 /* 2a. Send security type */
777 buf[1] = SECURITY_TYPE_VNC_AUTH;
779 buf[1] = SECURITY_TYPE_NONE;
781 buf[1] = SECURITY_TYPE_NONE;
784 stream_write(cfd, buf, 2);
786 /* 2b. Read agreed security type */
787 len = stream_read(cfd, buf, 1);
789 /* 2c. Do VNC authentication */
791 case SECURITY_TYPE_NONE:
794 case SECURITY_TYPE_VNC_AUTH:
796 * The client encrypts the challenge with DES, using a password
797 * supplied by the user as the key.
798 * To form the key, the password is truncated to
799 * eight characters, or padded with null bytes on the right.
800 * The client then sends the resulting 16-bytes response.
803 strncpy(keystr, rc->password, PASSWD_LENGTH);
805 /* VNC clients encrypts the challenge with all the bit fields
806 * in each byte of the password mirrored.
807 * Here we flip each byte of the keystr.
809 for (i = 0; i < PASSWD_LENGTH; i++) {
810 keystr[i] = (keystr[i] & 0xF0) >> 4
811 | (keystr[i] & 0x0F) << 4;
812 keystr[i] = (keystr[i] & 0xCC) >> 2
813 | (keystr[i] & 0x33) << 2;
814 keystr[i] = (keystr[i] & 0xAA) >> 1
815 | (keystr[i] & 0x55) << 1;
818 /* Initialize a 16-byte random challenge */
819 arc4random_buf(challenge, sizeof(challenge));
820 stream_write(cfd, challenge, AUTH_LENGTH);
822 /* Receive the 16-byte challenge response */
823 stream_read(cfd, buf, AUTH_LENGTH);
825 memcpy(crypt_expected, challenge, AUTH_LENGTH);
827 /* Encrypt the Challenge with DES */
828 DES_set_key((const_DES_cblock *)keystr, &ks);
829 DES_ecb_encrypt((const_DES_cblock *)challenge,
830 (const_DES_cblock *)crypt_expected,
832 DES_ecb_encrypt((const_DES_cblock *)(challenge + PASSWD_LENGTH),
833 (const_DES_cblock *)(crypt_expected +
837 if (memcmp(crypt_expected, buf, AUTH_LENGTH) != 0) {
838 message = "Auth Failed: Invalid Password.";
844 WPRINTF(("Auth not supported, no OpenSSL in your system"));
850 /* 2d. Write back a status */
851 stream_write(cfd, &sres, 4);
854 be32enc(buf, strlen(message));
855 stream_write(cfd, buf, 4);
856 stream_write(cfd, message, strlen(message));
860 /* 3a. Read client shared-flag byte */
861 len = stream_read(cfd, buf, 1);
863 /* 4a. Write server-init info */
864 rfb_send_server_init_msg(cfd);
867 rc->zbuf = malloc(RFB_ZLIB_BUFSZ + 16);
868 assert(rc->zbuf != NULL);
871 rfb_send_screen(rc, cfd, 1);
873 perror = pthread_create(&tid, NULL, rfb_wr_thr, rc);
875 pthread_set_name_np(tid, "rfbout");
877 /* Now read in client requests. 1st byte identifies type */
879 len = read(cfd, buf, 1);
881 DPRINTF(("rfb client exiting\r\n"));
887 rfb_recv_set_pixfmt_msg(rc, cfd);
890 rfb_recv_set_encodings_msg(rc, cfd);
893 rfb_recv_update_msg(rc, cfd, 1);
896 rfb_recv_key_msg(rc, cfd);
899 rfb_recv_ptr_msg(rc, cfd);
902 rfb_recv_cuttext_msg(rc, cfd);
905 WPRINTF(("rfb unknown cli-code %d!\n", buf[0] & 0xff));
912 pthread_join(tid, NULL);
914 deflateEnd(&rc->zstream);
920 struct rfb_softc *rc;
928 sigaddset(&set, SIGPIPE);
929 if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0) {
930 perror("pthread_sigmask");
935 rc->enc_raw_ok = false;
936 rc->enc_zlib_ok = false;
937 rc->enc_resize_ok = false;
939 cfd = accept(rc->sfd, NULL, NULL);
941 pthread_mutex_lock(&rc->mtx);
942 pthread_cond_signal(&rc->cond);
943 pthread_mutex_unlock(&rc->mtx);
955 sse42_supported(void)
957 u_int cpu_registers[4], ecx;
959 do_cpuid(1, cpu_registers);
961 ecx = cpu_registers[2];
963 return ((ecx & CPUID2_SSE42) != 0);
967 rfb_init(char *hostname, int port, int wait, char *password)
971 struct rfb_softc *rc;
973 struct addrinfo hints;
975 #ifndef WITHOUT_CAPSICUM
979 rc = calloc(1, sizeof(struct rfb_softc));
981 rc->crc = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
983 rc->crc_tmp = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
985 rc->crc_width = RFB_MAX_WIDTH;
986 rc->crc_height = RFB_MAX_HEIGHT;
988 rc->password = password;
990 snprintf(servname, sizeof(servname), "%d", port ? port : 5900);
992 if (!hostname || strlen(hostname) == 0)
994 hostname = "127.0.0.1";
999 memset(&hints, 0, sizeof(hints));
1000 hints.ai_family = AF_UNSPEC;
1001 hints.ai_socktype = SOCK_STREAM;
1002 hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV | AI_PASSIVE;
1004 if ((e = getaddrinfo(hostname, servname, &hints, &ai)) != 0) {
1005 fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
1009 rc->sfd = socket(ai->ai_family, ai->ai_socktype, 0);
1016 setsockopt(rc->sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
1018 if (bind(rc->sfd, ai->ai_addr, ai->ai_addrlen) < 0) {
1024 if (listen(rc->sfd, 1) < 0) {
1030 #ifndef WITHOUT_CAPSICUM
1031 cap_rights_init(&rights, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE);
1032 if (caph_rights_limit(rc->sfd, &rights) == -1)
1033 errx(EX_OSERR, "Unable to apply rights for sandbox");
1036 rc->hw_crc = sse42_supported();
1038 rc->conn_wait = wait;
1040 pthread_mutex_init(&rc->mtx, NULL);
1041 pthread_cond_init(&rc->cond, NULL);
1044 pthread_create(&rc->tid, NULL, rfb_thr, rc);
1045 pthread_set_name_np(rc->tid, "rfb");
1048 DPRINTF(("Waiting for rfb client...\n"));
1049 pthread_mutex_lock(&rc->mtx);
1050 pthread_cond_wait(&rc->cond, &rc->mtx);
1051 pthread_mutex_unlock(&rc->mtx);