Changeset 3234
- Timestamp:
- Jul 5, 2010 1:47:30 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/addr_resolv_sock.c
r3044 r3234 64 64 char nodecopy[PJ_MAX_HOSTNAME]; 65 65 struct addrinfo hint, *res, *orig_res; 66 pj_bool_t has_addr = PJ_FALSE; 66 67 unsigned i; 67 68 int rc; … … 74 75 /* Check if nodename is IP address */ 75 76 pj_bzero(&ai[0], sizeof(ai[0])); 76 if (af == PJ_AF_UNSPEC) { 77 if (pj_inet_pton(PJ_AF_INET, nodename, 78 &ai[0].ai_addr.ipv4.sin_addr) == PJ_SUCCESS) 79 { 80 af = PJ_AF_INET; 81 } 82 else if (pj_inet_pton(PJ_AF_INET6, nodename, 83 &ai[0].ai_addr.ipv6.sin6_addr) == PJ_SUCCESS) 84 { 85 af = PJ_AF_INET6; 86 } 87 88 if (af != PJ_AF_UNSPEC) { 89 pj_str_t tmp; 90 91 tmp.ptr = ai[0].ai_canonname; 92 pj_strncpy_with_null(&tmp, nodename, PJ_MAX_HOSTNAME); 93 ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; 94 *count = 1; 95 96 return PJ_SUCCESS; 97 } 77 if ((af==PJ_AF_INET || af==PJ_AF_UNSPEC) && 78 pj_inet_pton(PJ_AF_INET, nodename, 79 &ai[0].ai_addr.ipv4.sin_addr) == PJ_SUCCESS) 80 { 81 af = PJ_AF_INET; 82 has_addr = PJ_TRUE; 83 } else if ((af==PJ_AF_INET6 || af==PJ_AF_UNSPEC) && 84 pj_inet_pton(PJ_AF_INET6, nodename, 85 &ai[0].ai_addr.ipv6.sin6_addr) == PJ_SUCCESS) 86 { 87 af = PJ_AF_INET6; 88 has_addr = PJ_TRUE; 89 } 90 91 if (has_addr) { 92 pj_str_t tmp; 93 94 tmp.ptr = ai[0].ai_canonname; 95 pj_strncpy_with_null(&tmp, nodename, PJ_MAX_HOSTNAME); 96 ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; 97 *count = 1; 98 99 return PJ_SUCCESS; 98 100 } 99 101 … … 146 148 147 149 #else /* PJ_SOCK_HAS_GETADDRINFO */ 150 pj_bool_t has_addr = PJ_FALSE; 148 151 149 152 PJ_ASSERT_RETURN(count && *count, PJ_EINVAL); … … 151 154 /* Check if nodename is IP address */ 152 155 pj_bzero(&ai[0], sizeof(ai[0])); 153 if (af == PJ_AF_UNSPEC) { 154 if (pj_inet_pton(PJ_AF_INET, nodename, 155 &ai[0].ai_addr.ipv4.sin_addr) == PJ_SUCCESS) 156 { 157 af = PJ_AF_INET; 158 } 159 else if (pj_inet_pton(PJ_AF_INET6, nodename, 160 &ai[0].ai_addr.ipv6.sin6_addr) == PJ_SUCCESS) 161 { 162 af = PJ_AF_INET6; 163 } 164 165 if (af != PJ_AF_UNSPEC) { 166 pj_str_t tmp; 167 168 tmp.ptr = ai[0].ai_canonname; 169 pj_strncpy_with_null(&tmp, nodename, PJ_MAX_HOSTNAME); 170 ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; 171 *count = 1; 172 173 return PJ_SUCCESS; 174 } 156 if ((af==PJ_AF_INET || af==PJ_AF_UNSPEC) && 157 pj_inet_pton(PJ_AF_INET, nodename, 158 &ai[0].ai_addr.ipv4.sin_addr) == PJ_SUCCESS) 159 { 160 af = PJ_AF_INET; 161 has_addr = PJ_TRUE; 162 } 163 else if ((af==PJ_AF_INET6 || af==PJ_AF_UNSPEC) && 164 pj_inet_pton(PJ_AF_INET6, nodename, 165 &ai[0].ai_addr.ipv6.sin6_addr) == PJ_SUCCESS) 166 { 167 af = PJ_AF_INET6; 168 has_addr = PJ_TRUE; 169 } 170 171 if (has_addr) { 172 pj_str_t tmp; 173 174 tmp.ptr = ai[0].ai_canonname; 175 pj_strncpy_with_null(&tmp, nodename, PJ_MAX_HOSTNAME); 176 ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; 177 *count = 1; 178 179 return PJ_SUCCESS; 175 180 } 176 181
Note: See TracChangeset
for help on using the changeset viewer.