summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Dorokhine <arrenlex@gmail.com>2009-10-30 12:27:05 +0100
committerJohannes Schindelin <johannes.schindelin@gmx.de>2009-10-30 12:36:52 +0100
commitb02849ab807bf756a748ce7e174d85a745c49b1e (patch)
treed3d59e937abd6186edaa4d1d0d2cac723de55769
parent35c42cf3a64b633ca07f0fe47182955736b8c5e1 (diff)
downloadlibvncserver-b02849ab807bf756a748ce7e174d85a745c49b1e.zip
libvncserver-b02849ab807bf756a748ce7e174d85a745c49b1e.tar.gz
Fix hostname resolution problems under Windows
On Windows, the WSA system needs to be initialized to be able to look up host names. This patch also changes *addr = 0 to use the constant INADDR_LOOPBACK instead, which seems to be required on Windows.
-rw-r--r--libvncclient/sockets.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c
index 135861e..bdfd811 100644
--- a/libvncclient/sockets.c
+++ b/libvncclient/sockets.c
@@ -250,13 +250,7 @@ WriteToRFBServer(rfbClient* client, char *buf, int n)
* ConnectToTcpAddr connects to the given TCP port.
*/
-int
-ConnectClientToTcpAddr(unsigned int host, int port)
-{
- int sock;
- struct sockaddr_in addr;
- int one = 1;
-
+static int initSockets() {
#ifdef WIN32
WSADATA trash;
static rfbBool WSAinitted=FALSE;
@@ -269,6 +263,18 @@ ConnectClientToTcpAddr(unsigned int host, int port)
}
}
#endif
+ return 1;
+}
+
+int
+ConnectClientToTcpAddr(unsigned int host, int port)
+{
+ int sock;
+ struct sockaddr_in addr;
+ int one = 1;
+
+ if (!initSockets())
+ return -1;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
@@ -464,7 +470,7 @@ StringToIPAddr(const char *str, unsigned int *addr)
struct hostent *hp;
if (strcmp(str,"") == 0) {
- *addr = 0; /* local */
+ *addr = htonl(INADDR_LOOPBACK); /* local */
return TRUE;
}
@@ -473,6 +479,9 @@ StringToIPAddr(const char *str, unsigned int *addr)
if (*addr != -1)
return TRUE;
+ if (!initSockets())
+ return -1;
+
hp = gethostbyname(str);
if (hp) {
OpenPOWER on IntegriCloud