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 VERSION_LENGTH 12
80 #define AUTH_LENGTH 16
81 #define PASSWD_LENGTH 8
83 #define SECURITY_TYPE_NONE 1
84 #define SECURITY_TYPE_VNC_AUTH 2
86 #define AUTH_FAILED_UNAUTH 1
87 #define AUTH_FAILED_ERROR 2
113 uint32_t *crc; /* WxH crc cells */
114 uint32_t *crc_tmp; /* buffer to store single crc row */
115 int crc_width, crc_height;
132 struct rfb_srvr_info {
135 struct rfb_pixfmt pixfmt;
139 struct rfb_pixfmt_msg {
142 struct rfb_pixfmt pixfmt;
145 #define RFB_ENCODING_RAW 0
146 #define RFB_ENCODING_ZLIB 6
147 #define RFB_ENCODING_RESIZE -223
149 #define RFB_MAX_WIDTH 2000
150 #define RFB_MAX_HEIGHT 1200
151 #define RFB_ZLIB_BUFSZ RFB_MAX_WIDTH*RFB_MAX_HEIGHT*4
153 /* percentage changes to screen before sending the entire screen */
154 #define RFB_SEND_ALL_THRESH 25
162 struct rfb_updt_msg {
185 struct rfb_srvr_updt_msg {
191 struct rfb_srvr_rect_hdr {
199 struct rfb_cuttext_msg {
207 rfb_send_server_init_msg(int cfd)
209 struct bhyvegc_image *gc_image;
210 struct rfb_srvr_info sinfo;
212 gc_image = console_get_image();
214 sinfo.width = htons(gc_image->width);
215 sinfo.height = htons(gc_image->height);
216 sinfo.pixfmt.bpp = 32;
217 sinfo.pixfmt.depth = 32;
218 sinfo.pixfmt.bigendian = 0;
219 sinfo.pixfmt.truecolor = 1;
220 sinfo.pixfmt.red_max = htons(255);
221 sinfo.pixfmt.green_max = htons(255);
222 sinfo.pixfmt.blue_max = htons(255);
223 sinfo.pixfmt.red_shift = 16;
224 sinfo.pixfmt.green_shift = 8;
225 sinfo.pixfmt.blue_shift = 0;
226 sinfo.namelen = htonl(strlen("bhyve"));
227 (void)stream_write(cfd, &sinfo, sizeof(sinfo));
228 (void)stream_write(cfd, "bhyve", strlen("bhyve"));
232 rfb_send_resize_update_msg(struct rfb_softc *rc, int cfd)
234 struct rfb_srvr_updt_msg supdt_msg;
235 struct rfb_srvr_rect_hdr srect_hdr;
237 /* Number of rectangles: 1 */
240 supdt_msg.numrects = htons(1);
241 stream_write(cfd, &supdt_msg, sizeof(struct rfb_srvr_updt_msg));
243 /* Rectangle header */
244 srect_hdr.x = htons(0);
245 srect_hdr.y = htons(0);
246 srect_hdr.width = htons(rc->width);
247 srect_hdr.height = htons(rc->height);
248 srect_hdr.encoding = htonl(RFB_ENCODING_RESIZE);
249 stream_write(cfd, &srect_hdr, sizeof(struct rfb_srvr_rect_hdr));
253 rfb_recv_set_pixfmt_msg(struct rfb_softc *rc, int cfd)
255 struct rfb_pixfmt_msg pixfmt_msg;
257 (void)stream_read(cfd, ((void *)&pixfmt_msg)+1, sizeof(pixfmt_msg)-1);
262 rfb_recv_set_encodings_msg(struct rfb_softc *rc, int cfd)
264 struct rfb_enc_msg enc_msg;
268 assert((sizeof(enc_msg) - 1) == 3);
269 (void)stream_read(cfd, ((void *)&enc_msg)+1, sizeof(enc_msg)-1);
271 for (i = 0; i < htons(enc_msg.numencs); i++) {
272 (void)stream_read(cfd, &encoding, sizeof(encoding));
273 switch (htonl(encoding)) {
274 case RFB_ENCODING_RAW:
275 rc->enc_raw_ok = true;
277 case RFB_ENCODING_ZLIB:
278 if (!rc->enc_zlib_ok) {
279 deflateInit(&rc->zstream, Z_BEST_SPEED);
280 rc->enc_zlib_ok = true;
283 case RFB_ENCODING_RESIZE:
284 rc->enc_resize_ok = true;
291 * Calculate CRC32 using SSE4.2; Intel or AMD Bulldozer+ CPUs only
293 static __inline uint32_t
294 fast_crc32(void *buf, int len, uint32_t crcval)
296 uint32_t q = len / sizeof(uint32_t);
297 uint32_t *p = (uint32_t *)buf;
301 ".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;"
303 :"0" (crcval), "c" (*p)
313 rfb_send_rect(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc,
314 int x, int y, int w, int h)
316 struct rfb_srvr_updt_msg supdt_msg;
317 struct rfb_srvr_rect_hdr srect_hdr;
319 ssize_t nwrite, total;
325 * Send a single rectangle of the given x, y, w h dimensions.
328 /* Number of rectangles: 1 */
331 supdt_msg.numrects = htons(1);
332 nwrite = stream_write(cfd, &supdt_msg,
333 sizeof(struct rfb_srvr_updt_msg));
338 /* Rectangle header */
339 srect_hdr.x = htons(x);
340 srect_hdr.y = htons(y);
341 srect_hdr.width = htons(w);
342 srect_hdr.height = htons(h);
345 w *= sizeof(uint32_t);
346 if (rc->enc_zlib_ok) {
348 rc->zstream.total_in = 0;
349 rc->zstream.total_out = 0;
350 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
351 rc->zstream.next_in = (Bytef *)p;
352 rc->zstream.avail_in = w;
353 rc->zstream.next_out = (Bytef *)zbufp;
354 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16 -
355 rc->zstream.total_out;
356 rc->zstream.data_type = Z_BINARY;
358 /* Compress with zlib */
359 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
361 WPRINTF(("zlib[rect] deflate err: %d", err));
362 rc->enc_zlib_ok = false;
363 deflateEnd(&rc->zstream);
366 zbufp = rc->zbuf + rc->zstream.total_out;
369 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
370 nwrite = stream_write(cfd, &srect_hdr,
371 sizeof(struct rfb_srvr_rect_hdr));
375 zlen = htonl(rc->zstream.total_out);
376 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
379 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
386 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
393 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
394 nwrite = stream_write(cfd, &srect_hdr,
395 sizeof(struct rfb_srvr_rect_hdr));
399 total = stream_write(cfd, rc->zbuf, total);
405 rfb_send_all(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc)
407 struct rfb_srvr_updt_msg supdt_msg;
408 struct rfb_srvr_rect_hdr srect_hdr;
414 * Send the whole thing
417 /* Number of rectangles: 1 */
420 supdt_msg.numrects = htons(1);
421 nwrite = stream_write(cfd, &supdt_msg,
422 sizeof(struct rfb_srvr_updt_msg));
426 /* Rectangle header */
429 srect_hdr.width = htons(gc->width);
430 srect_hdr.height = htons(gc->height);
431 if (rc->enc_zlib_ok) {
432 rc->zstream.next_in = (Bytef *)gc->data;
433 rc->zstream.avail_in = gc->width * gc->height *
435 rc->zstream.next_out = (Bytef *)rc->zbuf;
436 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16;
437 rc->zstream.data_type = Z_BINARY;
439 rc->zstream.total_in = 0;
440 rc->zstream.total_out = 0;
442 /* Compress with zlib */
443 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
445 WPRINTF(("zlib deflate err: %d", err));
446 rc->enc_zlib_ok = false;
447 deflateEnd(&rc->zstream);
451 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
452 nwrite = stream_write(cfd, &srect_hdr,
453 sizeof(struct rfb_srvr_rect_hdr));
457 zlen = htonl(rc->zstream.total_out);
458 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
461 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
465 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
466 nwrite = stream_write(cfd, &srect_hdr,
467 sizeof(struct rfb_srvr_rect_hdr));
471 nwrite = stream_write(cfd, gc->data,
472 gc->width * gc->height * sizeof(uint32_t));
477 #define PIX_PER_CELL 32
478 #define PIXCELL_SHIFT 5
479 #define PIXCELL_MASK 0x1F
482 rfb_send_screen(struct rfb_softc *rc, int cfd, int all)
484 struct bhyvegc_image *gc_image;
487 int celly, cellwidth;
491 int rem_x, rem_y; /* remainder for resolutions not x32 pixels ratio */
493 uint32_t *crc_p, *orig_crc;
497 gc_image = console_get_image();
499 pthread_mutex_lock(&rc->mtx);
501 pthread_mutex_unlock(&rc->mtx);
505 pthread_mutex_unlock(&rc->mtx);
510 retval = rfb_send_all(rc, cfd, gc_image);
515 * Calculate the checksum for each 32x32 cell. Send each that
516 * has changed since the last scan.
519 /* Resolution changed */
521 rc->crc_width = gc_image->width;
522 rc->crc_height = gc_image->height;
526 xcells = howmany(rc->crc_width, PIX_PER_CELL);
527 ycells = howmany(rc->crc_height, PIX_PER_CELL);
529 rem_x = w & PIXCELL_MASK;
531 rem_y = h & PIXCELL_MASK;
533 rem_y = PIX_PER_CELL;
538 * Go through all cells and calculate crc. If significant number
539 * of changes, then send entire screen.
540 * crc_tmp is dual purpose: to store the new crc and to flag as
541 * a cell that has changed.
543 crc_p = rc->crc_tmp - xcells;
544 orig_crc = rc->crc - xcells;
546 memset(rc->crc_tmp, 0, sizeof(uint32_t) * xcells * ycells);
547 for (y = 0; y < h; y++) {
548 if ((y & PIXCELL_MASK) == 0) {
553 for (x = 0; x < xcells; x++) {
554 if (x == (xcells - 1) && rem_x > 0)
557 cellwidth = PIX_PER_CELL;
560 crc_p[x] = fast_crc32(p,
561 cellwidth * sizeof(uint32_t),
564 crc_p[x] = (uint32_t)crc32(crc_p[x],
566 cellwidth * sizeof(uint32_t));
570 /* check for crc delta if last row in cell */
571 if ((y & PIXCELL_MASK) == PIXCELL_MASK || y == (h-1)) {
572 if (orig_crc[x] != crc_p[x]) {
573 orig_crc[x] = crc_p[x];
583 /* If number of changes is > THRESH percent, send the whole screen */
584 if (((changes * 100) / (xcells * ycells)) >= RFB_SEND_ALL_THRESH) {
585 retval = rfb_send_all(rc, cfd, gc_image);
589 /* Go through all cells, and send only changed ones */
591 for (y = 0; y < h; y += PIX_PER_CELL) {
592 /* previous cell's row */
593 celly = (y >> PIXCELL_SHIFT);
595 /* Delta check crc to previous set */
596 for (x = 0; x < xcells; x++) {
600 if (x == (xcells - 1) && rem_x > 0)
603 cellwidth = PIX_PER_CELL;
604 nwrite = rfb_send_rect(rc, cfd,
607 celly * PIX_PER_CELL,
609 y + PIX_PER_CELL >= h ? rem_y : PIX_PER_CELL);
619 pthread_mutex_lock(&rc->mtx);
621 pthread_mutex_unlock(&rc->mtx);
628 rfb_recv_update_msg(struct rfb_softc *rc, int cfd, int discardonly)
630 struct rfb_updt_msg updt_msg;
631 struct bhyvegc_image *gc_image;
633 (void)stream_read(cfd, ((void *)&updt_msg) + 1 , sizeof(updt_msg) - 1);
636 gc_image = console_get_image();
638 updt_msg.x = htons(updt_msg.x);
639 updt_msg.y = htons(updt_msg.y);
640 updt_msg.width = htons(updt_msg.width);
641 updt_msg.height = htons(updt_msg.height);
643 if (updt_msg.width != gc_image->width ||
644 updt_msg.height != gc_image->height) {
645 rc->width = gc_image->width;
646 rc->height = gc_image->height;
647 if (rc->enc_resize_ok)
648 rfb_send_resize_update_msg(rc, cfd);
654 rfb_send_screen(rc, cfd, 1);
658 rfb_recv_key_msg(struct rfb_softc *rc, int cfd)
660 struct rfb_key_msg key_msg;
662 (void)stream_read(cfd, ((void *)&key_msg) + 1, sizeof(key_msg) - 1);
664 console_key_event(key_msg.down, htonl(key_msg.code));
668 rfb_recv_ptr_msg(struct rfb_softc *rc, int cfd)
670 struct rfb_ptr_msg ptr_msg;
672 (void)stream_read(cfd, ((void *)&ptr_msg) + 1, sizeof(ptr_msg) - 1);
674 console_ptr_event(ptr_msg.button, htons(ptr_msg.x), htons(ptr_msg.y));
678 rfb_recv_cuttext_msg(struct rfb_softc *rc, int cfd)
680 struct rfb_cuttext_msg ct_msg;
681 unsigned char buf[32];
684 len = stream_read(cfd, ((void *)&ct_msg) + 1, sizeof(ct_msg) - 1);
685 ct_msg.length = htonl(ct_msg.length);
686 while (ct_msg.length > 0) {
687 len = stream_read(cfd, buf, ct_msg.length > sizeof(buf) ?
688 sizeof(buf) : ct_msg.length);
689 ct_msg.length -= len;
694 timeval_delta(struct timeval *prev, struct timeval *now)
697 n1 = now->tv_sec * 1000000 + now->tv_usec;
698 n2 = prev->tv_sec * 1000000 + prev->tv_usec;
703 rfb_wr_thr(void *arg)
705 struct rfb_softc *rc;
708 struct timeval prev_tv;
718 while (rc->cfd >= 0) {
724 err = select(cfd+1, &rfds, NULL, NULL, &tv);
728 /* Determine if its time to push screen; ~24hz */
729 gettimeofday(&tv, NULL);
730 tdiff = timeval_delta(&prev_tv, &tv);
732 prev_tv.tv_sec = tv.tv_sec;
733 prev_tv.tv_usec = tv.tv_usec;
734 if (rfb_send_screen(rc, cfd, 0) <= 0) {
739 usleep(40000 - tdiff);
747 rfb_handle(struct rfb_softc *rc, int cfd)
749 const char *vbuf = "RFB 003.008\n";
750 unsigned char buf[80];
751 unsigned char *message = NULL;
754 unsigned char challenge[AUTH_LENGTH];
755 unsigned char keystr[PASSWD_LENGTH];
756 unsigned char crypt_expected[AUTH_LENGTH];
769 /* 1a. Send server version */
770 stream_write(cfd, vbuf, strlen(vbuf));
772 /* 1b. Read client version */
773 len = stream_read(cfd, buf, VERSION_LENGTH);
775 /* 2a. Send security type */
779 buf[1] = SECURITY_TYPE_VNC_AUTH;
781 buf[1] = SECURITY_TYPE_NONE;
783 buf[1] = SECURITY_TYPE_NONE;
786 stream_write(cfd, buf, 2);
788 /* 2b. Read agreed security type */
789 len = stream_read(cfd, buf, 1);
791 /* 2c. Do VNC authentication */
793 case SECURITY_TYPE_NONE:
796 case SECURITY_TYPE_VNC_AUTH:
798 * The client encrypts the challenge with DES, using a password
799 * supplied by the user as the key.
800 * To form the key, the password is truncated to
801 * eight characters, or padded with null bytes on the right.
802 * The client then sends the resulting 16-bytes response.
805 strncpy(keystr, rc->password, PASSWD_LENGTH);
807 /* VNC clients encrypts the challenge with all the bit fields
808 * in each byte of the password mirrored.
809 * Here we flip each byte of the keystr.
811 for (i = 0; i < PASSWD_LENGTH; i++) {
812 keystr[i] = (keystr[i] & 0xF0) >> 4
813 | (keystr[i] & 0x0F) << 4;
814 keystr[i] = (keystr[i] & 0xCC) >> 2
815 | (keystr[i] & 0x33) << 2;
816 keystr[i] = (keystr[i] & 0xAA) >> 1
817 | (keystr[i] & 0x55) << 1;
820 /* Initialize a 16-byte random challenge */
821 arc4random_buf(challenge, sizeof(challenge));
822 stream_write(cfd, challenge, AUTH_LENGTH);
824 /* Receive the 16-byte challenge response */
825 stream_read(cfd, buf, AUTH_LENGTH);
827 memcpy(crypt_expected, challenge, AUTH_LENGTH);
829 /* Encrypt the Challenge with DES */
830 DES_set_key((const_DES_cblock *)keystr, &ks);
831 DES_ecb_encrypt((const_DES_cblock *)challenge,
832 (const_DES_cblock *)crypt_expected,
834 DES_ecb_encrypt((const_DES_cblock *)(challenge + PASSWD_LENGTH),
835 (const_DES_cblock *)(crypt_expected +
839 if (memcmp(crypt_expected, buf, AUTH_LENGTH) != 0) {
840 message = "Auth Failed: Invalid Password.";
846 WPRINTF(("Auth not supported, no OpenSSL in your system"));
852 /* 2d. Write back a status */
853 stream_write(cfd, &sres, 4);
856 be32enc(buf, strlen(message));
857 stream_write(cfd, buf, 4);
858 stream_write(cfd, message, strlen(message));
862 /* 3a. Read client shared-flag byte */
863 len = stream_read(cfd, buf, 1);
865 /* 4a. Write server-init info */
866 rfb_send_server_init_msg(cfd);
869 rc->zbuf = malloc(RFB_ZLIB_BUFSZ + 16);
870 assert(rc->zbuf != NULL);
873 rfb_send_screen(rc, cfd, 1);
875 perror = pthread_create(&tid, NULL, rfb_wr_thr, rc);
877 pthread_set_name_np(tid, "rfbout");
879 /* Now read in client requests. 1st byte identifies type */
881 len = read(cfd, buf, 1);
883 DPRINTF(("rfb client exiting"));
889 rfb_recv_set_pixfmt_msg(rc, cfd);
892 rfb_recv_set_encodings_msg(rc, cfd);
895 rfb_recv_update_msg(rc, cfd, 1);
898 rfb_recv_key_msg(rc, cfd);
901 rfb_recv_ptr_msg(rc, cfd);
904 rfb_recv_cuttext_msg(rc, cfd);
907 WPRINTF(("rfb unknown cli-code %d!", buf[0] & 0xff));
914 pthread_join(tid, NULL);
916 deflateEnd(&rc->zstream);
922 struct rfb_softc *rc;
930 sigaddset(&set, SIGPIPE);
931 if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0) {
932 perror("pthread_sigmask");
937 rc->enc_raw_ok = false;
938 rc->enc_zlib_ok = false;
939 rc->enc_resize_ok = false;
941 cfd = accept(rc->sfd, NULL, NULL);
943 pthread_mutex_lock(&rc->mtx);
944 pthread_cond_signal(&rc->cond);
945 pthread_mutex_unlock(&rc->mtx);
957 sse42_supported(void)
959 u_int cpu_registers[4], ecx;
961 do_cpuid(1, cpu_registers);
963 ecx = cpu_registers[2];
965 return ((ecx & CPUID2_SSE42) != 0);
969 rfb_init(char *hostname, int port, int wait, char *password)
973 struct rfb_softc *rc;
974 struct addrinfo *ai = NULL;
975 struct addrinfo hints;
977 #ifndef WITHOUT_CAPSICUM
981 rc = calloc(1, sizeof(struct rfb_softc));
983 rc->crc = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
985 rc->crc_tmp = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
987 rc->crc_width = RFB_MAX_WIDTH;
988 rc->crc_height = RFB_MAX_HEIGHT;
991 rc->password = password;
993 snprintf(servname, sizeof(servname), "%d", port ? port : 5900);
995 if (!hostname || strlen(hostname) == 0)
997 hostname = "127.0.0.1";
1002 memset(&hints, 0, sizeof(hints));
1003 hints.ai_family = AF_UNSPEC;
1004 hints.ai_socktype = SOCK_STREAM;
1005 hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV | AI_PASSIVE;
1007 if ((e = getaddrinfo(hostname, servname, &hints, &ai)) != 0) {
1008 EPRINTLN("getaddrinfo: %s", gai_strerror(e));
1012 rc->sfd = socket(ai->ai_family, ai->ai_socktype, 0);
1018 setsockopt(rc->sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
1020 if (bind(rc->sfd, ai->ai_addr, ai->ai_addrlen) < 0) {
1025 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..."));
1049 pthread_mutex_lock(&rc->mtx);
1050 pthread_cond_wait(&rc->cond, &rc->mtx);
1051 pthread_mutex_unlock(&rc->mtx);
1052 DPRINTF(("rfb client connected"));