- Timestamp:
- Jan 4, 2010 4:54:50 PM (15 years ago)
- Location:
- pjproject/trunk/pjlib/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/addr_resolv_sock.c
r2394 r3044 74 74 /* Check if nodename is IP address */ 75 75 pj_bzero(&ai[0], sizeof(ai[0])); 76 ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; 77 if (pj_inet_pton(af, nodename, pj_sockaddr_get_addr(&ai[0].ai_addr)) 78 == PJ_SUCCESS) 79 { 80 pj_str_t tmp; 81 82 tmp.ptr = ai[0].ai_canonname; 83 pj_strncpy_with_null(&tmp, nodename, PJ_MAX_HOSTNAME); 84 ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; 85 *count = 1; 86 87 return PJ_SUCCESS; 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 } 88 98 } 89 99 … … 122 132 PJ_ASSERT_ON_FAIL(res->ai_addrlen <= sizeof(pj_sockaddr), continue); 123 133 pj_memcpy(&ai[i].ai_addr, res->ai_addr, res->ai_addrlen); 134 PJ_SOCKADDR_RESET_LEN(&ai[i].ai_addr); 124 135 125 136 /* Next slot */ … … 140 151 /* Check if nodename is IP address */ 141 152 pj_bzero(&ai[0], sizeof(ai[0])); 142 ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; 143 if (pj_inet_pton(af, nodename, pj_sockaddr_get_addr(&ai[0].ai_addr)) 144 == PJ_SUCCESS) 145 { 146 pj_str_t tmp; 147 148 tmp.ptr = ai[0].ai_canonname; 149 pj_strncpy_with_null(&tmp, nodename, PJ_MAX_HOSTNAME); 150 ai[0].ai_addr.addr.sa_family = (pj_uint16_t)af; 151 *count = 1; 152 153 return PJ_SUCCESS; 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 } 154 175 } 155 176 … … 181 202 pj_memcpy(&ai[*count].ai_addr.ipv4.sin_addr, 182 203 he.h_addr_list[i], he.h_length); 204 PJ_SOCKADDR_RESET_LEN(&ai[*count].ai_addr); 183 205 184 206 (*count)++; -
pjproject/trunk/pjlib/src/pj/ip_helper_generic.c
r2394 r3044 122 122 pj_bzero(&ifs[*p_cnt], sizeof(ifs[0])); 123 123 pj_memcpy(&ifs[*p_cnt], ad, pj_sockaddr_get_len(ad)); 124 PJ_SOCKADDR_RESET_LEN(&ifs[*p_cnt]); 124 125 (*p_cnt)++; 125 126 } … … 216 217 pj_bzero(&ifs[*p_cnt], sizeof(ifs[0])); 217 218 pj_memcpy(&ifs[*p_cnt], ad, pj_sockaddr_get_len(ad)); 219 PJ_SOCKADDR_RESET_LEN(&ifs[*p_cnt]); 218 220 (*p_cnt)++; 219 221 } … … 306 308 pj_bzero(&ifs[*p_cnt], sizeof(ifs[0])); 307 309 pj_memcpy(&ifs[*p_cnt], ad, pj_sockaddr_get_len(ad)); 310 PJ_SOCKADDR_RESET_LEN(&ifs[*p_cnt]); 308 311 (*p_cnt)++; 309 312 } -
pjproject/trunk/pjlib/src/pjlib-test/sock.c
r3016 r3044 72 72 static char bigdata[BIG_DATA_LEN]; 73 73 static char bigbuffer[BIG_DATA_LEN]; 74 75 /* Macro for checking the value of "sin_len" member of sockaddr 76 * (it must always be zero). 77 */ 78 #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 79 # define CHECK_SA_ZERO_LEN(addr, ret) \ 80 if (((pj_addr_hdr*)(addr))->sa_zero_len != 0) \ 81 return ret 82 #else 83 # define CHECK_SA_ZERO_LEN(addr, ret) 84 #endif 85 74 86 75 87 static int format_test(void) … … 285 297 } 286 298 299 /* Check "sin_len" member of parse result */ 300 CHECK_SA_ZERO_LEN(&addr, -20); 301 287 302 /* Build the correct result */ 288 303 status = pj_sockaddr_init(valid_tests[i].result_af, … … 312 327 return -50; 313 328 } 329 330 /* Check "sin_len" member of parse result */ 331 CHECK_SA_ZERO_LEN(&addr, -55); 314 332 315 333 /* Compare the result again */ … … 348 366 } 349 367 } 368 369 return 0; 370 } 371 372 static int purity_test(void) 373 { 374 PJ_LOG(3,("test", "...purity_test()")); 375 376 #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 377 /* Check on "sin_len" member of sockaddr */ 378 { 379 const pj_str_t str_ip = {"1.1.1.1", 7}; 380 pj_sockaddr addr[16]; 381 pj_addrinfo ai[16]; 382 unsigned cnt; 383 pj_status_t rc; 384 385 /* pj_enum_ip_interface() */ 386 cnt = PJ_ARRAY_SIZE(addr); 387 rc = pj_enum_ip_interface(pj_AF_UNSPEC(), &cnt, addr); 388 if (rc == PJ_SUCCESS) { 389 while (cnt--) 390 CHECK_SA_ZERO_LEN(&addr[cnt], -10); 391 } 392 393 /* pj_gethostip() on IPv4 */ 394 rc = pj_gethostip(pj_AF_INET(), &addr[0]); 395 if (rc == PJ_SUCCESS) 396 CHECK_SA_ZERO_LEN(&addr[0], -20); 397 398 /* pj_gethostip() on IPv6 */ 399 rc = pj_gethostip(pj_AF_INET6(), &addr[0]); 400 if (rc == PJ_SUCCESS) 401 CHECK_SA_ZERO_LEN(&addr[0], -30); 402 403 /* pj_getdefaultipinterface() on IPv4 */ 404 rc = pj_getdefaultipinterface(pj_AF_INET(), &addr[0]); 405 if (rc == PJ_SUCCESS) 406 CHECK_SA_ZERO_LEN(&addr[0], -40); 407 408 /* pj_getdefaultipinterface() on IPv6 */ 409 rc = pj_getdefaultipinterface(pj_AF_INET6(), &addr[0]); 410 if (rc == PJ_SUCCESS) 411 CHECK_SA_ZERO_LEN(&addr[0], -50); 412 413 /* pj_getaddrinfo() on a host name */ 414 cnt = PJ_ARRAY_SIZE(ai); 415 rc = pj_getaddrinfo(pj_AF_UNSPEC(), pj_gethostname(), &cnt, ai); 416 if (rc == PJ_SUCCESS) { 417 while (cnt--) 418 CHECK_SA_ZERO_LEN(&ai[cnt].ai_addr, -60); 419 } 420 421 /* pj_getaddrinfo() on an IP address */ 422 cnt = PJ_ARRAY_SIZE(ai); 423 rc = pj_getaddrinfo(pj_AF_UNSPEC(), &str_ip, &cnt, ai); 424 if (rc == PJ_SUCCESS) { 425 pj_assert(cnt == 1); 426 CHECK_SA_ZERO_LEN(&ai[0].ai_addr, -70); 427 } 428 } 429 #endif 350 430 351 431 return 0; … … 761 841 return rc; 762 842 843 rc = purity_test(); 844 if (rc != 0) 845 return rc; 846 763 847 rc = gethostbyname_test(); 764 848 if (rc != 0)
Note: See TracChangeset
for help on using the changeset viewer.