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 #include <sys/endian.h>
35 #ifndef WITHOUT_CAPSICUM
36 #include <sys/capsicum.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>
51 #include <pthread_np.h>
65 #include "sockstream.h"
68 #include <openssl/des.h>
71 static int rfb_debug = 0;
72 #define DPRINTF(params) if (rfb_debug) printf params
73 #define WPRINTF(params) printf params
75 #define AUTH_LENGTH 16
76 #define PASSWD_LENGTH 8
78 #define SECURITY_TYPE_NONE 1
79 #define SECURITY_TYPE_VNC_AUTH 2
81 #define AUTH_FAILED_UNAUTH 1
82 #define AUTH_FAILED_ERROR 2
108 uint32_t *crc; /* WxH crc cells */
109 uint32_t *crc_tmp; /* buffer to store single crc row */
110 int crc_width, crc_height;
127 struct rfb_srvr_info {
130 struct rfb_pixfmt pixfmt;
134 struct rfb_pixfmt_msg {
137 struct rfb_pixfmt pixfmt;
140 #define RFB_ENCODING_RAW 0
141 #define RFB_ENCODING_ZLIB 6
142 #define RFB_ENCODING_RESIZE -223
144 #define RFB_MAX_WIDTH 2000
145 #define RFB_MAX_HEIGHT 1200
146 #define RFB_ZLIB_BUFSZ RFB_MAX_WIDTH*RFB_MAX_HEIGHT*4
148 /* percentage changes to screen before sending the entire screen */
149 #define RFB_SEND_ALL_THRESH 25
157 struct rfb_updt_msg {
180 struct rfb_srvr_updt_msg {
186 struct rfb_srvr_rect_hdr {
194 struct rfb_cuttext_msg {
202 rfb_send_server_init_msg(int cfd)
204 struct bhyvegc_image *gc_image;
205 struct rfb_srvr_info sinfo;
207 gc_image = console_get_image();
209 sinfo.width = htons(gc_image->width);
210 sinfo.height = htons(gc_image->height);
211 sinfo.pixfmt.bpp = 32;
212 sinfo.pixfmt.depth = 32;
213 sinfo.pixfmt.bigendian = 0;
214 sinfo.pixfmt.truecolor = 1;
215 sinfo.pixfmt.red_max = htons(255);
216 sinfo.pixfmt.green_max = htons(255);
217 sinfo.pixfmt.blue_max = htons(255);
218 sinfo.pixfmt.red_shift = 16;
219 sinfo.pixfmt.green_shift = 8;
220 sinfo.pixfmt.blue_shift = 0;
221 sinfo.namelen = htonl(strlen("bhyve"));
222 (void)stream_write(cfd, &sinfo, sizeof(sinfo));
223 (void)stream_write(cfd, "bhyve", strlen("bhyve"));
227 rfb_send_resize_update_msg(struct rfb_softc *rc, int cfd)
229 struct rfb_srvr_updt_msg supdt_msg;
230 struct rfb_srvr_rect_hdr srect_hdr;
232 /* Number of rectangles: 1 */
235 supdt_msg.numrects = htons(1);
236 stream_write(cfd, &supdt_msg, sizeof(struct rfb_srvr_updt_msg));
238 /* Rectangle header */
239 srect_hdr.x = htons(0);
240 srect_hdr.y = htons(0);
241 srect_hdr.width = htons(rc->width);
242 srect_hdr.height = htons(rc->height);
243 srect_hdr.encoding = htonl(RFB_ENCODING_RESIZE);
244 stream_write(cfd, &srect_hdr, sizeof(struct rfb_srvr_rect_hdr));
248 rfb_recv_set_pixfmt_msg(struct rfb_softc *rc, int cfd)
250 struct rfb_pixfmt_msg pixfmt_msg;
252 (void)stream_read(cfd, ((void *)&pixfmt_msg)+1, sizeof(pixfmt_msg)-1);
257 rfb_recv_set_encodings_msg(struct rfb_softc *rc, int cfd)
259 struct rfb_enc_msg enc_msg;
263 assert((sizeof(enc_msg) - 1) == 3);
264 (void)stream_read(cfd, ((void *)&enc_msg)+1, sizeof(enc_msg)-1);
266 for (i = 0; i < htons(enc_msg.numencs); i++) {
267 (void)stream_read(cfd, &encoding, sizeof(encoding));
268 switch (htonl(encoding)) {
269 case RFB_ENCODING_RAW:
270 rc->enc_raw_ok = true;
272 case RFB_ENCODING_ZLIB:
273 rc->enc_zlib_ok = true;
274 deflateInit(&rc->zstream, Z_BEST_SPEED);
276 case RFB_ENCODING_RESIZE:
277 rc->enc_resize_ok = true;
284 * Calculate CRC32 using SSE4.2; Intel or AMD Bulldozer+ CPUs only
286 static __inline uint32_t
287 fast_crc32(void *buf, int len, uint32_t crcval)
289 uint32_t q = len / sizeof(uint32_t);
290 uint32_t *p = (uint32_t *)buf;
294 ".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;"
296 :"0" (crcval), "c" (*p)
306 rfb_send_rect(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc,
307 int x, int y, int w, int h)
309 struct rfb_srvr_updt_msg supdt_msg;
310 struct rfb_srvr_rect_hdr srect_hdr;
312 ssize_t nwrite, total;
318 * Send a single rectangle of the given x, y, w h dimensions.
321 /* Number of rectangles: 1 */
324 supdt_msg.numrects = htons(1);
325 nwrite = stream_write(cfd, &supdt_msg,
326 sizeof(struct rfb_srvr_updt_msg));
331 /* Rectangle header */
332 srect_hdr.x = htons(x);
333 srect_hdr.y = htons(y);
334 srect_hdr.width = htons(w);
335 srect_hdr.height = htons(h);
338 w *= sizeof(uint32_t);
339 if (rc->enc_zlib_ok) {
341 rc->zstream.total_in = 0;
342 rc->zstream.total_out = 0;
343 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
344 rc->zstream.next_in = (Bytef *)p;
345 rc->zstream.avail_in = w;
346 rc->zstream.next_out = (Bytef *)zbufp;
347 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16 -
348 rc->zstream.total_out;
349 rc->zstream.data_type = Z_BINARY;
351 /* Compress with zlib */
352 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
354 WPRINTF(("zlib[rect] deflate err: %d\n", err));
355 rc->enc_zlib_ok = false;
356 deflateEnd(&rc->zstream);
359 zbufp = rc->zbuf + rc->zstream.total_out;
362 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
363 nwrite = stream_write(cfd, &srect_hdr,
364 sizeof(struct rfb_srvr_rect_hdr));
368 zlen = htonl(rc->zstream.total_out);
369 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
372 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
379 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
386 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
387 nwrite = stream_write(cfd, &srect_hdr,
388 sizeof(struct rfb_srvr_rect_hdr));
392 total = stream_write(cfd, rc->zbuf, total);
398 rfb_send_all(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc)
400 struct rfb_srvr_updt_msg supdt_msg;
401 struct rfb_srvr_rect_hdr srect_hdr;
407 * Send the whole thing
410 /* Number of rectangles: 1 */
413 supdt_msg.numrects = htons(1);
414 nwrite = stream_write(cfd, &supdt_msg,
415 sizeof(struct rfb_srvr_updt_msg));
419 /* Rectangle header */
422 srect_hdr.width = htons(gc->width);
423 srect_hdr.height = htons(gc->height);
424 if (rc->enc_zlib_ok) {
425 rc->zstream.next_in = (Bytef *)gc->data;
426 rc->zstream.avail_in = gc->width * gc->height *
428 rc->zstream.next_out = (Bytef *)rc->zbuf;
429 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16;
430 rc->zstream.data_type = Z_BINARY;
432 rc->zstream.total_in = 0;
433 rc->zstream.total_out = 0;
435 /* Compress with zlib */
436 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
438 WPRINTF(("zlib deflate err: %d\n", err));
439 rc->enc_zlib_ok = false;
440 deflateEnd(&rc->zstream);
444 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
445 nwrite = stream_write(cfd, &srect_hdr,
446 sizeof(struct rfb_srvr_rect_hdr));
450 zlen = htonl(rc->zstream.total_out);
451 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
454 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
458 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
459 nwrite = stream_write(cfd, &srect_hdr,
460 sizeof(struct rfb_srvr_rect_hdr));
464 nwrite = stream_write(cfd, gc->data,
465 gc->width * gc->height * sizeof(uint32_t));
470 #define PIX_PER_CELL 32
471 #define PIXCELL_SHIFT 5
472 #define PIXCELL_MASK 0x1F
475 rfb_send_screen(struct rfb_softc *rc, int cfd, int all)
477 struct bhyvegc_image *gc_image;
480 int celly, cellwidth;
484 int rem_x, rem_y; /* remainder for resolutions not x32 pixels ratio */
486 uint32_t *crc_p, *orig_crc;
490 gc_image = console_get_image();
492 pthread_mutex_lock(&rc->mtx);
494 pthread_mutex_unlock(&rc->mtx);
498 pthread_mutex_unlock(&rc->mtx);
503 retval = rfb_send_all(rc, cfd, gc_image);
508 * Calculate the checksum for each 32x32 cell. Send each that
509 * has changed since the last scan.
512 /* Resolution changed */
514 rc->crc_width = gc_image->width;
515 rc->crc_height = gc_image->height;
519 xcells = howmany(rc->crc_width, PIX_PER_CELL);
520 ycells = howmany(rc->crc_height, PIX_PER_CELL);
522 rem_x = w & PIXCELL_MASK;
524 rem_y = h & PIXCELL_MASK;
526 rem_y = PIX_PER_CELL;
531 * Go through all cells and calculate crc. If significant number
532 * of changes, then send entire screen.
533 * crc_tmp is dual purpose: to store the new crc and to flag as
534 * a cell that has changed.
536 crc_p = rc->crc_tmp - xcells;
537 orig_crc = rc->crc - xcells;
539 memset(rc->crc_tmp, 0, sizeof(uint32_t) * xcells * ycells);
540 for (y = 0; y < h; y++) {
541 if ((y & PIXCELL_MASK) == 0) {
546 for (x = 0; x < xcells; x++) {
547 if (x == (xcells - 1) && rem_x > 0)
550 cellwidth = PIX_PER_CELL;
553 crc_p[x] = fast_crc32(p,
554 cellwidth * sizeof(uint32_t),
557 crc_p[x] = (uint32_t)crc32(crc_p[x],
559 cellwidth * sizeof(uint32_t));
563 /* check for crc delta if last row in cell */
564 if ((y & PIXCELL_MASK) == PIXCELL_MASK || y == (h-1)) {
565 if (orig_crc[x] != crc_p[x]) {
566 orig_crc[x] = crc_p[x];
576 /* If number of changes is > THRESH percent, send the whole screen */
577 if (((changes * 100) / (xcells * ycells)) >= RFB_SEND_ALL_THRESH) {
578 retval = rfb_send_all(rc, cfd, gc_image);
582 /* Go through all cells, and send only changed ones */
584 for (y = 0; y < h; y += PIX_PER_CELL) {
585 /* previous cell's row */
586 celly = (y >> PIXCELL_SHIFT);
588 /* Delta check crc to previous set */
589 for (x = 0; x < xcells; x++) {
593 if (x == (xcells - 1) && rem_x > 0)
596 cellwidth = PIX_PER_CELL;
597 nwrite = rfb_send_rect(rc, cfd,
600 celly * PIX_PER_CELL,
602 y + PIX_PER_CELL >= h ? rem_y : PIX_PER_CELL);
612 pthread_mutex_lock(&rc->mtx);
614 pthread_mutex_unlock(&rc->mtx);
621 rfb_recv_update_msg(struct rfb_softc *rc, int cfd, int discardonly)
623 struct rfb_updt_msg updt_msg;
624 struct bhyvegc_image *gc_image;
626 (void)stream_read(cfd, ((void *)&updt_msg) + 1 , sizeof(updt_msg) - 1);
629 gc_image = console_get_image();
631 updt_msg.x = htons(updt_msg.x);
632 updt_msg.y = htons(updt_msg.y);
633 updt_msg.width = htons(updt_msg.width);
634 updt_msg.height = htons(updt_msg.height);
636 if (updt_msg.width != gc_image->width ||
637 updt_msg.height != gc_image->height) {
638 rc->width = gc_image->width;
639 rc->height = gc_image->height;
640 if (rc->enc_resize_ok)
641 rfb_send_resize_update_msg(rc, cfd);
647 rfb_send_screen(rc, cfd, 1);
651 rfb_recv_key_msg(struct rfb_softc *rc, int cfd)
653 struct rfb_key_msg key_msg;
655 (void)stream_read(cfd, ((void *)&key_msg) + 1, sizeof(key_msg) - 1);
657 console_key_event(key_msg.down, htonl(key_msg.code));
661 rfb_recv_ptr_msg(struct rfb_softc *rc, int cfd)
663 struct rfb_ptr_msg ptr_msg;
665 (void)stream_read(cfd, ((void *)&ptr_msg) + 1, sizeof(ptr_msg) - 1);
667 console_ptr_event(ptr_msg.button, htons(ptr_msg.x), htons(ptr_msg.y));
671 rfb_recv_cuttext_msg(struct rfb_softc *rc, int cfd)
673 struct rfb_cuttext_msg ct_msg;
674 unsigned char buf[32];
677 len = stream_read(cfd, ((void *)&ct_msg) + 1, sizeof(ct_msg) - 1);
678 ct_msg.length = htonl(ct_msg.length);
679 while (ct_msg.length > 0) {
680 len = stream_read(cfd, buf, ct_msg.length > sizeof(buf) ?
681 sizeof(buf) : ct_msg.length);
682 ct_msg.length -= len;
687 timeval_delta(struct timeval *prev, struct timeval *now)
690 n1 = now->tv_sec * 1000000 + now->tv_usec;
691 n2 = prev->tv_sec * 1000000 + prev->tv_usec;
696 rfb_wr_thr(void *arg)
698 struct rfb_softc *rc;
701 struct timeval prev_tv;
711 while (rc->cfd >= 0) {
717 err = select(cfd+1, &rfds, NULL, NULL, &tv);
721 /* Determine if its time to push screen; ~24hz */
722 gettimeofday(&tv, NULL);
723 tdiff = timeval_delta(&prev_tv, &tv);
725 prev_tv.tv_sec = tv.tv_sec;
726 prev_tv.tv_usec = tv.tv_usec;
727 if (rfb_send_screen(rc, cfd, 0) <= 0) {
732 usleep(40000 - tdiff);
740 rfb_handle(struct rfb_softc *rc, int cfd)
742 const char *vbuf = "RFB 003.008\n";
743 unsigned char buf[80];
744 unsigned char *message = NULL;
747 unsigned char challenge[AUTH_LENGTH];
748 unsigned char keystr[PASSWD_LENGTH];
749 unsigned char crypt_expected[AUTH_LENGTH];
762 /* 1a. Send server version */
763 stream_write(cfd, vbuf, strlen(vbuf));
765 /* 1b. Read client version */
766 len = read(cfd, buf, sizeof(buf));
768 /* 2a. Send security type */
772 buf[1] = SECURITY_TYPE_VNC_AUTH;
774 buf[1] = SECURITY_TYPE_NONE;
776 buf[1] = SECURITY_TYPE_NONE;
779 stream_write(cfd, buf, 2);
781 /* 2b. Read agreed security type */
782 len = stream_read(cfd, buf, 1);
784 /* 2c. Do VNC authentication */
786 case SECURITY_TYPE_NONE:
789 case SECURITY_TYPE_VNC_AUTH:
791 * The client encrypts the challenge with DES, using a password
792 * supplied by the user as the key.
793 * To form the key, the password is truncated to
794 * eight characters, or padded with null bytes on the right.
795 * The client then sends the resulting 16-bytes response.
798 strncpy(keystr, rc->password, PASSWD_LENGTH);
800 /* VNC clients encrypts the challenge with all the bit fields
801 * in each byte of the password mirrored.
802 * Here we flip each byte of the keystr.
804 for (i = 0; i < PASSWD_LENGTH; i++) {
805 keystr[i] = (keystr[i] & 0xF0) >> 4
806 | (keystr[i] & 0x0F) << 4;
807 keystr[i] = (keystr[i] & 0xCC) >> 2
808 | (keystr[i] & 0x33) << 2;
809 keystr[i] = (keystr[i] & 0xAA) >> 1
810 | (keystr[i] & 0x55) << 1;
813 /* Initialize a 16-byte random challenge */
814 arc4random_buf(challenge, sizeof(challenge));
815 stream_write(cfd, challenge, AUTH_LENGTH);
817 /* Receive the 16-byte challenge response */
818 stream_read(cfd, buf, AUTH_LENGTH);
820 memcpy(crypt_expected, challenge, AUTH_LENGTH);
822 /* Encrypt the Challenge with DES */
823 DES_set_key((const_DES_cblock *)keystr, &ks);
824 DES_ecb_encrypt((const_DES_cblock *)challenge,
825 (const_DES_cblock *)crypt_expected,
827 DES_ecb_encrypt((const_DES_cblock *)(challenge + PASSWD_LENGTH),
828 (const_DES_cblock *)(crypt_expected +
832 if (memcmp(crypt_expected, buf, AUTH_LENGTH) != 0) {
833 message = "Auth Failed: Invalid Password.";
839 WPRINTF(("Auth not supported, no OpenSSL in your system"));
845 /* 2d. Write back a status */
846 stream_write(cfd, &sres, 4);
849 be32enc(buf, strlen(message));
850 stream_write(cfd, buf, 4);
851 stream_write(cfd, message, strlen(message));
855 /* 3a. Read client shared-flag byte */
856 len = stream_read(cfd, buf, 1);
858 /* 4a. Write server-init info */
859 rfb_send_server_init_msg(cfd);
862 rc->zbuf = malloc(RFB_ZLIB_BUFSZ + 16);
863 assert(rc->zbuf != NULL);
866 rfb_send_screen(rc, cfd, 1);
868 perror = pthread_create(&tid, NULL, rfb_wr_thr, rc);
870 pthread_set_name_np(tid, "rfbout");
872 /* Now read in client requests. 1st byte identifies type */
874 len = read(cfd, buf, 1);
876 DPRINTF(("rfb client exiting\r\n"));
882 rfb_recv_set_pixfmt_msg(rc, cfd);
885 rfb_recv_set_encodings_msg(rc, cfd);
888 rfb_recv_update_msg(rc, cfd, 1);
891 rfb_recv_key_msg(rc, cfd);
894 rfb_recv_ptr_msg(rc, cfd);
897 rfb_recv_cuttext_msg(rc, cfd);
900 WPRINTF(("rfb unknown cli-code %d!\n", buf[0] & 0xff));
907 pthread_join(tid, NULL);
909 deflateEnd(&rc->zstream);
915 struct rfb_softc *rc;
923 sigaddset(&set, SIGPIPE);
924 if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0) {
925 perror("pthread_sigmask");
930 rc->enc_raw_ok = false;
931 rc->enc_zlib_ok = false;
932 rc->enc_resize_ok = false;
934 cfd = accept(rc->sfd, NULL, NULL);
936 pthread_mutex_lock(&rc->mtx);
937 pthread_cond_signal(&rc->cond);
938 pthread_mutex_unlock(&rc->mtx);
950 sse42_supported(void)
952 u_int cpu_registers[4], ecx;
954 do_cpuid(1, cpu_registers);
956 ecx = cpu_registers[2];
958 return ((ecx & CPUID2_SSE42) != 0);
962 rfb_init(char *hostname, int port, int wait, char *password)
966 struct rfb_softc *rc;
968 struct addrinfo hints;
970 #ifndef WITHOUT_CAPSICUM
974 rc = calloc(1, sizeof(struct rfb_softc));
976 rc->crc = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
978 rc->crc_tmp = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
980 rc->crc_width = RFB_MAX_WIDTH;
981 rc->crc_height = RFB_MAX_HEIGHT;
983 rc->password = password;
985 snprintf(servname, sizeof(servname), "%d", port ? port : 5900);
987 if (!hostname || strlen(hostname) == 0)
989 hostname = "127.0.0.1";
994 memset(&hints, 0, sizeof(hints));
995 hints.ai_family = AF_UNSPEC;
996 hints.ai_socktype = SOCK_STREAM;
997 hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV | AI_PASSIVE;
999 if ((e = getaddrinfo(hostname, servname, &hints, &ai)) != 0) {
1000 fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
1004 rc->sfd = socket(ai->ai_family, ai->ai_socktype, 0);
1011 setsockopt(rc->sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
1013 if (bind(rc->sfd, ai->ai_addr, ai->ai_addrlen) < 0) {
1019 if (listen(rc->sfd, 1) < 0) {
1025 #ifndef WITHOUT_CAPSICUM
1026 cap_rights_init(&rights, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE);
1027 if (cap_rights_limit(rc->sfd, &rights) == -1 && errno != ENOSYS)
1028 errx(EX_OSERR, "Unable to apply rights for sandbox");
1031 rc->hw_crc = sse42_supported();
1033 rc->conn_wait = wait;
1035 pthread_mutex_init(&rc->mtx, NULL);
1036 pthread_cond_init(&rc->cond, NULL);
1039 pthread_create(&rc->tid, NULL, rfb_thr, rc);
1040 pthread_set_name_np(rc->tid, "rfb");
1043 DPRINTF(("Waiting for rfb client...\n"));
1044 pthread_mutex_lock(&rc->mtx);
1045 pthread_cond_wait(&rc->cond, &rc->mtx);
1046 pthread_mutex_unlock(&rc->mtx);