Changeset 1647
- Timestamp:
- Dec 31, 2007 11:26:21 AM (17 years ago)
- Location:
- pjproject/trunk/pjlib/src/pj
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/addr_resolv_symbian.cpp
r1608 r1647 21 21 #include <pj/errno.h> 22 22 #include <pj/ip_helper.h> 23 #include <pj/log.h> 23 24 #include <pj/sock.h> 24 25 #include <pj/string.h> … … 27 28 #include "os_symbian.h" 28 29 30 #define THIS_FILE "addr_resolv_symbian.cpp" 31 #define TRACE_ME 0 29 32 30 33 … … 87 90 while (reqStatus == KErrNone && i < *count) { 88 91 89 // Get the resolved TInetAddr90 TInetAddr inetAddr(nameEntry().iAddr);91 int addrlen;92 // Get the resolved TInetAddr 93 TInetAddr inetAddr(nameEntry().iAddr); 94 int addrlen; 92 95 93 // Ignore if this is not the same address family 94 if (inetAddr.Family() != (unsigned)af) { 95 resv.Next(nameEntry, reqStatus); 96 User::WaitForRequest(reqStatus); 97 continue; 98 } 96 #if TRACE_ME 97 if (1) { 98 pj_sockaddr a; 99 char ipaddr[PJ_INET6_ADDRSTRLEN+2]; 100 int namelen; 101 102 namelen = sizeof(pj_sockaddr); 103 if (PjSymbianOS::Addr2pj(inetAddr, a, &namelen, 104 PJ_FALSE) == PJ_SUCCESS) 105 { 106 PJ_LOG(5,(THIS_FILE, "resolve %.*s: %s", 107 (int)name->slen, name->ptr, 108 pj_sockaddr_print(&a, ipaddr, sizeof(ipaddr), 2))); 109 } 110 } 111 #endif 112 113 // Ignore if this is not the same address family 114 // Not a good idea, as Symbian mapps IPv4 to IPv6. 115 //fam = inetAddr.Family(); 116 //if (fam != af) { 117 // resv.Next(nameEntry, reqStatus); 118 // User::WaitForRequest(reqStatus); 119 // continue; 120 //} 121 122 // Convert IP address first to get IPv4 mapped address 123 addrlen = sizeof(ai[i].ai_addr); 124 status = PjSymbianOS::Addr2pj(inetAddr, ai[i].ai_addr, 125 &addrlen, PJ_TRUE); 126 if (status != PJ_SUCCESS) 127 return status; 128 129 // Ignore if address family doesn't match 130 if (ai[i].ai_addr.addr.sa_family != af) { 131 resv.Next(nameEntry, reqStatus); 132 User::WaitForRequest(reqStatus); 133 continue; 134 } 135 136 // Convert the official address to ANSI. 137 pj_unicode_to_ansi((const wchar_t*)nameEntry().iName.Ptr(), 138 nameEntry().iName.Length(), 139 ai[i].ai_canonname, sizeof(ai[i].ai_canonname)); 99 140 100 // Convert the official address to ANSI. 101 pj_unicode_to_ansi((const wchar_t*)nameEntry().iName.Ptr(), 102 nameEntry().iName.Length(), 103 ai[i].ai_canonname, sizeof(ai[i].ai_canonname)); 104 105 // Convert IP address 106 addrlen = sizeof(ai[i].ai_addr); 107 status = PjSymbianOS::Addr2pj(inetAddr, ai[i].ai_addr, &addrlen); 108 if (status != PJ_SUCCESS) 109 return status; 110 111 // Next 112 ++i; 113 resv.Next(nameEntry, reqStatus); 114 User::WaitForRequest(reqStatus); 141 // Next 142 ++i; 143 resv.Next(nameEntry, reqStatus); 144 User::WaitForRequest(reqStatus); 115 145 } 116 146 -
pjproject/trunk/pjlib/src/pj/ip_helper_symbian.cpp
r1608 r1647 21 21 #include <pj/assert.h> 22 22 #include <pj/errno.h> 23 #include <pj/log.h> 23 24 #include <pj/string.h> 24 25 #include <pj/compat/socket.h> … … 26 27 27 28 #include "os_symbian.h" 29 30 #define THIS_FILE "ip_helper_symbian.cpp" 31 #define TRACE_ME 0 28 32 29 33 static pj_status_t rsock_enum_interface(int af, … … 59 63 TInetAddr &iAddress = info().iAddress; 60 64 int namelen; 65 66 #if TRACE_ME 67 if (1) { 68 pj_sockaddr a; 69 char ipaddr[PJ_INET6_ADDRSTRLEN+2]; 70 71 namelen = sizeof(pj_sockaddr); 72 if (PjSymbianOS::Addr2pj(iAddress, a, &namelen, 73 PJ_FALSE) == PJ_SUCCESS) 74 { 75 PJ_LOG(5,(THIS_FILE, "Enum: found address %s", 76 pj_sockaddr_print(&a, ipaddr, sizeof(ipaddr), 2))); 77 } 78 } 79 #endif 61 80 62 if (iAddress.Family() != (unsigned)af) { 81 namelen = sizeof(ifs[i]); 82 if (PjSymbianOS::Addr2pj(iAddress, ifs[i], &namelen, 83 PJ_TRUE) != PJ_SUCCESS) 84 { 63 85 continue; 64 86 } 65 66 namelen = sizeof(ifs[i]); 67 if (PjSymbianOS::Addr2pj(iAddress, ifs[i], &namelen) != PJ_SUCCESS) 68 continue; 87 88 if (ifs[i].addr.sa_family != af) 89 continue; 69 90 70 91 ++i; -
pjproject/trunk/pjlib/src/pj/os_symbian.h
r1628 r1647 240 240 static inline pj_status_t Addr2pj(const TInetAddr & sym_addr, 241 241 pj_sockaddr &pj_addr, 242 int *addr_len) 243 { 242 int *addr_len, 243 pj_bool_t convert_ipv4_mapped_addr = PJ_FALSE) 244 { 245 TUint fam = sym_addr.Family(); 244 246 pj_bzero(&pj_addr, *addr_len); 245 pj_addr.addr.sa_family = (pj_uint16_t)sym_addr.Family(); 246 if (pj_addr.addr.sa_family == PJ_AF_INET) { 247 if (fam == PJ_AF_INET || 248 (convert_ipv4_mapped_addr && 249 fam == PJ_AF_INET6 && 250 sym_addr.IsV4Mapped())) 251 { 252 pj_addr.addr.sa_family = PJ_AF_INET; 247 253 PJ_ASSERT_RETURN(*addr_len>=(int)sizeof(pj_sockaddr_in), PJ_ETOOSMALL); 248 254 pj_addr.ipv4.sin_addr.s_addr = pj_htonl(sym_addr.Address()); 249 255 pj_addr.ipv4.sin_port = pj_htons((pj_uint16_t) sym_addr.Port()); 250 256 *addr_len = sizeof(pj_sockaddr_in); 251 } else if ( pj_addr.addr.sa_family== PJ_AF_INET6) {257 } else if (fam == PJ_AF_INET6) { 252 258 PJ_ASSERT_RETURN(*addr_len>=(int)sizeof(pj_sockaddr_in6), PJ_ETOOSMALL); 253 259 const TIp6Addr & ip6 = sym_addr.Ip6Address(); 260 pj_addr.addr.sa_family = PJ_AF_INET6; 254 261 pj_memcpy(&pj_addr.ipv6.sin6_addr, ip6.u.iAddr8, 16); 255 262 pj_addr.ipv6.sin6_port = pj_htons((pj_uint16_t) sym_addr.Port()); -
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 */ -
pjproject/trunk/pjlib/src/pj/sock_symbian.cpp
r1608 r1647 406 406 pj_in_addr inaddr; 407 407 408 if (size < =PJ_INET_ADDRSTRLEN)408 if (size < PJ_INET_ADDRSTRLEN) 409 409 return PJ_ETOOSMALL; 410 410 … … 422 422 TBuf<PJ_INET6_ADDRSTRLEN> str16; 423 423 424 if (size < =PJ_INET6_ADDRSTRLEN)424 if (size < PJ_INET6_ADDRSTRLEN) 425 425 return PJ_ETOOSMALL; 426 426
Note: See TracChangeset
for help on using the changeset viewer.