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
This commit is contained in:
Michael Jerris 2006-04-13 01:05:47 +00:00
parent 345518019f
commit ecc2a3baa1
4 changed files with 16 additions and 6 deletions

View File

@ -74,6 +74,7 @@ load => mod_softtimer
[+iax.conf] [+iax.conf]
[settings] [settings]
debug => 0 debug => 0
;ip => 1.2.3.4
port => 4569 port => 4569
dialplan => demo dialplan => demo
codec_prefs => PCMU,PCMA,speex,L16 codec_prefs => PCMU,PCMA,speex,L16

View File

@ -125,7 +125,7 @@ extern "C"
/* Called to initialize IAX structures and sockets. Returns actual /* Called to initialize IAX structures and sockets. Returns actual
portnumber (which it will try preferred portno first, but if not portnumber (which it will try preferred portno first, but if not
take what it can get */ take what it can get */
extern int iax_init(int preferredportno); extern int iax_init(char *ip, int preferredportno);
extern int iax_shutdown(void); extern int iax_shutdown(void);

View File

@ -917,7 +917,7 @@ int iax_shutdown(void)
return do_shutdown++; return do_shutdown++;
} }
int iax_init(int preferredportno) int iax_init(char *ip, int preferredportno)
{ {
int portno = preferredportno; int portno = preferredportno;
struct sockaddr_in sin; struct sockaddr_in sin;
@ -944,7 +944,12 @@ int iax_init(int preferredportno)
if (preferredportno > 0) { if (preferredportno > 0) {
sin.sin_family = AF_INET; 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); sin.sin_port = htons((short)preferredportno);
if (bind(netfd, (struct sockaddr *) &sin, sizeof(sin)) < 0) { if (bind(netfd, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
DEBU(G "Unable to bind to preferred port. Using random one instead."); DEBU(G "Unable to bind to preferred port. Using random one instead.");

View File

@ -64,6 +64,7 @@ typedef enum {
static struct { static struct {
int debug; int debug;
char *ip;
int port; int port;
char *dialplan; char *dialplan;
char *codec_string; 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_dialplan, globals.dialplan)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_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_codec_rates_string, globals.codec_rates_string)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip)
static char *IAXNAMES[] = static char *IAXNAMES[] =
@ -830,6 +832,8 @@ static switch_status load_config(void)
globals.debug = atoi(val); globals.debug = atoi(val);
} else if (!strcmp(var, "port")) { } else if (!strcmp(var, "port")) {
globals.port = atoi(val); globals.port = atoi(val);
} else if (!strcmp(var, "ip")) {
set_global_ip(val);
} else if (!strcmp(var, "codec_master")) { } else if (!strcmp(var, "codec_master")) {
if (!strcasecmp(val, "us")) { if (!strcasecmp(val, "us")) {
switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS); switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS);
@ -873,7 +877,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
if (globals.debug) { if (globals.debug) {
iax_enable_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"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Error Binding Port!\n");
return SWITCH_STATUS_TERM; return SWITCH_STATUS_TERM;
} }