Changeset 1613
- Timestamp:
- Dec 3, 2007 2:33:39 PM (17 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/src/pjlib-util/dns_dump.c
r1587 r1613 121 121 char addr[PJ_INET6_ADDRSTRLEN]; 122 122 PJ_LOG(3,(THIS_FILE, " IPv6 address: %s", 123 pj_inet_ntop (pj_AF_INET6(), &rr->rdata.aaaa.ip_addr,124 addr, sizeof(addr))));123 pj_inet_ntop2(pj_AF_INET6(), &rr->rdata.aaaa.ip_addr, 124 addr, sizeof(addr)))); 125 125 } 126 126 } -
pjproject/trunk/pjlib/include/pj/sock.h
r1608 r1613 596 596 * This function converts a numeric address into a text string suitable 597 597 * for presentation. It supports both IPv4 and IPv6 address 598 * conversion. 598 * conversion. 599 * @see pj_sockaddr_print() 599 600 * 600 601 * @param af Specify the family of the address. This can be PJ_AF_INET … … 616 617 /** 617 618 * Converts numeric address into its text string representation. 619 * @see pj_sockaddr_print() 618 620 * 619 621 * @param af Specify the family of the address. This can be PJ_AF_INET … … 633 635 char *dst, int size); 634 636 637 /** 638 * Print socket address. 639 * 640 * @param addr The socket address. 641 * @param buf Text buffer. 642 * @param size Size of buffer. 643 * @param flags Bitmask combination of these value: 644 * - 1: port number is included. 645 * - 2: square bracket is included for IPv6 address. 646 * 647 * @return The address string. 648 */ 649 PJ_DECL(char*) pj_sockaddr_print(const pj_sockaddr_t *addr, 650 char *buf, int size, 651 unsigned flags); 635 652 636 653 /** … … 703 720 704 721 /** 722 * Compare two socket addresses. 723 * 724 * @param addr1 First address. 725 * @param addr2 Second address. 726 * 727 * @return Zero on equal, -1 if addr1 is less than addr2, 728 * and +1 if addr1 is more than addr2. 729 */ 730 PJ_DECL(int) pj_sockaddr_cmp(const pj_sockaddr_t *addr1, 731 const pj_sockaddr_t *addr2); 732 733 /** 705 734 * Get pointer to the address part of a socket address. 706 735 * … … 743 772 PJ_DECL(unsigned) pj_sockaddr_get_len(const pj_sockaddr_t *addr); 744 773 774 /** 775 * Copy only the address part (sin_addr/sin6_addr) of a socket address. 776 * 777 * @param dst Destination socket address. 778 * @param src Source socket address. 779 */ 780 PJ_DECL(void) pj_sockaddr_copy_addr(pj_sockaddr *dst, 781 const pj_sockaddr *src); 745 782 /** 746 783 * Get the IP address of an IPv4 socket address. -
pjproject/trunk/pjlib/src/pj/ip_helper_generic.c
r1612 r1613 274 274 PJ_ASSERT_RETURN(p_cnt && *p_cnt > 0 && ifs, PJ_EINVAL); 275 275 276 PJ_UNUSED_ARG(&get_addr);277 PJ_UNUSED_ARG(&get_os_errmsg);278 279 276 pj_bzero(ifs, sizeof(ifs[0]) * (*p_cnt)); 280 277 -
pjproject/trunk/pjlib/src/pj/sock_common.c
r1608 r1613 60 60 61 61 /* 62 * Print socket address. 63 */ 64 PJ_DEF(char*) pj_sockaddr_print( const pj_sockaddr_t *addr, 65 char *buf, int size, 66 unsigned flags) 67 { 68 enum { 69 WITH_PORT = 1, 70 WITH_BRACKETS = 2 71 }; 72 73 char txt[PJ_INET6_ADDRSTRLEN]; 74 char port[32]; 75 const pj_addr_hdr *h = (const pj_addr_hdr*)addr; 76 char *bquote, *equote; 77 pj_status_t status; 78 79 status = pj_inet_ntop(h->sa_family, pj_sockaddr_get_addr(addr), 80 txt, sizeof(txt)); 81 if (status != PJ_SUCCESS) 82 return ""; 83 84 if (h->sa_family != PJ_AF_INET6 || (flags & WITH_BRACKETS)==0) { 85 bquote = ""; equote = ""; 86 } else { 87 bquote = "["; equote = "]"; 88 } 89 90 if (flags & WITH_PORT) { 91 pj_ansi_snprintf(port, sizeof(port), ":%d", 92 pj_sockaddr_get_port(addr)); 93 } else { 94 port[0] = '\0'; 95 } 96 97 pj_ansi_snprintf(buf, size, "%s%s%s%s", 98 bquote, txt, equote, port); 99 100 return buf; 101 } 102 103 /* 62 104 * Set the IP address of an IP socket address from string address, 63 105 * with resolving the host if necessary. The string address may be in a … … 185 227 186 228 /* 229 * Compare two socket addresses. 230 */ 231 PJ_DEF(int) pj_sockaddr_cmp( const pj_sockaddr_t *addr1, 232 const pj_sockaddr_t *addr2) 233 { 234 const pj_sockaddr *a1 = (const pj_sockaddr*) addr1; 235 const pj_sockaddr *a2 = (const pj_sockaddr*) addr2; 236 int port1, port2; 237 int result; 238 239 /* Compare address family */ 240 if (a1->addr.sa_family < a2->addr.sa_family) 241 return -1; 242 else if (a1->addr.sa_family > a2->addr.sa_family) 243 return 1; 244 245 /* Compare addresses */ 246 result = pj_memcmp(pj_sockaddr_get_addr(a1), 247 pj_sockaddr_get_addr(a2), 248 pj_sockaddr_get_addr_len(a1)); 249 if (result != 0) 250 return result; 251 252 /* Compare port number */ 253 port1 = pj_sockaddr_get_port(a1); 254 port2 = pj_sockaddr_get_port(a2); 255 256 if (port1 < port2) 257 return -1; 258 else if (port1 > port2) 259 return 1; 260 261 /* TODO: 262 * Do we need to compare flow label and scope id in IPv6? 263 */ 264 265 /* Looks equal */ 266 return 0; 267 } 268 269 /* 187 270 * Get first IP address associated with the hostname. 188 271 */ … … 278 361 279 362 /* 363 * Copy only the address part (sin_addr/sin6_addr) of a socket address. 364 */ 365 PJ_DEF(void) pj_sockaddr_copy_addr( pj_sockaddr *dst, 366 const pj_sockaddr *src) 367 { 368 pj_memcpy(pj_sockaddr_get_addr(dst), 369 pj_sockaddr_get_addr(src), 370 pj_sockaddr_get_addr_len(src)); 371 } 372 373 /* 280 374 * Set port number of pj_sockaddr_in 281 375 */
Note: See TracChangeset
for help on using the changeset viewer.