Changeset 1647 for pjproject/trunk/pjlib/src/pj/sock_common.c
- Timestamp:
- Dec 31, 2007 11:26:21 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/sock_common.c
r1629 r1647 456 456 status = pj_getaddrinfo(af, pj_gethostname(), &count, &ai); 457 457 if (status == PJ_SUCCESS) { 458 pj_memcpy(pj_sockaddr_get_addr(addr), 459 pj_sockaddr_get_addr(&ai.ai_addr), 460 pj_sockaddr_get_addr_len(&ai.ai_addr)); 458 pj_assert(ai.ai_addr.addr.sa_family == (pj_uint16_t)af); 459 pj_sockaddr_copy_addr(addr, &ai.ai_addr); 461 460 } 462 461 … … 466 465 */ 467 466 if (status != PJ_SUCCESS || !pj_sockaddr_has_addr(addr) || 468 (af==PJ_AF_INET && (pj_ntohl(addr->ipv4.sin_addr.s_addr) >> 24)==127))467 (af==PJ_AF_INET && (pj_ntohl(addr->ipv4.sin_addr.s_addr) >> 24)==127)) 469 468 { 470 status = pj_getdefaultipinterface(af, addr);469 status = pj_getdefaultipinterface(af, addr); 471 470 } 472 471 473 472 /* If failed, get the first available interface */ 474 473 if (status != PJ_SUCCESS) { 475 pj_sockaddr itf[1]; 476 unsigned count = PJ_ARRAY_SIZE(itf); 477 478 status = pj_enum_ip_interface(af, &count, itf); 479 if (status == PJ_SUCCESS) { 480 itf[0].addr.sa_family = (pj_uint16_t)af; 481 pj_memcpy(pj_sockaddr_get_addr(addr), 482 pj_sockaddr_get_addr(&itf[0]), 483 pj_sockaddr_get_addr_len(&itf[0])); 484 } 474 pj_sockaddr itf[1]; 475 unsigned count = PJ_ARRAY_SIZE(itf); 476 477 status = pj_enum_ip_interface(af, &count, itf); 478 if (status == PJ_SUCCESS) { 479 pj_assert(itf[0].addr.sa_family == (pj_uint16_t)af); 480 pj_sockaddr_copy_addr(addr, &itf[0]); 481 } 485 482 } 486 483 487 484 /* If else fails, returns loopback interface as the last resort */ 488 485 if (status != PJ_SUCCESS) { 489 if (af==PJ_AF_INET) {490 addr->ipv4.sin_addr.s_addr = pj_htonl (0x7f000001);491 } else {492 pj_in6_addr *s6_addr;493 494 s6_addr = (pj_in6_addr*) pj_sockaddr_get_addr(addr);495 pj_bzero(s6_addr, sizeof(pj_in6_addr));496 s6_addr->s6_addr[15] = 1;497 }498 status = PJ_SUCCESS;486 if (af==PJ_AF_INET) { 487 addr->ipv4.sin_addr.s_addr = pj_htonl (0x7f000001); 488 } else { 489 pj_in6_addr *s6_addr; 490 491 s6_addr = (pj_in6_addr*) pj_sockaddr_get_addr(addr); 492 pj_bzero(s6_addr, sizeof(pj_in6_addr)); 493 s6_addr->s6_addr[15] = 1; 494 } 495 status = PJ_SUCCESS; 499 496 } 500 497 … … 553 550 } 554 551 555 pj_memcpy(pj_sockaddr_get_addr(addr), 556 pj_sockaddr_get_addr(&a), 557 pj_sockaddr_get_addr_len(&a)); 552 pj_sockaddr_copy_addr(addr, &a); 558 553 559 554 /* Success */
Note: See TracChangeset
for help on using the changeset viewer.