Enable IPv6

Sometimes features can be added by removing code. ;)

Closes: #18
pull/23/head
Andri Yngvason 2022-10-23 18:25:18 +00:00
parent 232bcadd4a
commit ed52288aca
3 changed files with 2 additions and 117 deletions

View File

@ -737,7 +737,6 @@ extern rfbBool SetNonBlocking(rfbSocket sock);
extern rfbBool SetBlocking(rfbSocket sock);
extern rfbBool SetDSCP(rfbSocket sock, int dscp);
extern rfbBool StringToIPAddr(const char *str, unsigned int *addr);
extern rfbBool SameMachine(rfbSocket sock);
/* vncviewer.c */

View File

@ -286,26 +286,13 @@ static rfbBool IsUnixSocket(const char* name)
rfbBool ConnectToRFBServer(rfbClient* client, const char* hostname, int port)
{
if (IsUnixSocket(hostname))
if (IsUnixSocket(hostname)) {
/* serverHost is a UNIX socket. */
client->sock = ConnectClientToUnixSockWithTimeout(
hostname, client->connectTimeout);
else {
#ifdef LIBVNCSERVER_IPv6
} else {
client->sock = ConnectClientToTcpAddr6WithTimeout(
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) {
@ -330,20 +317,8 @@ rfbBool ConnectToRFBRepeater(rfbClient* client, const char* repeaterHost,
int major, minor;
char tmphost[250];
#ifdef LIBVNCSERVER_IPv6
client->sock = ConnectClientToTcpAddr6WithTimeout(
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) {
rfbClientLog("Unable to connect to VNC repeater\n");

View File

@ -179,55 +179,6 @@ static rfbBool WaitForConnected(int socket, unsigned int secs)
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
ConnectClientToTcpAddr6(const char *hostname, int port)
{
@ -242,7 +193,6 @@ ConnectClientToTcpAddr6(const char *hostname, int port)
rfbSocket
ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int timeout)
{
#ifdef LIBVNCSERVER_IPv6
rfbSocket sock;
int n;
struct addrinfo hints, *res, *ressave;
@ -298,13 +248,6 @@ ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int
}
return sock;
#else
rfbClientErr("ConnectClientToTcpAddr6: IPv6 disabled\n");
return RFB_INVALID_SOCKET;
#endif
}
rfbSocket
@ -395,12 +338,10 @@ SetDSCP(rfbSocket sock, int dscp)
switch(addr.sa_family)
{
#if defined LIBVNCSERVER_IPv6 && defined IPV6_TCLASS
case AF_INET6:
level = IPPROTO_IPV6;
cmd = IPV6_TCLASS;
break;
#endif
case AF_INET:
level = IPPROTO_IP;
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.
*/