summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/os_calls.c18
-rw-r--r--common/os_calls.h2
-rw-r--r--common/trans.c11
-rw-r--r--common/trans.h2
-rw-r--r--xrdp/xrdp_listen.c19
5 files changed, 45 insertions, 7 deletions
diff --git a/common/os_calls.c b/common/os_calls.c
index d6adf40c..913c4296 100644
--- a/common/os_calls.c
+++ b/common/os_calls.c
@@ -453,6 +453,24 @@ g_tcp_local_bind(int sck, char* port)
/*****************************************************************************/
/* returns error, zero is good */
int APP_CC
+g_tcp_bind_address(int sck, char* port, const char* address)
+{
+ struct sockaddr_in s;
+
+ memset(&s, 0, sizeof(struct sockaddr_in));
+ s.sin_family = AF_INET;
+ s.sin_port = htons((tui16)atoi(port));
+ s.sin_addr.s_addr = INADDR_ANY;
+ if (inet_aton(address, &s.sin_addr) < 0)
+ {
+ return -1; /* bad address */
+ }
+ return bind(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
+}
+
+/*****************************************************************************/
+/* returns error, zero is good */
+int APP_CC
g_tcp_listen(int sck)
{
return listen(sck, 2);
diff --git a/common/os_calls.h b/common/os_calls.h
index 9cad75db..333c0f29 100644
--- a/common/os_calls.h
+++ b/common/os_calls.h
@@ -76,6 +76,8 @@ g_tcp_bind(int sck, char* port);
int APP_CC
g_tcp_local_bind(int sck, char* port);
int APP_CC
+g_tcp_bind_address(int sck, char* port, const char* address);
+int APP_CC
g_tcp_listen(int sck);
int APP_CC
g_tcp_accept(int sck);
diff --git a/common/trans.c b/common/trans.c
index 84b44b72..681174ac 100644
--- a/common/trans.c
+++ b/common/trans.c
@@ -342,7 +342,7 @@ trans_connect(struct trans* self, const char* server, const char* port,
/*****************************************************************************/
int APP_CC
-trans_listen(struct trans* self, char* port)
+trans_listen_address(struct trans* self, char* port, const char* address)
{
if (self->sck != 0)
{
@@ -352,7 +352,7 @@ trans_listen(struct trans* self, char* port)
{
self->sck = g_tcp_socket();
g_tcp_set_non_blocking(self->sck);
- if (g_tcp_bind(self->sck, port) == 0)
+ if (g_tcp_bind_address(self->sck, port, address) == 0)
{
if (g_tcp_listen(self->sck) == 0)
{
@@ -385,6 +385,13 @@ trans_listen(struct trans* self, char* port)
}
/*****************************************************************************/
+int APP_CC
+trans_listen(struct trans* self, char* port)
+{
+ return trans_listen_address(self, port, "0.0.0.0");
+}
+
+/*****************************************************************************/
struct stream* APP_CC
trans_get_in_s(struct trans* self)
{
diff --git a/common/trans.h b/common/trans.h
index 3aa1df54..bb0f42c0 100644
--- a/common/trans.h
+++ b/common/trans.h
@@ -79,6 +79,8 @@ int APP_CC
trans_connect(struct trans* self, const char* server, const char* port,
int timeout);
int APP_CC
+trans_listen_address(struct trans* self, char* port, const char* address);
+int APP_CC
trans_listen(struct trans* self, char* port);
struct stream* APP_CC
trans_get_in_s(struct trans* self);
diff --git a/xrdp/xrdp_listen.c b/xrdp/xrdp_listen.c
index 1d3b3de1..c5746281 100644
--- a/xrdp/xrdp_listen.c
+++ b/xrdp/xrdp_listen.c
@@ -119,7 +119,8 @@ xrdp_process_run(void* in_val)
/*****************************************************************************/
static int
-xrdp_listen_get_port(char* port, int port_bytes)
+xrdp_listen_get_port_address(char* port, int port_bytes,
+ char* address, int address_bytes)
{
int fd;
int error;
@@ -131,7 +132,9 @@ xrdp_listen_get_port(char* port, int port_bytes)
/* default to port 3389 */
g_strncpy(port, "3389", port_bytes - 1);
- /* see if port is in xrdp.ini file */
+ /* Default to all */
+ g_strncpy(address, "0.0.0.0", address_bytes - 1);
+ /* see if port or address is in xrdp.ini file */
g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
fd = g_file_open(cfg_file);
if (fd > 0)
@@ -155,7 +158,11 @@ xrdp_listen_get_port(char* port, int port_bytes)
{
g_strncpy(port, val, port_bytes - 1);
}
- break;
+ }
+ if (g_strcasecmp(val, "address") == 0)
+ {
+ val = (char*)list_get_item(values, index);
+ g_strncpy(address, val, address_bytes - 1);
}
}
}
@@ -203,6 +210,7 @@ xrdp_listen_main_loop(struct xrdp_listen* self)
int cont;
int timeout;
char port[8];
+ char address[256];
tbus robjs[8];
tbus term_obj;
tbus sync_obj;
@@ -210,13 +218,14 @@ xrdp_listen_main_loop(struct xrdp_listen* self)
tbus done_obj;
self->status = 1;
- if (xrdp_listen_get_port(port, sizeof(port)) != 0)
+ if (xrdp_listen_get_port_address(port, sizeof(port),
+ address, sizeof(address)) != 0)
{
g_writeln("xrdp_listen_main_loop: xrdp_listen_get_port failed");
self->status = -1;
return 1;
}
- error = trans_listen(self->listen_trans, port);
+ error = trans_listen_address(self->listen_trans, port,address);
if (error == 0)
{
self->listen_trans->trans_conn_in = xrdp_listen_conn_in;