Commit fe2e2e4b authored by Luca Stauble's avatar Luca Stauble Committed by Johannes Schindelin

Add an optional parameter to specify the ip address for reverse connections

For security reasons, it can be important to limit which IP addresses a
LibVNCClient-based client should listen for reverse connections. This
commit adds that option.

To preserve binary backwards-compatibility, the field was added to the end
of the rfbclient struct, and the function ListenAtTcpPort retains its
signature (but calls the new ListenAtTcpPortAndAddress).

[jes: shortened the commit subject, added a longer explanation in the
commit body and adjusted style]
Signed-off-by: 's avatarLuca Stauble <gnekoz@gmail.com>
Signed-off-by: 's avatarJohannes Schindelin <johannes.schindelin@gmx.de>
parent 5ea7e51e
...@@ -55,7 +55,7 @@ listenForIncomingConnections(rfbClient* client) ...@@ -55,7 +55,7 @@ listenForIncomingConnections(rfbClient* client)
client->listenSpecified = TRUE; client->listenSpecified = TRUE;
listenSocket = ListenAtTcpPort(client->listenPort); listenSocket = ListenAtTcpPortAndAddress(client->listenPort, client->listenAddress);
if ((listenSocket < 0)) if ((listenSocket < 0))
return; return;
...@@ -133,7 +133,7 @@ listenForIncomingConnectionsNoFork(rfbClient* client, int timeout) ...@@ -133,7 +133,7 @@ listenForIncomingConnectionsNoFork(rfbClient* client, int timeout)
if (client->listenSock < 0) if (client->listenSock < 0)
{ {
client->listenSock = ListenAtTcpPort(client->listenPort); client->listenSock = ListenAtTcpPortAndAddress(client->listenPort, client->listenAddress);
if (client->listenSock < 0) if (client->listenSock < 0)
return -1; return -1;
......
...@@ -479,6 +479,19 @@ FindFreeTcpPort(void) ...@@ -479,6 +479,19 @@ FindFreeTcpPort(void)
int int
ListenAtTcpPort(int port) ListenAtTcpPort(int port)
{
return ListenAtTcpPortAndAddress(port, NULL);
}
/*
* ListenAtTcpPortAndAddress starts listening at the given TCP port on
* the given IP address
*/
int
ListenAtTcpPortAndAddress(int port, const char *address)
{ {
int sock; int sock;
struct sockaddr_in addr; struct sockaddr_in addr;
...@@ -486,7 +499,11 @@ ListenAtTcpPort(int port) ...@@ -486,7 +499,11 @@ ListenAtTcpPort(int port)
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons(port); addr.sin_port = htons(port);
if (address) {
addr.sin_addr.s_addr = inet_addr(address);
} else {
addr.sin_addr.s_addr = htonl(INADDR_ANY); addr.sin_addr.s_addr = htonl(INADDR_ANY);
}
if (!initSockets()) if (!initSockets())
return -1; return -1;
......
...@@ -196,6 +196,7 @@ rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel, ...@@ -196,6 +196,7 @@ rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,
#endif #endif
client->sock = -1; client->sock = -1;
client->listenSock = -1; client->listenSock = -1;
client->listenAddress = NULL;
client->clientAuthSchemes = NULL; client->clientAuthSchemes = NULL;
return client; return client;
} }
......
...@@ -345,6 +345,9 @@ typedef struct _rfbClient { ...@@ -345,6 +345,9 @@ typedef struct _rfbClient {
int listenSock; int listenSock;
FinishedFrameBufferUpdateProc FinishedFrameBufferUpdate; FinishedFrameBufferUpdateProc FinishedFrameBufferUpdate;
char *listenAddress;
} rfbClient; } rfbClient;
/* cursor.c */ /* cursor.c */
...@@ -541,6 +544,7 @@ extern rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n); ...@@ -541,6 +544,7 @@ extern rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n);
extern rfbBool WriteToRFBServer(rfbClient* client, char *buf, int n); 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 ListenAtTcpPortAndAddress(int port, const char *address);
extern int ConnectClientToTcpAddr(unsigned int host, int port); extern int ConnectClientToTcpAddr(unsigned int host, int port);
extern int ConnectClientToTcpAddr6(const char *hostname, int port); extern int ConnectClientToTcpAddr6(const char *hostname, int port);
extern int ConnectClientToUnixSock(const char *sockFile); extern int ConnectClientToUnixSock(const char *sockFile);
......
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