2 * Copyright (c) 2015 Tycho Nightingale <tycho.nightingale@pluribusnetworks.com>
3 * Copyright (c) 2015 Leon Dang
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #ifndef WITHOUT_CAPSICUM
33 #include <sys/capsicum.h>
35 #include <sys/endian.h>
36 #include <sys/socket.h>
37 #include <sys/select.h>
39 #include <arpa/inet.h>
40 #include <machine/cpufunc.h>
41 #include <machine/specialreg.h>
42 #include <netinet/in.h>
48 #include <pthread_np.h>
62 #include "sockstream.h"
65 #include <openssl/des.h>
68 static int rfb_debug = 0;
69 #define DPRINTF(params) if (rfb_debug) printf params
70 #define WPRINTF(params) printf params
72 #define AUTH_LENGTH 16
73 #define PASSWD_LENGTH 8
75 #define SECURITY_TYPE_NONE 1
76 #define SECURITY_TYPE_VNC_AUTH 2
78 #define AUTH_FAILED_UNAUTH 1
79 #define AUTH_FAILED_ERROR 2
105 uint32_t *crc; /* WxH crc cells */
106 uint32_t *crc_tmp; /* buffer to store single crc row */
107 int crc_width, crc_height;
124 struct rfb_srvr_info {
127 struct rfb_pixfmt pixfmt;
131 struct rfb_pixfmt_msg {
134 struct rfb_pixfmt pixfmt;
137 #define RFB_ENCODING_RAW 0
138 #define RFB_ENCODING_ZLIB 6
139 #define RFB_ENCODING_RESIZE -223
141 #define RFB_MAX_WIDTH 2000
142 #define RFB_MAX_HEIGHT 1200
143 #define RFB_ZLIB_BUFSZ RFB_MAX_WIDTH*RFB_MAX_HEIGHT*4
145 /* percentage changes to screen before sending the entire screen */
146 #define RFB_SEND_ALL_THRESH 25
154 struct rfb_updt_msg {
177 struct rfb_srvr_updt_msg {
183 struct rfb_srvr_rect_hdr {
191 struct rfb_cuttext_msg {
199 rfb_send_server_init_msg(int cfd)
201 struct bhyvegc_image *gc_image;
202 struct rfb_srvr_info sinfo;
204 gc_image = console_get_image();
206 sinfo.width = htons(gc_image->width);
207 sinfo.height = htons(gc_image->height);
208 sinfo.pixfmt.bpp = 32;
209 sinfo.pixfmt.depth = 32;
210 sinfo.pixfmt.bigendian = 0;
211 sinfo.pixfmt.truecolor = 1;
212 sinfo.pixfmt.red_max = htons(255);
213 sinfo.pixfmt.green_max = htons(255);
214 sinfo.pixfmt.blue_max = htons(255);
215 sinfo.pixfmt.red_shift = 16;
216 sinfo.pixfmt.green_shift = 8;
217 sinfo.pixfmt.blue_shift = 0;
218 sinfo.namelen = htonl(strlen("bhyve"));
219 (void)stream_write(cfd, &sinfo, sizeof(sinfo));
220 (void)stream_write(cfd, "bhyve", strlen("bhyve"));
224 rfb_send_resize_update_msg(struct rfb_softc *rc, int cfd)
226 struct rfb_srvr_updt_msg supdt_msg;
227 struct rfb_srvr_rect_hdr srect_hdr;
229 /* Number of rectangles: 1 */
232 supdt_msg.numrects = htons(1);
233 stream_write(cfd, &supdt_msg, sizeof(struct rfb_srvr_updt_msg));
235 /* Rectangle header */
236 srect_hdr.x = htons(0);
237 srect_hdr.y = htons(0);
238 srect_hdr.width = htons(rc->width);
239 srect_hdr.height = htons(rc->height);
240 srect_hdr.encoding = htonl(RFB_ENCODING_RESIZE);
241 stream_write(cfd, &srect_hdr, sizeof(struct rfb_srvr_rect_hdr));
245 rfb_recv_set_pixfmt_msg(struct rfb_softc *rc, int cfd)
247 struct rfb_pixfmt_msg pixfmt_msg;
249 (void)stream_read(cfd, ((void *)&pixfmt_msg)+1, sizeof(pixfmt_msg)-1);
254 rfb_recv_set_encodings_msg(struct rfb_softc *rc, int cfd)
256 struct rfb_enc_msg enc_msg;
260 assert((sizeof(enc_msg) - 1) == 3);
261 (void)stream_read(cfd, ((void *)&enc_msg)+1, sizeof(enc_msg)-1);
263 for (i = 0; i < htons(enc_msg.numencs); i++) {
264 (void)stream_read(cfd, &encoding, sizeof(encoding));
265 switch (htonl(encoding)) {
266 case RFB_ENCODING_RAW:
267 rc->enc_raw_ok = true;
269 case RFB_ENCODING_ZLIB:
270 rc->enc_zlib_ok = true;
271 deflateInit(&rc->zstream, Z_BEST_SPEED);
273 case RFB_ENCODING_RESIZE:
274 rc->enc_resize_ok = true;
281 * Calculate CRC32 using SSE4.2; Intel or AMD Bulldozer+ CPUs only
283 static __inline uint32_t
284 fast_crc32(void *buf, int len, uint32_t crcval)
286 uint32_t q = len / sizeof(uint32_t);
287 uint32_t *p = (uint32_t *)buf;
291 ".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;"
293 :"0" (crcval), "c" (*p)
303 rfb_send_rect(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc,
304 int x, int y, int w, int h)
306 struct rfb_srvr_updt_msg supdt_msg;
307 struct rfb_srvr_rect_hdr srect_hdr;
309 ssize_t nwrite, total;
315 * Send a single rectangle of the given x, y, w h dimensions.
318 /* Number of rectangles: 1 */
321 supdt_msg.numrects = htons(1);
322 nwrite = stream_write(cfd, &supdt_msg,
323 sizeof(struct rfb_srvr_updt_msg));
328 /* Rectangle header */
329 srect_hdr.x = htons(x);
330 srect_hdr.y = htons(y);
331 srect_hdr.width = htons(w);
332 srect_hdr.height = htons(h);
335 w *= sizeof(uint32_t);
336 if (rc->enc_zlib_ok) {
338 rc->zstream.total_in = 0;
339 rc->zstream.total_out = 0;
340 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
341 rc->zstream.next_in = (Bytef *)p;
342 rc->zstream.avail_in = w;
343 rc->zstream.next_out = (Bytef *)zbufp;
344 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16 -
345 rc->zstream.total_out;
346 rc->zstream.data_type = Z_BINARY;
348 /* Compress with zlib */
349 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
351 WPRINTF(("zlib[rect] deflate err: %d\n", err));
352 rc->enc_zlib_ok = false;
353 deflateEnd(&rc->zstream);
356 zbufp = rc->zbuf + rc->zstream.total_out;
359 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
360 nwrite = stream_write(cfd, &srect_hdr,
361 sizeof(struct rfb_srvr_rect_hdr));
365 zlen = htonl(rc->zstream.total_out);
366 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
369 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
376 for (p = &gc->data[y * gc->width + x]; y < h; y++) {
383 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
384 nwrite = stream_write(cfd, &srect_hdr,
385 sizeof(struct rfb_srvr_rect_hdr));
389 total = stream_write(cfd, rc->zbuf, total);
395 rfb_send_all(struct rfb_softc *rc, int cfd, struct bhyvegc_image *gc)
397 struct rfb_srvr_updt_msg supdt_msg;
398 struct rfb_srvr_rect_hdr srect_hdr;
404 * Send the whole thing
407 /* Number of rectangles: 1 */
410 supdt_msg.numrects = htons(1);
411 nwrite = stream_write(cfd, &supdt_msg,
412 sizeof(struct rfb_srvr_updt_msg));
416 /* Rectangle header */
419 srect_hdr.width = htons(gc->width);
420 srect_hdr.height = htons(gc->height);
421 if (rc->enc_zlib_ok) {
422 rc->zstream.next_in = (Bytef *)gc->data;
423 rc->zstream.avail_in = gc->width * gc->height *
425 rc->zstream.next_out = (Bytef *)rc->zbuf;
426 rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16;
427 rc->zstream.data_type = Z_BINARY;
429 rc->zstream.total_in = 0;
430 rc->zstream.total_out = 0;
432 /* Compress with zlib */
433 err = deflate(&rc->zstream, Z_SYNC_FLUSH);
435 WPRINTF(("zlib deflate err: %d\n", err));
436 rc->enc_zlib_ok = false;
437 deflateEnd(&rc->zstream);
441 srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB);
442 nwrite = stream_write(cfd, &srect_hdr,
443 sizeof(struct rfb_srvr_rect_hdr));
447 zlen = htonl(rc->zstream.total_out);
448 nwrite = stream_write(cfd, &zlen, sizeof(uint32_t));
451 return (stream_write(cfd, rc->zbuf, rc->zstream.total_out));
455 srect_hdr.encoding = htonl(RFB_ENCODING_RAW);
456 nwrite = stream_write(cfd, &srect_hdr,
457 sizeof(struct rfb_srvr_rect_hdr));
461 nwrite = stream_write(cfd, gc->data,
462 gc->width * gc->height * sizeof(uint32_t));
467 #define PIX_PER_CELL 32
468 #define PIXCELL_SHIFT 5
469 #define PIXCELL_MASK 0x1F
472 rfb_send_screen(struct rfb_softc *rc, int cfd, int all)
474 struct bhyvegc_image *gc_image;
477 int celly, cellwidth;
481 int rem_x, rem_y; /* remainder for resolutions not x32 pixels ratio */
483 uint32_t *crc_p, *orig_crc;
487 gc_image = console_get_image();
489 pthread_mutex_lock(&rc->mtx);
491 pthread_mutex_unlock(&rc->mtx);
495 pthread_mutex_unlock(&rc->mtx);
500 retval = rfb_send_all(rc, cfd, gc_image);
505 * Calculate the checksum for each 32x32 cell. Send each that
506 * has changed since the last scan.
509 /* Resolution changed */
511 rc->crc_width = gc_image->width;
512 rc->crc_height = gc_image->height;
516 xcells = howmany(rc->crc_width, PIX_PER_CELL);
517 ycells = howmany(rc->crc_height, PIX_PER_CELL);
519 rem_x = w & PIXCELL_MASK;
521 rem_y = h & PIXCELL_MASK;
523 rem_y = PIX_PER_CELL;
528 * Go through all cells and calculate crc. If significant number
529 * of changes, then send entire screen.
530 * crc_tmp is dual purpose: to store the new crc and to flag as
531 * a cell that has changed.
533 crc_p = rc->crc_tmp - xcells;
534 orig_crc = rc->crc - xcells;
536 memset(rc->crc_tmp, 0, sizeof(uint32_t) * xcells * ycells);
537 for (y = 0; y < h; y++) {
538 if ((y & PIXCELL_MASK) == 0) {
543 for (x = 0; x < xcells; x++) {
545 crc_p[x] = fast_crc32(p,
546 PIX_PER_CELL * sizeof(uint32_t),
549 crc_p[x] = (uint32_t)crc32(crc_p[x],
551 PIX_PER_CELL * sizeof(uint32_t));
555 /* check for crc delta if last row in cell */
556 if ((y & PIXCELL_MASK) == PIXCELL_MASK || y == (h-1)) {
557 if (orig_crc[x] != crc_p[x]) {
558 orig_crc[x] = crc_p[x];
569 crc_p[x] = fast_crc32(p,
570 rem_x * sizeof(uint32_t),
573 crc_p[x] = (uint32_t)crc32(crc_p[x],
575 rem_x * sizeof(uint32_t));
578 if ((y & PIXCELL_MASK) == PIXCELL_MASK || y == (h-1)) {
579 if (orig_crc[x] != crc_p[x]) {
580 orig_crc[x] = crc_p[x];
590 /* If number of changes is > THRESH percent, send the whole screen */
591 if (((changes * 100) / (xcells * ycells)) >= RFB_SEND_ALL_THRESH) {
592 retval = rfb_send_all(rc, cfd, gc_image);
596 /* Go through all cells, and send only changed ones */
598 for (y = 0; y < h; y += PIX_PER_CELL) {
599 /* previous cell's row */
600 celly = (y >> PIXCELL_SHIFT);
602 /* Delta check crc to previous set */
603 for (x = 0; x < xcells; x++) {
607 if (x == (xcells - 1) && rem_x > 0)
610 cellwidth = PIX_PER_CELL;
611 nwrite = rfb_send_rect(rc, cfd,
614 celly * PIX_PER_CELL,
616 y + PIX_PER_CELL >= h ? rem_y : PIX_PER_CELL);
626 pthread_mutex_lock(&rc->mtx);
628 pthread_mutex_unlock(&rc->mtx);
635 rfb_recv_update_msg(struct rfb_softc *rc, int cfd, int discardonly)
637 struct rfb_updt_msg updt_msg;
638 struct bhyvegc_image *gc_image;
640 (void)stream_read(cfd, ((void *)&updt_msg) + 1 , sizeof(updt_msg) - 1);
643 gc_image = console_get_image();
645 updt_msg.x = htons(updt_msg.x);
646 updt_msg.y = htons(updt_msg.y);
647 updt_msg.width = htons(updt_msg.width);
648 updt_msg.height = htons(updt_msg.height);
650 if (updt_msg.width != gc_image->width ||
651 updt_msg.height != gc_image->height) {
652 rc->width = gc_image->width;
653 rc->height = gc_image->height;
654 if (rc->enc_resize_ok)
655 rfb_send_resize_update_msg(rc, cfd);
661 rfb_send_screen(rc, cfd, 1);
665 rfb_recv_key_msg(struct rfb_softc *rc, int cfd)
667 struct rfb_key_msg key_msg;
669 (void)stream_read(cfd, ((void *)&key_msg) + 1, sizeof(key_msg) - 1);
671 console_key_event(key_msg.down, htonl(key_msg.code));
675 rfb_recv_ptr_msg(struct rfb_softc *rc, int cfd)
677 struct rfb_ptr_msg ptr_msg;
679 (void)stream_read(cfd, ((void *)&ptr_msg) + 1, sizeof(ptr_msg) - 1);
681 console_ptr_event(ptr_msg.button, htons(ptr_msg.x), htons(ptr_msg.y));
685 rfb_recv_cuttext_msg(struct rfb_softc *rc, int cfd)
687 struct rfb_cuttext_msg ct_msg;
688 unsigned char buf[32];
691 len = stream_read(cfd, ((void *)&ct_msg) + 1, sizeof(ct_msg) - 1);
692 ct_msg.length = htonl(ct_msg.length);
693 while (ct_msg.length > 0) {
694 len = stream_read(cfd, buf, ct_msg.length > sizeof(buf) ?
695 sizeof(buf) : ct_msg.length);
696 ct_msg.length -= len;
701 timeval_delta(struct timeval *prev, struct timeval *now)
704 n1 = now->tv_sec * 1000000 + now->tv_usec;
705 n2 = prev->tv_sec * 1000000 + prev->tv_usec;
710 rfb_wr_thr(void *arg)
712 struct rfb_softc *rc;
715 struct timeval prev_tv;
725 while (rc->cfd >= 0) {
731 err = select(cfd+1, &rfds, NULL, NULL, &tv);
735 /* Determine if its time to push screen; ~24hz */
736 gettimeofday(&tv, NULL);
737 tdiff = timeval_delta(&prev_tv, &tv);
739 prev_tv.tv_sec = tv.tv_sec;
740 prev_tv.tv_usec = tv.tv_usec;
741 if (rfb_send_screen(rc, cfd, 0) <= 0) {
746 usleep(40000 - tdiff);
754 rfb_handle(struct rfb_softc *rc, int cfd)
756 const char *vbuf = "RFB 003.008\n";
757 unsigned char buf[80];
758 unsigned char *message = NULL;
761 unsigned char challenge[AUTH_LENGTH];
762 unsigned char keystr[PASSWD_LENGTH];
763 unsigned char crypt_expected[AUTH_LENGTH];
776 /* 1a. Send server version */
777 stream_write(cfd, vbuf, strlen(vbuf));
779 /* 1b. Read client version */
780 len = read(cfd, buf, sizeof(buf));
782 /* 2a. Send security type */
786 buf[1] = SECURITY_TYPE_VNC_AUTH;
788 buf[1] = SECURITY_TYPE_NONE;
790 buf[1] = SECURITY_TYPE_NONE;
793 stream_write(cfd, buf, 2);
795 /* 2b. Read agreed security type */
796 len = stream_read(cfd, buf, 1);
798 /* 2c. Do VNC authentication */
800 case SECURITY_TYPE_NONE:
803 case SECURITY_TYPE_VNC_AUTH:
805 * The client encrypts the challenge with DES, using a password
806 * supplied by the user as the key.
807 * To form the key, the password is truncated to
808 * eight characters, or padded with null bytes on the right.
809 * The client then sends the resulting 16-bytes response.
812 strncpy(keystr, rc->password, PASSWD_LENGTH);
814 /* VNC clients encrypts the challenge with all the bit fields
815 * in each byte of the password mirrored.
816 * Here we flip each byte of the keystr.
818 for (i = 0; i < PASSWD_LENGTH; i++) {
819 keystr[i] = (keystr[i] & 0xF0) >> 4
820 | (keystr[i] & 0x0F) << 4;
821 keystr[i] = (keystr[i] & 0xCC) >> 2
822 | (keystr[i] & 0x33) << 2;
823 keystr[i] = (keystr[i] & 0xAA) >> 1
824 | (keystr[i] & 0x55) << 1;
827 /* Initialize a 16-byte random challenge */
828 arc4random_buf(challenge, sizeof(challenge));
829 stream_write(cfd, challenge, AUTH_LENGTH);
831 /* Receive the 16-byte challenge response */
832 stream_read(cfd, buf, AUTH_LENGTH);
834 memcpy(crypt_expected, challenge, AUTH_LENGTH);
836 /* Encrypt the Challenge with DES */
837 DES_set_key((const_DES_cblock *)keystr, &ks);
838 DES_ecb_encrypt((const_DES_cblock *)challenge,
839 (const_DES_cblock *)crypt_expected,
841 DES_ecb_encrypt((const_DES_cblock *)(challenge + PASSWD_LENGTH),
842 (const_DES_cblock *)(crypt_expected +
846 if (memcmp(crypt_expected, buf, AUTH_LENGTH) != 0) {
847 message = "Auth Failed: Invalid Password.";
853 WPRINTF(("Auth not supported, no OpenSSL in your system"));
859 /* 2d. Write back a status */
860 stream_write(cfd, &sres, 4);
863 be32enc(buf, strlen(message));
864 stream_write(cfd, buf, 4);
865 stream_write(cfd, message, strlen(message));
869 /* 3a. Read client shared-flag byte */
870 len = stream_read(cfd, buf, 1);
872 /* 4a. Write server-init info */
873 rfb_send_server_init_msg(cfd);
876 rc->zbuf = malloc(RFB_ZLIB_BUFSZ + 16);
877 assert(rc->zbuf != NULL);
880 rfb_send_screen(rc, cfd, 1);
882 perror = pthread_create(&tid, NULL, rfb_wr_thr, rc);
884 pthread_set_name_np(tid, "rfbout");
886 /* Now read in client requests. 1st byte identifies type */
888 len = read(cfd, buf, 1);
890 DPRINTF(("rfb client exiting\r\n"));
896 rfb_recv_set_pixfmt_msg(rc, cfd);
899 rfb_recv_set_encodings_msg(rc, cfd);
902 rfb_recv_update_msg(rc, cfd, 1);
905 rfb_recv_key_msg(rc, cfd);
908 rfb_recv_ptr_msg(rc, cfd);
911 rfb_recv_cuttext_msg(rc, cfd);
914 WPRINTF(("rfb unknown cli-code %d!\n", buf[0] & 0xff));
921 pthread_join(tid, NULL);
923 deflateEnd(&rc->zstream);
929 struct rfb_softc *rc;
937 sigaddset(&set, SIGPIPE);
938 if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0) {
939 perror("pthread_sigmask");
944 rc->enc_raw_ok = false;
945 rc->enc_zlib_ok = false;
946 rc->enc_resize_ok = false;
948 cfd = accept(rc->sfd, NULL, NULL);
950 pthread_mutex_lock(&rc->mtx);
951 pthread_cond_signal(&rc->cond);
952 pthread_mutex_unlock(&rc->mtx);
964 sse42_supported(void)
966 u_int cpu_registers[4], ecx;
968 do_cpuid(1, cpu_registers);
970 ecx = cpu_registers[2];
972 return ((ecx & CPUID2_SSE42) != 0);
976 rfb_init(char *hostname, int port, int wait, char *password)
978 struct rfb_softc *rc;
979 struct sockaddr_in sin;
981 #ifndef WITHOUT_CAPSICUM
985 rc = calloc(1, sizeof(struct rfb_softc));
987 rc->crc = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
989 rc->crc_tmp = calloc(howmany(RFB_MAX_WIDTH * RFB_MAX_HEIGHT, 32),
991 rc->crc_width = RFB_MAX_WIDTH;
992 rc->crc_height = RFB_MAX_HEIGHT;
994 rc->password = password;
996 rc->sfd = socket(AF_INET, SOCK_STREAM, 0);
1002 setsockopt(rc->sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
1004 sin.sin_len = sizeof(sin);
1005 sin.sin_family = AF_INET;
1006 sin.sin_port = port ? htons(port) : htons(5900);
1007 if (hostname && strlen(hostname) > 0)
1008 inet_pton(AF_INET, hostname, &(sin.sin_addr));
1010 sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
1012 if (bind(rc->sfd, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
1017 if (listen(rc->sfd, 1) < 0) {
1022 #ifndef WITHOUT_CAPSICUM
1023 cap_rights_init(&rights, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE);
1024 if (cap_rights_limit(rc->sfd, &rights) == -1 && errno != ENOSYS)
1025 errx(EX_OSERR, "Unable to apply rights for sandbox");
1028 rc->hw_crc = sse42_supported();
1030 rc->conn_wait = wait;
1032 pthread_mutex_init(&rc->mtx, NULL);
1033 pthread_cond_init(&rc->cond, NULL);
1036 pthread_create(&rc->tid, NULL, rfb_thr, rc);
1037 pthread_set_name_np(rc->tid, "rfb");
1040 DPRINTF(("Waiting for rfb client...\n"));
1041 pthread_mutex_lock(&rc->mtx);
1042 pthread_cond_wait(&rc->cond, &rc->mtx);
1043 pthread_mutex_unlock(&rc->mtx);