parent
232bcadd4a
commit
ed52288aca
|
@ -737,7 +737,6 @@ extern rfbBool SetNonBlocking(rfbSocket sock);
|
||||||
extern rfbBool SetBlocking(rfbSocket sock);
|
extern rfbBool SetBlocking(rfbSocket sock);
|
||||||
extern rfbBool SetDSCP(rfbSocket sock, int dscp);
|
extern rfbBool SetDSCP(rfbSocket sock, int dscp);
|
||||||
|
|
||||||
extern rfbBool StringToIPAddr(const char *str, unsigned int *addr);
|
|
||||||
extern rfbBool SameMachine(rfbSocket sock);
|
extern rfbBool SameMachine(rfbSocket sock);
|
||||||
|
|
||||||
/* vncviewer.c */
|
/* vncviewer.c */
|
||||||
|
|
|
@ -286,26 +286,13 @@ static rfbBool IsUnixSocket(const char* name)
|
||||||
|
|
||||||
rfbBool ConnectToRFBServer(rfbClient* client, const char* hostname, int port)
|
rfbBool ConnectToRFBServer(rfbClient* client, const char* hostname, int port)
|
||||||
{
|
{
|
||||||
if (IsUnixSocket(hostname))
|
if (IsUnixSocket(hostname)) {
|
||||||
/* serverHost is a UNIX socket. */
|
/* serverHost is a UNIX socket. */
|
||||||
client->sock = ConnectClientToUnixSockWithTimeout(
|
client->sock = ConnectClientToUnixSockWithTimeout(
|
||||||
hostname, client->connectTimeout);
|
hostname, client->connectTimeout);
|
||||||
else {
|
} else {
|
||||||
#ifdef LIBVNCSERVER_IPv6
|
|
||||||
client->sock = ConnectClientToTcpAddr6WithTimeout(
|
client->sock = ConnectClientToTcpAddr6WithTimeout(
|
||||||
hostname, port, client->connectTimeout);
|
hostname, port, client->connectTimeout);
|
||||||
#else
|
|
||||||
unsigned int host;
|
|
||||||
|
|
||||||
/* serverHost is a hostname */
|
|
||||||
if (!StringToIPAddr(hostname, &host)) {
|
|
||||||
rfbClientLog("Couldn't convert '%s' to host address\n",
|
|
||||||
hostname);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
client->sock = ConnectClientToTcpAddrWithTimeout(
|
|
||||||
host, port, client->connectTimeout);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client->sock == RFB_INVALID_SOCKET) {
|
if (client->sock == RFB_INVALID_SOCKET) {
|
||||||
|
@ -330,20 +317,8 @@ rfbBool ConnectToRFBRepeater(rfbClient* client, const char* repeaterHost,
|
||||||
int major, minor;
|
int major, minor;
|
||||||
char tmphost[250];
|
char tmphost[250];
|
||||||
|
|
||||||
#ifdef LIBVNCSERVER_IPv6
|
|
||||||
client->sock = ConnectClientToTcpAddr6WithTimeout(
|
client->sock = ConnectClientToTcpAddr6WithTimeout(
|
||||||
repeaterHost, repeaterPort, client->connectTimeout);
|
repeaterHost, repeaterPort, client->connectTimeout);
|
||||||
#else
|
|
||||||
unsigned int host;
|
|
||||||
if (!StringToIPAddr(repeaterHost, &host)) {
|
|
||||||
rfbClientLog("Couldn't convert '%s' to host address\n",
|
|
||||||
repeaterHost);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
client->sock = ConnectClientToTcpAddrWithTimeout(host, repeaterPort,
|
|
||||||
client->connectTimeout);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (client->sock == RFB_INVALID_SOCKET) {
|
if (client->sock == RFB_INVALID_SOCKET) {
|
||||||
rfbClientLog("Unable to connect to VNC repeater\n");
|
rfbClientLog("Unable to connect to VNC repeater\n");
|
||||||
|
|
|
@ -179,55 +179,6 @@ static rfbBool WaitForConnected(int socket, unsigned int secs)
|
||||||
return so_error == 0 ? TRUE : FALSE;
|
return so_error == 0 ? TRUE : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
rfbSocket
|
|
||||||
ConnectClientToTcpAddr(unsigned int host, int port)
|
|
||||||
{
|
|
||||||
rfbSocket sock = ConnectClientToTcpAddrWithTimeout(host, port, DEFAULT_CONNECT_TIMEOUT);
|
|
||||||
/* put socket back into blocking mode for compatibility reasons */
|
|
||||||
if (sock != RFB_INVALID_SOCKET) {
|
|
||||||
SetBlocking(sock);
|
|
||||||
}
|
|
||||||
return sock;
|
|
||||||
}
|
|
||||||
|
|
||||||
rfbSocket
|
|
||||||
ConnectClientToTcpAddrWithTimeout(unsigned int host, int port, unsigned int timeout)
|
|
||||||
{
|
|
||||||
rfbSocket sock;
|
|
||||||
struct sockaddr_in addr;
|
|
||||||
int one = 1;
|
|
||||||
|
|
||||||
addr.sin_family = AF_INET;
|
|
||||||
addr.sin_port = htons(port);
|
|
||||||
addr.sin_addr.s_addr = host;
|
|
||||||
|
|
||||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
|
||||||
if (sock == RFB_INVALID_SOCKET) {
|
|
||||||
rfbClientErr("ConnectToTcpAddr: socket (%s)\n",strerror(errno));
|
|
||||||
return RFB_INVALID_SOCKET;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SetNonBlocking(sock))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
|
||||||
if (!((errno == EWOULDBLOCK || errno == EINPROGRESS) && WaitForConnected(sock, timeout))) {
|
|
||||||
rfbClientErr("ConnectToTcpAddr: connect\n");
|
|
||||||
rfbCloseSocket(sock);
|
|
||||||
return RFB_INVALID_SOCKET;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
|
|
||||||
(char *)&one, sizeof(one)) < 0) {
|
|
||||||
rfbClientErr("ConnectToTcpAddr: setsockopt\n");
|
|
||||||
rfbCloseSocket(sock);
|
|
||||||
return RFB_INVALID_SOCKET;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sock;
|
|
||||||
}
|
|
||||||
|
|
||||||
rfbSocket
|
rfbSocket
|
||||||
ConnectClientToTcpAddr6(const char *hostname, int port)
|
ConnectClientToTcpAddr6(const char *hostname, int port)
|
||||||
{
|
{
|
||||||
|
@ -242,7 +193,6 @@ ConnectClientToTcpAddr6(const char *hostname, int port)
|
||||||
rfbSocket
|
rfbSocket
|
||||||
ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int timeout)
|
ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int timeout)
|
||||||
{
|
{
|
||||||
#ifdef LIBVNCSERVER_IPv6
|
|
||||||
rfbSocket sock;
|
rfbSocket sock;
|
||||||
int n;
|
int n;
|
||||||
struct addrinfo hints, *res, *ressave;
|
struct addrinfo hints, *res, *ressave;
|
||||||
|
@ -298,13 +248,6 @@ ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int
|
||||||
}
|
}
|
||||||
|
|
||||||
return sock;
|
return sock;
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
rfbClientErr("ConnectClientToTcpAddr6: IPv6 disabled\n");
|
|
||||||
return RFB_INVALID_SOCKET;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rfbSocket
|
rfbSocket
|
||||||
|
@ -395,12 +338,10 @@ SetDSCP(rfbSocket sock, int dscp)
|
||||||
|
|
||||||
switch(addr.sa_family)
|
switch(addr.sa_family)
|
||||||
{
|
{
|
||||||
#if defined LIBVNCSERVER_IPv6 && defined IPV6_TCLASS
|
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
level = IPPROTO_IPV6;
|
level = IPPROTO_IPV6;
|
||||||
cmd = IPV6_TCLASS;
|
cmd = IPV6_TCLASS;
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
level = IPPROTO_IP;
|
level = IPPROTO_IP;
|
||||||
cmd = IP_TOS;
|
cmd = IP_TOS;
|
||||||
|
@ -420,36 +361,6 @@ SetDSCP(rfbSocket sock, int dscp)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* StringToIPAddr - convert a host string to an IP address.
|
|
||||||
*/
|
|
||||||
|
|
||||||
rfbBool
|
|
||||||
StringToIPAddr(const char *str, unsigned int *addr)
|
|
||||||
{
|
|
||||||
struct hostent *hp;
|
|
||||||
|
|
||||||
if (strcmp(str,"") == 0) {
|
|
||||||
*addr = htonl(INADDR_LOOPBACK); /* local */
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
*addr = inet_addr(str);
|
|
||||||
|
|
||||||
if (*addr != -1)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
hp = gethostbyname(str);
|
|
||||||
|
|
||||||
if (hp) {
|
|
||||||
*addr = *(unsigned int *)hp->h_addr;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test if the other end of a socket is on the same machine.
|
* Test if the other end of a socket is on the same machine.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue