Changeset 1054 for pjproject/trunk
- Timestamp:
- Mar 10, 2007 11:15:36 PM (18 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/include/pjlib-util/stun_msg.h
r1053 r1054 270 270 * STUN/TURN Send Indication 271 271 */ 272 PJ_STUN_SEND_INDICATION = 0x00 04,272 PJ_STUN_SEND_INDICATION = 0x0014, 273 273 274 274 /** 275 275 * STUN/TURN Data Indication 276 276 */ 277 PJ_STUN_DATA_INDICATION = 0x0 115,277 PJ_STUN_DATA_INDICATION = 0x0015, 278 278 279 279 /** … … 310 310 * STUN/TURN Connect Status Indication 311 311 */ 312 PJ_STUN_CONNECT_STATUS_INDICATION = 0x0 118312 PJ_STUN_CONNECT_STATUS_INDICATION = 0x0018 313 313 314 314 … … 516 516 \endverbatim 517 517 */ 518 typedef struct pj_stun_ ip_addr_attr518 typedef struct pj_stun_sockaddr_attr 519 519 { 520 520 /** … … 522 522 */ 523 523 pj_stun_attr_hdr hdr; 524 525 /** 526 * Flag to indicate whether this attribute should be sent in XOR-ed 527 * format, or has been received in XOR-ed format. 528 */ 529 pj_bool_t xor_ed; 524 530 525 531 /** … … 532 538 } addr; 533 539 534 } pj_stun_ ip_addr_attr;540 } pj_stun_sockaddr_attr; 535 541 536 542 … … 745 751 * The MAPPED-ADDRESS attribute indicates the mapped transport address. 746 752 */ 747 typedef struct pj_stun_ ip_addr_attr pj_stun_mapped_addr_attr;753 typedef struct pj_stun_sockaddr_attr pj_stun_mapped_addr_attr; 748 754 749 755 … … 757 763 * through NATs which would otherwise interfere with STUN. 758 764 */ 759 typedef struct pj_stun_ ip_addr_attr pj_stun_xor_mapped_addr_attr;765 typedef struct pj_stun_sockaddr_attr pj_stun_xor_mapped_addr_attr; 760 766 761 767 … … 777 783 * MAPPED-ADDRESS. 778 784 */ 779 typedef struct pj_stun_ ip_addr_attr pj_stun_alt_server_attr;785 typedef struct pj_stun_sockaddr_attr pj_stun_alt_server_attr; 780 786 781 787 … … 798 804 * RFC 3489-bis standard. 799 805 */ 800 typedef struct pj_stun_ ip_addr_attr pj_stun_response_addr_attr;806 typedef struct pj_stun_sockaddr_attr pj_stun_response_addr_attr; 801 807 802 808 … … 813 819 * RFC 3489-bis standard. 814 820 */ 815 typedef struct pj_stun_ ip_addr_attr pj_stun_changed_addr_attr;821 typedef struct pj_stun_sockaddr_attr pj_stun_changed_addr_attr; 816 822 817 823 … … 845 851 * RFC 3489-bis standard. 846 852 */ 847 typedef struct pj_stun_ ip_addr_attr pj_stun_src_addr_attr;853 typedef struct pj_stun_sockaddr_attr pj_stun_src_addr_attr; 848 854 849 855 … … 857 863 * denial-of-service attacks. 858 864 */ 859 typedef struct pj_stun_ ip_addr_attr pj_stun_reflected_from_attr;865 typedef struct pj_stun_sockaddr_attr pj_stun_reflected_from_attr; 860 866 861 867 … … 902 908 * from the STUN relay server. 903 909 */ 904 typedef struct pj_stun_ ip_addr_attr pj_stun_remote_addr_attr;910 typedef struct pj_stun_sockaddr_attr pj_stun_remote_addr_attr; 905 911 906 912 … … 920 926 * address and port that the server allocated to the client. 921 927 */ 922 typedef struct pj_stun_ ip_addr_attr pj_stun_relay_addr_attr;928 typedef struct pj_stun_sockaddr_attr pj_stun_relay_addr_attr; 923 929 924 930 … … 976 982 * specific IP address be allocated to it. 977 983 */ 978 typedef struct pj_stun_ ip_addr_attr pj_stun_req_ip_attr;984 typedef struct pj_stun_sockaddr_attr pj_stun_req_ip_attr; 979 985 980 986 /** … … 988 994 * to XOR-MAPPED-ADDRESS. 989 995 */ 990 typedef struct pj_stun_ ip_addr_attr pj_stun_xor_reflected_from_attr;996 typedef struct pj_stun_sockaddr_attr pj_stun_xor_reflected_from_attr; 991 997 992 998 /** … … 1016 1022 * the STUN-aware NATs along the path. 1017 1023 */ 1018 typedef pj_stun_ ip_addr_attr pj_stun_xor_internal_addr_attr;1024 typedef pj_stun_sockaddr_attr pj_stun_xor_internal_addr_attr; 1019 1025 1020 1026 /** … … 1305 1311 * @return PJ_SUCCESS on success or the appropriate error code. 1306 1312 */ 1307 PJ_DECL(pj_status_t) pj_stun_ ip_addr_attr_create(pj_pool_t *pool,1313 PJ_DECL(pj_status_t) pj_stun_sockaddr_attr_create(pj_pool_t *pool, 1308 1314 int attr_type, 1309 1315 pj_bool_t xor_ed, 1310 1316 const pj_sockaddr_t *addr, 1311 1317 unsigned addr_len, 1312 pj_stun_ ip_addr_attr **p_attr);1318 pj_stun_sockaddr_attr **p_attr); 1313 1319 1314 1320 … … 1328 1334 * @return PJ_SUCCESS on success or the appropriate error code. 1329 1335 */ 1330 PJ_DECL(pj_status_t) pj_stun_msg_add_ ip_addr_attr(pj_pool_t *pool,1336 PJ_DECL(pj_status_t) pj_stun_msg_add_sockaddr_attr(pj_pool_t *pool, 1331 1337 pj_stun_msg *msg, 1332 1338 int attr_type, -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_msg.c
r1053 r1054 90 90 }; 91 91 92 static pj_status_t decode_ ip_addr_attr(pj_pool_t *pool,92 static pj_status_t decode_sockaddr_attr(pj_pool_t *pool, 93 93 const pj_uint8_t *buf, 94 94 void **p_attr); 95 static pj_status_t encode_ip_addr_attr(const void *a, pj_uint8_t *buf, 95 static pj_status_t decode_xored_sockaddr_attr(pj_pool_t *pool, 96 const pj_uint8_t *buf, 97 void **p_attr); 98 static pj_status_t encode_sockaddr_attr(const void *a, pj_uint8_t *buf, 96 99 unsigned len, 97 100 unsigned *printed); … … 144 147 /* PJ_STUN_ATTR_MAPPED_ADDR, */ 145 148 "MAPPED-ADDRESS", 146 &decode_ ip_addr_attr,147 &encode_ ip_addr_attr149 &decode_sockaddr_attr, 150 &encode_sockaddr_attr 148 151 }, 149 152 { 150 153 /* PJ_STUN_ATTR_RESPONSE_ADDR, */ 151 154 "RESPONSE-ADDRESS", 152 &decode_ ip_addr_attr,153 &encode_ ip_addr_attr155 &decode_sockaddr_attr, 156 &encode_sockaddr_attr 154 157 }, 155 158 { … … 162 165 /* PJ_STUN_ATTR_SOURCE_ADDR, */ 163 166 "SOURCE-ADDRESS", 164 &decode_ ip_addr_attr,165 &encode_ ip_addr_attr167 &decode_sockaddr_attr, 168 &encode_sockaddr_attr 166 169 }, 167 170 { 168 171 /* PJ_STUN_ATTR_CHANGED_ADDR, */ 169 172 "CHANGED-ADDRESS", 170 &decode_ ip_addr_attr,171 &encode_ ip_addr_attr173 &decode_sockaddr_attr, 174 &encode_sockaddr_attr 172 175 }, 173 176 { … … 204 207 /* PJ_STUN_ATTR_REFLECTED_FROM, */ 205 208 "REFLECTED-FROM", 206 &decode_ ip_addr_attr,207 &encode_ ip_addr_attr209 &decode_sockaddr_attr, 210 &encode_sockaddr_attr 208 211 }, 209 212 { … … 246 249 /* PJ_STUN_ATTR_REMOTE_ADDRESS, */ 247 250 "REMOTE-ADDRESS", 248 &decode_ ip_addr_attr,249 &encode_ ip_addr_attr251 &decode_sockaddr_attr, 252 &encode_sockaddr_attr 250 253 }, 251 254 { … … 270 273 /* PJ_STUN_ATTR_RELAY_ADDRESS, */ 271 274 "RELAY-ADDRESS", 272 &decode_ ip_addr_attr,273 &encode_ ip_addr_attr275 &decode_sockaddr_attr, 276 &encode_sockaddr_attr 274 277 }, 275 278 { … … 330 333 /* PJ_STUN_ATTR_XOR_MAPPED_ADDRESS, */ 331 334 "XOR-MAPPED-ADDRESS", 332 &decode_ ip_addr_attr,333 &encode_ ip_addr_attr335 &decode_xored_sockaddr_attr, 336 &encode_sockaddr_attr 334 337 }, 335 338 { … … 342 345 /* PJ_STUN_ATTR_REQUESTED_IP, */ 343 346 "REQUESTED-IP", 344 &decode_ ip_addr_attr,345 &encode_ ip_addr_attr347 &decode_sockaddr_attr, 348 &encode_sockaddr_attr 346 349 }, 347 350 { 348 351 /* PJ_STUN_ATTR_XOR_REFLECTED_FROM, */ 349 352 "XOR-REFLECTED-FROM", 350 &decode_ ip_addr_attr,351 &encode_ ip_addr_attr353 &decode_xored_sockaddr_attr, 354 &encode_sockaddr_attr 352 355 }, 353 356 { … … 366 369 /* PJ_STUN_ATTR_XOR_INTERNAL_ADDR, */ 367 370 "XOR-INTERNAL-ADDRESS", 368 &decode_ ip_addr_attr,369 &encode_ ip_addr_attr371 &decode_xored_sockaddr_attr, 372 &encode_sockaddr_attr 370 373 }, 371 374 … … 396 399 /* PJ_STUN_ATTR_ALTERNATE_SERVER, */ 397 400 "ALTERNATE-SERVER", 398 &decode_ ip_addr_attr,399 &encode_ ip_addr_attr401 &decode_sockaddr_attr, 402 &encode_sockaddr_attr 400 403 }, 401 404 { … … 540 543 */ 541 544 PJ_DEF(pj_status_t) 542 pj_stun_ ip_addr_attr_create(pj_pool_t *pool,543 int attr_type,544 pj_bool_t xor_ed,545 const pj_sockaddr_t *addr,546 unsigned addr_len,547 pj_stun_ip_addr_attr **p_attr)548 { 549 pj_stun_ ip_addr_attr *attr;545 pj_stun_sockaddr_attr_create(pj_pool_t *pool, 546 int attr_type, 547 pj_bool_t xor_ed, 548 const pj_sockaddr_t *addr, 549 unsigned addr_len, 550 pj_stun_sockaddr_attr **p_attr) 551 { 552 pj_stun_sockaddr_attr *attr; 550 553 551 554 PJ_ASSERT_RETURN(pool && addr_len && addr && p_attr, PJ_EINVAL); … … 553 556 addr_len == sizeof(pj_sockaddr_in6), PJ_EINVAL); 554 557 555 attr = PJ_POOL_ZALLOC_T(pool, pj_stun_ ip_addr_attr);558 attr = PJ_POOL_ZALLOC_T(pool, pj_stun_sockaddr_attr); 556 559 INIT_ATTR(attr, attr_type, STUN_GENERIC_IP_ADDR_LEN); 557 560 558 if (!xor_ed) { 559 pj_memcpy(&attr->addr, addr, addr_len); 560 } else if (addr_len == sizeof(pj_sockaddr_in)) { 561 const pj_sockaddr_in *addr4 = (const pj_sockaddr_in*) addr; 562 563 pj_sockaddr_in_init(&attr->addr.ipv4, NULL, 0); 564 attr->addr.ipv4.sin_port = (pj_uint16_t)(addr4->sin_port ^ 0x2112); 565 attr->addr.ipv4.sin_addr.s_addr = (addr4->sin_addr.s_addr ^ 566 pj_htonl(0x2112A442)); 567 } else if (addr_len == sizeof(pj_sockaddr_in6)) { 568 return PJLIB_UTIL_ESTUNIPV6NOTSUPP; 569 } else { 570 return PJLIB_UTIL_ESTUNINADDRLEN; 571 } 561 pj_memcpy(&attr->addr, addr, addr_len); 562 attr->xor_ed = xor_ed; 572 563 573 564 *p_attr = attr; … … 581 572 */ 582 573 PJ_DEF(pj_status_t) 583 pj_stun_msg_add_ ip_addr_attr(pj_pool_t *pool,584 pj_stun_msg *msg,585 int attr_type,586 pj_bool_t xor_ed,587 const pj_sockaddr_t *addr,588 unsigned addr_len)589 { 590 pj_stun_ ip_addr_attr *attr;574 pj_stun_msg_add_sockaddr_attr(pj_pool_t *pool, 575 pj_stun_msg *msg, 576 int attr_type, 577 pj_bool_t xor_ed, 578 const pj_sockaddr_t *addr, 579 unsigned addr_len) 580 { 581 pj_stun_sockaddr_attr *attr; 591 582 pj_status_t status; 592 583 593 status = pj_stun_ ip_addr_attr_create(pool, attr_type, xor_ed,584 status = pj_stun_sockaddr_attr_create(pool, attr_type, xor_ed, 594 585 addr, addr_len, &attr); 595 586 if (status != PJ_SUCCESS) … … 599 590 } 600 591 601 static pj_status_t decode_ ip_addr_attr(pj_pool_t *pool,602 const pj_uint8_t *buf,603 void **p_attr)604 { 605 pj_stun_ ip_addr_attr *attr;592 static pj_status_t decode_sockaddr_attr(pj_pool_t *pool, 593 const pj_uint8_t *buf, 594 void **p_attr) 595 { 596 pj_stun_sockaddr_attr *attr; 606 597 pj_uint32_t val; 607 598 608 599 /* Create the attribute */ 609 attr = PJ_POOL_ZALLOC_T(pool, pj_stun_ ip_addr_attr);600 attr = PJ_POOL_ZALLOC_T(pool, pj_stun_sockaddr_attr); 610 601 pj_memcpy(attr, buf, ATTR_HDR_LEN); 611 602 … … 627 618 /* Get port and address */ 628 619 pj_sockaddr_in_init(&attr->addr.ipv4, NULL, 0); 629 attr->addr.ipv4.sin_port = getval16(buf, ATTR_HDR_LEN +2);620 pj_memcpy(&attr->addr.ipv4.sin_port, buf+ATTR_HDR_LEN+2, 2); 630 621 pj_memcpy(&attr->addr.ipv4.sin_addr, buf+ATTR_HDR_LEN+4, 4); 631 622 … … 637 628 638 629 639 static pj_status_t encode_ip_addr_attr(const void *a, pj_uint8_t *buf, 640 unsigned len, unsigned *printed) 630 static pj_status_t decode_xored_sockaddr_attr(pj_pool_t *pool, 631 const pj_uint8_t *buf, 632 void **p_attr) 633 { 634 pj_stun_sockaddr_attr *attr; 635 pj_uint32_t val; 636 637 /* Create the attribute */ 638 attr = PJ_POOL_ZALLOC_T(pool, pj_stun_sockaddr_attr); 639 pj_memcpy(attr, buf, ATTR_HDR_LEN); 640 641 /* Convert to host byte order */ 642 attr->hdr.type = pj_ntohs(attr->hdr.type); 643 attr->hdr.length = pj_ntohs(attr->hdr.length); 644 645 /* Check that the attribute length is valid */ 646 if (attr->hdr.length != STUN_GENERIC_IP_ADDR_LEN) 647 return PJLIB_UTIL_ESTUNINATTRLEN; 648 649 /* Check address family */ 650 val = *(pj_uint8_t*)(buf + ATTR_HDR_LEN + 1); 651 652 /* Check address family is valid (only supports ipv4 for now) */ 653 if (val != 1) 654 return PJLIB_UTIL_ESTUNIPV6NOTSUPP; 655 656 /* Get port and address */ 657 pj_sockaddr_in_init(&attr->addr.ipv4, NULL, 0); 658 pj_memcpy(&attr->addr.ipv4.sin_port, buf+ATTR_HDR_LEN+2, 2); 659 pj_memcpy(&attr->addr.ipv4.sin_addr, buf+ATTR_HDR_LEN+4, 4); 660 661 attr->addr.ipv4.sin_port ^= 0x2112; 662 attr->addr.ipv4.sin_addr.s_addr ^= pj_htonl(0x2112A442); 663 664 /* Done */ 665 *p_attr = attr; 666 667 return PJ_SUCCESS; 668 } 669 670 671 static pj_status_t encode_sockaddr_attr(const void *a, pj_uint8_t *buf, 672 unsigned len, unsigned *printed) 641 673 { 642 674 enum { … … 644 676 }; 645 677 pj_uint8_t *start_buf = buf; 646 const pj_stun_ ip_addr_attr *ca =647 (const pj_stun_ ip_addr_attr *)a;648 pj_stun_ ip_addr_attr *attr;678 const pj_stun_sockaddr_attr *ca = 679 (const pj_stun_sockaddr_attr *)a; 680 pj_stun_sockaddr_attr *attr; 649 681 650 682 if (len < ATTR_LEN) … … 653 685 /* Copy and convert headers to network byte order */ 654 686 pj_memcpy(buf, a, ATTR_HDR_LEN); 655 attr = (pj_stun_ ip_addr_attr*) buf;687 attr = (pj_stun_sockaddr_attr*) buf; 656 688 attr->hdr.type = pj_htons(attr->hdr.type); 657 689 attr->hdr.length = pj_htons((pj_uint16_t)STUN_GENERIC_IP_ADDR_LEN); … … 665 697 *buf++ = 1; 666 698 667 /* Port */ 668 pj_memcpy(buf, &ca->addr.ipv4.sin_port, 2); 669 buf += 2; 670 671 /* Address */ 672 pj_memcpy(buf, &ca->addr.ipv4.sin_addr, 4); 673 buf += 4; 699 if (ca->xor_ed) { 700 pj_uint32_t addr; 701 pj_uint16_t port; 702 703 addr = ca->addr.ipv4.sin_addr.s_addr; 704 port = ca->addr.ipv4.sin_port; 705 706 port ^= 0x2112; 707 addr ^= pj_htonl(0x2112A442); 708 709 /* Port */ 710 pj_memcpy(buf, &port, 2); 711 buf += 2; 712 713 /* Address */ 714 pj_memcpy(buf, &addr, 4); 715 buf += 4; 716 717 } else { 718 /* Port */ 719 pj_memcpy(buf, &ca->addr.ipv4.sin_port, 2); 720 buf += 2; 721 722 /* Address */ 723 pj_memcpy(buf, &ca->addr.ipv4.sin_addr, 4); 724 buf += 4; 725 } 674 726 675 727 pj_assert(buf - start_buf == ATTR_LEN); -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_msg_dump.c
r1052 r1054 77 77 case PJ_STUN_ATTR_ALTERNATE_SERVER: 78 78 { 79 const pj_stun_ ip_addr_attr *attr;80 81 attr = (const pj_stun_ ip_addr_attr*)ahdr;79 const pj_stun_sockaddr_attr *attr; 80 81 attr = (const pj_stun_sockaddr_attr*)ahdr; 82 82 83 83 if (attr->addr.addr.sa_family == PJ_AF_INET) { -
pjproject/trunk/pjlib-util/src/pjstun-client/client_main.c
r1053 r1054 22 22 23 23 #define THIS_FILE "client_main.c" 24 #define LOCAL_PORT 1998 24 25 #define BANDWIDTH 64 /* -1 to disable */ 25 #define LIFETIME 30 /* -1 to disable */26 #define LIFETIME 600 /* -1 to disable */ 26 27 #define REQ_TRANSPORT -1 /* 0: udp, 1: tcp, -1: disable */ 27 28 #define REQ_PORT_PROPS -1 /* -1 to disable */ … … 40 41 pj_bool_t quit; 41 42 pj_sockaddr_in peer_addr; 42 pj_sockaddr_in srv_addr; /**< server addr */ 43 43 pj_sockaddr_in srv_addr; 44 pj_sockaddr_in relay_addr; 45 char data_buf[256]; 46 char *data; 44 47 } g; 45 48 … … 52 55 char *password; 53 56 char *nonce; 57 char *peer_addr; 54 58 pj_bool_t use_fingerprint; 55 59 } o; 60 61 62 static pj_status_t parse_addr(const char *input, pj_sockaddr_in *addr); 56 63 57 64 … … 88 95 { 89 96 if (status == PJ_SUCCESS) { 90 puts("Client transaction completes"); 97 switch (response->hdr.type) { 98 case PJ_STUN_ALLOCATE_RESPONSE: 99 { 100 pj_stun_relay_addr_attr *ar; 101 102 ar = (pj_stun_relay_addr_attr*) 103 pj_stun_msg_find_attr(response, 104 PJ_STUN_ATTR_RELAY_ADDR, 0); 105 if (ar) { 106 pj_memcpy(&g.relay_addr, &ar->addr.ipv4, 107 sizeof(pj_sockaddr_in)); 108 PJ_LOG(3,(THIS_FILE, "Relay address is %s:%d", 109 pj_inet_ntoa(g.relay_addr.sin_addr), 110 (int)pj_ntohs(g.relay_addr.sin_port))); 111 } else { 112 pj_memset(&g.relay_addr, 0, sizeof(g.relay_addr)); 113 } 114 } 115 break; 116 } 91 117 } else { 92 118 my_perror("Client transaction error", status); … … 120 146 addrlen = sizeof(addr); 121 147 rc = pj_sock_recvfrom(g.sock, buffer, &len, 0, &addr, &addrlen); 122 if (rc == PJ_SUCCESS && len > 0) { 148 if (rc != PJ_SUCCESS || len <= 0) 149 continue; 150 151 if (pj_stun_msg_check(buffer, len, PJ_STUN_IS_DATAGRAM)==PJ_SUCCESS) { 123 152 rc = pj_stun_session_on_rx_pkt(g.sess, buffer, len, 124 PJ_STUN_IS_DATAGRAM|PJ_STUN_CHECK_PACKET,153 0, 125 154 NULL, &addr, addrlen); 126 155 if (rc != PJ_SUCCESS) 127 156 my_perror("Error processing packet", rc); 157 158 } else { 159 buffer[len] = '\0'; 160 PJ_LOG(3,(THIS_FILE, "Received data: %s", (char*)buffer)); 128 161 } 129 162 } … … 139 172 pj_sockaddr_in addr; 140 173 pj_stun_session_cb stun_cb; 174 int len; 141 175 pj_status_t status; 142 176 … … 182 216 status = pj_sockaddr_in_init(&addr, NULL, 0); 183 217 pj_assert(status == PJ_SUCCESS); 218 219 addr.sin_port = pj_htons((pj_uint16_t)LOCAL_PORT); 220 status = pj_sock_bind(g.sock, &addr, sizeof(addr)); 221 pj_assert(status == PJ_SUCCESS); 222 223 len = sizeof(addr); 224 status = pj_sock_getsockname(g.sock, &addr, &len); 225 pj_assert(status == PJ_SUCCESS); 226 227 PJ_LOG(3,(THIS_FILE, "Listening on port %d", (int)pj_ntohs(addr.sin_port))); 228 229 pj_memcpy(&g.peer_addr, &addr, sizeof(pj_sockaddr_in)); 230 if (g.peer_addr.sin_addr.s_addr == 0) 231 pj_gethostip(&g.peer_addr.sin_addr); 184 232 185 233 pj_memset(&stun_cb, 0, sizeof(stun_cb)); … … 207 255 } else { 208 256 puts("Credential not set"); 257 } 258 259 if (o.peer_addr) { 260 if (parse_addr(o.peer_addr, &g.peer_addr)!=PJ_SUCCESS) 261 return -1; 209 262 } 210 263 … … 297 350 298 351 pj_sockaddr_in_init(&addr, pj_cstr(&tmp, REQ_IP), 0); 299 pj_stun_msg_add_ ip_addr_attr(tdata->pool, tdata->msg,352 pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, 300 353 PJ_STUN_ATTR_REQ_IP, PJ_FALSE, 301 354 &addr, sizeof(addr)); … … 321 374 } 322 375 323 rc = pj_stun_session_create_req(g.sess, PJ_STUN_ ALLOCATE_REQUEST, &tdata);376 rc = pj_stun_session_create_req(g.sess, PJ_STUN_SET_ACTIVE_DESTINATION_REQUEST, &tdata); 324 377 pj_assert(rc == PJ_SUCCESS); 325 378 326 379 if (set) { 327 pj_stun_msg_add_ ip_addr_attr(tdata->pool, tdata->msg,380 pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, 328 381 PJ_STUN_ATTR_REMOTE_ADDR, PJ_FALSE, 329 382 &g.peer_addr, sizeof(g.peer_addr)); … … 338 391 static void send_send_ind(void) 339 392 { 340 } 341 342 static void send_raw_data(void) 343 { 393 pj_stun_tx_data *tdata; 394 int len; 395 pj_status_t rc; 396 397 if (g.peer_addr.sin_addr.s_addr == 0 || 398 g.peer_addr.sin_port == 0) 399 { 400 puts("Error: peer address is not set"); 401 return; 402 } 403 404 len = strlen(g.data); 405 if (len==0) { 406 puts("Error: data is not set"); 407 return; 408 } 409 410 rc = pj_stun_session_create_ind(g.sess, PJ_STUN_SEND_INDICATION, &tdata); 411 pj_assert(rc == PJ_SUCCESS); 412 413 pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, 414 PJ_STUN_ATTR_REMOTE_ADDR, PJ_FALSE, 415 &g.peer_addr, sizeof(g.peer_addr)); 416 pj_stun_msg_add_binary_attr(tdata->pool, tdata->msg, 417 PJ_STUN_ATTR_DATA, g.data, len); 418 419 rc = pj_stun_session_send_msg(g.sess, PJ_FALSE, 420 &g.srv_addr, sizeof(g.srv_addr), 421 tdata); 422 pj_assert(rc == PJ_SUCCESS); 423 424 } 425 426 static void send_raw_data_to_srv(void) 427 { 428 pj_ssize_t len; 429 430 if (g.srv_addr.sin_addr.s_addr == 0 || 431 g.srv_addr.sin_port == 0) 432 { 433 puts("Error: server address is not set"); 434 return; 435 } 436 437 len = strlen(g.data); 438 if (len==0) { 439 puts("Error: data is not set"); 440 return; 441 } 442 443 len = strlen(g.data); 444 pj_sock_sendto(g.sock, g.data, &len, 0, &g.srv_addr, sizeof(g.srv_addr)); 445 } 446 447 static void send_raw_data_to_relay(void) 448 { 449 pj_ssize_t len; 450 451 if (g.relay_addr.sin_addr.s_addr == 0 || 452 g.relay_addr.sin_port == 0) 453 { 454 puts("Error: relay address is not set"); 455 return; 456 } 457 458 len = strlen(g.data); 459 if (len==0) { 460 puts("Error: data is not set"); 461 return; 462 } 463 464 len = strlen(g.data); 465 pj_sock_sendto(g.sock, g.data, &len, 0, &g.relay_addr, sizeof(g.relay_addr)); 466 } 467 468 static pj_status_t parse_addr(const char *input, 469 pj_sockaddr_in *addr) 470 { 471 const char *pos; 472 pj_str_t ip; 473 pj_uint16_t port; 474 pj_sockaddr_in tmp_addr; 475 476 pos = pj_ansi_strchr(input, ':'); 477 if (pos==NULL) { 478 puts("Invalid format"); 479 return -1; 480 } 481 482 ip.ptr = (char*)input; 483 ip.slen = pos - input; 484 port = (pj_uint16_t)atoi(pos+1); 485 486 if (port==0) { 487 puts("Invalid port"); 488 return -1; 489 } 490 491 if (pj_sockaddr_in_init(&tmp_addr, &ip, port)!=PJ_SUCCESS) { 492 puts("Invalid address"); 493 return -1; 494 } 495 496 pj_memcpy(addr, &tmp_addr, sizeof(tmp_addr)); 497 498 return PJ_SUCCESS; 344 499 } 345 500 346 501 static void set_peer_addr(void) 347 502 { 348 char ip_addr[64]; 349 pj_str_t tmp; 350 pj_sockaddr_in addr; 351 int port; 503 char addr[64]; 352 504 353 505 printf("Current peer address: %s:%d\n", … … 357 509 printf("Input peer address in IP:PORT format: "); 358 510 fflush(stdout); 359 360 if (scanf("%s:%d", ip_addr, &port) != 2) { 361 puts("Error."); 362 return; 363 } 364 365 if (pj_sockaddr_in_init(&addr, pj_cstr(&tmp,ip_addr), (pj_uint16_t)port) != PJ_SUCCESS) { 366 puts("Error: invalid address"); 367 return; 368 } 369 370 g.peer_addr = addr; 511 gets(addr); 512 513 if (parse_addr(addr, &g.peer_addr) != PJ_SUCCESS) { 514 return; 515 } 516 371 517 } 372 518 … … 376 522 printf(" pr Set peer address (currently %s:%d)\n", 377 523 pj_inet_ntoa(g.peer_addr.sin_addr), pj_ntohs(g.peer_addr.sin_port)); 378 p uts("");524 printf(" dt Set data (currently \"%s\")\n", g.data); 379 525 puts(" br Send Bind request"); 380 526 puts(" ar Send Allocate request"); 381 527 puts(" dr Send de-Allocate request"); 382 puts(" sr Send Set Active Indication request");383 puts(" cr Send clear Active Indication request");528 puts(" sr Send Set Active Destination request"); 529 puts(" cr Send clear Active Destination request"); 384 530 puts(" si Send data with Send Indication"); 385 puts(" rw Send raw data"); 531 puts(" rw Send raw data to TURN server"); 532 puts(" rW Send raw data to relay address"); 386 533 puts(" q Quit"); 387 534 puts(""); … … 399 546 fgets(input, sizeof(input), stdin); 400 547 401 if (input[0]=='b' && input[1]=='r') { 548 if (0) { 549 550 } else if (input[0]=='d' && input[1]=='t') { 551 printf("Input data: "); 552 gets(g.data); 553 554 } else if (input[0]=='p' && input[1]=='r') { 555 set_peer_addr(); 556 557 } else if (input[0]=='b' && input[1]=='r') { 402 558 send_bind_request(); 403 559 … … 418 574 419 575 } else if (input[0]=='r' && input[1]=='w') { 420 send_raw_data ();421 422 } else if (input[0]==' p' && input[1]=='r') {423 se t_peer_addr();576 send_raw_data_to_srv(); 577 578 } else if (input[0]=='r' && input[1]=='W') { 579 send_raw_data_to_relay(); 424 580 425 581 } else if (input[0]=='q') { … … 442 598 puts(" --nonce, -N Set NONCE"); 443 599 puts(" --fingerprint, -F Use fingerprint for outgoing requests"); 600 puts(" --peer, -P Set peer address (address is in HOST:PORT format)"); 601 puts(" --data, -D Set data"); 444 602 puts(" --help, -h"); 445 603 } … … 453 611 { "nonce", 1, 0, 'N'}, 454 612 { "fingerprint",0, 0, 'F'}, 613 { "peer", 1, 0, 'P'}, 614 { "data", 1, 0, 'D'}, 455 615 { "help", 0, 0, 'h'} 456 616 }; … … 459 619 pj_status_t status; 460 620 621 g.data = g.data_buf; 622 461 623 while((c=pj_getopt_long(argc,argv, "r:u:p:hF", long_options, &opt_id))!=-1) { 462 624 switch (c) { … … 479 641 o.use_fingerprint = PJ_TRUE; 480 642 break; 643 case 'P': 644 o.peer_addr = pj_optarg; 645 break; 646 case 'D': 647 g.data = pj_optarg; 648 break; 649 481 650 default: 482 651 printf("Argument \"%s\" is not valid. Use -h to see help", -
pjproject/trunk/pjlib-util/src/pjstun-srv-test/bind_usage.c
r1049 r1054 163 163 164 164 /* Create MAPPED-ADDRESS attribute */ 165 status = pj_stun_msg_add_ ip_addr_attr(tdata->pool, tdata->msg,166 PJ_STUN_ATTR_MAPPED_ADDR,167 PJ_FALSE,168 src_addr, src_addr_len);165 status = pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, 166 PJ_STUN_ATTR_MAPPED_ADDR, 167 PJ_FALSE, 168 src_addr, src_addr_len); 169 169 if (status != PJ_SUCCESS) { 170 170 pj_stun_perror(THIS_FILE, "Error creating response", status); … … 176 176 if (msg->hdr.magic == PJ_STUN_MAGIC) { 177 177 status = 178 pj_stun_msg_add_ ip_addr_attr(tdata->pool, tdata->msg,179 PJ_STUN_ATTR_XOR_MAPPED_ADDR,180 PJ_TRUE,181 src_addr, src_addr_len);178 pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, 179 PJ_STUN_ATTR_XOR_MAPPED_ADDR, 180 PJ_TRUE, 181 src_addr, src_addr_len); 182 182 if (status != PJ_SUCCESS) { 183 183 pj_stun_perror(THIS_FILE, "Error creating response", status); -
pjproject/trunk/pjlib-util/src/pjstun-srv-test/main.c
r1049 r1054 123 123 } 124 124 125 /* 125 126 status = pj_stun_bind_usage_create(srv, NULL, 3478, NULL); 127 if (status != PJ_SUCCESS) { 128 pj_stun_perror(THIS_FILE, "Unable to create bind usage", status); 129 return 1; 130 } 131 */ 132 133 status = pj_stun_turn_usage_create(srv, PJ_SOCK_DGRAM, NULL, 134 3478, NULL); 126 135 if (status != PJ_SUCCESS) { 127 136 pj_stun_perror(THIS_FILE, "Unable to create bind usage", status); -
pjproject/trunk/pjlib-util/src/pjstun-srv-test/server.h
r1049 r1054 113 113 unsigned addr_len); 114 114 115 PJ_DE F(pj_status_t) pj_stun_bind_usage_create(pj_stun_server *srv,116 const pj_str_t *ip_addr,117 unsigned port,118 pj_stun_usage **p_bu);115 PJ_DECL(pj_status_t) pj_stun_bind_usage_create(pj_stun_server *srv, 116 const pj_str_t *ip_addr, 117 unsigned port, 118 pj_stun_usage **p_bu); 119 119 120 PJ_DECL(pj_status_t) pj_stun_turn_usage_create(pj_stun_server *srv, 121 int type, 122 const pj_str_t *ip_addr, 123 unsigned port, 124 pj_stun_usage **p_bu); 120 125 121 126 -
pjproject/trunk/pjlib-util/src/pjstun-srv-test/turn_usage.c
r1053 r1054 50 50 unsigned src_addr_len); 51 51 52 static pj_status_t handle_binding_req(pj_stun_session *session, 53 const pj_stun_msg *msg, 54 const pj_sockaddr_t *src_addr, 55 unsigned src_addr_len); 56 52 57 static pj_status_t client_create(struct turn_usage *tu, 53 58 const pj_sockaddr_t *src_addr, … … 91 96 pj_mutex_t *mutex; 92 97 98 pj_sockaddr_in client_src_addr; 99 93 100 /* Socket and socket address of the allocated port */ 94 101 int sock_type; 95 102 pj_sock_t sock; 96 103 pj_ioqueue_key_t *key; 97 pj_sockaddr_in client_addr;104 pj_sockaddr_in alloc_addr; 98 105 99 106 /* Allocation properties */ … … 150 157 pj_status_t status; 151 158 152 PJ_ASSERT_RETURN(srv && (type==PJ_SOCK_DGRAM||type==PJ_SOCK_STREAM) &&153 p_bu,PJ_EINVAL);159 PJ_ASSERT_RETURN(srv && (type==PJ_SOCK_DGRAM||type==PJ_SOCK_STREAM), 160 PJ_EINVAL); 154 161 si = pj_stun_server_get_info(srv); 155 162 … … 160 167 tu->pf = si->pf; 161 168 tu->endpt = si->endpt; 169 tu->ioqueue = si->ioqueue; 162 170 tu->timer_heap = si->timer_heap; 163 171 tu->next_port = START_PORT; 172 tu->max_bw_kbps = 64; 173 tu->max_lifetime = 10 * 60; 164 174 165 175 status = pj_sockaddr_in_init(&local_addr, ip_addr, (pj_uint16_t)port); … … 206 216 } 207 217 208 *p_bu = tu->usage; 218 if (p_bu) { 219 *p_bu = tu->usage; 220 } 209 221 210 222 return PJ_SUCCESS; … … 224 236 225 237 /* Destroy all clients */ 226 it = pj_hash_first(tu->client_htable, &hit); 227 while (it) { 228 struct turn_client *client; 229 230 client = (struct turn_client *)pj_hash_this(tu->client_htable, it); 231 client_destroy(client, PJ_SUCCESS); 232 233 it = pj_hash_next(tu->client_htable, it); 238 if (tu->client_htable) { 239 it = pj_hash_first(tu->client_htable, &hit); 240 while (it) { 241 struct turn_client *client; 242 243 client = (struct turn_client *)pj_hash_this(tu->client_htable, it); 244 client_destroy(client, PJ_SUCCESS); 245 246 it = pj_hash_first(tu->client_htable, &hit); 247 } 234 248 } 235 249 … … 392 406 } 393 407 408 *p_sock = sock; 394 409 return PJ_SUCCESS; 395 410 } … … 420 435 pj_assert(sd->client == NULL); 421 436 422 if (msg->hdr.type != PJ_STUN_ALLOCATE_REQUEST) { 437 if (msg->hdr.type == PJ_STUN_BINDING_REQUEST) { 438 return handle_binding_req(sess, msg, src_addr, src_addr_len); 439 440 } else if (msg->hdr.type != PJ_STUN_ALLOCATE_REQUEST) { 423 441 if (PJ_STUN_IS_REQUEST(msg->hdr.type)) { 424 442 status = pj_stun_session_create_response(sess, msg, … … 506 524 static const char *get_tp_type(int type) 507 525 { 508 if (type== 0)526 if (type==PJ_SOCK_DGRAM) 509 527 return "udp"; 510 else if (type== 1)528 else if (type==PJ_SOCK_STREAM) 511 529 return "tcp"; 512 530 else … … 520 538 * the packet is handed over to the client. 521 539 */ 522 static pj_status_t client_sess_on_rx_ request(pj_stun_session *sess,523 524 525 526 527 540 static pj_status_t client_sess_on_rx_msg(pj_stun_session *sess, 541 const pj_uint8_t *pkt, 542 unsigned pkt_len, 543 const pj_stun_msg *msg, 544 const pj_sockaddr_t *src_addr, 545 unsigned src_addr_len) 528 546 { 529 547 struct session_data *sd; … … 577 595 pj_status_t status; 578 596 597 PJ_ASSERT_RETURN(src_addr_len==sizeof(pj_sockaddr_in), PJ_EINVAL); 598 579 599 pool = pj_pool_create(tu->pf, "turnc%p", 4000, 4000, NULL); 580 600 client = PJ_POOL_ZALLOC_T(pool, struct turn_client); … … 582 602 client->tu = tu; 583 603 client->sock = PJ_INVALID_SOCKET; 604 605 pj_memcpy(&client->client_src_addr, src_addr, 606 sizeof(client->client_src_addr)); 584 607 585 608 if (src_addr) { … … 596 619 pj_bzero(&sess_cb, sizeof(sess_cb)); 597 620 sess_cb.on_send_msg = &client_sess_on_send_msg; 598 sess_cb.on_rx_request = &client_sess_on_rx_request; 621 sess_cb.on_rx_request = &client_sess_on_rx_msg; 622 sess_cb.on_rx_indication = &client_sess_on_rx_msg; 599 623 status = pj_stun_session_create(tu->endpt, client->obj_name, 600 624 &sess_cb, PJ_FALSE, … … 668 692 pj_mutex_lock(tu->mutex); 669 693 pj_hash_set(NULL, tu->client_htable, 670 &client->client_addr, sizeof(client->client_addr), 0, NULL); 694 &client->client_src_addr, sizeof(client->client_src_addr), 695 0, NULL); 671 696 pj_mutex_unlock(tu->mutex); 672 697 … … 710 735 /* Update address */ 711 736 addrlen = sizeof(pj_sockaddr_in); 712 status = pj_sock_getsockname(client->sock, &client-> client_addr,737 status = pj_sock_getsockname(client->sock, &client->alloc_addr, 713 738 &addrlen); 714 739 if (status != PJ_SUCCESS) { … … 716 741 client->sock = PJ_INVALID_SOCKET; 717 742 return status; 743 } 744 745 if (client->alloc_addr.sin_addr.s_addr == 0) { 746 status = pj_gethostip(&client->alloc_addr.sin_addr); 747 if (status != PJ_SUCCESS) { 748 pj_sock_close(client->sock); 749 client->sock = PJ_INVALID_SOCKET; 750 return status; 751 } 718 752 } 719 753 … … 741 775 client->obj_name, 742 776 get_tp_type(client->sock_type), 743 pj_inet_ntoa(client-> client_addr.sin_addr),744 (int)pj_ntohs(client-> client_addr.sin_port)));777 pj_inet_ntoa(client->alloc_addr.sin_addr), 778 (int)pj_ntohs(client->alloc_addr.sin_port))); 745 779 746 780 return PJ_SUCCESS; … … 767 801 client->obj_name, 768 802 get_tp_type(client->sock_type), 769 pj_inet_ntoa(client-> client_addr.sin_addr),770 (int)pj_ntohs(client-> client_addr.sin_port)));803 pj_inet_ntoa(client->alloc_addr.sin_addr), 804 (int)pj_ntohs(client->alloc_addr.sin_port))); 771 805 return PJ_SUCCESS; 772 806 } … … 796 830 peer = PJ_POOL_ZALLOC_T(client->pool, struct peer); 797 831 peer->client = client; 798 pj_memcpy(&peer->addr, peer_addr, sizeof( *peer_addr));832 pj_memcpy(&peer->addr, peer_addr, sizeof(peer->addr)); 799 833 800 834 pj_hash_set(client->pool, client->peer_htable, 801 peer_addr, sizeof(*peer_addr), hval, peer);835 &peer->addr, sizeof(peer->addr), hval, peer); 802 836 803 837 PJ_LOG(4,(THIS_FILE, "TURN client %s: peer %s:%s:%d added", 804 838 client->obj_name, get_tp_type(client->sock_type), 805 pj_inet_ntoa(peer _addr->sin_addr),806 (int)pj_ntohs(peer _addr->sin_port)));839 pj_inet_ntoa(peer->addr.sin_addr), 840 (int)pj_ntohs(peer->addr.sin_port))); 807 841 808 842 return peer; … … 976 1010 timeout.msec = 0; 977 1011 pj_timer_heap_schedule(client->tu->timer_heap, &client->expiry_timer, &timeout); 978 1012 client->expiry_timer.id = PJ_TRUE; 979 1013 980 1014 /* Done successfully, create and send success response */ … … 989 1023 pj_stun_msg_add_uint_attr(response->pool, response->msg, 990 1024 PJ_STUN_ATTR_LIFETIME, client->lifetime); 991 pj_stun_msg_add_ ip_addr_attr(response->pool, response->msg,1025 pj_stun_msg_add_sockaddr_attr(response->pool, response->msg, 992 1026 PJ_STUN_ATTR_MAPPED_ADDR, PJ_FALSE, 993 1027 src_addr, src_addr_len); 994 pj_stun_msg_add_ ip_addr_attr(response->pool, response->msg,1028 pj_stun_msg_add_sockaddr_attr(response->pool, response->msg, 995 1029 PJ_STUN_ATTR_XOR_MAPPED_ADDR, PJ_TRUE, 996 1030 src_addr, src_addr_len); … … 998 1032 addr_len = sizeof(req_addr); 999 1033 pj_sock_getsockname(client->sock, &req_addr, &addr_len); 1000 pj_stun_msg_add_ ip_addr_attr(response->pool, response->msg,1034 pj_stun_msg_add_sockaddr_attr(response->pool, response->msg, 1001 1035 PJ_STUN_ATTR_RELAY_ADDR, PJ_FALSE, 1002 & req_addr, addr_len);1036 &client->alloc_addr, addr_len); 1003 1037 1004 1038 PJ_LOG(4,(THIS_FILE, "TURN client %s: relay allocated or refreshed, " … … 1011 1045 return pj_stun_session_send_msg(client->session, PJ_TRUE, 1012 1046 src_addr, src_addr_len, response); 1047 } 1048 1049 1050 /* 1051 * Handle incoming Binding request. 1052 * This function is called by client_handle_stun_msg() below. 1053 */ 1054 static pj_status_t handle_binding_req(pj_stun_session *session, 1055 const pj_stun_msg *msg, 1056 const pj_sockaddr_t *src_addr, 1057 unsigned src_addr_len) 1058 { 1059 pj_stun_tx_data *tdata; 1060 pj_status_t status; 1061 1062 /* Create response */ 1063 status = pj_stun_session_create_response(session, msg, 0, NULL, 1064 &tdata); 1065 if (status != PJ_SUCCESS) 1066 return status; 1067 1068 /* Create MAPPED-ADDRESS attribute */ 1069 pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, 1070 PJ_STUN_ATTR_MAPPED_ADDR, 1071 PJ_FALSE, 1072 src_addr, src_addr_len); 1073 1074 /* On the presence of magic, create XOR-MAPPED-ADDRESS attribute */ 1075 if (msg->hdr.magic == PJ_STUN_MAGIC) { 1076 status = 1077 pj_stun_msg_add_sockaddr_attr(tdata->pool, tdata->msg, 1078 PJ_STUN_ATTR_XOR_MAPPED_ADDR, 1079 PJ_TRUE, 1080 src_addr, src_addr_len); 1081 } 1082 1083 /* Send */ 1084 status = pj_stun_session_send_msg(session, PJ_TRUE, 1085 src_addr, src_addr_len, tdata); 1086 return status; 1013 1087 } 1014 1088 … … 1059 1133 } 1060 1134 1061 PJ_LOG(4,(THIS_FILE, "TURN client %s: active destination set to %s:%d", 1062 client->obj_name, 1063 pj_inet_ntoa(client->active_peer->addr.sin_addr), 1064 (int)pj_ntohs(client->active_peer->addr.sin_port))); 1135 if (client->active_peer) { 1136 PJ_LOG(4,(THIS_FILE, 1137 "TURN client %s: active destination set to %s:%d", 1138 client->obj_name, 1139 pj_inet_ntoa(client->active_peer->addr.sin_addr), 1140 (int)pj_ntohs(client->active_peer->addr.sin_port))); 1141 } else { 1142 PJ_LOG(4,(THIS_FILE, "TURN client %s: active destination cleared", 1143 client->obj_name)); 1144 } 1065 1145 1066 1146 /* Respond with successful response */ … … 1163 1243 case PJ_STUN_SEND_INDICATION: 1164 1244 status = client_handle_send_ind(client, msg); 1245 break; 1165 1246 1166 1247 case PJ_STUN_SET_ACTIVE_DESTINATION_REQUEST: 1167 1248 status = client_handle_sad(client, msg, 1168 1249 src_addr, src_addr_len); 1250 break; 1251 1169 1252 case PJ_STUN_ALLOCATE_REQUEST: 1170 1253 status = client_handle_allocate_req(client, msg, 1171 1254 src_addr, src_addr_len); 1255 break; 1256 1257 case PJ_STUN_BINDING_REQUEST: 1258 status = handle_binding_req(client->session, msg, 1259 src_addr, src_addr_len); 1260 break; 1172 1261 1173 1262 default: 1174 1263 status = client_handle_unknown_msg(client, msg, 1175 1264 src_addr, src_addr_len); 1265 break; 1176 1266 } 1177 1267 … … 1204 1294 if (peer == NULL) { 1205 1295 /* Nope. Discard packet */ 1296 PJ_LOG(5,(THIS_FILE, 1297 "TURN client %s: discarded data from %s:%d", 1298 client->obj_name, 1299 pj_inet_ntoa(client->pkt_src_addr.sin_addr), 1300 (int)pj_ntohs(client->pkt_src_addr.sin_port))); 1206 1301 return; 1207 1302 } … … 1226 1321 return; 1227 1322 1228 pj_stun_msg_add_ ip_addr_attr(data_ind->pool, data_ind->msg,1229 PJ_STUN_ATTR_REMOTE_ADDR, PJ_FALSE,1230 &client->pkt_src_addr,1231 client->pkt_src_addr_len);1323 pj_stun_msg_add_sockaddr_attr(data_ind->pool, data_ind->msg, 1324 PJ_STUN_ATTR_REMOTE_ADDR, PJ_FALSE, 1325 &client->pkt_src_addr, 1326 client->pkt_src_addr_len); 1232 1327 pj_stun_msg_add_binary_attr(data_ind->pool, data_ind->msg, 1233 1328 PJ_STUN_ATTR_DATA, -
pjproject/trunk/pjlib-util/src/pjstun-srv-test/usage.c
r1049 r1054 83 83 goto on_error; 84 84 85 pj_memcpy(&usage->cb, cb, sizeof(*cb));86 87 85 usage->type = type; 88 86 status = pj_sock_socket(family, type, protocol, &usage->sock); … … 134 132 pj_stun_server_register_usage(srv, usage); 135 133 134 /* Only after everything has been initialized we copy the callback, 135 * to prevent callback from being called when we encounter error 136 * during initialiation (decendant would not expect this). 137 */ 138 pj_memcpy(&usage->cb, cb, sizeof(*cb)); 139 136 140 *p_usage = usage; 137 141 return PJ_SUCCESS; -
pjproject/trunk/pjlib/include/pj/hash.h
r974 r1054 120 120 * created. 121 121 * @param ht the hash table. 122 * @param key the key. 122 * @param key the key, which MUST point to buffer that remains valid 123 * for the duration of the entry. 123 124 * @param keylen the length of the key, or PJ_HASH_KEY_STRING to use the 124 125 * string length of the key. -
pjproject/trunk/pjlib/src/pj/addr_resolv_sock.c
r1025 r1054 56 56 57 57 /* Resolve the IP address of local machine */ 58 pj_status_tpj_gethostip(pj_in_addr *addr)58 PJ_DEF(pj_status_t) pj_gethostip(pj_in_addr *addr) 59 59 { 60 60 const pj_str_t *hostname = pj_gethostname();
Note: See TracChangeset
for help on using the changeset viewer.