Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/rfb.c
Show First 20 Lines • Show All 350 Lines • ▼ Show 20 Lines | for (p = &gc->data[y * gc->width + x]; y < h; y++) { | ||||
rc->zstream.next_out = (Bytef *)zbufp; | rc->zstream.next_out = (Bytef *)zbufp; | ||||
rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16 - | rc->zstream.avail_out = RFB_ZLIB_BUFSZ + 16 - | ||||
rc->zstream.total_out; | rc->zstream.total_out; | ||||
rc->zstream.data_type = Z_BINARY; | rc->zstream.data_type = Z_BINARY; | ||||
/* Compress with zlib */ | /* Compress with zlib */ | ||||
err = deflate(&rc->zstream, Z_SYNC_FLUSH); | err = deflate(&rc->zstream, Z_SYNC_FLUSH); | ||||
if (err != Z_OK) { | if (err != Z_OK) { | ||||
WPRINTF(("zlib[rect] deflate err: %d\n", err)); | WPRINTF(("zlib[rect] deflate err: %d\n\r", err)); | ||||
rc->enc_zlib_ok = false; | rc->enc_zlib_ok = false; | ||||
deflateEnd(&rc->zstream); | deflateEnd(&rc->zstream); | ||||
goto doraw; | goto doraw; | ||||
} | } | ||||
zbufp = rc->zbuf + rc->zstream.total_out; | zbufp = rc->zbuf + rc->zstream.total_out; | ||||
p += gc->width; | p += gc->width; | ||||
} | } | ||||
srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB); | srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB); | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if (rc->enc_zlib_ok) { | ||||
rc->zstream.data_type = Z_BINARY; | rc->zstream.data_type = Z_BINARY; | ||||
rc->zstream.total_in = 0; | rc->zstream.total_in = 0; | ||||
rc->zstream.total_out = 0; | rc->zstream.total_out = 0; | ||||
/* Compress with zlib */ | /* Compress with zlib */ | ||||
err = deflate(&rc->zstream, Z_SYNC_FLUSH); | err = deflate(&rc->zstream, Z_SYNC_FLUSH); | ||||
if (err != Z_OK) { | if (err != Z_OK) { | ||||
WPRINTF(("zlib deflate err: %d\n", err)); | WPRINTF(("zlib deflate err: %d\n\r", err)); | ||||
rc->enc_zlib_ok = false; | rc->enc_zlib_ok = false; | ||||
deflateEnd(&rc->zstream); | deflateEnd(&rc->zstream); | ||||
goto doraw; | goto doraw; | ||||
} | } | ||||
srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB); | srect_hdr.encoding = htonl(RFB_ENCODING_ZLIB); | ||||
nwrite = stream_write(cfd, &srect_hdr, | nwrite = stream_write(cfd, &srect_hdr, | ||||
sizeof(struct rfb_srvr_rect_hdr)); | sizeof(struct rfb_srvr_rect_hdr)); | ||||
▲ Show 20 Lines • Show All 287 Lines • ▼ Show 20 Lines | rfb_wr_thr(void *arg) | ||||
} | } | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
void | void | ||||
rfb_handle(struct rfb_softc *rc, int cfd) | rfb_handle(struct rfb_softc *rc, int cfd) | ||||
{ | { | ||||
const char *vbuf = "RFB 003.008\n"; | const char *vbuf = "RFB 003.008\n\r"; | ||||
unsigned char buf[80]; | unsigned char buf[80]; | ||||
unsigned char *message = NULL; | unsigned char *message = NULL; | ||||
#ifndef NO_OPENSSL | #ifndef NO_OPENSSL | ||||
unsigned char challenge[AUTH_LENGTH]; | unsigned char challenge[AUTH_LENGTH]; | ||||
unsigned char keystr[PASSWD_LENGTH]; | unsigned char keystr[PASSWD_LENGTH]; | ||||
unsigned char crypt_expected[AUTH_LENGTH]; | unsigned char crypt_expected[AUTH_LENGTH]; | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | #endif | ||||
perror = pthread_create(&tid, NULL, rfb_wr_thr, rc); | perror = pthread_create(&tid, NULL, rfb_wr_thr, rc); | ||||
if (perror == 0) | if (perror == 0) | ||||
pthread_set_name_np(tid, "rfbout"); | pthread_set_name_np(tid, "rfbout"); | ||||
/* Now read in client requests. 1st byte identifies type */ | /* Now read in client requests. 1st byte identifies type */ | ||||
for (;;) { | for (;;) { | ||||
len = read(cfd, buf, 1); | len = read(cfd, buf, 1); | ||||
if (len <= 0) { | if (len <= 0) { | ||||
DPRINTF(("rfb client exiting\r\n")); | DPRINTF(("rfb client exiting\n\r")); | ||||
break; | break; | ||||
} | } | ||||
switch (buf[0]) { | switch (buf[0]) { | ||||
case 0: | case 0: | ||||
rfb_recv_set_pixfmt_msg(rc, cfd); | rfb_recv_set_pixfmt_msg(rc, cfd); | ||||
break; | break; | ||||
case 2: | case 2: | ||||
rfb_recv_set_encodings_msg(rc, cfd); | rfb_recv_set_encodings_msg(rc, cfd); | ||||
break; | break; | ||||
case 3: | case 3: | ||||
rfb_recv_update_msg(rc, cfd, 1); | rfb_recv_update_msg(rc, cfd, 1); | ||||
break; | break; | ||||
case 4: | case 4: | ||||
rfb_recv_key_msg(rc, cfd); | rfb_recv_key_msg(rc, cfd); | ||||
break; | break; | ||||
case 5: | case 5: | ||||
rfb_recv_ptr_msg(rc, cfd); | rfb_recv_ptr_msg(rc, cfd); | ||||
break; | break; | ||||
case 6: | case 6: | ||||
rfb_recv_cuttext_msg(rc, cfd); | rfb_recv_cuttext_msg(rc, cfd); | ||||
break; | break; | ||||
default: | default: | ||||
WPRINTF(("rfb unknown cli-code %d!\n", buf[0] & 0xff)); | WPRINTF(("rfb unknown cli-code %d!\n\r", buf[0] & 0xff)); | ||||
goto done; | goto done; | ||||
} | } | ||||
} | } | ||||
done: | done: | ||||
rc->cfd = -1; | rc->cfd = -1; | ||||
if (perror == 0) | if (perror == 0) | ||||
pthread_join(tid, NULL); | pthread_join(tid, NULL); | ||||
if (rc->enc_zlib_ok) | if (rc->enc_zlib_ok) | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
memset(&hints, 0, sizeof(hints)); | memset(&hints, 0, sizeof(hints)); | ||||
hints.ai_family = AF_UNSPEC; | hints.ai_family = AF_UNSPEC; | ||||
hints.ai_socktype = SOCK_STREAM; | hints.ai_socktype = SOCK_STREAM; | ||||
hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV | AI_PASSIVE; | hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV | AI_PASSIVE; | ||||
if ((e = getaddrinfo(hostname, servname, &hints, &ai)) != 0) { | if ((e = getaddrinfo(hostname, servname, &hints, &ai)) != 0) { | ||||
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e)); | fprintf(stderr, "getaddrinfo: %s\n\r", gai_strerror(e)); | ||||
goto error; | goto error; | ||||
} | } | ||||
rc->sfd = socket(ai->ai_family, ai->ai_socktype, 0); | rc->sfd = socket(ai->ai_family, ai->ai_socktype, 0); | ||||
if (rc->sfd < 0) { | if (rc->sfd < 0) { | ||||
perror("socket"); | perror("socket"); | ||||
goto error; | goto error; | ||||
} | } | ||||
Show All 23 Lines | if (wait) { | ||||
pthread_mutex_init(&rc->mtx, NULL); | pthread_mutex_init(&rc->mtx, NULL); | ||||
pthread_cond_init(&rc->cond, NULL); | pthread_cond_init(&rc->cond, NULL); | ||||
} | } | ||||
pthread_create(&rc->tid, NULL, rfb_thr, rc); | pthread_create(&rc->tid, NULL, rfb_thr, rc); | ||||
pthread_set_name_np(rc->tid, "rfb"); | pthread_set_name_np(rc->tid, "rfb"); | ||||
if (wait) { | if (wait) { | ||||
DPRINTF(("Waiting for rfb client...\n")); | DPRINTF(("Waiting for rfb client...\n\r")); | ||||
pthread_mutex_lock(&rc->mtx); | pthread_mutex_lock(&rc->mtx); | ||||
pthread_cond_wait(&rc->cond, &rc->mtx); | pthread_cond_wait(&rc->cond, &rc->mtx); | ||||
pthread_mutex_unlock(&rc->mtx); | pthread_mutex_unlock(&rc->mtx); | ||||
} | } | ||||
freeaddrinfo(ai); | freeaddrinfo(ai); | ||||
return (0); | return (0); | ||||
Show All 10 Lines |