Lines 42-47
__FBSDID("$FreeBSD$");
Link Here
|
42 |
#include <machine/cpufunc.h> |
42 |
#include <machine/cpufunc.h> |
43 |
#include <machine/specialreg.h> |
43 |
#include <machine/specialreg.h> |
44 |
#include <netinet/in.h> |
44 |
#include <netinet/in.h> |
|
|
45 |
#include <netdb.h> |
45 |
|
46 |
|
46 |
#include <assert.h> |
47 |
#include <assert.h> |
47 |
#include <err.h> |
48 |
#include <err.h> |
Lines 960-967
sse42_supported(void)
Link Here
|
960 |
int |
961 |
int |
961 |
rfb_init(char *hostname, int port, int wait, char *password) |
962 |
rfb_init(char *hostname, int port, int wait, char *password) |
962 |
{ |
963 |
{ |
|
|
964 |
int e; |
965 |
char servname[6]; |
963 |
struct rfb_softc *rc; |
966 |
struct rfb_softc *rc; |
964 |
struct sockaddr_in sin; |
967 |
struct addrinfo *ai; |
|
|
968 |
struct addrinfo hints; |
965 |
int on = 1; |
969 |
int on = 1; |
966 |
#ifndef WITHOUT_CAPSICUM |
970 |
#ifndef WITHOUT_CAPSICUM |
967 |
cap_rights_t rights; |
971 |
cap_rights_t rights; |
Lines 978-1006
rfb_init(char *hostname, int port, int wait, char
Link Here
|
978 |
|
982 |
|
979 |
rc->password = password; |
983 |
rc->password = password; |
980 |
|
984 |
|
981 |
rc->sfd = socket(AF_INET, SOCK_STREAM, 0); |
985 |
snprintf(servname, sizeof(servname), "%d", port ? port : 5900); |
|
|
986 |
|
987 |
if (!hostname || strlen(hostname) == 0) |
988 |
#if defined(INET) |
989 |
hostname = "127.0.0.1"; |
990 |
#elif defined(INET6) |
991 |
hostname = "[::1]"; |
992 |
#endif |
993 |
|
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; |
998 |
|
999 |
if ((e = getaddrinfo(hostname, servname, &hints, &ai)) != 0) { |
1000 |
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e)); |
1001 |
return(-1); |
1002 |
} |
1003 |
|
1004 |
rc->sfd = socket(ai->ai_family, ai->ai_socktype, 0); |
982 |
if (rc->sfd < 0) { |
1005 |
if (rc->sfd < 0) { |
983 |
perror("socket"); |
1006 |
perror("socket"); |
|
|
1007 |
freeaddrinfo(ai); |
984 |
return (-1); |
1008 |
return (-1); |
985 |
} |
1009 |
} |
986 |
|
1010 |
|
987 |
setsockopt(rc->sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
1011 |
setsockopt(rc->sfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
988 |
|
1012 |
|
989 |
sin.sin_len = sizeof(sin); |
1013 |
if (bind(rc->sfd, ai->ai_addr, ai->ai_addrlen) < 0) { |
990 |
sin.sin_family = AF_INET; |
|
|
991 |
sin.sin_port = port ? htons(port) : htons(5900); |
992 |
if (hostname && strlen(hostname) > 0) |
993 |
inet_pton(AF_INET, hostname, &(sin.sin_addr)); |
994 |
else |
995 |
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); |
996 |
|
997 |
if (bind(rc->sfd, (struct sockaddr *)&sin, sizeof(sin)) < 0) { |
998 |
perror("bind"); |
1014 |
perror("bind"); |
|
|
1015 |
freeaddrinfo(ai); |
999 |
return (-1); |
1016 |
return (-1); |
1000 |
} |
1017 |
} |
1001 |
|
1018 |
|
1002 |
if (listen(rc->sfd, 1) < 0) { |
1019 |
if (listen(rc->sfd, 1) < 0) { |
1003 |
perror("listen"); |
1020 |
perror("listen"); |
|
|
1021 |
freeaddrinfo(ai); |
1004 |
return (-1); |
1022 |
return (-1); |
1005 |
} |
1023 |
} |
1006 |
|
1024 |
|
Lines 1028-1032
rfb_init(char *hostname, int port, int wait, char
Link Here
|
1028 |
pthread_mutex_unlock(&rc->mtx); |
1046 |
pthread_mutex_unlock(&rc->mtx); |
1029 |
} |
1047 |
} |
1030 |
|
1048 |
|
|
|
1049 |
freeaddrinfo(ai); |
1031 |
return (0); |
1050 |
return (0); |
1032 |
} |
1051 |
} |