From ecc2a3baa1fe5aa272479c9d599c0e9723c793d0 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 13 Apr 2006 01:05:47 +0000 Subject: [PATCH] let iax bind to specific ip (rm libs/iax/.complete next time you build) git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1134 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- conf/freeswitch.conf | 1 + libs/iax/src/iax-client.h | 2 +- libs/iax/src/iax.c | 9 +++++++-- src/mod/endpoints/mod_iax/mod_iax.c | 10 +++++++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/conf/freeswitch.conf b/conf/freeswitch.conf index 8768f918e5..cd3a828b89 100644 --- a/conf/freeswitch.conf +++ b/conf/freeswitch.conf @@ -74,6 +74,7 @@ load => mod_softtimer [+iax.conf] [settings] debug => 0 +;ip => 1.2.3.4 port => 4569 dialplan => demo codec_prefs => PCMU,PCMA,speex,L16 diff --git a/libs/iax/src/iax-client.h b/libs/iax/src/iax-client.h index 837e5b7eea..533e1978a0 100644 --- a/libs/iax/src/iax-client.h +++ b/libs/iax/src/iax-client.h @@ -125,7 +125,7 @@ extern "C" /* Called to initialize IAX structures and sockets. Returns actual portnumber (which it will try preferred portno first, but if not take what it can get */ -extern int iax_init(int preferredportno); +extern int iax_init(char *ip, int preferredportno); extern int iax_shutdown(void); diff --git a/libs/iax/src/iax.c b/libs/iax/src/iax.c index 607b1ed5f7..5448b8196a 100644 --- a/libs/iax/src/iax.c +++ b/libs/iax/src/iax.c @@ -917,7 +917,7 @@ int iax_shutdown(void) return do_shutdown++; } -int iax_init(int preferredportno) +int iax_init(char *ip, int preferredportno) { int portno = preferredportno; struct sockaddr_in sin; @@ -944,7 +944,12 @@ int iax_init(int preferredportno) if (preferredportno > 0) { sin.sin_family = AF_INET; - sin.sin_addr.s_addr = 0; + if (ip) { + inet_aton(ip, &sin.sin_addr); + } else { + sin.sin_addr.s_addr = 0; + } + sin.sin_port = htons((short)preferredportno); if (bind(netfd, (struct sockaddr *) &sin, sizeof(sin)) < 0) { DEBU(G "Unable to bind to preferred port. Using random one instead."); diff --git a/src/mod/endpoints/mod_iax/mod_iax.c b/src/mod/endpoints/mod_iax/mod_iax.c index 550ee95387..d5108fe2ca 100644 --- a/src/mod/endpoints/mod_iax/mod_iax.c +++ b/src/mod/endpoints/mod_iax/mod_iax.c @@ -64,6 +64,7 @@ typedef enum { static struct { int debug; + char *ip; int port; char *dialplan; char *codec_string; @@ -92,8 +93,9 @@ struct private_object { }; SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan) - SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string) - SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string) +SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string) +SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string) +SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip) static char *IAXNAMES[] = @@ -830,6 +832,8 @@ static switch_status load_config(void) globals.debug = atoi(val); } else if (!strcmp(var, "port")) { globals.port = atoi(val); + } else if (!strcmp(var, "ip")) { + set_global_ip(val); } else if (!strcmp(var, "codec_master")) { if (!strcasecmp(val, "us")) { switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS); @@ -873,7 +877,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) if (globals.debug) { iax_enable_debug(); } - if (iax_init(globals.port) < 0) { + if (iax_init(globals.ip, globals.port) < 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error Binding Port!\n"); return SWITCH_STATUS_TERM; }