]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Make ttl configurable for event_multicast
authorAndrew Thompson <andrew@hijacked.us>
Wed, 17 Jun 2009 04:15:45 +0000 (04:15 +0000)
committerAndrew Thompson <andrew@hijacked.us>
Wed, 17 Jun 2009 04:15:45 +0000 (04:15 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13802 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c

index 410f5e57aca2059450eebff026e058e458dcdfa1..cf3ea8048b7e657143095714d13474a85e4dea6a 100644 (file)
@@ -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);