}
/* opens the inet and unix sockets that we're listening on */
-int jserver_connect(jserver* js, int port, char* unix_path) {
+int jserver_connect(jserver* js, int port, char* listen_ip, char* unix_path) {
if(js == NULL || js->mgr == NULL) return -1;
int status = 0;
if(port > 0) {
- status = socket_open_tcp_server(js->mgr, port);
+ status = socket_open_tcp_server(js->mgr, port, listen_ip);
if(status == -1) return status;
}
void jserver_free();
/* opens the inet and unix sockets that we're listening on
+ listen_ip is the IP address the server should listen on.
+ if listen_ip is NULL, jserver will bind to all local IP's.
if(port < 1) no inet socket is opened
if unix_path == NULL no unix socket is opened
returns -1 on error */
-int jserver_connect(jserver* js, int port, char* unix_path);
+int jserver_connect(jserver* js, int port, char* listen_ip, char* unix_path);
/* allocates a new client node */
jclient_node* _new_jclient_node(int id);
char* unix_sock_file = NULL;
int log_level = -1;
char* log_file = NULL;
+char* listen_ip = NULL;
/* starts the logging and server processes */
void launch_server();
char* prog = argv[0];
char* sport = argv[1];
- unix_sock_file = argv[2];
- char* slog_level = argv[3];
- log_file = argv[4];
+ listen_ip = argv[2];
+ unix_sock_file = argv[3];
+ char* slog_level = argv[4];
+ log_file = argv[5];
if(!sport || !unix_sock_file || !slog_level) {
fprintf(stderr,
- "usage: %s <port> <path_to_unix_sock_file> <log_level [1-4]"
+ "usage: %s <port> <listen_ip> <path_to_unix_sock_file> <log_level [1-4]"
"(4 is the highest)> [log_file (optional, goes to stderr otherwise)]\n"
- "e.g: %s 5222 /tmp/server.sock 1 /tmp/server.log\n",
+ "e.g: %s 5222 10.0.0.100 /tmp/server.sock 1 /tmp/server.log\n"
+ "if listen_ip is '*', then we will listen on all addresses",
prog, prog);
return 99;
}
info_handler("Booting jserver-c on port %d and "
"sock file %s", port, unix_sock_file);
+ if(!strcmp(listen_ip,"*")) listen_ip = NULL;
+
js = jserver_init();
unlink(unix_sock_file);
- if(jserver_connect(js, port, unix_sock_file) < 0)
+ if(jserver_connect(js, port, listen_ip, unix_sock_file) < 0)
fatal_handler("Could not connect...");
jserver_wait(js);