diff --git a/src/include/switch_apr.h b/src/include/switch_apr.h index d7bd63d896..7dde426e38 100644 --- a/src/include/switch_apr.h +++ b/src/include/switch_apr.h @@ -649,7 +649,7 @@ DoxyDefine(apr_status_t switch_socket_sendto(switcj_socket_t *sock, * @param flags The flags to use * @param buf The buffer to use * @param len The length of the available buffer - */ + * DoxyDefine(apr_status_t switch_socket_recvfrom(switch_sockaddr_t *from, switch_socket_t *sock, @@ -657,6 +657,7 @@ DoxyDefine(apr_status_t switch_socket_recvfrom(switch_sockaddr_t *from, char *buf, apr_size_t *len);) #define switch_socket_recvfrom apr_socket_recvfrom +*/ /** * Send a file from an open file descriptor to a socket, along with diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 27d86cd80f..ebf0aa366b 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -54,6 +54,11 @@ SWITCH_BEGIN_EXTERN_C #define SWITCH_SMIN -32768 #define switch_normalize_to_16bit(n) if (n > SWITCH_SMAX) n = SWITCH_SMAX / 2; else if (n < SWITCH_SMIN) n = SWITCH_SMIN / 2; +SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in); + +SWITCH_DECLARE(apr_status_t) switch_socket_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock, + apr_int32_t flags, char *buf, + apr_size_t *len); /*! diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 3923bc3085..5bd28138fd 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -272,14 +272,18 @@ static void handle_ice(switch_rtp_t *rtp_session, void *data, switch_size_t len) switch_stun_packet_t *rpacket; char *remote_ip; switch_size_t bytes; - + char ipbuf[25]; + memset(buf, 0, sizeof(buf)); rpacket = switch_stun_packet_build_header(SWITCH_STUN_BINDING_RESPONSE, packet->header.id, buf); switch_stun_packet_attribute_add_username(rpacket, username, 32); - switch_sockaddr_ip_get(&remote_ip, rtp_session->from_addr); + //switch_sockaddr_ip_get(&remote_ip, rtp_session->from_addr); + + remote_ip = switch_get_addr(ipbuf, sizeof(ipbuf), rtp_session->from_addr); + + switch_stun_packet_attribute_add_binded_address(rpacket, remote_ip, rtp_session->from_addr->port); bytes = switch_stun_packet_length(rpacket); - switch_socket_sendto(rtp_session->sock, rtp_session->from_addr, 0, (void*)rpacket, &bytes); } } @@ -866,9 +870,14 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ char *tx_host; uint32_t old = rtp_session->remote_port; char *old_host; - - switch_sockaddr_ip_get(&tx_host, rtp_session->from_addr); - switch_sockaddr_ip_get(&old_host, rtp_session->remote_addr); + char bufa[30], bufb[30]; + + //switch_sockaddr_ip_get(&tx_host, rtp_session->from_addr); + //switch_sockaddr_ip_get(&old_host, rtp_session->remote_addr); + + tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr); + old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr); + if (!switch_strlen_zero(tx_host) && rtp_session->from_addr->port > 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Auto Changing port from %s:%u to %s:%u\n", old_host, old, tx_host, rtp_session->from_addr->port); diff --git a/src/switch_utils.c b/src/switch_utils.c index 998c1854c5..6fee6cc832 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -34,6 +34,7 @@ #include #include + SWITCH_DECLARE(char *) switch_priority_name(switch_priority_t priority) { switch(priority) { /*lol*/ @@ -50,6 +51,40 @@ SWITCH_DECLARE(char *) switch_priority_name(switch_priority_t priority) static char RFC2833_CHARS[] = "0123456789*#ABCDF"; + + +SWITCH_DECLARE(char *) switch_get_addr(char *buf, switch_size_t len, switch_sockaddr_t *in) +{ + uint8_t x, *i; + char *p = buf; + + + i = (uint8_t *) &in->sa.sin.sin_addr; + + memset(buf, 0, len); + for(x =0; x < 4; x++) { + sprintf(p, "%u%s", i[x], x == 3 ? "" : "."); + p = buf + strlen(buf); + } + return buf; +} + +SWITCH_DECLARE(apr_status_t) switch_socket_recvfrom(apr_sockaddr_t *from, apr_socket_t *sock, + apr_int32_t flags, char *buf, + apr_size_t *len) +{ + apr_status_t r; + + if ((r = apr_socket_recvfrom(from, sock, flags, buf, len)) == APR_SUCCESS) { + from->port = ntohs(from->sa.sin.sin_port); + //from->ipaddr_ptr = &(from->sa.sin.sin_addr); + //from->ipaddr_ptr = inet_ntoa(from->sa.sin.sin_addr); + } + + return r; + +} + SWITCH_DECLARE(char) switch_rfc2833_to_char(int event) { if (event > -1 && event < (int32_t) sizeof(RFC2833_CHARS)) {