Changeset 3543 for pjproject/trunk/pjlib/src/pj/addr_resolv_sock.c
- Timestamp:
- Apr 26, 2011 3:07:24 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/addr_resolv_sock.c
r3234 r3543 25 25 #include <pj/compat/socket.h> 26 26 27 #if defined(PJ_GETADDRINFO_USE_CFHOST) && PJ_GETADDRINFO_USE_CFHOST!=0 28 # include <CoreFoundation/CFString.h> 29 # include <CFNetwork/CFHost.h> 30 #endif 27 31 28 32 PJ_DEF(pj_status_t) pj_gethostbyname(const pj_str_t *hostname, pj_hostent *phe) … … 63 67 #if defined(PJ_SOCK_HAS_GETADDRINFO) && PJ_SOCK_HAS_GETADDRINFO!=0 64 68 char nodecopy[PJ_MAX_HOSTNAME]; 65 struct addrinfo hint, *res, *orig_res;66 69 pj_bool_t has_addr = PJ_FALSE; 67 70 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 68 76 int rc; 77 struct addrinfo hint, *res, *orig_res; 78 #endif 69 79 70 80 PJ_ASSERT_RETURN(nodename && count && *count && ai, PJ_EINVAL); … … 106 116 nodecopy[nodename->slen] = '\0'; 107 117 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 108 165 /* Call getaddrinfo() */ 109 166 pj_bzero(&hint, sizeof(hint)); … … 146 203 /* Done */ 147 204 return PJ_SUCCESS; 205 #endif 148 206 149 207 #else /* PJ_SOCK_HAS_GETADDRINFO */
Note: See TracChangeset
for help on using the changeset viewer.