diff options
author | dscho <dscho> | 2004-12-01 23:06:56 +0000 |
---|---|---|
committer | dscho <dscho> | 2004-12-01 23:06:56 +0000 |
commit | 658b65ad0cc2045bf2c930c8ef2a2853a07ba6ee (patch) | |
tree | 51a7b1f153204de2c3bc423411d8f5b2f566c4f6 /libvncclient | |
parent | 7d3b1c9762b5f2878e9783677677cb2b3aa10e7e (diff) | |
download | libtdevnc-658b65ad0cc2045bf2c930c8ef2a2853a07ba6ee.tar.gz libtdevnc-658b65ad0cc2045bf2c930c8ef2a2853a07ba6ee.zip |
support MinGW32!
Diffstat (limited to 'libvncclient')
-rw-r--r-- | libvncclient/listen.c | 14 | ||||
-rw-r--r-- | libvncclient/rfbproto.c | 2 | ||||
-rw-r--r-- | libvncclient/sockets.c | 77 | ||||
-rw-r--r-- | libvncclient/vncviewer.c | 13 |
4 files changed, 84 insertions, 22 deletions
diff --git a/libvncclient/listen.c b/libvncclient/listen.c index a7e4259..dc6508c 100644 --- a/libvncclient/listen.c +++ b/libvncclient/listen.c @@ -23,9 +23,13 @@ #include <unistd.h> #include <sys/types.h> +#ifdef __MINGW32__ +#include <winsock2.h> +#else #include <sys/wait.h> -#include <sys/time.h> #include <sys/utsname.h> +#endif +#include <sys/time.h> #include <rfb/rfbclient.h> /* @@ -36,6 +40,11 @@ void listenForIncomingConnections(rfbClient* client) { +#ifdef __MINGW32__ + /* FIXME */ + rfbClientErr("listenForIncomingConnections on MinGW32 NOT IMPLEMENTED\n"); + return; +#else int listenSocket; fd_set fds; @@ -77,7 +86,7 @@ listenForIncomingConnections(rfbClient* client) switch (fork()) { case -1: - rfbClientErr("fork"); + rfbClientErr("fork\n"); return; case 0: @@ -92,6 +101,7 @@ listenForIncomingConnections(rfbClient* client) } } } +#endif } diff --git a/libvncclient/rfbproto.c b/libvncclient/rfbproto.c index 0f12407..40783c6 100644 --- a/libvncclient/rfbproto.c +++ b/libvncclient/rfbproto.c @@ -25,7 +25,9 @@ #include <unistd.h> #include <errno.h> +#ifndef __MINGW32__ #include <pwd.h> +#endif #include <rfb/rfbclient.h> #ifdef LIBVNCSERVER_HAVE_LIBZ #include <zlib.h> diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c index 13cb770..efe7eb9 100644 --- a/libvncclient/sockets.c +++ b/libvncclient/sockets.c @@ -22,15 +22,23 @@ */ #include <unistd.h> -#include <sys/socket.h> #include <errno.h> +#include <fcntl.h> +#include <assert.h> +#include <rfb/rfbclient.h> +#ifdef WIN32 +#include <winsock2.h> +#define EWOULDBLOCK WSAEWOULDBLOCK +#define close closesocket +#define read(sock,buf,len) recv(sock,buf,len,0) +#define write(sock,buf,len) send(sock,buf,len,0) +#else +#include <sys/socket.h> #include <netinet/in.h> #include <netinet/tcp.h> #include <arpa/inet.h> #include <netdb.h> -#include <fcntl.h> -#include <assert.h> -#include <rfb/rfbclient.h> +#endif void PrintInHex(char *buf, int len); @@ -81,7 +89,12 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n) diff.tv_usec+=1000000; } sleep (diff.tv_sec); +#ifndef __MINGW32__ + /* FIXME */ usleep (diff.tv_usec); +#else + rfbClientErr("usleep on MinGW32 NOT IMPLEMENTED\n"); +#endif } rec->tv=tv; @@ -114,13 +127,16 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n) int i = read(client->sock, client->buf + client->buffered, RFB_BUF_SIZE - client->buffered); if (i <= 0) { if (i < 0) { +#ifdef WIN32 + errno=WSAGetLastError(); +#endif if (errno == EWOULDBLOCK || errno == EAGAIN) { /* TODO: ProcessXtEvents(); */ i = 0; } else { - rfbClientErr("read"); + rfbClientErr("read (%d: %s)\n",errno,strerror(errno)); return FALSE; } } else { @@ -143,13 +159,16 @@ ReadFromRFBServer(rfbClient* client, char *out, unsigned int n) int i = read(client->sock, out, n); if (i <= 0) { if (i < 0) { +#ifdef WIN32 + errno=WSAGetLastError(); +#endif if (errno == EWOULDBLOCK || errno == EAGAIN) { /* TODO: ProcessXtEvents(); */ i = 0; } else { - rfbClientErr("read"); + rfbClientErr("read (%s)\n",strerror(errno)); return FALSE; } } else { @@ -200,12 +219,12 @@ WriteToRFBServer(rfbClient* client, char *buf, int n) FD_SET(client->sock,&fds); if (select(client->sock+1, NULL, &fds, NULL, NULL) <= 0) { - rfbClientErr("select"); + rfbClientErr("select\n"); return FALSE; } j = 0; } else { - rfbClientErr("write"); + rfbClientErr("write\n"); return FALSE; } } else { @@ -230,25 +249,41 @@ ConnectClientToTcpAddr(unsigned int host, int port) struct sockaddr_in addr; int one = 1; +#ifdef WIN32 + WSADATA trash; + static rfbBool WSAinitted=FALSE; + if(!WSAinitted) { + WSAinitted=TRUE; + int i=WSAStartup(MAKEWORD(2,0),&trash); + if(i!=0) { + rfbClientErr("Couldn't init Windows Sockets\n"); + return -1; + } + } +#endif + 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 < 0) { - rfbClientErr("ConnectToTcpAddr: socket"); +#ifdef WIN32 + errno=WSAGetLastError(); +#endif + rfbClientErr("ConnectToTcpAddr: socket (%s)\n",strerror(errno)); return -1; } if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - rfbClientErr("ConnectToTcpAddr: connect"); + rfbClientErr("ConnectToTcpAddr: connect\n"); close(sock); return -1; } if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one)) < 0) { - rfbClientErr("ConnectToTcpAddr: setsockopt"); + rfbClientErr("ConnectToTcpAddr: setsockopt\n"); close(sock); return -1; } @@ -274,7 +309,7 @@ FindFreeTcpPort(void) sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { - rfbClientErr(": FindFreeTcpPort: socket"); + rfbClientErr(": FindFreeTcpPort: socket\n"); return 0; } @@ -308,25 +343,25 @@ ListenAtTcpPort(int port) sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { - rfbClientErr("ListenAtTcpPort: socket"); + rfbClientErr("ListenAtTcpPort: socket\n"); return -1; } if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char *)&one, sizeof(one)) < 0) { - rfbClientErr("ListenAtTcpPort: setsockopt"); + rfbClientErr("ListenAtTcpPort: setsockopt\n"); close(sock); return -1; } if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - rfbClientErr("ListenAtTcpPort: bind"); + rfbClientErr("ListenAtTcpPort: bind\n"); close(sock); return -1; } if (listen(sock, 5) < 0) { - rfbClientErr("ListenAtTcpPort: listen"); + rfbClientErr("ListenAtTcpPort: listen\n"); close(sock); return -1; } @@ -349,13 +384,13 @@ AcceptTcpConnection(int listenSock) sock = accept(listenSock, (struct sockaddr *) &addr, &addrlen); if (sock < 0) { - rfbClientErr("AcceptTcpConnection: accept"); + rfbClientErr("AcceptTcpConnection: accept\n"); return -1; } if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one)) < 0) { - rfbClientErr("AcceptTcpConnection: setsockopt"); + rfbClientErr("AcceptTcpConnection: setsockopt\n"); close(sock); return -1; } @@ -371,10 +406,14 @@ AcceptTcpConnection(int listenSock) rfbBool SetNonBlocking(int sock) { +#ifndef __MINGW32__ if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) { - rfbClientErr("AcceptTcpConnection: fcntl"); + rfbClientErr("AcceptTcpConnection: fcntl\n"); return FALSE; } +#else + rfbClientErr("O_NONBLOCK on MinGW32 NOT IMPLEMENTED\n"); +#endif return TRUE; } diff --git a/libvncclient/vncviewer.c b/libvncclient/vncviewer.c index 2a11970..c97b234 100644 --- a/libvncclient/vncviewer.c +++ b/libvncclient/vncviewer.c @@ -37,9 +37,18 @@ static void DummyRect(rfbClient* client, int x, int y, int w, int h) { static char* NoPassword(rfbClient* client) { return strdup(""); } + +#ifndef __MINGW32__ #include <stdio.h> #include <termios.h> +#endif + static char* ReadPassword(rfbClient* client) { +#ifdef __MINGW32__ + /* FIXME */ + rfbClientErr("ReadPassword on MinGW32 NOT IMPLEMENTED\n"); + return NoPassword(client); +#else int i; char* p=malloc(9); struct termios save,noecho; @@ -61,6 +70,7 @@ static char* ReadPassword(rfbClient* client) { } tcsetattr(fileno(stdin),TCSAFLUSH,&save); return p; +#endif } static rfbBool MallocFrameBuffer(rfbClient* client) { if(client->frameBuffer) @@ -196,7 +206,8 @@ rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv) { char* colon=strchr(argv[i],':'); if(colon) { - client->serverHost=strndup(argv[i],(int)(colon-argv[i])); + client->serverHost=strdup(argv[i]); + client->serverHost[(int)(colon-argv[i])]='\0'; client->serverPort=atoi(colon+1); } else { client->serverHost=strdup(argv[i]); |