Subject: [PATCH] pjsua: new option: --bind-addr

This is against svn r2391.
(Please CC: me on reply as I'm not subscribed.)

ChangeLog:

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>

--- pjproject/pjsip-apps/src/pjsua/pjsua_app.c.orig	2008-12-20 21:40:29.000000000 +0100
+++ pjproject/pjsip-apps/src/pjsua/pjsua_app.c	2008-12-20 21:47:56.000000000 +0100
@@ -197,6 +197,8 @@
     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.");
@@ -461,7 +463,7 @@
     enum { OPT_CONFIG_FILE=127, OPT_LOG_FILE, OPT_LOG_LEVEL, OPT_APP_LOG_LEVEL, 
 	   OPT_COLOR, OPT_NO_COLOR, OPT_LIGHT_BG,
 	   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_CONTACT_PARAMS,
 	   OPT_100REL, OPT_USE_IMS, OPT_REALM, OPT_USERNAME, OPT_PASSWORD,
@@ -506,6 +508,7 @@
 	{ "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},
@@ -729,6 +732,11 @@
 	    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);
@@ -1500,6 +1508,14 @@
     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", 
