Changeset 721
- Timestamp:
- Sep 14, 2006 6:51:01 PM (18 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/addr_resolv.h
r65 r721 22 22 /** 23 23 * @file addr_resolv.h 24 * @brief Address resolve (pj_gethostbyname()).24 * @brief IP address resolution. 25 25 */ 26 26 27 #include <pj/ types.h>27 #include <pj/sock.h> 28 28 29 29 PJ_BEGIN_DECL … … 85 85 86 86 87 /** 88 * Resolve the primary IP address of local host. 89 * 90 * @param ip_addr On successful resolution, this will be filled up with 91 * the host IP address, in network byte order. 92 * 93 * @return PJ_SUCCESS on success, or the appropriate error code. 94 */ 95 PJ_DECL(pj_status_t) pj_gethostip(pj_in_addr *ip_addr); 96 97 87 98 /** @} */ 88 99 -
pjproject/trunk/pjlib/src/pj/addr_resolv_sock.c
r65 r721 20 20 #include <pj/assert.h> 21 21 #include <pj/string.h> 22 #include <pj/errno.h> 22 23 #include <pj/compat/socket.h> 23 #include <pj/errno.h>24 24 25 25 … … 50 50 } 51 51 52 /* Resolve the IP address of local machine */ 53 pj_status_t pj_gethostip(pj_in_addr *addr) 54 { 55 const pj_str_t *hostname = pj_gethostname(); 56 struct pj_hostent he; 57 pj_str_t cp; 58 pj_in_addr loopip; 59 pj_status_t status; 60 61 cp = pj_str("127.0.0.1"); 62 loopip = pj_inet_addr(&cp); 63 64 /* Try with resolving local hostname first */ 65 status = pj_gethostbyname(hostname, &he); 66 if (status == PJ_SUCCESS) { 67 *addr = *(pj_in_addr*)he.h_addr; 68 } 69 70 71 /* If we end up with 127.0.0.1, resolve the IP by getting the default 72 * interface to connect to some public host. 73 */ 74 if (status != PJ_SUCCESS || addr->s_addr == loopip.s_addr) { 75 pj_sock_t fd; 76 pj_sockaddr_in a; 77 int len; 78 79 status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &fd); 80 if (status != PJ_SUCCESS) { 81 return status; 82 } 83 84 cp = pj_str("1.1.1.1"); 85 pj_sockaddr_in_init(&a, &cp, 53); 86 87 status = pj_sock_connect(fd, &a, sizeof(a)); 88 if (status != PJ_SUCCESS) { 89 pj_sock_close(fd); 90 return status; 91 } 92 93 len = sizeof(a); 94 status = pj_sock_getsockname(fd, &a, &len); 95 if (status != PJ_SUCCESS) { 96 pj_sock_close(fd); 97 return status; 98 } 99 100 pj_sock_close(fd); 101 102 *addr = a.sin_addr; 103 } 104 105 return status; 106 } 107 108 -
pjproject/trunk/pjmedia/src/pjmedia-codec/ilbc/iCBSearch.c
r638 r721 128 128 pp=buf+LPC_FILTERORDER+lMem-lTarget; 129 129 for (j=0; j<lTarget; j++) { 130 *ppe+=(*pp)*(*pp++); 130 *ppe+=(*pp)*(*pp); 131 ++pp; 131 132 } 132 133 … … 323 324 pp=cbvectors+lMem-lTarget; 324 325 for (j=0; j<lTarget; j++) { 325 *ppe+=(*pp)*(*pp++); 326 *ppe+=(*pp)*(*pp); 327 ++pp; 326 328 } 327 329 -
pjproject/trunk/pjmedia/src/pjmedia/transport_udp.c
r705 r721 246 246 /* If address is 0.0.0.0, use host's IP address */ 247 247 if (tp->rtp_addr_name.sin_addr.s_addr == 0) { 248 pj_ hostent he;249 const pj_str_t *hostname = pj_gethostname(); 250 status = pj_gethost byname(hostname, &he);251 if (status != PJ_SUCCESS) {248 pj_in_addr hostip; 249 250 status = pj_gethostip(&hostip); 251 if (status != PJ_SUCCESS) 252 252 goto on_error; 253 } 254 tp->rtp_addr_name.sin_addr = *(pj_in_addr*)he.h_addr;253 254 tp->rtp_addr_name.sin_addr = hostip; 255 255 } 256 256 -
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r715 r721 79 79 static pj_str_t uri_arg; 80 80 81 #ifdef STEREO_DEMO 81 82 static void stereo_demo(); 83 #endif 82 84 83 85 /***************************************************************************** -
pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c
r635 r721 250 250 */ 251 251 if (listener_addr->sin_addr.s_addr == 0) { 252 const pj_str_t *hostname; 253 struct pj_hostent he; 254 255 hostname = pj_gethostname(); 256 status = pj_gethostbyname(hostname, &he); 252 pj_in_addr hostip; 253 254 status = pj_gethostip(&hostip); 257 255 if (status != PJ_SUCCESS) 258 256 goto on_error; 259 257 260 listener_addr->sin_addr = *(pj_in_addr*)he.h_addr;258 listener_addr->sin_addr = hostip; 261 259 } 262 260 -
pjproject/trunk/pjsip/src/pjsip/sip_transport_udp.c
r635 r721 653 653 */ 654 654 if (tmp_addr.sin_addr.s_addr == PJ_INADDR_ANY) { 655 pj_hostent he; 656 const pj_str_t *hostname = pj_gethostname(); 657 status = pj_gethostbyname(hostname, &he); 658 if (status != PJ_SUCCESS) { 659 pj_sock_close(sock); 655 pj_in_addr hostip; 656 657 status = pj_gethostip(&hostip); 658 if (status != PJ_SUCCESS) 660 659 return status; 661 } 662 pj_strcpy2(&bound_name.host, 663 pj_inet_ntoa(*(pj_in_addr*)he.h_addr)); 660 661 pj_strcpy2(&bound_name.host, pj_inet_ntoa(hostip)); 664 662 } else { 665 663 /* Otherwise use bound address. */ -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_core.c
r690 r721 813 813 } else { 814 814 815 const pj_str_t *hostname = pj_gethostname(); 816 struct pj_hostent he; 817 818 status = pj_gethostbyname(hostname, &he); 815 pj_bzero(p_pub_addr, sizeof(pj_sockaddr_in)); 816 817 status = pj_gethostip(&p_pub_addr->sin_addr); 819 818 if (status != PJ_SUCCESS) { 820 pjsua_perror(THIS_FILE, "Unable to resolve local host", status);821 819 pj_sock_close(sock); 822 820 return status; 823 821 } 824 822 825 pj_bzero(p_pub_addr, sizeof(pj_sockaddr_in));826 823 p_pub_addr->sin_family = PJ_AF_INET; 827 824 p_pub_addr->sin_port = pj_htons((pj_uint16_t)port); 828 p_pub_addr->sin_addr = *(pj_in_addr*)he.h_addr;829 825 } 830 826 -
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
r659 r721 287 287 288 288 } else { 289 const pj_str_t *hostname; 290 pj_sockaddr_in addr; 289 pj_in_addr addr; 291 290 292 291 /* Get local IP address. */ 293 hostname = pj_gethostname(); 294 295 pj_bzero( &addr, sizeof(addr)); 296 addr.sin_family = PJ_AF_INET; 297 status = pj_sockaddr_in_set_str_addr( &addr, hostname); 298 if (status != PJ_SUCCESS) { 299 pjsua_perror(THIS_FILE, "Unresolvable local hostname", 300 status); 292 status = pj_gethostip(&addr); 293 if (status != PJ_SUCCESS) 301 294 goto on_error; 302 }303 295 304 296 for (i=0; i<2; ++i) 305 pj_memcpy(&mapped_addr[i], &addr, sizeof(addr));297 mapped_addr[i].sin_addr = addr; 306 298 307 299 mapped_addr[0].sin_port=pj_htons((pj_uint16_t)rtp_port);
Note: See TracChangeset
for help on using the changeset viewer.