Subject: pjsua: new option: --bind-addr

Implement new option for pjsua to force use of specific socket address.
Needed for running multiple instances on the same host with same port
but different IP.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>

diff -uprN pjproject-0.9.0/pjsip-apps/src/pjsua/pjsua_app.c pjproject-0.9.0-new/pjsip-apps/src/pjsua/pjsua_app.c
--- pjproject-0.9.0/pjsip-apps/src/pjsua/pjsua_app.c	2008-06-27 14:52:51.000000000 +0200
+++ pjproject-0.9.0-new/pjsip-apps/src/pjsua/pjsua_app.c	2008-08-19 20:43:15.000000000 +0200
@@ -187,6 +187,8 @@ static void usage(void)
     puts  ("  --local-port=port   Set TCP/UDP port. This implicitly enables both ");
     puts  ("                      TCP and UDP transports on the specified port, unless");
     puts  ("                      if TCP or UDP is disabled.");
+    puts  ("  --bind-addr=IP      Bind socket to the specifed address for SIP and RTP.");
+    puts  ("                      (Hint: the IP must be configured on local interface)");
     puts  ("  --ip-addr=IP        Use the specifed address as SIP and RTP addresses.");
     puts  ("                      (Hint: the IP may be the public IP of the NAT/router)");
     puts  ("  --no-tcp            Disable TCP transport.");
@@ -441,7 +443,7 @@ static pj_status_t parse_args(int argc, 
     int option_index;
     enum { OPT_CONFIG_FILE=127, OPT_LOG_FILE, OPT_LOG_LEVEL, OPT_APP_LOG_LEVEL, 
 	   OPT_HELP, OPT_VERSION, OPT_NULL_AUDIO, OPT_SND_AUTO_CLOSE,
-	   OPT_LOCAL_PORT, OPT_IP_ADDR, OPT_PROXY, OPT_OUTBOUND_PROXY, 
+	   OPT_LOCAL_PORT, OPT_BIND_ADDR, OPT_IP_ADDR, OPT_PROXY, OPT_OUTBOUND_PROXY, 
 	   OPT_REGISTRAR, OPT_REG_TIMEOUT, OPT_PUBLISH, OPT_ID, OPT_CONTACT,
 	   OPT_100REL, OPT_USE_IMS, OPT_REALM, OPT_USERNAME, OPT_PASSWORD,
 	   OPT_NAMESERVER, OPT_STUN_DOMAIN, OPT_STUN_SRV,
@@ -481,6 +483,7 @@ static pj_status_t parse_args(int argc, 
 	{ "stereo",	0, 0, OPT_STEREO},
 	{ "null-audio", 0, 0, OPT_NULL_AUDIO},
 	{ "local-port", 1, 0, OPT_LOCAL_PORT},
+	{ "bind-addr",	1, 0, OPT_BIND_ADDR},
 	{ "ip-addr",	1, 0, OPT_IP_ADDR},
 	{ "no-tcp",     0, 0, OPT_NO_TCP},
 	{ "no-udp",     0, 0, OPT_NO_UDP},
@@ -680,6 +683,11 @@ static pj_status_t parse_args(int argc, 
 	    cfg->udp_cfg.port = (pj_uint16_t)lval;
 	    break;
 
+	case OPT_BIND_ADDR: /* bind-addr */
+	    cfg->udp_cfg.bound_addr = pj_str(pj_optarg);
+	    cfg->rtp_cfg.bound_addr = pj_str(pj_optarg);
+	    break;
+
 	case OPT_IP_ADDR: /* ip-addr */
 	    cfg->udp_cfg.public_addr = pj_str(pj_optarg);
 	    cfg->rtp_cfg.public_addr = pj_str(pj_optarg);
@@ -1410,6 +1418,14 @@ static int write_settings(const struct a
     pj_ansi_sprintf(line, "--local-port %d\n", config->udp_cfg.port);
     pj_strcat2(&cfg, line);
 
+    /* bound IP address, if any. */
+    if (config->udp_cfg.bound_addr.slen) {
+	pj_ansi_sprintf(line, "--bind-addr %.*s\n", 
+			(int)config->udp_cfg.bound_addr.slen,
+			config->udp_cfg.bound_addr.ptr);
+	pj_strcat2(&cfg, line);
+    }
+
     /* IP address, if any. */
     if (config->udp_cfg.public_addr.slen) {
 	pj_ansi_sprintf(line, "--ip-addr %.*s\n", 
