Commit b02849ab authored by Alexander Dorokhine's avatar Alexander Dorokhine Committed by Johannes Schindelin

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.
parent 35c42cf3
...@@ -250,13 +250,7 @@ WriteToRFBServer(rfbClient* client, char *buf, int n) ...@@ -250,13 +250,7 @@ WriteToRFBServer(rfbClient* client, char *buf, int n)
* ConnectToTcpAddr connects to the given TCP port. * ConnectToTcpAddr connects to the given TCP port.
*/ */
int static int initSockets() {
ConnectClientToTcpAddr(unsigned int host, int port)
{
int sock;
struct sockaddr_in addr;
int one = 1;
#ifdef WIN32 #ifdef WIN32
WSADATA trash; WSADATA trash;
static rfbBool WSAinitted=FALSE; static rfbBool WSAinitted=FALSE;
...@@ -269,6 +263,18 @@ ConnectClientToTcpAddr(unsigned int host, int port) ...@@ -269,6 +263,18 @@ ConnectClientToTcpAddr(unsigned int host, int port)
} }
} }
#endif #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_family = AF_INET;
addr.sin_port = htons(port); addr.sin_port = htons(port);
...@@ -464,7 +470,7 @@ StringToIPAddr(const char *str, unsigned int *addr) ...@@ -464,7 +470,7 @@ StringToIPAddr(const char *str, unsigned int *addr)
struct hostent *hp; struct hostent *hp;
if (strcmp(str,"") == 0) { if (strcmp(str,"") == 0) {
*addr = 0; /* local */ *addr = htonl(INADDR_LOOPBACK); /* local */
return TRUE; return TRUE;
} }
...@@ -473,6 +479,9 @@ StringToIPAddr(const char *str, unsigned int *addr) ...@@ -473,6 +479,9 @@ StringToIPAddr(const char *str, unsigned int *addr)
if (*addr != -1) if (*addr != -1)
return TRUE; return TRUE;
if (!initSockets())
return -1;
hp = gethostbyname(str); hp = gethostbyname(str);
if (hp) { if (hp) {
......
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