bind to specific address

ulab-original
Jay Sorg 14 years ago
parent bb7898419f
commit 1e8b5ea2cd

@ -450,6 +450,24 @@ g_tcp_local_bind(int sck, char* port)
#endif #endif
} }
/*****************************************************************************/
/* 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 */ /* returns error, zero is good */
int APP_CC int APP_CC

@ -76,6 +76,8 @@ g_tcp_bind(int sck, char* port);
int APP_CC int APP_CC
g_tcp_local_bind(int sck, char* port); g_tcp_local_bind(int sck, char* port);
int APP_CC int APP_CC
g_tcp_bind_address(int sck, char* port, const char* address);
int APP_CC
g_tcp_listen(int sck); g_tcp_listen(int sck);
int APP_CC int APP_CC
g_tcp_accept(int sck); g_tcp_accept(int sck);

@ -342,7 +342,7 @@ trans_connect(struct trans* self, const char* server, const char* port,
/*****************************************************************************/ /*****************************************************************************/
int APP_CC 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) if (self->sck != 0)
{ {
@ -352,7 +352,7 @@ trans_listen(struct trans* self, char* port)
{ {
self->sck = g_tcp_socket(); self->sck = g_tcp_socket();
g_tcp_set_non_blocking(self->sck); 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) if (g_tcp_listen(self->sck) == 0)
{ {
@ -384,6 +384,13 @@ trans_listen(struct trans* self, char* port)
return 1; return 1;
} }
/*****************************************************************************/
int APP_CC
trans_listen(struct trans* self, char* port)
{
return trans_listen_address(self, port, "0.0.0.0");
}
/*****************************************************************************/ /*****************************************************************************/
struct stream* APP_CC struct stream* APP_CC
trans_get_in_s(struct trans* self) trans_get_in_s(struct trans* self)

@ -79,6 +79,8 @@ int APP_CC
trans_connect(struct trans* self, const char* server, const char* port, trans_connect(struct trans* self, const char* server, const char* port,
int timeout); int timeout);
int APP_CC int APP_CC
trans_listen_address(struct trans* self, char* port, const char* address);
int APP_CC
trans_listen(struct trans* self, char* port); trans_listen(struct trans* self, char* port);
struct stream* APP_CC struct stream* APP_CC
trans_get_in_s(struct trans* self); trans_get_in_s(struct trans* self);

@ -119,7 +119,8 @@ xrdp_process_run(void* in_val)
/*****************************************************************************/ /*****************************************************************************/
static int 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 fd;
int error; int error;
@ -131,7 +132,9 @@ xrdp_listen_get_port(char* port, int port_bytes)
/* default to port 3389 */ /* default to port 3389 */
g_strncpy(port, "3389", port_bytes - 1); 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); g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
fd = g_file_open(cfg_file); fd = g_file_open(cfg_file);
if (fd > 0) if (fd > 0)
@ -155,7 +158,11 @@ xrdp_listen_get_port(char* port, int port_bytes)
{ {
g_strncpy(port, val, port_bytes - 1); 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 cont;
int timeout; int timeout;
char port[8]; char port[8];
char address[256];
tbus robjs[8]; tbus robjs[8];
tbus term_obj; tbus term_obj;
tbus sync_obj; tbus sync_obj;
@ -210,13 +218,14 @@ xrdp_listen_main_loop(struct xrdp_listen* self)
tbus done_obj; tbus done_obj;
self->status = 1; 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"); g_writeln("xrdp_listen_main_loop: xrdp_listen_get_port failed");
self->status = -1; self->status = -1;
return 1; return 1;
} }
error = trans_listen(self->listen_trans, port); error = trans_listen_address(self->listen_trans, port,address);
if (error == 0) if (error == 0)
{ {
self->listen_trans->trans_conn_in = xrdp_listen_conn_in; self->listen_trans->trans_conn_in = xrdp_listen_conn_in;

Loading…
Cancel
Save