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>
69 #include "sockstream.h"
72 #include <openssl/des.h>
75 static int rfb_debug = 0;
76 #define DPRINTF(params) if (rfb_debug) PRINTLN params
77 #define WPRINTF(params) PRINTLN params
79 #define AUTH_LENGTH 16
80 #define PASSWD_LENGTH 8
82 #define SECURITY_TYPE_NONE 1
83 #define SECURITY_TYPE_VNC_AUTH 2
85 #define AUTH_FAILED_UNAUTH 1
86 #define AUTH_FAILED_ERROR 2
112 uint32_t *crc; /* WxH crc cells */
113 uint32_t *crc_tmp; /* buffer to store single crc row */
114 int crc_width, crc_height;
131 struct rfb_srvr_info {
134 struct rfb_pixfmt pixfmt;
138 struct rfb_pixfmt_msg {
141 struct rfb_pixfmt pixfmt;
144 #define RFB_ENCODING_RAW 0
145 #define RFB_ENCODING_ZLIB 6
146 #define RFB_ENCODING_RESIZE -223
148 #define RFB_MAX_WIDTH 2000
149 #define RFB_MAX_HEIGHT 1200
150 #define RFB_ZLIB_BUFSZ RFB_MAX_WIDTH*RFB_MAX_HEIGHT*4
152 /* percentage changes to screen before sending the entire screen */
153 #define RFB_SEND_ALL_THRESH 25
161 struct rfb_updt_msg {
184 struct rfb_srvr_updt_msg {
190 struct rfb_srvr_rect_hdr {
198 struct rfb_cuttext_msg {
206 rfb_send_server_init_msg(int cfd)
208 struct bhyvegc_image *gc_image;
209 struct rfb_srvr_info sinfo;
211 gc_image = console_get_image();
213 sinfo.width = htons(gc_image->width);
214 sinfo.height = htons(gc_image->height);
215 sinfo.pixfmt.bpp = 32;
216 sinfo.pixfmt.depth = 32;
217 sinfo.pixfmt.bigendian = 0;
218 sinfo.pixfmt.truecolor = 1;
219 sinfo.pixfmt.red_max = htons(255);
220 sinfo.pixfmt.green_max = htons(255);
221 sinfo.pixfmt.blue_max = htons(255);
222 sinfo.pixfmt.red_shift = 16;
223 sinfo.pixfmt.green_shift = 8;
224 sinfo.pixfmt.blue_shift = 0;
225 sinfo.namelen = htonl(strlen("bhyve"));
226 (void)stream_write(cfd, &sinfo, sizeof(sinfo));
227 (void)stream_write(cfd, "bhyve", strlen("bhyve"));
231 rfb_send_resize_update_msg(struct rfb_softc *rc, int cfd)
233 struct rfb_srvr_updt_msg supdt_msg;
234 struct rfb_srvr_rect_hdr srect_hdr;
236 /* Number of rectangles: 1 */
239 supdt_msg.numrects = htons(1);
240 stream_write(cfd, &supdt_msg, sizeof(struct rfb_srvr_updt_msg));
242 /* Rectangle header */
243 srect_hdr.x = htons(0);
244 srect_hdr.y = htons(0);
245 srect_hdr.width = htons(rc->width);
246 srect_hdr.height = htons(rc->height);
247 srect_hdr.encoding = htonl(RFB_ENCODING_RESIZE);
248 stream_write(cfd, &srect_hdr, sizeof(struct rfb_srvr_rect_hdr));
252 rfb_recv_set_pixfmt_msg(struct rfb_softc *rc, int cfd)
254 struct rfb_pixfmt_msg pixfmt_msg;
256 (void)stream_read(cfd, ((void *)&pixfmt_msg)+1, sizeof(pixfmt_msg)-1);
261 rfb_recv_set_encodings_msg(struct rfb_softc *rc, int cfd)
263 struct rfb_enc_msg enc_msg;
267 assert((sizeof(enc_msg) - 1) == 3);
268 (void)stream_read(cfd, ((void *)&enc_msg)+1, sizeof(enc_msg)-1);
270 for (i = 0; i < htons(enc_msg.numencs); i++) {
271 (void)stream_read(cfd, &encoding, sizeof(encoding));
272 switch (htonl(encoding)) {
273 case RFB_ENCODING_RAW:
274 rc->enc_raw_ok = true;
276 case RFB_ENCODING_ZLIB:
277 if (!rc->enc_zlib_ok) {
278 deflateInit(&rc->zstream, Z_BEST_SPEED);
279 rc->enc_zlib_ok = true;
282 case RFB_ENCODING_RESIZE:
283 rc->enc_resize_ok = true;
290 * Calculate CRC32 using SSE4.2; Intel or AMD Bulldozer+ CPUs only
292 static __inline uint32_t
293 fast_crc32(void *buf, int len, uint32_t crcval)
295 uint32_t q = len / sizeof(uint32_t);
296 uint32_t *p = (uint32_t *)buf;
300 ".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;"
302 :"0" (crcval), "c" (*p)
312 rfb_send_rect(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc,
313 int x, int y, int w, int h)
315 struct rfb_srvr_updt_msg supdt_msg;
316 struct rfb_srvr_rect_hdr srect_hdr;
318 ssize_t nwrite, total;
324 * Send a single rectangle of the given x, y, w h dimensions.
327 /* Number of rectangles: 1 */
330 supdt_msg.numrects = htons(1);
331 nwrite = stream_write(cfd, &supdt_msg,
332 sizeof(struct rfb_srvr_updt_msg));
337 /* Rectangle header */
338 srect_hdr.x = htons(x);
339 srect_hdr.y = htons(y);
340 srect_hdr.width = htons(w);
341 srect_hdr.height = htons(h);
344 w *= sizeof(uint32_t);
345 if (rc->enc_zlib_ok) {
347 rc->zstream.total_in = 0;
348 rc->zstream.total_out = 0;
349 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
350 rc->zstream.next_in = (Bytef *)p;
351 rc->zstream.avail_in = w;
352 rc->zstream.next_out = (Bytef *)zbufp;
353 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16 -
354 rc->zstream.total_out;
355 rc->zstream.data_type = Z_BINARY;
357 /* Compress with zlib */
358 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
360 WPRINTF(("zlib[rect] deflate err: %d", err));
361 rc->enc_zlib_ok = false;
362 deflateEnd(&rc->zstream);
365 zbufp = rc->zbuf + rc->zstream.total_out;
368 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
369 nwrite = stream_write(cfd, &srect_hdr,
370 sizeof(struct rfb_srvr_rect_hdr));
374 zlen = htonl(rc->zstream.total_out);
375 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
378 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
385 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
392 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
393 nwrite = stream_write(cfd, &srect_hdr,
394 sizeof(struct rfb_srvr_rect_hdr));
398 total = stream_write(cfd, rc->zbuf, total);
404 rfb_send_all(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc)
406 struct rfb_srvr_updt_msg supdt_msg;
407 struct rfb_srvr_rect_hdr srect_hdr;
413 * Send the whole thing
416 /* Number of rectangles: 1 */
419 supdt_msg.numrects = htons(1);
420 nwrite = stream_write(cfd, &supdt_msg,
421 sizeof(struct rfb_srvr_updt_msg));
425 /* Rectangle header */
428 srect_hdr.width = htons(gc->width);
429 srect_hdr.height = htons(gc->height);
430 if (rc->enc_zlib_ok) {
431 rc->zstream.next_in = (Bytef *)gc->data;
432 rc->zstream.avail_in = gc->width * gc->height *
434 rc->zstream.next_out = (Bytef *)rc->zbuf;
435 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16;
436 rc->zstream.data_type = Z_BINARY;
438 rc->zstream.total_in = 0;
439 rc->zstream.total_out = 0;
441 /* Compress with zlib */
442 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
444 WPRINTF(("zlib deflate err: %d", err));
445 rc->enc_zlib_ok = false;
446 deflateEnd(&rc->zstream);
450 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
451 nwrite = stream_write(cfd, &srect_hdr,
452 sizeof(struct rfb_srvr_rect_hdr));
456 zlen = htonl(rc->zstream.total_out);
457 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
460 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
464 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
465 nwrite = stream_write(cfd, &srect_hdr,
466 sizeof(struct rfb_srvr_rect_hdr));
470 nwrite = stream_write(cfd, gc->data,
471 gc->width * gc->height * sizeof(uint32_t));
476 #define PIX_PER_CELL 32
477 #define PIXCELL_SHIFT 5
478 #define PIXCELL_MASK 0x1F
481 rfb_send_screen(struct rfb_softc *rc, int cfd, int all)
483 struct bhyvegc_image *gc_image;
486 int celly, cellwidth;
490 int rem_x, rem_y; /* remainder for resolutions not x32 pixels ratio */
492 uint32_t *crc_p, *orig_crc;
496 gc_image = console_get_image();
498 pthread_mutex_lock(&rc->mtx);
500 pthread_mutex_unlock(&rc->mtx);
504 pthread_mutex_unlock(&rc->mtx);
509 retval = rfb_send_all(rc, cfd, gc_image);
514 * Calculate the checksum for each 32x32 cell. Send each that
515 * has changed since the last scan.
518 /* Resolution changed */
520 rc->crc_width = gc_image->width;
521 rc->crc_height = gc_image->height;
525 xcells = howmany(rc->crc_width, PIX_PER_CELL);
526 ycells = howmany(rc->crc_height, PIX_PER_CELL);
528 rem_x = w & PIXCELL_MASK;
530 rem_y = h & PIXCELL_MASK;
532 rem_y = PIX_PER_CELL;
537 * Go through all cells and calculate crc. If significant number
538 * of changes, then send entire screen.
539 * crc_tmp is dual purpose: to store the new crc and to flag as
540 * a cell that has changed.
542 crc_p = rc->crc_tmp - xcells;
543 orig_crc = rc->crc - xcells;
545 memset(rc->crc_tmp, 0, sizeof(uint32_t) * xcells * ycells);
546 for (y = 0; y < h; y++) {
547 if ((y & PIXCELL_MASK) == 0) {
552 for (x = 0; x < xcells; x++) {
553 if (x == (xcells - 1) && rem_x > 0)
556 cellwidth = PIX_PER_CELL;
559 crc_p[x] = fast_crc32(p,
560 cellwidth * sizeof(uint32_t),
563 crc_p[x] = (uint32_t)crc32(crc_p[x],
565 cellwidth * sizeof(uint32_t));
569 /* check for crc delta if last row in cell */
570 if ((y & PIXCELL_MASK) == PIXCELL_MASK || y == (h-1)) {
571 if (orig_crc[x] != crc_p[x]) {
572 orig_crc[x] = crc_p[x];
582 /* If number of changes is > THRESH percent, send the whole screen */
583 if (((changes * 100) / (xcells * ycells)) >= RFB_SEND_ALL_THRESH) {
584 retval = rfb_send_all(rc, cfd, gc_image);
588 /* Go through all cells, and send only changed ones */
590 for (y = 0; y < h; y += PIX_PER_CELL) {
591 /* previous cell's row */
592 celly = (y >> PIXCELL_SHIFT);
594 /* Delta check crc to previous set */
595 for (x = 0; x < xcells; x++) {
599 if (x == (xcells - 1) && rem_x > 0)
602 cellwidth = PIX_PER_CELL;
603 nwrite = rfb_send_rect(rc, cfd,
606 celly * PIX_PER_CELL,
608 y + PIX_PER_CELL >= h ? rem_y : PIX_PER_CELL);
618 pthread_mutex_lock(&rc->mtx);
620 pthread_mutex_unlock(&rc->mtx);
627 rfb_recv_update_msg(struct rfb_softc *rc, int cfd, int discardonly)
629 struct rfb_updt_msg updt_msg;
630 struct bhyvegc_image *gc_image;
632 (void)stream_read(cfd, ((void *)&updt_msg) + 1 , sizeof(updt_msg) - 1);
635 gc_image = console_get_image();
637 updt_msg.x = htons(updt_msg.x);
638 updt_msg.y = htons(updt_msg.y);
639 updt_msg.width = htons(updt_msg.width);
640 updt_msg.height = htons(updt_msg.height);
642 if (updt_msg.width != gc_image->width ||
643 updt_msg.height != gc_image->height) {
644 rc->width = gc_image->width;
645 rc->height = gc_image->height;
646 if (rc->enc_resize_ok)
647 rfb_send_resize_update_msg(rc, cfd);
653 rfb_send_screen(rc, cfd, 1);
657 rfb_recv_key_msg(struct rfb_softc *rc, int cfd)
659 struct rfb_key_msg key_msg;
661 (void)stream_read(cfd, ((void *)&key_msg) + 1, sizeof(key_msg) - 1);
663 console_key_event(key_msg.down, htonl(key_msg.code));
667 rfb_recv_ptr_msg(struct rfb_softc *rc, int cfd)
669 struct rfb_ptr_msg ptr_msg;
671 (void)stream_read(cfd, ((void *)&ptr_msg) + 1, sizeof(ptr_msg) - 1);
673 console_ptr_event(ptr_msg.button, htons(ptr_msg.x), htons(ptr_msg.y));
677 rfb_recv_cuttext_msg(struct rfb_softc *rc, int cfd)
679 struct rfb_cuttext_msg ct_msg;
680 unsigned char buf[32];
683 len = stream_read(cfd, ((void *)&ct_msg) + 1, sizeof(ct_msg) - 1);
684 ct_msg.length = htonl(ct_msg.length);
685 while (ct_msg.length > 0) {
686 len = stream_read(cfd, buf, ct_msg.length > sizeof(buf) ?
687 sizeof(buf) : ct_msg.length);
688 ct_msg.length -= len;
693 timeval_delta(struct timeval *prev, struct timeval *now)
696 n1 = now->tv_sec * 1000000 + now->tv_usec;
697 n2 = prev->tv_sec * 1000000 + prev->tv_usec;
702 rfb_wr_thr(void *arg)
704 struct rfb_softc *rc;
707 struct timeval prev_tv;
717 while (rc->cfd >= 0) {
723 err = select(cfd+1, &rfds, NULL, NULL, &tv);
727 /* Determine if its time to push screen; ~24hz */
728 gettimeofday(&tv, NULL);
729 tdiff = timeval_delta(&prev_tv, &tv);
731 prev_tv.tv_sec = tv.tv_sec;
732 prev_tv.tv_usec = tv.tv_usec;
733 if (rfb_send_screen(rc, cfd, 0) <= 0) {
738 usleep(40000 - tdiff);
746 rfb_handle(struct rfb_softc *rc, int cfd)
748 const char *vbuf = "RFB 003.008\n";
749 unsigned char buf[80];
750 unsigned char *message = NULL;
753 unsigned char challenge[AUTH_LENGTH];
754 unsigned char keystr[PASSWD_LENGTH];
755 unsigned char crypt_expected[AUTH_LENGTH];
768 /* 1a. Send server version */
769 stream_write(cfd, vbuf, strlen(vbuf));
771 /* 1b. Read client version */
772 len = read(cfd, buf, sizeof(buf));
774 /* 2a. Send security type */
778 buf[1] = SECURITY_TYPE_VNC_AUTH;
780 buf[1] = SECURITY_TYPE_NONE;
782 buf[1] = SECURITY_TYPE_NONE;
785 stream_write(cfd, buf, 2);
787 /* 2b. Read agreed security type */
788 len = stream_read(cfd, buf, 1);
790 /* 2c. Do VNC authentication */
792 case SECURITY_TYPE_NONE:
795 case SECURITY_TYPE_VNC_AUTH:
797 * The client encrypts the challenge with DES, using a password
798 * supplied by the user as the key.
799 * To form the key, the password is truncated to
800 * eight characters, or padded with null bytes on the right.
801 * The client then sends the resulting 16-bytes response.
804 strncpy(keystr, rc->password, PASSWD_LENGTH);
806 /* VNC clients encrypts the challenge with all the bit fields
807 * in each byte of the password mirrored.
808 * Here we flip each byte of the keystr.
810 for (i = 0; i < PASSWD_LENGTH; i++) {
811 keystr[i] = (keystr[i] & 0xF0) >> 4
812 | (keystr[i] & 0x0F) << 4;
813 keystr[i] = (keystr[i] & 0xCC) >> 2
814 | (keystr[i] & 0x33) << 2;
815 keystr[i] = (keystr[i] & 0xAA) >> 1
816 | (keystr[i] & 0x55) << 1;
819 /* Initialize a 16-byte random challenge */
820 arc4random_buf(challenge, sizeof(challenge));
821 stream_write(cfd, challenge, AUTH_LENGTH);
823 /* Receive the 16-byte challenge response */
824 stream_read(cfd, buf, AUTH_LENGTH);
826 memcpy(crypt_expected, challenge, AUTH_LENGTH);
828 /* Encrypt the Challenge with DES */
829 DES_set_key((const_DES_cblock *)keystr, &ks);
830 DES_ecb_encrypt((const_DES_cblock *)challenge,
831 (const_DES_cblock *)crypt_expected,
833 DES_ecb_encrypt((const_DES_cblock *)(challenge + PASSWD_LENGTH),
834 (const_DES_cblock *)(crypt_expected +
838 if (memcmp(crypt_expected, buf, AUTH_LENGTH) != 0) {
839 message = "Auth Failed: Invalid Password.";
845 WPRINTF(("Auth not supported, no OpenSSL in your system"));
851 /* 2d. Write back a status */
852 stream_write(cfd, &sres, 4);
855 be32enc(buf, strlen(message));
856 stream_write(cfd, buf, 4);
857 stream_write(cfd, message, strlen(message));
861 /* 3a. Read client shared-flag byte */
862 len = stream_read(cfd, buf, 1);
864 /* 4a. Write server-init info */
865 rfb_send_server_init_msg(cfd);
868 rc->zbuf = malloc(RFB_ZLIB_BUFSZ + 16);
869 assert(rc->zbuf != NULL);
872 rfb_send_screen(rc, cfd, 1);
874 perror = pthread_create(&tid, NULL, rfb_wr_thr, rc);
876 pthread_set_name_np(tid, "rfbout");
878 /* Now read in client requests. 1st byte identifies type */
880 len = read(cfd, buf, 1);
882 DPRINTF(("rfb client exiting"));
888 rfb_recv_set_pixfmt_msg(rc, cfd);
891 rfb_recv_set_encodings_msg(rc, cfd);
894 rfb_recv_update_msg(rc, cfd, 1);
897 rfb_recv_key_msg(rc, cfd);
900 rfb_recv_ptr_msg(rc, cfd);
903 rfb_recv_cuttext_msg(rc, cfd);
906 WPRINTF(("rfb unknown cli-code %d!", buf[0] & 0xff));
913 pthread_join(tid, NULL);
915 deflateEnd(&rc->zstream);
921 struct rfb_softc *rc;
929 sigaddset(&set, SIGPIPE);
930 if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0) {
931 perror("pthread_sigmask");
936 rc->enc_raw_ok = false;
937 rc->enc_zlib_ok = false;
938 rc->enc_resize_ok = false;
940 cfd = accept(rc->sfd, NULL, NULL);
942 pthread_mutex_lock(&rc->mtx);
943 pthread_cond_signal(&rc->cond);
944 pthread_mutex_unlock(&rc->mtx);
956 sse42_supported(void)
958 u_int cpu_registers[4], ecx;
960 do_cpuid(1, cpu_registers);
962 ecx = cpu_registers[2];
964 return ((ecx & CPUID2_SSE42) != 0);
968 rfb_init(char *hostname, int port, int wait, char *password)
972 struct rfb_softc *rc;
973 struct addrinfo *ai = NULL;
974 struct addrinfo hints;
976 #ifndef WITHOUT_CAPSICUM
980 rc = calloc(1, sizeof(struct rfb_softc));
982 rc->crc = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
984 rc->crc_tmp = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
986 rc->crc_width = RFB_MAX_WIDTH;
987 rc->crc_height = RFB_MAX_HEIGHT;
990 rc->password = password;
992 snprintf(servname, sizeof(servname), "%d", port ? port : 5900);
994 if (!hostname || strlen(hostname) == 0)
996 hostname = "127.0.0.1";
1001 memset(&hints, 0, sizeof(hints));
1002 hints.ai_family = AF_UNSPEC;
1003 hints.ai_socktype = SOCK_STREAM;
1004 hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV | AI_PASSIVE;
1006 if ((e = getaddrinfo(hostname, servname, &hints, &ai)) != 0) {
1007 EPRINTLN("getaddrinfo: %s", gai_strerror(e));
1011 rc->sfd = socket(ai->ai_family, ai->ai_socktype, 0);
1017 setsockopt(rc->sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
1019 if (bind(rc->sfd, ai->ai_addr, ai->ai_addrlen) < 0) {
1024 if (listen(rc->sfd, 1) < 0) {
1029 #ifndef WITHOUT_CAPSICUM
1030 cap_rights_init(&rights, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE);
1031 if (caph_rights_limit(rc->sfd, &rights) == -1)
1032 errx(EX_OSERR, "Unable to apply rights for sandbox");
1035 rc->hw_crc = sse42_supported();
1037 rc->conn_wait = wait;
1039 pthread_mutex_init(&rc->mtx, NULL);
1040 pthread_cond_init(&rc->cond, NULL);
1043 pthread_create(&rc->tid, NULL, rfb_thr, rc);
1044 pthread_set_name_np(rc->tid, "rfb");
1047 DPRINTF(("Waiting for rfb client..."));
1048 pthread_mutex_lock(&rc->mtx);
1049 pthread_cond_wait(&rc->cond, &rc->mtx);
1050 pthread_mutex_unlock(&rc->mtx);