mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-13 17:38:59 +00:00
add auto ip-change detection and some other goodies
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9138 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -76,9 +76,55 @@ static void send_heartbeat(void)
|
||||
}
|
||||
}
|
||||
|
||||
static char main_ip4[256] = "";
|
||||
static char main_ip6[256] = "";
|
||||
|
||||
static void check_ip(void) {
|
||||
char guess_ip4[256] = "";
|
||||
char guess_ip6[256] = "";
|
||||
int ok4 = 1, ok6 = 1;
|
||||
|
||||
switch_find_local_ip(guess_ip4, sizeof(guess_ip4), AF_INET);
|
||||
switch_find_local_ip(guess_ip6, sizeof(guess_ip6), AF_INET6);
|
||||
|
||||
if (!*main_ip4) {
|
||||
switch_set_string(main_ip4, guess_ip4);
|
||||
} else {
|
||||
if (!(ok4 = !strcmp(main_ip4, guess_ip4))) {
|
||||
switch_set_string(main_ip4, guess_ip4);
|
||||
switch_core_set_variable("local_ip_v4", guess_ip4);
|
||||
}
|
||||
}
|
||||
|
||||
if (!*main_ip6) {
|
||||
switch_set_string(main_ip6, guess_ip6);
|
||||
} else {
|
||||
if (!(ok6 = !strcmp(main_ip6, guess_ip6))) {
|
||||
switch_set_string(main_ip6, guess_ip6);
|
||||
switch_core_set_variable("local_ip_v4", guess_ip6);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ok4 || !ok6) {
|
||||
switch_event_t *event;
|
||||
|
||||
if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "condition", "network-address-change");
|
||||
if (!ok4) {
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "network-address-change-v4", "%s", main_ip4);
|
||||
}
|
||||
if (!ok6) {
|
||||
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "network-address-change-v6", "%s", main_ip6);
|
||||
}
|
||||
switch_event_fire(&event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SWITCH_STANDARD_SCHED_FUNC(heartbeat_callback)
|
||||
{
|
||||
send_heartbeat();
|
||||
check_ip();
|
||||
|
||||
/* reschedule this task */
|
||||
task->runtime = switch_timestamp(NULL) + 20;
|
||||
|
Reference in New Issue
Block a user