From fb2b7ee40df1954235d64d7c69899997f5ea3dfc Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Mon, 5 May 2014 11:47:19 +0200 Subject: [PATCH] ipv6 detection fix --- coreapi/linphonecore.c | 4 +++- coreapi/misc.c | 17 +++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index b15bd71b4..edd8a0c47 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -1527,7 +1527,9 @@ void linphone_core_get_local_ip(LinphoneCore *lc, int af, char *result){ strncpy(result,"::1",LINPHONE_IPADDR_SIZE); return; } - }else af=AF_INET; + } + /*in all other cases use IPv4*/ + af=AF_INET; } if (linphone_core_get_local_ip_for(af,NULL,result)==0) return; diff --git a/coreapi/misc.c b/coreapi/misc.c index 38f72bfe3..e3fef7c59 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -1000,12 +1000,12 @@ bool_t linphone_core_tone_indications_enabled(LinphoneCore*lc){ #ifdef HAVE_GETIFADDRS #include -static int get_local_ip_with_getifaddrs(int type, char *address, int size) -{ +static int get_local_ip_with_getifaddrs(int type, char *address, int size){ struct ifaddrs *ifp; struct ifaddrs *ifpstart; - int ret = 0; - + char retaddr[LINPHONE_IPADDR_SIZE]={0}; + bool_t found=FALSE; + if (getifaddrs(&ifpstart) < 0) { return -1; } @@ -1022,17 +1022,18 @@ static int get_local_ip_with_getifaddrs(int type, char *address, int size) if(getnameinfo(ifp->ifa_addr, (type == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in), - address, size, NULL, 0, NI_NUMERICHOST) == 0) { - if (strchr(address, '%') == NULL) { /*avoid ipv6 link-local addresses */ + retaddr, size, NULL, 0, NI_NUMERICHOST) == 0) { + if (strchr(retaddr, '%') == NULL) { /*avoid ipv6 link-local addresses */ /*ms_message("getifaddrs() found %s",address);*/ - ret++; + found=TRUE; break; } } } } freeifaddrs(ifpstart); - return ret; + if (found) strncpy(address,retaddr,size); + return found; } #endif