Commit d7c0b34b authored by Ben Klopfenstein's avatar Ben Klopfenstein Committed by Johannes Schindelin

libvncclient: Unix sockets support by Ben Klopfenstein

Signed-off-by: 's avatarJohannes Schindelin <johannes.schindelin@gmx.de>
parent 4088906b
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#endif #endif
#ifndef WIN32 #ifndef WIN32
#include <unistd.h> #include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#else #else
#define strncasecmp _strnicmp #define strncasecmp _strnicmp
#endif #endif
...@@ -342,6 +344,15 @@ DefaultSupportedMessagesTightVNC(rfbClient* client) ...@@ -342,6 +344,15 @@ DefaultSupportedMessagesTightVNC(rfbClient* client)
SetServer2Client(client, rfbTextChat); SetServer2Client(client, rfbTextChat);
} }
static rfbBool
IsUnixSocket(const char *name)
{
struct stat sb;
if(stat(name, &sb) && (sb.st_mode & S_IFMT) == S_IFSOCK)
return TRUE;
return FALSE;
}
/* /*
* ConnectToRFBServer. * ConnectToRFBServer.
*/ */
...@@ -378,12 +389,20 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port) ...@@ -378,12 +389,20 @@ ConnectToRFBServer(rfbClient* client,const char *hostname, int port)
return TRUE; return TRUE;
} }
#ifndef WIN32
if(IsUnixSocket(hostname))
/* serverHost is a UNIX socket. */
client->sock = ConnectClientToUnixSock(hostname);
else
#endif
{
/* serverHost is a hostname */
if (!StringToIPAddr(hostname, &host)) { if (!StringToIPAddr(hostname, &host)) {
rfbClientLog("Couldn't convert '%s' to host address\n", hostname); rfbClientLog("Couldn't convert '%s' to host address\n", hostname);
return FALSE; return FALSE;
} }
client->sock = ConnectClientToTcpAddr(host, port); client->sock = ConnectClientToTcpAddr(host, port);
}
if (client->sock < 0) { if (client->sock < 0) {
rfbClientLog("Unable to connect to VNC server\n"); rfbClientLog("Unable to connect to VNC server\n");
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#else #else
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/un.h>
#include <netinet/tcp.h> #include <netinet/tcp.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netdb.h> #include <netdb.h>
...@@ -297,6 +298,34 @@ ConnectClientToTcpAddr(unsigned int host, int port) ...@@ -297,6 +298,34 @@ ConnectClientToTcpAddr(unsigned int host, int port)
return sock; return sock;
} }
int
ConnectClientToUnixSock(const char *sockFile)
{
#ifdef WIN32
rfbClientErr("Windows doesn't support UNIX sockets\n");
return -1;
#else
int sock;
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, sockFile);
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
rfbClientErr("ConnectToUnixSock: socket (%s)\n",strerror(errno));
return -1;
}
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr.sun_family) + strlen(addr.sun_path)) < 0) {
rfbClientErr("ConnectToUnixSock: connect\n");
close(sock);
return -1;
}
return sock;
#endif
}
/* /*
......
...@@ -314,6 +314,7 @@ extern rfbBool WriteToRFBServer(rfbClient* client, char *buf, int n); ...@@ -314,6 +314,7 @@ extern rfbBool WriteToRFBServer(rfbClient* client, char *buf, int n);
extern int FindFreeTcpPort(void); extern int FindFreeTcpPort(void);
extern int ListenAtTcpPort(int port); extern int ListenAtTcpPort(int port);
extern int ConnectClientToTcpAddr(unsigned int host, int port); extern int ConnectClientToTcpAddr(unsigned int host, int port);
extern int ConnectClientToUnixSock(const char *sockFile);
extern int AcceptTcpConnection(int listenSock); extern int AcceptTcpConnection(int listenSock);
extern rfbBool SetNonBlocking(int sock); extern rfbBool SetNonBlocking(int sock);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment