Changeset 1601 for pjproject/trunk/pjlib/include/pj/sock.h
- Timestamp:
- Dec 1, 2007 8:52:57 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/sock.h
r1585 r1601 88 88 */ 89 89 90 /** Get #PJ_AF_UNSPEC value */ 91 PJ_DECL(pj_uint16_t) pj_AF_UNSPEC(void); 92 /** Get #PJ_AF_UNIX value. */ 93 PJ_DECL(pj_uint16_t) pj_AF_UNIX(void); 94 /** Get #PJ_AF_INET value. */ 95 PJ_DECL(pj_uint16_t) pj_AF_INET(void); 96 /** Get #PJ_AF_INET6 value. */ 97 PJ_DECL(pj_uint16_t) pj_AF_INET6(void); 98 /** Get #PJ_AF_PACKET value. */ 99 PJ_DECL(pj_uint16_t) pj_AF_PACKET(void); 100 /** Get #PJ_AF_IRDA value. */ 101 PJ_DECL(pj_uint16_t) pj_AF_IRDA(void); 90 #if defined(PJ_DLL) 91 /** Get #PJ_AF_UNSPEC value */ 92 PJ_DECL(pj_uint16_t) pj_AF_UNSPEC(void); 93 /** Get #PJ_AF_UNIX value. */ 94 PJ_DECL(pj_uint16_t) pj_AF_UNIX(void); 95 /** Get #PJ_AF_INET value. */ 96 PJ_DECL(pj_uint16_t) pj_AF_INET(void); 97 /** Get #PJ_AF_INET6 value. */ 98 PJ_DECL(pj_uint16_t) pj_AF_INET6(void); 99 /** Get #PJ_AF_PACKET value. */ 100 PJ_DECL(pj_uint16_t) pj_AF_PACKET(void); 101 /** Get #PJ_AF_IRDA value. */ 102 PJ_DECL(pj_uint16_t) pj_AF_IRDA(void); 103 #else 104 /* When pjlib is not built as DLL, these accessor functions are 105 * simply a macro to get their constants 106 */ 107 /** Get #PJ_AF_UNSPEC value */ 108 # define pj_AF_UNSPEC() PJ_AF_UNSPEC 109 /** Get #PJ_AF_UNIX value. */ 110 # define pj_AF_UNIX() PJ_AF_UNIX 111 /** Get #PJ_AF_INET value. */ 112 # define pj_AF_INET() PJ_AF_INET 113 /** Get #PJ_AF_INET6 value. */ 114 # define pj_AF_INET6() PJ_AF_INET6 115 /** Get #PJ_AF_PACKET value. */ 116 # define pj_AF_PACKET() PJ_AF_PACKET 117 /** Get #PJ_AF_IRDA value. */ 118 # define pj_AF_IRDA() PJ_AF_IRDA 119 #endif 102 120 103 121 … … 128 146 */ 129 147 130 /** Get #PJ_SOCK_STREAM constant */ 131 PJ_DECL(int) pj_SOCK_STREAM(void); 132 /** Get #PJ_SOCK_DGRAM constant */ 133 PJ_DECL(int) pj_SOCK_DGRAM(void); 134 /** Get #PJ_SOCK_RAW constant */ 135 PJ_DECL(int) pj_SOCK_RAW(void); 136 /** Get #PJ_SOCK_RDM constant */ 137 PJ_DECL(int) pj_SOCK_RDM(void); 148 #if defined(PJ_DLL) 149 /** Get #PJ_SOCK_STREAM constant */ 150 PJ_DECL(int) pj_SOCK_STREAM(void); 151 /** Get #PJ_SOCK_DGRAM constant */ 152 PJ_DECL(int) pj_SOCK_DGRAM(void); 153 /** Get #PJ_SOCK_RAW constant */ 154 PJ_DECL(int) pj_SOCK_RAW(void); 155 /** Get #PJ_SOCK_RDM constant */ 156 PJ_DECL(int) pj_SOCK_RDM(void); 157 #else 158 /** Get #PJ_SOCK_STREAM constant */ 159 # define pj_SOCK_STREAM() PJ_SOCK_STREAM 160 /** Get #PJ_SOCK_DGRAM constant */ 161 # define pj_SOCK_DGRAM() PJ_SOCK_DGRAM 162 /** Get #PJ_SOCK_RAW constant */ 163 # define pj_SOCK_RAW() PJ_SOCK_RAW 164 /** Get #PJ_SOCK_RDM constant */ 165 # define pj_SOCK_RDM() PJ_SOCK_RDM 166 #endif 138 167 139 168 … … 159 188 */ 160 189 161 /** Get #PJ_SOL_SOCKET constant */ 162 PJ_DECL(pj_uint16_t) pj_SOL_SOCKET(void); 163 /** Get #PJ_SOL_IP constant */ 164 PJ_DECL(pj_uint16_t) pj_SOL_IP(void); 165 /** Get #PJ_SOL_TCP constant */ 166 PJ_DECL(pj_uint16_t) pj_SOL_TCP(void); 167 /** Get #PJ_SOL_UDP constant */ 168 PJ_DECL(pj_uint16_t) pj_SOL_UDP(void); 169 /** Get #PJ_SOL_IPV6 constant */ 170 PJ_DECL(pj_uint16_t) pj_SOL_IPV6(void); 190 #if defined(PJ_DLL) 191 /** Get #PJ_SOL_SOCKET constant */ 192 PJ_DECL(pj_uint16_t) pj_SOL_SOCKET(void); 193 /** Get #PJ_SOL_IP constant */ 194 PJ_DECL(pj_uint16_t) pj_SOL_IP(void); 195 /** Get #PJ_SOL_TCP constant */ 196 PJ_DECL(pj_uint16_t) pj_SOL_TCP(void); 197 /** Get #PJ_SOL_UDP constant */ 198 PJ_DECL(pj_uint16_t) pj_SOL_UDP(void); 199 /** Get #PJ_SOL_IPV6 constant */ 200 PJ_DECL(pj_uint16_t) pj_SOL_IPV6(void); 201 #else 202 /** Get #PJ_SOL_SOCKET constant */ 203 # define pj_SOL_SOCKET() PJ_SOL_SOCKET 204 /** Get #PJ_SOL_IP constant */ 205 # define pj_SOL_IP() PJ_SOL_IP 206 /** Get #PJ_SOL_TCP constant */ 207 # define pj_SOL_TCP() PJ_SOL_TCP 208 /** Get #PJ_SOL_UDP constant */ 209 # define pj_SOL_UDP() PJ_SOL_UDP 210 /** Get #PJ_SOL_IPV6 constant */ 211 # define pj_SOL_IPV6() PJ_SOL_IPV6 212 #endif 171 213 172 214 … … 180 222 extern const pj_uint16_t PJ_IP_TOS; 181 223 182 /** Get #PJ_IP_TOS constant */183 PJ_DECL(int) pj_IP_TOS(void);184 185 224 /* 186 225 * IP TOS related constats. … … 204 243 205 244 206 /** Get #PJ_IPTOS_LOWDELAY constant */ 207 PJ_DECL(int) pj_IPTOS_LOWDELAY(void); 208 209 /** Get #PJ_IPTOS_THROUGHPUT constant */ 210 PJ_DECL(int) pj_IPTOS_THROUGHPUT(void); 211 212 /** Get #PJ_IPTOS_RELIABILITY constant */ 213 PJ_DECL(int) pj_IPTOS_RELIABILITY(void); 214 215 /** Get #PJ_IPTOS_MINCOST constant */ 216 PJ_DECL(int) pj_IPTOS_MINCOST(void); 245 #if defined(PJ_DLL) 246 /** Get #PJ_IP_TOS constant */ 247 PJ_DECL(int) pj_IP_TOS(void); 248 249 /** Get #PJ_IPTOS_LOWDELAY constant */ 250 PJ_DECL(int) pj_IPTOS_LOWDELAY(void); 251 252 /** Get #PJ_IPTOS_THROUGHPUT constant */ 253 PJ_DECL(int) pj_IPTOS_THROUGHPUT(void); 254 255 /** Get #PJ_IPTOS_RELIABILITY constant */ 256 PJ_DECL(int) pj_IPTOS_RELIABILITY(void); 257 258 /** Get #PJ_IPTOS_MINCOST constant */ 259 PJ_DECL(int) pj_IPTOS_MINCOST(void); 260 #else 261 /** Get #PJ_IP_TOS constant */ 262 # define pj_IP_TOS() PJ_IP_TOS 263 264 /** Get #PJ_IPTOS_LOWDELAY constant */ 265 # define pj_IPTOS_LOWDELAY() PJ_IP_TOS_LOWDELAY 266 267 /** Get #PJ_IPTOS_THROUGHPUT constant */ 268 # define pj_IPTOS_THROUGHPUT() PJ_IP_TOS_THROUGHPUT 269 270 /** Get #PJ_IPTOS_RELIABILITY constant */ 271 # define pj_IPTOS_RELIABILITY() PJ_IP_TOS_RELIABILITY 272 273 /** Get #PJ_IPTOS_MINCOST constant */ 274 # define pj_IPTOS_MINCOST() PJ_IP_TOS_MINCOST 275 #endif 217 276 218 277 … … 232 291 233 292 234 /** Get #PJ_SO_TYPE constant */ 235 PJ_DECL(pj_uint16_t) pj_SO_TYPE(void); 236 237 /** Get #PJ_SO_RCVBUF constant */ 238 PJ_DECL(pj_uint16_t) pj_SO_RCVBUF(void); 239 240 /** Get #PJ_SO_SNDBUF constant */ 241 PJ_DECL(pj_uint16_t) pj_SO_SNDBUF(void); 293 #if defined(PJ_DLL) 294 /** Get #PJ_SO_TYPE constant */ 295 PJ_DECL(pj_uint16_t) pj_SO_TYPE(void); 296 297 /** Get #PJ_SO_RCVBUF constant */ 298 PJ_DECL(pj_uint16_t) pj_SO_RCVBUF(void); 299 300 /** Get #PJ_SO_SNDBUF constant */ 301 PJ_DECL(pj_uint16_t) pj_SO_SNDBUF(void); 302 #else 303 /** Get #PJ_SO_TYPE constant */ 304 # define pj_SO_TYPE() PJ_SO_TYPE 305 306 /** Get #PJ_SO_RCVBUF constant */ 307 # define pj_SO_RCVBUF() PJ_SO_RCVBUF 308 309 /** Get #PJ_SO_SNDBUF constant */ 310 # define pj_SO_SNDBUF() PJ_SO_SNDBUF 311 #endif 242 312 243 313 … … 256 326 257 327 258 /** Get #PJ_MSG_OOB constant */ 259 PJ_DECL(int) pj_MSG_OOB(void); 260 261 /** Get #PJ_MSG_PEEK constant */ 262 PJ_DECL(int) pj_MSG_PEEK(void); 263 264 /** Get #PJ_MSG_DONTROUTE constant */ 265 PJ_DECL(int) pj_MSG_DONTROUTE(void); 328 #if defined(PJ_DLL) 329 /** Get #PJ_MSG_OOB constant */ 330 PJ_DECL(int) pj_MSG_OOB(void); 331 332 /** Get #PJ_MSG_PEEK constant */ 333 PJ_DECL(int) pj_MSG_PEEK(void); 334 335 /** Get #PJ_MSG_DONTROUTE constant */ 336 PJ_DECL(int) pj_MSG_DONTROUTE(void); 337 #else 338 /** Get #PJ_MSG_OOB constant */ 339 # define pj_MSG_OOB() PJ_MSG_OOB 340 341 /** Get #PJ_MSG_PEEK constant */ 342 # define pj_MSG_PEEK() PJ_MSG_PEEK 343 344 /** Get #PJ_MSG_DONTROUTE constant */ 345 # define pj_MSG_DONTROUTE() PJ_MSG_DONTROUTE 346 #endif 266 347 267 348 … … 307 388 #define PJ_INVALID_SOCKET (-1) 308 389 390 /* Must undefine s_addr because of pj_in_addr below */ 309 391 #undef s_addr 310 392 … … 363 445 /* While these are used for proper alignment */ 364 446 pj_uint32_t u6_addr32[4]; 365 #if defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0 447 448 /* Do not use this with Winsock2, as this will align pj_sockaddr_in6 449 * to 64-bit boundary and Winsock2 doesn't like it! 450 */ 451 #if defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0 && \ 452 (!defined(PJ_WIN32) || PJ_WIN32==0) 366 453 pj_int64_t u6_addr64[2]; 367 454 #endif … … 556 643 557 644 /** 558 * Get the transport layer port number of an Internet socket address. 559 * The port is returned in host byte order. 560 * 561 * @param addr The IP socket address. 645 * Initialize IPv4 socket address based on the address and port info. 646 * The string address may be in a standard numbers and dots notation or 647 * may be a hostname. If hostname is specified, then the function will 648 * resolve the host into the IP address. 649 * 650 * @see pj_sockaddr_init() 651 * 652 * @param addr The IP socket address to be set. 653 * @param cp The address string, which can be in a standard 654 * dotted numbers or a hostname to be resolved. 655 * @param port The port number, in host byte order. 656 * 657 * @return Zero on success. 658 */ 659 PJ_DECL(pj_status_t) pj_sockaddr_in_init( pj_sockaddr_in *addr, 660 const pj_str_t *cp, 661 pj_uint16_t port); 662 663 /** 664 * Initialize IP socket address based on the address and port info. 665 * The string address may be in a standard numbers and dots notation or 666 * may be a hostname. If hostname is specified, then the function will 667 * resolve the host into the IP address. 668 * 669 * @see pj_sockaddr_in_init() 670 * 671 * @param af Internet address family. 672 * @param addr The IP socket address to be set. 673 * @param cp The address string, which can be in a standard 674 * dotted numbers or a hostname to be resolved. 675 * @param port The port number, in host byte order. 676 * 677 * @return Zero on success. 678 */ 679 PJ_DECL(pj_status_t) pj_sockaddr_init(int af, 680 pj_sockaddr *addr, 681 const pj_str_t *cp, 682 pj_uint16_t port); 683 684 /** 685 * Get pointer to the address part of a socket address. 686 * 687 * @param addr Socket address. 688 * 689 * @return Pointer to address part (sin_addr or sin6_addr, 690 * depending on address family) 691 */ 692 PJ_DECL(void*) pj_sockaddr_get_addr(const pj_sockaddr_t *addr); 693 694 /** 695 * Check that a socket address contains a non-zero address part. 696 * 697 * @param addr Socket address. 698 * 699 * @return Non-zero if address is set to non-zero. 700 */ 701 PJ_DECL(pj_bool_t) pj_sockaddr_has_addr(const pj_sockaddr_t *addr); 702 703 /** 704 * Get the address part length of a socket address, based on its address 705 * family. For PJ_AF_INET, the length will be sizeof(pj_in_addr), and 706 * for PJ_AF_INET6, the length will be sizeof(pj_in6_addr). 707 * 708 * @param addr Socket address. 709 * 562 710 * @return Port number, in host byte order. 563 711 */ 564 PJ_INLINE(pj_uint16_t) pj_sockaddr_in_get_port(const pj_sockaddr_in *addr) 565 { 566 return pj_ntohs(addr->sin_port); 567 } 568 569 /** 570 * Set the port number of an Internet socket address. 571 * 572 * @param addr The IP socket address. 573 * @param hostport The port number, in host byte order. 574 */ 575 PJ_INLINE(void) pj_sockaddr_in_set_port(pj_sockaddr_in *addr, 576 pj_uint16_t hostport) 577 { 578 addr->sin_port = pj_htons(hostport); 579 } 580 581 /** 582 * Get the IP address of an Internet socket address. 712 PJ_DECL(unsigned) pj_sockaddr_get_addr_len(const pj_sockaddr_t *addr); 713 714 /** 715 * Get the IP address of an IPv4 socket address. 583 716 * The address is returned as 32bit value in host byte order. 584 717 * … … 586 719 * @return 32bit address, in host byte order. 587 720 */ 588 PJ_INLINE(pj_in_addr) pj_sockaddr_in_get_addr(const pj_sockaddr_in *addr) 589 { 590 pj_in_addr in_addr; 591 in_addr.s_addr = pj_ntohl(addr->sin_addr.s_addr); 592 return in_addr; 593 } 594 595 /** 596 * Set the IP address of an Internet socket address. 721 PJ_DECL(pj_in_addr) pj_sockaddr_in_get_addr(const pj_sockaddr_in *addr); 722 723 /** 724 * Set the IP address of an IPv4 socket address. 597 725 * 598 726 * @param addr The IP socket address. 599 727 * @param hostaddr The host address, in host byte order. 600 728 */ 601 PJ_INLINE(void) pj_sockaddr_in_set_addr(pj_sockaddr_in *addr, 602 pj_uint32_t hostaddr) 603 { 604 addr->sin_addr.s_addr = pj_htonl(hostaddr); 605 } 729 PJ_DECL(void) pj_sockaddr_in_set_addr(pj_sockaddr_in *addr, 730 pj_uint32_t hostaddr); 606 731 607 732 /** … … 612 737 * address. 613 738 * 739 * @see pj_sockaddr_set_str_addr() 740 * 614 741 * @param addr The IP socket address to be set. 615 742 * @param cp The address string, which can be in a standard 616 743 * dotted numbers or a hostname to be resolved. 617 744 * 618 * @return Zeroon success.745 * @return PJ_SUCCESS on success. 619 746 */ 620 747 PJ_DECL(pj_status_t) pj_sockaddr_in_set_str_addr( pj_sockaddr_in *addr, … … 622 749 623 750 /** 624 * Set the IP address and port of an IP socket address. 625 * The string address may be in a standard numbers and dots notation or 626 * may be a hostname. If hostname is specified, then the function will 627 * resolve the host into the IP address. 628 * 751 * Set the IP address of an IPv4 or IPv6 socket address from string address, 752 * with resolving the host if necessary. The string address may be in a 753 * standard IPv6 or IPv6 address or may be a hostname. If hostname 754 * is specified, then the function will resolve the host into the IP 755 * address according to the address family. 756 * 757 * @param af Address family. 629 758 * @param addr The IP socket address to be set. 630 759 * @param cp The address string, which can be in a standard 631 * dotted numbers or a hostname to be resolved. 632 * @param port The port number, in host byte order. 633 * 634 * @return Zero on success. 635 */ 636 PJ_DECL(pj_status_t) pj_sockaddr_in_init( pj_sockaddr_in *addr, 637 const pj_str_t *cp, 638 pj_uint16_t port); 639 760 * IP numbers (IPv4 or IPv6) or a hostname to be resolved. 761 * 762 * @return PJ_SUCCESS on success. 763 */ 764 PJ_DECL(pj_status_t) pj_sockaddr_set_str_addr(int af, 765 pj_sockaddr *addr, 766 const pj_str_t *cp); 767 768 /** 769 * Get the port number of a socket address, in host byte order. 770 * This function can be used for both IPv4 and IPv6 socket address. 771 * 772 * @param addr Socket address. 773 * 774 * @return Port number, in host byte order. 775 */ 776 PJ_DECL(pj_uint16_t) pj_sockaddr_get_port(const pj_sockaddr_t *addr); 777 778 /** 779 * Get the transport layer port number of an Internet socket address. 780 * The port is returned in host byte order. 781 * 782 * @param addr The IP socket address. 783 * @return Port number, in host byte order. 784 */ 785 PJ_DECL(pj_uint16_t) pj_sockaddr_in_get_port(const pj_sockaddr_in *addr); 786 787 /** 788 * Set the port number of an Internet socket address. 789 * 790 * @param addr The socket address. 791 * @param hostport The port number, in host byte order. 792 */ 793 PJ_DECL(pj_status_t) pj_sockaddr_set_port(pj_sockaddr *addr, 794 pj_uint16_t hostport); 795 796 /** 797 * Set the port number of an IPv4 socket address. 798 * 799 * @see pj_sockaddr_set_port() 800 * 801 * @param addr The IP socket address. 802 * @param hostport The port number, in host byte order. 803 */ 804 PJ_DECL(void) pj_sockaddr_in_set_port(pj_sockaddr_in *addr, 805 pj_uint16_t hostport); 640 806 641 807 /*****************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.