summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorJay Sorg <jay.sorg@gmail.com>2010-10-19 21:23:13 -0700
committerJay Sorg <jay.sorg@gmail.com>2010-10-19 21:23:13 -0700
commit1e8b5ea2cd2415e8c9ca2c5cb36d3d76071f8f76 (patch)
tree7a84e9c31f653ef75e648f403d6e1b8e1a658d9c /common
parentbb7898419fea4648d7038ff78037df24a271b491 (diff)
downloadxrdp-proprietary-1e8b5ea2cd2415e8c9ca2c5cb36d3d76071f8f76.tar.gz
xrdp-proprietary-1e8b5ea2cd2415e8c9ca2c5cb36d3d76071f8f76.zip
bind to specific address
Diffstat (limited to 'common')
-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
4 files changed, 31 insertions, 2 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);