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: Luca Stauble <gnekoz@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
pull/1/head
Luca Stauble 12 years ago committed by Johannes Schindelin
parent 5ea7e51e6b
commit fe2e2e4b59

@ -55,7 +55,7 @@ listenForIncomingConnections(rfbClient* client)
client->listenSpecified = TRUE;
listenSocket = ListenAtTcpPort(client->listenPort);
listenSocket = ListenAtTcpPortAndAddress(client->listenPort, client->listenAddress);
if ((listenSocket < 0))
return;
@ -133,7 +133,7 @@ listenForIncomingConnectionsNoFork(rfbClient* client, int timeout)
if (client->listenSock < 0)
{
client->listenSock = ListenAtTcpPort(client->listenPort);
client->listenSock = ListenAtTcpPortAndAddress(client->listenPort, client->listenAddress);
if (client->listenSock < 0)
return -1;

@ -479,6 +479,19 @@ FindFreeTcpPort(void)
int
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;
struct sockaddr_in addr;
@ -486,7 +499,11 @@ ListenAtTcpPort(int port)
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
if (address) {
addr.sin_addr.s_addr = inet_addr(address);
} else {
addr.sin_addr.s_addr = htonl(INADDR_ANY);
}
if (!initSockets())
return -1;

@ -196,6 +196,7 @@ rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,
#endif
client->sock = -1;
client->listenSock = -1;
client->listenAddress = NULL;
client->clientAuthSchemes = NULL;
return client;
}

@ -345,6 +345,9 @@ typedef struct _rfbClient {
int listenSock;
FinishedFrameBufferUpdateProc FinishedFrameBufferUpdate;
char *listenAddress;
} rfbClient;
/* cursor.c */
@ -541,6 +544,7 @@ extern rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n);
extern rfbBool WriteToRFBServer(rfbClient* client, char *buf, int n);
extern int FindFreeTcpPort(void);
extern int ListenAtTcpPort(int port);
extern int ListenAtTcpPortAndAddress(int port, const char *address);
extern int ConnectClientToTcpAddr(unsigned int host, int port);
extern int ConnectClientToTcpAddr6(const char *hostname, int port);
extern int ConnectClientToUnixSock(const char *sockFile);

Loading…
Cancel
Save