From 3c2d4f9912768c34bb8639235f0246f2e0507998 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Wed, 17 Jun 2009 04:15:45 +0000 Subject: [PATCH] Make ttl configurable for event_multicast git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13802 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../mod_event_multicast/mod_event_multicast.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c index 410f5e57ac..cf3ea8048b 100644 --- a/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c +++ b/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c @@ -55,6 +55,7 @@ static struct { uint8_t event_list[SWITCH_EVENT_ALL + 1]; int running; switch_event_node_t *node; + uint8_t ttl; } globals; SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_address, globals.address); @@ -74,6 +75,8 @@ static switch_status_t load_config(void) globals.host_hash = switch_hashfunc_default(globals.hostname, &hlen); globals.key_count = 0; + globals.ttl = 1; + if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", cf); return SWITCH_STATUS_TERM; @@ -95,7 +98,15 @@ static switch_status_t load_config(void) set_global_bindings(val); } else if (!strcasecmp(var, "port")) { globals.port = (switch_port_t) atoi(val); + } else if (!strcasecmp(var, "ttl")) { + int ttl = atoi(val); + if ((ttl && ttl <= 255) || !strcmp(val, "0")) { + globals.ttl = (uint8_t) ttl; + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid ttl '%s' specified, using default of 1\n", val); + } } + } } @@ -222,6 +233,12 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load) return SWITCH_STATUS_TERM; } + if (switch_mcast_hops(globals.udp_socket, globals.ttl) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to set ttl to '%d'\n", globals.ttl); + switch_socket_close(globals.udp_socket); + return SWITCH_STATUS_TERM; + } + if (switch_socket_bind(globals.udp_socket, globals.addr) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bind Error\n"); switch_socket_close(globals.udp_socket);