author | Alberto Bertogli
<albertito@gmail.com> 2007-06-01 18:13:14 UTC |
committer | Alberto Bertogli
<albertito@gmail.com> 2007-06-01 18:13:14 UTC |
parent | 438c10bf3f16243f8dc4684f2e4f45e3f03f0f06 |
nmdb/common.h | +2 | -0 |
nmdb/main.c | +15 | -1 |
nmdb/net-const.h | +4 | -0 |
nmdb/tcp.c | +7 | -3 |
diff --git a/nmdb/common.h b/nmdb/common.h index 210ca4a..31d1548 100644 --- a/nmdb/common.h +++ b/nmdb/common.h @@ -16,6 +16,8 @@ extern struct queue *op_queue; struct settings { int tipc_lower; int tipc_upper; + char *tcp_addr; + int tcp_port; int numobjs; int foreground; int passive; diff --git a/nmdb/main.c b/nmdb/main.c index 8b671db..49e3816 100644 --- a/nmdb/main.c +++ b/nmdb/main.c @@ -28,6 +28,8 @@ static void help(void) { " -d dbpath database path ('database', must be created with dpmgr)\n" " -l lower lower TIPC port number (10)\n" " -L upper upper TIPC port number (= lower)\n" + " -a addr TCP listening address (all local addresses)\n" + " -P port TCP listening port (26010)\n" " -c nobj max. number of objects to be cached, in thousands (128)\n" " -f don't fork and stay in the foreground\n" " -p enable passive mode, for redundancy purposes (read docs.)\n" @@ -45,6 +47,8 @@ static int load_settings(int argc, char **argv) settings.tipc_lower = -1; settings.tipc_upper = -1; + settings.tcp_addr = NULL; + settings.tcp_port = -1; settings.numobjs = -1; settings.foreground = 0; settings.passive = 0; @@ -52,7 +56,7 @@ static int load_settings(int argc, char **argv) settings.dbname = malloc(strlen(DEFDBNAME) + 1); strcpy(settings.dbname, DEFDBNAME); - while ((c = getopt(argc, argv, "d:l:L:c:fph?")) != -1) { + while ((c = getopt(argc, argv, "d:l:L:a:P:c:fph?")) != -1) { switch(c) { case 'd': free(settings.dbname); @@ -65,6 +69,12 @@ static int load_settings(int argc, char **argv) case 'L': settings.tipc_upper = atoi(optarg); break; + case 'a': + settings.tcp_addr = optarg; + break; + case 'P': + settings.tcp_port = atoi(optarg); + break; case 'c': settings.numobjs = atoi(optarg) * 1024; break; @@ -88,6 +98,10 @@ static int load_settings(int argc, char **argv) settings.tipc_lower = TIPC_SERVER_INST; if (settings.tipc_upper == -1) settings.tipc_upper = settings.tipc_lower; + if (settings.tcp_addr == NULL) + settings.tcp_addr = TCP_SERVER_ADDR; + if (settings.tcp_port == -1) + settings.tcp_port = TCP_SERVER_PORT; if (settings.numobjs == -1) settings.numobjs = 128 * 1024; diff --git a/nmdb/net-const.h b/nmdb/net-const.h index e0f5fc2..16871e7 100644 --- a/nmdb/net-const.h +++ b/nmdb/net-const.h @@ -11,6 +11,10 @@ #define TIPC_SERVER_TYPE 26001 #define TIPC_SERVER_INST 10 +/* TCP default listen address and port. */ +#define TCP_SERVER_ADDR "0.0.0.0" +#define TCP_SERVER_PORT 26010 + /* Protocol version, for checking in the network header. */ #define PROTO_VER 1 diff --git a/nmdb/tcp.c b/nmdb/tcp.c index c159315..7b34508 100644 --- a/nmdb/tcp.c +++ b/nmdb/tcp.c @@ -228,12 +228,16 @@ void tcp_reply_cas(struct req_info *req, uint32_t reply) int tcp_init(void) { int fd, rv; - static struct sockaddr_in srvsa; + struct sockaddr_in srvsa; + struct in_addr ia; + rv = inet_pton(AF_INET, settings.tcp_addr, &ia); + if (rv <= 0) + return -1; srvsa.sin_family = AF_INET; - srvsa.sin_addr.s_addr = INADDR_ANY; - srvsa.sin_port = htons(20026); + srvsa.sin_addr.s_addr = ia.s_addr; + srvsa.sin_port = htons(settings.tcp_port); fd = socket(AF_INET, SOCK_STREAM, 0);