Commit 2eda794c authored by Simon Morlat's avatar Simon Morlat
Browse files

Handle network connectivity monitoring independently for IPv4 and IPv6....

Handle network connectivity monitoring independently for IPv4 and IPv6. Indeed, the previous code could not work if the host has no IPv6 support at all.
parent 36c6a9d8
......@@ -3437,7 +3437,8 @@ void linphone_core_enable_ipv6(LinphoneCore *lc, bool_t val){
_linphone_core_apply_transports(lc);
}
/*update the localip immediately for the network monitor to avoid to "discover" later that we switched to ipv6*/
linphone_core_get_local_ip(lc,AF_UNSPEC,NULL,lc->localip);
linphone_core_get_local_ip(lc,AF_INET,NULL,lc->localip4);
if (val) linphone_core_get_local_ip(lc,AF_INET6,NULL,lc->localip6);
if (linphone_core_ready(lc)){
lp_config_set_int(lc->config,"sip","use_ipv6",(int)val);
}
......
......@@ -807,7 +807,8 @@ namespace LinphonePrivate {
bool_t forced_ice_relay; \
bool_t short_turn_refresh; \
MSRect qrcode_rect; \
char localip[LINPHONE_IPADDR_SIZE]; \
char localip4[LINPHONE_IPADDR_SIZE]; \
char localip6[LINPHONE_IPADDR_SIZE]; \
int device_rotation; \
int max_calls; \
LinphoneTunnel *tunnel; \
......
......@@ -143,22 +143,39 @@ void GenericPlatformHelpers::onLinphoneCoreStop () {}
int GenericPlatformHelpers::monitorTimerExpired (void *data, unsigned int revents) {
GenericPlatformHelpers *helper = static_cast<GenericPlatformHelpers *>(data);
LinphoneCore *core = helper->getCore()->getCCore();
char newIp[LINPHONE_IPADDR_SIZE];
linphone_core_get_local_ip(core, AF_UNSPEC, nullptr, newIp);
bool status = strcmp(newIp,"::1") != 0 && strcmp(newIp,"127.0.0.1") != 0;
if (status && core->network_last_status && strcmp(newIp, core->localip) != 0) {
lInfo() << "IP address change detected";
helper->setNetworkReachable(false);
core->network_last_status = FALSE;
bool ipv6Enabled = linphone_core_ipv6_enabled(core);
char newIp4[LINPHONE_IPADDR_SIZE];
char newIp6[LINPHONE_IPADDR_SIZE];
linphone_core_get_local_ip(core, AF_INET, nullptr, newIp4);
if (ipv6Enabled)
linphone_core_get_local_ip(core, AF_INET6, nullptr, newIp6);
bool status = strcmp(newIp6,"::1") != 0 || strcmp(newIp4,"127.0.0.1") != 0;
if (status && core->network_last_status){
bool ipChanged = false;
// Check for IP address changes:
if (strcmp(newIp4, core->localip4) != 0) {
lInfo() << "IPv4 address change detected";
ipChanged = true;
}
if (ipv6Enabled && strcmp(newIp6, core->localip6) != 0) {
lInfo() << "IPv6 address change detected";
ipChanged = true;
}
if (ipChanged){
helper->setNetworkReachable(false);
core->network_last_status = FALSE;
}
}
strncpy(core->localip, newIp, sizeof core->localip);
strncpy(core->localip4, newIp4, sizeof core->localip4);
if (ipv6Enabled) strncpy(core->localip6, newIp6, sizeof core->localip6);
if (bool_t(status) != core->network_last_status) {
if (status) {
lInfo() << "New local ip address is " << core->localip;
lInfo() << "Default local ipv4 address is " << core->localip4;
if (ipv6Enabled) lInfo() << "Default local ipv6 address is " << core->localip6;
}
helper->setNetworkReachable(status);
core->network_last_status = status;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment