- Timestamp:
- Dec 28, 2016 3:40:07 AM (8 years ago)
- Location:
- pjproject/branches/projects/uwp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/uwp
- Property svn:mergeinfo changed
/pjproject/trunk (added) merged: 5209,5212-5234,5237-5253,5255,5257-5292,5294-5297,5299-5332,5334-5394,5396-5438,5440-5469,5471-5496,5498-5510
- Property svn:mergeinfo changed
-
pjproject/branches/projects/uwp/pjsip/src/pjsip/sip_transport_udp.c
r5035 r5513 161 161 rdata->pkt_info.zero = 0; 162 162 pj_gettimeofday(&rdata->pkt_info.timestamp); 163 if (src_addr->addr.sa_family == pj_AF_INET()) { 164 pj_ansi_strcpy(rdata->pkt_info.src_name, 165 pj_inet_ntoa(src_addr->ipv4.sin_addr)); 166 rdata->pkt_info.src_port = pj_ntohs(src_addr->ipv4.sin_port); 167 } else { 168 pj_inet_ntop(pj_AF_INET6(), 169 pj_sockaddr_get_addr(&rdata->pkt_info.src_addr), 170 rdata->pkt_info.src_name, 171 sizeof(rdata->pkt_info.src_name)); 172 rdata->pkt_info.src_port = pj_ntohs(src_addr->ipv6.sin6_port); 173 } 163 pj_sockaddr_print(src_addr, rdata->pkt_info.src_name, 164 sizeof(rdata->pkt_info.src_name), 0); 165 rdata->pkt_info.src_port = pj_sockaddr_get_port(src_addr); 174 166 175 167 size_eaten = … … 518 510 return status; 519 511 520 pj_strcpy2(&bound_name->host, pj_inet_ntoa(hostip.ipv4.sin_addr)); 512 status = pj_inet_ntop(pj_AF_INET(), &hostip.ipv4.sin_addr, 513 hostbuf, hostbufsz); 521 514 } else { 522 515 /* Otherwise use bound address. */ 523 pj_strcpy2(&bound_name->host, 524 pj_inet_ntoa(tmp_addr.ipv4.sin_addr)); 525 status = PJ_SUCCESS; 516 status = pj_inet_ntop(pj_AF_INET(), &tmp_addr.ipv4.sin_addr, 517 hostbuf, hostbufsz); 526 518 } 527 519 … … 543 535 pj_sockaddr_get_addr(&tmp_addr), 544 536 hostbuf, hostbufsz); 545 if (status == PJ_SUCCESS) { 546 bound_name->host.slen = pj_ansi_strlen(hostbuf); 547 }537 } 538 if (status == PJ_SUCCESS) { 539 bound_name->host.slen = pj_ansi_strlen(hostbuf); 548 540 } 549 541 … … 870 862 } 871 863 864 865 /* 866 * Initialize pjsip_udp_transport_cfg structure with default values. 867 */ 868 PJ_DEF(void) pjsip_udp_transport_cfg_default(pjsip_udp_transport_cfg *cfg, 869 int af) 870 { 871 pj_bzero(cfg, sizeof(*cfg)); 872 cfg->af = af; 873 pj_sockaddr_init(cfg->af, &cfg->bind_addr, NULL, 0); 874 cfg->async_cnt = 1; 875 } 876 877 878 /* 879 * pjsip_udp_transport_start2() 880 * 881 * Create a UDP socket in the specified address and start a transport. 882 */ 883 PJ_DEF(pj_status_t) pjsip_udp_transport_start2( 884 pjsip_endpoint *endpt, 885 const pjsip_udp_transport_cfg *cfg, 886 pjsip_transport **p_transport) 887 { 888 pj_sock_t sock; 889 pj_status_t status; 890 pjsip_host_port addr_name; 891 char addr_buf[PJ_INET6_ADDRSTRLEN]; 892 pjsip_transport_type_e transport_type; 893 pj_uint16_t af; 894 int addr_len; 895 896 PJ_ASSERT_RETURN(endpt && cfg && cfg->async_cnt, PJ_EINVAL); 897 898 if (cfg->bind_addr.addr.sa_family == pj_AF_INET()) { 899 af = pj_AF_INET(); 900 transport_type = PJSIP_TRANSPORT_UDP; 901 addr_len = sizeof(pj_sockaddr_in); 902 } else { 903 af = pj_AF_INET6(); 904 transport_type = PJSIP_TRANSPORT_UDP6; 905 addr_len = sizeof(pj_sockaddr_in6); 906 } 907 908 status = create_socket(af, &cfg->bind_addr, addr_len, &sock); 909 if (status != PJ_SUCCESS) 910 return status; 911 912 /* Apply QoS, if specified */ 913 pj_sock_apply_qos2(sock, cfg->qos_type, &cfg->qos_params, 914 2, THIS_FILE, "SIP UDP transport"); 915 916 /* Apply sockopt, if specified */ 917 if (cfg->sockopt_params.cnt) 918 pj_sock_setsockopt_params(sock, &cfg->sockopt_params); 919 920 if (cfg->addr_name.host.slen == 0) { 921 /* Address name is not specified. 922 * Build a name based on bound address. 923 */ 924 status = get_published_name(sock, addr_buf, sizeof(addr_buf), 925 &addr_name); 926 if (status != PJ_SUCCESS) { 927 pj_sock_close(sock); 928 return status; 929 } 930 } else { 931 addr_name = cfg->addr_name; 932 } 933 934 return pjsip_udp_transport_attach2(endpt, transport_type, sock, 935 &addr_name, cfg->async_cnt, 936 p_transport); 937 } 938 872 939 /* 873 940 * pjsip_udp_transport_start() … … 881 948 pjsip_transport **p_transport) 882 949 { 883 pj_sock_t sock; 884 pj_status_t status; 885 char addr_buf[PJ_INET6_ADDRSTRLEN]; 886 pjsip_host_port bound_name; 887 888 PJ_ASSERT_RETURN(endpt && async_cnt, PJ_EINVAL); 889 890 status = create_socket(pj_AF_INET(), local_a, sizeof(pj_sockaddr_in), 891 &sock); 892 if (status != PJ_SUCCESS) 893 return status; 894 895 if (a_name == NULL) { 896 /* Address name is not specified. 897 * Build a name based on bound address. 898 */ 899 status = get_published_name(sock, addr_buf, sizeof(addr_buf), 900 &bound_name); 901 if (status != PJ_SUCCESS) { 902 pj_sock_close(sock); 903 return status; 904 } 905 906 a_name = &bound_name; 907 } 908 909 return pjsip_udp_transport_attach( endpt, sock, a_name, async_cnt, 910 p_transport ); 911 } 912 950 pjsip_udp_transport_cfg cfg; 951 952 pjsip_udp_transport_cfg_default(&cfg, pj_AF_INET()); 953 if (local_a) 954 pj_sockaddr_cp(&cfg.bind_addr, local_a); 955 if (a_name) 956 cfg.addr_name = *a_name; 957 cfg.async_cnt = async_cnt; 958 959 return pjsip_udp_transport_start2(endpt, &cfg, p_transport); 960 } 913 961 914 962 /* … … 923 971 pjsip_transport **p_transport) 924 972 { 925 pj_sock_t sock; 926 pj_status_t status; 927 char addr_buf[PJ_INET6_ADDRSTRLEN]; 928 pjsip_host_port bound_name; 929 930 PJ_ASSERT_RETURN(endpt && async_cnt, PJ_EINVAL); 931 932 status = create_socket(pj_AF_INET6(), local_a, sizeof(pj_sockaddr_in6), 933 &sock); 934 if (status != PJ_SUCCESS) 935 return status; 936 937 if (a_name == NULL) { 938 /* Address name is not specified. 939 * Build a name based on bound address. 940 */ 941 status = get_published_name(sock, addr_buf, sizeof(addr_buf), 942 &bound_name); 943 if (status != PJ_SUCCESS) { 944 pj_sock_close(sock); 945 return status; 946 } 947 948 a_name = &bound_name; 949 } 950 951 return pjsip_udp_transport_attach2(endpt, PJSIP_TRANSPORT_UDP6, 952 sock, a_name, async_cnt, p_transport); 973 pjsip_udp_transport_cfg cfg; 974 975 pjsip_udp_transport_cfg_default(&cfg, pj_AF_INET6()); 976 if (local_a) 977 pj_sockaddr_cp(&cfg.bind_addr, local_a); 978 if (a_name) 979 cfg.addr_name = *a_name; 980 cfg.async_cnt = async_cnt; 981 982 return pjsip_udp_transport_start2(endpt, &cfg, p_transport); 953 983 } 954 984 … … 1091 1121 status = pj_sock_getsockname(sock, &tp->base.local_addr, 1092 1122 &tp->base.addr_len); 1093 if (status != PJ_SUCCESS) 1094 return status; 1123 if (status != PJ_SUCCESS) { 1124 pj_sock_close(sock); 1125 return status; 1126 } 1095 1127 1096 1128 /* Assign the socket and published address to transport. */
Note: See TracChangeset
for help on using the changeset viewer.