Skip to content
Snippets Groups Projects
Commit 171e61b2 authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud
Browse files

pjproject: remove usage of CFHOST and use POSIX api instead

This code seems bugguy when the iOS device is in LTE. IPv4 addresses for TURN
is not added, however it's successfully done for getaddrinfo.

From https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/ResolvingDNSHostnames.html
3 APIs exists for doing this resolution: "These functions should be used only
if you are writing portable code" and this is the case of pjsip. We should
avoid any platform specific code because it's hard to maintain.

Moreover, this code was included by https://trac.pjsip.org/repos/ticket/1246
I don't find any reference to this problem about local hostname, moreover,
local hostnames are not resolved by Jami, because we only pass IPs addresses
directly to pjsip, so this ticket doesn't apply for our codebase.

Change-Id: Iff6384eb3325d19f2c215dec953d794823adec51
parent 51c15915
No related branches found
No related tags found
No related merge requests found
pjlib/include/pj/compat/os_auto.h.in | 2 --
pjlib/src/pj/addr_resolv_sock.c | 66 ------------------------------------------------------------------
2 files changed, 68 deletions(-)
diff --git a/pjlib/include/pj/compat/os_auto.h.in b/pjlib/include/pj/compat/os_auto.h.in
index 159d2bcf0..aef68490b 100644
--- a/pjlib/include/pj/compat/os_auto.h.in
+++ b/pjlib/include/pj/compat/os_auto.h.in
@@ -190,8 +190,6 @@
# include "TargetConditionals.h"
# if TARGET_OS_IPHONE
# include "Availability.h"
- /* Use CFHost API for pj_getaddrinfo() (see ticket #1246) */
-# define PJ_GETADDRINFO_USE_CFHOST 1
# ifdef __IPHONE_4_0
/* Is multitasking support available? (see ticket #1107) */
# define PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT 1
diff --git a/pjlib/src/pj/addr_resolv_sock.c b/pjlib/src/pj/addr_resolv_sock.c
index 54646007c..4b09a989e 100644
--- a/pjlib/src/pj/addr_resolv_sock.c
+++ b/pjlib/src/pj/addr_resolv_sock.c
@@ -24,11 +24,6 @@
#include <pj/ip_helper.h>
#include <pj/compat/socket.h>
-#if defined(PJ_GETADDRINFO_USE_CFHOST) && PJ_GETADDRINFO_USE_CFHOST!=0
-# include <CoreFoundation/CFString.h>
-# include <CFNetwork/CFHost.h>
-#endif
-
PJ_DEF(pj_status_t) pj_gethostbyname(const pj_str_t *hostname, pj_hostent *phe)
{
struct hostent *he;
@@ -68,14 +63,8 @@ PJ_DEF(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *nodename,
char nodecopy[PJ_MAX_HOSTNAME];
pj_bool_t has_addr = PJ_FALSE;
unsigned i;
-#if defined(PJ_GETADDRINFO_USE_CFHOST) && PJ_GETADDRINFO_USE_CFHOST!=0
- CFStringRef hostname;
- CFHostRef hostRef;
- pj_status_t status = PJ_SUCCESS;
-#else
int rc;
struct addrinfo hint, *res, *orig_res;
-#endif
PJ_ASSERT_RETURN(nodename && count && *count && ai, PJ_EINVAL);
PJ_ASSERT_RETURN(nodename->ptr && nodename->slen, PJ_EINVAL);
@@ -121,60 +110,6 @@ PJ_DEF(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *nodename,
pj_memcpy(nodecopy, nodename->ptr, nodename->slen);
nodecopy[nodename->slen] = '\0';
-#if defined(PJ_GETADDRINFO_USE_CFHOST) && PJ_GETADDRINFO_USE_CFHOST!=0
- hostname = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, nodecopy,
- kCFStringEncodingASCII,
- kCFAllocatorNull);
- hostRef = CFHostCreateWithName(kCFAllocatorDefault, hostname);
- if (CFHostStartInfoResolution(hostRef, kCFHostAddresses, nil)) {
- CFArrayRef addrRef = CFHostGetAddressing(hostRef, nil);
- i = 0;
- if (addrRef != nil) {
- CFIndex idx, naddr;
-
- naddr = CFArrayGetCount(addrRef);
- for (idx = 0; idx < naddr && i < *count; idx++) {
- struct sockaddr *addr;
- size_t addr_size;
-
- addr = (struct sockaddr *)
- CFDataGetBytePtr(CFArrayGetValueAtIndex(addrRef, idx));
- /* This should not happen. */
- pj_assert(addr);
-
- /* Ignore unwanted address families */
- if (af!=PJ_AF_UNSPEC && addr->sa_family != af)
- continue;
-
- /* Store canonical name */
- pj_ansi_strcpy(ai[i].ai_canonname, nodecopy);
-
- /* Store address */
- addr_size = sizeof(*addr);
- if (addr->sa_family == PJ_AF_INET6) {
- addr_size = addr->sa_len;
- }
- PJ_ASSERT_ON_FAIL(addr_size <= sizeof(pj_sockaddr), continue);
- pj_memcpy(&ai[i].ai_addr, addr, addr_size);
- PJ_SOCKADDR_RESET_LEN(&ai[i].ai_addr);
-
- i++;
- }
- }
-
- *count = i;
- if (*count == 0)
- status = PJ_ERESOLVE;
-
- } else {
- status = PJ_ERESOLVE;
- }
-
- CFRelease(hostRef);
- CFRelease(hostname);
-
- return status;
-#else
/* Call getaddrinfo() */
pj_bzero(&hint, sizeof(hint));
hint.ai_family = af;
@@ -216,7 +151,6 @@ PJ_DEF(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *nodename,
/* Done */
return (*count > 0? PJ_SUCCESS : PJ_ERESOLVE);
-#endif
#else /* PJ_SOCK_HAS_GETADDRINFO */
pj_bool_t has_addr = PJ_FALSE;
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
"0013-Assign-unique-local-preferences-for-candidates-with-.patch", "0013-Assign-unique-local-preferences-for-candidates-with-.patch",
"0014-Add-new-compile-time-setting-PJ_ICE_ST_USE_TURN_PERM.patch", "0014-Add-new-compile-time-setting-PJ_ICE_ST_USE_TURN_PERM.patch",
"0015-update-local-preference-for-peer-reflexive-candidate.patch", "0015-update-local-preference-for-peer-reflexive-candidate.patch",
"0016-use-addrinfo-instead-CFHOST.patch",
"0001-win-config.patch", "0001-win-config.patch",
"0002-win-vs-gnutls.patch", "0002-win-vs-gnutls.patch",
"0003-win-vs2017-props.patch" "0003-win-vs2017-props.patch"
......
...@@ -60,6 +60,7 @@ pjproject: pjproject-$(PJPROJECT_VERSION).tar.gz .sum-pjproject ...@@ -60,6 +60,7 @@ pjproject: pjproject-$(PJPROJECT_VERSION).tar.gz .sum-pjproject
$(APPLY) $(SRC)/pjproject/0013-Assign-unique-local-preferences-for-candidates-with-.patch $(APPLY) $(SRC)/pjproject/0013-Assign-unique-local-preferences-for-candidates-with-.patch
$(APPLY) $(SRC)/pjproject/0014-Add-new-compile-time-setting-PJ_ICE_ST_USE_TURN_PERM.patch $(APPLY) $(SRC)/pjproject/0014-Add-new-compile-time-setting-PJ_ICE_ST_USE_TURN_PERM.patch
$(APPLY) $(SRC)/pjproject/0015-update-local-preference-for-peer-reflexive-candidate.patch $(APPLY) $(SRC)/pjproject/0015-update-local-preference-for-peer-reflexive-candidate.patch
$(APPLY) $(SRC)/pjproject/0016-use-addrinfo-instead-CFHOST.patch
ifdef HAVE_ANDROID ifdef HAVE_ANDROID
$(APPLY) $(SRC)/pjproject/0001-android.patch $(APPLY) $(SRC)/pjproject/0001-android.patch
endif endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment