Ignore:
Timestamp:
Apr 26, 2011 3:07:24 AM (13 years ago)
Author:
ming
Message:

Fixed #1246: Use CFHost for pj_getaddrinfo() on iOS

  • Replace the fix for ticket #1104 with this fix
  • Modify pjturn-client/client_main's shutdown() function which conflicts with an existing function

Re-run configure-iphone to use this fix automatically.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/addr_resolv_sock.c

    r3234 r3543  
    2525#include <pj/compat/socket.h> 
    2626 
     27#if defined(PJ_GETADDRINFO_USE_CFHOST) && PJ_GETADDRINFO_USE_CFHOST!=0 
     28#   include <CoreFoundation/CFString.h> 
     29#   include <CFNetwork/CFHost.h> 
     30#endif 
    2731 
    2832PJ_DEF(pj_status_t) pj_gethostbyname(const pj_str_t *hostname, pj_hostent *phe) 
     
    6367#if defined(PJ_SOCK_HAS_GETADDRINFO) && PJ_SOCK_HAS_GETADDRINFO!=0 
    6468    char nodecopy[PJ_MAX_HOSTNAME]; 
    65     struct addrinfo hint, *res, *orig_res; 
    6669    pj_bool_t has_addr = PJ_FALSE; 
    6770    unsigned i; 
     71#if defined(PJ_GETADDRINFO_USE_CFHOST) && PJ_GETADDRINFO_USE_CFHOST!=0 
     72    CFStringRef hostname; 
     73    CFHostRef hostRef; 
     74    pj_status_t status = PJ_SUCCESS; 
     75#else 
    6876    int rc; 
     77    struct addrinfo hint, *res, *orig_res; 
     78#endif 
    6979 
    7080    PJ_ASSERT_RETURN(nodename && count && *count && ai, PJ_EINVAL); 
     
    106116    nodecopy[nodename->slen] = '\0'; 
    107117 
     118#if defined(PJ_GETADDRINFO_USE_CFHOST) && PJ_GETADDRINFO_USE_CFHOST!=0 
     119    hostname =  CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, nodecopy, 
     120                                                kCFStringEncodingASCII, 
     121                                                kCFAllocatorNull); 
     122    hostRef = CFHostCreateWithName(kCFAllocatorDefault, hostname); 
     123    if (CFHostStartInfoResolution(hostRef, kCFHostAddresses, nil)) { 
     124        CFArrayRef addrRef = CFHostGetAddressing(hostRef, nil); 
     125        i = 0; 
     126        if (addrRef != nil) { 
     127            CFIndex idx, naddr; 
     128             
     129            naddr = CFArrayGetCount(addrRef); 
     130            for (idx = 0; idx < naddr && i < *count; idx++) { 
     131                struct sockaddr *addr; 
     132                 
     133                addr = (struct sockaddr *) 
     134                       CFDataGetBytePtr(CFArrayGetValueAtIndex(addrRef, idx)); 
     135                /* This should not happen. */ 
     136                pj_assert(addr); 
     137                 
     138                /* Ignore unwanted address families */ 
     139                if (af!=PJ_AF_UNSPEC && addr->sa_family != af) 
     140                    continue; 
     141 
     142                /* Store canonical name */ 
     143                pj_ansi_strcpy(ai[i].ai_canonname, nodecopy); 
     144                 
     145                /* Store address */ 
     146                PJ_ASSERT_ON_FAIL(sizeof(*addr) <= sizeof(pj_sockaddr), 
     147                                  continue); 
     148                pj_memcpy(&ai[i].ai_addr, addr, sizeof(*addr)); 
     149                PJ_SOCKADDR_RESET_LEN(&ai[i].ai_addr); 
     150                 
     151                i++; 
     152            } 
     153        } 
     154         
     155        *count = i; 
     156    } else { 
     157        status = PJ_ERESOLVE; 
     158    } 
     159     
     160    CFRelease(hostRef); 
     161    CFRelease(hostname); 
     162     
     163    return status; 
     164#else 
    108165    /* Call getaddrinfo() */ 
    109166    pj_bzero(&hint, sizeof(hint)); 
     
    146203    /* Done */ 
    147204    return PJ_SUCCESS; 
     205#endif 
    148206 
    149207#else   /* PJ_SOCK_HAS_GETADDRINFO */ 
Note: See TracChangeset for help on using the changeset viewer.