- Timestamp:
- Nov 1, 2006 1:57:01 PM (18 years ago)
- Location:
- pjproject/branches/symbian
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/symbian/pjlib/include/pj/addr_resolv.h
r65 r791 25 25 */ 26 26 27 #include <pj/ types.h>27 #include <pj/sock.h> 28 28 29 29 PJ_BEGIN_DECL … … 84 84 PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he); 85 85 86 /** 87 * Resolve the primary IP address of local host. 88 * 89 * @param ip_addr On successful resolution, this will be filled up with 90 * the host IP address, in network byte order. 91 * 92 * @return PJ_SUCCESS on success, or the appropriate error code. 93 */ 94 PJ_DECL(pj_status_t) pj_gethostip(pj_in_addr *ip_addr); 95 96 86 97 87 98 /** @} */ -
pjproject/branches/symbian/pjlib/src/pj/addr_resolv_symbian.cpp
r788 r791 20 20 #include <pj/assert.h> 21 21 #include <pj/errno.h> 22 #include <pj/string.h> 22 23 #include <pj/unicode.h> 23 24 … … 78 79 } 79 80 81 82 /* Resolve the IP address of local machine */ 83 pj_status_t pj_gethostip(pj_in_addr *addr) 84 { 85 const pj_str_t *hostname = pj_gethostname(); 86 struct pj_hostent he; 87 pj_str_t cp; 88 pj_in_addr loopip; 89 pj_status_t status; 90 91 cp = pj_str("127.0.0.1"); 92 loopip = pj_inet_addr(&cp); 93 94 /* Try with resolving local hostname first */ 95 status = pj_gethostbyname(hostname, &he); 96 if (status == PJ_SUCCESS) { 97 *addr = *(pj_in_addr*)he.h_addr; 98 } 99 100 101 /* If we end up with 127.0.0.1 or 0.0.0.0, resolve the IP by getting 102 * the default interface to connect to some public host. 103 */ 104 if (status!=PJ_SUCCESS || addr->s_addr == loopip.s_addr || !addr->s_addr) { 105 pj_sock_t fd; 106 pj_sockaddr_in a; 107 int len; 108 109 status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &fd); 110 if (status != PJ_SUCCESS) { 111 return status; 112 } 113 114 cp = pj_str("1.1.1.1"); 115 pj_sockaddr_in_init(&a, &cp, 53); 116 117 status = pj_sock_connect(fd, &a, sizeof(a)); 118 if (status != PJ_SUCCESS) { 119 pj_sock_close(fd); 120 return status; 121 } 122 123 len = sizeof(a); 124 status = pj_sock_getsockname(fd, &a, &len); 125 if (status != PJ_SUCCESS) { 126 pj_sock_close(fd); 127 return status; 128 } 129 130 pj_sock_close(fd); 131 132 *addr = a.sin_addr; 133 134 if (a.sin_addr.s_addr == 0) 135 return PJ_ENOTFOUND; 136 } 137 138 return status; 139 } 140 141 142 -
pjproject/branches/symbian/pjsip/src/pjsip/sip_transport_udp.c
r789 r791 579 579 */ 580 580 PJ_DEF(pj_status_t) pjsip_udp_transport_start( pjsip_endpoint *endpt, 581 const pj_sockaddr_in *local ,581 const pj_sockaddr_in *local_a, 582 582 const pjsip_host_port *a_name, 583 583 unsigned async_cnt, … … 587 587 pj_status_t status; 588 588 char addr_buf[16]; 589 pj_sockaddr_in tmp_addr; 589 590 pjsip_host_port bound_name; 590 591 591 PJ_ASSERT_RETURN( local != NULL, PJ_EINVAL);592 PJ_ASSERT_RETURN(endpt && async_cnt, PJ_EINVAL); 592 593 593 594 status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &sock); … … 595 596 return status; 596 597 597 status = pj_sock_bind(sock, local, sizeof(*local)); 598 if (local_a == NULL) { 599 pj_sockaddr_in_init(&tmp_addr, NULL, 0); 600 local_a = &tmp_addr; 601 } 602 603 status = pj_sock_bind(sock, local_a, sizeof(*local_a)); 598 604 if (status != PJ_SUCCESS) { 599 605 pj_sock_close(sock); … … 605 611 * Build a name based on bound address. 606 612 */ 613 int addr_len; 614 615 addr_len = sizeof(tmp_addr); 616 status = pj_sock_getsockname(sock, &tmp_addr, &addr_len); 617 if (status != PJ_SUCCESS) { 618 pj_sock_close(sock); 619 return status; 620 } 621 607 622 a_name = &bound_name; 608 623 bound_name.host.ptr = addr_buf; 609 bound_name.port = pj_ntohs( local->sin_port);624 bound_name.port = pj_ntohs(tmp_addr.sin_port); 610 625 611 626 /* If bound address specifies "0.0.0.0", get the IP address 612 627 * of local hostname. 613 628 */ 614 if (local->sin_addr.s_addr == PJ_INADDR_ANY) { 615 pj_hostent he; 616 const pj_str_t *hostname = pj_gethostname(); 617 status = pj_gethostbyname(hostname, &he); 618 if (status != PJ_SUCCESS) { 619 pj_sock_close(sock); 629 if (tmp_addr.sin_addr.s_addr == PJ_INADDR_ANY) { 630 pj_in_addr hostip; 631 632 status = pj_gethostip(&hostip); 633 if (status != PJ_SUCCESS) 620 634 return status; 621 } 622 pj_strcpy2(&bound_name.host, 623 pj_inet_ntoa(*(pj_in_addr*)he.h_addr)); 635 636 pj_strcpy2(&bound_name.host, pj_inet_ntoa(hostip)); 624 637 } else { 625 638 /* Otherwise use bound address. */ 626 pj_strcpy2(&bound_name.host, pj_inet_ntoa( local->sin_addr));639 pj_strcpy2(&bound_name.host, pj_inet_ntoa(tmp_addr.sin_addr)); 627 640 } 628 641
Note: See TracChangeset
for help on using the changeset viewer.